暂无描述

index.js 1.5MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406464074640846409464104641146412464134641446415464164641746418464194642046421464224642346424464254642646427464284642946430464314643246433464344643546436464374643846439464404644146442464434644446445464464644746448464494645046451464524645346454464554645646457464584645946460464614646246463464644646546466464674646846469464704647146472464734647446475464764647746478464794648046481464824648346484464854648646487464884648946490464914649246493464944649546496464974649846499465004650146502465034650446505465064650746508465094651046511465124651346514465154651646517465184651946520465214652246523465244652546526465274652846529465304653146532465334653446535465364653746538465394654046541465424654346544465454654646547465484654946550465514655246553465544655546556465574655846559465604656146562465634656446565465664656746568465694657046571465724657346574465754657646577465784657946580465814658246583465844658546586465874658846589465904659146592465934659446595465964659746598465994660046601466024660346604466054660646607466084660946610466114661246613466144661546616466174661846619466204662146622466234662446625466264662746628466294663046631466324663346634466354663646637466384663946640466414664246643466444664546646466474664846649466504665146652466534665446655466564665746658466594666046661466624666346664466654666646667466684666946670466714667246673466744667546676466774667846679466804668146682466834668446685466864668746688466894669046691466924669346694466954669646697466984669946700467014670246703467044670546706467074670846709467104671146712467134671446715467164671746718467194672046721467224672346724467254672646727467284672946730467314673246733467344673546736467374673846739467404674146742467434674446745467464674746748467494675046751467524675346754467554675646757467584675946760467614676246763467644676546766467674676846769467704677146772467734677446775467764677746778467794678046781467824678346784467854678646787467884678946790467914679246793467944679546796467974679846799468004680146802468034680446805468064680746808468094681046811468124681346814468154681646817468184681946820468214682246823468244682546826468274682846829468304683146832468334683446835468364683746838468394684046841468424684346844468454684646847468484684946850468514685246853468544685546856468574685846859468604686146862468634686446865468664686746868468694687046871468724687346874468754687646877468784687946880468814688246883468844688546886468874688846889468904689146892468934689446895468964689746898468994690046901469024690346904469054690646907469084690946910469114691246913469144691546916469174691846919469204692146922469234692446925469264692746928469294693046931469324693346934469354693646937469384693946940469414694246943469444694546946469474694846949469504695146952469534695446955469564695746958469594696046961469624696346964469654696646967469684696946970469714697246973469744697546976469774697846979469804698146982469834698446985469864698746988469894699046991469924699346994469954699646997469984699947000470014700247003470044700547006470074700847009470104701147012470134701447015470164701747018470194702047021470224702347024470254702647027470284702947030470314703247033470344703547036470374703847039470404704147042470434704447045470464704747048470494705047051470524705347054470554705647057470584705947060470614706247063470644706547066470674706847069470704707147072470734707447075470764707747078470794708047081470824708347084470854708647087470884708947090470914709247093470944709547096470974709847099471004710147102471034710447105471064710747108471094711047111471124711347114471154711647117471184711947120471214712247123471244712547126471274712847129471304713147132471334713447135471364713747138471394714047141471424714347144471454714647147471484714947150471514715247153471544715547156471574715847159471604716147162471634716447165471664716747168471694717047171471724717347174471754717647177471784717947180471814718247183471844718547186471874718847189471904719147192471934719447195471964719747198471994720047201472024720347204472054720647207472084720947210472114721247213472144721547216472174721847219472204722147222472234722447225472264722747228472294723047231472324723347234472354723647237472384723947240472414724247243472444724547246472474724847249472504725147252472534725447255472564725747258472594726047261472624726347264472654726647267472684726947270472714727247273472744727547276472774727847279472804728147282472834728447285472864728747288472894729047291472924729347294472954729647297472984729947300473014730247303473044730547306473074730847309473104731147312473134731447315473164731747318473194732047321473224732347324473254732647327473284732947330473314733247333473344733547336473374733847339473404734147342473434734447345473464734747348473494735047351473524735347354473554735647357473584735947360473614736247363473644736547366473674736847369473704737147372473734737447375473764737747378473794738047381473824738347384473854738647387473884738947390473914739247393473944739547396473974739847399474004740147402474034740447405474064740747408474094741047411474124741347414474154741647417474184741947420474214742247423474244742547426474274742847429474304743147432474334743447435474364743747438474394744047441474424744347444474454744647447474484744947450474514745247453474544745547456474574745847459474604746147462474634746447465474664746747468474694747047471474724747347474474754747647477474784747947480474814748247483474844748547486474874748847489474904749147492474934749447495474964749747498474994750047501475024750347504475054750647507475084750947510475114751247513475144751547516475174751847519475204752147522475234752447525475264752747528475294753047531475324753347534475354753647537475384753947540475414754247543475444754547546475474754847549475504755147552475534755447555475564755747558475594756047561475624756347564475654756647567475684756947570475714757247573475744757547576475774757847579
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
  4. var React = require('react');
  5. var React__default = _interopDefault(React);
  6. var reactDom = require('react-dom');
  7. var reactDom__default = _interopDefault(reactDom);
  8. var styleInject_es = require('../style-inject.es-dcee06b6.js');
  9. var _commonjsHelpers = require('../_commonjsHelpers-72d386ba.js');
  10. var slicedToArray = require('../slicedToArray-172f4624.js');
  11. var server = _interopDefault(require('react-dom/server'));
  12. /*
  13. object-assign
  14. (c) Sindre Sorhus
  15. @license MIT
  16. */
  17. /* eslint-disable no-unused-vars */
  18. var getOwnPropertySymbols = Object.getOwnPropertySymbols;
  19. var hasOwnProperty = Object.prototype.hasOwnProperty;
  20. var propIsEnumerable = Object.prototype.propertyIsEnumerable;
  21. function toObject(val) {
  22. if (val === null || val === undefined) {
  23. throw new TypeError('Object.assign cannot be called with null or undefined');
  24. }
  25. return Object(val);
  26. }
  27. function shouldUseNative() {
  28. try {
  29. if (!Object.assign) {
  30. return false;
  31. }
  32. // Detect buggy property enumeration order in older V8 versions.
  33. // https://bugs.chromium.org/p/v8/issues/detail?id=4118
  34. var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
  35. test1[5] = 'de';
  36. if (Object.getOwnPropertyNames(test1)[0] === '5') {
  37. return false;
  38. }
  39. // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  40. var test2 = {};
  41. for (var i = 0; i < 10; i++) {
  42. test2['_' + String.fromCharCode(i)] = i;
  43. }
  44. var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
  45. return test2[n];
  46. });
  47. if (order2.join('') !== '0123456789') {
  48. return false;
  49. }
  50. // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  51. var test3 = {};
  52. 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
  53. test3[letter] = letter;
  54. });
  55. if (Object.keys(Object.assign({}, test3)).join('') !==
  56. 'abcdefghijklmnopqrst') {
  57. return false;
  58. }
  59. return true;
  60. } catch (err) {
  61. // We don't expect any of the above to throw, but better to be safe.
  62. return false;
  63. }
  64. }
  65. var objectAssign = shouldUseNative() ? Object.assign : function (target, source) {
  66. var from;
  67. var to = toObject(target);
  68. var symbols;
  69. for (var s = 1; s < arguments.length; s++) {
  70. from = Object(arguments[s]);
  71. for (var key in from) {
  72. if (hasOwnProperty.call(from, key)) {
  73. to[key] = from[key];
  74. }
  75. }
  76. if (getOwnPropertySymbols) {
  77. symbols = getOwnPropertySymbols(from);
  78. for (var i = 0; i < symbols.length; i++) {
  79. if (propIsEnumerable.call(from, symbols[i])) {
  80. to[symbols[i]] = from[symbols[i]];
  81. }
  82. }
  83. }
  84. }
  85. return to;
  86. };
  87. var immutable = _commonjsHelpers.createCommonjsModule(function (module, exports) {
  88. /**
  89. * Copyright (c) 2014-2015, Facebook, Inc.
  90. * All rights reserved.
  91. *
  92. * This source code is licensed under the BSD-style license found in the
  93. * LICENSE file in the root directory of this source tree. An additional grant
  94. * of patent rights can be found in the PATENTS file in the same directory.
  95. */
  96. (function (global, factory) {
  97. module.exports = factory() ;
  98. }(_commonjsHelpers.commonjsGlobal, function () {var SLICE$0 = Array.prototype.slice;
  99. function createClass(ctor, superClass) {
  100. if (superClass) {
  101. ctor.prototype = Object.create(superClass.prototype);
  102. }
  103. ctor.prototype.constructor = ctor;
  104. }
  105. function Iterable(value) {
  106. return isIterable(value) ? value : Seq(value);
  107. }
  108. createClass(KeyedIterable, Iterable);
  109. function KeyedIterable(value) {
  110. return isKeyed(value) ? value : KeyedSeq(value);
  111. }
  112. createClass(IndexedIterable, Iterable);
  113. function IndexedIterable(value) {
  114. return isIndexed(value) ? value : IndexedSeq(value);
  115. }
  116. createClass(SetIterable, Iterable);
  117. function SetIterable(value) {
  118. return isIterable(value) && !isAssociative(value) ? value : SetSeq(value);
  119. }
  120. function isIterable(maybeIterable) {
  121. return !!(maybeIterable && maybeIterable[IS_ITERABLE_SENTINEL]);
  122. }
  123. function isKeyed(maybeKeyed) {
  124. return !!(maybeKeyed && maybeKeyed[IS_KEYED_SENTINEL]);
  125. }
  126. function isIndexed(maybeIndexed) {
  127. return !!(maybeIndexed && maybeIndexed[IS_INDEXED_SENTINEL]);
  128. }
  129. function isAssociative(maybeAssociative) {
  130. return isKeyed(maybeAssociative) || isIndexed(maybeAssociative);
  131. }
  132. function isOrdered(maybeOrdered) {
  133. return !!(maybeOrdered && maybeOrdered[IS_ORDERED_SENTINEL]);
  134. }
  135. Iterable.isIterable = isIterable;
  136. Iterable.isKeyed = isKeyed;
  137. Iterable.isIndexed = isIndexed;
  138. Iterable.isAssociative = isAssociative;
  139. Iterable.isOrdered = isOrdered;
  140. Iterable.Keyed = KeyedIterable;
  141. Iterable.Indexed = IndexedIterable;
  142. Iterable.Set = SetIterable;
  143. var IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
  144. var IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
  145. var IS_INDEXED_SENTINEL = '@@__IMMUTABLE_INDEXED__@@';
  146. var IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
  147. // Used for setting prototype methods that IE8 chokes on.
  148. var DELETE = 'delete';
  149. // Constants describing the size of trie nodes.
  150. var SHIFT = 5; // Resulted in best performance after ______?
  151. var SIZE = 1 << SHIFT;
  152. var MASK = SIZE - 1;
  153. // A consistent shared value representing "not set" which equals nothing other
  154. // than itself, and nothing that could be provided externally.
  155. var NOT_SET = {};
  156. // Boolean references, Rough equivalent of `bool &`.
  157. var CHANGE_LENGTH = { value: false };
  158. var DID_ALTER = { value: false };
  159. function MakeRef(ref) {
  160. ref.value = false;
  161. return ref;
  162. }
  163. function SetRef(ref) {
  164. ref && (ref.value = true);
  165. }
  166. // A function which returns a value representing an "owner" for transient writes
  167. // to tries. The return value will only ever equal itself, and will not equal
  168. // the return of any subsequent call of this function.
  169. function OwnerID() {}
  170. // http://jsperf.com/copy-array-inline
  171. function arrCopy(arr, offset) {
  172. offset = offset || 0;
  173. var len = Math.max(0, arr.length - offset);
  174. var newArr = new Array(len);
  175. for (var ii = 0; ii < len; ii++) {
  176. newArr[ii] = arr[ii + offset];
  177. }
  178. return newArr;
  179. }
  180. function ensureSize(iter) {
  181. if (iter.size === undefined) {
  182. iter.size = iter.__iterate(returnTrue);
  183. }
  184. return iter.size;
  185. }
  186. function wrapIndex(iter, index) {
  187. // This implements "is array index" which the ECMAString spec defines as:
  188. //
  189. // A String property name P is an array index if and only if
  190. // ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal
  191. // to 2^32−1.
  192. //
  193. // http://www.ecma-international.org/ecma-262/6.0/#sec-array-exotic-objects
  194. if (typeof index !== 'number') {
  195. var uint32Index = index >>> 0; // N >>> 0 is shorthand for ToUint32
  196. if ('' + uint32Index !== index || uint32Index === 4294967295) {
  197. return NaN;
  198. }
  199. index = uint32Index;
  200. }
  201. return index < 0 ? ensureSize(iter) + index : index;
  202. }
  203. function returnTrue() {
  204. return true;
  205. }
  206. function wholeSlice(begin, end, size) {
  207. return (begin === 0 || (size !== undefined && begin <= -size)) &&
  208. (end === undefined || (size !== undefined && end >= size));
  209. }
  210. function resolveBegin(begin, size) {
  211. return resolveIndex(begin, size, 0);
  212. }
  213. function resolveEnd(end, size) {
  214. return resolveIndex(end, size, size);
  215. }
  216. function resolveIndex(index, size, defaultIndex) {
  217. return index === undefined ?
  218. defaultIndex :
  219. index < 0 ?
  220. Math.max(0, size + index) :
  221. size === undefined ?
  222. index :
  223. Math.min(size, index);
  224. }
  225. /* global Symbol */
  226. var ITERATE_KEYS = 0;
  227. var ITERATE_VALUES = 1;
  228. var ITERATE_ENTRIES = 2;
  229. var REAL_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
  230. var FAUX_ITERATOR_SYMBOL = '@@iterator';
  231. var ITERATOR_SYMBOL = REAL_ITERATOR_SYMBOL || FAUX_ITERATOR_SYMBOL;
  232. function Iterator(next) {
  233. this.next = next;
  234. }
  235. Iterator.prototype.toString = function() {
  236. return '[Iterator]';
  237. };
  238. Iterator.KEYS = ITERATE_KEYS;
  239. Iterator.VALUES = ITERATE_VALUES;
  240. Iterator.ENTRIES = ITERATE_ENTRIES;
  241. Iterator.prototype.inspect =
  242. Iterator.prototype.toSource = function () { return this.toString(); };
  243. Iterator.prototype[ITERATOR_SYMBOL] = function () {
  244. return this;
  245. };
  246. function iteratorValue(type, k, v, iteratorResult) {
  247. var value = type === 0 ? k : type === 1 ? v : [k, v];
  248. iteratorResult ? (iteratorResult.value = value) : (iteratorResult = {
  249. value: value, done: false
  250. });
  251. return iteratorResult;
  252. }
  253. function iteratorDone() {
  254. return { value: undefined, done: true };
  255. }
  256. function hasIterator(maybeIterable) {
  257. return !!getIteratorFn(maybeIterable);
  258. }
  259. function isIterator(maybeIterator) {
  260. return maybeIterator && typeof maybeIterator.next === 'function';
  261. }
  262. function getIterator(iterable) {
  263. var iteratorFn = getIteratorFn(iterable);
  264. return iteratorFn && iteratorFn.call(iterable);
  265. }
  266. function getIteratorFn(iterable) {
  267. var iteratorFn = iterable && (
  268. (REAL_ITERATOR_SYMBOL && iterable[REAL_ITERATOR_SYMBOL]) ||
  269. iterable[FAUX_ITERATOR_SYMBOL]
  270. );
  271. if (typeof iteratorFn === 'function') {
  272. return iteratorFn;
  273. }
  274. }
  275. function isArrayLike(value) {
  276. return value && typeof value.length === 'number';
  277. }
  278. createClass(Seq, Iterable);
  279. function Seq(value) {
  280. return value === null || value === undefined ? emptySequence() :
  281. isIterable(value) ? value.toSeq() : seqFromValue(value);
  282. }
  283. Seq.of = function(/*...values*/) {
  284. return Seq(arguments);
  285. };
  286. Seq.prototype.toSeq = function() {
  287. return this;
  288. };
  289. Seq.prototype.toString = function() {
  290. return this.__toString('Seq {', '}');
  291. };
  292. Seq.prototype.cacheResult = function() {
  293. if (!this._cache && this.__iterateUncached) {
  294. this._cache = this.entrySeq().toArray();
  295. this.size = this._cache.length;
  296. }
  297. return this;
  298. };
  299. // abstract __iterateUncached(fn, reverse)
  300. Seq.prototype.__iterate = function(fn, reverse) {
  301. return seqIterate(this, fn, reverse, true);
  302. };
  303. // abstract __iteratorUncached(type, reverse)
  304. Seq.prototype.__iterator = function(type, reverse) {
  305. return seqIterator(this, type, reverse, true);
  306. };
  307. createClass(KeyedSeq, Seq);
  308. function KeyedSeq(value) {
  309. return value === null || value === undefined ?
  310. emptySequence().toKeyedSeq() :
  311. isIterable(value) ?
  312. (isKeyed(value) ? value.toSeq() : value.fromEntrySeq()) :
  313. keyedSeqFromValue(value);
  314. }
  315. KeyedSeq.prototype.toKeyedSeq = function() {
  316. return this;
  317. };
  318. createClass(IndexedSeq, Seq);
  319. function IndexedSeq(value) {
  320. return value === null || value === undefined ? emptySequence() :
  321. !isIterable(value) ? indexedSeqFromValue(value) :
  322. isKeyed(value) ? value.entrySeq() : value.toIndexedSeq();
  323. }
  324. IndexedSeq.of = function(/*...values*/) {
  325. return IndexedSeq(arguments);
  326. };
  327. IndexedSeq.prototype.toIndexedSeq = function() {
  328. return this;
  329. };
  330. IndexedSeq.prototype.toString = function() {
  331. return this.__toString('Seq [', ']');
  332. };
  333. IndexedSeq.prototype.__iterate = function(fn, reverse) {
  334. return seqIterate(this, fn, reverse, false);
  335. };
  336. IndexedSeq.prototype.__iterator = function(type, reverse) {
  337. return seqIterator(this, type, reverse, false);
  338. };
  339. createClass(SetSeq, Seq);
  340. function SetSeq(value) {
  341. return (
  342. value === null || value === undefined ? emptySequence() :
  343. !isIterable(value) ? indexedSeqFromValue(value) :
  344. isKeyed(value) ? value.entrySeq() : value
  345. ).toSetSeq();
  346. }
  347. SetSeq.of = function(/*...values*/) {
  348. return SetSeq(arguments);
  349. };
  350. SetSeq.prototype.toSetSeq = function() {
  351. return this;
  352. };
  353. Seq.isSeq = isSeq;
  354. Seq.Keyed = KeyedSeq;
  355. Seq.Set = SetSeq;
  356. Seq.Indexed = IndexedSeq;
  357. var IS_SEQ_SENTINEL = '@@__IMMUTABLE_SEQ__@@';
  358. Seq.prototype[IS_SEQ_SENTINEL] = true;
  359. createClass(ArraySeq, IndexedSeq);
  360. function ArraySeq(array) {
  361. this._array = array;
  362. this.size = array.length;
  363. }
  364. ArraySeq.prototype.get = function(index, notSetValue) {
  365. return this.has(index) ? this._array[wrapIndex(this, index)] : notSetValue;
  366. };
  367. ArraySeq.prototype.__iterate = function(fn, reverse) {
  368. var array = this._array;
  369. var maxIndex = array.length - 1;
  370. for (var ii = 0; ii <= maxIndex; ii++) {
  371. if (fn(array[reverse ? maxIndex - ii : ii], ii, this) === false) {
  372. return ii + 1;
  373. }
  374. }
  375. return ii;
  376. };
  377. ArraySeq.prototype.__iterator = function(type, reverse) {
  378. var array = this._array;
  379. var maxIndex = array.length - 1;
  380. var ii = 0;
  381. return new Iterator(function()
  382. {return ii > maxIndex ?
  383. iteratorDone() :
  384. iteratorValue(type, ii, array[reverse ? maxIndex - ii++ : ii++])}
  385. );
  386. };
  387. createClass(ObjectSeq, KeyedSeq);
  388. function ObjectSeq(object) {
  389. var keys = Object.keys(object);
  390. this._object = object;
  391. this._keys = keys;
  392. this.size = keys.length;
  393. }
  394. ObjectSeq.prototype.get = function(key, notSetValue) {
  395. if (notSetValue !== undefined && !this.has(key)) {
  396. return notSetValue;
  397. }
  398. return this._object[key];
  399. };
  400. ObjectSeq.prototype.has = function(key) {
  401. return this._object.hasOwnProperty(key);
  402. };
  403. ObjectSeq.prototype.__iterate = function(fn, reverse) {
  404. var object = this._object;
  405. var keys = this._keys;
  406. var maxIndex = keys.length - 1;
  407. for (var ii = 0; ii <= maxIndex; ii++) {
  408. var key = keys[reverse ? maxIndex - ii : ii];
  409. if (fn(object[key], key, this) === false) {
  410. return ii + 1;
  411. }
  412. }
  413. return ii;
  414. };
  415. ObjectSeq.prototype.__iterator = function(type, reverse) {
  416. var object = this._object;
  417. var keys = this._keys;
  418. var maxIndex = keys.length - 1;
  419. var ii = 0;
  420. return new Iterator(function() {
  421. var key = keys[reverse ? maxIndex - ii : ii];
  422. return ii++ > maxIndex ?
  423. iteratorDone() :
  424. iteratorValue(type, key, object[key]);
  425. });
  426. };
  427. ObjectSeq.prototype[IS_ORDERED_SENTINEL] = true;
  428. createClass(IterableSeq, IndexedSeq);
  429. function IterableSeq(iterable) {
  430. this._iterable = iterable;
  431. this.size = iterable.length || iterable.size;
  432. }
  433. IterableSeq.prototype.__iterateUncached = function(fn, reverse) {
  434. if (reverse) {
  435. return this.cacheResult().__iterate(fn, reverse);
  436. }
  437. var iterable = this._iterable;
  438. var iterator = getIterator(iterable);
  439. var iterations = 0;
  440. if (isIterator(iterator)) {
  441. var step;
  442. while (!(step = iterator.next()).done) {
  443. if (fn(step.value, iterations++, this) === false) {
  444. break;
  445. }
  446. }
  447. }
  448. return iterations;
  449. };
  450. IterableSeq.prototype.__iteratorUncached = function(type, reverse) {
  451. if (reverse) {
  452. return this.cacheResult().__iterator(type, reverse);
  453. }
  454. var iterable = this._iterable;
  455. var iterator = getIterator(iterable);
  456. if (!isIterator(iterator)) {
  457. return new Iterator(iteratorDone);
  458. }
  459. var iterations = 0;
  460. return new Iterator(function() {
  461. var step = iterator.next();
  462. return step.done ? step : iteratorValue(type, iterations++, step.value);
  463. });
  464. };
  465. createClass(IteratorSeq, IndexedSeq);
  466. function IteratorSeq(iterator) {
  467. this._iterator = iterator;
  468. this._iteratorCache = [];
  469. }
  470. IteratorSeq.prototype.__iterateUncached = function(fn, reverse) {
  471. if (reverse) {
  472. return this.cacheResult().__iterate(fn, reverse);
  473. }
  474. var iterator = this._iterator;
  475. var cache = this._iteratorCache;
  476. var iterations = 0;
  477. while (iterations < cache.length) {
  478. if (fn(cache[iterations], iterations++, this) === false) {
  479. return iterations;
  480. }
  481. }
  482. var step;
  483. while (!(step = iterator.next()).done) {
  484. var val = step.value;
  485. cache[iterations] = val;
  486. if (fn(val, iterations++, this) === false) {
  487. break;
  488. }
  489. }
  490. return iterations;
  491. };
  492. IteratorSeq.prototype.__iteratorUncached = function(type, reverse) {
  493. if (reverse) {
  494. return this.cacheResult().__iterator(type, reverse);
  495. }
  496. var iterator = this._iterator;
  497. var cache = this._iteratorCache;
  498. var iterations = 0;
  499. return new Iterator(function() {
  500. if (iterations >= cache.length) {
  501. var step = iterator.next();
  502. if (step.done) {
  503. return step;
  504. }
  505. cache[iterations] = step.value;
  506. }
  507. return iteratorValue(type, iterations, cache[iterations++]);
  508. });
  509. };
  510. // # pragma Helper functions
  511. function isSeq(maybeSeq) {
  512. return !!(maybeSeq && maybeSeq[IS_SEQ_SENTINEL]);
  513. }
  514. var EMPTY_SEQ;
  515. function emptySequence() {
  516. return EMPTY_SEQ || (EMPTY_SEQ = new ArraySeq([]));
  517. }
  518. function keyedSeqFromValue(value) {
  519. var seq =
  520. Array.isArray(value) ? new ArraySeq(value).fromEntrySeq() :
  521. isIterator(value) ? new IteratorSeq(value).fromEntrySeq() :
  522. hasIterator(value) ? new IterableSeq(value).fromEntrySeq() :
  523. typeof value === 'object' ? new ObjectSeq(value) :
  524. undefined;
  525. if (!seq) {
  526. throw new TypeError(
  527. 'Expected Array or iterable object of [k, v] entries, '+
  528. 'or keyed object: ' + value
  529. );
  530. }
  531. return seq;
  532. }
  533. function indexedSeqFromValue(value) {
  534. var seq = maybeIndexedSeqFromValue(value);
  535. if (!seq) {
  536. throw new TypeError(
  537. 'Expected Array or iterable object of values: ' + value
  538. );
  539. }
  540. return seq;
  541. }
  542. function seqFromValue(value) {
  543. var seq = maybeIndexedSeqFromValue(value) ||
  544. (typeof value === 'object' && new ObjectSeq(value));
  545. if (!seq) {
  546. throw new TypeError(
  547. 'Expected Array or iterable object of values, or keyed object: ' + value
  548. );
  549. }
  550. return seq;
  551. }
  552. function maybeIndexedSeqFromValue(value) {
  553. return (
  554. isArrayLike(value) ? new ArraySeq(value) :
  555. isIterator(value) ? new IteratorSeq(value) :
  556. hasIterator(value) ? new IterableSeq(value) :
  557. undefined
  558. );
  559. }
  560. function seqIterate(seq, fn, reverse, useKeys) {
  561. var cache = seq._cache;
  562. if (cache) {
  563. var maxIndex = cache.length - 1;
  564. for (var ii = 0; ii <= maxIndex; ii++) {
  565. var entry = cache[reverse ? maxIndex - ii : ii];
  566. if (fn(entry[1], useKeys ? entry[0] : ii, seq) === false) {
  567. return ii + 1;
  568. }
  569. }
  570. return ii;
  571. }
  572. return seq.__iterateUncached(fn, reverse);
  573. }
  574. function seqIterator(seq, type, reverse, useKeys) {
  575. var cache = seq._cache;
  576. if (cache) {
  577. var maxIndex = cache.length - 1;
  578. var ii = 0;
  579. return new Iterator(function() {
  580. var entry = cache[reverse ? maxIndex - ii : ii];
  581. return ii++ > maxIndex ?
  582. iteratorDone() :
  583. iteratorValue(type, useKeys ? entry[0] : ii - 1, entry[1]);
  584. });
  585. }
  586. return seq.__iteratorUncached(type, reverse);
  587. }
  588. function fromJS(json, converter) {
  589. return converter ?
  590. fromJSWith(converter, json, '', {'': json}) :
  591. fromJSDefault(json);
  592. }
  593. function fromJSWith(converter, json, key, parentJSON) {
  594. if (Array.isArray(json)) {
  595. return converter.call(parentJSON, key, IndexedSeq(json).map(function(v, k) {return fromJSWith(converter, v, k, json)}));
  596. }
  597. if (isPlainObj(json)) {
  598. return converter.call(parentJSON, key, KeyedSeq(json).map(function(v, k) {return fromJSWith(converter, v, k, json)}));
  599. }
  600. return json;
  601. }
  602. function fromJSDefault(json) {
  603. if (Array.isArray(json)) {
  604. return IndexedSeq(json).map(fromJSDefault).toList();
  605. }
  606. if (isPlainObj(json)) {
  607. return KeyedSeq(json).map(fromJSDefault).toMap();
  608. }
  609. return json;
  610. }
  611. function isPlainObj(value) {
  612. return value && (value.constructor === Object || value.constructor === undefined);
  613. }
  614. /**
  615. * An extension of the "same-value" algorithm as [described for use by ES6 Map
  616. * and Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map#Key_equality)
  617. *
  618. * NaN is considered the same as NaN, however -0 and 0 are considered the same
  619. * value, which is different from the algorithm described by
  620. * [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is).
  621. *
  622. * This is extended further to allow Objects to describe the values they
  623. * represent, by way of `valueOf` or `equals` (and `hashCode`).
  624. *
  625. * Note: because of this extension, the key equality of Immutable.Map and the
  626. * value equality of Immutable.Set will differ from ES6 Map and Set.
  627. *
  628. * ### Defining custom values
  629. *
  630. * The easiest way to describe the value an object represents is by implementing
  631. * `valueOf`. For example, `Date` represents a value by returning a unix
  632. * timestamp for `valueOf`:
  633. *
  634. * var date1 = new Date(1234567890000); // Fri Feb 13 2009 ...
  635. * var date2 = new Date(1234567890000);
  636. * date1.valueOf(); // 1234567890000
  637. * assert( date1 !== date2 );
  638. * assert( Immutable.is( date1, date2 ) );
  639. *
  640. * Note: overriding `valueOf` may have other implications if you use this object
  641. * where JavaScript expects a primitive, such as implicit string coercion.
  642. *
  643. * For more complex types, especially collections, implementing `valueOf` may
  644. * not be performant. An alternative is to implement `equals` and `hashCode`.
  645. *
  646. * `equals` takes another object, presumably of similar type, and returns true
  647. * if the it is equal. Equality is symmetrical, so the same result should be
  648. * returned if this and the argument are flipped.
  649. *
  650. * assert( a.equals(b) === b.equals(a) );
  651. *
  652. * `hashCode` returns a 32bit integer number representing the object which will
  653. * be used to determine how to store the value object in a Map or Set. You must
  654. * provide both or neither methods, one must not exist without the other.
  655. *
  656. * Also, an important relationship between these methods must be upheld: if two
  657. * values are equal, they *must* return the same hashCode. If the values are not
  658. * equal, they might have the same hashCode; this is called a hash collision,
  659. * and while undesirable for performance reasons, it is acceptable.
  660. *
  661. * if (a.equals(b)) {
  662. * assert( a.hashCode() === b.hashCode() );
  663. * }
  664. *
  665. * All Immutable collections implement `equals` and `hashCode`.
  666. *
  667. */
  668. function is(valueA, valueB) {
  669. if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
  670. return true;
  671. }
  672. if (!valueA || !valueB) {
  673. return false;
  674. }
  675. if (typeof valueA.valueOf === 'function' &&
  676. typeof valueB.valueOf === 'function') {
  677. valueA = valueA.valueOf();
  678. valueB = valueB.valueOf();
  679. if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
  680. return true;
  681. }
  682. if (!valueA || !valueB) {
  683. return false;
  684. }
  685. }
  686. if (typeof valueA.equals === 'function' &&
  687. typeof valueB.equals === 'function' &&
  688. valueA.equals(valueB)) {
  689. return true;
  690. }
  691. return false;
  692. }
  693. function deepEqual(a, b) {
  694. if (a === b) {
  695. return true;
  696. }
  697. if (
  698. !isIterable(b) ||
  699. a.size !== undefined && b.size !== undefined && a.size !== b.size ||
  700. a.__hash !== undefined && b.__hash !== undefined && a.__hash !== b.__hash ||
  701. isKeyed(a) !== isKeyed(b) ||
  702. isIndexed(a) !== isIndexed(b) ||
  703. isOrdered(a) !== isOrdered(b)
  704. ) {
  705. return false;
  706. }
  707. if (a.size === 0 && b.size === 0) {
  708. return true;
  709. }
  710. var notAssociative = !isAssociative(a);
  711. if (isOrdered(a)) {
  712. var entries = a.entries();
  713. return b.every(function(v, k) {
  714. var entry = entries.next().value;
  715. return entry && is(entry[1], v) && (notAssociative || is(entry[0], k));
  716. }) && entries.next().done;
  717. }
  718. var flipped = false;
  719. if (a.size === undefined) {
  720. if (b.size === undefined) {
  721. if (typeof a.cacheResult === 'function') {
  722. a.cacheResult();
  723. }
  724. } else {
  725. flipped = true;
  726. var _ = a;
  727. a = b;
  728. b = _;
  729. }
  730. }
  731. var allEqual = true;
  732. var bSize = b.__iterate(function(v, k) {
  733. if (notAssociative ? !a.has(v) :
  734. flipped ? !is(v, a.get(k, NOT_SET)) : !is(a.get(k, NOT_SET), v)) {
  735. allEqual = false;
  736. return false;
  737. }
  738. });
  739. return allEqual && a.size === bSize;
  740. }
  741. createClass(Repeat, IndexedSeq);
  742. function Repeat(value, times) {
  743. if (!(this instanceof Repeat)) {
  744. return new Repeat(value, times);
  745. }
  746. this._value = value;
  747. this.size = times === undefined ? Infinity : Math.max(0, times);
  748. if (this.size === 0) {
  749. if (EMPTY_REPEAT) {
  750. return EMPTY_REPEAT;
  751. }
  752. EMPTY_REPEAT = this;
  753. }
  754. }
  755. Repeat.prototype.toString = function() {
  756. if (this.size === 0) {
  757. return 'Repeat []';
  758. }
  759. return 'Repeat [ ' + this._value + ' ' + this.size + ' times ]';
  760. };
  761. Repeat.prototype.get = function(index, notSetValue) {
  762. return this.has(index) ? this._value : notSetValue;
  763. };
  764. Repeat.prototype.includes = function(searchValue) {
  765. return is(this._value, searchValue);
  766. };
  767. Repeat.prototype.slice = function(begin, end) {
  768. var size = this.size;
  769. return wholeSlice(begin, end, size) ? this :
  770. new Repeat(this._value, resolveEnd(end, size) - resolveBegin(begin, size));
  771. };
  772. Repeat.prototype.reverse = function() {
  773. return this;
  774. };
  775. Repeat.prototype.indexOf = function(searchValue) {
  776. if (is(this._value, searchValue)) {
  777. return 0;
  778. }
  779. return -1;
  780. };
  781. Repeat.prototype.lastIndexOf = function(searchValue) {
  782. if (is(this._value, searchValue)) {
  783. return this.size;
  784. }
  785. return -1;
  786. };
  787. Repeat.prototype.__iterate = function(fn, reverse) {
  788. for (var ii = 0; ii < this.size; ii++) {
  789. if (fn(this._value, ii, this) === false) {
  790. return ii + 1;
  791. }
  792. }
  793. return ii;
  794. };
  795. Repeat.prototype.__iterator = function(type, reverse) {var this$0 = this;
  796. var ii = 0;
  797. return new Iterator(function()
  798. {return ii < this$0.size ? iteratorValue(type, ii++, this$0._value) : iteratorDone()}
  799. );
  800. };
  801. Repeat.prototype.equals = function(other) {
  802. return other instanceof Repeat ?
  803. is(this._value, other._value) :
  804. deepEqual(other);
  805. };
  806. var EMPTY_REPEAT;
  807. function invariant(condition, error) {
  808. if (!condition) throw new Error(error);
  809. }
  810. createClass(Range, IndexedSeq);
  811. function Range(start, end, step) {
  812. if (!(this instanceof Range)) {
  813. return new Range(start, end, step);
  814. }
  815. invariant(step !== 0, 'Cannot step a Range by 0');
  816. start = start || 0;
  817. if (end === undefined) {
  818. end = Infinity;
  819. }
  820. step = step === undefined ? 1 : Math.abs(step);
  821. if (end < start) {
  822. step = -step;
  823. }
  824. this._start = start;
  825. this._end = end;
  826. this._step = step;
  827. this.size = Math.max(0, Math.ceil((end - start) / step - 1) + 1);
  828. if (this.size === 0) {
  829. if (EMPTY_RANGE) {
  830. return EMPTY_RANGE;
  831. }
  832. EMPTY_RANGE = this;
  833. }
  834. }
  835. Range.prototype.toString = function() {
  836. if (this.size === 0) {
  837. return 'Range []';
  838. }
  839. return 'Range [ ' +
  840. this._start + '...' + this._end +
  841. (this._step > 1 ? ' by ' + this._step : '') +
  842. ' ]';
  843. };
  844. Range.prototype.get = function(index, notSetValue) {
  845. return this.has(index) ?
  846. this._start + wrapIndex(this, index) * this._step :
  847. notSetValue;
  848. };
  849. Range.prototype.includes = function(searchValue) {
  850. var possibleIndex = (searchValue - this._start) / this._step;
  851. return possibleIndex >= 0 &&
  852. possibleIndex < this.size &&
  853. possibleIndex === Math.floor(possibleIndex);
  854. };
  855. Range.prototype.slice = function(begin, end) {
  856. if (wholeSlice(begin, end, this.size)) {
  857. return this;
  858. }
  859. begin = resolveBegin(begin, this.size);
  860. end = resolveEnd(end, this.size);
  861. if (end <= begin) {
  862. return new Range(0, 0);
  863. }
  864. return new Range(this.get(begin, this._end), this.get(end, this._end), this._step);
  865. };
  866. Range.prototype.indexOf = function(searchValue) {
  867. var offsetValue = searchValue - this._start;
  868. if (offsetValue % this._step === 0) {
  869. var index = offsetValue / this._step;
  870. if (index >= 0 && index < this.size) {
  871. return index
  872. }
  873. }
  874. return -1;
  875. };
  876. Range.prototype.lastIndexOf = function(searchValue) {
  877. return this.indexOf(searchValue);
  878. };
  879. Range.prototype.__iterate = function(fn, reverse) {
  880. var maxIndex = this.size - 1;
  881. var step = this._step;
  882. var value = reverse ? this._start + maxIndex * step : this._start;
  883. for (var ii = 0; ii <= maxIndex; ii++) {
  884. if (fn(value, ii, this) === false) {
  885. return ii + 1;
  886. }
  887. value += reverse ? -step : step;
  888. }
  889. return ii;
  890. };
  891. Range.prototype.__iterator = function(type, reverse) {
  892. var maxIndex = this.size - 1;
  893. var step = this._step;
  894. var value = reverse ? this._start + maxIndex * step : this._start;
  895. var ii = 0;
  896. return new Iterator(function() {
  897. var v = value;
  898. value += reverse ? -step : step;
  899. return ii > maxIndex ? iteratorDone() : iteratorValue(type, ii++, v);
  900. });
  901. };
  902. Range.prototype.equals = function(other) {
  903. return other instanceof Range ?
  904. this._start === other._start &&
  905. this._end === other._end &&
  906. this._step === other._step :
  907. deepEqual(this, other);
  908. };
  909. var EMPTY_RANGE;
  910. createClass(Collection, Iterable);
  911. function Collection() {
  912. throw TypeError('Abstract');
  913. }
  914. createClass(KeyedCollection, Collection);function KeyedCollection() {}
  915. createClass(IndexedCollection, Collection);function IndexedCollection() {}
  916. createClass(SetCollection, Collection);function SetCollection() {}
  917. Collection.Keyed = KeyedCollection;
  918. Collection.Indexed = IndexedCollection;
  919. Collection.Set = SetCollection;
  920. var imul =
  921. typeof Math.imul === 'function' && Math.imul(0xffffffff, 2) === -2 ?
  922. Math.imul :
  923. function imul(a, b) {
  924. a = a | 0; // int
  925. b = b | 0; // int
  926. var c = a & 0xffff;
  927. var d = b & 0xffff;
  928. // Shift by 0 fixes the sign on the high part.
  929. return (c * d) + ((((a >>> 16) * d + c * (b >>> 16)) << 16) >>> 0) | 0; // int
  930. };
  931. // v8 has an optimization for storing 31-bit signed numbers.
  932. // Values which have either 00 or 11 as the high order bits qualify.
  933. // This function drops the highest order bit in a signed number, maintaining
  934. // the sign bit.
  935. function smi(i32) {
  936. return ((i32 >>> 1) & 0x40000000) | (i32 & 0xBFFFFFFF);
  937. }
  938. function hash(o) {
  939. if (o === false || o === null || o === undefined) {
  940. return 0;
  941. }
  942. if (typeof o.valueOf === 'function') {
  943. o = o.valueOf();
  944. if (o === false || o === null || o === undefined) {
  945. return 0;
  946. }
  947. }
  948. if (o === true) {
  949. return 1;
  950. }
  951. var type = typeof o;
  952. if (type === 'number') {
  953. var h = o | 0;
  954. if (h !== o) {
  955. h ^= o * 0xFFFFFFFF;
  956. }
  957. while (o > 0xFFFFFFFF) {
  958. o /= 0xFFFFFFFF;
  959. h ^= o;
  960. }
  961. return smi(h);
  962. }
  963. if (type === 'string') {
  964. return o.length > STRING_HASH_CACHE_MIN_STRLEN ? cachedHashString(o) : hashString(o);
  965. }
  966. if (typeof o.hashCode === 'function') {
  967. return o.hashCode();
  968. }
  969. if (type === 'object') {
  970. return hashJSObj(o);
  971. }
  972. if (typeof o.toString === 'function') {
  973. return hashString(o.toString());
  974. }
  975. throw new Error('Value type ' + type + ' cannot be hashed.');
  976. }
  977. function cachedHashString(string) {
  978. var hash = stringHashCache[string];
  979. if (hash === undefined) {
  980. hash = hashString(string);
  981. if (STRING_HASH_CACHE_SIZE === STRING_HASH_CACHE_MAX_SIZE) {
  982. STRING_HASH_CACHE_SIZE = 0;
  983. stringHashCache = {};
  984. }
  985. STRING_HASH_CACHE_SIZE++;
  986. stringHashCache[string] = hash;
  987. }
  988. return hash;
  989. }
  990. // http://jsperf.com/hashing-strings
  991. function hashString(string) {
  992. // This is the hash from JVM
  993. // The hash code for a string is computed as
  994. // s[0] * 31 ^ (n - 1) + s[1] * 31 ^ (n - 2) + ... + s[n - 1],
  995. // where s[i] is the ith character of the string and n is the length of
  996. // the string. We "mod" the result to make it between 0 (inclusive) and 2^31
  997. // (exclusive) by dropping high bits.
  998. var hash = 0;
  999. for (var ii = 0; ii < string.length; ii++) {
  1000. hash = 31 * hash + string.charCodeAt(ii) | 0;
  1001. }
  1002. return smi(hash);
  1003. }
  1004. function hashJSObj(obj) {
  1005. var hash;
  1006. if (usingWeakMap) {
  1007. hash = weakMap.get(obj);
  1008. if (hash !== undefined) {
  1009. return hash;
  1010. }
  1011. }
  1012. hash = obj[UID_HASH_KEY];
  1013. if (hash !== undefined) {
  1014. return hash;
  1015. }
  1016. if (!canDefineProperty) {
  1017. hash = obj.propertyIsEnumerable && obj.propertyIsEnumerable[UID_HASH_KEY];
  1018. if (hash !== undefined) {
  1019. return hash;
  1020. }
  1021. hash = getIENodeHash(obj);
  1022. if (hash !== undefined) {
  1023. return hash;
  1024. }
  1025. }
  1026. hash = ++objHashUID;
  1027. if (objHashUID & 0x40000000) {
  1028. objHashUID = 0;
  1029. }
  1030. if (usingWeakMap) {
  1031. weakMap.set(obj, hash);
  1032. } else if (isExtensible !== undefined && isExtensible(obj) === false) {
  1033. throw new Error('Non-extensible objects are not allowed as keys.');
  1034. } else if (canDefineProperty) {
  1035. Object.defineProperty(obj, UID_HASH_KEY, {
  1036. 'enumerable': false,
  1037. 'configurable': false,
  1038. 'writable': false,
  1039. 'value': hash
  1040. });
  1041. } else if (obj.propertyIsEnumerable !== undefined &&
  1042. obj.propertyIsEnumerable === obj.constructor.prototype.propertyIsEnumerable) {
  1043. // Since we can't define a non-enumerable property on the object
  1044. // we'll hijack one of the less-used non-enumerable properties to
  1045. // save our hash on it. Since this is a function it will not show up in
  1046. // `JSON.stringify` which is what we want.
  1047. obj.propertyIsEnumerable = function() {
  1048. return this.constructor.prototype.propertyIsEnumerable.apply(this, arguments);
  1049. };
  1050. obj.propertyIsEnumerable[UID_HASH_KEY] = hash;
  1051. } else if (obj.nodeType !== undefined) {
  1052. // At this point we couldn't get the IE `uniqueID` to use as a hash
  1053. // and we couldn't use a non-enumerable property to exploit the
  1054. // dontEnum bug so we simply add the `UID_HASH_KEY` on the node
  1055. // itself.
  1056. obj[UID_HASH_KEY] = hash;
  1057. } else {
  1058. throw new Error('Unable to set a non-enumerable property on object.');
  1059. }
  1060. return hash;
  1061. }
  1062. // Get references to ES5 object methods.
  1063. var isExtensible = Object.isExtensible;
  1064. // True if Object.defineProperty works as expected. IE8 fails this test.
  1065. var canDefineProperty = (function() {
  1066. try {
  1067. Object.defineProperty({}, '@', {});
  1068. return true;
  1069. } catch (e) {
  1070. return false;
  1071. }
  1072. }());
  1073. // IE has a `uniqueID` property on DOM nodes. We can construct the hash from it
  1074. // and avoid memory leaks from the IE cloneNode bug.
  1075. function getIENodeHash(node) {
  1076. if (node && node.nodeType > 0) {
  1077. switch (node.nodeType) {
  1078. case 1: // Element
  1079. return node.uniqueID;
  1080. case 9: // Document
  1081. return node.documentElement && node.documentElement.uniqueID;
  1082. }
  1083. }
  1084. }
  1085. // If possible, use a WeakMap.
  1086. var usingWeakMap = typeof WeakMap === 'function';
  1087. var weakMap;
  1088. if (usingWeakMap) {
  1089. weakMap = new WeakMap();
  1090. }
  1091. var objHashUID = 0;
  1092. var UID_HASH_KEY = '__immutablehash__';
  1093. if (typeof Symbol === 'function') {
  1094. UID_HASH_KEY = Symbol(UID_HASH_KEY);
  1095. }
  1096. var STRING_HASH_CACHE_MIN_STRLEN = 16;
  1097. var STRING_HASH_CACHE_MAX_SIZE = 255;
  1098. var STRING_HASH_CACHE_SIZE = 0;
  1099. var stringHashCache = {};
  1100. function assertNotInfinite(size) {
  1101. invariant(
  1102. size !== Infinity,
  1103. 'Cannot perform this action with an infinite size.'
  1104. );
  1105. }
  1106. createClass(Map, KeyedCollection);
  1107. // @pragma Construction
  1108. function Map(value) {
  1109. return value === null || value === undefined ? emptyMap() :
  1110. isMap(value) && !isOrdered(value) ? value :
  1111. emptyMap().withMutations(function(map ) {
  1112. var iter = KeyedIterable(value);
  1113. assertNotInfinite(iter.size);
  1114. iter.forEach(function(v, k) {return map.set(k, v)});
  1115. });
  1116. }
  1117. Map.prototype.toString = function() {
  1118. return this.__toString('Map {', '}');
  1119. };
  1120. // @pragma Access
  1121. Map.prototype.get = function(k, notSetValue) {
  1122. return this._root ?
  1123. this._root.get(0, undefined, k, notSetValue) :
  1124. notSetValue;
  1125. };
  1126. // @pragma Modification
  1127. Map.prototype.set = function(k, v) {
  1128. return updateMap(this, k, v);
  1129. };
  1130. Map.prototype.setIn = function(keyPath, v) {
  1131. return this.updateIn(keyPath, NOT_SET, function() {return v});
  1132. };
  1133. Map.prototype.remove = function(k) {
  1134. return updateMap(this, k, NOT_SET);
  1135. };
  1136. Map.prototype.deleteIn = function(keyPath) {
  1137. return this.updateIn(keyPath, function() {return NOT_SET});
  1138. };
  1139. Map.prototype.update = function(k, notSetValue, updater) {
  1140. return arguments.length === 1 ?
  1141. k(this) :
  1142. this.updateIn([k], notSetValue, updater);
  1143. };
  1144. Map.prototype.updateIn = function(keyPath, notSetValue, updater) {
  1145. if (!updater) {
  1146. updater = notSetValue;
  1147. notSetValue = undefined;
  1148. }
  1149. var updatedValue = updateInDeepMap(
  1150. this,
  1151. forceIterator(keyPath),
  1152. notSetValue,
  1153. updater
  1154. );
  1155. return updatedValue === NOT_SET ? undefined : updatedValue;
  1156. };
  1157. Map.prototype.clear = function() {
  1158. if (this.size === 0) {
  1159. return this;
  1160. }
  1161. if (this.__ownerID) {
  1162. this.size = 0;
  1163. this._root = null;
  1164. this.__hash = undefined;
  1165. this.__altered = true;
  1166. return this;
  1167. }
  1168. return emptyMap();
  1169. };
  1170. // @pragma Composition
  1171. Map.prototype.merge = function(/*...iters*/) {
  1172. return mergeIntoMapWith(this, undefined, arguments);
  1173. };
  1174. Map.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  1175. return mergeIntoMapWith(this, merger, iters);
  1176. };
  1177. Map.prototype.mergeIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1);
  1178. return this.updateIn(
  1179. keyPath,
  1180. emptyMap(),
  1181. function(m ) {return typeof m.merge === 'function' ?
  1182. m.merge.apply(m, iters) :
  1183. iters[iters.length - 1]}
  1184. );
  1185. };
  1186. Map.prototype.mergeDeep = function(/*...iters*/) {
  1187. return mergeIntoMapWith(this, deepMerger, arguments);
  1188. };
  1189. Map.prototype.mergeDeepWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  1190. return mergeIntoMapWith(this, deepMergerWith(merger), iters);
  1191. };
  1192. Map.prototype.mergeDeepIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1);
  1193. return this.updateIn(
  1194. keyPath,
  1195. emptyMap(),
  1196. function(m ) {return typeof m.mergeDeep === 'function' ?
  1197. m.mergeDeep.apply(m, iters) :
  1198. iters[iters.length - 1]}
  1199. );
  1200. };
  1201. Map.prototype.sort = function(comparator) {
  1202. // Late binding
  1203. return OrderedMap(sortFactory(this, comparator));
  1204. };
  1205. Map.prototype.sortBy = function(mapper, comparator) {
  1206. // Late binding
  1207. return OrderedMap(sortFactory(this, comparator, mapper));
  1208. };
  1209. // @pragma Mutability
  1210. Map.prototype.withMutations = function(fn) {
  1211. var mutable = this.asMutable();
  1212. fn(mutable);
  1213. return mutable.wasAltered() ? mutable.__ensureOwner(this.__ownerID) : this;
  1214. };
  1215. Map.prototype.asMutable = function() {
  1216. return this.__ownerID ? this : this.__ensureOwner(new OwnerID());
  1217. };
  1218. Map.prototype.asImmutable = function() {
  1219. return this.__ensureOwner();
  1220. };
  1221. Map.prototype.wasAltered = function() {
  1222. return this.__altered;
  1223. };
  1224. Map.prototype.__iterator = function(type, reverse) {
  1225. return new MapIterator(this, type, reverse);
  1226. };
  1227. Map.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  1228. var iterations = 0;
  1229. this._root && this._root.iterate(function(entry ) {
  1230. iterations++;
  1231. return fn(entry[1], entry[0], this$0);
  1232. }, reverse);
  1233. return iterations;
  1234. };
  1235. Map.prototype.__ensureOwner = function(ownerID) {
  1236. if (ownerID === this.__ownerID) {
  1237. return this;
  1238. }
  1239. if (!ownerID) {
  1240. this.__ownerID = ownerID;
  1241. this.__altered = false;
  1242. return this;
  1243. }
  1244. return makeMap(this.size, this._root, ownerID, this.__hash);
  1245. };
  1246. function isMap(maybeMap) {
  1247. return !!(maybeMap && maybeMap[IS_MAP_SENTINEL]);
  1248. }
  1249. Map.isMap = isMap;
  1250. var IS_MAP_SENTINEL = '@@__IMMUTABLE_MAP__@@';
  1251. var MapPrototype = Map.prototype;
  1252. MapPrototype[IS_MAP_SENTINEL] = true;
  1253. MapPrototype[DELETE] = MapPrototype.remove;
  1254. MapPrototype.removeIn = MapPrototype.deleteIn;
  1255. // #pragma Trie Nodes
  1256. function ArrayMapNode(ownerID, entries) {
  1257. this.ownerID = ownerID;
  1258. this.entries = entries;
  1259. }
  1260. ArrayMapNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  1261. var entries = this.entries;
  1262. for (var ii = 0, len = entries.length; ii < len; ii++) {
  1263. if (is(key, entries[ii][0])) {
  1264. return entries[ii][1];
  1265. }
  1266. }
  1267. return notSetValue;
  1268. };
  1269. ArrayMapNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  1270. var removed = value === NOT_SET;
  1271. var entries = this.entries;
  1272. var idx = 0;
  1273. for (var len = entries.length; idx < len; idx++) {
  1274. if (is(key, entries[idx][0])) {
  1275. break;
  1276. }
  1277. }
  1278. var exists = idx < len;
  1279. if (exists ? entries[idx][1] === value : removed) {
  1280. return this;
  1281. }
  1282. SetRef(didAlter);
  1283. (removed || !exists) && SetRef(didChangeSize);
  1284. if (removed && entries.length === 1) {
  1285. return; // undefined
  1286. }
  1287. if (!exists && !removed && entries.length >= MAX_ARRAY_MAP_SIZE) {
  1288. return createNodes(ownerID, entries, key, value);
  1289. }
  1290. var isEditable = ownerID && ownerID === this.ownerID;
  1291. var newEntries = isEditable ? entries : arrCopy(entries);
  1292. if (exists) {
  1293. if (removed) {
  1294. idx === len - 1 ? newEntries.pop() : (newEntries[idx] = newEntries.pop());
  1295. } else {
  1296. newEntries[idx] = [key, value];
  1297. }
  1298. } else {
  1299. newEntries.push([key, value]);
  1300. }
  1301. if (isEditable) {
  1302. this.entries = newEntries;
  1303. return this;
  1304. }
  1305. return new ArrayMapNode(ownerID, newEntries);
  1306. };
  1307. function BitmapIndexedNode(ownerID, bitmap, nodes) {
  1308. this.ownerID = ownerID;
  1309. this.bitmap = bitmap;
  1310. this.nodes = nodes;
  1311. }
  1312. BitmapIndexedNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  1313. if (keyHash === undefined) {
  1314. keyHash = hash(key);
  1315. }
  1316. var bit = (1 << ((shift === 0 ? keyHash : keyHash >>> shift) & MASK));
  1317. var bitmap = this.bitmap;
  1318. return (bitmap & bit) === 0 ? notSetValue :
  1319. this.nodes[popCount(bitmap & (bit - 1))].get(shift + SHIFT, keyHash, key, notSetValue);
  1320. };
  1321. BitmapIndexedNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  1322. if (keyHash === undefined) {
  1323. keyHash = hash(key);
  1324. }
  1325. var keyHashFrag = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  1326. var bit = 1 << keyHashFrag;
  1327. var bitmap = this.bitmap;
  1328. var exists = (bitmap & bit) !== 0;
  1329. if (!exists && value === NOT_SET) {
  1330. return this;
  1331. }
  1332. var idx = popCount(bitmap & (bit - 1));
  1333. var nodes = this.nodes;
  1334. var node = exists ? nodes[idx] : undefined;
  1335. var newNode = updateNode(node, ownerID, shift + SHIFT, keyHash, key, value, didChangeSize, didAlter);
  1336. if (newNode === node) {
  1337. return this;
  1338. }
  1339. if (!exists && newNode && nodes.length >= MAX_BITMAP_INDEXED_SIZE) {
  1340. return expandNodes(ownerID, nodes, bitmap, keyHashFrag, newNode);
  1341. }
  1342. if (exists && !newNode && nodes.length === 2 && isLeafNode(nodes[idx ^ 1])) {
  1343. return nodes[idx ^ 1];
  1344. }
  1345. if (exists && newNode && nodes.length === 1 && isLeafNode(newNode)) {
  1346. return newNode;
  1347. }
  1348. var isEditable = ownerID && ownerID === this.ownerID;
  1349. var newBitmap = exists ? newNode ? bitmap : bitmap ^ bit : bitmap | bit;
  1350. var newNodes = exists ? newNode ?
  1351. setIn(nodes, idx, newNode, isEditable) :
  1352. spliceOut(nodes, idx, isEditable) :
  1353. spliceIn(nodes, idx, newNode, isEditable);
  1354. if (isEditable) {
  1355. this.bitmap = newBitmap;
  1356. this.nodes = newNodes;
  1357. return this;
  1358. }
  1359. return new BitmapIndexedNode(ownerID, newBitmap, newNodes);
  1360. };
  1361. function HashArrayMapNode(ownerID, count, nodes) {
  1362. this.ownerID = ownerID;
  1363. this.count = count;
  1364. this.nodes = nodes;
  1365. }
  1366. HashArrayMapNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  1367. if (keyHash === undefined) {
  1368. keyHash = hash(key);
  1369. }
  1370. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  1371. var node = this.nodes[idx];
  1372. return node ? node.get(shift + SHIFT, keyHash, key, notSetValue) : notSetValue;
  1373. };
  1374. HashArrayMapNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  1375. if (keyHash === undefined) {
  1376. keyHash = hash(key);
  1377. }
  1378. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  1379. var removed = value === NOT_SET;
  1380. var nodes = this.nodes;
  1381. var node = nodes[idx];
  1382. if (removed && !node) {
  1383. return this;
  1384. }
  1385. var newNode = updateNode(node, ownerID, shift + SHIFT, keyHash, key, value, didChangeSize, didAlter);
  1386. if (newNode === node) {
  1387. return this;
  1388. }
  1389. var newCount = this.count;
  1390. if (!node) {
  1391. newCount++;
  1392. } else if (!newNode) {
  1393. newCount--;
  1394. if (newCount < MIN_HASH_ARRAY_MAP_SIZE) {
  1395. return packNodes(ownerID, nodes, newCount, idx);
  1396. }
  1397. }
  1398. var isEditable = ownerID && ownerID === this.ownerID;
  1399. var newNodes = setIn(nodes, idx, newNode, isEditable);
  1400. if (isEditable) {
  1401. this.count = newCount;
  1402. this.nodes = newNodes;
  1403. return this;
  1404. }
  1405. return new HashArrayMapNode(ownerID, newCount, newNodes);
  1406. };
  1407. function HashCollisionNode(ownerID, keyHash, entries) {
  1408. this.ownerID = ownerID;
  1409. this.keyHash = keyHash;
  1410. this.entries = entries;
  1411. }
  1412. HashCollisionNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  1413. var entries = this.entries;
  1414. for (var ii = 0, len = entries.length; ii < len; ii++) {
  1415. if (is(key, entries[ii][0])) {
  1416. return entries[ii][1];
  1417. }
  1418. }
  1419. return notSetValue;
  1420. };
  1421. HashCollisionNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  1422. if (keyHash === undefined) {
  1423. keyHash = hash(key);
  1424. }
  1425. var removed = value === NOT_SET;
  1426. if (keyHash !== this.keyHash) {
  1427. if (removed) {
  1428. return this;
  1429. }
  1430. SetRef(didAlter);
  1431. SetRef(didChangeSize);
  1432. return mergeIntoNode(this, ownerID, shift, keyHash, [key, value]);
  1433. }
  1434. var entries = this.entries;
  1435. var idx = 0;
  1436. for (var len = entries.length; idx < len; idx++) {
  1437. if (is(key, entries[idx][0])) {
  1438. break;
  1439. }
  1440. }
  1441. var exists = idx < len;
  1442. if (exists ? entries[idx][1] === value : removed) {
  1443. return this;
  1444. }
  1445. SetRef(didAlter);
  1446. (removed || !exists) && SetRef(didChangeSize);
  1447. if (removed && len === 2) {
  1448. return new ValueNode(ownerID, this.keyHash, entries[idx ^ 1]);
  1449. }
  1450. var isEditable = ownerID && ownerID === this.ownerID;
  1451. var newEntries = isEditable ? entries : arrCopy(entries);
  1452. if (exists) {
  1453. if (removed) {
  1454. idx === len - 1 ? newEntries.pop() : (newEntries[idx] = newEntries.pop());
  1455. } else {
  1456. newEntries[idx] = [key, value];
  1457. }
  1458. } else {
  1459. newEntries.push([key, value]);
  1460. }
  1461. if (isEditable) {
  1462. this.entries = newEntries;
  1463. return this;
  1464. }
  1465. return new HashCollisionNode(ownerID, this.keyHash, newEntries);
  1466. };
  1467. function ValueNode(ownerID, keyHash, entry) {
  1468. this.ownerID = ownerID;
  1469. this.keyHash = keyHash;
  1470. this.entry = entry;
  1471. }
  1472. ValueNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  1473. return is(key, this.entry[0]) ? this.entry[1] : notSetValue;
  1474. };
  1475. ValueNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  1476. var removed = value === NOT_SET;
  1477. var keyMatch = is(key, this.entry[0]);
  1478. if (keyMatch ? value === this.entry[1] : removed) {
  1479. return this;
  1480. }
  1481. SetRef(didAlter);
  1482. if (removed) {
  1483. SetRef(didChangeSize);
  1484. return; // undefined
  1485. }
  1486. if (keyMatch) {
  1487. if (ownerID && ownerID === this.ownerID) {
  1488. this.entry[1] = value;
  1489. return this;
  1490. }
  1491. return new ValueNode(ownerID, this.keyHash, [key, value]);
  1492. }
  1493. SetRef(didChangeSize);
  1494. return mergeIntoNode(this, ownerID, shift, hash(key), [key, value]);
  1495. };
  1496. // #pragma Iterators
  1497. ArrayMapNode.prototype.iterate =
  1498. HashCollisionNode.prototype.iterate = function (fn, reverse) {
  1499. var entries = this.entries;
  1500. for (var ii = 0, maxIndex = entries.length - 1; ii <= maxIndex; ii++) {
  1501. if (fn(entries[reverse ? maxIndex - ii : ii]) === false) {
  1502. return false;
  1503. }
  1504. }
  1505. };
  1506. BitmapIndexedNode.prototype.iterate =
  1507. HashArrayMapNode.prototype.iterate = function (fn, reverse) {
  1508. var nodes = this.nodes;
  1509. for (var ii = 0, maxIndex = nodes.length - 1; ii <= maxIndex; ii++) {
  1510. var node = nodes[reverse ? maxIndex - ii : ii];
  1511. if (node && node.iterate(fn, reverse) === false) {
  1512. return false;
  1513. }
  1514. }
  1515. };
  1516. ValueNode.prototype.iterate = function (fn, reverse) {
  1517. return fn(this.entry);
  1518. };
  1519. createClass(MapIterator, Iterator);
  1520. function MapIterator(map, type, reverse) {
  1521. this._type = type;
  1522. this._reverse = reverse;
  1523. this._stack = map._root && mapIteratorFrame(map._root);
  1524. }
  1525. MapIterator.prototype.next = function() {
  1526. var type = this._type;
  1527. var stack = this._stack;
  1528. while (stack) {
  1529. var node = stack.node;
  1530. var index = stack.index++;
  1531. var maxIndex;
  1532. if (node.entry) {
  1533. if (index === 0) {
  1534. return mapIteratorValue(type, node.entry);
  1535. }
  1536. } else if (node.entries) {
  1537. maxIndex = node.entries.length - 1;
  1538. if (index <= maxIndex) {
  1539. return mapIteratorValue(type, node.entries[this._reverse ? maxIndex - index : index]);
  1540. }
  1541. } else {
  1542. maxIndex = node.nodes.length - 1;
  1543. if (index <= maxIndex) {
  1544. var subNode = node.nodes[this._reverse ? maxIndex - index : index];
  1545. if (subNode) {
  1546. if (subNode.entry) {
  1547. return mapIteratorValue(type, subNode.entry);
  1548. }
  1549. stack = this._stack = mapIteratorFrame(subNode, stack);
  1550. }
  1551. continue;
  1552. }
  1553. }
  1554. stack = this._stack = this._stack.__prev;
  1555. }
  1556. return iteratorDone();
  1557. };
  1558. function mapIteratorValue(type, entry) {
  1559. return iteratorValue(type, entry[0], entry[1]);
  1560. }
  1561. function mapIteratorFrame(node, prev) {
  1562. return {
  1563. node: node,
  1564. index: 0,
  1565. __prev: prev
  1566. };
  1567. }
  1568. function makeMap(size, root, ownerID, hash) {
  1569. var map = Object.create(MapPrototype);
  1570. map.size = size;
  1571. map._root = root;
  1572. map.__ownerID = ownerID;
  1573. map.__hash = hash;
  1574. map.__altered = false;
  1575. return map;
  1576. }
  1577. var EMPTY_MAP;
  1578. function emptyMap() {
  1579. return EMPTY_MAP || (EMPTY_MAP = makeMap(0));
  1580. }
  1581. function updateMap(map, k, v) {
  1582. var newRoot;
  1583. var newSize;
  1584. if (!map._root) {
  1585. if (v === NOT_SET) {
  1586. return map;
  1587. }
  1588. newSize = 1;
  1589. newRoot = new ArrayMapNode(map.__ownerID, [[k, v]]);
  1590. } else {
  1591. var didChangeSize = MakeRef(CHANGE_LENGTH);
  1592. var didAlter = MakeRef(DID_ALTER);
  1593. newRoot = updateNode(map._root, map.__ownerID, 0, undefined, k, v, didChangeSize, didAlter);
  1594. if (!didAlter.value) {
  1595. return map;
  1596. }
  1597. newSize = map.size + (didChangeSize.value ? v === NOT_SET ? -1 : 1 : 0);
  1598. }
  1599. if (map.__ownerID) {
  1600. map.size = newSize;
  1601. map._root = newRoot;
  1602. map.__hash = undefined;
  1603. map.__altered = true;
  1604. return map;
  1605. }
  1606. return newRoot ? makeMap(newSize, newRoot) : emptyMap();
  1607. }
  1608. function updateNode(node, ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  1609. if (!node) {
  1610. if (value === NOT_SET) {
  1611. return node;
  1612. }
  1613. SetRef(didAlter);
  1614. SetRef(didChangeSize);
  1615. return new ValueNode(ownerID, keyHash, [key, value]);
  1616. }
  1617. return node.update(ownerID, shift, keyHash, key, value, didChangeSize, didAlter);
  1618. }
  1619. function isLeafNode(node) {
  1620. return node.constructor === ValueNode || node.constructor === HashCollisionNode;
  1621. }
  1622. function mergeIntoNode(node, ownerID, shift, keyHash, entry) {
  1623. if (node.keyHash === keyHash) {
  1624. return new HashCollisionNode(ownerID, keyHash, [node.entry, entry]);
  1625. }
  1626. var idx1 = (shift === 0 ? node.keyHash : node.keyHash >>> shift) & MASK;
  1627. var idx2 = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  1628. var newNode;
  1629. var nodes = idx1 === idx2 ?
  1630. [mergeIntoNode(node, ownerID, shift + SHIFT, keyHash, entry)] :
  1631. ((newNode = new ValueNode(ownerID, keyHash, entry)), idx1 < idx2 ? [node, newNode] : [newNode, node]);
  1632. return new BitmapIndexedNode(ownerID, (1 << idx1) | (1 << idx2), nodes);
  1633. }
  1634. function createNodes(ownerID, entries, key, value) {
  1635. if (!ownerID) {
  1636. ownerID = new OwnerID();
  1637. }
  1638. var node = new ValueNode(ownerID, hash(key), [key, value]);
  1639. for (var ii = 0; ii < entries.length; ii++) {
  1640. var entry = entries[ii];
  1641. node = node.update(ownerID, 0, undefined, entry[0], entry[1]);
  1642. }
  1643. return node;
  1644. }
  1645. function packNodes(ownerID, nodes, count, excluding) {
  1646. var bitmap = 0;
  1647. var packedII = 0;
  1648. var packedNodes = new Array(count);
  1649. for (var ii = 0, bit = 1, len = nodes.length; ii < len; ii++, bit <<= 1) {
  1650. var node = nodes[ii];
  1651. if (node !== undefined && ii !== excluding) {
  1652. bitmap |= bit;
  1653. packedNodes[packedII++] = node;
  1654. }
  1655. }
  1656. return new BitmapIndexedNode(ownerID, bitmap, packedNodes);
  1657. }
  1658. function expandNodes(ownerID, nodes, bitmap, including, node) {
  1659. var count = 0;
  1660. var expandedNodes = new Array(SIZE);
  1661. for (var ii = 0; bitmap !== 0; ii++, bitmap >>>= 1) {
  1662. expandedNodes[ii] = bitmap & 1 ? nodes[count++] : undefined;
  1663. }
  1664. expandedNodes[including] = node;
  1665. return new HashArrayMapNode(ownerID, count + 1, expandedNodes);
  1666. }
  1667. function mergeIntoMapWith(map, merger, iterables) {
  1668. var iters = [];
  1669. for (var ii = 0; ii < iterables.length; ii++) {
  1670. var value = iterables[ii];
  1671. var iter = KeyedIterable(value);
  1672. if (!isIterable(value)) {
  1673. iter = iter.map(function(v ) {return fromJS(v)});
  1674. }
  1675. iters.push(iter);
  1676. }
  1677. return mergeIntoCollectionWith(map, merger, iters);
  1678. }
  1679. function deepMerger(existing, value, key) {
  1680. return existing && existing.mergeDeep && isIterable(value) ?
  1681. existing.mergeDeep(value) :
  1682. is(existing, value) ? existing : value;
  1683. }
  1684. function deepMergerWith(merger) {
  1685. return function(existing, value, key) {
  1686. if (existing && existing.mergeDeepWith && isIterable(value)) {
  1687. return existing.mergeDeepWith(merger, value);
  1688. }
  1689. var nextValue = merger(existing, value, key);
  1690. return is(existing, nextValue) ? existing : nextValue;
  1691. };
  1692. }
  1693. function mergeIntoCollectionWith(collection, merger, iters) {
  1694. iters = iters.filter(function(x ) {return x.size !== 0});
  1695. if (iters.length === 0) {
  1696. return collection;
  1697. }
  1698. if (collection.size === 0 && !collection.__ownerID && iters.length === 1) {
  1699. return collection.constructor(iters[0]);
  1700. }
  1701. return collection.withMutations(function(collection ) {
  1702. var mergeIntoMap = merger ?
  1703. function(value, key) {
  1704. collection.update(key, NOT_SET, function(existing )
  1705. {return existing === NOT_SET ? value : merger(existing, value, key)}
  1706. );
  1707. } :
  1708. function(value, key) {
  1709. collection.set(key, value);
  1710. };
  1711. for (var ii = 0; ii < iters.length; ii++) {
  1712. iters[ii].forEach(mergeIntoMap);
  1713. }
  1714. });
  1715. }
  1716. function updateInDeepMap(existing, keyPathIter, notSetValue, updater) {
  1717. var isNotSet = existing === NOT_SET;
  1718. var step = keyPathIter.next();
  1719. if (step.done) {
  1720. var existingValue = isNotSet ? notSetValue : existing;
  1721. var newValue = updater(existingValue);
  1722. return newValue === existingValue ? existing : newValue;
  1723. }
  1724. invariant(
  1725. isNotSet || (existing && existing.set),
  1726. 'invalid keyPath'
  1727. );
  1728. var key = step.value;
  1729. var nextExisting = isNotSet ? NOT_SET : existing.get(key, NOT_SET);
  1730. var nextUpdated = updateInDeepMap(
  1731. nextExisting,
  1732. keyPathIter,
  1733. notSetValue,
  1734. updater
  1735. );
  1736. return nextUpdated === nextExisting ? existing :
  1737. nextUpdated === NOT_SET ? existing.remove(key) :
  1738. (isNotSet ? emptyMap() : existing).set(key, nextUpdated);
  1739. }
  1740. function popCount(x) {
  1741. x = x - ((x >> 1) & 0x55555555);
  1742. x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
  1743. x = (x + (x >> 4)) & 0x0f0f0f0f;
  1744. x = x + (x >> 8);
  1745. x = x + (x >> 16);
  1746. return x & 0x7f;
  1747. }
  1748. function setIn(array, idx, val, canEdit) {
  1749. var newArray = canEdit ? array : arrCopy(array);
  1750. newArray[idx] = val;
  1751. return newArray;
  1752. }
  1753. function spliceIn(array, idx, val, canEdit) {
  1754. var newLen = array.length + 1;
  1755. if (canEdit && idx + 1 === newLen) {
  1756. array[idx] = val;
  1757. return array;
  1758. }
  1759. var newArray = new Array(newLen);
  1760. var after = 0;
  1761. for (var ii = 0; ii < newLen; ii++) {
  1762. if (ii === idx) {
  1763. newArray[ii] = val;
  1764. after = -1;
  1765. } else {
  1766. newArray[ii] = array[ii + after];
  1767. }
  1768. }
  1769. return newArray;
  1770. }
  1771. function spliceOut(array, idx, canEdit) {
  1772. var newLen = array.length - 1;
  1773. if (canEdit && idx === newLen) {
  1774. array.pop();
  1775. return array;
  1776. }
  1777. var newArray = new Array(newLen);
  1778. var after = 0;
  1779. for (var ii = 0; ii < newLen; ii++) {
  1780. if (ii === idx) {
  1781. after = 1;
  1782. }
  1783. newArray[ii] = array[ii + after];
  1784. }
  1785. return newArray;
  1786. }
  1787. var MAX_ARRAY_MAP_SIZE = SIZE / 4;
  1788. var MAX_BITMAP_INDEXED_SIZE = SIZE / 2;
  1789. var MIN_HASH_ARRAY_MAP_SIZE = SIZE / 4;
  1790. createClass(List, IndexedCollection);
  1791. // @pragma Construction
  1792. function List(value) {
  1793. var empty = emptyList();
  1794. if (value === null || value === undefined) {
  1795. return empty;
  1796. }
  1797. if (isList(value)) {
  1798. return value;
  1799. }
  1800. var iter = IndexedIterable(value);
  1801. var size = iter.size;
  1802. if (size === 0) {
  1803. return empty;
  1804. }
  1805. assertNotInfinite(size);
  1806. if (size > 0 && size < SIZE) {
  1807. return makeList(0, size, SHIFT, null, new VNode(iter.toArray()));
  1808. }
  1809. return empty.withMutations(function(list ) {
  1810. list.setSize(size);
  1811. iter.forEach(function(v, i) {return list.set(i, v)});
  1812. });
  1813. }
  1814. List.of = function(/*...values*/) {
  1815. return this(arguments);
  1816. };
  1817. List.prototype.toString = function() {
  1818. return this.__toString('List [', ']');
  1819. };
  1820. // @pragma Access
  1821. List.prototype.get = function(index, notSetValue) {
  1822. index = wrapIndex(this, index);
  1823. if (index >= 0 && index < this.size) {
  1824. index += this._origin;
  1825. var node = listNodeFor(this, index);
  1826. return node && node.array[index & MASK];
  1827. }
  1828. return notSetValue;
  1829. };
  1830. // @pragma Modification
  1831. List.prototype.set = function(index, value) {
  1832. return updateList(this, index, value);
  1833. };
  1834. List.prototype.remove = function(index) {
  1835. return !this.has(index) ? this :
  1836. index === 0 ? this.shift() :
  1837. index === this.size - 1 ? this.pop() :
  1838. this.splice(index, 1);
  1839. };
  1840. List.prototype.insert = function(index, value) {
  1841. return this.splice(index, 0, value);
  1842. };
  1843. List.prototype.clear = function() {
  1844. if (this.size === 0) {
  1845. return this;
  1846. }
  1847. if (this.__ownerID) {
  1848. this.size = this._origin = this._capacity = 0;
  1849. this._level = SHIFT;
  1850. this._root = this._tail = null;
  1851. this.__hash = undefined;
  1852. this.__altered = true;
  1853. return this;
  1854. }
  1855. return emptyList();
  1856. };
  1857. List.prototype.push = function(/*...values*/) {
  1858. var values = arguments;
  1859. var oldSize = this.size;
  1860. return this.withMutations(function(list ) {
  1861. setListBounds(list, 0, oldSize + values.length);
  1862. for (var ii = 0; ii < values.length; ii++) {
  1863. list.set(oldSize + ii, values[ii]);
  1864. }
  1865. });
  1866. };
  1867. List.prototype.pop = function() {
  1868. return setListBounds(this, 0, -1);
  1869. };
  1870. List.prototype.unshift = function(/*...values*/) {
  1871. var values = arguments;
  1872. return this.withMutations(function(list ) {
  1873. setListBounds(list, -values.length);
  1874. for (var ii = 0; ii < values.length; ii++) {
  1875. list.set(ii, values[ii]);
  1876. }
  1877. });
  1878. };
  1879. List.prototype.shift = function() {
  1880. return setListBounds(this, 1);
  1881. };
  1882. // @pragma Composition
  1883. List.prototype.merge = function(/*...iters*/) {
  1884. return mergeIntoListWith(this, undefined, arguments);
  1885. };
  1886. List.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  1887. return mergeIntoListWith(this, merger, iters);
  1888. };
  1889. List.prototype.mergeDeep = function(/*...iters*/) {
  1890. return mergeIntoListWith(this, deepMerger, arguments);
  1891. };
  1892. List.prototype.mergeDeepWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  1893. return mergeIntoListWith(this, deepMergerWith(merger), iters);
  1894. };
  1895. List.prototype.setSize = function(size) {
  1896. return setListBounds(this, 0, size);
  1897. };
  1898. // @pragma Iteration
  1899. List.prototype.slice = function(begin, end) {
  1900. var size = this.size;
  1901. if (wholeSlice(begin, end, size)) {
  1902. return this;
  1903. }
  1904. return setListBounds(
  1905. this,
  1906. resolveBegin(begin, size),
  1907. resolveEnd(end, size)
  1908. );
  1909. };
  1910. List.prototype.__iterator = function(type, reverse) {
  1911. var index = 0;
  1912. var values = iterateList(this, reverse);
  1913. return new Iterator(function() {
  1914. var value = values();
  1915. return value === DONE ?
  1916. iteratorDone() :
  1917. iteratorValue(type, index++, value);
  1918. });
  1919. };
  1920. List.prototype.__iterate = function(fn, reverse) {
  1921. var index = 0;
  1922. var values = iterateList(this, reverse);
  1923. var value;
  1924. while ((value = values()) !== DONE) {
  1925. if (fn(value, index++, this) === false) {
  1926. break;
  1927. }
  1928. }
  1929. return index;
  1930. };
  1931. List.prototype.__ensureOwner = function(ownerID) {
  1932. if (ownerID === this.__ownerID) {
  1933. return this;
  1934. }
  1935. if (!ownerID) {
  1936. this.__ownerID = ownerID;
  1937. return this;
  1938. }
  1939. return makeList(this._origin, this._capacity, this._level, this._root, this._tail, ownerID, this.__hash);
  1940. };
  1941. function isList(maybeList) {
  1942. return !!(maybeList && maybeList[IS_LIST_SENTINEL]);
  1943. }
  1944. List.isList = isList;
  1945. var IS_LIST_SENTINEL = '@@__IMMUTABLE_LIST__@@';
  1946. var ListPrototype = List.prototype;
  1947. ListPrototype[IS_LIST_SENTINEL] = true;
  1948. ListPrototype[DELETE] = ListPrototype.remove;
  1949. ListPrototype.setIn = MapPrototype.setIn;
  1950. ListPrototype.deleteIn =
  1951. ListPrototype.removeIn = MapPrototype.removeIn;
  1952. ListPrototype.update = MapPrototype.update;
  1953. ListPrototype.updateIn = MapPrototype.updateIn;
  1954. ListPrototype.mergeIn = MapPrototype.mergeIn;
  1955. ListPrototype.mergeDeepIn = MapPrototype.mergeDeepIn;
  1956. ListPrototype.withMutations = MapPrototype.withMutations;
  1957. ListPrototype.asMutable = MapPrototype.asMutable;
  1958. ListPrototype.asImmutable = MapPrototype.asImmutable;
  1959. ListPrototype.wasAltered = MapPrototype.wasAltered;
  1960. function VNode(array, ownerID) {
  1961. this.array = array;
  1962. this.ownerID = ownerID;
  1963. }
  1964. // TODO: seems like these methods are very similar
  1965. VNode.prototype.removeBefore = function(ownerID, level, index) {
  1966. if (index === level ? 1 << level : this.array.length === 0) {
  1967. return this;
  1968. }
  1969. var originIndex = (index >>> level) & MASK;
  1970. if (originIndex >= this.array.length) {
  1971. return new VNode([], ownerID);
  1972. }
  1973. var removingFirst = originIndex === 0;
  1974. var newChild;
  1975. if (level > 0) {
  1976. var oldChild = this.array[originIndex];
  1977. newChild = oldChild && oldChild.removeBefore(ownerID, level - SHIFT, index);
  1978. if (newChild === oldChild && removingFirst) {
  1979. return this;
  1980. }
  1981. }
  1982. if (removingFirst && !newChild) {
  1983. return this;
  1984. }
  1985. var editable = editableVNode(this, ownerID);
  1986. if (!removingFirst) {
  1987. for (var ii = 0; ii < originIndex; ii++) {
  1988. editable.array[ii] = undefined;
  1989. }
  1990. }
  1991. if (newChild) {
  1992. editable.array[originIndex] = newChild;
  1993. }
  1994. return editable;
  1995. };
  1996. VNode.prototype.removeAfter = function(ownerID, level, index) {
  1997. if (index === (level ? 1 << level : 0) || this.array.length === 0) {
  1998. return this;
  1999. }
  2000. var sizeIndex = ((index - 1) >>> level) & MASK;
  2001. if (sizeIndex >= this.array.length) {
  2002. return this;
  2003. }
  2004. var newChild;
  2005. if (level > 0) {
  2006. var oldChild = this.array[sizeIndex];
  2007. newChild = oldChild && oldChild.removeAfter(ownerID, level - SHIFT, index);
  2008. if (newChild === oldChild && sizeIndex === this.array.length - 1) {
  2009. return this;
  2010. }
  2011. }
  2012. var editable = editableVNode(this, ownerID);
  2013. editable.array.splice(sizeIndex + 1);
  2014. if (newChild) {
  2015. editable.array[sizeIndex] = newChild;
  2016. }
  2017. return editable;
  2018. };
  2019. var DONE = {};
  2020. function iterateList(list, reverse) {
  2021. var left = list._origin;
  2022. var right = list._capacity;
  2023. var tailPos = getTailOffset(right);
  2024. var tail = list._tail;
  2025. return iterateNodeOrLeaf(list._root, list._level, 0);
  2026. function iterateNodeOrLeaf(node, level, offset) {
  2027. return level === 0 ?
  2028. iterateLeaf(node, offset) :
  2029. iterateNode(node, level, offset);
  2030. }
  2031. function iterateLeaf(node, offset) {
  2032. var array = offset === tailPos ? tail && tail.array : node && node.array;
  2033. var from = offset > left ? 0 : left - offset;
  2034. var to = right - offset;
  2035. if (to > SIZE) {
  2036. to = SIZE;
  2037. }
  2038. return function() {
  2039. if (from === to) {
  2040. return DONE;
  2041. }
  2042. var idx = reverse ? --to : from++;
  2043. return array && array[idx];
  2044. };
  2045. }
  2046. function iterateNode(node, level, offset) {
  2047. var values;
  2048. var array = node && node.array;
  2049. var from = offset > left ? 0 : (left - offset) >> level;
  2050. var to = ((right - offset) >> level) + 1;
  2051. if (to > SIZE) {
  2052. to = SIZE;
  2053. }
  2054. return function() {
  2055. do {
  2056. if (values) {
  2057. var value = values();
  2058. if (value !== DONE) {
  2059. return value;
  2060. }
  2061. values = null;
  2062. }
  2063. if (from === to) {
  2064. return DONE;
  2065. }
  2066. var idx = reverse ? --to : from++;
  2067. values = iterateNodeOrLeaf(
  2068. array && array[idx], level - SHIFT, offset + (idx << level)
  2069. );
  2070. } while (true);
  2071. };
  2072. }
  2073. }
  2074. function makeList(origin, capacity, level, root, tail, ownerID, hash) {
  2075. var list = Object.create(ListPrototype);
  2076. list.size = capacity - origin;
  2077. list._origin = origin;
  2078. list._capacity = capacity;
  2079. list._level = level;
  2080. list._root = root;
  2081. list._tail = tail;
  2082. list.__ownerID = ownerID;
  2083. list.__hash = hash;
  2084. list.__altered = false;
  2085. return list;
  2086. }
  2087. var EMPTY_LIST;
  2088. function emptyList() {
  2089. return EMPTY_LIST || (EMPTY_LIST = makeList(0, 0, SHIFT));
  2090. }
  2091. function updateList(list, index, value) {
  2092. index = wrapIndex(list, index);
  2093. if (index !== index) {
  2094. return list;
  2095. }
  2096. if (index >= list.size || index < 0) {
  2097. return list.withMutations(function(list ) {
  2098. index < 0 ?
  2099. setListBounds(list, index).set(0, value) :
  2100. setListBounds(list, 0, index + 1).set(index, value);
  2101. });
  2102. }
  2103. index += list._origin;
  2104. var newTail = list._tail;
  2105. var newRoot = list._root;
  2106. var didAlter = MakeRef(DID_ALTER);
  2107. if (index >= getTailOffset(list._capacity)) {
  2108. newTail = updateVNode(newTail, list.__ownerID, 0, index, value, didAlter);
  2109. } else {
  2110. newRoot = updateVNode(newRoot, list.__ownerID, list._level, index, value, didAlter);
  2111. }
  2112. if (!didAlter.value) {
  2113. return list;
  2114. }
  2115. if (list.__ownerID) {
  2116. list._root = newRoot;
  2117. list._tail = newTail;
  2118. list.__hash = undefined;
  2119. list.__altered = true;
  2120. return list;
  2121. }
  2122. return makeList(list._origin, list._capacity, list._level, newRoot, newTail);
  2123. }
  2124. function updateVNode(node, ownerID, level, index, value, didAlter) {
  2125. var idx = (index >>> level) & MASK;
  2126. var nodeHas = node && idx < node.array.length;
  2127. if (!nodeHas && value === undefined) {
  2128. return node;
  2129. }
  2130. var newNode;
  2131. if (level > 0) {
  2132. var lowerNode = node && node.array[idx];
  2133. var newLowerNode = updateVNode(lowerNode, ownerID, level - SHIFT, index, value, didAlter);
  2134. if (newLowerNode === lowerNode) {
  2135. return node;
  2136. }
  2137. newNode = editableVNode(node, ownerID);
  2138. newNode.array[idx] = newLowerNode;
  2139. return newNode;
  2140. }
  2141. if (nodeHas && node.array[idx] === value) {
  2142. return node;
  2143. }
  2144. SetRef(didAlter);
  2145. newNode = editableVNode(node, ownerID);
  2146. if (value === undefined && idx === newNode.array.length - 1) {
  2147. newNode.array.pop();
  2148. } else {
  2149. newNode.array[idx] = value;
  2150. }
  2151. return newNode;
  2152. }
  2153. function editableVNode(node, ownerID) {
  2154. if (ownerID && node && ownerID === node.ownerID) {
  2155. return node;
  2156. }
  2157. return new VNode(node ? node.array.slice() : [], ownerID);
  2158. }
  2159. function listNodeFor(list, rawIndex) {
  2160. if (rawIndex >= getTailOffset(list._capacity)) {
  2161. return list._tail;
  2162. }
  2163. if (rawIndex < 1 << (list._level + SHIFT)) {
  2164. var node = list._root;
  2165. var level = list._level;
  2166. while (node && level > 0) {
  2167. node = node.array[(rawIndex >>> level) & MASK];
  2168. level -= SHIFT;
  2169. }
  2170. return node;
  2171. }
  2172. }
  2173. function setListBounds(list, begin, end) {
  2174. // Sanitize begin & end using this shorthand for ToInt32(argument)
  2175. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  2176. if (begin !== undefined) {
  2177. begin = begin | 0;
  2178. }
  2179. if (end !== undefined) {
  2180. end = end | 0;
  2181. }
  2182. var owner = list.__ownerID || new OwnerID();
  2183. var oldOrigin = list._origin;
  2184. var oldCapacity = list._capacity;
  2185. var newOrigin = oldOrigin + begin;
  2186. var newCapacity = end === undefined ? oldCapacity : end < 0 ? oldCapacity + end : oldOrigin + end;
  2187. if (newOrigin === oldOrigin && newCapacity === oldCapacity) {
  2188. return list;
  2189. }
  2190. // If it's going to end after it starts, it's empty.
  2191. if (newOrigin >= newCapacity) {
  2192. return list.clear();
  2193. }
  2194. var newLevel = list._level;
  2195. var newRoot = list._root;
  2196. // New origin might need creating a higher root.
  2197. var offsetShift = 0;
  2198. while (newOrigin + offsetShift < 0) {
  2199. newRoot = new VNode(newRoot && newRoot.array.length ? [undefined, newRoot] : [], owner);
  2200. newLevel += SHIFT;
  2201. offsetShift += 1 << newLevel;
  2202. }
  2203. if (offsetShift) {
  2204. newOrigin += offsetShift;
  2205. oldOrigin += offsetShift;
  2206. newCapacity += offsetShift;
  2207. oldCapacity += offsetShift;
  2208. }
  2209. var oldTailOffset = getTailOffset(oldCapacity);
  2210. var newTailOffset = getTailOffset(newCapacity);
  2211. // New size might need creating a higher root.
  2212. while (newTailOffset >= 1 << (newLevel + SHIFT)) {
  2213. newRoot = new VNode(newRoot && newRoot.array.length ? [newRoot] : [], owner);
  2214. newLevel += SHIFT;
  2215. }
  2216. // Locate or create the new tail.
  2217. var oldTail = list._tail;
  2218. var newTail = newTailOffset < oldTailOffset ?
  2219. listNodeFor(list, newCapacity - 1) :
  2220. newTailOffset > oldTailOffset ? new VNode([], owner) : oldTail;
  2221. // Merge Tail into tree.
  2222. if (oldTail && newTailOffset > oldTailOffset && newOrigin < oldCapacity && oldTail.array.length) {
  2223. newRoot = editableVNode(newRoot, owner);
  2224. var node = newRoot;
  2225. for (var level = newLevel; level > SHIFT; level -= SHIFT) {
  2226. var idx = (oldTailOffset >>> level) & MASK;
  2227. node = node.array[idx] = editableVNode(node.array[idx], owner);
  2228. }
  2229. node.array[(oldTailOffset >>> SHIFT) & MASK] = oldTail;
  2230. }
  2231. // If the size has been reduced, there's a chance the tail needs to be trimmed.
  2232. if (newCapacity < oldCapacity) {
  2233. newTail = newTail && newTail.removeAfter(owner, 0, newCapacity);
  2234. }
  2235. // If the new origin is within the tail, then we do not need a root.
  2236. if (newOrigin >= newTailOffset) {
  2237. newOrigin -= newTailOffset;
  2238. newCapacity -= newTailOffset;
  2239. newLevel = SHIFT;
  2240. newRoot = null;
  2241. newTail = newTail && newTail.removeBefore(owner, 0, newOrigin);
  2242. // Otherwise, if the root has been trimmed, garbage collect.
  2243. } else if (newOrigin > oldOrigin || newTailOffset < oldTailOffset) {
  2244. offsetShift = 0;
  2245. // Identify the new top root node of the subtree of the old root.
  2246. while (newRoot) {
  2247. var beginIndex = (newOrigin >>> newLevel) & MASK;
  2248. if (beginIndex !== (newTailOffset >>> newLevel) & MASK) {
  2249. break;
  2250. }
  2251. if (beginIndex) {
  2252. offsetShift += (1 << newLevel) * beginIndex;
  2253. }
  2254. newLevel -= SHIFT;
  2255. newRoot = newRoot.array[beginIndex];
  2256. }
  2257. // Trim the new sides of the new root.
  2258. if (newRoot && newOrigin > oldOrigin) {
  2259. newRoot = newRoot.removeBefore(owner, newLevel, newOrigin - offsetShift);
  2260. }
  2261. if (newRoot && newTailOffset < oldTailOffset) {
  2262. newRoot = newRoot.removeAfter(owner, newLevel, newTailOffset - offsetShift);
  2263. }
  2264. if (offsetShift) {
  2265. newOrigin -= offsetShift;
  2266. newCapacity -= offsetShift;
  2267. }
  2268. }
  2269. if (list.__ownerID) {
  2270. list.size = newCapacity - newOrigin;
  2271. list._origin = newOrigin;
  2272. list._capacity = newCapacity;
  2273. list._level = newLevel;
  2274. list._root = newRoot;
  2275. list._tail = newTail;
  2276. list.__hash = undefined;
  2277. list.__altered = true;
  2278. return list;
  2279. }
  2280. return makeList(newOrigin, newCapacity, newLevel, newRoot, newTail);
  2281. }
  2282. function mergeIntoListWith(list, merger, iterables) {
  2283. var iters = [];
  2284. var maxSize = 0;
  2285. for (var ii = 0; ii < iterables.length; ii++) {
  2286. var value = iterables[ii];
  2287. var iter = IndexedIterable(value);
  2288. if (iter.size > maxSize) {
  2289. maxSize = iter.size;
  2290. }
  2291. if (!isIterable(value)) {
  2292. iter = iter.map(function(v ) {return fromJS(v)});
  2293. }
  2294. iters.push(iter);
  2295. }
  2296. if (maxSize > list.size) {
  2297. list = list.setSize(maxSize);
  2298. }
  2299. return mergeIntoCollectionWith(list, merger, iters);
  2300. }
  2301. function getTailOffset(size) {
  2302. return size < SIZE ? 0 : (((size - 1) >>> SHIFT) << SHIFT);
  2303. }
  2304. createClass(OrderedMap, Map);
  2305. // @pragma Construction
  2306. function OrderedMap(value) {
  2307. return value === null || value === undefined ? emptyOrderedMap() :
  2308. isOrderedMap(value) ? value :
  2309. emptyOrderedMap().withMutations(function(map ) {
  2310. var iter = KeyedIterable(value);
  2311. assertNotInfinite(iter.size);
  2312. iter.forEach(function(v, k) {return map.set(k, v)});
  2313. });
  2314. }
  2315. OrderedMap.of = function(/*...values*/) {
  2316. return this(arguments);
  2317. };
  2318. OrderedMap.prototype.toString = function() {
  2319. return this.__toString('OrderedMap {', '}');
  2320. };
  2321. // @pragma Access
  2322. OrderedMap.prototype.get = function(k, notSetValue) {
  2323. var index = this._map.get(k);
  2324. return index !== undefined ? this._list.get(index)[1] : notSetValue;
  2325. };
  2326. // @pragma Modification
  2327. OrderedMap.prototype.clear = function() {
  2328. if (this.size === 0) {
  2329. return this;
  2330. }
  2331. if (this.__ownerID) {
  2332. this.size = 0;
  2333. this._map.clear();
  2334. this._list.clear();
  2335. return this;
  2336. }
  2337. return emptyOrderedMap();
  2338. };
  2339. OrderedMap.prototype.set = function(k, v) {
  2340. return updateOrderedMap(this, k, v);
  2341. };
  2342. OrderedMap.prototype.remove = function(k) {
  2343. return updateOrderedMap(this, k, NOT_SET);
  2344. };
  2345. OrderedMap.prototype.wasAltered = function() {
  2346. return this._map.wasAltered() || this._list.wasAltered();
  2347. };
  2348. OrderedMap.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  2349. return this._list.__iterate(
  2350. function(entry ) {return entry && fn(entry[1], entry[0], this$0)},
  2351. reverse
  2352. );
  2353. };
  2354. OrderedMap.prototype.__iterator = function(type, reverse) {
  2355. return this._list.fromEntrySeq().__iterator(type, reverse);
  2356. };
  2357. OrderedMap.prototype.__ensureOwner = function(ownerID) {
  2358. if (ownerID === this.__ownerID) {
  2359. return this;
  2360. }
  2361. var newMap = this._map.__ensureOwner(ownerID);
  2362. var newList = this._list.__ensureOwner(ownerID);
  2363. if (!ownerID) {
  2364. this.__ownerID = ownerID;
  2365. this._map = newMap;
  2366. this._list = newList;
  2367. return this;
  2368. }
  2369. return makeOrderedMap(newMap, newList, ownerID, this.__hash);
  2370. };
  2371. function isOrderedMap(maybeOrderedMap) {
  2372. return isMap(maybeOrderedMap) && isOrdered(maybeOrderedMap);
  2373. }
  2374. OrderedMap.isOrderedMap = isOrderedMap;
  2375. OrderedMap.prototype[IS_ORDERED_SENTINEL] = true;
  2376. OrderedMap.prototype[DELETE] = OrderedMap.prototype.remove;
  2377. function makeOrderedMap(map, list, ownerID, hash) {
  2378. var omap = Object.create(OrderedMap.prototype);
  2379. omap.size = map ? map.size : 0;
  2380. omap._map = map;
  2381. omap._list = list;
  2382. omap.__ownerID = ownerID;
  2383. omap.__hash = hash;
  2384. return omap;
  2385. }
  2386. var EMPTY_ORDERED_MAP;
  2387. function emptyOrderedMap() {
  2388. return EMPTY_ORDERED_MAP || (EMPTY_ORDERED_MAP = makeOrderedMap(emptyMap(), emptyList()));
  2389. }
  2390. function updateOrderedMap(omap, k, v) {
  2391. var map = omap._map;
  2392. var list = omap._list;
  2393. var i = map.get(k);
  2394. var has = i !== undefined;
  2395. var newMap;
  2396. var newList;
  2397. if (v === NOT_SET) { // removed
  2398. if (!has) {
  2399. return omap;
  2400. }
  2401. if (list.size >= SIZE && list.size >= map.size * 2) {
  2402. newList = list.filter(function(entry, idx) {return entry !== undefined && i !== idx});
  2403. newMap = newList.toKeyedSeq().map(function(entry ) {return entry[0]}).flip().toMap();
  2404. if (omap.__ownerID) {
  2405. newMap.__ownerID = newList.__ownerID = omap.__ownerID;
  2406. }
  2407. } else {
  2408. newMap = map.remove(k);
  2409. newList = i === list.size - 1 ? list.pop() : list.set(i, undefined);
  2410. }
  2411. } else {
  2412. if (has) {
  2413. if (v === list.get(i)[1]) {
  2414. return omap;
  2415. }
  2416. newMap = map;
  2417. newList = list.set(i, [k, v]);
  2418. } else {
  2419. newMap = map.set(k, list.size);
  2420. newList = list.set(list.size, [k, v]);
  2421. }
  2422. }
  2423. if (omap.__ownerID) {
  2424. omap.size = newMap.size;
  2425. omap._map = newMap;
  2426. omap._list = newList;
  2427. omap.__hash = undefined;
  2428. return omap;
  2429. }
  2430. return makeOrderedMap(newMap, newList);
  2431. }
  2432. createClass(ToKeyedSequence, KeyedSeq);
  2433. function ToKeyedSequence(indexed, useKeys) {
  2434. this._iter = indexed;
  2435. this._useKeys = useKeys;
  2436. this.size = indexed.size;
  2437. }
  2438. ToKeyedSequence.prototype.get = function(key, notSetValue) {
  2439. return this._iter.get(key, notSetValue);
  2440. };
  2441. ToKeyedSequence.prototype.has = function(key) {
  2442. return this._iter.has(key);
  2443. };
  2444. ToKeyedSequence.prototype.valueSeq = function() {
  2445. return this._iter.valueSeq();
  2446. };
  2447. ToKeyedSequence.prototype.reverse = function() {var this$0 = this;
  2448. var reversedSequence = reverseFactory(this, true);
  2449. if (!this._useKeys) {
  2450. reversedSequence.valueSeq = function() {return this$0._iter.toSeq().reverse()};
  2451. }
  2452. return reversedSequence;
  2453. };
  2454. ToKeyedSequence.prototype.map = function(mapper, context) {var this$0 = this;
  2455. var mappedSequence = mapFactory(this, mapper, context);
  2456. if (!this._useKeys) {
  2457. mappedSequence.valueSeq = function() {return this$0._iter.toSeq().map(mapper, context)};
  2458. }
  2459. return mappedSequence;
  2460. };
  2461. ToKeyedSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  2462. var ii;
  2463. return this._iter.__iterate(
  2464. this._useKeys ?
  2465. function(v, k) {return fn(v, k, this$0)} :
  2466. ((ii = reverse ? resolveSize(this) : 0),
  2467. function(v ) {return fn(v, reverse ? --ii : ii++, this$0)}),
  2468. reverse
  2469. );
  2470. };
  2471. ToKeyedSequence.prototype.__iterator = function(type, reverse) {
  2472. if (this._useKeys) {
  2473. return this._iter.__iterator(type, reverse);
  2474. }
  2475. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  2476. var ii = reverse ? resolveSize(this) : 0;
  2477. return new Iterator(function() {
  2478. var step = iterator.next();
  2479. return step.done ? step :
  2480. iteratorValue(type, reverse ? --ii : ii++, step.value, step);
  2481. });
  2482. };
  2483. ToKeyedSequence.prototype[IS_ORDERED_SENTINEL] = true;
  2484. createClass(ToIndexedSequence, IndexedSeq);
  2485. function ToIndexedSequence(iter) {
  2486. this._iter = iter;
  2487. this.size = iter.size;
  2488. }
  2489. ToIndexedSequence.prototype.includes = function(value) {
  2490. return this._iter.includes(value);
  2491. };
  2492. ToIndexedSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  2493. var iterations = 0;
  2494. return this._iter.__iterate(function(v ) {return fn(v, iterations++, this$0)}, reverse);
  2495. };
  2496. ToIndexedSequence.prototype.__iterator = function(type, reverse) {
  2497. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  2498. var iterations = 0;
  2499. return new Iterator(function() {
  2500. var step = iterator.next();
  2501. return step.done ? step :
  2502. iteratorValue(type, iterations++, step.value, step)
  2503. });
  2504. };
  2505. createClass(ToSetSequence, SetSeq);
  2506. function ToSetSequence(iter) {
  2507. this._iter = iter;
  2508. this.size = iter.size;
  2509. }
  2510. ToSetSequence.prototype.has = function(key) {
  2511. return this._iter.includes(key);
  2512. };
  2513. ToSetSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  2514. return this._iter.__iterate(function(v ) {return fn(v, v, this$0)}, reverse);
  2515. };
  2516. ToSetSequence.prototype.__iterator = function(type, reverse) {
  2517. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  2518. return new Iterator(function() {
  2519. var step = iterator.next();
  2520. return step.done ? step :
  2521. iteratorValue(type, step.value, step.value, step);
  2522. });
  2523. };
  2524. createClass(FromEntriesSequence, KeyedSeq);
  2525. function FromEntriesSequence(entries) {
  2526. this._iter = entries;
  2527. this.size = entries.size;
  2528. }
  2529. FromEntriesSequence.prototype.entrySeq = function() {
  2530. return this._iter.toSeq();
  2531. };
  2532. FromEntriesSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  2533. return this._iter.__iterate(function(entry ) {
  2534. // Check if entry exists first so array access doesn't throw for holes
  2535. // in the parent iteration.
  2536. if (entry) {
  2537. validateEntry(entry);
  2538. var indexedIterable = isIterable(entry);
  2539. return fn(
  2540. indexedIterable ? entry.get(1) : entry[1],
  2541. indexedIterable ? entry.get(0) : entry[0],
  2542. this$0
  2543. );
  2544. }
  2545. }, reverse);
  2546. };
  2547. FromEntriesSequence.prototype.__iterator = function(type, reverse) {
  2548. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  2549. return new Iterator(function() {
  2550. while (true) {
  2551. var step = iterator.next();
  2552. if (step.done) {
  2553. return step;
  2554. }
  2555. var entry = step.value;
  2556. // Check if entry exists first so array access doesn't throw for holes
  2557. // in the parent iteration.
  2558. if (entry) {
  2559. validateEntry(entry);
  2560. var indexedIterable = isIterable(entry);
  2561. return iteratorValue(
  2562. type,
  2563. indexedIterable ? entry.get(0) : entry[0],
  2564. indexedIterable ? entry.get(1) : entry[1],
  2565. step
  2566. );
  2567. }
  2568. }
  2569. });
  2570. };
  2571. ToIndexedSequence.prototype.cacheResult =
  2572. ToKeyedSequence.prototype.cacheResult =
  2573. ToSetSequence.prototype.cacheResult =
  2574. FromEntriesSequence.prototype.cacheResult =
  2575. cacheResultThrough;
  2576. function flipFactory(iterable) {
  2577. var flipSequence = makeSequence(iterable);
  2578. flipSequence._iter = iterable;
  2579. flipSequence.size = iterable.size;
  2580. flipSequence.flip = function() {return iterable};
  2581. flipSequence.reverse = function () {
  2582. var reversedSequence = iterable.reverse.apply(this); // super.reverse()
  2583. reversedSequence.flip = function() {return iterable.reverse()};
  2584. return reversedSequence;
  2585. };
  2586. flipSequence.has = function(key ) {return iterable.includes(key)};
  2587. flipSequence.includes = function(key ) {return iterable.has(key)};
  2588. flipSequence.cacheResult = cacheResultThrough;
  2589. flipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  2590. return iterable.__iterate(function(v, k) {return fn(k, v, this$0) !== false}, reverse);
  2591. };
  2592. flipSequence.__iteratorUncached = function(type, reverse) {
  2593. if (type === ITERATE_ENTRIES) {
  2594. var iterator = iterable.__iterator(type, reverse);
  2595. return new Iterator(function() {
  2596. var step = iterator.next();
  2597. if (!step.done) {
  2598. var k = step.value[0];
  2599. step.value[0] = step.value[1];
  2600. step.value[1] = k;
  2601. }
  2602. return step;
  2603. });
  2604. }
  2605. return iterable.__iterator(
  2606. type === ITERATE_VALUES ? ITERATE_KEYS : ITERATE_VALUES,
  2607. reverse
  2608. );
  2609. };
  2610. return flipSequence;
  2611. }
  2612. function mapFactory(iterable, mapper, context) {
  2613. var mappedSequence = makeSequence(iterable);
  2614. mappedSequence.size = iterable.size;
  2615. mappedSequence.has = function(key ) {return iterable.has(key)};
  2616. mappedSequence.get = function(key, notSetValue) {
  2617. var v = iterable.get(key, NOT_SET);
  2618. return v === NOT_SET ?
  2619. notSetValue :
  2620. mapper.call(context, v, key, iterable);
  2621. };
  2622. mappedSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  2623. return iterable.__iterate(
  2624. function(v, k, c) {return fn(mapper.call(context, v, k, c), k, this$0) !== false},
  2625. reverse
  2626. );
  2627. };
  2628. mappedSequence.__iteratorUncached = function (type, reverse) {
  2629. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  2630. return new Iterator(function() {
  2631. var step = iterator.next();
  2632. if (step.done) {
  2633. return step;
  2634. }
  2635. var entry = step.value;
  2636. var key = entry[0];
  2637. return iteratorValue(
  2638. type,
  2639. key,
  2640. mapper.call(context, entry[1], key, iterable),
  2641. step
  2642. );
  2643. });
  2644. };
  2645. return mappedSequence;
  2646. }
  2647. function reverseFactory(iterable, useKeys) {
  2648. var reversedSequence = makeSequence(iterable);
  2649. reversedSequence._iter = iterable;
  2650. reversedSequence.size = iterable.size;
  2651. reversedSequence.reverse = function() {return iterable};
  2652. if (iterable.flip) {
  2653. reversedSequence.flip = function () {
  2654. var flipSequence = flipFactory(iterable);
  2655. flipSequence.reverse = function() {return iterable.flip()};
  2656. return flipSequence;
  2657. };
  2658. }
  2659. reversedSequence.get = function(key, notSetValue)
  2660. {return iterable.get(useKeys ? key : -1 - key, notSetValue)};
  2661. reversedSequence.has = function(key )
  2662. {return iterable.has(useKeys ? key : -1 - key)};
  2663. reversedSequence.includes = function(value ) {return iterable.includes(value)};
  2664. reversedSequence.cacheResult = cacheResultThrough;
  2665. reversedSequence.__iterate = function (fn, reverse) {var this$0 = this;
  2666. return iterable.__iterate(function(v, k) {return fn(v, k, this$0)}, !reverse);
  2667. };
  2668. reversedSequence.__iterator =
  2669. function(type, reverse) {return iterable.__iterator(type, !reverse)};
  2670. return reversedSequence;
  2671. }
  2672. function filterFactory(iterable, predicate, context, useKeys) {
  2673. var filterSequence = makeSequence(iterable);
  2674. if (useKeys) {
  2675. filterSequence.has = function(key ) {
  2676. var v = iterable.get(key, NOT_SET);
  2677. return v !== NOT_SET && !!predicate.call(context, v, key, iterable);
  2678. };
  2679. filterSequence.get = function(key, notSetValue) {
  2680. var v = iterable.get(key, NOT_SET);
  2681. return v !== NOT_SET && predicate.call(context, v, key, iterable) ?
  2682. v : notSetValue;
  2683. };
  2684. }
  2685. filterSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  2686. var iterations = 0;
  2687. iterable.__iterate(function(v, k, c) {
  2688. if (predicate.call(context, v, k, c)) {
  2689. iterations++;
  2690. return fn(v, useKeys ? k : iterations - 1, this$0);
  2691. }
  2692. }, reverse);
  2693. return iterations;
  2694. };
  2695. filterSequence.__iteratorUncached = function (type, reverse) {
  2696. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  2697. var iterations = 0;
  2698. return new Iterator(function() {
  2699. while (true) {
  2700. var step = iterator.next();
  2701. if (step.done) {
  2702. return step;
  2703. }
  2704. var entry = step.value;
  2705. var key = entry[0];
  2706. var value = entry[1];
  2707. if (predicate.call(context, value, key, iterable)) {
  2708. return iteratorValue(type, useKeys ? key : iterations++, value, step);
  2709. }
  2710. }
  2711. });
  2712. };
  2713. return filterSequence;
  2714. }
  2715. function countByFactory(iterable, grouper, context) {
  2716. var groups = Map().asMutable();
  2717. iterable.__iterate(function(v, k) {
  2718. groups.update(
  2719. grouper.call(context, v, k, iterable),
  2720. 0,
  2721. function(a ) {return a + 1}
  2722. );
  2723. });
  2724. return groups.asImmutable();
  2725. }
  2726. function groupByFactory(iterable, grouper, context) {
  2727. var isKeyedIter = isKeyed(iterable);
  2728. var groups = (isOrdered(iterable) ? OrderedMap() : Map()).asMutable();
  2729. iterable.__iterate(function(v, k) {
  2730. groups.update(
  2731. grouper.call(context, v, k, iterable),
  2732. function(a ) {return (a = a || [], a.push(isKeyedIter ? [k, v] : v), a)}
  2733. );
  2734. });
  2735. var coerce = iterableClass(iterable);
  2736. return groups.map(function(arr ) {return reify(iterable, coerce(arr))});
  2737. }
  2738. function sliceFactory(iterable, begin, end, useKeys) {
  2739. var originalSize = iterable.size;
  2740. // Sanitize begin & end using this shorthand for ToInt32(argument)
  2741. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  2742. if (begin !== undefined) {
  2743. begin = begin | 0;
  2744. }
  2745. if (end !== undefined) {
  2746. end = end | 0;
  2747. }
  2748. if (wholeSlice(begin, end, originalSize)) {
  2749. return iterable;
  2750. }
  2751. var resolvedBegin = resolveBegin(begin, originalSize);
  2752. var resolvedEnd = resolveEnd(end, originalSize);
  2753. // begin or end will be NaN if they were provided as negative numbers and
  2754. // this iterable's size is unknown. In that case, cache first so there is
  2755. // a known size and these do not resolve to NaN.
  2756. if (resolvedBegin !== resolvedBegin || resolvedEnd !== resolvedEnd) {
  2757. return sliceFactory(iterable.toSeq().cacheResult(), begin, end, useKeys);
  2758. }
  2759. // Note: resolvedEnd is undefined when the original sequence's length is
  2760. // unknown and this slice did not supply an end and should contain all
  2761. // elements after resolvedBegin.
  2762. // In that case, resolvedSize will be NaN and sliceSize will remain undefined.
  2763. var resolvedSize = resolvedEnd - resolvedBegin;
  2764. var sliceSize;
  2765. if (resolvedSize === resolvedSize) {
  2766. sliceSize = resolvedSize < 0 ? 0 : resolvedSize;
  2767. }
  2768. var sliceSeq = makeSequence(iterable);
  2769. // If iterable.size is undefined, the size of the realized sliceSeq is
  2770. // unknown at this point unless the number of items to slice is 0
  2771. sliceSeq.size = sliceSize === 0 ? sliceSize : iterable.size && sliceSize || undefined;
  2772. if (!useKeys && isSeq(iterable) && sliceSize >= 0) {
  2773. sliceSeq.get = function (index, notSetValue) {
  2774. index = wrapIndex(this, index);
  2775. return index >= 0 && index < sliceSize ?
  2776. iterable.get(index + resolvedBegin, notSetValue) :
  2777. notSetValue;
  2778. };
  2779. }
  2780. sliceSeq.__iterateUncached = function(fn, reverse) {var this$0 = this;
  2781. if (sliceSize === 0) {
  2782. return 0;
  2783. }
  2784. if (reverse) {
  2785. return this.cacheResult().__iterate(fn, reverse);
  2786. }
  2787. var skipped = 0;
  2788. var isSkipping = true;
  2789. var iterations = 0;
  2790. iterable.__iterate(function(v, k) {
  2791. if (!(isSkipping && (isSkipping = skipped++ < resolvedBegin))) {
  2792. iterations++;
  2793. return fn(v, useKeys ? k : iterations - 1, this$0) !== false &&
  2794. iterations !== sliceSize;
  2795. }
  2796. });
  2797. return iterations;
  2798. };
  2799. sliceSeq.__iteratorUncached = function(type, reverse) {
  2800. if (sliceSize !== 0 && reverse) {
  2801. return this.cacheResult().__iterator(type, reverse);
  2802. }
  2803. // Don't bother instantiating parent iterator if taking 0.
  2804. var iterator = sliceSize !== 0 && iterable.__iterator(type, reverse);
  2805. var skipped = 0;
  2806. var iterations = 0;
  2807. return new Iterator(function() {
  2808. while (skipped++ < resolvedBegin) {
  2809. iterator.next();
  2810. }
  2811. if (++iterations > sliceSize) {
  2812. return iteratorDone();
  2813. }
  2814. var step = iterator.next();
  2815. if (useKeys || type === ITERATE_VALUES) {
  2816. return step;
  2817. } else if (type === ITERATE_KEYS) {
  2818. return iteratorValue(type, iterations - 1, undefined, step);
  2819. } else {
  2820. return iteratorValue(type, iterations - 1, step.value[1], step);
  2821. }
  2822. });
  2823. };
  2824. return sliceSeq;
  2825. }
  2826. function takeWhileFactory(iterable, predicate, context) {
  2827. var takeSequence = makeSequence(iterable);
  2828. takeSequence.__iterateUncached = function(fn, reverse) {var this$0 = this;
  2829. if (reverse) {
  2830. return this.cacheResult().__iterate(fn, reverse);
  2831. }
  2832. var iterations = 0;
  2833. iterable.__iterate(function(v, k, c)
  2834. {return predicate.call(context, v, k, c) && ++iterations && fn(v, k, this$0)}
  2835. );
  2836. return iterations;
  2837. };
  2838. takeSequence.__iteratorUncached = function(type, reverse) {var this$0 = this;
  2839. if (reverse) {
  2840. return this.cacheResult().__iterator(type, reverse);
  2841. }
  2842. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  2843. var iterating = true;
  2844. return new Iterator(function() {
  2845. if (!iterating) {
  2846. return iteratorDone();
  2847. }
  2848. var step = iterator.next();
  2849. if (step.done) {
  2850. return step;
  2851. }
  2852. var entry = step.value;
  2853. var k = entry[0];
  2854. var v = entry[1];
  2855. if (!predicate.call(context, v, k, this$0)) {
  2856. iterating = false;
  2857. return iteratorDone();
  2858. }
  2859. return type === ITERATE_ENTRIES ? step :
  2860. iteratorValue(type, k, v, step);
  2861. });
  2862. };
  2863. return takeSequence;
  2864. }
  2865. function skipWhileFactory(iterable, predicate, context, useKeys) {
  2866. var skipSequence = makeSequence(iterable);
  2867. skipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  2868. if (reverse) {
  2869. return this.cacheResult().__iterate(fn, reverse);
  2870. }
  2871. var isSkipping = true;
  2872. var iterations = 0;
  2873. iterable.__iterate(function(v, k, c) {
  2874. if (!(isSkipping && (isSkipping = predicate.call(context, v, k, c)))) {
  2875. iterations++;
  2876. return fn(v, useKeys ? k : iterations - 1, this$0);
  2877. }
  2878. });
  2879. return iterations;
  2880. };
  2881. skipSequence.__iteratorUncached = function(type, reverse) {var this$0 = this;
  2882. if (reverse) {
  2883. return this.cacheResult().__iterator(type, reverse);
  2884. }
  2885. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  2886. var skipping = true;
  2887. var iterations = 0;
  2888. return new Iterator(function() {
  2889. var step, k, v;
  2890. do {
  2891. step = iterator.next();
  2892. if (step.done) {
  2893. if (useKeys || type === ITERATE_VALUES) {
  2894. return step;
  2895. } else if (type === ITERATE_KEYS) {
  2896. return iteratorValue(type, iterations++, undefined, step);
  2897. } else {
  2898. return iteratorValue(type, iterations++, step.value[1], step);
  2899. }
  2900. }
  2901. var entry = step.value;
  2902. k = entry[0];
  2903. v = entry[1];
  2904. skipping && (skipping = predicate.call(context, v, k, this$0));
  2905. } while (skipping);
  2906. return type === ITERATE_ENTRIES ? step :
  2907. iteratorValue(type, k, v, step);
  2908. });
  2909. };
  2910. return skipSequence;
  2911. }
  2912. function concatFactory(iterable, values) {
  2913. var isKeyedIterable = isKeyed(iterable);
  2914. var iters = [iterable].concat(values).map(function(v ) {
  2915. if (!isIterable(v)) {
  2916. v = isKeyedIterable ?
  2917. keyedSeqFromValue(v) :
  2918. indexedSeqFromValue(Array.isArray(v) ? v : [v]);
  2919. } else if (isKeyedIterable) {
  2920. v = KeyedIterable(v);
  2921. }
  2922. return v;
  2923. }).filter(function(v ) {return v.size !== 0});
  2924. if (iters.length === 0) {
  2925. return iterable;
  2926. }
  2927. if (iters.length === 1) {
  2928. var singleton = iters[0];
  2929. if (singleton === iterable ||
  2930. isKeyedIterable && isKeyed(singleton) ||
  2931. isIndexed(iterable) && isIndexed(singleton)) {
  2932. return singleton;
  2933. }
  2934. }
  2935. var concatSeq = new ArraySeq(iters);
  2936. if (isKeyedIterable) {
  2937. concatSeq = concatSeq.toKeyedSeq();
  2938. } else if (!isIndexed(iterable)) {
  2939. concatSeq = concatSeq.toSetSeq();
  2940. }
  2941. concatSeq = concatSeq.flatten(true);
  2942. concatSeq.size = iters.reduce(
  2943. function(sum, seq) {
  2944. if (sum !== undefined) {
  2945. var size = seq.size;
  2946. if (size !== undefined) {
  2947. return sum + size;
  2948. }
  2949. }
  2950. },
  2951. 0
  2952. );
  2953. return concatSeq;
  2954. }
  2955. function flattenFactory(iterable, depth, useKeys) {
  2956. var flatSequence = makeSequence(iterable);
  2957. flatSequence.__iterateUncached = function(fn, reverse) {
  2958. var iterations = 0;
  2959. var stopped = false;
  2960. function flatDeep(iter, currentDepth) {var this$0 = this;
  2961. iter.__iterate(function(v, k) {
  2962. if ((!depth || currentDepth < depth) && isIterable(v)) {
  2963. flatDeep(v, currentDepth + 1);
  2964. } else if (fn(v, useKeys ? k : iterations++, this$0) === false) {
  2965. stopped = true;
  2966. }
  2967. return !stopped;
  2968. }, reverse);
  2969. }
  2970. flatDeep(iterable, 0);
  2971. return iterations;
  2972. };
  2973. flatSequence.__iteratorUncached = function(type, reverse) {
  2974. var iterator = iterable.__iterator(type, reverse);
  2975. var stack = [];
  2976. var iterations = 0;
  2977. return new Iterator(function() {
  2978. while (iterator) {
  2979. var step = iterator.next();
  2980. if (step.done !== false) {
  2981. iterator = stack.pop();
  2982. continue;
  2983. }
  2984. var v = step.value;
  2985. if (type === ITERATE_ENTRIES) {
  2986. v = v[1];
  2987. }
  2988. if ((!depth || stack.length < depth) && isIterable(v)) {
  2989. stack.push(iterator);
  2990. iterator = v.__iterator(type, reverse);
  2991. } else {
  2992. return useKeys ? step : iteratorValue(type, iterations++, v, step);
  2993. }
  2994. }
  2995. return iteratorDone();
  2996. });
  2997. };
  2998. return flatSequence;
  2999. }
  3000. function flatMapFactory(iterable, mapper, context) {
  3001. var coerce = iterableClass(iterable);
  3002. return iterable.toSeq().map(
  3003. function(v, k) {return coerce(mapper.call(context, v, k, iterable))}
  3004. ).flatten(true);
  3005. }
  3006. function interposeFactory(iterable, separator) {
  3007. var interposedSequence = makeSequence(iterable);
  3008. interposedSequence.size = iterable.size && iterable.size * 2 -1;
  3009. interposedSequence.__iterateUncached = function(fn, reverse) {var this$0 = this;
  3010. var iterations = 0;
  3011. iterable.__iterate(function(v, k)
  3012. {return (!iterations || fn(separator, iterations++, this$0) !== false) &&
  3013. fn(v, iterations++, this$0) !== false},
  3014. reverse
  3015. );
  3016. return iterations;
  3017. };
  3018. interposedSequence.__iteratorUncached = function(type, reverse) {
  3019. var iterator = iterable.__iterator(ITERATE_VALUES, reverse);
  3020. var iterations = 0;
  3021. var step;
  3022. return new Iterator(function() {
  3023. if (!step || iterations % 2) {
  3024. step = iterator.next();
  3025. if (step.done) {
  3026. return step;
  3027. }
  3028. }
  3029. return iterations % 2 ?
  3030. iteratorValue(type, iterations++, separator) :
  3031. iteratorValue(type, iterations++, step.value, step);
  3032. });
  3033. };
  3034. return interposedSequence;
  3035. }
  3036. function sortFactory(iterable, comparator, mapper) {
  3037. if (!comparator) {
  3038. comparator = defaultComparator;
  3039. }
  3040. var isKeyedIterable = isKeyed(iterable);
  3041. var index = 0;
  3042. var entries = iterable.toSeq().map(
  3043. function(v, k) {return [k, v, index++, mapper ? mapper(v, k, iterable) : v]}
  3044. ).toArray();
  3045. entries.sort(function(a, b) {return comparator(a[3], b[3]) || a[2] - b[2]}).forEach(
  3046. isKeyedIterable ?
  3047. function(v, i) { entries[i].length = 2; } :
  3048. function(v, i) { entries[i] = v[1]; }
  3049. );
  3050. return isKeyedIterable ? KeyedSeq(entries) :
  3051. isIndexed(iterable) ? IndexedSeq(entries) :
  3052. SetSeq(entries);
  3053. }
  3054. function maxFactory(iterable, comparator, mapper) {
  3055. if (!comparator) {
  3056. comparator = defaultComparator;
  3057. }
  3058. if (mapper) {
  3059. var entry = iterable.toSeq()
  3060. .map(function(v, k) {return [v, mapper(v, k, iterable)]})
  3061. .reduce(function(a, b) {return maxCompare(comparator, a[1], b[1]) ? b : a});
  3062. return entry && entry[0];
  3063. } else {
  3064. return iterable.reduce(function(a, b) {return maxCompare(comparator, a, b) ? b : a});
  3065. }
  3066. }
  3067. function maxCompare(comparator, a, b) {
  3068. var comp = comparator(b, a);
  3069. // b is considered the new max if the comparator declares them equal, but
  3070. // they are not equal and b is in fact a nullish value.
  3071. return (comp === 0 && b !== a && (b === undefined || b === null || b !== b)) || comp > 0;
  3072. }
  3073. function zipWithFactory(keyIter, zipper, iters) {
  3074. var zipSequence = makeSequence(keyIter);
  3075. zipSequence.size = new ArraySeq(iters).map(function(i ) {return i.size}).min();
  3076. // Note: this a generic base implementation of __iterate in terms of
  3077. // __iterator which may be more generically useful in the future.
  3078. zipSequence.__iterate = function(fn, reverse) {
  3079. /* generic:
  3080. var iterator = this.__iterator(ITERATE_ENTRIES, reverse);
  3081. var step;
  3082. var iterations = 0;
  3083. while (!(step = iterator.next()).done) {
  3084. iterations++;
  3085. if (fn(step.value[1], step.value[0], this) === false) {
  3086. break;
  3087. }
  3088. }
  3089. return iterations;
  3090. */
  3091. // indexed:
  3092. var iterator = this.__iterator(ITERATE_VALUES, reverse);
  3093. var step;
  3094. var iterations = 0;
  3095. while (!(step = iterator.next()).done) {
  3096. if (fn(step.value, iterations++, this) === false) {
  3097. break;
  3098. }
  3099. }
  3100. return iterations;
  3101. };
  3102. zipSequence.__iteratorUncached = function(type, reverse) {
  3103. var iterators = iters.map(function(i )
  3104. {return (i = Iterable(i), getIterator(reverse ? i.reverse() : i))}
  3105. );
  3106. var iterations = 0;
  3107. var isDone = false;
  3108. return new Iterator(function() {
  3109. var steps;
  3110. if (!isDone) {
  3111. steps = iterators.map(function(i ) {return i.next()});
  3112. isDone = steps.some(function(s ) {return s.done});
  3113. }
  3114. if (isDone) {
  3115. return iteratorDone();
  3116. }
  3117. return iteratorValue(
  3118. type,
  3119. iterations++,
  3120. zipper.apply(null, steps.map(function(s ) {return s.value}))
  3121. );
  3122. });
  3123. };
  3124. return zipSequence
  3125. }
  3126. // #pragma Helper Functions
  3127. function reify(iter, seq) {
  3128. return isSeq(iter) ? seq : iter.constructor(seq);
  3129. }
  3130. function validateEntry(entry) {
  3131. if (entry !== Object(entry)) {
  3132. throw new TypeError('Expected [K, V] tuple: ' + entry);
  3133. }
  3134. }
  3135. function resolveSize(iter) {
  3136. assertNotInfinite(iter.size);
  3137. return ensureSize(iter);
  3138. }
  3139. function iterableClass(iterable) {
  3140. return isKeyed(iterable) ? KeyedIterable :
  3141. isIndexed(iterable) ? IndexedIterable :
  3142. SetIterable;
  3143. }
  3144. function makeSequence(iterable) {
  3145. return Object.create(
  3146. (
  3147. isKeyed(iterable) ? KeyedSeq :
  3148. isIndexed(iterable) ? IndexedSeq :
  3149. SetSeq
  3150. ).prototype
  3151. );
  3152. }
  3153. function cacheResultThrough() {
  3154. if (this._iter.cacheResult) {
  3155. this._iter.cacheResult();
  3156. this.size = this._iter.size;
  3157. return this;
  3158. } else {
  3159. return Seq.prototype.cacheResult.call(this);
  3160. }
  3161. }
  3162. function defaultComparator(a, b) {
  3163. return a > b ? 1 : a < b ? -1 : 0;
  3164. }
  3165. function forceIterator(keyPath) {
  3166. var iter = getIterator(keyPath);
  3167. if (!iter) {
  3168. // Array might not be iterable in this environment, so we need a fallback
  3169. // to our wrapped type.
  3170. if (!isArrayLike(keyPath)) {
  3171. throw new TypeError('Expected iterable or array-like: ' + keyPath);
  3172. }
  3173. iter = getIterator(Iterable(keyPath));
  3174. }
  3175. return iter;
  3176. }
  3177. createClass(Record, KeyedCollection);
  3178. function Record(defaultValues, name) {
  3179. var hasInitialized;
  3180. var RecordType = function Record(values) {
  3181. if (values instanceof RecordType) {
  3182. return values;
  3183. }
  3184. if (!(this instanceof RecordType)) {
  3185. return new RecordType(values);
  3186. }
  3187. if (!hasInitialized) {
  3188. hasInitialized = true;
  3189. var keys = Object.keys(defaultValues);
  3190. setProps(RecordTypePrototype, keys);
  3191. RecordTypePrototype.size = keys.length;
  3192. RecordTypePrototype._name = name;
  3193. RecordTypePrototype._keys = keys;
  3194. RecordTypePrototype._defaultValues = defaultValues;
  3195. }
  3196. this._map = Map(values);
  3197. };
  3198. var RecordTypePrototype = RecordType.prototype = Object.create(RecordPrototype);
  3199. RecordTypePrototype.constructor = RecordType;
  3200. return RecordType;
  3201. }
  3202. Record.prototype.toString = function() {
  3203. return this.__toString(recordName(this) + ' {', '}');
  3204. };
  3205. // @pragma Access
  3206. Record.prototype.has = function(k) {
  3207. return this._defaultValues.hasOwnProperty(k);
  3208. };
  3209. Record.prototype.get = function(k, notSetValue) {
  3210. if (!this.has(k)) {
  3211. return notSetValue;
  3212. }
  3213. var defaultVal = this._defaultValues[k];
  3214. return this._map ? this._map.get(k, defaultVal) : defaultVal;
  3215. };
  3216. // @pragma Modification
  3217. Record.prototype.clear = function() {
  3218. if (this.__ownerID) {
  3219. this._map && this._map.clear();
  3220. return this;
  3221. }
  3222. var RecordType = this.constructor;
  3223. return RecordType._empty || (RecordType._empty = makeRecord(this, emptyMap()));
  3224. };
  3225. Record.prototype.set = function(k, v) {
  3226. if (!this.has(k)) {
  3227. throw new Error('Cannot set unknown key "' + k + '" on ' + recordName(this));
  3228. }
  3229. var newMap = this._map && this._map.set(k, v);
  3230. if (this.__ownerID || newMap === this._map) {
  3231. return this;
  3232. }
  3233. return makeRecord(this, newMap);
  3234. };
  3235. Record.prototype.remove = function(k) {
  3236. if (!this.has(k)) {
  3237. return this;
  3238. }
  3239. var newMap = this._map && this._map.remove(k);
  3240. if (this.__ownerID || newMap === this._map) {
  3241. return this;
  3242. }
  3243. return makeRecord(this, newMap);
  3244. };
  3245. Record.prototype.wasAltered = function() {
  3246. return this._map.wasAltered();
  3247. };
  3248. Record.prototype.__iterator = function(type, reverse) {var this$0 = this;
  3249. return KeyedIterable(this._defaultValues).map(function(_, k) {return this$0.get(k)}).__iterator(type, reverse);
  3250. };
  3251. Record.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  3252. return KeyedIterable(this._defaultValues).map(function(_, k) {return this$0.get(k)}).__iterate(fn, reverse);
  3253. };
  3254. Record.prototype.__ensureOwner = function(ownerID) {
  3255. if (ownerID === this.__ownerID) {
  3256. return this;
  3257. }
  3258. var newMap = this._map && this._map.__ensureOwner(ownerID);
  3259. if (!ownerID) {
  3260. this.__ownerID = ownerID;
  3261. this._map = newMap;
  3262. return this;
  3263. }
  3264. return makeRecord(this, newMap, ownerID);
  3265. };
  3266. var RecordPrototype = Record.prototype;
  3267. RecordPrototype[DELETE] = RecordPrototype.remove;
  3268. RecordPrototype.deleteIn =
  3269. RecordPrototype.removeIn = MapPrototype.removeIn;
  3270. RecordPrototype.merge = MapPrototype.merge;
  3271. RecordPrototype.mergeWith = MapPrototype.mergeWith;
  3272. RecordPrototype.mergeIn = MapPrototype.mergeIn;
  3273. RecordPrototype.mergeDeep = MapPrototype.mergeDeep;
  3274. RecordPrototype.mergeDeepWith = MapPrototype.mergeDeepWith;
  3275. RecordPrototype.mergeDeepIn = MapPrototype.mergeDeepIn;
  3276. RecordPrototype.setIn = MapPrototype.setIn;
  3277. RecordPrototype.update = MapPrototype.update;
  3278. RecordPrototype.updateIn = MapPrototype.updateIn;
  3279. RecordPrototype.withMutations = MapPrototype.withMutations;
  3280. RecordPrototype.asMutable = MapPrototype.asMutable;
  3281. RecordPrototype.asImmutable = MapPrototype.asImmutable;
  3282. function makeRecord(likeRecord, map, ownerID) {
  3283. var record = Object.create(Object.getPrototypeOf(likeRecord));
  3284. record._map = map;
  3285. record.__ownerID = ownerID;
  3286. return record;
  3287. }
  3288. function recordName(record) {
  3289. return record._name || record.constructor.name || 'Record';
  3290. }
  3291. function setProps(prototype, names) {
  3292. try {
  3293. names.forEach(setProp.bind(undefined, prototype));
  3294. } catch (error) {
  3295. // Object.defineProperty failed. Probably IE8.
  3296. }
  3297. }
  3298. function setProp(prototype, name) {
  3299. Object.defineProperty(prototype, name, {
  3300. get: function() {
  3301. return this.get(name);
  3302. },
  3303. set: function(value) {
  3304. invariant(this.__ownerID, 'Cannot set on an immutable record.');
  3305. this.set(name, value);
  3306. }
  3307. });
  3308. }
  3309. createClass(Set, SetCollection);
  3310. // @pragma Construction
  3311. function Set(value) {
  3312. return value === null || value === undefined ? emptySet() :
  3313. isSet(value) && !isOrdered(value) ? value :
  3314. emptySet().withMutations(function(set ) {
  3315. var iter = SetIterable(value);
  3316. assertNotInfinite(iter.size);
  3317. iter.forEach(function(v ) {return set.add(v)});
  3318. });
  3319. }
  3320. Set.of = function(/*...values*/) {
  3321. return this(arguments);
  3322. };
  3323. Set.fromKeys = function(value) {
  3324. return this(KeyedIterable(value).keySeq());
  3325. };
  3326. Set.prototype.toString = function() {
  3327. return this.__toString('Set {', '}');
  3328. };
  3329. // @pragma Access
  3330. Set.prototype.has = function(value) {
  3331. return this._map.has(value);
  3332. };
  3333. // @pragma Modification
  3334. Set.prototype.add = function(value) {
  3335. return updateSet(this, this._map.set(value, true));
  3336. };
  3337. Set.prototype.remove = function(value) {
  3338. return updateSet(this, this._map.remove(value));
  3339. };
  3340. Set.prototype.clear = function() {
  3341. return updateSet(this, this._map.clear());
  3342. };
  3343. // @pragma Composition
  3344. Set.prototype.union = function() {var iters = SLICE$0.call(arguments, 0);
  3345. iters = iters.filter(function(x ) {return x.size !== 0});
  3346. if (iters.length === 0) {
  3347. return this;
  3348. }
  3349. if (this.size === 0 && !this.__ownerID && iters.length === 1) {
  3350. return this.constructor(iters[0]);
  3351. }
  3352. return this.withMutations(function(set ) {
  3353. for (var ii = 0; ii < iters.length; ii++) {
  3354. SetIterable(iters[ii]).forEach(function(value ) {return set.add(value)});
  3355. }
  3356. });
  3357. };
  3358. Set.prototype.intersect = function() {var iters = SLICE$0.call(arguments, 0);
  3359. if (iters.length === 0) {
  3360. return this;
  3361. }
  3362. iters = iters.map(function(iter ) {return SetIterable(iter)});
  3363. var originalSet = this;
  3364. return this.withMutations(function(set ) {
  3365. originalSet.forEach(function(value ) {
  3366. if (!iters.every(function(iter ) {return iter.includes(value)})) {
  3367. set.remove(value);
  3368. }
  3369. });
  3370. });
  3371. };
  3372. Set.prototype.subtract = function() {var iters = SLICE$0.call(arguments, 0);
  3373. if (iters.length === 0) {
  3374. return this;
  3375. }
  3376. iters = iters.map(function(iter ) {return SetIterable(iter)});
  3377. var originalSet = this;
  3378. return this.withMutations(function(set ) {
  3379. originalSet.forEach(function(value ) {
  3380. if (iters.some(function(iter ) {return iter.includes(value)})) {
  3381. set.remove(value);
  3382. }
  3383. });
  3384. });
  3385. };
  3386. Set.prototype.merge = function() {
  3387. return this.union.apply(this, arguments);
  3388. };
  3389. Set.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  3390. return this.union.apply(this, iters);
  3391. };
  3392. Set.prototype.sort = function(comparator) {
  3393. // Late binding
  3394. return OrderedSet(sortFactory(this, comparator));
  3395. };
  3396. Set.prototype.sortBy = function(mapper, comparator) {
  3397. // Late binding
  3398. return OrderedSet(sortFactory(this, comparator, mapper));
  3399. };
  3400. Set.prototype.wasAltered = function() {
  3401. return this._map.wasAltered();
  3402. };
  3403. Set.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  3404. return this._map.__iterate(function(_, k) {return fn(k, k, this$0)}, reverse);
  3405. };
  3406. Set.prototype.__iterator = function(type, reverse) {
  3407. return this._map.map(function(_, k) {return k}).__iterator(type, reverse);
  3408. };
  3409. Set.prototype.__ensureOwner = function(ownerID) {
  3410. if (ownerID === this.__ownerID) {
  3411. return this;
  3412. }
  3413. var newMap = this._map.__ensureOwner(ownerID);
  3414. if (!ownerID) {
  3415. this.__ownerID = ownerID;
  3416. this._map = newMap;
  3417. return this;
  3418. }
  3419. return this.__make(newMap, ownerID);
  3420. };
  3421. function isSet(maybeSet) {
  3422. return !!(maybeSet && maybeSet[IS_SET_SENTINEL]);
  3423. }
  3424. Set.isSet = isSet;
  3425. var IS_SET_SENTINEL = '@@__IMMUTABLE_SET__@@';
  3426. var SetPrototype = Set.prototype;
  3427. SetPrototype[IS_SET_SENTINEL] = true;
  3428. SetPrototype[DELETE] = SetPrototype.remove;
  3429. SetPrototype.mergeDeep = SetPrototype.merge;
  3430. SetPrototype.mergeDeepWith = SetPrototype.mergeWith;
  3431. SetPrototype.withMutations = MapPrototype.withMutations;
  3432. SetPrototype.asMutable = MapPrototype.asMutable;
  3433. SetPrototype.asImmutable = MapPrototype.asImmutable;
  3434. SetPrototype.__empty = emptySet;
  3435. SetPrototype.__make = makeSet;
  3436. function updateSet(set, newMap) {
  3437. if (set.__ownerID) {
  3438. set.size = newMap.size;
  3439. set._map = newMap;
  3440. return set;
  3441. }
  3442. return newMap === set._map ? set :
  3443. newMap.size === 0 ? set.__empty() :
  3444. set.__make(newMap);
  3445. }
  3446. function makeSet(map, ownerID) {
  3447. var set = Object.create(SetPrototype);
  3448. set.size = map ? map.size : 0;
  3449. set._map = map;
  3450. set.__ownerID = ownerID;
  3451. return set;
  3452. }
  3453. var EMPTY_SET;
  3454. function emptySet() {
  3455. return EMPTY_SET || (EMPTY_SET = makeSet(emptyMap()));
  3456. }
  3457. createClass(OrderedSet, Set);
  3458. // @pragma Construction
  3459. function OrderedSet(value) {
  3460. return value === null || value === undefined ? emptyOrderedSet() :
  3461. isOrderedSet(value) ? value :
  3462. emptyOrderedSet().withMutations(function(set ) {
  3463. var iter = SetIterable(value);
  3464. assertNotInfinite(iter.size);
  3465. iter.forEach(function(v ) {return set.add(v)});
  3466. });
  3467. }
  3468. OrderedSet.of = function(/*...values*/) {
  3469. return this(arguments);
  3470. };
  3471. OrderedSet.fromKeys = function(value) {
  3472. return this(KeyedIterable(value).keySeq());
  3473. };
  3474. OrderedSet.prototype.toString = function() {
  3475. return this.__toString('OrderedSet {', '}');
  3476. };
  3477. function isOrderedSet(maybeOrderedSet) {
  3478. return isSet(maybeOrderedSet) && isOrdered(maybeOrderedSet);
  3479. }
  3480. OrderedSet.isOrderedSet = isOrderedSet;
  3481. var OrderedSetPrototype = OrderedSet.prototype;
  3482. OrderedSetPrototype[IS_ORDERED_SENTINEL] = true;
  3483. OrderedSetPrototype.__empty = emptyOrderedSet;
  3484. OrderedSetPrototype.__make = makeOrderedSet;
  3485. function makeOrderedSet(map, ownerID) {
  3486. var set = Object.create(OrderedSetPrototype);
  3487. set.size = map ? map.size : 0;
  3488. set._map = map;
  3489. set.__ownerID = ownerID;
  3490. return set;
  3491. }
  3492. var EMPTY_ORDERED_SET;
  3493. function emptyOrderedSet() {
  3494. return EMPTY_ORDERED_SET || (EMPTY_ORDERED_SET = makeOrderedSet(emptyOrderedMap()));
  3495. }
  3496. createClass(Stack, IndexedCollection);
  3497. // @pragma Construction
  3498. function Stack(value) {
  3499. return value === null || value === undefined ? emptyStack() :
  3500. isStack(value) ? value :
  3501. emptyStack().unshiftAll(value);
  3502. }
  3503. Stack.of = function(/*...values*/) {
  3504. return this(arguments);
  3505. };
  3506. Stack.prototype.toString = function() {
  3507. return this.__toString('Stack [', ']');
  3508. };
  3509. // @pragma Access
  3510. Stack.prototype.get = function(index, notSetValue) {
  3511. var head = this._head;
  3512. index = wrapIndex(this, index);
  3513. while (head && index--) {
  3514. head = head.next;
  3515. }
  3516. return head ? head.value : notSetValue;
  3517. };
  3518. Stack.prototype.peek = function() {
  3519. return this._head && this._head.value;
  3520. };
  3521. // @pragma Modification
  3522. Stack.prototype.push = function(/*...values*/) {
  3523. if (arguments.length === 0) {
  3524. return this;
  3525. }
  3526. var newSize = this.size + arguments.length;
  3527. var head = this._head;
  3528. for (var ii = arguments.length - 1; ii >= 0; ii--) {
  3529. head = {
  3530. value: arguments[ii],
  3531. next: head
  3532. };
  3533. }
  3534. if (this.__ownerID) {
  3535. this.size = newSize;
  3536. this._head = head;
  3537. this.__hash = undefined;
  3538. this.__altered = true;
  3539. return this;
  3540. }
  3541. return makeStack(newSize, head);
  3542. };
  3543. Stack.prototype.pushAll = function(iter) {
  3544. iter = IndexedIterable(iter);
  3545. if (iter.size === 0) {
  3546. return this;
  3547. }
  3548. assertNotInfinite(iter.size);
  3549. var newSize = this.size;
  3550. var head = this._head;
  3551. iter.reverse().forEach(function(value ) {
  3552. newSize++;
  3553. head = {
  3554. value: value,
  3555. next: head
  3556. };
  3557. });
  3558. if (this.__ownerID) {
  3559. this.size = newSize;
  3560. this._head = head;
  3561. this.__hash = undefined;
  3562. this.__altered = true;
  3563. return this;
  3564. }
  3565. return makeStack(newSize, head);
  3566. };
  3567. Stack.prototype.pop = function() {
  3568. return this.slice(1);
  3569. };
  3570. Stack.prototype.unshift = function(/*...values*/) {
  3571. return this.push.apply(this, arguments);
  3572. };
  3573. Stack.prototype.unshiftAll = function(iter) {
  3574. return this.pushAll(iter);
  3575. };
  3576. Stack.prototype.shift = function() {
  3577. return this.pop.apply(this, arguments);
  3578. };
  3579. Stack.prototype.clear = function() {
  3580. if (this.size === 0) {
  3581. return this;
  3582. }
  3583. if (this.__ownerID) {
  3584. this.size = 0;
  3585. this._head = undefined;
  3586. this.__hash = undefined;
  3587. this.__altered = true;
  3588. return this;
  3589. }
  3590. return emptyStack();
  3591. };
  3592. Stack.prototype.slice = function(begin, end) {
  3593. if (wholeSlice(begin, end, this.size)) {
  3594. return this;
  3595. }
  3596. var resolvedBegin = resolveBegin(begin, this.size);
  3597. var resolvedEnd = resolveEnd(end, this.size);
  3598. if (resolvedEnd !== this.size) {
  3599. // super.slice(begin, end);
  3600. return IndexedCollection.prototype.slice.call(this, begin, end);
  3601. }
  3602. var newSize = this.size - resolvedBegin;
  3603. var head = this._head;
  3604. while (resolvedBegin--) {
  3605. head = head.next;
  3606. }
  3607. if (this.__ownerID) {
  3608. this.size = newSize;
  3609. this._head = head;
  3610. this.__hash = undefined;
  3611. this.__altered = true;
  3612. return this;
  3613. }
  3614. return makeStack(newSize, head);
  3615. };
  3616. // @pragma Mutability
  3617. Stack.prototype.__ensureOwner = function(ownerID) {
  3618. if (ownerID === this.__ownerID) {
  3619. return this;
  3620. }
  3621. if (!ownerID) {
  3622. this.__ownerID = ownerID;
  3623. this.__altered = false;
  3624. return this;
  3625. }
  3626. return makeStack(this.size, this._head, ownerID, this.__hash);
  3627. };
  3628. // @pragma Iteration
  3629. Stack.prototype.__iterate = function(fn, reverse) {
  3630. if (reverse) {
  3631. return this.reverse().__iterate(fn);
  3632. }
  3633. var iterations = 0;
  3634. var node = this._head;
  3635. while (node) {
  3636. if (fn(node.value, iterations++, this) === false) {
  3637. break;
  3638. }
  3639. node = node.next;
  3640. }
  3641. return iterations;
  3642. };
  3643. Stack.prototype.__iterator = function(type, reverse) {
  3644. if (reverse) {
  3645. return this.reverse().__iterator(type);
  3646. }
  3647. var iterations = 0;
  3648. var node = this._head;
  3649. return new Iterator(function() {
  3650. if (node) {
  3651. var value = node.value;
  3652. node = node.next;
  3653. return iteratorValue(type, iterations++, value);
  3654. }
  3655. return iteratorDone();
  3656. });
  3657. };
  3658. function isStack(maybeStack) {
  3659. return !!(maybeStack && maybeStack[IS_STACK_SENTINEL]);
  3660. }
  3661. Stack.isStack = isStack;
  3662. var IS_STACK_SENTINEL = '@@__IMMUTABLE_STACK__@@';
  3663. var StackPrototype = Stack.prototype;
  3664. StackPrototype[IS_STACK_SENTINEL] = true;
  3665. StackPrototype.withMutations = MapPrototype.withMutations;
  3666. StackPrototype.asMutable = MapPrototype.asMutable;
  3667. StackPrototype.asImmutable = MapPrototype.asImmutable;
  3668. StackPrototype.wasAltered = MapPrototype.wasAltered;
  3669. function makeStack(size, head, ownerID, hash) {
  3670. var map = Object.create(StackPrototype);
  3671. map.size = size;
  3672. map._head = head;
  3673. map.__ownerID = ownerID;
  3674. map.__hash = hash;
  3675. map.__altered = false;
  3676. return map;
  3677. }
  3678. var EMPTY_STACK;
  3679. function emptyStack() {
  3680. return EMPTY_STACK || (EMPTY_STACK = makeStack(0));
  3681. }
  3682. /**
  3683. * Contributes additional methods to a constructor
  3684. */
  3685. function mixin(ctor, methods) {
  3686. var keyCopier = function(key ) { ctor.prototype[key] = methods[key]; };
  3687. Object.keys(methods).forEach(keyCopier);
  3688. Object.getOwnPropertySymbols &&
  3689. Object.getOwnPropertySymbols(methods).forEach(keyCopier);
  3690. return ctor;
  3691. }
  3692. Iterable.Iterator = Iterator;
  3693. mixin(Iterable, {
  3694. // ### Conversion to other types
  3695. toArray: function() {
  3696. assertNotInfinite(this.size);
  3697. var array = new Array(this.size || 0);
  3698. this.valueSeq().__iterate(function(v, i) { array[i] = v; });
  3699. return array;
  3700. },
  3701. toIndexedSeq: function() {
  3702. return new ToIndexedSequence(this);
  3703. },
  3704. toJS: function() {
  3705. return this.toSeq().map(
  3706. function(value ) {return value && typeof value.toJS === 'function' ? value.toJS() : value}
  3707. ).__toJS();
  3708. },
  3709. toJSON: function() {
  3710. return this.toSeq().map(
  3711. function(value ) {return value && typeof value.toJSON === 'function' ? value.toJSON() : value}
  3712. ).__toJS();
  3713. },
  3714. toKeyedSeq: function() {
  3715. return new ToKeyedSequence(this, true);
  3716. },
  3717. toMap: function() {
  3718. // Use Late Binding here to solve the circular dependency.
  3719. return Map(this.toKeyedSeq());
  3720. },
  3721. toObject: function() {
  3722. assertNotInfinite(this.size);
  3723. var object = {};
  3724. this.__iterate(function(v, k) { object[k] = v; });
  3725. return object;
  3726. },
  3727. toOrderedMap: function() {
  3728. // Use Late Binding here to solve the circular dependency.
  3729. return OrderedMap(this.toKeyedSeq());
  3730. },
  3731. toOrderedSet: function() {
  3732. // Use Late Binding here to solve the circular dependency.
  3733. return OrderedSet(isKeyed(this) ? this.valueSeq() : this);
  3734. },
  3735. toSet: function() {
  3736. // Use Late Binding here to solve the circular dependency.
  3737. return Set(isKeyed(this) ? this.valueSeq() : this);
  3738. },
  3739. toSetSeq: function() {
  3740. return new ToSetSequence(this);
  3741. },
  3742. toSeq: function() {
  3743. return isIndexed(this) ? this.toIndexedSeq() :
  3744. isKeyed(this) ? this.toKeyedSeq() :
  3745. this.toSetSeq();
  3746. },
  3747. toStack: function() {
  3748. // Use Late Binding here to solve the circular dependency.
  3749. return Stack(isKeyed(this) ? this.valueSeq() : this);
  3750. },
  3751. toList: function() {
  3752. // Use Late Binding here to solve the circular dependency.
  3753. return List(isKeyed(this) ? this.valueSeq() : this);
  3754. },
  3755. // ### Common JavaScript methods and properties
  3756. toString: function() {
  3757. return '[Iterable]';
  3758. },
  3759. __toString: function(head, tail) {
  3760. if (this.size === 0) {
  3761. return head + tail;
  3762. }
  3763. return head + ' ' + this.toSeq().map(this.__toStringMapper).join(', ') + ' ' + tail;
  3764. },
  3765. // ### ES6 Collection methods (ES6 Array and Map)
  3766. concat: function() {var values = SLICE$0.call(arguments, 0);
  3767. return reify(this, concatFactory(this, values));
  3768. },
  3769. includes: function(searchValue) {
  3770. return this.some(function(value ) {return is(value, searchValue)});
  3771. },
  3772. entries: function() {
  3773. return this.__iterator(ITERATE_ENTRIES);
  3774. },
  3775. every: function(predicate, context) {
  3776. assertNotInfinite(this.size);
  3777. var returnValue = true;
  3778. this.__iterate(function(v, k, c) {
  3779. if (!predicate.call(context, v, k, c)) {
  3780. returnValue = false;
  3781. return false;
  3782. }
  3783. });
  3784. return returnValue;
  3785. },
  3786. filter: function(predicate, context) {
  3787. return reify(this, filterFactory(this, predicate, context, true));
  3788. },
  3789. find: function(predicate, context, notSetValue) {
  3790. var entry = this.findEntry(predicate, context);
  3791. return entry ? entry[1] : notSetValue;
  3792. },
  3793. findEntry: function(predicate, context) {
  3794. var found;
  3795. this.__iterate(function(v, k, c) {
  3796. if (predicate.call(context, v, k, c)) {
  3797. found = [k, v];
  3798. return false;
  3799. }
  3800. });
  3801. return found;
  3802. },
  3803. findLastEntry: function(predicate, context) {
  3804. return this.toSeq().reverse().findEntry(predicate, context);
  3805. },
  3806. forEach: function(sideEffect, context) {
  3807. assertNotInfinite(this.size);
  3808. return this.__iterate(context ? sideEffect.bind(context) : sideEffect);
  3809. },
  3810. join: function(separator) {
  3811. assertNotInfinite(this.size);
  3812. separator = separator !== undefined ? '' + separator : ',';
  3813. var joined = '';
  3814. var isFirst = true;
  3815. this.__iterate(function(v ) {
  3816. isFirst ? (isFirst = false) : (joined += separator);
  3817. joined += v !== null && v !== undefined ? v.toString() : '';
  3818. });
  3819. return joined;
  3820. },
  3821. keys: function() {
  3822. return this.__iterator(ITERATE_KEYS);
  3823. },
  3824. map: function(mapper, context) {
  3825. return reify(this, mapFactory(this, mapper, context));
  3826. },
  3827. reduce: function(reducer, initialReduction, context) {
  3828. assertNotInfinite(this.size);
  3829. var reduction;
  3830. var useFirst;
  3831. if (arguments.length < 2) {
  3832. useFirst = true;
  3833. } else {
  3834. reduction = initialReduction;
  3835. }
  3836. this.__iterate(function(v, k, c) {
  3837. if (useFirst) {
  3838. useFirst = false;
  3839. reduction = v;
  3840. } else {
  3841. reduction = reducer.call(context, reduction, v, k, c);
  3842. }
  3843. });
  3844. return reduction;
  3845. },
  3846. reduceRight: function(reducer, initialReduction, context) {
  3847. var reversed = this.toKeyedSeq().reverse();
  3848. return reversed.reduce.apply(reversed, arguments);
  3849. },
  3850. reverse: function() {
  3851. return reify(this, reverseFactory(this, true));
  3852. },
  3853. slice: function(begin, end) {
  3854. return reify(this, sliceFactory(this, begin, end, true));
  3855. },
  3856. some: function(predicate, context) {
  3857. return !this.every(not(predicate), context);
  3858. },
  3859. sort: function(comparator) {
  3860. return reify(this, sortFactory(this, comparator));
  3861. },
  3862. values: function() {
  3863. return this.__iterator(ITERATE_VALUES);
  3864. },
  3865. // ### More sequential methods
  3866. butLast: function() {
  3867. return this.slice(0, -1);
  3868. },
  3869. isEmpty: function() {
  3870. return this.size !== undefined ? this.size === 0 : !this.some(function() {return true});
  3871. },
  3872. count: function(predicate, context) {
  3873. return ensureSize(
  3874. predicate ? this.toSeq().filter(predicate, context) : this
  3875. );
  3876. },
  3877. countBy: function(grouper, context) {
  3878. return countByFactory(this, grouper, context);
  3879. },
  3880. equals: function(other) {
  3881. return deepEqual(this, other);
  3882. },
  3883. entrySeq: function() {
  3884. var iterable = this;
  3885. if (iterable._cache) {
  3886. // We cache as an entries array, so we can just return the cache!
  3887. return new ArraySeq(iterable._cache);
  3888. }
  3889. var entriesSequence = iterable.toSeq().map(entryMapper).toIndexedSeq();
  3890. entriesSequence.fromEntrySeq = function() {return iterable.toSeq()};
  3891. return entriesSequence;
  3892. },
  3893. filterNot: function(predicate, context) {
  3894. return this.filter(not(predicate), context);
  3895. },
  3896. findLast: function(predicate, context, notSetValue) {
  3897. return this.toKeyedSeq().reverse().find(predicate, context, notSetValue);
  3898. },
  3899. first: function() {
  3900. return this.find(returnTrue);
  3901. },
  3902. flatMap: function(mapper, context) {
  3903. return reify(this, flatMapFactory(this, mapper, context));
  3904. },
  3905. flatten: function(depth) {
  3906. return reify(this, flattenFactory(this, depth, true));
  3907. },
  3908. fromEntrySeq: function() {
  3909. return new FromEntriesSequence(this);
  3910. },
  3911. get: function(searchKey, notSetValue) {
  3912. return this.find(function(_, key) {return is(key, searchKey)}, undefined, notSetValue);
  3913. },
  3914. getIn: function(searchKeyPath, notSetValue) {
  3915. var nested = this;
  3916. // Note: in an ES6 environment, we would prefer:
  3917. // for (var key of searchKeyPath) {
  3918. var iter = forceIterator(searchKeyPath);
  3919. var step;
  3920. while (!(step = iter.next()).done) {
  3921. var key = step.value;
  3922. nested = nested && nested.get ? nested.get(key, NOT_SET) : NOT_SET;
  3923. if (nested === NOT_SET) {
  3924. return notSetValue;
  3925. }
  3926. }
  3927. return nested;
  3928. },
  3929. groupBy: function(grouper, context) {
  3930. return groupByFactory(this, grouper, context);
  3931. },
  3932. has: function(searchKey) {
  3933. return this.get(searchKey, NOT_SET) !== NOT_SET;
  3934. },
  3935. hasIn: function(searchKeyPath) {
  3936. return this.getIn(searchKeyPath, NOT_SET) !== NOT_SET;
  3937. },
  3938. isSubset: function(iter) {
  3939. iter = typeof iter.includes === 'function' ? iter : Iterable(iter);
  3940. return this.every(function(value ) {return iter.includes(value)});
  3941. },
  3942. isSuperset: function(iter) {
  3943. iter = typeof iter.isSubset === 'function' ? iter : Iterable(iter);
  3944. return iter.isSubset(this);
  3945. },
  3946. keySeq: function() {
  3947. return this.toSeq().map(keyMapper).toIndexedSeq();
  3948. },
  3949. last: function() {
  3950. return this.toSeq().reverse().first();
  3951. },
  3952. max: function(comparator) {
  3953. return maxFactory(this, comparator);
  3954. },
  3955. maxBy: function(mapper, comparator) {
  3956. return maxFactory(this, comparator, mapper);
  3957. },
  3958. min: function(comparator) {
  3959. return maxFactory(this, comparator ? neg(comparator) : defaultNegComparator);
  3960. },
  3961. minBy: function(mapper, comparator) {
  3962. return maxFactory(this, comparator ? neg(comparator) : defaultNegComparator, mapper);
  3963. },
  3964. rest: function() {
  3965. return this.slice(1);
  3966. },
  3967. skip: function(amount) {
  3968. return this.slice(Math.max(0, amount));
  3969. },
  3970. skipLast: function(amount) {
  3971. return reify(this, this.toSeq().reverse().skip(amount).reverse());
  3972. },
  3973. skipWhile: function(predicate, context) {
  3974. return reify(this, skipWhileFactory(this, predicate, context, true));
  3975. },
  3976. skipUntil: function(predicate, context) {
  3977. return this.skipWhile(not(predicate), context);
  3978. },
  3979. sortBy: function(mapper, comparator) {
  3980. return reify(this, sortFactory(this, comparator, mapper));
  3981. },
  3982. take: function(amount) {
  3983. return this.slice(0, Math.max(0, amount));
  3984. },
  3985. takeLast: function(amount) {
  3986. return reify(this, this.toSeq().reverse().take(amount).reverse());
  3987. },
  3988. takeWhile: function(predicate, context) {
  3989. return reify(this, takeWhileFactory(this, predicate, context));
  3990. },
  3991. takeUntil: function(predicate, context) {
  3992. return this.takeWhile(not(predicate), context);
  3993. },
  3994. valueSeq: function() {
  3995. return this.toIndexedSeq();
  3996. },
  3997. // ### Hashable Object
  3998. hashCode: function() {
  3999. return this.__hash || (this.__hash = hashIterable(this));
  4000. }
  4001. // ### Internal
  4002. // abstract __iterate(fn, reverse)
  4003. // abstract __iterator(type, reverse)
  4004. });
  4005. // var IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
  4006. // var IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
  4007. // var IS_INDEXED_SENTINEL = '@@__IMMUTABLE_INDEXED__@@';
  4008. // var IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
  4009. var IterablePrototype = Iterable.prototype;
  4010. IterablePrototype[IS_ITERABLE_SENTINEL] = true;
  4011. IterablePrototype[ITERATOR_SYMBOL] = IterablePrototype.values;
  4012. IterablePrototype.__toJS = IterablePrototype.toArray;
  4013. IterablePrototype.__toStringMapper = quoteString;
  4014. IterablePrototype.inspect =
  4015. IterablePrototype.toSource = function() { return this.toString(); };
  4016. IterablePrototype.chain = IterablePrototype.flatMap;
  4017. IterablePrototype.contains = IterablePrototype.includes;
  4018. // Temporary warning about using length
  4019. (function () {
  4020. try {
  4021. Object.defineProperty(IterablePrototype, 'length', {
  4022. get: function () {
  4023. if (!Iterable.noLengthWarning) {
  4024. var stack;
  4025. try {
  4026. throw new Error();
  4027. } catch (error) {
  4028. stack = error.stack;
  4029. }
  4030. if (stack.indexOf('_wrapObject') === -1) {
  4031. console && console.warn && console.warn(
  4032. 'iterable.length has been deprecated, '+
  4033. 'use iterable.size or iterable.count(). '+
  4034. 'This warning will become a silent error in a future version. ' +
  4035. stack
  4036. );
  4037. return this.size;
  4038. }
  4039. }
  4040. }
  4041. });
  4042. } catch (e) {}
  4043. })();
  4044. mixin(KeyedIterable, {
  4045. // ### More sequential methods
  4046. flip: function() {
  4047. return reify(this, flipFactory(this));
  4048. },
  4049. findKey: function(predicate, context) {
  4050. var entry = this.findEntry(predicate, context);
  4051. return entry && entry[0];
  4052. },
  4053. findLastKey: function(predicate, context) {
  4054. return this.toSeq().reverse().findKey(predicate, context);
  4055. },
  4056. keyOf: function(searchValue) {
  4057. return this.findKey(function(value ) {return is(value, searchValue)});
  4058. },
  4059. lastKeyOf: function(searchValue) {
  4060. return this.findLastKey(function(value ) {return is(value, searchValue)});
  4061. },
  4062. mapEntries: function(mapper, context) {var this$0 = this;
  4063. var iterations = 0;
  4064. return reify(this,
  4065. this.toSeq().map(
  4066. function(v, k) {return mapper.call(context, [k, v], iterations++, this$0)}
  4067. ).fromEntrySeq()
  4068. );
  4069. },
  4070. mapKeys: function(mapper, context) {var this$0 = this;
  4071. return reify(this,
  4072. this.toSeq().flip().map(
  4073. function(k, v) {return mapper.call(context, k, v, this$0)}
  4074. ).flip()
  4075. );
  4076. }
  4077. });
  4078. var KeyedIterablePrototype = KeyedIterable.prototype;
  4079. KeyedIterablePrototype[IS_KEYED_SENTINEL] = true;
  4080. KeyedIterablePrototype[ITERATOR_SYMBOL] = IterablePrototype.entries;
  4081. KeyedIterablePrototype.__toJS = IterablePrototype.toObject;
  4082. KeyedIterablePrototype.__toStringMapper = function(v, k) {return JSON.stringify(k) + ': ' + quoteString(v)};
  4083. mixin(IndexedIterable, {
  4084. // ### Conversion to other types
  4085. toKeyedSeq: function() {
  4086. return new ToKeyedSequence(this, false);
  4087. },
  4088. // ### ES6 Collection methods (ES6 Array and Map)
  4089. filter: function(predicate, context) {
  4090. return reify(this, filterFactory(this, predicate, context, false));
  4091. },
  4092. findIndex: function(predicate, context) {
  4093. var entry = this.findEntry(predicate, context);
  4094. return entry ? entry[0] : -1;
  4095. },
  4096. indexOf: function(searchValue) {
  4097. var key = this.toKeyedSeq().keyOf(searchValue);
  4098. return key === undefined ? -1 : key;
  4099. },
  4100. lastIndexOf: function(searchValue) {
  4101. var key = this.toKeyedSeq().reverse().keyOf(searchValue);
  4102. return key === undefined ? -1 : key;
  4103. // var index =
  4104. // return this.toSeq().reverse().indexOf(searchValue);
  4105. },
  4106. reverse: function() {
  4107. return reify(this, reverseFactory(this, false));
  4108. },
  4109. slice: function(begin, end) {
  4110. return reify(this, sliceFactory(this, begin, end, false));
  4111. },
  4112. splice: function(index, removeNum /*, ...values*/) {
  4113. var numArgs = arguments.length;
  4114. removeNum = Math.max(removeNum | 0, 0);
  4115. if (numArgs === 0 || (numArgs === 2 && !removeNum)) {
  4116. return this;
  4117. }
  4118. // If index is negative, it should resolve relative to the size of the
  4119. // collection. However size may be expensive to compute if not cached, so
  4120. // only call count() if the number is in fact negative.
  4121. index = resolveBegin(index, index < 0 ? this.count() : this.size);
  4122. var spliced = this.slice(0, index);
  4123. return reify(
  4124. this,
  4125. numArgs === 1 ?
  4126. spliced :
  4127. spliced.concat(arrCopy(arguments, 2), this.slice(index + removeNum))
  4128. );
  4129. },
  4130. // ### More collection methods
  4131. findLastIndex: function(predicate, context) {
  4132. var key = this.toKeyedSeq().findLastKey(predicate, context);
  4133. return key === undefined ? -1 : key;
  4134. },
  4135. first: function() {
  4136. return this.get(0);
  4137. },
  4138. flatten: function(depth) {
  4139. return reify(this, flattenFactory(this, depth, false));
  4140. },
  4141. get: function(index, notSetValue) {
  4142. index = wrapIndex(this, index);
  4143. return (index < 0 || (this.size === Infinity ||
  4144. (this.size !== undefined && index > this.size))) ?
  4145. notSetValue :
  4146. this.find(function(_, key) {return key === index}, undefined, notSetValue);
  4147. },
  4148. has: function(index) {
  4149. index = wrapIndex(this, index);
  4150. return index >= 0 && (this.size !== undefined ?
  4151. this.size === Infinity || index < this.size :
  4152. this.indexOf(index) !== -1
  4153. );
  4154. },
  4155. interpose: function(separator) {
  4156. return reify(this, interposeFactory(this, separator));
  4157. },
  4158. interleave: function(/*...iterables*/) {
  4159. var iterables = [this].concat(arrCopy(arguments));
  4160. var zipped = zipWithFactory(this.toSeq(), IndexedSeq.of, iterables);
  4161. var interleaved = zipped.flatten(true);
  4162. if (zipped.size) {
  4163. interleaved.size = zipped.size * iterables.length;
  4164. }
  4165. return reify(this, interleaved);
  4166. },
  4167. last: function() {
  4168. return this.get(-1);
  4169. },
  4170. skipWhile: function(predicate, context) {
  4171. return reify(this, skipWhileFactory(this, predicate, context, false));
  4172. },
  4173. zip: function(/*, ...iterables */) {
  4174. var iterables = [this].concat(arrCopy(arguments));
  4175. return reify(this, zipWithFactory(this, defaultZipper, iterables));
  4176. },
  4177. zipWith: function(zipper/*, ...iterables */) {
  4178. var iterables = arrCopy(arguments);
  4179. iterables[0] = this;
  4180. return reify(this, zipWithFactory(this, zipper, iterables));
  4181. }
  4182. });
  4183. IndexedIterable.prototype[IS_INDEXED_SENTINEL] = true;
  4184. IndexedIterable.prototype[IS_ORDERED_SENTINEL] = true;
  4185. mixin(SetIterable, {
  4186. // ### ES6 Collection methods (ES6 Array and Map)
  4187. get: function(value, notSetValue) {
  4188. return this.has(value) ? value : notSetValue;
  4189. },
  4190. includes: function(value) {
  4191. return this.has(value);
  4192. },
  4193. // ### More sequential methods
  4194. keySeq: function() {
  4195. return this.valueSeq();
  4196. }
  4197. });
  4198. SetIterable.prototype.has = IterablePrototype.includes;
  4199. // Mixin subclasses
  4200. mixin(KeyedSeq, KeyedIterable.prototype);
  4201. mixin(IndexedSeq, IndexedIterable.prototype);
  4202. mixin(SetSeq, SetIterable.prototype);
  4203. mixin(KeyedCollection, KeyedIterable.prototype);
  4204. mixin(IndexedCollection, IndexedIterable.prototype);
  4205. mixin(SetCollection, SetIterable.prototype);
  4206. // #pragma Helper functions
  4207. function keyMapper(v, k) {
  4208. return k;
  4209. }
  4210. function entryMapper(v, k) {
  4211. return [k, v];
  4212. }
  4213. function not(predicate) {
  4214. return function() {
  4215. return !predicate.apply(this, arguments);
  4216. }
  4217. }
  4218. function neg(predicate) {
  4219. return function() {
  4220. return -predicate.apply(this, arguments);
  4221. }
  4222. }
  4223. function quoteString(value) {
  4224. return typeof value === 'string' ? JSON.stringify(value) : value;
  4225. }
  4226. function defaultZipper() {
  4227. return arrCopy(arguments);
  4228. }
  4229. function defaultNegComparator(a, b) {
  4230. return a < b ? 1 : a > b ? -1 : 0;
  4231. }
  4232. function hashIterable(iterable) {
  4233. if (iterable.size === Infinity) {
  4234. return 0;
  4235. }
  4236. var ordered = isOrdered(iterable);
  4237. var keyed = isKeyed(iterable);
  4238. var h = ordered ? 1 : 0;
  4239. var size = iterable.__iterate(
  4240. keyed ?
  4241. ordered ?
  4242. function(v, k) { h = 31 * h + hashMerge(hash(v), hash(k)) | 0; } :
  4243. function(v, k) { h = h + hashMerge(hash(v), hash(k)) | 0; } :
  4244. ordered ?
  4245. function(v ) { h = 31 * h + hash(v) | 0; } :
  4246. function(v ) { h = h + hash(v) | 0; }
  4247. );
  4248. return murmurHashOfSize(size, h);
  4249. }
  4250. function murmurHashOfSize(size, h) {
  4251. h = imul(h, 0xCC9E2D51);
  4252. h = imul(h << 15 | h >>> -15, 0x1B873593);
  4253. h = imul(h << 13 | h >>> -13, 5);
  4254. h = (h + 0xE6546B64 | 0) ^ size;
  4255. h = imul(h ^ h >>> 16, 0x85EBCA6B);
  4256. h = imul(h ^ h >>> 13, 0xC2B2AE35);
  4257. h = smi(h ^ h >>> 16);
  4258. return h;
  4259. }
  4260. function hashMerge(a, b) {
  4261. return a ^ b + 0x9E3779B9 + (a << 6) + (a >> 2) | 0; // int
  4262. }
  4263. var Immutable = {
  4264. Iterable: Iterable,
  4265. Seq: Seq,
  4266. Collection: Collection,
  4267. Map: Map,
  4268. OrderedMap: OrderedMap,
  4269. List: List,
  4270. Stack: Stack,
  4271. Set: Set,
  4272. OrderedSet: OrderedSet,
  4273. Record: Record,
  4274. Range: Range,
  4275. Repeat: Repeat,
  4276. is: is,
  4277. fromJS: fromJS
  4278. };
  4279. return Immutable;
  4280. }));
  4281. });
  4282. var OrderedMap = immutable.OrderedMap;
  4283. var BlockMapBuilder = {
  4284. createFromArray: function createFromArray(blocks) {
  4285. return OrderedMap(blocks.map(function (block) {
  4286. return [block.getKey(), block];
  4287. }));
  4288. }
  4289. };
  4290. var BlockMapBuilder_1 = BlockMapBuilder;
  4291. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4292. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  4293. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  4294. var Map = immutable.Map,
  4295. OrderedSet = immutable.OrderedSet,
  4296. Record = immutable.Record;
  4297. // Immutable.map is typed such that the value for every key in the map
  4298. // must be the same type
  4299. var EMPTY_SET = OrderedSet();
  4300. var defaultRecord = {
  4301. style: EMPTY_SET,
  4302. entity: null
  4303. };
  4304. var CharacterMetadataRecord = Record(defaultRecord);
  4305. var CharacterMetadata = function (_CharacterMetadataRec) {
  4306. _inherits(CharacterMetadata, _CharacterMetadataRec);
  4307. function CharacterMetadata() {
  4308. _classCallCheck(this, CharacterMetadata);
  4309. return _possibleConstructorReturn(this, _CharacterMetadataRec.apply(this, arguments));
  4310. }
  4311. CharacterMetadata.prototype.getStyle = function getStyle() {
  4312. return this.get('style');
  4313. };
  4314. CharacterMetadata.prototype.getEntity = function getEntity() {
  4315. return this.get('entity');
  4316. };
  4317. CharacterMetadata.prototype.hasStyle = function hasStyle(style) {
  4318. return this.getStyle().includes(style);
  4319. };
  4320. CharacterMetadata.applyStyle = function applyStyle(record, style) {
  4321. var withStyle = record.set('style', record.getStyle().add(style));
  4322. return CharacterMetadata.create(withStyle);
  4323. };
  4324. CharacterMetadata.removeStyle = function removeStyle(record, style) {
  4325. var withoutStyle = record.set('style', record.getStyle().remove(style));
  4326. return CharacterMetadata.create(withoutStyle);
  4327. };
  4328. CharacterMetadata.applyEntity = function applyEntity(record, entityKey) {
  4329. var withEntity = record.getEntity() === entityKey ? record : record.set('entity', entityKey);
  4330. return CharacterMetadata.create(withEntity);
  4331. };
  4332. /**
  4333. * Use this function instead of the `CharacterMetadata` constructor.
  4334. * Since most content generally uses only a very small number of
  4335. * style/entity permutations, we can reuse these objects as often as
  4336. * possible.
  4337. */
  4338. CharacterMetadata.create = function create(config) {
  4339. if (!config) {
  4340. return EMPTY;
  4341. }
  4342. var defaultConfig = {
  4343. style: EMPTY_SET,
  4344. entity: null
  4345. };
  4346. // Fill in unspecified properties, if necessary.
  4347. var configMap = Map(defaultConfig).merge(config);
  4348. var existing = pool.get(configMap);
  4349. if (existing) {
  4350. return existing;
  4351. }
  4352. var newCharacter = new CharacterMetadata(configMap);
  4353. pool = pool.set(configMap, newCharacter);
  4354. return newCharacter;
  4355. };
  4356. return CharacterMetadata;
  4357. }(CharacterMetadataRecord);
  4358. var EMPTY = new CharacterMetadata();
  4359. var pool = Map([[Map(defaultRecord), EMPTY]]);
  4360. CharacterMetadata.EMPTY = EMPTY;
  4361. var CharacterMetadata_1 = CharacterMetadata;
  4362. /**
  4363. * Copyright (c) 2013-present, Facebook, Inc.
  4364. * All rights reserved.
  4365. *
  4366. * This source code is licensed under the BSD-style license found in the
  4367. * LICENSE file in the root directory of this source tree. An additional grant
  4368. * of patent rights can be found in the PATENTS file in the same directory.
  4369. *
  4370. * @providesModule findRangesImmutable
  4371. * @format
  4372. *
  4373. */
  4374. /**
  4375. * Search through an array to find contiguous stretches of elements that
  4376. * match a specified filter function.
  4377. *
  4378. * When ranges are found, execute a specified `found` function to supply
  4379. * the values to the caller.
  4380. */
  4381. function findRangesImmutable(haystack, areEqualFn, filterFn, foundFn) {
  4382. if (!haystack.size) {
  4383. return;
  4384. }
  4385. var cursor = 0;
  4386. haystack.reduce(function (value, nextValue, nextIndex) {
  4387. if (!areEqualFn(value, nextValue)) {
  4388. if (filterFn(value)) {
  4389. foundFn(cursor, nextIndex);
  4390. }
  4391. cursor = nextIndex;
  4392. }
  4393. return nextValue;
  4394. });
  4395. filterFn(haystack.last()) && foundFn(cursor, haystack.count());
  4396. }
  4397. var findRangesImmutable_1 = findRangesImmutable;
  4398. function _classCallCheck$1(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4399. function _possibleConstructorReturn$1(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  4400. function _inherits$1(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  4401. var List = immutable.List,
  4402. Map$1 = immutable.Map,
  4403. OrderedSet$1 = immutable.OrderedSet,
  4404. Record$1 = immutable.Record,
  4405. Repeat = immutable.Repeat;
  4406. var EMPTY_SET$1 = OrderedSet$1();
  4407. var defaultRecord$1 = {
  4408. key: '',
  4409. type: 'unstyled',
  4410. text: '',
  4411. characterList: List(),
  4412. depth: 0,
  4413. data: Map$1()
  4414. };
  4415. var ContentBlockRecord = Record$1(defaultRecord$1);
  4416. var decorateCharacterList = function decorateCharacterList(config) {
  4417. if (!config) {
  4418. return config;
  4419. }
  4420. var characterList = config.characterList,
  4421. text = config.text;
  4422. if (text && !characterList) {
  4423. config.characterList = List(Repeat(CharacterMetadata_1.EMPTY, text.length));
  4424. }
  4425. return config;
  4426. };
  4427. var ContentBlock = function (_ContentBlockRecord) {
  4428. _inherits$1(ContentBlock, _ContentBlockRecord);
  4429. function ContentBlock(config) {
  4430. _classCallCheck$1(this, ContentBlock);
  4431. return _possibleConstructorReturn$1(this, _ContentBlockRecord.call(this, decorateCharacterList(config)));
  4432. }
  4433. ContentBlock.prototype.getKey = function getKey() {
  4434. return this.get('key');
  4435. };
  4436. ContentBlock.prototype.getType = function getType() {
  4437. return this.get('type');
  4438. };
  4439. ContentBlock.prototype.getText = function getText() {
  4440. return this.get('text');
  4441. };
  4442. ContentBlock.prototype.getCharacterList = function getCharacterList() {
  4443. return this.get('characterList');
  4444. };
  4445. ContentBlock.prototype.getLength = function getLength() {
  4446. return this.getText().length;
  4447. };
  4448. ContentBlock.prototype.getDepth = function getDepth() {
  4449. return this.get('depth');
  4450. };
  4451. ContentBlock.prototype.getData = function getData() {
  4452. return this.get('data');
  4453. };
  4454. ContentBlock.prototype.getInlineStyleAt = function getInlineStyleAt(offset) {
  4455. var character = this.getCharacterList().get(offset);
  4456. return character ? character.getStyle() : EMPTY_SET$1;
  4457. };
  4458. ContentBlock.prototype.getEntityAt = function getEntityAt(offset) {
  4459. var character = this.getCharacterList().get(offset);
  4460. return character ? character.getEntity() : null;
  4461. };
  4462. /**
  4463. * Execute a callback for every contiguous range of styles within the block.
  4464. */
  4465. ContentBlock.prototype.findStyleRanges = function findStyleRanges(filterFn, callback) {
  4466. findRangesImmutable_1(this.getCharacterList(), haveEqualStyle, filterFn, callback);
  4467. };
  4468. /**
  4469. * Execute a callback for every contiguous range of entities within the block.
  4470. */
  4471. ContentBlock.prototype.findEntityRanges = function findEntityRanges(filterFn, callback) {
  4472. findRangesImmutable_1(this.getCharacterList(), haveEqualEntity, filterFn, callback);
  4473. };
  4474. return ContentBlock;
  4475. }(ContentBlockRecord);
  4476. function haveEqualStyle(charA, charB) {
  4477. return charA.getStyle() === charB.getStyle();
  4478. }
  4479. function haveEqualEntity(charA, charB) {
  4480. return charA.getEntity() === charB.getEntity();
  4481. }
  4482. var ContentBlock_1 = ContentBlock;
  4483. function _classCallCheck$2(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4484. function _possibleConstructorReturn$2(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  4485. function _inherits$2(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  4486. var List$1 = immutable.List,
  4487. Map$2 = immutable.Map,
  4488. OrderedSet$2 = immutable.OrderedSet,
  4489. Record$2 = immutable.Record,
  4490. Repeat$1 = immutable.Repeat;
  4491. var EMPTY_SET$2 = OrderedSet$2();
  4492. var defaultRecord$2 = {
  4493. parent: null,
  4494. characterList: List$1(),
  4495. data: Map$2(),
  4496. depth: 0,
  4497. key: '',
  4498. text: '',
  4499. type: 'unstyled',
  4500. children: List$1(),
  4501. prevSibling: null,
  4502. nextSibling: null
  4503. };
  4504. var haveEqualStyle$1 = function haveEqualStyle(charA, charB) {
  4505. return charA.getStyle() === charB.getStyle();
  4506. };
  4507. var haveEqualEntity$1 = function haveEqualEntity(charA, charB) {
  4508. return charA.getEntity() === charB.getEntity();
  4509. };
  4510. var decorateCharacterList$1 = function decorateCharacterList(config) {
  4511. if (!config) {
  4512. return config;
  4513. }
  4514. var characterList = config.characterList,
  4515. text = config.text;
  4516. if (text && !characterList) {
  4517. config.characterList = List$1(Repeat$1(CharacterMetadata_1.EMPTY, text.length));
  4518. }
  4519. return config;
  4520. };
  4521. var ContentBlockNode = function (_Record) {
  4522. _inherits$2(ContentBlockNode, _Record);
  4523. function ContentBlockNode() {
  4524. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultRecord$2;
  4525. _classCallCheck$2(this, ContentBlockNode);
  4526. return _possibleConstructorReturn$2(this, _Record.call(this, decorateCharacterList$1(props)));
  4527. }
  4528. ContentBlockNode.prototype.getKey = function getKey() {
  4529. return this.get('key');
  4530. };
  4531. ContentBlockNode.prototype.getType = function getType() {
  4532. return this.get('type');
  4533. };
  4534. ContentBlockNode.prototype.getText = function getText() {
  4535. return this.get('text');
  4536. };
  4537. ContentBlockNode.prototype.getCharacterList = function getCharacterList() {
  4538. return this.get('characterList');
  4539. };
  4540. ContentBlockNode.prototype.getLength = function getLength() {
  4541. return this.getText().length;
  4542. };
  4543. ContentBlockNode.prototype.getDepth = function getDepth() {
  4544. return this.get('depth');
  4545. };
  4546. ContentBlockNode.prototype.getData = function getData() {
  4547. return this.get('data');
  4548. };
  4549. ContentBlockNode.prototype.getInlineStyleAt = function getInlineStyleAt(offset) {
  4550. var character = this.getCharacterList().get(offset);
  4551. return character ? character.getStyle() : EMPTY_SET$2;
  4552. };
  4553. ContentBlockNode.prototype.getEntityAt = function getEntityAt(offset) {
  4554. var character = this.getCharacterList().get(offset);
  4555. return character ? character.getEntity() : null;
  4556. };
  4557. ContentBlockNode.prototype.getChildKeys = function getChildKeys() {
  4558. return this.get('children');
  4559. };
  4560. ContentBlockNode.prototype.getParentKey = function getParentKey() {
  4561. return this.get('parent');
  4562. };
  4563. ContentBlockNode.prototype.getPrevSiblingKey = function getPrevSiblingKey() {
  4564. return this.get('prevSibling');
  4565. };
  4566. ContentBlockNode.prototype.getNextSiblingKey = function getNextSiblingKey() {
  4567. return this.get('nextSibling');
  4568. };
  4569. ContentBlockNode.prototype.findStyleRanges = function findStyleRanges(filterFn, callback) {
  4570. findRangesImmutable_1(this.getCharacterList(), haveEqualStyle$1, filterFn, callback);
  4571. };
  4572. ContentBlockNode.prototype.findEntityRanges = function findEntityRanges(filterFn, callback) {
  4573. findRangesImmutable_1(this.getCharacterList(), haveEqualEntity$1, filterFn, callback);
  4574. };
  4575. return ContentBlockNode;
  4576. }(Record$2(defaultRecord$2));
  4577. var ContentBlockNode_1 = ContentBlockNode;
  4578. /**
  4579. * Copyright 2013-present, Facebook, Inc.
  4580. * All rights reserved.
  4581. *
  4582. * This source code is licensed under the BSD-style license found in the
  4583. * LICENSE file in the root directory of this source tree. An additional grant
  4584. * of patent rights can be found in the PATENTS file in the same directory.
  4585. *
  4586. * @providesModule DraftFeatureFlags-core
  4587. * @format
  4588. *
  4589. */
  4590. var DraftFeatureFlags = {
  4591. draft_killswitch_allow_nontextnodes: false,
  4592. draft_segmented_entities_behavior: false,
  4593. draft_handlebeforeinput_composed_text: false,
  4594. draft_tree_data_support: false
  4595. };
  4596. var DraftFeatureFlagsCore = DraftFeatureFlags;
  4597. var DraftFeatureFlags_1 = DraftFeatureFlagsCore;
  4598. var Map$3 = immutable.Map;
  4599. var ContentStateInlineStyle = {
  4600. add: function add(contentState, selectionState, inlineStyle) {
  4601. return modifyInlineStyle(contentState, selectionState, inlineStyle, true);
  4602. },
  4603. remove: function remove(contentState, selectionState, inlineStyle) {
  4604. return modifyInlineStyle(contentState, selectionState, inlineStyle, false);
  4605. }
  4606. };
  4607. function modifyInlineStyle(contentState, selectionState, inlineStyle, addOrRemove) {
  4608. var blockMap = contentState.getBlockMap();
  4609. var startKey = selectionState.getStartKey();
  4610. var startOffset = selectionState.getStartOffset();
  4611. var endKey = selectionState.getEndKey();
  4612. var endOffset = selectionState.getEndOffset();
  4613. var newBlocks = blockMap.skipUntil(function (_, k) {
  4614. return k === startKey;
  4615. }).takeUntil(function (_, k) {
  4616. return k === endKey;
  4617. }).concat(Map$3([[endKey, blockMap.get(endKey)]])).map(function (block, blockKey) {
  4618. var sliceStart;
  4619. var sliceEnd;
  4620. if (startKey === endKey) {
  4621. sliceStart = startOffset;
  4622. sliceEnd = endOffset;
  4623. } else {
  4624. sliceStart = blockKey === startKey ? startOffset : 0;
  4625. sliceEnd = blockKey === endKey ? endOffset : block.getLength();
  4626. }
  4627. var chars = block.getCharacterList();
  4628. var current;
  4629. while (sliceStart < sliceEnd) {
  4630. current = chars.get(sliceStart);
  4631. chars = chars.set(sliceStart, addOrRemove ? CharacterMetadata_1.applyStyle(current, inlineStyle) : CharacterMetadata_1.removeStyle(current, inlineStyle));
  4632. sliceStart++;
  4633. }
  4634. return block.set('characterList', chars);
  4635. });
  4636. return contentState.merge({
  4637. blockMap: blockMap.merge(newBlocks),
  4638. selectionBefore: selectionState,
  4639. selectionAfter: selectionState
  4640. });
  4641. }
  4642. var ContentStateInlineStyle_1 = ContentStateInlineStyle;
  4643. function applyEntityToContentBlock(contentBlock, start, end, entityKey) {
  4644. var characterList = contentBlock.getCharacterList();
  4645. while (start < end) {
  4646. characterList = characterList.set(start, CharacterMetadata_1.applyEntity(characterList.get(start), entityKey));
  4647. start++;
  4648. }
  4649. return contentBlock.set('characterList', characterList);
  4650. }
  4651. var applyEntityToContentBlock_1 = applyEntityToContentBlock;
  4652. function applyEntityToContentState(contentState, selectionState, entityKey) {
  4653. var blockMap = contentState.getBlockMap();
  4654. var startKey = selectionState.getStartKey();
  4655. var startOffset = selectionState.getStartOffset();
  4656. var endKey = selectionState.getEndKey();
  4657. var endOffset = selectionState.getEndOffset();
  4658. var newBlocks = blockMap.skipUntil(function (_, k) {
  4659. return k === startKey;
  4660. }).takeUntil(function (_, k) {
  4661. return k === endKey;
  4662. }).toOrderedMap().merge(immutable.OrderedMap([[endKey, blockMap.get(endKey)]])).map(function (block, blockKey) {
  4663. var sliceStart = blockKey === startKey ? startOffset : 0;
  4664. var sliceEnd = blockKey === endKey ? endOffset : block.getLength();
  4665. return applyEntityToContentBlock_1(block, sliceStart, sliceEnd, entityKey);
  4666. });
  4667. return contentState.merge({
  4668. blockMap: blockMap.merge(newBlocks),
  4669. selectionBefore: selectionState,
  4670. selectionAfter: selectionState
  4671. });
  4672. }
  4673. var applyEntityToContentState_1 = applyEntityToContentState;
  4674. /**
  4675. * Copyright (c) 2013-present, Facebook, Inc.
  4676. * All rights reserved.
  4677. *
  4678. * This source code is licensed under the BSD-style license found in the
  4679. * LICENSE file in the root directory of this source tree. An additional grant
  4680. * of patent rights can be found in the PATENTS file in the same directory.
  4681. *
  4682. * @providesModule DraftEntitySegments
  4683. * @format
  4684. *
  4685. */
  4686. /**
  4687. * Identify the range to delete from a segmented entity.
  4688. *
  4689. * Rules:
  4690. *
  4691. * Example: 'John F. Kennedy'
  4692. *
  4693. * - Deletion from within any non-whitespace (i.e. ['John', 'F.', 'Kennedy'])
  4694. * will return the range of that text.
  4695. *
  4696. * 'John F. Kennedy' -> 'John F.'
  4697. * ^
  4698. *
  4699. * - Forward deletion of whitespace will remove the following section:
  4700. *
  4701. * 'John F. Kennedy' -> 'John Kennedy'
  4702. * ^
  4703. *
  4704. * - Backward deletion of whitespace will remove the previous section:
  4705. *
  4706. * 'John F. Kennedy' -> 'F. Kennedy'
  4707. * ^
  4708. */
  4709. var DraftEntitySegments = {
  4710. getRemovalRange: function getRemovalRange(selectionStart, selectionEnd, text, entityStart, direction) {
  4711. var segments = text.split(' ');
  4712. segments = segments.map(function ( /*string*/segment, /*number*/ii) {
  4713. if (direction === 'forward') {
  4714. if (ii > 0) {
  4715. return ' ' + segment;
  4716. }
  4717. } else if (ii < segments.length - 1) {
  4718. return segment + ' ';
  4719. }
  4720. return segment;
  4721. });
  4722. var segmentStart = entityStart;
  4723. var segmentEnd;
  4724. var segment;
  4725. var removalStart = null;
  4726. var removalEnd = null;
  4727. for (var jj = 0; jj < segments.length; jj++) {
  4728. segment = segments[jj];
  4729. segmentEnd = segmentStart + segment.length;
  4730. // Our selection overlaps this segment.
  4731. if (selectionStart < segmentEnd && segmentStart < selectionEnd) {
  4732. if (removalStart !== null) {
  4733. removalEnd = segmentEnd;
  4734. } else {
  4735. removalStart = segmentStart;
  4736. removalEnd = segmentEnd;
  4737. }
  4738. } else if (removalStart !== null) {
  4739. break;
  4740. }
  4741. segmentStart = segmentEnd;
  4742. }
  4743. var entityEnd = entityStart + text.length;
  4744. var atStart = removalStart === entityStart;
  4745. var atEnd = removalEnd === entityEnd;
  4746. if (!atStart && atEnd || atStart && !atEnd) {
  4747. if (direction === 'forward') {
  4748. if (removalEnd !== entityEnd) {
  4749. removalEnd++;
  4750. }
  4751. } else if (removalStart !== entityStart) {
  4752. removalStart--;
  4753. }
  4754. }
  4755. return {
  4756. start: removalStart,
  4757. end: removalEnd
  4758. };
  4759. }
  4760. };
  4761. var DraftEntitySegments_1 = DraftEntitySegments;
  4762. /**
  4763. * Copyright (c) 2013-present, Facebook, Inc.
  4764. *
  4765. * This source code is licensed under the MIT license found in the
  4766. * LICENSE file in the root directory of this source tree.
  4767. *
  4768. */
  4769. /**
  4770. * Use invariant() to assert state which your program assumes to be true.
  4771. *
  4772. * Provide sprintf-style format (only %s is supported) and arguments
  4773. * to provide information about what broke and what you were
  4774. * expecting.
  4775. *
  4776. * The invariant message will be stripped in production, but the invariant
  4777. * will remain to ensure logic does not differ in production.
  4778. */
  4779. var validateFormat = function validateFormat(format) {};
  4780. if (process.env.NODE_ENV !== 'production') {
  4781. validateFormat = function validateFormat(format) {
  4782. if (format === undefined) {
  4783. throw new Error('invariant requires an error message argument');
  4784. }
  4785. };
  4786. }
  4787. function invariant(condition, format, a, b, c, d, e, f) {
  4788. validateFormat(format);
  4789. if (!condition) {
  4790. var error;
  4791. if (format === undefined) {
  4792. error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
  4793. } else {
  4794. var args = [a, b, c, d, e, f];
  4795. var argIndex = 0;
  4796. error = new Error(format.replace(/%s/g, function () {
  4797. return args[argIndex++];
  4798. }));
  4799. error.name = 'Invariant Violation';
  4800. }
  4801. error.framesToPop = 1; // we don't care about invariant's own frame
  4802. throw error;
  4803. }
  4804. }
  4805. var invariant_1 = invariant;
  4806. /**
  4807. * Obtain the start and end positions of the range that has the
  4808. * specified entity applied to it.
  4809. *
  4810. * Entity keys are applied only to contiguous stretches of text, so this
  4811. * method searches for the first instance of the entity key and returns
  4812. * the subsequent range.
  4813. */
  4814. function getRangesForDraftEntity(block, key) {
  4815. var ranges = [];
  4816. block.findEntityRanges(function (c) {
  4817. return c.getEntity() === key;
  4818. }, function (start, end) {
  4819. ranges.push({ start: start, end: end });
  4820. });
  4821. !!!ranges.length ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Entity key not found in this range.') : invariant_1(false) : void 0;
  4822. return ranges;
  4823. }
  4824. var getRangesForDraftEntity_1 = getRangesForDraftEntity;
  4825. /**
  4826. * Given a SelectionState and a removal direction, determine the entire range
  4827. * that should be removed from a ContentState. This is based on any entities
  4828. * within the target, with their `mutability` values taken into account.
  4829. *
  4830. * For instance, if we are attempting to remove part of an "immutable" entity
  4831. * range, the entire entity must be removed. The returned `SelectionState`
  4832. * will be adjusted accordingly.
  4833. */
  4834. function getCharacterRemovalRange(entityMap, startBlock, endBlock, selectionState, direction) {
  4835. var start = selectionState.getStartOffset();
  4836. var end = selectionState.getEndOffset();
  4837. var startEntityKey = startBlock.getEntityAt(start);
  4838. var endEntityKey = endBlock.getEntityAt(end - 1);
  4839. if (!startEntityKey && !endEntityKey) {
  4840. return selectionState;
  4841. }
  4842. var newSelectionState = selectionState;
  4843. if (startEntityKey && startEntityKey === endEntityKey) {
  4844. newSelectionState = getEntityRemovalRange(entityMap, startBlock, newSelectionState, direction, startEntityKey, true, true);
  4845. } else if (startEntityKey && endEntityKey) {
  4846. var startSelectionState = getEntityRemovalRange(entityMap, startBlock, newSelectionState, direction, startEntityKey, false, true);
  4847. var endSelectionState = getEntityRemovalRange(entityMap, endBlock, newSelectionState, direction, endEntityKey, false, false);
  4848. newSelectionState = newSelectionState.merge({
  4849. anchorOffset: startSelectionState.getAnchorOffset(),
  4850. focusOffset: endSelectionState.getFocusOffset(),
  4851. isBackward: false
  4852. });
  4853. } else if (startEntityKey) {
  4854. var _startSelectionState = getEntityRemovalRange(entityMap, startBlock, newSelectionState, direction, startEntityKey, false, true);
  4855. newSelectionState = newSelectionState.merge({
  4856. anchorOffset: _startSelectionState.getStartOffset(),
  4857. isBackward: false
  4858. });
  4859. } else if (endEntityKey) {
  4860. var _endSelectionState = getEntityRemovalRange(entityMap, endBlock, newSelectionState, direction, endEntityKey, false, false);
  4861. newSelectionState = newSelectionState.merge({
  4862. focusOffset: _endSelectionState.getEndOffset(),
  4863. isBackward: false
  4864. });
  4865. }
  4866. return newSelectionState;
  4867. }
  4868. function getEntityRemovalRange(entityMap, block, selectionState, direction, entityKey, isEntireSelectionWithinEntity, isEntityAtStart) {
  4869. var start = selectionState.getStartOffset();
  4870. var end = selectionState.getEndOffset();
  4871. var entity = entityMap.__get(entityKey);
  4872. var mutability = entity.getMutability();
  4873. var sideToConsider = isEntityAtStart ? start : end;
  4874. // `MUTABLE` entities can just have the specified range of text removed
  4875. // directly. No adjustments are needed.
  4876. if (mutability === 'MUTABLE') {
  4877. return selectionState;
  4878. }
  4879. // Find the entity range that overlaps with our removal range.
  4880. var entityRanges = getRangesForDraftEntity_1(block, entityKey).filter(function (range) {
  4881. return sideToConsider <= range.end && sideToConsider >= range.start;
  4882. });
  4883. !(entityRanges.length == 1) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'There should only be one entity range within this removal range.') : invariant_1(false) : void 0;
  4884. var entityRange = entityRanges[0];
  4885. // For `IMMUTABLE` entity types, we will remove the entire entity range.
  4886. if (mutability === 'IMMUTABLE') {
  4887. return selectionState.merge({
  4888. anchorOffset: entityRange.start,
  4889. focusOffset: entityRange.end,
  4890. isBackward: false
  4891. });
  4892. }
  4893. // For `SEGMENTED` entity types, determine the appropriate segment to
  4894. // remove.
  4895. if (!isEntireSelectionWithinEntity) {
  4896. if (isEntityAtStart) {
  4897. end = entityRange.end;
  4898. } else {
  4899. start = entityRange.start;
  4900. }
  4901. }
  4902. var removalRange = DraftEntitySegments_1.getRemovalRange(start, end, block.getText().slice(entityRange.start, entityRange.end), entityRange.start, direction);
  4903. return selectionState.merge({
  4904. anchorOffset: removalRange.start,
  4905. focusOffset: removalRange.end,
  4906. isBackward: false
  4907. });
  4908. }
  4909. var getCharacterRemovalRange_1 = getCharacterRemovalRange;
  4910. /**
  4911. * Copyright (c) 2013-present, Facebook, Inc.
  4912. * All rights reserved.
  4913. *
  4914. * This source code is licensed under the BSD-style license found in the
  4915. * LICENSE file in the root directory of this source tree. An additional grant
  4916. * of patent rights can be found in the PATENTS file in the same directory.
  4917. *
  4918. * @providesModule generateRandomKey
  4919. * @format
  4920. *
  4921. */
  4922. var seenKeys = {};
  4923. var MULTIPLIER = Math.pow(2, 24);
  4924. function generateRandomKey() {
  4925. var key = void 0;
  4926. while (key === undefined || seenKeys.hasOwnProperty(key) || !isNaN(+key)) {
  4927. key = Math.floor(Math.random() * MULTIPLIER).toString(32);
  4928. }
  4929. seenKeys[key] = true;
  4930. return key;
  4931. }
  4932. var generateRandomKey_1 = generateRandomKey;
  4933. var OrderedMap$1 = immutable.OrderedMap;
  4934. var randomizeContentBlockNodeKeys = function randomizeContentBlockNodeKeys(blockMap) {
  4935. var newKeysRef = {};
  4936. // we keep track of root blocks in order to update subsequent sibling links
  4937. var lastRootBlock = void 0;
  4938. return OrderedMap$1(blockMap.withMutations(function (blockMapState) {
  4939. blockMapState.forEach(function (block, index) {
  4940. var oldKey = block.getKey();
  4941. var nextKey = block.getNextSiblingKey();
  4942. var prevKey = block.getPrevSiblingKey();
  4943. var childrenKeys = block.getChildKeys();
  4944. var parentKey = block.getParentKey();
  4945. // new key that we will use to build linking
  4946. var key = generateRandomKey_1();
  4947. // we will add it here to re-use it later
  4948. newKeysRef[oldKey] = key;
  4949. if (nextKey) {
  4950. var nextBlock = blockMapState.get(nextKey);
  4951. if (nextBlock) {
  4952. blockMapState.setIn([nextKey, 'prevSibling'], key);
  4953. } else {
  4954. // this can happen when generating random keys for fragments
  4955. blockMapState.setIn([oldKey, 'nextSibling'], null);
  4956. }
  4957. }
  4958. if (prevKey) {
  4959. var prevBlock = blockMapState.get(prevKey);
  4960. if (prevBlock) {
  4961. blockMapState.setIn([prevKey, 'nextSibling'], key);
  4962. } else {
  4963. // this can happen when generating random keys for fragments
  4964. blockMapState.setIn([oldKey, 'prevSibling'], null);
  4965. }
  4966. }
  4967. if (parentKey && blockMapState.get(parentKey)) {
  4968. var parentBlock = blockMapState.get(parentKey);
  4969. var parentChildrenList = parentBlock.getChildKeys();
  4970. blockMapState.setIn([parentKey, 'children'], parentChildrenList.set(parentChildrenList.indexOf(block.getKey()), key));
  4971. } else {
  4972. // blocks will then be treated as root block nodes
  4973. blockMapState.setIn([oldKey, 'parent'], null);
  4974. if (lastRootBlock) {
  4975. blockMapState.setIn([lastRootBlock.getKey(), 'nextSibling'], key);
  4976. blockMapState.setIn([oldKey, 'prevSibling'], newKeysRef[lastRootBlock.getKey()]);
  4977. }
  4978. lastRootBlock = blockMapState.get(oldKey);
  4979. }
  4980. childrenKeys.forEach(function (childKey) {
  4981. var childBlock = blockMapState.get(childKey);
  4982. if (childBlock) {
  4983. blockMapState.setIn([childKey, 'parent'], key);
  4984. } else {
  4985. blockMapState.setIn([oldKey, 'children'], block.getChildKeys().filter(function (child) {
  4986. return child !== childKey;
  4987. }));
  4988. }
  4989. });
  4990. });
  4991. }).toArray().map(function (block) {
  4992. return [newKeysRef[block.getKey()], block.set('key', newKeysRef[block.getKey()])];
  4993. }));
  4994. };
  4995. var randomizeContentBlockKeys = function randomizeContentBlockKeys(blockMap) {
  4996. return OrderedMap$1(blockMap.toArray().map(function (block) {
  4997. var key = generateRandomKey_1();
  4998. return [key, block.set('key', key)];
  4999. }));
  5000. };
  5001. var randomizeBlockMapKeys = function randomizeBlockMapKeys(blockMap) {
  5002. var isTreeBasedBlockMap = blockMap.first() instanceof ContentBlockNode_1;
  5003. if (!isTreeBasedBlockMap) {
  5004. return randomizeContentBlockKeys(blockMap);
  5005. }
  5006. return randomizeContentBlockNodeKeys(blockMap);
  5007. };
  5008. var randomizeBlockMapKeys_1 = randomizeBlockMapKeys;
  5009. function removeEntitiesAtEdges(contentState, selectionState) {
  5010. var blockMap = contentState.getBlockMap();
  5011. var entityMap = contentState.getEntityMap();
  5012. var updatedBlocks = {};
  5013. var startKey = selectionState.getStartKey();
  5014. var startOffset = selectionState.getStartOffset();
  5015. var startBlock = blockMap.get(startKey);
  5016. var updatedStart = removeForBlock(entityMap, startBlock, startOffset);
  5017. if (updatedStart !== startBlock) {
  5018. updatedBlocks[startKey] = updatedStart;
  5019. }
  5020. var endKey = selectionState.getEndKey();
  5021. var endOffset = selectionState.getEndOffset();
  5022. var endBlock = blockMap.get(endKey);
  5023. if (startKey === endKey) {
  5024. endBlock = updatedStart;
  5025. }
  5026. var updatedEnd = removeForBlock(entityMap, endBlock, endOffset);
  5027. if (updatedEnd !== endBlock) {
  5028. updatedBlocks[endKey] = updatedEnd;
  5029. }
  5030. if (!Object.keys(updatedBlocks).length) {
  5031. return contentState.set('selectionAfter', selectionState);
  5032. }
  5033. return contentState.merge({
  5034. blockMap: blockMap.merge(updatedBlocks),
  5035. selectionAfter: selectionState
  5036. });
  5037. }
  5038. function getRemovalRange(characters, key, offset) {
  5039. var removalRange;
  5040. findRangesImmutable_1(characters, function (a, b) {
  5041. return a.getEntity() === b.getEntity();
  5042. }, function (element) {
  5043. return element.getEntity() === key;
  5044. }, function (start, end) {
  5045. if (start <= offset && end >= offset) {
  5046. removalRange = { start: start, end: end };
  5047. }
  5048. });
  5049. !(typeof removalRange === 'object') ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Removal range must exist within character list.') : invariant_1(false) : void 0;
  5050. return removalRange;
  5051. }
  5052. function removeForBlock(entityMap, block, offset) {
  5053. var chars = block.getCharacterList();
  5054. var charBefore = offset > 0 ? chars.get(offset - 1) : undefined;
  5055. var charAfter = offset < chars.count() ? chars.get(offset) : undefined;
  5056. var entityBeforeCursor = charBefore ? charBefore.getEntity() : undefined;
  5057. var entityAfterCursor = charAfter ? charAfter.getEntity() : undefined;
  5058. if (entityAfterCursor && entityAfterCursor === entityBeforeCursor) {
  5059. var entity = entityMap.__get(entityAfterCursor);
  5060. if (entity.getMutability() !== 'MUTABLE') {
  5061. var _getRemovalRange = getRemovalRange(chars, entityAfterCursor, offset),
  5062. start = _getRemovalRange.start,
  5063. end = _getRemovalRange.end;
  5064. var current;
  5065. while (start < end) {
  5066. current = chars.get(start);
  5067. chars = chars.set(start, CharacterMetadata_1.applyEntity(current, null));
  5068. start++;
  5069. }
  5070. return block.set('characterList', chars);
  5071. }
  5072. }
  5073. return block;
  5074. }
  5075. var removeEntitiesAtEdges_1 = removeEntitiesAtEdges;
  5076. var getContentStateFragment = function getContentStateFragment(contentState, selectionState) {
  5077. var startKey = selectionState.getStartKey();
  5078. var startOffset = selectionState.getStartOffset();
  5079. var endKey = selectionState.getEndKey();
  5080. var endOffset = selectionState.getEndOffset();
  5081. // Edge entities should be stripped to ensure that we don't preserve
  5082. // invalid partial entities when the fragment is reused. We do, however,
  5083. // preserve entities that are entirely within the selection range.
  5084. var contentWithoutEdgeEntities = removeEntitiesAtEdges_1(contentState, selectionState);
  5085. var blockMap = contentWithoutEdgeEntities.getBlockMap();
  5086. var blockKeys = blockMap.keySeq();
  5087. var startIndex = blockKeys.indexOf(startKey);
  5088. var endIndex = blockKeys.indexOf(endKey) + 1;
  5089. return randomizeBlockMapKeys_1(blockMap.slice(startIndex, endIndex).map(function (block, blockKey) {
  5090. var text = block.getText();
  5091. var chars = block.getCharacterList();
  5092. if (startKey === endKey) {
  5093. return block.merge({
  5094. text: text.slice(startOffset, endOffset),
  5095. characterList: chars.slice(startOffset, endOffset)
  5096. });
  5097. }
  5098. if (blockKey === startKey) {
  5099. return block.merge({
  5100. text: text.slice(startOffset),
  5101. characterList: chars.slice(startOffset)
  5102. });
  5103. }
  5104. if (blockKey === endKey) {
  5105. return block.merge({
  5106. text: text.slice(0, endOffset),
  5107. characterList: chars.slice(0, endOffset)
  5108. });
  5109. }
  5110. return block;
  5111. }));
  5112. };
  5113. var getContentStateFragment_1 = getContentStateFragment;
  5114. /**
  5115. * Copyright (c) 2013-present, Facebook, Inc.
  5116. * All rights reserved.
  5117. *
  5118. * This source code is licensed under the BSD-style license found in the
  5119. * LICENSE file in the root directory of this source tree. An additional grant
  5120. * of patent rights can be found in the PATENTS file in the same directory.
  5121. *
  5122. * @providesModule insertIntoList
  5123. * @format
  5124. *
  5125. */
  5126. /**
  5127. * Maintain persistence for target list when appending and prepending.
  5128. */
  5129. function insertIntoList(targetList, toInsert, offset) {
  5130. if (offset === targetList.count()) {
  5131. toInsert.forEach(function (c) {
  5132. targetList = targetList.push(c);
  5133. });
  5134. } else if (offset === 0) {
  5135. toInsert.reverse().forEach(function (c) {
  5136. targetList = targetList.unshift(c);
  5137. });
  5138. } else {
  5139. var head = targetList.slice(0, offset);
  5140. var tail = targetList.slice(offset);
  5141. targetList = head.concat(toInsert, tail).toList();
  5142. }
  5143. return targetList;
  5144. }
  5145. var insertIntoList_1 = insertIntoList;
  5146. var List$2 = immutable.List;
  5147. var updateExistingBlock = function updateExistingBlock(contentState, selectionState, blockMap, fragmentBlock, targetKey, targetOffset) {
  5148. var targetBlock = blockMap.get(targetKey);
  5149. var text = targetBlock.getText();
  5150. var chars = targetBlock.getCharacterList();
  5151. var finalKey = targetKey;
  5152. var finalOffset = targetOffset + fragmentBlock.getText().length;
  5153. var newBlock = targetBlock.merge({
  5154. text: text.slice(0, targetOffset) + fragmentBlock.getText() + text.slice(targetOffset),
  5155. characterList: insertIntoList_1(chars, fragmentBlock.getCharacterList(), targetOffset),
  5156. data: fragmentBlock.getData()
  5157. });
  5158. return contentState.merge({
  5159. blockMap: blockMap.set(targetKey, newBlock),
  5160. selectionBefore: selectionState,
  5161. selectionAfter: selectionState.merge({
  5162. anchorKey: finalKey,
  5163. anchorOffset: finalOffset,
  5164. focusKey: finalKey,
  5165. focusOffset: finalOffset,
  5166. isBackward: false
  5167. })
  5168. });
  5169. };
  5170. /**
  5171. * Appends text/characterList from the fragment first block to
  5172. * target block.
  5173. */
  5174. var updateHead = function updateHead(block, targetOffset, fragment) {
  5175. var text = block.getText();
  5176. var chars = block.getCharacterList();
  5177. // Modify head portion of block.
  5178. var headText = text.slice(0, targetOffset);
  5179. var headCharacters = chars.slice(0, targetOffset);
  5180. var appendToHead = fragment.first();
  5181. return block.merge({
  5182. text: headText + appendToHead.getText(),
  5183. characterList: headCharacters.concat(appendToHead.getCharacterList()),
  5184. type: headText ? block.getType() : appendToHead.getType(),
  5185. data: appendToHead.getData()
  5186. });
  5187. };
  5188. /**
  5189. * Appends offset text/characterList from the target block to the last
  5190. * fragment block.
  5191. */
  5192. var updateTail = function updateTail(block, targetOffset, fragment) {
  5193. // Modify tail portion of block.
  5194. var text = block.getText();
  5195. var chars = block.getCharacterList();
  5196. // Modify head portion of block.
  5197. var blockSize = text.length;
  5198. var tailText = text.slice(targetOffset, blockSize);
  5199. var tailCharacters = chars.slice(targetOffset, blockSize);
  5200. var prependToTail = fragment.last();
  5201. return prependToTail.merge({
  5202. text: prependToTail.getText() + tailText,
  5203. characterList: prependToTail.getCharacterList().concat(tailCharacters),
  5204. data: prependToTail.getData()
  5205. });
  5206. };
  5207. var getRootBlocks = function getRootBlocks(block, blockMap) {
  5208. var headKey = block.getKey();
  5209. var rootBlock = block;
  5210. var rootBlocks = [];
  5211. // sometimes the fragment head block will not be part of the blockMap itself this can happen when
  5212. // the fragment head is used to update the target block, however when this does not happen we need
  5213. // to make sure that we include it on the rootBlocks since the first block of a fragment is always a
  5214. // fragment root block
  5215. if (blockMap.get(headKey)) {
  5216. rootBlocks.push(headKey);
  5217. }
  5218. while (rootBlock && rootBlock.getNextSiblingKey()) {
  5219. var lastSiblingKey = rootBlock.getNextSiblingKey();
  5220. if (!lastSiblingKey) {
  5221. break;
  5222. }
  5223. rootBlocks.push(lastSiblingKey);
  5224. rootBlock = blockMap.get(lastSiblingKey);
  5225. }
  5226. return rootBlocks;
  5227. };
  5228. var updateBlockMapLinks = function updateBlockMapLinks(blockMap, originalBlockMap, targetBlock, fragmentHeadBlock) {
  5229. return blockMap.withMutations(function (blockMapState) {
  5230. var targetKey = targetBlock.getKey();
  5231. var headKey = fragmentHeadBlock.getKey();
  5232. var targetNextKey = targetBlock.getNextSiblingKey();
  5233. var targetParentKey = targetBlock.getParentKey();
  5234. var fragmentRootBlocks = getRootBlocks(fragmentHeadBlock, blockMap);
  5235. var lastRootFragmentBlockKey = fragmentRootBlocks[fragmentRootBlocks.length - 1];
  5236. if (blockMapState.get(headKey)) {
  5237. // update the fragment head when it is part of the blockMap otherwise
  5238. blockMapState.setIn([targetKey, 'nextSibling'], headKey);
  5239. blockMapState.setIn([headKey, 'prevSibling'], targetKey);
  5240. } else {
  5241. // update the target block that had the fragment head contents merged into it
  5242. blockMapState.setIn([targetKey, 'nextSibling'], fragmentHeadBlock.getNextSiblingKey());
  5243. blockMapState.setIn([fragmentHeadBlock.getNextSiblingKey(), 'prevSibling'], targetKey);
  5244. }
  5245. // update the last root block fragment
  5246. blockMapState.setIn([lastRootFragmentBlockKey, 'nextSibling'], targetNextKey);
  5247. // update the original target next block
  5248. if (targetNextKey) {
  5249. blockMapState.setIn([targetNextKey, 'prevSibling'], lastRootFragmentBlockKey);
  5250. }
  5251. // update fragment parent links
  5252. fragmentRootBlocks.forEach(function (blockKey) {
  5253. return blockMapState.setIn([blockKey, 'parent'], targetParentKey);
  5254. });
  5255. // update targetBlock parent child links
  5256. if (targetParentKey) {
  5257. var targetParent = blockMap.get(targetParentKey);
  5258. var originalTargetParentChildKeys = targetParent.getChildKeys();
  5259. var targetBlockIndex = originalTargetParentChildKeys.indexOf(targetKey);
  5260. var insertionIndex = targetBlockIndex + 1;
  5261. var newChildrenKeysArray = originalTargetParentChildKeys.toArray();
  5262. // insert fragment children
  5263. newChildrenKeysArray.splice.apply(newChildrenKeysArray, [insertionIndex, 0].concat(fragmentRootBlocks));
  5264. blockMapState.setIn([targetParentKey, 'children'], List$2(newChildrenKeysArray));
  5265. }
  5266. });
  5267. };
  5268. var insertFragment = function insertFragment(contentState, selectionState, blockMap, fragment, targetKey, targetOffset) {
  5269. var isTreeBasedBlockMap = blockMap.first() instanceof ContentBlockNode_1;
  5270. var newBlockArr = [];
  5271. var fragmentSize = fragment.size;
  5272. var target = blockMap.get(targetKey);
  5273. var head = fragment.first();
  5274. var tail = fragment.last();
  5275. var finalOffset = tail.getLength();
  5276. var finalKey = tail.getKey();
  5277. var shouldNotUpdateFromFragmentBlock = isTreeBasedBlockMap && (!target.getChildKeys().isEmpty() || !head.getChildKeys().isEmpty());
  5278. blockMap.forEach(function (block, blockKey) {
  5279. if (blockKey !== targetKey) {
  5280. newBlockArr.push(block);
  5281. return;
  5282. }
  5283. if (shouldNotUpdateFromFragmentBlock) {
  5284. newBlockArr.push(block);
  5285. } else {
  5286. newBlockArr.push(updateHead(block, targetOffset, fragment));
  5287. }
  5288. // Insert fragment blocks after the head and before the tail.
  5289. fragment
  5290. // when we are updating the target block with the head fragment block we skip the first fragment
  5291. // head since its contents have already been merged with the target block otherwise we include
  5292. // the whole fragment
  5293. .slice(shouldNotUpdateFromFragmentBlock ? 0 : 1, fragmentSize - 1).forEach(function (fragmentBlock) {
  5294. return newBlockArr.push(fragmentBlock);
  5295. });
  5296. // update tail
  5297. newBlockArr.push(updateTail(block, targetOffset, fragment));
  5298. });
  5299. var updatedBlockMap = BlockMapBuilder_1.createFromArray(newBlockArr);
  5300. if (isTreeBasedBlockMap) {
  5301. updatedBlockMap = updateBlockMapLinks(updatedBlockMap, blockMap, target, head);
  5302. }
  5303. return contentState.merge({
  5304. blockMap: updatedBlockMap,
  5305. selectionBefore: selectionState,
  5306. selectionAfter: selectionState.merge({
  5307. anchorKey: finalKey,
  5308. anchorOffset: finalOffset,
  5309. focusKey: finalKey,
  5310. focusOffset: finalOffset,
  5311. isBackward: false
  5312. })
  5313. });
  5314. };
  5315. var insertFragmentIntoContentState = function insertFragmentIntoContentState(contentState, selectionState, fragmentBlockMap) {
  5316. !selectionState.isCollapsed() ? process.env.NODE_ENV !== 'production' ? invariant_1(false, '`insertFragment` should only be called with a collapsed selection state.') : invariant_1(false) : void 0;
  5317. var blockMap = contentState.getBlockMap();
  5318. var fragment = randomizeBlockMapKeys_1(fragmentBlockMap);
  5319. var targetKey = selectionState.getStartKey();
  5320. var targetOffset = selectionState.getStartOffset();
  5321. var targetBlock = blockMap.get(targetKey);
  5322. if (targetBlock instanceof ContentBlockNode_1) {
  5323. !targetBlock.getChildKeys().isEmpty() ? process.env.NODE_ENV !== 'production' ? invariant_1(false, '`insertFragment` should not be called when a container node is selected.') : invariant_1(false) : void 0;
  5324. }
  5325. // When we insert a fragment with a single block we simply update the target block
  5326. // with the contents of the inserted fragment block
  5327. if (fragment.size === 1) {
  5328. return updateExistingBlock(contentState, selectionState, blockMap, fragment.first(), targetKey, targetOffset);
  5329. }
  5330. return insertFragment(contentState, selectionState, blockMap, fragment, targetKey, targetOffset);
  5331. };
  5332. var insertFragmentIntoContentState_1 = insertFragmentIntoContentState;
  5333. var Repeat$2 = immutable.Repeat;
  5334. function insertTextIntoContentState(contentState, selectionState, text, characterMetadata) {
  5335. !selectionState.isCollapsed() ? process.env.NODE_ENV !== 'production' ? invariant_1(false, '`insertText` should only be called with a collapsed range.') : invariant_1(false) : void 0;
  5336. var len = text.length;
  5337. if (!len) {
  5338. return contentState;
  5339. }
  5340. var blockMap = contentState.getBlockMap();
  5341. var key = selectionState.getStartKey();
  5342. var offset = selectionState.getStartOffset();
  5343. var block = blockMap.get(key);
  5344. var blockText = block.getText();
  5345. var newBlock = block.merge({
  5346. text: blockText.slice(0, offset) + text + blockText.slice(offset, block.getLength()),
  5347. characterList: insertIntoList_1(block.getCharacterList(), Repeat$2(characterMetadata, len).toList(), offset)
  5348. });
  5349. var newOffset = offset + len;
  5350. return contentState.merge({
  5351. blockMap: blockMap.set(key, newBlock),
  5352. selectionAfter: selectionState.merge({
  5353. anchorOffset: newOffset,
  5354. focusOffset: newOffset
  5355. })
  5356. });
  5357. }
  5358. var insertTextIntoContentState_1 = insertTextIntoContentState;
  5359. var Map$4 = immutable.Map;
  5360. function modifyBlockForContentState(contentState, selectionState, operation) {
  5361. var startKey = selectionState.getStartKey();
  5362. var endKey = selectionState.getEndKey();
  5363. var blockMap = contentState.getBlockMap();
  5364. var newBlocks = blockMap.toSeq().skipUntil(function (_, k) {
  5365. return k === startKey;
  5366. }).takeUntil(function (_, k) {
  5367. return k === endKey;
  5368. }).concat(Map$4([[endKey, blockMap.get(endKey)]])).map(operation);
  5369. return contentState.merge({
  5370. blockMap: blockMap.merge(newBlocks),
  5371. selectionBefore: selectionState,
  5372. selectionAfter: selectionState
  5373. });
  5374. }
  5375. var modifyBlockForContentState_1 = modifyBlockForContentState;
  5376. /**
  5377. * Copyright (c) 2013-present, Facebook, Inc.
  5378. * All rights reserved.
  5379. *
  5380. * This source code is licensed under the BSD-style license found in the
  5381. * LICENSE file in the root directory of this source tree. An additional grant
  5382. * of patent rights can be found in the PATENTS file in the same directory.
  5383. *
  5384. * @providesModule getNextDelimiterBlockKey
  5385. * @format
  5386. *
  5387. *
  5388. * This is unstable and not part of the public API and should not be used by
  5389. * production systems. This file may be update/removed without notice.
  5390. */
  5391. var getNextDelimiterBlockKey = function getNextDelimiterBlockKey(block, blockMap) {
  5392. var isExperimentalTreeBlock = block instanceof ContentBlockNode_1;
  5393. if (!isExperimentalTreeBlock) {
  5394. return null;
  5395. }
  5396. var nextSiblingKey = block.getNextSiblingKey();
  5397. if (nextSiblingKey) {
  5398. return nextSiblingKey;
  5399. }
  5400. var parent = block.getParentKey();
  5401. if (!parent) {
  5402. return null;
  5403. }
  5404. var nextNonDescendantBlock = blockMap.get(parent);
  5405. while (nextNonDescendantBlock && !nextNonDescendantBlock.getNextSiblingKey()) {
  5406. var parentKey = nextNonDescendantBlock.getParentKey();
  5407. nextNonDescendantBlock = parentKey ? blockMap.get(parentKey) : null;
  5408. }
  5409. if (!nextNonDescendantBlock) {
  5410. return null;
  5411. }
  5412. return nextNonDescendantBlock.getNextSiblingKey();
  5413. };
  5414. var getNextDelimiterBlockKey_1 = getNextDelimiterBlockKey;
  5415. var List$3 = immutable.List,
  5416. Map$5 = immutable.Map;
  5417. var transformBlock = function transformBlock(key, blockMap, func) {
  5418. if (!key) {
  5419. return;
  5420. }
  5421. var block = blockMap.get(key);
  5422. if (!block) {
  5423. return;
  5424. }
  5425. blockMap.set(key, func(block));
  5426. };
  5427. /**
  5428. * Ancestors needs to be preserved when there are non selected
  5429. * children to make sure we do not leave any orphans behind
  5430. */
  5431. var getAncestorsKeys = function getAncestorsKeys(blockKey, blockMap) {
  5432. var parents = [];
  5433. if (!blockKey) {
  5434. return parents;
  5435. }
  5436. var blockNode = blockMap.get(blockKey);
  5437. while (blockNode && blockNode.getParentKey()) {
  5438. var parentKey = blockNode.getParentKey();
  5439. if (parentKey) {
  5440. parents.push(parentKey);
  5441. }
  5442. blockNode = parentKey ? blockMap.get(parentKey) : null;
  5443. }
  5444. return parents;
  5445. };
  5446. /**
  5447. * Get all next delimiter keys until we hit a root delimiter and return
  5448. * an array of key references
  5449. */
  5450. var getNextDelimitersBlockKeys = function getNextDelimitersBlockKeys(block, blockMap) {
  5451. var nextDelimiters = [];
  5452. if (!block) {
  5453. return nextDelimiters;
  5454. }
  5455. var nextDelimiter = getNextDelimiterBlockKey_1(block, blockMap);
  5456. while (nextDelimiter && blockMap.get(nextDelimiter)) {
  5457. var _block = blockMap.get(nextDelimiter);
  5458. nextDelimiters.push(nextDelimiter);
  5459. // we do not need to keep checking all root node siblings, just the first occurance
  5460. nextDelimiter = _block.getParentKey() ? getNextDelimiterBlockKey_1(_block, blockMap) : null;
  5461. }
  5462. return nextDelimiters;
  5463. };
  5464. var getNextValidSibling = function getNextValidSibling(block, blockMap, originalBlockMap) {
  5465. if (!block) {
  5466. return null;
  5467. }
  5468. // note that we need to make sure we refer to the original block since this
  5469. // function is called within a withMutations
  5470. var nextValidSiblingKey = originalBlockMap.get(block.getKey()).getNextSiblingKey();
  5471. while (nextValidSiblingKey && !blockMap.get(nextValidSiblingKey)) {
  5472. nextValidSiblingKey = originalBlockMap.get(nextValidSiblingKey).getNextSiblingKey() || null;
  5473. }
  5474. return nextValidSiblingKey;
  5475. };
  5476. var getPrevValidSibling = function getPrevValidSibling(block, blockMap, originalBlockMap) {
  5477. if (!block) {
  5478. return null;
  5479. }
  5480. // note that we need to make sure we refer to the original block since this
  5481. // function is called within a withMutations
  5482. var prevValidSiblingKey = originalBlockMap.get(block.getKey()).getPrevSiblingKey();
  5483. while (prevValidSiblingKey && !blockMap.get(prevValidSiblingKey)) {
  5484. prevValidSiblingKey = originalBlockMap.get(prevValidSiblingKey).getPrevSiblingKey() || null;
  5485. }
  5486. return prevValidSiblingKey;
  5487. };
  5488. var updateBlockMapLinks$1 = function updateBlockMapLinks(blockMap, startBlock, endBlock, originalBlockMap) {
  5489. return blockMap.withMutations(function (blocks) {
  5490. // update start block if its retained
  5491. transformBlock(startBlock.getKey(), blocks, function (block) {
  5492. return block.merge({
  5493. nextSibling: getNextValidSibling(startBlock, blocks, originalBlockMap),
  5494. prevSibling: getPrevValidSibling(startBlock, blocks, originalBlockMap)
  5495. });
  5496. });
  5497. // update endblock if its retained
  5498. transformBlock(endBlock.getKey(), blocks, function (block) {
  5499. return block.merge({
  5500. nextSibling: getNextValidSibling(endBlock, blocks, originalBlockMap),
  5501. prevSibling: getPrevValidSibling(endBlock, blocks, originalBlockMap)
  5502. });
  5503. });
  5504. // update start block parent ancestors
  5505. getAncestorsKeys(startBlock.getKey(), originalBlockMap).forEach(function (parentKey) {
  5506. return transformBlock(parentKey, blocks, function (block) {
  5507. return block.merge({
  5508. children: block.getChildKeys().filter(function (key) {
  5509. return blocks.get(key);
  5510. }),
  5511. nextSibling: getNextValidSibling(block, blocks, originalBlockMap),
  5512. prevSibling: getPrevValidSibling(block, blocks, originalBlockMap)
  5513. });
  5514. });
  5515. });
  5516. // update start block next - can only happen if startBlock == endBlock
  5517. transformBlock(startBlock.getNextSiblingKey(), blocks, function (block) {
  5518. return block.merge({
  5519. prevSibling: startBlock.getPrevSiblingKey()
  5520. });
  5521. });
  5522. // update start block prev
  5523. transformBlock(startBlock.getPrevSiblingKey(), blocks, function (block) {
  5524. return block.merge({
  5525. nextSibling: getNextValidSibling(startBlock, blocks, originalBlockMap)
  5526. });
  5527. });
  5528. // update end block next
  5529. transformBlock(endBlock.getNextSiblingKey(), blocks, function (block) {
  5530. return block.merge({
  5531. prevSibling: getPrevValidSibling(endBlock, blocks, originalBlockMap)
  5532. });
  5533. });
  5534. // update end block prev
  5535. transformBlock(endBlock.getPrevSiblingKey(), blocks, function (block) {
  5536. return block.merge({
  5537. nextSibling: endBlock.getNextSiblingKey()
  5538. });
  5539. });
  5540. // update end block parent ancestors
  5541. getAncestorsKeys(endBlock.getKey(), originalBlockMap).forEach(function (parentKey) {
  5542. transformBlock(parentKey, blocks, function (block) {
  5543. return block.merge({
  5544. children: block.getChildKeys().filter(function (key) {
  5545. return blocks.get(key);
  5546. }),
  5547. nextSibling: getNextValidSibling(block, blocks, originalBlockMap),
  5548. prevSibling: getPrevValidSibling(block, blocks, originalBlockMap)
  5549. });
  5550. });
  5551. });
  5552. // update next delimiters all the way to a root delimiter
  5553. getNextDelimitersBlockKeys(endBlock, originalBlockMap).forEach(function (delimiterKey) {
  5554. return transformBlock(delimiterKey, blocks, function (block) {
  5555. return block.merge({
  5556. nextSibling: getNextValidSibling(block, blocks, originalBlockMap),
  5557. prevSibling: getPrevValidSibling(block, blocks, originalBlockMap)
  5558. });
  5559. });
  5560. });
  5561. });
  5562. };
  5563. var removeRangeFromContentState = function removeRangeFromContentState(contentState, selectionState) {
  5564. if (selectionState.isCollapsed()) {
  5565. return contentState;
  5566. }
  5567. var blockMap = contentState.getBlockMap();
  5568. var startKey = selectionState.getStartKey();
  5569. var startOffset = selectionState.getStartOffset();
  5570. var endKey = selectionState.getEndKey();
  5571. var endOffset = selectionState.getEndOffset();
  5572. var startBlock = blockMap.get(startKey);
  5573. var endBlock = blockMap.get(endKey);
  5574. // we assume that ContentBlockNode and ContentBlocks are not mixed together
  5575. var isExperimentalTreeBlock = startBlock instanceof ContentBlockNode_1;
  5576. // used to retain blocks that should not be deleted to avoid orphan children
  5577. var parentAncestors = [];
  5578. if (isExperimentalTreeBlock) {
  5579. var endBlockchildrenKeys = endBlock.getChildKeys();
  5580. var endBlockAncestors = getAncestorsKeys(endKey, blockMap);
  5581. // endBlock has unselected sibblings so we can not remove its ancestors parents
  5582. if (endBlock.getNextSiblingKey()) {
  5583. parentAncestors = parentAncestors.concat(endBlockAncestors);
  5584. }
  5585. // endBlock has children so can not remove this block or any of its ancestors
  5586. if (!endBlockchildrenKeys.isEmpty()) {
  5587. parentAncestors = parentAncestors.concat(endBlockAncestors.concat([endKey]));
  5588. }
  5589. // we need to retain all ancestors of the next delimiter block
  5590. parentAncestors = parentAncestors.concat(getAncestorsKeys(getNextDelimiterBlockKey_1(endBlock, blockMap), blockMap));
  5591. }
  5592. var characterList = void 0;
  5593. if (startBlock === endBlock) {
  5594. characterList = removeFromList(startBlock.getCharacterList(), startOffset, endOffset);
  5595. } else {
  5596. characterList = startBlock.getCharacterList().slice(0, startOffset).concat(endBlock.getCharacterList().slice(endOffset));
  5597. }
  5598. var modifiedStart = startBlock.merge({
  5599. text: startBlock.getText().slice(0, startOffset) + endBlock.getText().slice(endOffset),
  5600. characterList: characterList
  5601. });
  5602. var newBlocks = blockMap.toSeq().skipUntil(function (_, k) {
  5603. return k === startKey;
  5604. }).takeUntil(function (_, k) {
  5605. return k === endKey;
  5606. }).filter(function (_, k) {
  5607. return parentAncestors.indexOf(k) === -1;
  5608. }).concat(Map$5([[endKey, null]])).map(function (_, k) {
  5609. return k === startKey ? modifiedStart : null;
  5610. });
  5611. var updatedBlockMap = blockMap.merge(newBlocks).filter(function (block) {
  5612. return !!block;
  5613. });
  5614. if (isExperimentalTreeBlock) {
  5615. updatedBlockMap = updateBlockMapLinks$1(updatedBlockMap, startBlock, endBlock, blockMap);
  5616. }
  5617. return contentState.merge({
  5618. blockMap: updatedBlockMap,
  5619. selectionBefore: selectionState,
  5620. selectionAfter: selectionState.merge({
  5621. anchorKey: startKey,
  5622. anchorOffset: startOffset,
  5623. focusKey: startKey,
  5624. focusOffset: startOffset,
  5625. isBackward: false
  5626. })
  5627. });
  5628. };
  5629. /**
  5630. * Maintain persistence for target list when removing characters on the
  5631. * head and tail of the character list.
  5632. */
  5633. var removeFromList = function removeFromList(targetList, startOffset, endOffset) {
  5634. if (startOffset === 0) {
  5635. while (startOffset < endOffset) {
  5636. targetList = targetList.shift();
  5637. startOffset++;
  5638. }
  5639. } else if (endOffset === targetList.count()) {
  5640. while (endOffset > startOffset) {
  5641. targetList = targetList.pop();
  5642. endOffset--;
  5643. }
  5644. } else {
  5645. var head = targetList.slice(0, startOffset);
  5646. var tail = targetList.slice(endOffset);
  5647. targetList = head.concat(tail).toList();
  5648. }
  5649. return targetList;
  5650. };
  5651. var removeRangeFromContentState_1 = removeRangeFromContentState;
  5652. var List$4 = immutable.List,
  5653. Map$6 = immutable.Map;
  5654. var transformBlock$1 = function transformBlock(key, blockMap, func) {
  5655. if (!key) {
  5656. return;
  5657. }
  5658. var block = blockMap.get(key);
  5659. if (!block) {
  5660. return;
  5661. }
  5662. blockMap.set(key, func(block));
  5663. };
  5664. var updateBlockMapLinks$2 = function updateBlockMapLinks(blockMap, originalBlock, belowBlock) {
  5665. return blockMap.withMutations(function (blocks) {
  5666. var originalBlockKey = originalBlock.getKey();
  5667. var belowBlockKey = belowBlock.getKey();
  5668. // update block parent
  5669. transformBlock$1(originalBlock.getParentKey(), blocks, function (block) {
  5670. var parentChildrenList = block.getChildKeys();
  5671. var insertionIndex = parentChildrenList.indexOf(originalBlockKey) + 1;
  5672. var newChildrenArray = parentChildrenList.toArray();
  5673. newChildrenArray.splice(insertionIndex, 0, belowBlockKey);
  5674. return block.merge({
  5675. children: List$4(newChildrenArray)
  5676. });
  5677. });
  5678. // update original next block
  5679. transformBlock$1(originalBlock.getNextSiblingKey(), blocks, function (block) {
  5680. return block.merge({
  5681. prevSibling: belowBlockKey
  5682. });
  5683. });
  5684. // update original block
  5685. transformBlock$1(originalBlockKey, blocks, function (block) {
  5686. return block.merge({
  5687. nextSibling: belowBlockKey
  5688. });
  5689. });
  5690. // update below block
  5691. transformBlock$1(belowBlockKey, blocks, function (block) {
  5692. return block.merge({
  5693. prevSibling: originalBlockKey
  5694. });
  5695. });
  5696. });
  5697. };
  5698. var splitBlockInContentState = function splitBlockInContentState(contentState, selectionState) {
  5699. !selectionState.isCollapsed() ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Selection range must be collapsed.') : invariant_1(false) : void 0;
  5700. var key = selectionState.getAnchorKey();
  5701. var offset = selectionState.getAnchorOffset();
  5702. var blockMap = contentState.getBlockMap();
  5703. var blockToSplit = blockMap.get(key);
  5704. var text = blockToSplit.getText();
  5705. var chars = blockToSplit.getCharacterList();
  5706. var keyBelow = generateRandomKey_1();
  5707. var isExperimentalTreeBlock = blockToSplit instanceof ContentBlockNode_1;
  5708. var blockAbove = blockToSplit.merge({
  5709. text: text.slice(0, offset),
  5710. characterList: chars.slice(0, offset)
  5711. });
  5712. var blockBelow = blockAbove.merge({
  5713. key: keyBelow,
  5714. text: text.slice(offset),
  5715. characterList: chars.slice(offset),
  5716. data: Map$6()
  5717. });
  5718. var blocksBefore = blockMap.toSeq().takeUntil(function (v) {
  5719. return v === blockToSplit;
  5720. });
  5721. var blocksAfter = blockMap.toSeq().skipUntil(function (v) {
  5722. return v === blockToSplit;
  5723. }).rest();
  5724. var newBlocks = blocksBefore.concat([[key, blockAbove], [keyBelow, blockBelow]], blocksAfter).toOrderedMap();
  5725. if (isExperimentalTreeBlock) {
  5726. !blockToSplit.getChildKeys().isEmpty() ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'ContentBlockNode must not have children') : invariant_1(false) : void 0;
  5727. newBlocks = updateBlockMapLinks$2(newBlocks, blockAbove, blockBelow);
  5728. }
  5729. return contentState.merge({
  5730. blockMap: newBlocks,
  5731. selectionBefore: selectionState,
  5732. selectionAfter: selectionState.merge({
  5733. anchorKey: keyBelow,
  5734. anchorOffset: 0,
  5735. focusKey: keyBelow,
  5736. focusOffset: 0,
  5737. isBackward: false
  5738. })
  5739. });
  5740. };
  5741. var splitBlockInContentState_1 = splitBlockInContentState;
  5742. var OrderedSet$3 = immutable.OrderedSet;
  5743. /**
  5744. * `DraftModifier` provides a set of convenience methods that apply
  5745. * modifications to a `ContentState` object based on a target `SelectionState`.
  5746. *
  5747. * Any change to a `ContentState` should be decomposable into a series of
  5748. * transaction functions that apply the required changes and return output
  5749. * `ContentState` objects.
  5750. *
  5751. * These functions encapsulate some of the most common transaction sequences.
  5752. */
  5753. var DraftModifier = {
  5754. replaceText: function replaceText(contentState, rangeToReplace, text, inlineStyle, entityKey) {
  5755. var withoutEntities = removeEntitiesAtEdges_1(contentState, rangeToReplace);
  5756. var withoutText = removeRangeFromContentState_1(withoutEntities, rangeToReplace);
  5757. var character = CharacterMetadata_1.create({
  5758. style: inlineStyle || OrderedSet$3(),
  5759. entity: entityKey || null
  5760. });
  5761. return insertTextIntoContentState_1(withoutText, withoutText.getSelectionAfter(), text, character);
  5762. },
  5763. insertText: function insertText(contentState, targetRange, text, inlineStyle, entityKey) {
  5764. !targetRange.isCollapsed() ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Target range must be collapsed for `insertText`.') : invariant_1(false) : void 0;
  5765. return DraftModifier.replaceText(contentState, targetRange, text, inlineStyle, entityKey);
  5766. },
  5767. moveText: function moveText(contentState, removalRange, targetRange) {
  5768. var movedFragment = getContentStateFragment_1(contentState, removalRange);
  5769. var afterRemoval = DraftModifier.removeRange(contentState, removalRange, 'backward');
  5770. return DraftModifier.replaceWithFragment(afterRemoval, targetRange, movedFragment);
  5771. },
  5772. replaceWithFragment: function replaceWithFragment(contentState, targetRange, fragment) {
  5773. var withoutEntities = removeEntitiesAtEdges_1(contentState, targetRange);
  5774. var withoutText = removeRangeFromContentState_1(withoutEntities, targetRange);
  5775. return insertFragmentIntoContentState_1(withoutText, withoutText.getSelectionAfter(), fragment);
  5776. },
  5777. removeRange: function removeRange(contentState, rangeToRemove, removalDirection) {
  5778. var startKey = void 0,
  5779. endKey = void 0,
  5780. startBlock = void 0,
  5781. endBlock = void 0;
  5782. if (rangeToRemove.getIsBackward()) {
  5783. rangeToRemove = rangeToRemove.merge({
  5784. anchorKey: rangeToRemove.getFocusKey(),
  5785. anchorOffset: rangeToRemove.getFocusOffset(),
  5786. focusKey: rangeToRemove.getAnchorKey(),
  5787. focusOffset: rangeToRemove.getAnchorOffset(),
  5788. isBackward: false
  5789. });
  5790. }
  5791. startKey = rangeToRemove.getAnchorKey();
  5792. endKey = rangeToRemove.getFocusKey();
  5793. startBlock = contentState.getBlockForKey(startKey);
  5794. endBlock = contentState.getBlockForKey(endKey);
  5795. var startOffset = rangeToRemove.getStartOffset();
  5796. var endOffset = rangeToRemove.getEndOffset();
  5797. var startEntityKey = startBlock.getEntityAt(startOffset);
  5798. var endEntityKey = endBlock.getEntityAt(endOffset - 1);
  5799. // Check whether the selection state overlaps with a single entity.
  5800. // If so, try to remove the appropriate substring of the entity text.
  5801. if (startKey === endKey) {
  5802. if (startEntityKey && startEntityKey === endEntityKey) {
  5803. var _adjustedRemovalRange = getCharacterRemovalRange_1(contentState.getEntityMap(), startBlock, endBlock, rangeToRemove, removalDirection);
  5804. return removeRangeFromContentState_1(contentState, _adjustedRemovalRange);
  5805. }
  5806. }
  5807. var adjustedRemovalRange = rangeToRemove;
  5808. var withoutEntities = removeEntitiesAtEdges_1(contentState, adjustedRemovalRange);
  5809. return removeRangeFromContentState_1(withoutEntities, adjustedRemovalRange);
  5810. },
  5811. splitBlock: function splitBlock(contentState, selectionState) {
  5812. var withoutEntities = removeEntitiesAtEdges_1(contentState, selectionState);
  5813. var withoutText = removeRangeFromContentState_1(withoutEntities, selectionState);
  5814. return splitBlockInContentState_1(withoutText, withoutText.getSelectionAfter());
  5815. },
  5816. applyInlineStyle: function applyInlineStyle(contentState, selectionState, inlineStyle) {
  5817. return ContentStateInlineStyle_1.add(contentState, selectionState, inlineStyle);
  5818. },
  5819. removeInlineStyle: function removeInlineStyle(contentState, selectionState, inlineStyle) {
  5820. return ContentStateInlineStyle_1.remove(contentState, selectionState, inlineStyle);
  5821. },
  5822. setBlockType: function setBlockType(contentState, selectionState, blockType) {
  5823. return modifyBlockForContentState_1(contentState, selectionState, function (block) {
  5824. return block.merge({ type: blockType, depth: 0 });
  5825. });
  5826. },
  5827. setBlockData: function setBlockData(contentState, selectionState, blockData) {
  5828. return modifyBlockForContentState_1(contentState, selectionState, function (block) {
  5829. return block.merge({ data: blockData });
  5830. });
  5831. },
  5832. mergeBlockData: function mergeBlockData(contentState, selectionState, blockData) {
  5833. return modifyBlockForContentState_1(contentState, selectionState, function (block) {
  5834. return block.merge({ data: block.getData().merge(blockData) });
  5835. });
  5836. },
  5837. applyEntity: function applyEntity(contentState, selectionState, entityKey) {
  5838. var withoutEntities = removeEntitiesAtEdges_1(contentState, selectionState);
  5839. return applyEntityToContentState_1(withoutEntities, selectionState, entityKey);
  5840. }
  5841. };
  5842. var DraftModifier_1 = DraftModifier;
  5843. /**
  5844. * Copyright (c) 2013-present, Facebook, Inc.
  5845. *
  5846. * This source code is licensed under the MIT license found in the
  5847. * LICENSE file in the root directory of this source tree.
  5848. *
  5849. *
  5850. */
  5851. function makeEmptyFunction(arg) {
  5852. return function () {
  5853. return arg;
  5854. };
  5855. }
  5856. /**
  5857. * This function accepts and discards inputs; it has no side effects. This is
  5858. * primarily useful idiomatically for overridable function endpoints which
  5859. * always need to be callable, since JS lacks a null-call idiom ala Cocoa.
  5860. */
  5861. var emptyFunction = function emptyFunction() {};
  5862. emptyFunction.thatReturns = makeEmptyFunction;
  5863. emptyFunction.thatReturnsFalse = makeEmptyFunction(false);
  5864. emptyFunction.thatReturnsTrue = makeEmptyFunction(true);
  5865. emptyFunction.thatReturnsNull = makeEmptyFunction(null);
  5866. emptyFunction.thatReturnsThis = function () {
  5867. return this;
  5868. };
  5869. emptyFunction.thatReturnsArgument = function (arg) {
  5870. return arg;
  5871. };
  5872. var emptyFunction_1 = emptyFunction;
  5873. var List$5 = immutable.List,
  5874. Repeat$3 = immutable.Repeat,
  5875. Record$3 = immutable.Record;
  5876. var returnTrue = emptyFunction_1.thatReturnsTrue;
  5877. var FINGERPRINT_DELIMITER = '-';
  5878. var defaultLeafRange = {
  5879. start: null,
  5880. end: null
  5881. };
  5882. var LeafRange = Record$3(defaultLeafRange);
  5883. var defaultDecoratorRange = {
  5884. start: null,
  5885. end: null,
  5886. decoratorKey: null,
  5887. leaves: null
  5888. };
  5889. var DecoratorRange = Record$3(defaultDecoratorRange);
  5890. var BlockTree = {
  5891. /**
  5892. * Generate a block tree for a given ContentBlock/decorator pair.
  5893. */
  5894. generate: function generate(contentState, block, decorator) {
  5895. var textLength = block.getLength();
  5896. if (!textLength) {
  5897. return List$5.of(new DecoratorRange({
  5898. start: 0,
  5899. end: 0,
  5900. decoratorKey: null,
  5901. leaves: List$5.of(new LeafRange({ start: 0, end: 0 }))
  5902. }));
  5903. }
  5904. var leafSets = [];
  5905. var decorations = decorator ? decorator.getDecorations(block, contentState) : List$5(Repeat$3(null, textLength));
  5906. var chars = block.getCharacterList();
  5907. findRangesImmutable_1(decorations, areEqual, returnTrue, function (start, end) {
  5908. leafSets.push(new DecoratorRange({
  5909. start: start,
  5910. end: end,
  5911. decoratorKey: decorations.get(start),
  5912. leaves: generateLeaves(chars.slice(start, end).toList(), start)
  5913. }));
  5914. });
  5915. return List$5(leafSets);
  5916. },
  5917. /**
  5918. * Create a string representation of the given tree map. This allows us
  5919. * to rapidly determine whether a tree has undergone a significant
  5920. * structural change.
  5921. */
  5922. getFingerprint: function getFingerprint(tree) {
  5923. return tree.map(function (leafSet) {
  5924. var decoratorKey = leafSet.get('decoratorKey');
  5925. var fingerprintString = decoratorKey !== null ? decoratorKey + '.' + (leafSet.get('end') - leafSet.get('start')) : '';
  5926. return '' + fingerprintString + '.' + leafSet.get('leaves').size;
  5927. }).join(FINGERPRINT_DELIMITER);
  5928. }
  5929. };
  5930. /**
  5931. * Generate LeafRange records for a given character list.
  5932. */
  5933. function generateLeaves(characters, offset) {
  5934. var leaves = [];
  5935. var inlineStyles = characters.map(function (c) {
  5936. return c.getStyle();
  5937. }).toList();
  5938. findRangesImmutable_1(inlineStyles, areEqual, returnTrue, function (start, end) {
  5939. leaves.push(new LeafRange({
  5940. start: start + offset,
  5941. end: end + offset
  5942. }));
  5943. });
  5944. return List$5(leaves);
  5945. }
  5946. function areEqual(a, b) {
  5947. return a === b;
  5948. }
  5949. var BlockTree_1 = BlockTree;
  5950. function _classCallCheck$3(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5951. function _possibleConstructorReturn$3(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  5952. function _inherits$3(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  5953. var Record$4 = immutable.Record;
  5954. var DraftEntityInstanceRecord = Record$4({
  5955. type: 'TOKEN',
  5956. mutability: 'IMMUTABLE',
  5957. data: Object
  5958. });
  5959. /**
  5960. * An instance of a document entity, consisting of a `type` and relevant
  5961. * `data`, metadata about the entity.
  5962. *
  5963. * For instance, a "link" entity might provide a URI, and a "mention"
  5964. * entity might provide the mentioned user's ID. These pieces of data
  5965. * may be used when rendering the entity as part of a ContentBlock DOM
  5966. * representation. For a link, the data would be used as an href for
  5967. * the rendered anchor. For a mention, the ID could be used to retrieve
  5968. * a hovercard.
  5969. */
  5970. var DraftEntityInstance = function (_DraftEntityInstanceR) {
  5971. _inherits$3(DraftEntityInstance, _DraftEntityInstanceR);
  5972. function DraftEntityInstance() {
  5973. _classCallCheck$3(this, DraftEntityInstance);
  5974. return _possibleConstructorReturn$3(this, _DraftEntityInstanceR.apply(this, arguments));
  5975. }
  5976. DraftEntityInstance.prototype.getType = function getType() {
  5977. return this.get('type');
  5978. };
  5979. DraftEntityInstance.prototype.getMutability = function getMutability() {
  5980. return this.get('mutability');
  5981. };
  5982. DraftEntityInstance.prototype.getData = function getData() {
  5983. return this.get('data');
  5984. };
  5985. return DraftEntityInstance;
  5986. }(DraftEntityInstanceRecord);
  5987. var DraftEntityInstance_1 = DraftEntityInstance;
  5988. var _extends = objectAssign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  5989. /**
  5990. * Copyright (c) 2013-present, Facebook, Inc.
  5991. * All rights reserved.
  5992. *
  5993. * This source code is licensed under the BSD-style license found in the
  5994. * LICENSE file in the root directory of this source tree. An additional grant
  5995. * of patent rights can be found in the PATENTS file in the same directory.
  5996. *
  5997. * @providesModule DraftEntity
  5998. * @format
  5999. *
  6000. */
  6001. var Map$7 = immutable.Map;
  6002. var instances = Map$7();
  6003. var instanceKey = 0;
  6004. /**
  6005. * Temporary utility for generating the warnings
  6006. */
  6007. function logWarning(oldMethodCall, newMethodCall) {
  6008. console.warn('WARNING: ' + oldMethodCall + ' will be deprecated soon!\nPlease use "' + newMethodCall + '" instead.');
  6009. }
  6010. /**
  6011. * A "document entity" is an object containing metadata associated with a
  6012. * piece of text in a ContentBlock.
  6013. *
  6014. * For example, a `link` entity might include a `uri` property. When a
  6015. * ContentBlock is rendered in the browser, text that refers to that link
  6016. * entity may be rendered as an anchor, with the `uri` as the href value.
  6017. *
  6018. * In a ContentBlock, every position in the text may correspond to zero
  6019. * or one entities. This correspondence is tracked using a key string,
  6020. * generated via DraftEntity.create() and used to obtain entity metadata
  6021. * via DraftEntity.get().
  6022. */
  6023. var DraftEntity = {
  6024. /**
  6025. * WARNING: This method will be deprecated soon!
  6026. * Please use 'contentState.getLastCreatedEntityKey' instead.
  6027. * ---
  6028. * Get the random key string from whatever entity was last created.
  6029. * We need this to support the new API, as part of transitioning to put Entity
  6030. * storage in contentState.
  6031. */
  6032. getLastCreatedEntityKey: function getLastCreatedEntityKey() {
  6033. logWarning('DraftEntity.getLastCreatedEntityKey', 'contentState.getLastCreatedEntityKey');
  6034. return DraftEntity.__getLastCreatedEntityKey();
  6035. },
  6036. /**
  6037. * WARNING: This method will be deprecated soon!
  6038. * Please use 'contentState.createEntity' instead.
  6039. * ---
  6040. * Create a DraftEntityInstance and store it for later retrieval.
  6041. *
  6042. * A random key string will be generated and returned. This key may
  6043. * be used to track the entity's usage in a ContentBlock, and for
  6044. * retrieving data about the entity at render time.
  6045. */
  6046. create: function create(type, mutability, data) {
  6047. logWarning('DraftEntity.create', 'contentState.createEntity');
  6048. return DraftEntity.__create(type, mutability, data);
  6049. },
  6050. /**
  6051. * WARNING: This method will be deprecated soon!
  6052. * Please use 'contentState.addEntity' instead.
  6053. * ---
  6054. * Add an existing DraftEntityInstance to the DraftEntity map. This is
  6055. * useful when restoring instances from the server.
  6056. */
  6057. add: function add(instance) {
  6058. logWarning('DraftEntity.add', 'contentState.addEntity');
  6059. return DraftEntity.__add(instance);
  6060. },
  6061. /**
  6062. * WARNING: This method will be deprecated soon!
  6063. * Please use 'contentState.getEntity' instead.
  6064. * ---
  6065. * Retrieve the entity corresponding to the supplied key string.
  6066. */
  6067. get: function get(key) {
  6068. logWarning('DraftEntity.get', 'contentState.getEntity');
  6069. return DraftEntity.__get(key);
  6070. },
  6071. /**
  6072. * WARNING: This method will be deprecated soon!
  6073. * Please use 'contentState.mergeEntityData' instead.
  6074. * ---
  6075. * Entity instances are immutable. If you need to update the data for an
  6076. * instance, this method will merge your data updates and return a new
  6077. * instance.
  6078. */
  6079. mergeData: function mergeData(key, toMerge) {
  6080. logWarning('DraftEntity.mergeData', 'contentState.mergeEntityData');
  6081. return DraftEntity.__mergeData(key, toMerge);
  6082. },
  6083. /**
  6084. * WARNING: This method will be deprecated soon!
  6085. * Please use 'contentState.replaceEntityData' instead.
  6086. * ---
  6087. * Completely replace the data for a given instance.
  6088. */
  6089. replaceData: function replaceData(key, newData) {
  6090. logWarning('DraftEntity.replaceData', 'contentState.replaceEntityData');
  6091. return DraftEntity.__replaceData(key, newData);
  6092. },
  6093. // ***********************************WARNING******************************
  6094. // --- the above public API will be deprecated in the next version of Draft!
  6095. // The methods below this line are private - don't call them directly.
  6096. /**
  6097. * Get the random key string from whatever entity was last created.
  6098. * We need this to support the new API, as part of transitioning to put Entity
  6099. * storage in contentState.
  6100. */
  6101. __getLastCreatedEntityKey: function __getLastCreatedEntityKey() {
  6102. return '' + instanceKey;
  6103. },
  6104. /**
  6105. * Create a DraftEntityInstance and store it for later retrieval.
  6106. *
  6107. * A random key string will be generated and returned. This key may
  6108. * be used to track the entity's usage in a ContentBlock, and for
  6109. * retrieving data about the entity at render time.
  6110. */
  6111. __create: function __create(type, mutability, data) {
  6112. return DraftEntity.__add(new DraftEntityInstance_1({ type: type, mutability: mutability, data: data || {} }));
  6113. },
  6114. /**
  6115. * Add an existing DraftEntityInstance to the DraftEntity map. This is
  6116. * useful when restoring instances from the server.
  6117. */
  6118. __add: function __add(instance) {
  6119. var key = '' + ++instanceKey;
  6120. instances = instances.set(key, instance);
  6121. return key;
  6122. },
  6123. /**
  6124. * Retrieve the entity corresponding to the supplied key string.
  6125. */
  6126. __get: function __get(key) {
  6127. var instance = instances.get(key);
  6128. !!!instance ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Unknown DraftEntity key: %s.', key) : invariant_1(false) : void 0;
  6129. return instance;
  6130. },
  6131. /**
  6132. * Entity instances are immutable. If you need to update the data for an
  6133. * instance, this method will merge your data updates and return a new
  6134. * instance.
  6135. */
  6136. __mergeData: function __mergeData(key, toMerge) {
  6137. var instance = DraftEntity.__get(key);
  6138. var newData = _extends({}, instance.getData(), toMerge);
  6139. var newInstance = instance.set('data', newData);
  6140. instances = instances.set(key, newInstance);
  6141. return newInstance;
  6142. },
  6143. /**
  6144. * Completely replace the data for a given instance.
  6145. */
  6146. __replaceData: function __replaceData(key, newData) {
  6147. var instance = DraftEntity.__get(key);
  6148. var newInstance = instance.set('data', newData);
  6149. instances = instances.set(key, newInstance);
  6150. return newInstance;
  6151. }
  6152. };
  6153. var DraftEntity_1 = DraftEntity;
  6154. function _classCallCheck$4(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6155. function _possibleConstructorReturn$4(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  6156. function _inherits$4(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  6157. var Record$5 = immutable.Record;
  6158. var defaultRecord$3 = {
  6159. anchorKey: '',
  6160. anchorOffset: 0,
  6161. focusKey: '',
  6162. focusOffset: 0,
  6163. isBackward: false,
  6164. hasFocus: false
  6165. };
  6166. var SelectionStateRecord = Record$5(defaultRecord$3);
  6167. var SelectionState = function (_SelectionStateRecord) {
  6168. _inherits$4(SelectionState, _SelectionStateRecord);
  6169. function SelectionState() {
  6170. _classCallCheck$4(this, SelectionState);
  6171. return _possibleConstructorReturn$4(this, _SelectionStateRecord.apply(this, arguments));
  6172. }
  6173. SelectionState.prototype.serialize = function serialize() {
  6174. return 'Anchor: ' + this.getAnchorKey() + ':' + this.getAnchorOffset() + ', ' + 'Focus: ' + this.getFocusKey() + ':' + this.getFocusOffset() + ', ' + 'Is Backward: ' + String(this.getIsBackward()) + ', ' + 'Has Focus: ' + String(this.getHasFocus());
  6175. };
  6176. SelectionState.prototype.getAnchorKey = function getAnchorKey() {
  6177. return this.get('anchorKey');
  6178. };
  6179. SelectionState.prototype.getAnchorOffset = function getAnchorOffset() {
  6180. return this.get('anchorOffset');
  6181. };
  6182. SelectionState.prototype.getFocusKey = function getFocusKey() {
  6183. return this.get('focusKey');
  6184. };
  6185. SelectionState.prototype.getFocusOffset = function getFocusOffset() {
  6186. return this.get('focusOffset');
  6187. };
  6188. SelectionState.prototype.getIsBackward = function getIsBackward() {
  6189. return this.get('isBackward');
  6190. };
  6191. SelectionState.prototype.getHasFocus = function getHasFocus() {
  6192. return this.get('hasFocus');
  6193. };
  6194. /**
  6195. * Return whether the specified range overlaps with an edge of the
  6196. * SelectionState.
  6197. */
  6198. SelectionState.prototype.hasEdgeWithin = function hasEdgeWithin(blockKey, start, end) {
  6199. var anchorKey = this.getAnchorKey();
  6200. var focusKey = this.getFocusKey();
  6201. if (anchorKey === focusKey && anchorKey === blockKey) {
  6202. var selectionStart = this.getStartOffset();
  6203. var selectionEnd = this.getEndOffset();
  6204. return start <= selectionEnd && selectionStart <= end;
  6205. }
  6206. if (blockKey !== anchorKey && blockKey !== focusKey) {
  6207. return false;
  6208. }
  6209. var offsetToCheck = blockKey === anchorKey ? this.getAnchorOffset() : this.getFocusOffset();
  6210. return start <= offsetToCheck && end >= offsetToCheck;
  6211. };
  6212. SelectionState.prototype.isCollapsed = function isCollapsed() {
  6213. return this.getAnchorKey() === this.getFocusKey() && this.getAnchorOffset() === this.getFocusOffset();
  6214. };
  6215. SelectionState.prototype.getStartKey = function getStartKey() {
  6216. return this.getIsBackward() ? this.getFocusKey() : this.getAnchorKey();
  6217. };
  6218. SelectionState.prototype.getStartOffset = function getStartOffset() {
  6219. return this.getIsBackward() ? this.getFocusOffset() : this.getAnchorOffset();
  6220. };
  6221. SelectionState.prototype.getEndKey = function getEndKey() {
  6222. return this.getIsBackward() ? this.getAnchorKey() : this.getFocusKey();
  6223. };
  6224. SelectionState.prototype.getEndOffset = function getEndOffset() {
  6225. return this.getIsBackward() ? this.getAnchorOffset() : this.getFocusOffset();
  6226. };
  6227. SelectionState.createEmpty = function createEmpty(key) {
  6228. return new SelectionState({
  6229. anchorKey: key,
  6230. anchorOffset: 0,
  6231. focusKey: key,
  6232. focusOffset: 0,
  6233. isBackward: false,
  6234. hasFocus: false
  6235. });
  6236. };
  6237. return SelectionState;
  6238. }(SelectionStateRecord);
  6239. var SelectionState_1 = SelectionState;
  6240. /**
  6241. * Copyright (c) 2013-present, Facebook, Inc.
  6242. * All rights reserved.
  6243. *
  6244. * This source code is licensed under the BSD-style license found in the
  6245. * LICENSE file in the root directory of this source tree. An additional grant
  6246. * of patent rights can be found in the PATENTS file in the same directory.
  6247. *
  6248. * @providesModule sanitizeDraftText
  6249. * @format
  6250. *
  6251. */
  6252. var REGEX_BLOCK_DELIMITER = new RegExp('\r', 'g');
  6253. function sanitizeDraftText(input) {
  6254. return input.replace(REGEX_BLOCK_DELIMITER, '');
  6255. }
  6256. var sanitizeDraftText_1 = sanitizeDraftText;
  6257. function _classCallCheck$5(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6258. function _possibleConstructorReturn$5(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  6259. function _inherits$5(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  6260. var List$6 = immutable.List,
  6261. Record$6 = immutable.Record,
  6262. Repeat$4 = immutable.Repeat;
  6263. var defaultRecord$4 = {
  6264. entityMap: null,
  6265. blockMap: null,
  6266. selectionBefore: null,
  6267. selectionAfter: null
  6268. };
  6269. var ContentBlockNodeRecord = ContentBlock_1;
  6270. var ContentStateRecord = Record$6(defaultRecord$4);
  6271. var ContentState = function (_ContentStateRecord) {
  6272. _inherits$5(ContentState, _ContentStateRecord);
  6273. function ContentState() {
  6274. _classCallCheck$5(this, ContentState);
  6275. return _possibleConstructorReturn$5(this, _ContentStateRecord.apply(this, arguments));
  6276. }
  6277. ContentState.prototype.getEntityMap = function getEntityMap() {
  6278. // TODO: update this when we fully remove DraftEntity
  6279. return DraftEntity_1;
  6280. };
  6281. ContentState.prototype.getBlockMap = function getBlockMap() {
  6282. return this.get('blockMap');
  6283. };
  6284. ContentState.prototype.getSelectionBefore = function getSelectionBefore() {
  6285. return this.get('selectionBefore');
  6286. };
  6287. ContentState.prototype.getSelectionAfter = function getSelectionAfter() {
  6288. return this.get('selectionAfter');
  6289. };
  6290. ContentState.prototype.getBlockForKey = function getBlockForKey(key) {
  6291. var block = this.getBlockMap().get(key);
  6292. return block;
  6293. };
  6294. ContentState.prototype.getKeyBefore = function getKeyBefore(key) {
  6295. return this.getBlockMap().reverse().keySeq().skipUntil(function (v) {
  6296. return v === key;
  6297. }).skip(1).first();
  6298. };
  6299. ContentState.prototype.getKeyAfter = function getKeyAfter(key) {
  6300. return this.getBlockMap().keySeq().skipUntil(function (v) {
  6301. return v === key;
  6302. }).skip(1).first();
  6303. };
  6304. ContentState.prototype.getBlockAfter = function getBlockAfter(key) {
  6305. return this.getBlockMap().skipUntil(function (_, k) {
  6306. return k === key;
  6307. }).skip(1).first();
  6308. };
  6309. ContentState.prototype.getBlockBefore = function getBlockBefore(key) {
  6310. return this.getBlockMap().reverse().skipUntil(function (_, k) {
  6311. return k === key;
  6312. }).skip(1).first();
  6313. };
  6314. ContentState.prototype.getBlocksAsArray = function getBlocksAsArray() {
  6315. return this.getBlockMap().toArray();
  6316. };
  6317. ContentState.prototype.getFirstBlock = function getFirstBlock() {
  6318. return this.getBlockMap().first();
  6319. };
  6320. ContentState.prototype.getLastBlock = function getLastBlock() {
  6321. return this.getBlockMap().last();
  6322. };
  6323. ContentState.prototype.getPlainText = function getPlainText(delimiter) {
  6324. return this.getBlockMap().map(function (block) {
  6325. return block ? block.getText() : '';
  6326. }).join(delimiter || '\n');
  6327. };
  6328. ContentState.prototype.getLastCreatedEntityKey = function getLastCreatedEntityKey() {
  6329. // TODO: update this when we fully remove DraftEntity
  6330. return DraftEntity_1.__getLastCreatedEntityKey();
  6331. };
  6332. ContentState.prototype.hasText = function hasText() {
  6333. var blockMap = this.getBlockMap();
  6334. return blockMap.size > 1 || blockMap.first().getLength() > 0;
  6335. };
  6336. ContentState.prototype.createEntity = function createEntity(type, mutability, data) {
  6337. // TODO: update this when we fully remove DraftEntity
  6338. DraftEntity_1.__create(type, mutability, data);
  6339. return this;
  6340. };
  6341. ContentState.prototype.mergeEntityData = function mergeEntityData(key, toMerge) {
  6342. // TODO: update this when we fully remove DraftEntity
  6343. DraftEntity_1.__mergeData(key, toMerge);
  6344. return this;
  6345. };
  6346. ContentState.prototype.replaceEntityData = function replaceEntityData(key, newData) {
  6347. // TODO: update this when we fully remove DraftEntity
  6348. DraftEntity_1.__replaceData(key, newData);
  6349. return this;
  6350. };
  6351. ContentState.prototype.addEntity = function addEntity(instance) {
  6352. // TODO: update this when we fully remove DraftEntity
  6353. DraftEntity_1.__add(instance);
  6354. return this;
  6355. };
  6356. ContentState.prototype.getEntity = function getEntity(key) {
  6357. // TODO: update this when we fully remove DraftEntity
  6358. return DraftEntity_1.__get(key);
  6359. };
  6360. ContentState.createFromBlockArray = function createFromBlockArray(
  6361. // TODO: update flow type when we completely deprecate the old entity API
  6362. blocks, entityMap) {
  6363. // TODO: remove this when we completely deprecate the old entity API
  6364. var theBlocks = Array.isArray(blocks) ? blocks : blocks.contentBlocks;
  6365. var blockMap = BlockMapBuilder_1.createFromArray(theBlocks);
  6366. var selectionState = blockMap.isEmpty() ? new SelectionState_1() : SelectionState_1.createEmpty(blockMap.first().getKey());
  6367. return new ContentState({
  6368. blockMap: blockMap,
  6369. entityMap: entityMap || DraftEntity_1,
  6370. selectionBefore: selectionState,
  6371. selectionAfter: selectionState
  6372. });
  6373. };
  6374. ContentState.createFromText = function createFromText(text) {
  6375. var delimiter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : /\r\n?|\n/g;
  6376. var strings = text.split(delimiter);
  6377. var blocks = strings.map(function (block) {
  6378. block = sanitizeDraftText_1(block);
  6379. return new ContentBlockNodeRecord({
  6380. key: generateRandomKey_1(),
  6381. text: block,
  6382. type: 'unstyled',
  6383. characterList: List$6(Repeat$4(CharacterMetadata_1.EMPTY, block.length))
  6384. });
  6385. });
  6386. return ContentState.createFromBlockArray(blocks);
  6387. };
  6388. return ContentState;
  6389. }(ContentStateRecord);
  6390. var ContentState_1 = ContentState;
  6391. var NEUTRAL = 'NEUTRAL'; // No strong direction
  6392. var LTR = 'LTR'; // Left-to-Right direction
  6393. var RTL = 'RTL'; // Right-to-Left direction
  6394. var globalDir = null;
  6395. // == Helpers ==
  6396. /**
  6397. * Check if a directionality value is a Strong one
  6398. */
  6399. function isStrong(dir) {
  6400. return dir === LTR || dir === RTL;
  6401. }
  6402. /**
  6403. * Get string value to be used for `dir` HTML attribute or `direction` CSS
  6404. * property.
  6405. */
  6406. function getHTMLDir(dir) {
  6407. !isStrong(dir) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, '`dir` must be a strong direction to be converted to HTML Direction') : invariant_1(false) : void 0;
  6408. return dir === LTR ? 'ltr' : 'rtl';
  6409. }
  6410. /**
  6411. * Get string value to be used for `dir` HTML attribute or `direction` CSS
  6412. * property, but returns null if `dir` has same value as `otherDir`.
  6413. * `null`.
  6414. */
  6415. function getHTMLDirIfDifferent(dir, otherDir) {
  6416. !isStrong(dir) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, '`dir` must be a strong direction to be converted to HTML Direction') : invariant_1(false) : void 0;
  6417. !isStrong(otherDir) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, '`otherDir` must be a strong direction to be converted to HTML Direction') : invariant_1(false) : void 0;
  6418. return dir === otherDir ? null : getHTMLDir(dir);
  6419. }
  6420. // == Global Direction ==
  6421. /**
  6422. * Set the global direction.
  6423. */
  6424. function setGlobalDir(dir) {
  6425. globalDir = dir;
  6426. }
  6427. /**
  6428. * Initialize the global direction
  6429. */
  6430. function initGlobalDir() {
  6431. setGlobalDir(LTR);
  6432. }
  6433. /**
  6434. * Get the global direction
  6435. */
  6436. function getGlobalDir() {
  6437. if (!globalDir) {
  6438. this.initGlobalDir();
  6439. }
  6440. !globalDir ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Global direction not set.') : invariant_1(false) : void 0;
  6441. return globalDir;
  6442. }
  6443. var UnicodeBidiDirection = {
  6444. // Values
  6445. NEUTRAL: NEUTRAL,
  6446. LTR: LTR,
  6447. RTL: RTL,
  6448. // Helpers
  6449. isStrong: isStrong,
  6450. getHTMLDir: getHTMLDir,
  6451. getHTMLDirIfDifferent: getHTMLDirIfDifferent,
  6452. // Global Direction
  6453. setGlobalDir: setGlobalDir,
  6454. initGlobalDir: initGlobalDir,
  6455. getGlobalDir: getGlobalDir
  6456. };
  6457. var UnicodeBidiDirection_1 = UnicodeBidiDirection;
  6458. /**
  6459. * RegExp ranges of characters with a *Strong* Bidi_Class value.
  6460. *
  6461. * Data is based on DerivedBidiClass.txt in UCD version 7.0.0.
  6462. *
  6463. * NOTE: For performance reasons, we only support Unicode's
  6464. * Basic Multilingual Plane (BMP) for now.
  6465. */
  6466. var RANGE_BY_BIDI_TYPE = {
  6467. 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',
  6468. 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',
  6469. 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'
  6470. };
  6471. var REGEX_STRONG = new RegExp('[' + RANGE_BY_BIDI_TYPE.L + RANGE_BY_BIDI_TYPE.R + RANGE_BY_BIDI_TYPE.AL + ']');
  6472. var REGEX_RTL = new RegExp('[' + RANGE_BY_BIDI_TYPE.R + RANGE_BY_BIDI_TYPE.AL + ']');
  6473. /**
  6474. * Returns the first strong character (has Bidi_Class value of L, R, or AL).
  6475. *
  6476. * @param str A text block; e.g. paragraph, table cell, tag
  6477. * @return A character with strong bidi direction, or null if not found
  6478. */
  6479. function firstStrongChar(str) {
  6480. var match = REGEX_STRONG.exec(str);
  6481. return match == null ? null : match[0];
  6482. }
  6483. /**
  6484. * Returns the direction of a block of text, based on the direction of its
  6485. * first strong character (has Bidi_Class value of L, R, or AL).
  6486. *
  6487. * @param str A text block; e.g. paragraph, table cell, tag
  6488. * @return The resolved direction
  6489. */
  6490. function firstStrongCharDir(str) {
  6491. var strongChar = firstStrongChar(str);
  6492. if (strongChar == null) {
  6493. return UnicodeBidiDirection_1.NEUTRAL;
  6494. }
  6495. return REGEX_RTL.exec(strongChar) ? UnicodeBidiDirection_1.RTL : UnicodeBidiDirection_1.LTR;
  6496. }
  6497. /**
  6498. * Returns the direction of a block of text, based on the direction of its
  6499. * first strong character (has Bidi_Class value of L, R, or AL), or a fallback
  6500. * direction, if no strong character is found.
  6501. *
  6502. * This function is supposed to be used in respect to Higher-Level Protocol
  6503. * rule HL1. (http://www.unicode.org/reports/tr9/#HL1)
  6504. *
  6505. * @param str A text block; e.g. paragraph, table cell, tag
  6506. * @param fallback Fallback direction, used if no strong direction detected
  6507. * for the block (default = NEUTRAL)
  6508. * @return The resolved direction
  6509. */
  6510. function resolveBlockDir(str, fallback) {
  6511. fallback = fallback || UnicodeBidiDirection_1.NEUTRAL;
  6512. if (!str.length) {
  6513. return fallback;
  6514. }
  6515. var blockDir = firstStrongCharDir(str);
  6516. return blockDir === UnicodeBidiDirection_1.NEUTRAL ? fallback : blockDir;
  6517. }
  6518. /**
  6519. * Returns the direction of a block of text, based on the direction of its
  6520. * first strong character (has Bidi_Class value of L, R, or AL), or a fallback
  6521. * direction, if no strong character is found.
  6522. *
  6523. * NOTE: This function is similar to resolveBlockDir(), but uses the global
  6524. * direction as the fallback, so it *always* returns a Strong direction,
  6525. * making it useful for integration in places that you need to make the final
  6526. * decision, like setting some CSS class.
  6527. *
  6528. * This function is supposed to be used in respect to Higher-Level Protocol
  6529. * rule HL1. (http://www.unicode.org/reports/tr9/#HL1)
  6530. *
  6531. * @param str A text block; e.g. paragraph, table cell
  6532. * @param strongFallback Fallback direction, used if no strong direction
  6533. * detected for the block (default = global direction)
  6534. * @return The resolved Strong direction
  6535. */
  6536. function getDirection(str, strongFallback) {
  6537. if (!strongFallback) {
  6538. strongFallback = UnicodeBidiDirection_1.getGlobalDir();
  6539. }
  6540. !UnicodeBidiDirection_1.isStrong(strongFallback) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Fallback direction must be a strong direction') : invariant_1(false) : void 0;
  6541. return resolveBlockDir(str, strongFallback);
  6542. }
  6543. /**
  6544. * Returns true if getDirection(arguments...) returns LTR.
  6545. *
  6546. * @param str A text block; e.g. paragraph, table cell
  6547. * @param strongFallback Fallback direction, used if no strong direction
  6548. * detected for the block (default = global direction)
  6549. * @return True if the resolved direction is LTR
  6550. */
  6551. function isDirectionLTR(str, strongFallback) {
  6552. return getDirection(str, strongFallback) === UnicodeBidiDirection_1.LTR;
  6553. }
  6554. /**
  6555. * Returns true if getDirection(arguments...) returns RTL.
  6556. *
  6557. * @param str A text block; e.g. paragraph, table cell
  6558. * @param strongFallback Fallback direction, used if no strong direction
  6559. * detected for the block (default = global direction)
  6560. * @return True if the resolved direction is RTL
  6561. */
  6562. function isDirectionRTL(str, strongFallback) {
  6563. return getDirection(str, strongFallback) === UnicodeBidiDirection_1.RTL;
  6564. }
  6565. var UnicodeBidi = {
  6566. firstStrongChar: firstStrongChar,
  6567. firstStrongCharDir: firstStrongCharDir,
  6568. resolveBlockDir: resolveBlockDir,
  6569. getDirection: getDirection,
  6570. isDirectionLTR: isDirectionLTR,
  6571. isDirectionRTL: isDirectionRTL
  6572. };
  6573. var UnicodeBidi_1 = UnicodeBidi;
  6574. function _classCallCheck$6(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6575. var UnicodeBidiService = function () {
  6576. /**
  6577. * Stateful class for paragraph direction detection
  6578. *
  6579. * @param defaultDir Default direction of the service
  6580. */
  6581. function UnicodeBidiService(defaultDir) {
  6582. _classCallCheck$6(this, UnicodeBidiService);
  6583. if (!defaultDir) {
  6584. defaultDir = UnicodeBidiDirection_1.getGlobalDir();
  6585. } else {
  6586. !UnicodeBidiDirection_1.isStrong(defaultDir) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Default direction must be a strong direction (LTR or RTL)') : invariant_1(false) : void 0;
  6587. }
  6588. this._defaultDir = defaultDir;
  6589. this.reset();
  6590. }
  6591. /**
  6592. * Reset the internal state
  6593. *
  6594. * Instead of creating a new instance, you can just reset() your instance
  6595. * everytime you start a new loop.
  6596. */
  6597. UnicodeBidiService.prototype.reset = function reset() {
  6598. this._lastDir = this._defaultDir;
  6599. };
  6600. /**
  6601. * Returns the direction of a block of text, and remembers it as the
  6602. * fall-back direction for the next paragraph.
  6603. *
  6604. * @param str A text block, e.g. paragraph, table cell, tag
  6605. * @return The resolved direction
  6606. */
  6607. UnicodeBidiService.prototype.getDirection = function getDirection(str) {
  6608. this._lastDir = UnicodeBidi_1.getDirection(str, this._lastDir);
  6609. return this._lastDir;
  6610. };
  6611. return UnicodeBidiService;
  6612. }();
  6613. var UnicodeBidiService_1 = UnicodeBidiService;
  6614. /**
  6615. * Copyright (c) 2013-present, Facebook, Inc.
  6616. *
  6617. * This source code is licensed under the MIT license found in the
  6618. * LICENSE file in the root directory of this source tree.
  6619. *
  6620. *
  6621. */
  6622. var nullthrows = function nullthrows(x) {
  6623. if (x != null) {
  6624. return x;
  6625. }
  6626. throw new Error("Got unexpected null or undefined");
  6627. };
  6628. var nullthrows_1 = nullthrows;
  6629. var OrderedMap$2 = immutable.OrderedMap;
  6630. var bidiService;
  6631. var EditorBidiService = {
  6632. getDirectionMap: function getDirectionMap(content, prevBidiMap) {
  6633. if (!bidiService) {
  6634. bidiService = new UnicodeBidiService_1();
  6635. } else {
  6636. bidiService.reset();
  6637. }
  6638. var blockMap = content.getBlockMap();
  6639. var nextBidi = blockMap.valueSeq().map(function (block) {
  6640. return nullthrows_1(bidiService).getDirection(block.getText());
  6641. });
  6642. var bidiMap = OrderedMap$2(blockMap.keySeq().zip(nextBidi));
  6643. if (prevBidiMap != null && immutable.is(prevBidiMap, bidiMap)) {
  6644. return prevBidiMap;
  6645. }
  6646. return bidiMap;
  6647. }
  6648. };
  6649. var EditorBidiService_1 = EditorBidiService;
  6650. var _extends$1 = objectAssign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  6651. function _classCallCheck$7(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6652. var OrderedSet$4 = immutable.OrderedSet,
  6653. Record$7 = immutable.Record,
  6654. Stack = immutable.Stack;
  6655. var defaultRecord$5 = {
  6656. allowUndo: true,
  6657. currentContent: null,
  6658. decorator: null,
  6659. directionMap: null,
  6660. forceSelection: false,
  6661. inCompositionMode: false,
  6662. inlineStyleOverride: null,
  6663. lastChangeType: null,
  6664. nativelyRenderedContent: null,
  6665. redoStack: Stack(),
  6666. selection: null,
  6667. treeMap: null,
  6668. undoStack: Stack()
  6669. };
  6670. var EditorStateRecord = Record$7(defaultRecord$5);
  6671. var EditorState = function () {
  6672. EditorState.createEmpty = function createEmpty(decorator) {
  6673. return EditorState.createWithContent(ContentState_1.createFromText(''), decorator);
  6674. };
  6675. EditorState.createWithContent = function createWithContent(contentState, decorator) {
  6676. var firstKey = contentState.getBlockMap().first().getKey();
  6677. return EditorState.create({
  6678. currentContent: contentState,
  6679. undoStack: Stack(),
  6680. redoStack: Stack(),
  6681. decorator: decorator || null,
  6682. selection: SelectionState_1.createEmpty(firstKey)
  6683. });
  6684. };
  6685. EditorState.create = function create(config) {
  6686. var currentContent = config.currentContent,
  6687. decorator = config.decorator;
  6688. var recordConfig = _extends$1({}, config, {
  6689. treeMap: generateNewTreeMap(currentContent, decorator),
  6690. directionMap: EditorBidiService_1.getDirectionMap(currentContent)
  6691. });
  6692. return new EditorState(new EditorStateRecord(recordConfig));
  6693. };
  6694. EditorState.set = function set(editorState, put) {
  6695. var map = editorState.getImmutable().withMutations(function (state) {
  6696. var existingDecorator = state.get('decorator');
  6697. var decorator = existingDecorator;
  6698. if (put.decorator === null) {
  6699. decorator = null;
  6700. } else if (put.decorator) {
  6701. decorator = put.decorator;
  6702. }
  6703. var newContent = put.currentContent || editorState.getCurrentContent();
  6704. if (decorator !== existingDecorator) {
  6705. var treeMap = state.get('treeMap');
  6706. var newTreeMap;
  6707. if (decorator && existingDecorator) {
  6708. newTreeMap = regenerateTreeForNewDecorator(newContent, newContent.getBlockMap(), treeMap, decorator, existingDecorator);
  6709. } else {
  6710. newTreeMap = generateNewTreeMap(newContent, decorator);
  6711. }
  6712. state.merge({
  6713. decorator: decorator,
  6714. treeMap: newTreeMap,
  6715. nativelyRenderedContent: null
  6716. });
  6717. return;
  6718. }
  6719. var existingContent = editorState.getCurrentContent();
  6720. if (newContent !== existingContent) {
  6721. state.set('treeMap', regenerateTreeForNewBlocks(editorState, newContent.getBlockMap(), newContent.getEntityMap(), decorator));
  6722. }
  6723. state.merge(put);
  6724. });
  6725. return new EditorState(map);
  6726. };
  6727. EditorState.prototype.toJS = function toJS() {
  6728. return this.getImmutable().toJS();
  6729. };
  6730. EditorState.prototype.getAllowUndo = function getAllowUndo() {
  6731. return this.getImmutable().get('allowUndo');
  6732. };
  6733. EditorState.prototype.getCurrentContent = function getCurrentContent() {
  6734. return this.getImmutable().get('currentContent');
  6735. };
  6736. EditorState.prototype.getUndoStack = function getUndoStack() {
  6737. return this.getImmutable().get('undoStack');
  6738. };
  6739. EditorState.prototype.getRedoStack = function getRedoStack() {
  6740. return this.getImmutable().get('redoStack');
  6741. };
  6742. EditorState.prototype.getSelection = function getSelection() {
  6743. return this.getImmutable().get('selection');
  6744. };
  6745. EditorState.prototype.getDecorator = function getDecorator() {
  6746. return this.getImmutable().get('decorator');
  6747. };
  6748. EditorState.prototype.isInCompositionMode = function isInCompositionMode() {
  6749. return this.getImmutable().get('inCompositionMode');
  6750. };
  6751. EditorState.prototype.mustForceSelection = function mustForceSelection() {
  6752. return this.getImmutable().get('forceSelection');
  6753. };
  6754. EditorState.prototype.getNativelyRenderedContent = function getNativelyRenderedContent() {
  6755. return this.getImmutable().get('nativelyRenderedContent');
  6756. };
  6757. EditorState.prototype.getLastChangeType = function getLastChangeType() {
  6758. return this.getImmutable().get('lastChangeType');
  6759. };
  6760. /**
  6761. * While editing, the user may apply inline style commands with a collapsed
  6762. * cursor, intending to type text that adopts the specified style. In this
  6763. * case, we track the specified style as an "override" that takes precedence
  6764. * over the inline style of the text adjacent to the cursor.
  6765. *
  6766. * If null, there is no override in place.
  6767. */
  6768. EditorState.prototype.getInlineStyleOverride = function getInlineStyleOverride() {
  6769. return this.getImmutable().get('inlineStyleOverride');
  6770. };
  6771. EditorState.setInlineStyleOverride = function setInlineStyleOverride(editorState, inlineStyleOverride) {
  6772. return EditorState.set(editorState, { inlineStyleOverride: inlineStyleOverride });
  6773. };
  6774. /**
  6775. * Get the appropriate inline style for the editor state. If an
  6776. * override is in place, use it. Otherwise, the current style is
  6777. * based on the location of the selection state.
  6778. */
  6779. EditorState.prototype.getCurrentInlineStyle = function getCurrentInlineStyle() {
  6780. var override = this.getInlineStyleOverride();
  6781. if (override != null) {
  6782. return override;
  6783. }
  6784. var content = this.getCurrentContent();
  6785. var selection = this.getSelection();
  6786. if (selection.isCollapsed()) {
  6787. return getInlineStyleForCollapsedSelection(content, selection);
  6788. }
  6789. return getInlineStyleForNonCollapsedSelection(content, selection);
  6790. };
  6791. EditorState.prototype.getBlockTree = function getBlockTree(blockKey) {
  6792. return this.getImmutable().getIn(['treeMap', blockKey]);
  6793. };
  6794. EditorState.prototype.isSelectionAtStartOfContent = function isSelectionAtStartOfContent() {
  6795. var firstKey = this.getCurrentContent().getBlockMap().first().getKey();
  6796. return this.getSelection().hasEdgeWithin(firstKey, 0, 0);
  6797. };
  6798. EditorState.prototype.isSelectionAtEndOfContent = function isSelectionAtEndOfContent() {
  6799. var content = this.getCurrentContent();
  6800. var blockMap = content.getBlockMap();
  6801. var last = blockMap.last();
  6802. var end = last.getLength();
  6803. return this.getSelection().hasEdgeWithin(last.getKey(), end, end);
  6804. };
  6805. EditorState.prototype.getDirectionMap = function getDirectionMap() {
  6806. return this.getImmutable().get('directionMap');
  6807. };
  6808. /**
  6809. * Incorporate native DOM selection changes into the EditorState. This
  6810. * method can be used when we simply want to accept whatever the DOM
  6811. * has given us to represent selection, and we do not need to re-render
  6812. * the editor.
  6813. *
  6814. * To forcibly move the DOM selection, see `EditorState.forceSelection`.
  6815. */
  6816. EditorState.acceptSelection = function acceptSelection(editorState, selection) {
  6817. return updateSelection(editorState, selection, false);
  6818. };
  6819. /**
  6820. * At times, we need to force the DOM selection to be where we
  6821. * need it to be. This can occur when the anchor or focus nodes
  6822. * are non-text nodes, for instance. In this case, we want to trigger
  6823. * a re-render of the editor, which in turn forces selection into
  6824. * the correct place in the DOM. The `forceSelection` method
  6825. * accomplishes this.
  6826. *
  6827. * This method should be used in cases where you need to explicitly
  6828. * move the DOM selection from one place to another without a change
  6829. * in ContentState.
  6830. */
  6831. EditorState.forceSelection = function forceSelection(editorState, selection) {
  6832. if (!selection.getHasFocus()) {
  6833. selection = selection.set('hasFocus', true);
  6834. }
  6835. return updateSelection(editorState, selection, true);
  6836. };
  6837. /**
  6838. * Move selection to the end of the editor without forcing focus.
  6839. */
  6840. EditorState.moveSelectionToEnd = function moveSelectionToEnd(editorState) {
  6841. var content = editorState.getCurrentContent();
  6842. var lastBlock = content.getLastBlock();
  6843. var lastKey = lastBlock.getKey();
  6844. var length = lastBlock.getLength();
  6845. return EditorState.acceptSelection(editorState, new SelectionState_1({
  6846. anchorKey: lastKey,
  6847. anchorOffset: length,
  6848. focusKey: lastKey,
  6849. focusOffset: length,
  6850. isBackward: false
  6851. }));
  6852. };
  6853. /**
  6854. * Force focus to the end of the editor. This is useful in scenarios
  6855. * where we want to programmatically focus the input and it makes sense
  6856. * to allow the user to continue working seamlessly.
  6857. */
  6858. EditorState.moveFocusToEnd = function moveFocusToEnd(editorState) {
  6859. var afterSelectionMove = EditorState.moveSelectionToEnd(editorState);
  6860. return EditorState.forceSelection(afterSelectionMove, afterSelectionMove.getSelection());
  6861. };
  6862. /**
  6863. * Push the current ContentState onto the undo stack if it should be
  6864. * considered a boundary state, and set the provided ContentState as the
  6865. * new current content.
  6866. */
  6867. EditorState.push = function push(editorState, contentState, changeType) {
  6868. if (editorState.getCurrentContent() === contentState) {
  6869. return editorState;
  6870. }
  6871. var forceSelection = changeType !== 'insert-characters';
  6872. var directionMap = EditorBidiService_1.getDirectionMap(contentState, editorState.getDirectionMap());
  6873. if (!editorState.getAllowUndo()) {
  6874. return EditorState.set(editorState, {
  6875. currentContent: contentState,
  6876. directionMap: directionMap,
  6877. lastChangeType: changeType,
  6878. selection: contentState.getSelectionAfter(),
  6879. forceSelection: forceSelection,
  6880. inlineStyleOverride: null
  6881. });
  6882. }
  6883. var selection = editorState.getSelection();
  6884. var currentContent = editorState.getCurrentContent();
  6885. var undoStack = editorState.getUndoStack();
  6886. var newContent = contentState;
  6887. if (selection !== currentContent.getSelectionAfter() || mustBecomeBoundary(editorState, changeType)) {
  6888. undoStack = undoStack.push(currentContent);
  6889. newContent = newContent.set('selectionBefore', selection);
  6890. } else if (changeType === 'insert-characters' || changeType === 'backspace-character' || changeType === 'delete-character') {
  6891. // Preserve the previous selection.
  6892. newContent = newContent.set('selectionBefore', currentContent.getSelectionBefore());
  6893. }
  6894. var inlineStyleOverride = editorState.getInlineStyleOverride();
  6895. // Don't discard inline style overrides for the following change types:
  6896. var overrideChangeTypes = ['adjust-depth', 'change-block-type', 'split-block'];
  6897. if (overrideChangeTypes.indexOf(changeType) === -1) {
  6898. inlineStyleOverride = null;
  6899. }
  6900. var editorStateChanges = {
  6901. currentContent: newContent,
  6902. directionMap: directionMap,
  6903. undoStack: undoStack,
  6904. redoStack: Stack(),
  6905. lastChangeType: changeType,
  6906. selection: contentState.getSelectionAfter(),
  6907. forceSelection: forceSelection,
  6908. inlineStyleOverride: inlineStyleOverride
  6909. };
  6910. return EditorState.set(editorState, editorStateChanges);
  6911. };
  6912. /**
  6913. * Make the top ContentState in the undo stack the new current content and
  6914. * push the current content onto the redo stack.
  6915. */
  6916. EditorState.undo = function undo(editorState) {
  6917. if (!editorState.getAllowUndo()) {
  6918. return editorState;
  6919. }
  6920. var undoStack = editorState.getUndoStack();
  6921. var newCurrentContent = undoStack.peek();
  6922. if (!newCurrentContent) {
  6923. return editorState;
  6924. }
  6925. var currentContent = editorState.getCurrentContent();
  6926. var directionMap = EditorBidiService_1.getDirectionMap(newCurrentContent, editorState.getDirectionMap());
  6927. return EditorState.set(editorState, {
  6928. currentContent: newCurrentContent,
  6929. directionMap: directionMap,
  6930. undoStack: undoStack.shift(),
  6931. redoStack: editorState.getRedoStack().push(currentContent),
  6932. forceSelection: true,
  6933. inlineStyleOverride: null,
  6934. lastChangeType: 'undo',
  6935. nativelyRenderedContent: null,
  6936. selection: currentContent.getSelectionBefore()
  6937. });
  6938. };
  6939. /**
  6940. * Make the top ContentState in the redo stack the new current content and
  6941. * push the current content onto the undo stack.
  6942. */
  6943. EditorState.redo = function redo(editorState) {
  6944. if (!editorState.getAllowUndo()) {
  6945. return editorState;
  6946. }
  6947. var redoStack = editorState.getRedoStack();
  6948. var newCurrentContent = redoStack.peek();
  6949. if (!newCurrentContent) {
  6950. return editorState;
  6951. }
  6952. var currentContent = editorState.getCurrentContent();
  6953. var directionMap = EditorBidiService_1.getDirectionMap(newCurrentContent, editorState.getDirectionMap());
  6954. return EditorState.set(editorState, {
  6955. currentContent: newCurrentContent,
  6956. directionMap: directionMap,
  6957. undoStack: editorState.getUndoStack().push(currentContent),
  6958. redoStack: redoStack.shift(),
  6959. forceSelection: true,
  6960. inlineStyleOverride: null,
  6961. lastChangeType: 'redo',
  6962. nativelyRenderedContent: null,
  6963. selection: newCurrentContent.getSelectionAfter()
  6964. });
  6965. };
  6966. /**
  6967. * Not for public consumption.
  6968. */
  6969. function EditorState(immutable) {
  6970. _classCallCheck$7(this, EditorState);
  6971. this._immutable = immutable;
  6972. }
  6973. /**
  6974. * Not for public consumption.
  6975. */
  6976. EditorState.prototype.getImmutable = function getImmutable() {
  6977. return this._immutable;
  6978. };
  6979. return EditorState;
  6980. }();
  6981. /**
  6982. * Set the supplied SelectionState as the new current selection, and set
  6983. * the `force` flag to trigger manual selection placement by the view.
  6984. */
  6985. function updateSelection(editorState, selection, forceSelection) {
  6986. return EditorState.set(editorState, {
  6987. selection: selection,
  6988. forceSelection: forceSelection,
  6989. nativelyRenderedContent: null,
  6990. inlineStyleOverride: null
  6991. });
  6992. }
  6993. /**
  6994. * Regenerate the entire tree map for a given ContentState and decorator.
  6995. * Returns an OrderedMap that maps all available ContentBlock objects.
  6996. */
  6997. function generateNewTreeMap(contentState, decorator) {
  6998. return contentState.getBlockMap().map(function (block) {
  6999. return BlockTree_1.generate(contentState, block, decorator);
  7000. }).toOrderedMap();
  7001. }
  7002. /**
  7003. * Regenerate tree map objects for all ContentBlocks that have changed
  7004. * between the current editorState and newContent. Returns an OrderedMap
  7005. * with only changed regenerated tree map objects.
  7006. */
  7007. function regenerateTreeForNewBlocks(editorState, newBlockMap, newEntityMap, decorator) {
  7008. var contentState = editorState.getCurrentContent().set('entityMap', newEntityMap);
  7009. var prevBlockMap = contentState.getBlockMap();
  7010. var prevTreeMap = editorState.getImmutable().get('treeMap');
  7011. return prevTreeMap.merge(newBlockMap.toSeq().filter(function (block, key) {
  7012. return block !== prevBlockMap.get(key);
  7013. }).map(function (block) {
  7014. return BlockTree_1.generate(contentState, block, decorator);
  7015. }));
  7016. }
  7017. /**
  7018. * Generate tree map objects for a new decorator object, preserving any
  7019. * decorations that are unchanged from the previous decorator.
  7020. *
  7021. * Note that in order for this to perform optimally, decoration Lists for
  7022. * decorators should be preserved when possible to allow for direct immutable
  7023. * List comparison.
  7024. */
  7025. function regenerateTreeForNewDecorator(content, blockMap, previousTreeMap, decorator, existingDecorator) {
  7026. return previousTreeMap.merge(blockMap.toSeq().filter(function (block) {
  7027. return decorator.getDecorations(block, content) !== existingDecorator.getDecorations(block, content);
  7028. }).map(function (block) {
  7029. return BlockTree_1.generate(content, block, decorator);
  7030. }));
  7031. }
  7032. /**
  7033. * Return whether a change should be considered a boundary state, given
  7034. * the previous change type. Allows us to discard potential boundary states
  7035. * during standard typing or deletion behavior.
  7036. */
  7037. function mustBecomeBoundary(editorState, changeType) {
  7038. var lastChangeType = editorState.getLastChangeType();
  7039. return changeType !== lastChangeType || changeType !== 'insert-characters' && changeType !== 'backspace-character' && changeType !== 'delete-character';
  7040. }
  7041. function getInlineStyleForCollapsedSelection(content, selection) {
  7042. var startKey = selection.getStartKey();
  7043. var startOffset = selection.getStartOffset();
  7044. var startBlock = content.getBlockForKey(startKey);
  7045. // If the cursor is not at the start of the block, look backward to
  7046. // preserve the style of the preceding character.
  7047. if (startOffset > 0) {
  7048. return startBlock.getInlineStyleAt(startOffset - 1);
  7049. }
  7050. // The caret is at position zero in this block. If the block has any
  7051. // text at all, use the style of the first character.
  7052. if (startBlock.getLength()) {
  7053. return startBlock.getInlineStyleAt(0);
  7054. }
  7055. // Otherwise, look upward in the document to find the closest character.
  7056. return lookUpwardForInlineStyle(content, startKey);
  7057. }
  7058. function getInlineStyleForNonCollapsedSelection(content, selection) {
  7059. var startKey = selection.getStartKey();
  7060. var startOffset = selection.getStartOffset();
  7061. var startBlock = content.getBlockForKey(startKey);
  7062. // If there is a character just inside the selection, use its style.
  7063. if (startOffset < startBlock.getLength()) {
  7064. return startBlock.getInlineStyleAt(startOffset);
  7065. }
  7066. // Check if the selection at the end of a non-empty block. Use the last
  7067. // style in the block.
  7068. if (startOffset > 0) {
  7069. return startBlock.getInlineStyleAt(startOffset - 1);
  7070. }
  7071. // Otherwise, look upward in the document to find the closest character.
  7072. return lookUpwardForInlineStyle(content, startKey);
  7073. }
  7074. function lookUpwardForInlineStyle(content, fromKey) {
  7075. var lastNonEmpty = content.getBlockMap().reverse().skipUntil(function (_, k) {
  7076. return k === fromKey;
  7077. }).skip(1).skipUntil(function (block, _) {
  7078. return block.getLength();
  7079. }).first();
  7080. if (lastNonEmpty) return lastNonEmpty.getInlineStyleAt(lastNonEmpty.getLength() - 1);
  7081. return OrderedSet$4();
  7082. }
  7083. var EditorState_1 = EditorState;
  7084. var OrderedMap$3 = immutable.OrderedMap,
  7085. List$7 = immutable.List;
  7086. var transformBlock$2 = function transformBlock(key, blockMap, func) {
  7087. if (!key) {
  7088. return;
  7089. }
  7090. var block = blockMap.get(key);
  7091. if (!block) {
  7092. return;
  7093. }
  7094. blockMap.set(key, func(block));
  7095. };
  7096. var updateBlockMapLinks$3 = function updateBlockMapLinks(blockMap, originalBlockToBeMoved, originalTargetBlock, insertionMode, isExperimentalTreeBlock) {
  7097. if (!isExperimentalTreeBlock) {
  7098. return blockMap;
  7099. }
  7100. // possible values of 'insertionMode' are: 'after', 'before'
  7101. var isInsertedAfterTarget = insertionMode === 'after';
  7102. var originalBlockKey = originalBlockToBeMoved.getKey();
  7103. var originalTargetKey = originalTargetBlock.getKey();
  7104. var originalParentKey = originalBlockToBeMoved.getParentKey();
  7105. var originalNextSiblingKey = originalBlockToBeMoved.getNextSiblingKey();
  7106. var originalPrevSiblingKey = originalBlockToBeMoved.getPrevSiblingKey();
  7107. var newParentKey = originalTargetBlock.getParentKey();
  7108. var newNextSiblingKey = isInsertedAfterTarget ? originalTargetBlock.getNextSiblingKey() : originalTargetKey;
  7109. var newPrevSiblingKey = isInsertedAfterTarget ? originalTargetKey : originalTargetBlock.getPrevSiblingKey();
  7110. return blockMap.withMutations(function (blocks) {
  7111. // update old parent
  7112. transformBlock$2(originalParentKey, blocks, function (block) {
  7113. var parentChildrenList = block.getChildKeys();
  7114. return block.merge({
  7115. children: parentChildrenList['delete'](parentChildrenList.indexOf(originalBlockKey))
  7116. });
  7117. });
  7118. // update old prev
  7119. transformBlock$2(originalPrevSiblingKey, blocks, function (block) {
  7120. return block.merge({
  7121. nextSibling: originalNextSiblingKey
  7122. });
  7123. });
  7124. // update old next
  7125. transformBlock$2(originalNextSiblingKey, blocks, function (block) {
  7126. return block.merge({
  7127. prevSibling: originalPrevSiblingKey
  7128. });
  7129. });
  7130. // update new next
  7131. transformBlock$2(newNextSiblingKey, blocks, function (block) {
  7132. return block.merge({
  7133. prevSibling: originalBlockKey
  7134. });
  7135. });
  7136. // update new prev
  7137. transformBlock$2(newPrevSiblingKey, blocks, function (block) {
  7138. return block.merge({
  7139. nextSibling: originalBlockKey
  7140. });
  7141. });
  7142. // update new parent
  7143. transformBlock$2(newParentKey, blocks, function (block) {
  7144. var newParentChildrenList = block.getChildKeys();
  7145. var targetBlockIndex = newParentChildrenList.indexOf(originalTargetKey);
  7146. var insertionIndex = isInsertedAfterTarget ? targetBlockIndex + 1 : targetBlockIndex !== 0 ? targetBlockIndex - 1 : 0;
  7147. var newChildrenArray = newParentChildrenList.toArray();
  7148. newChildrenArray.splice(insertionIndex, 0, originalBlockKey);
  7149. return block.merge({
  7150. children: List$7(newChildrenArray)
  7151. });
  7152. });
  7153. // update block
  7154. transformBlock$2(originalBlockKey, blocks, function (block) {
  7155. return block.merge({
  7156. nextSibling: newNextSiblingKey,
  7157. prevSibling: newPrevSiblingKey,
  7158. parent: newParentKey
  7159. });
  7160. });
  7161. });
  7162. };
  7163. var moveBlockInContentState = function moveBlockInContentState(contentState, blockToBeMoved, targetBlock, insertionMode) {
  7164. !(insertionMode !== 'replace') ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Replacing blocks is not supported.') : invariant_1(false) : void 0;
  7165. var targetKey = targetBlock.getKey();
  7166. var blockKey = blockToBeMoved.getKey();
  7167. !(blockKey !== targetKey) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Block cannot be moved next to itself.') : invariant_1(false) : void 0;
  7168. var blockMap = contentState.getBlockMap();
  7169. var isExperimentalTreeBlock = blockToBeMoved instanceof ContentBlockNode_1;
  7170. var blocksToBeMoved = [blockToBeMoved];
  7171. var blockMapWithoutBlocksToBeMoved = blockMap['delete'](blockKey);
  7172. if (isExperimentalTreeBlock) {
  7173. blocksToBeMoved = [];
  7174. blockMapWithoutBlocksToBeMoved = blockMap.withMutations(function (blocks) {
  7175. var nextSiblingKey = blockToBeMoved.getNextSiblingKey();
  7176. var nextDelimiterBlockKey = getNextDelimiterBlockKey_1(blockToBeMoved, blocks);
  7177. blocks.toSeq().skipUntil(function (block) {
  7178. return block.getKey() === blockKey;
  7179. }).takeWhile(function (block) {
  7180. var key = block.getKey();
  7181. var isBlockToBeMoved = key === blockKey;
  7182. var hasNextSiblingAndIsNotNextSibling = nextSiblingKey && key !== nextSiblingKey;
  7183. var doesNotHaveNextSiblingAndIsNotDelimiter = !nextSiblingKey && block.getParentKey() && (!nextDelimiterBlockKey || key !== nextDelimiterBlockKey);
  7184. return !!(isBlockToBeMoved || hasNextSiblingAndIsNotNextSibling || doesNotHaveNextSiblingAndIsNotDelimiter);
  7185. }).forEach(function (block) {
  7186. blocksToBeMoved.push(block);
  7187. blocks['delete'](block.getKey());
  7188. });
  7189. });
  7190. }
  7191. var blocksBefore = blockMapWithoutBlocksToBeMoved.toSeq().takeUntil(function (v) {
  7192. return v === targetBlock;
  7193. });
  7194. var blocksAfter = blockMapWithoutBlocksToBeMoved.toSeq().skipUntil(function (v) {
  7195. return v === targetBlock;
  7196. }).skip(1);
  7197. var slicedBlocks = blocksToBeMoved.map(function (block) {
  7198. return [block.getKey(), block];
  7199. });
  7200. var newBlocks = OrderedMap$3();
  7201. if (insertionMode === 'before') {
  7202. var blockBefore = contentState.getBlockBefore(targetKey);
  7203. !(!blockBefore || blockBefore.getKey() !== blockToBeMoved.getKey()) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Block cannot be moved next to itself.') : invariant_1(false) : void 0;
  7204. newBlocks = blocksBefore.concat([].concat(slicedBlocks, [[targetKey, targetBlock]]), blocksAfter).toOrderedMap();
  7205. } else if (insertionMode === 'after') {
  7206. var blockAfter = contentState.getBlockAfter(targetKey);
  7207. !(!blockAfter || blockAfter.getKey() !== blockKey) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Block cannot be moved next to itself.') : invariant_1(false) : void 0;
  7208. newBlocks = blocksBefore.concat([[targetKey, targetBlock]].concat(slicedBlocks), blocksAfter).toOrderedMap();
  7209. }
  7210. return contentState.merge({
  7211. blockMap: updateBlockMapLinks$3(newBlocks, blockToBeMoved, targetBlock, insertionMode, isExperimentalTreeBlock),
  7212. selectionBefore: contentState.getSelectionAfter(),
  7213. selectionAfter: contentState.getSelectionAfter().merge({
  7214. anchorKey: blockKey,
  7215. focusKey: blockKey
  7216. })
  7217. });
  7218. };
  7219. var moveBlockInContentState_1 = moveBlockInContentState;
  7220. var ContentBlockRecord$1 = ContentBlock_1;
  7221. var List$8 = immutable.List,
  7222. Repeat$5 = immutable.Repeat;
  7223. var AtomicBlockUtils = {
  7224. insertAtomicBlock: function insertAtomicBlock(editorState, entityKey, character) {
  7225. var contentState = editorState.getCurrentContent();
  7226. var selectionState = editorState.getSelection();
  7227. var afterRemoval = DraftModifier_1.removeRange(contentState, selectionState, 'backward');
  7228. var targetSelection = afterRemoval.getSelectionAfter();
  7229. var afterSplit = DraftModifier_1.splitBlock(afterRemoval, targetSelection);
  7230. var insertionTarget = afterSplit.getSelectionAfter();
  7231. var asAtomicBlock = DraftModifier_1.setBlockType(afterSplit, insertionTarget, 'atomic');
  7232. var charData = CharacterMetadata_1.create({ entity: entityKey });
  7233. var atomicBlockConfig = {
  7234. key: generateRandomKey_1(),
  7235. type: 'atomic',
  7236. text: character,
  7237. characterList: List$8(Repeat$5(charData, character.length))
  7238. };
  7239. var atomicDividerBlockConfig = {
  7240. key: generateRandomKey_1(),
  7241. type: 'unstyled'
  7242. };
  7243. var fragmentArray = [new ContentBlockRecord$1(atomicBlockConfig), new ContentBlockRecord$1(atomicDividerBlockConfig)];
  7244. var fragment = BlockMapBuilder_1.createFromArray(fragmentArray);
  7245. var withAtomicBlock = DraftModifier_1.replaceWithFragment(asAtomicBlock, insertionTarget, fragment);
  7246. var newContent = withAtomicBlock.merge({
  7247. selectionBefore: selectionState,
  7248. selectionAfter: withAtomicBlock.getSelectionAfter().set('hasFocus', true)
  7249. });
  7250. return EditorState_1.push(editorState, newContent, 'insert-fragment');
  7251. },
  7252. moveAtomicBlock: function moveAtomicBlock(editorState, atomicBlock, targetRange, insertionMode) {
  7253. var contentState = editorState.getCurrentContent();
  7254. var selectionState = editorState.getSelection();
  7255. var withMovedAtomicBlock = void 0;
  7256. if (insertionMode === 'before' || insertionMode === 'after') {
  7257. var targetBlock = contentState.getBlockForKey(insertionMode === 'before' ? targetRange.getStartKey() : targetRange.getEndKey());
  7258. withMovedAtomicBlock = moveBlockInContentState_1(contentState, atomicBlock, targetBlock, insertionMode);
  7259. } else {
  7260. var afterRemoval = DraftModifier_1.removeRange(contentState, targetRange, 'backward');
  7261. var selectionAfterRemoval = afterRemoval.getSelectionAfter();
  7262. var _targetBlock = afterRemoval.getBlockForKey(selectionAfterRemoval.getFocusKey());
  7263. if (selectionAfterRemoval.getStartOffset() === 0) {
  7264. withMovedAtomicBlock = moveBlockInContentState_1(afterRemoval, atomicBlock, _targetBlock, 'before');
  7265. } else if (selectionAfterRemoval.getEndOffset() === _targetBlock.getLength()) {
  7266. withMovedAtomicBlock = moveBlockInContentState_1(afterRemoval, atomicBlock, _targetBlock, 'after');
  7267. } else {
  7268. var afterSplit = DraftModifier_1.splitBlock(afterRemoval, selectionAfterRemoval);
  7269. var selectionAfterSplit = afterSplit.getSelectionAfter();
  7270. var _targetBlock2 = afterSplit.getBlockForKey(selectionAfterSplit.getFocusKey());
  7271. withMovedAtomicBlock = moveBlockInContentState_1(afterSplit, atomicBlock, _targetBlock2, 'before');
  7272. }
  7273. }
  7274. var newContent = withMovedAtomicBlock.merge({
  7275. selectionBefore: selectionState,
  7276. selectionAfter: withMovedAtomicBlock.getSelectionAfter().set('hasFocus', true)
  7277. });
  7278. return EditorState_1.push(editorState, newContent, 'move-block');
  7279. }
  7280. };
  7281. var AtomicBlockUtils_1 = AtomicBlockUtils;
  7282. function _classCallCheck$8(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7283. var List$9 = immutable.List;
  7284. var DELIMITER = '.';
  7285. /**
  7286. * A CompositeDraftDecorator traverses through a list of DraftDecorator
  7287. * instances to identify sections of a ContentBlock that should be rendered
  7288. * in a "decorated" manner. For example, hashtags, mentions, and links may
  7289. * be intended to stand out visually, be rendered as anchors, etc.
  7290. *
  7291. * The list of decorators supplied to the constructor will be used in the
  7292. * order they are provided. This allows the caller to specify a priority for
  7293. * string matching, in case of match collisions among decorators.
  7294. *
  7295. * For instance, I may have a link with a `#` in its text. Though this section
  7296. * of text may match our hashtag decorator, it should not be treated as a
  7297. * hashtag. I should therefore list my link DraftDecorator
  7298. * before my hashtag DraftDecorator when constructing this composite
  7299. * decorator instance.
  7300. *
  7301. * Thus, when a collision like this is encountered, the earlier match is
  7302. * preserved and the new match is discarded.
  7303. */
  7304. var CompositeDraftDecorator = function () {
  7305. function CompositeDraftDecorator(decorators) {
  7306. _classCallCheck$8(this, CompositeDraftDecorator);
  7307. // Copy the decorator array, since we use this array order to determine
  7308. // precedence of decoration matching. If the array is mutated externally,
  7309. // we don't want to be affected here.
  7310. this._decorators = decorators.slice();
  7311. }
  7312. CompositeDraftDecorator.prototype.getDecorations = function getDecorations(block, contentState) {
  7313. var decorations = Array(block.getText().length).fill(null);
  7314. this._decorators.forEach(function ( /*object*/decorator, /*number*/ii) {
  7315. var counter = 0;
  7316. var strategy = decorator.strategy;
  7317. var callback = function callback( /*number*/start, /*number*/end) {
  7318. // Find out if any of our matching range is already occupied
  7319. // by another decorator. If so, discard the match. Otherwise, store
  7320. // the component key for rendering.
  7321. if (canOccupySlice(decorations, start, end)) {
  7322. occupySlice(decorations, start, end, ii + DELIMITER + counter);
  7323. counter++;
  7324. }
  7325. };
  7326. strategy(block, callback, contentState);
  7327. });
  7328. return List$9(decorations);
  7329. };
  7330. CompositeDraftDecorator.prototype.getComponentForKey = function getComponentForKey(key) {
  7331. var componentKey = parseInt(key.split(DELIMITER)[0], 10);
  7332. return this._decorators[componentKey].component;
  7333. };
  7334. CompositeDraftDecorator.prototype.getPropsForKey = function getPropsForKey(key) {
  7335. var componentKey = parseInt(key.split(DELIMITER)[0], 10);
  7336. return this._decorators[componentKey].props;
  7337. };
  7338. return CompositeDraftDecorator;
  7339. }();
  7340. /**
  7341. * Determine whether we can occupy the specified slice of the decorations
  7342. * array.
  7343. */
  7344. function canOccupySlice(decorations, start, end) {
  7345. for (var ii = start; ii < end; ii++) {
  7346. if (decorations[ii] != null) {
  7347. return false;
  7348. }
  7349. }
  7350. return true;
  7351. }
  7352. /**
  7353. * Splice the specified component into our decoration array at the desired
  7354. * range.
  7355. */
  7356. function occupySlice(targetArr, start, end, componentKey) {
  7357. for (var ii = start; ii < end; ii++) {
  7358. targetArr[ii] = componentKey;
  7359. }
  7360. }
  7361. var CompositeDraftDecorator_1 = CompositeDraftDecorator;
  7362. /**
  7363. * Copyright (c) 2013-present, Facebook, Inc.
  7364. *
  7365. * This source code is licensed under the MIT license found in the
  7366. * LICENSE file in the root directory of this source tree.
  7367. *
  7368. */
  7369. /**
  7370. * This function is used to mark string literals representing CSS class names
  7371. * so that they can be transformed statically. This allows for modularization
  7372. * and minification of CSS class names.
  7373. *
  7374. * In static_upstream, this function is actually implemented, but it should
  7375. * eventually be replaced with something more descriptive, and the transform
  7376. * that is used in the main stack should be ported for use elsewhere.
  7377. *
  7378. * @param string|object className to modularize, or an object of key/values.
  7379. * In the object case, the values are conditions that
  7380. * determine if the className keys should be included.
  7381. * @param [string ...] Variable list of classNames in the string case.
  7382. * @return string Renderable space-separated CSS className.
  7383. */
  7384. function cx(classNames) {
  7385. if (typeof classNames == 'object') {
  7386. return Object.keys(classNames).filter(function (className) {
  7387. return classNames[className];
  7388. }).map(replace).join(' ');
  7389. }
  7390. return Array.prototype.map.call(arguments, replace).join(' ');
  7391. }
  7392. function replace(str) {
  7393. return str.replace(/\//g, '-');
  7394. }
  7395. var cx_1 = cx;
  7396. var Map$8 = immutable.Map;
  7397. var UL_WRAP = React__default.createElement('ul', { className: cx_1('public/DraftStyleDefault/ul') });
  7398. var OL_WRAP = React__default.createElement('ol', { className: cx_1('public/DraftStyleDefault/ol') });
  7399. var PRE_WRAP = React__default.createElement('pre', { className: cx_1('public/DraftStyleDefault/pre') });
  7400. var DefaultDraftBlockRenderMap = Map$8({
  7401. 'header-one': {
  7402. element: 'h1'
  7403. },
  7404. 'header-two': {
  7405. element: 'h2'
  7406. },
  7407. 'header-three': {
  7408. element: 'h3'
  7409. },
  7410. 'header-four': {
  7411. element: 'h4'
  7412. },
  7413. 'header-five': {
  7414. element: 'h5'
  7415. },
  7416. 'header-six': {
  7417. element: 'h6'
  7418. },
  7419. 'unordered-list-item': {
  7420. element: 'li',
  7421. wrapper: UL_WRAP
  7422. },
  7423. 'ordered-list-item': {
  7424. element: 'li',
  7425. wrapper: OL_WRAP
  7426. },
  7427. blockquote: {
  7428. element: 'blockquote'
  7429. },
  7430. atomic: {
  7431. element: 'figure'
  7432. },
  7433. 'code-block': {
  7434. element: 'pre',
  7435. wrapper: PRE_WRAP
  7436. },
  7437. unstyled: {
  7438. element: 'div',
  7439. aliasedElements: ['p']
  7440. }
  7441. });
  7442. var DefaultDraftBlockRenderMap_1 = DefaultDraftBlockRenderMap;
  7443. /**
  7444. * Copyright (c) 2013-present, Facebook, Inc.
  7445. * All rights reserved.
  7446. *
  7447. * This source code is licensed under the BSD-style license found in the
  7448. * LICENSE file in the root directory of this source tree. An additional grant
  7449. * of patent rights can be found in the PATENTS file in the same directory.
  7450. *
  7451. * @providesModule DefaultDraftInlineStyle
  7452. * @format
  7453. *
  7454. */
  7455. var DefaultDraftInlineStyle = {
  7456. BOLD: {
  7457. fontWeight: 'bold'
  7458. },
  7459. CODE: {
  7460. fontFamily: 'monospace',
  7461. wordWrap: 'break-word'
  7462. },
  7463. ITALIC: {
  7464. fontStyle: 'italic'
  7465. },
  7466. STRIKETHROUGH: {
  7467. textDecoration: 'line-through'
  7468. },
  7469. UNDERLINE: {
  7470. textDecoration: 'underline'
  7471. }
  7472. };
  7473. /**
  7474. * Copyright (c) 2013-present, Facebook, Inc.
  7475. *
  7476. * This source code is licensed under the MIT license found in the
  7477. * LICENSE file in the root directory of this source tree.
  7478. *
  7479. */
  7480. var Keys = {
  7481. BACKSPACE: 8,
  7482. TAB: 9,
  7483. RETURN: 13,
  7484. ALT: 18,
  7485. ESC: 27,
  7486. SPACE: 32,
  7487. PAGE_UP: 33,
  7488. PAGE_DOWN: 34,
  7489. END: 35,
  7490. HOME: 36,
  7491. LEFT: 37,
  7492. UP: 38,
  7493. RIGHT: 39,
  7494. DOWN: 40,
  7495. DELETE: 46,
  7496. COMMA: 188,
  7497. PERIOD: 190,
  7498. A: 65,
  7499. Z: 90,
  7500. ZERO: 48,
  7501. NUMPAD_0: 96,
  7502. NUMPAD_9: 105
  7503. };
  7504. /**
  7505. * Copyright (c) 2013-present, Facebook, Inc.
  7506. * All rights reserved.
  7507. *
  7508. * This source code is licensed under the BSD-style license found in the
  7509. * LICENSE file in the root directory of this source tree. An additional grant
  7510. * of patent rights can be found in the PATENTS file in the same directory.
  7511. *
  7512. * @providesModule getEntityKeyForSelection
  7513. * @format
  7514. *
  7515. */
  7516. /**
  7517. * Return the entity key that should be used when inserting text for the
  7518. * specified target selection, only if the entity is `MUTABLE`. `IMMUTABLE`
  7519. * and `SEGMENTED` entities should not be used for insertion behavior.
  7520. */
  7521. function getEntityKeyForSelection(contentState, targetSelection) {
  7522. var entityKey;
  7523. if (targetSelection.isCollapsed()) {
  7524. var key = targetSelection.getAnchorKey();
  7525. var offset = targetSelection.getAnchorOffset();
  7526. if (offset > 0) {
  7527. entityKey = contentState.getBlockForKey(key).getEntityAt(offset - 1);
  7528. if (entityKey !== contentState.getBlockForKey(key).getEntityAt(offset)) {
  7529. return null;
  7530. }
  7531. return filterKey(contentState.getEntityMap(), entityKey);
  7532. }
  7533. return null;
  7534. }
  7535. var startKey = targetSelection.getStartKey();
  7536. var startOffset = targetSelection.getStartOffset();
  7537. var startBlock = contentState.getBlockForKey(startKey);
  7538. entityKey = startOffset === startBlock.getLength() ? null : startBlock.getEntityAt(startOffset);
  7539. return filterKey(contentState.getEntityMap(), entityKey);
  7540. }
  7541. /**
  7542. * Determine whether an entity key corresponds to a `MUTABLE` entity. If so,
  7543. * return it. If not, return null.
  7544. */
  7545. function filterKey(entityMap, entityKey) {
  7546. if (entityKey) {
  7547. var entity = entityMap.__get(entityKey);
  7548. return entity.getMutability() === 'MUTABLE' ? entityKey : null;
  7549. }
  7550. return null;
  7551. }
  7552. var getEntityKeyForSelection_1 = getEntityKeyForSelection;
  7553. /**
  7554. * Copyright (c) 2013-present, Facebook, Inc.
  7555. * All rights reserved.
  7556. *
  7557. * This source code is licensed under the BSD-style license found in the
  7558. * LICENSE file in the root directory of this source tree. An additional grant
  7559. * of patent rights can be found in the PATENTS file in the same directory.
  7560. *
  7561. * @providesModule isEventHandled
  7562. * @format
  7563. *
  7564. */
  7565. /**
  7566. * Utility method for determining whether or not the value returned
  7567. * from a handler indicates that it was handled.
  7568. */
  7569. function isEventHandled(value) {
  7570. return value === 'handled' || value === true;
  7571. }
  7572. var isEventHandled_1 = isEventHandled;
  7573. /**
  7574. * Copyright (c) 2013-present, Facebook, Inc.
  7575. * All rights reserved.
  7576. *
  7577. * This source code is licensed under the BSD-style license found in the
  7578. * LICENSE file in the root directory of this source tree. An additional grant
  7579. * of patent rights can be found in the PATENTS file in the same directory.
  7580. *
  7581. * @providesModule isSelectionAtLeafStart
  7582. * @format
  7583. *
  7584. */
  7585. function isSelectionAtLeafStart(editorState) {
  7586. var selection = editorState.getSelection();
  7587. var anchorKey = selection.getAnchorKey();
  7588. var blockTree = editorState.getBlockTree(anchorKey);
  7589. var offset = selection.getStartOffset();
  7590. var isAtStart = false;
  7591. blockTree.some(function (leafSet) {
  7592. if (offset === leafSet.get('start')) {
  7593. isAtStart = true;
  7594. return true;
  7595. }
  7596. if (offset < leafSet.get('end')) {
  7597. return leafSet.get('leaves').some(function (leaf) {
  7598. var leafStart = leaf.get('start');
  7599. if (offset === leafStart) {
  7600. isAtStart = true;
  7601. return true;
  7602. }
  7603. return false;
  7604. });
  7605. }
  7606. return false;
  7607. });
  7608. return isAtStart;
  7609. }
  7610. var isSelectionAtLeafStart_1 = isSelectionAtLeafStart;
  7611. /**
  7612. * Millisecond delay to allow `compositionstart` to fire again upon
  7613. * `compositionend`.
  7614. *
  7615. * This is used for Korean input to ensure that typing can continue without
  7616. * the editor trying to render too quickly. More specifically, Safari 7.1+
  7617. * triggers `compositionstart` a little slower than Chrome/FF, which
  7618. * leads to composed characters being resolved and re-render occurring
  7619. * sooner than we want.
  7620. */
  7621. var RESOLVE_DELAY = 20;
  7622. /**
  7623. * A handful of variables used to track the current composition and its
  7624. * resolution status. These exist at the module level because it is not
  7625. * possible to have compositions occurring in multiple editors simultaneously,
  7626. * and it simplifies state management with respect to the DraftEditor component.
  7627. */
  7628. var resolved = false;
  7629. var stillComposing = false;
  7630. var textInputData = '';
  7631. var DraftEditorCompositionHandler = {
  7632. onBeforeInput: function onBeforeInput(editor, e) {
  7633. textInputData = (textInputData || '') + e.data;
  7634. },
  7635. /**
  7636. * A `compositionstart` event has fired while we're still in composition
  7637. * mode. Continue the current composition session to prevent a re-render.
  7638. */
  7639. onCompositionStart: function onCompositionStart(editor) {
  7640. stillComposing = true;
  7641. },
  7642. /**
  7643. * Attempt to end the current composition session.
  7644. *
  7645. * Defer handling because browser will still insert the chars into active
  7646. * element after `compositionend`. If a `compositionstart` event fires
  7647. * before `resolveComposition` executes, our composition session will
  7648. * continue.
  7649. *
  7650. * The `resolved` flag is useful because certain IME interfaces fire the
  7651. * `compositionend` event multiple times, thus queueing up multiple attempts
  7652. * at handling the composition. Since handling the same composition event
  7653. * twice could break the DOM, we only use the first event. Example: Arabic
  7654. * Google Input Tools on Windows 8.1 fires `compositionend` three times.
  7655. */
  7656. onCompositionEnd: function onCompositionEnd(editor) {
  7657. resolved = false;
  7658. stillComposing = false;
  7659. setTimeout(function () {
  7660. if (!resolved) {
  7661. DraftEditorCompositionHandler.resolveComposition(editor);
  7662. }
  7663. }, RESOLVE_DELAY);
  7664. },
  7665. /**
  7666. * In Safari, keydown events may fire when committing compositions. If
  7667. * the arrow keys are used to commit, prevent default so that the cursor
  7668. * doesn't move, otherwise it will jump back noticeably on re-render.
  7669. */
  7670. onKeyDown: function onKeyDown(editor, e) {
  7671. if (!stillComposing) {
  7672. // If a keydown event is received after compositionend but before the
  7673. // 20ms timer expires (ex: type option-E then backspace, or type A then
  7674. // backspace in 2-Set Korean), we should immediately resolve the
  7675. // composition and reinterpret the key press in edit mode.
  7676. DraftEditorCompositionHandler.resolveComposition(editor);
  7677. editor._onKeyDown(e);
  7678. return;
  7679. }
  7680. if (e.which === Keys.RIGHT || e.which === Keys.LEFT) {
  7681. e.preventDefault();
  7682. }
  7683. },
  7684. /**
  7685. * Keypress events may fire when committing compositions. In Firefox,
  7686. * pressing RETURN commits the composition and inserts extra newline
  7687. * characters that we do not want. `preventDefault` allows the composition
  7688. * to be committed while preventing the extra characters.
  7689. */
  7690. onKeyPress: function onKeyPress(editor, e) {
  7691. if (e.which === Keys.RETURN) {
  7692. e.preventDefault();
  7693. }
  7694. },
  7695. /**
  7696. * Attempt to insert composed characters into the document.
  7697. *
  7698. * If we are still in a composition session, do nothing. Otherwise, insert
  7699. * the characters into the document and terminate the composition session.
  7700. *
  7701. * If no characters were composed -- for instance, the user
  7702. * deleted all composed characters and committed nothing new --
  7703. * force a re-render. We also re-render when the composition occurs
  7704. * at the beginning of a leaf, to ensure that if the browser has
  7705. * created a new text node for the composition, we will discard it.
  7706. *
  7707. * Resetting innerHTML will move focus to the beginning of the editor,
  7708. * so we update to force it back to the correct place.
  7709. */
  7710. resolveComposition: function resolveComposition(editor) {
  7711. if (stillComposing) {
  7712. return;
  7713. }
  7714. resolved = true;
  7715. var composedChars = textInputData;
  7716. textInputData = '';
  7717. var editorState = EditorState_1.set(editor._latestEditorState, {
  7718. inCompositionMode: false
  7719. });
  7720. var currentStyle = editorState.getCurrentInlineStyle();
  7721. var entityKey = getEntityKeyForSelection_1(editorState.getCurrentContent(), editorState.getSelection());
  7722. var mustReset = !composedChars || isSelectionAtLeafStart_1(editorState) || currentStyle.size > 0 || entityKey !== null;
  7723. if (mustReset) {
  7724. editor.restoreEditorDOM();
  7725. }
  7726. editor.exitCurrentMode();
  7727. if (composedChars) {
  7728. // If characters have been composed, re-rendering with the update
  7729. // is sufficient to reset the editor.
  7730. var contentState = DraftModifier_1.replaceText(editorState.getCurrentContent(), editorState.getSelection(), composedChars, currentStyle, entityKey);
  7731. editor.update(EditorState_1.push(editorState, contentState, 'insert-characters'));
  7732. return;
  7733. }
  7734. if (mustReset) {
  7735. editor.update(EditorState_1.set(editorState, {
  7736. nativelyRenderedContent: null,
  7737. forceSelection: true
  7738. }));
  7739. }
  7740. }
  7741. };
  7742. var DraftEditorCompositionHandler_1 = DraftEditorCompositionHandler;
  7743. var uaParser = _commonjsHelpers.createCommonjsModule(function (module, exports) {
  7744. /*!
  7745. * UAParser.js v0.7.21
  7746. * Lightweight JavaScript-based User-Agent string parser
  7747. * https://github.com/faisalman/ua-parser-js
  7748. *
  7749. * Copyright © 2012-2019 Faisal Salman <f@faisalman.com>
  7750. * Licensed under MIT License
  7751. */
  7752. (function (window, undefined$1) {
  7753. //////////////
  7754. // Constants
  7755. /////////////
  7756. var LIBVERSION = '0.7.21',
  7757. EMPTY = '',
  7758. UNKNOWN = '?',
  7759. FUNC_TYPE = 'function',
  7760. OBJ_TYPE = 'object',
  7761. STR_TYPE = 'string',
  7762. MAJOR = 'major', // deprecated
  7763. MODEL = 'model',
  7764. NAME = 'name',
  7765. TYPE = 'type',
  7766. VENDOR = 'vendor',
  7767. VERSION = 'version',
  7768. ARCHITECTURE= 'architecture',
  7769. CONSOLE = 'console',
  7770. MOBILE = 'mobile',
  7771. TABLET = 'tablet',
  7772. SMARTTV = 'smarttv',
  7773. WEARABLE = 'wearable',
  7774. EMBEDDED = 'embedded';
  7775. ///////////
  7776. // Helper
  7777. //////////
  7778. var util = {
  7779. extend : function (regexes, extensions) {
  7780. var mergedRegexes = {};
  7781. for (var i in regexes) {
  7782. if (extensions[i] && extensions[i].length % 2 === 0) {
  7783. mergedRegexes[i] = extensions[i].concat(regexes[i]);
  7784. } else {
  7785. mergedRegexes[i] = regexes[i];
  7786. }
  7787. }
  7788. return mergedRegexes;
  7789. },
  7790. has : function (str1, str2) {
  7791. if (typeof str1 === "string") {
  7792. return str2.toLowerCase().indexOf(str1.toLowerCase()) !== -1;
  7793. } else {
  7794. return false;
  7795. }
  7796. },
  7797. lowerize : function (str) {
  7798. return str.toLowerCase();
  7799. },
  7800. major : function (version) {
  7801. return typeof(version) === STR_TYPE ? version.replace(/[^\d\.]/g,'').split(".")[0] : undefined$1;
  7802. },
  7803. trim : function (str) {
  7804. return str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
  7805. }
  7806. };
  7807. ///////////////
  7808. // Map helper
  7809. //////////////
  7810. var mapper = {
  7811. rgx : function (ua, arrays) {
  7812. var i = 0, j, k, p, q, matches, match;
  7813. // loop through all regexes maps
  7814. while (i < arrays.length && !matches) {
  7815. var regex = arrays[i], // even sequence (0,2,4,..)
  7816. props = arrays[i + 1]; // odd sequence (1,3,5,..)
  7817. j = k = 0;
  7818. // try matching uastring with regexes
  7819. while (j < regex.length && !matches) {
  7820. matches = regex[j++].exec(ua);
  7821. if (!!matches) {
  7822. for (p = 0; p < props.length; p++) {
  7823. match = matches[++k];
  7824. q = props[p];
  7825. // check if given property is actually array
  7826. if (typeof q === OBJ_TYPE && q.length > 0) {
  7827. if (q.length == 2) {
  7828. if (typeof q[1] == FUNC_TYPE) {
  7829. // assign modified match
  7830. this[q[0]] = q[1].call(this, match);
  7831. } else {
  7832. // assign given value, ignore regex match
  7833. this[q[0]] = q[1];
  7834. }
  7835. } else if (q.length == 3) {
  7836. // check whether function or regex
  7837. if (typeof q[1] === FUNC_TYPE && !(q[1].exec && q[1].test)) {
  7838. // call function (usually string mapper)
  7839. this[q[0]] = match ? q[1].call(this, match, q[2]) : undefined$1;
  7840. } else {
  7841. // sanitize match using given regex
  7842. this[q[0]] = match ? match.replace(q[1], q[2]) : undefined$1;
  7843. }
  7844. } else if (q.length == 4) {
  7845. this[q[0]] = match ? q[3].call(this, match.replace(q[1], q[2])) : undefined$1;
  7846. }
  7847. } else {
  7848. this[q] = match ? match : undefined$1;
  7849. }
  7850. }
  7851. }
  7852. }
  7853. i += 2;
  7854. }
  7855. },
  7856. str : function (str, map) {
  7857. for (var i in map) {
  7858. // check if array
  7859. if (typeof map[i] === OBJ_TYPE && map[i].length > 0) {
  7860. for (var j = 0; j < map[i].length; j++) {
  7861. if (util.has(map[i][j], str)) {
  7862. return (i === UNKNOWN) ? undefined$1 : i;
  7863. }
  7864. }
  7865. } else if (util.has(map[i], str)) {
  7866. return (i === UNKNOWN) ? undefined$1 : i;
  7867. }
  7868. }
  7869. return str;
  7870. }
  7871. };
  7872. ///////////////
  7873. // String map
  7874. //////////////
  7875. var maps = {
  7876. browser : {
  7877. oldsafari : {
  7878. version : {
  7879. '1.0' : '/8',
  7880. '1.2' : '/1',
  7881. '1.3' : '/3',
  7882. '2.0' : '/412',
  7883. '2.0.2' : '/416',
  7884. '2.0.3' : '/417',
  7885. '2.0.4' : '/419',
  7886. '?' : '/'
  7887. }
  7888. }
  7889. },
  7890. device : {
  7891. amazon : {
  7892. model : {
  7893. 'Fire Phone' : ['SD', 'KF']
  7894. }
  7895. },
  7896. sprint : {
  7897. model : {
  7898. 'Evo Shift 4G' : '7373KT'
  7899. },
  7900. vendor : {
  7901. 'HTC' : 'APA',
  7902. 'Sprint' : 'Sprint'
  7903. }
  7904. }
  7905. },
  7906. os : {
  7907. windows : {
  7908. version : {
  7909. 'ME' : '4.90',
  7910. 'NT 3.11' : 'NT3.51',
  7911. 'NT 4.0' : 'NT4.0',
  7912. '2000' : 'NT 5.0',
  7913. 'XP' : ['NT 5.1', 'NT 5.2'],
  7914. 'Vista' : 'NT 6.0',
  7915. '7' : 'NT 6.1',
  7916. '8' : 'NT 6.2',
  7917. '8.1' : 'NT 6.3',
  7918. '10' : ['NT 6.4', 'NT 10.0'],
  7919. 'RT' : 'ARM'
  7920. }
  7921. }
  7922. }
  7923. };
  7924. //////////////
  7925. // Regex map
  7926. /////////////
  7927. var regexes = {
  7928. browser : [[
  7929. // Presto based
  7930. /(opera\smini)\/([\w\.-]+)/i, // Opera Mini
  7931. /(opera\s[mobiletab]+).+version\/([\w\.-]+)/i, // Opera Mobi/Tablet
  7932. /(opera).+version\/([\w\.]+)/i, // Opera > 9.80
  7933. /(opera)[\/\s]+([\w\.]+)/i // Opera < 9.80
  7934. ], [NAME, VERSION], [
  7935. /(opios)[\/\s]+([\w\.]+)/i // Opera mini on iphone >= 8.0
  7936. ], [[NAME, 'Opera Mini'], VERSION], [
  7937. /\s(opr)\/([\w\.]+)/i // Opera Webkit
  7938. ], [[NAME, 'Opera'], VERSION], [
  7939. // Mixed
  7940. /(kindle)\/([\w\.]+)/i, // Kindle
  7941. /(lunascape|maxthon|netfront|jasmine|blazer)[\/\s]?([\w\.]*)/i,
  7942. // Lunascape/Maxthon/Netfront/Jasmine/Blazer
  7943. // Trident based
  7944. /(avant\s|iemobile|slim)(?:browser)?[\/\s]?([\w\.]*)/i,
  7945. // Avant/IEMobile/SlimBrowser
  7946. /(bidubrowser|baidubrowser)[\/\s]?([\w\.]+)/i, // Baidu Browser
  7947. /(?:ms|\()(ie)\s([\w\.]+)/i, // Internet Explorer
  7948. // Webkit/KHTML based
  7949. /(rekonq)\/([\w\.]*)/i, // Rekonq
  7950. /(chromium|flock|rockmelt|midori|epiphany|silk|skyfire|ovibrowser|bolt|iron|vivaldi|iridium|phantomjs|bowser|quark|qupzilla|falkon)\/([\w\.-]+)/i
  7951. // Chromium/Flock/RockMelt/Midori/Epiphany/Silk/Skyfire/Bolt/Iron/Iridium/PhantomJS/Bowser/QupZilla/Falkon
  7952. ], [NAME, VERSION], [
  7953. /(konqueror)\/([\w\.]+)/i // Konqueror
  7954. ], [[NAME, 'Konqueror'], VERSION], [
  7955. /(trident).+rv[:\s]([\w\.]+).+like\sgecko/i // IE11
  7956. ], [[NAME, 'IE'], VERSION], [
  7957. /(edge|edgios|edga|edg)\/((\d+)?[\w\.]+)/i // Microsoft Edge
  7958. ], [[NAME, 'Edge'], VERSION], [
  7959. /(yabrowser)\/([\w\.]+)/i // Yandex
  7960. ], [[NAME, 'Yandex'], VERSION], [
  7961. /(Avast)\/([\w\.]+)/i // Avast Secure Browser
  7962. ], [[NAME, 'Avast Secure Browser'], VERSION], [
  7963. /(AVG)\/([\w\.]+)/i // AVG Secure Browser
  7964. ], [[NAME, 'AVG Secure Browser'], VERSION], [
  7965. /(puffin)\/([\w\.]+)/i // Puffin
  7966. ], [[NAME, 'Puffin'], VERSION], [
  7967. /(focus)\/([\w\.]+)/i // Firefox Focus
  7968. ], [[NAME, 'Firefox Focus'], VERSION], [
  7969. /(opt)\/([\w\.]+)/i // Opera Touch
  7970. ], [[NAME, 'Opera Touch'], VERSION], [
  7971. /((?:[\s\/])uc?\s?browser|(?:juc.+)ucweb)[\/\s]?([\w\.]+)/i // UCBrowser
  7972. ], [[NAME, 'UCBrowser'], VERSION], [
  7973. /(comodo_dragon)\/([\w\.]+)/i // Comodo Dragon
  7974. ], [[NAME, /_/g, ' '], VERSION], [
  7975. /(windowswechat qbcore)\/([\w\.]+)/i // WeChat Desktop for Windows Built-in Browser
  7976. ], [[NAME, 'WeChat(Win) Desktop'], VERSION], [
  7977. /(micromessenger)\/([\w\.]+)/i // WeChat
  7978. ], [[NAME, 'WeChat'], VERSION], [
  7979. /(brave)\/([\w\.]+)/i // Brave browser
  7980. ], [[NAME, 'Brave'], VERSION], [
  7981. /(qqbrowserlite)\/([\w\.]+)/i // QQBrowserLite
  7982. ], [NAME, VERSION], [
  7983. /(QQ)\/([\d\.]+)/i // QQ, aka ShouQ
  7984. ], [NAME, VERSION], [
  7985. /m?(qqbrowser)[\/\s]?([\w\.]+)/i // QQBrowser
  7986. ], [NAME, VERSION], [
  7987. /(baiduboxapp)[\/\s]?([\w\.]+)/i // Baidu App
  7988. ], [NAME, VERSION], [
  7989. /(2345Explorer)[\/\s]?([\w\.]+)/i // 2345 Browser
  7990. ], [NAME, VERSION], [
  7991. /(MetaSr)[\/\s]?([\w\.]+)/i // SouGouBrowser
  7992. ], [NAME], [
  7993. /(LBBROWSER)/i // LieBao Browser
  7994. ], [NAME], [
  7995. /xiaomi\/miuibrowser\/([\w\.]+)/i // MIUI Browser
  7996. ], [VERSION, [NAME, 'MIUI Browser']], [
  7997. /;fbav\/([\w\.]+);/i // Facebook App for iOS & Android
  7998. ], [VERSION, [NAME, 'Facebook']], [
  7999. /safari\s(line)\/([\w\.]+)/i, // Line App for iOS
  8000. /android.+(line)\/([\w\.]+)\/iab/i // Line App for Android
  8001. ], [NAME, VERSION], [
  8002. /headlesschrome(?:\/([\w\.]+)|\s)/i // Chrome Headless
  8003. ], [VERSION, [NAME, 'Chrome Headless']], [
  8004. /\swv\).+(chrome)\/([\w\.]+)/i // Chrome WebView
  8005. ], [[NAME, /(.+)/, '$1 WebView'], VERSION], [
  8006. /((?:oculus|samsung)browser)\/([\w\.]+)/i
  8007. ], [[NAME, /(.+(?:g|us))(.+)/, '$1 $2'], VERSION], [ // Oculus / Samsung Browser
  8008. /android.+version\/([\w\.]+)\s+(?:mobile\s?safari|safari)*/i // Android Browser
  8009. ], [VERSION, [NAME, 'Android Browser']], [
  8010. /(sailfishbrowser)\/([\w\.]+)/i // Sailfish Browser
  8011. ], [[NAME, 'Sailfish Browser'], VERSION], [
  8012. /(chrome|omniweb|arora|[tizenoka]{5}\s?browser)\/v?([\w\.]+)/i
  8013. // Chrome/OmniWeb/Arora/Tizen/Nokia
  8014. ], [NAME, VERSION], [
  8015. /(dolfin)\/([\w\.]+)/i // Dolphin
  8016. ], [[NAME, 'Dolphin'], VERSION], [
  8017. /(qihu|qhbrowser|qihoobrowser|360browser)/i // 360
  8018. ], [[NAME, '360 Browser']], [
  8019. /((?:android.+)crmo|crios)\/([\w\.]+)/i // Chrome for Android/iOS
  8020. ], [[NAME, 'Chrome'], VERSION], [
  8021. /(coast)\/([\w\.]+)/i // Opera Coast
  8022. ], [[NAME, 'Opera Coast'], VERSION], [
  8023. /fxios\/([\w\.-]+)/i // Firefox for iOS
  8024. ], [VERSION, [NAME, 'Firefox']], [
  8025. /version\/([\w\.]+).+?mobile\/\w+\s(safari)/i // Mobile Safari
  8026. ], [VERSION, [NAME, 'Mobile Safari']], [
  8027. /version\/([\w\.]+).+?(mobile\s?safari|safari)/i // Safari & Safari Mobile
  8028. ], [VERSION, NAME], [
  8029. /webkit.+?(gsa)\/([\w\.]+).+?(mobile\s?safari|safari)(\/[\w\.]+)/i // Google Search Appliance on iOS
  8030. ], [[NAME, 'GSA'], VERSION], [
  8031. /webkit.+?(mobile\s?safari|safari)(\/[\w\.]+)/i // Safari < 3.0
  8032. ], [NAME, [VERSION, mapper.str, maps.browser.oldsafari.version]], [
  8033. /(webkit|khtml)\/([\w\.]+)/i
  8034. ], [NAME, VERSION], [
  8035. // Gecko based
  8036. /(navigator|netscape)\/([\w\.-]+)/i // Netscape
  8037. ], [[NAME, 'Netscape'], VERSION], [
  8038. /(swiftfox)/i, // Swiftfox
  8039. /(icedragon|iceweasel|camino|chimera|fennec|maemo\sbrowser|minimo|conkeror)[\/\s]?([\w\.\+]+)/i,
  8040. // IceDragon/Iceweasel/Camino/Chimera/Fennec/Maemo/Minimo/Conkeror
  8041. /(firefox|seamonkey|k-meleon|icecat|iceape|firebird|phoenix|palemoon|basilisk|waterfox)\/([\w\.-]+)$/i,
  8042. // Firefox/SeaMonkey/K-Meleon/IceCat/IceApe/Firebird/Phoenix
  8043. /(mozilla)\/([\w\.]+).+rv\:.+gecko\/\d+/i, // Mozilla
  8044. // Other
  8045. /(polaris|lynx|dillo|icab|doris|amaya|w3m|netsurf|sleipnir)[\/\s]?([\w\.]+)/i,
  8046. // Polaris/Lynx/Dillo/iCab/Doris/Amaya/w3m/NetSurf/Sleipnir
  8047. /(links)\s\(([\w\.]+)/i, // Links
  8048. /(gobrowser)\/?([\w\.]*)/i, // GoBrowser
  8049. /(ice\s?browser)\/v?([\w\._]+)/i, // ICE Browser
  8050. /(mosaic)[\/\s]([\w\.]+)/i // Mosaic
  8051. ], [NAME, VERSION]
  8052. ],
  8053. cpu : [[
  8054. /(?:(amd|x(?:(?:86|64)[_-])?|wow|win)64)[;\)]/i // AMD64
  8055. ], [[ARCHITECTURE, 'amd64']], [
  8056. /(ia32(?=;))/i // IA32 (quicktime)
  8057. ], [[ARCHITECTURE, util.lowerize]], [
  8058. /((?:i[346]|x)86)[;\)]/i // IA32
  8059. ], [[ARCHITECTURE, 'ia32']], [
  8060. // PocketPC mistakenly identified as PowerPC
  8061. /windows\s(ce|mobile);\sppc;/i
  8062. ], [[ARCHITECTURE, 'arm']], [
  8063. /((?:ppc|powerpc)(?:64)?)(?:\smac|;|\))/i // PowerPC
  8064. ], [[ARCHITECTURE, /ower/, '', util.lowerize]], [
  8065. /(sun4\w)[;\)]/i // SPARC
  8066. ], [[ARCHITECTURE, 'sparc']], [
  8067. /((?:avr32|ia64(?=;))|68k(?=\))|arm(?:64|(?=v\d+[;l]))|(?=atmel\s)avr|(?:irix|mips|sparc)(?:64)?(?=;)|pa-risc)/i
  8068. // IA64, 68K, ARM/64, AVR/32, IRIX/64, MIPS/64, SPARC/64, PA-RISC
  8069. ], [[ARCHITECTURE, util.lowerize]]
  8070. ],
  8071. device : [[
  8072. /\((ipad|playbook);[\w\s\),;-]+(rim|apple)/i // iPad/PlayBook
  8073. ], [MODEL, VENDOR, [TYPE, TABLET]], [
  8074. /applecoremedia\/[\w\.]+ \((ipad)/ // iPad
  8075. ], [MODEL, [VENDOR, 'Apple'], [TYPE, TABLET]], [
  8076. /(apple\s{0,1}tv)/i // Apple TV
  8077. ], [[MODEL, 'Apple TV'], [VENDOR, 'Apple'], [TYPE, SMARTTV]], [
  8078. /(archos)\s(gamepad2?)/i, // Archos
  8079. /(hp).+(touchpad)/i, // HP TouchPad
  8080. /(hp).+(tablet)/i, // HP Tablet
  8081. /(kindle)\/([\w\.]+)/i, // Kindle
  8082. /\s(nook)[\w\s]+build\/(\w+)/i, // Nook
  8083. /(dell)\s(strea[kpr\s\d]*[\dko])/i // Dell Streak
  8084. ], [VENDOR, MODEL, [TYPE, TABLET]], [
  8085. /(kf[A-z]+)\sbuild\/.+silk\//i // Kindle Fire HD
  8086. ], [MODEL, [VENDOR, 'Amazon'], [TYPE, TABLET]], [
  8087. /(sd|kf)[0349hijorstuw]+\sbuild\/.+silk\//i // Fire Phone
  8088. ], [[MODEL, mapper.str, maps.device.amazon.model], [VENDOR, 'Amazon'], [TYPE, MOBILE]], [
  8089. /android.+aft([bms])\sbuild/i // Fire TV
  8090. ], [MODEL, [VENDOR, 'Amazon'], [TYPE, SMARTTV]], [
  8091. /\((ip[honed|\s\w*]+);.+(apple)/i // iPod/iPhone
  8092. ], [MODEL, VENDOR, [TYPE, MOBILE]], [
  8093. /\((ip[honed|\s\w*]+);/i // iPod/iPhone
  8094. ], [MODEL, [VENDOR, 'Apple'], [TYPE, MOBILE]], [
  8095. /(blackberry)[\s-]?(\w+)/i, // BlackBerry
  8096. /(blackberry|benq|palm(?=\-)|sonyericsson|acer|asus|dell|meizu|motorola|polytron)[\s_-]?([\w-]*)/i,
  8097. // BenQ/Palm/Sony-Ericsson/Acer/Asus/Dell/Meizu/Motorola/Polytron
  8098. /(hp)\s([\w\s]+\w)/i, // HP iPAQ
  8099. /(asus)-?(\w+)/i // Asus
  8100. ], [VENDOR, MODEL, [TYPE, MOBILE]], [
  8101. /\(bb10;\s(\w+)/i // BlackBerry 10
  8102. ], [MODEL, [VENDOR, 'BlackBerry'], [TYPE, MOBILE]], [
  8103. // Asus Tablets
  8104. /android.+(transfo[prime\s]{4,10}\s\w+|eeepc|slider\s\w+|nexus 7|padfone|p00c)/i
  8105. ], [MODEL, [VENDOR, 'Asus'], [TYPE, TABLET]], [
  8106. /(sony)\s(tablet\s[ps])\sbuild\//i, // Sony
  8107. /(sony)?(?:sgp.+)\sbuild\//i
  8108. ], [[VENDOR, 'Sony'], [MODEL, 'Xperia Tablet'], [TYPE, TABLET]], [
  8109. /android.+\s([c-g]\d{4}|so[-l]\w+)(?=\sbuild\/|\).+chrome\/(?![1-6]{0,1}\d\.))/i
  8110. ], [MODEL, [VENDOR, 'Sony'], [TYPE, MOBILE]], [
  8111. /\s(ouya)\s/i, // Ouya
  8112. /(nintendo)\s([wids3u]+)/i // Nintendo
  8113. ], [VENDOR, MODEL, [TYPE, CONSOLE]], [
  8114. /android.+;\s(shield)\sbuild/i // Nvidia
  8115. ], [MODEL, [VENDOR, 'Nvidia'], [TYPE, CONSOLE]], [
  8116. /(playstation\s[34portablevi]+)/i // Playstation
  8117. ], [MODEL, [VENDOR, 'Sony'], [TYPE, CONSOLE]], [
  8118. /(sprint\s(\w+))/i // Sprint Phones
  8119. ], [[VENDOR, mapper.str, maps.device.sprint.vendor], [MODEL, mapper.str, maps.device.sprint.model], [TYPE, MOBILE]], [
  8120. /(htc)[;_\s-]+([\w\s]+(?=\)|\sbuild)|\w+)/i, // HTC
  8121. /(zte)-(\w*)/i, // ZTE
  8122. /(alcatel|geeksphone|nexian|panasonic|(?=;\s)sony)[_\s-]?([\w-]*)/i
  8123. // Alcatel/GeeksPhone/Nexian/Panasonic/Sony
  8124. ], [VENDOR, [MODEL, /_/g, ' '], [TYPE, MOBILE]], [
  8125. /(nexus\s9)/i // HTC Nexus 9
  8126. ], [MODEL, [VENDOR, 'HTC'], [TYPE, TABLET]], [
  8127. /d\/huawei([\w\s-]+)[;\)]/i,
  8128. /(nexus\s6p|vog-l29|ane-lx1|eml-l29)/i // Huawei
  8129. ], [MODEL, [VENDOR, 'Huawei'], [TYPE, MOBILE]], [
  8130. /android.+(bah2?-a?[lw]\d{2})/i // Huawei MediaPad
  8131. ], [MODEL, [VENDOR, 'Huawei'], [TYPE, TABLET]], [
  8132. /(microsoft);\s(lumia[\s\w]+)/i // Microsoft Lumia
  8133. ], [VENDOR, MODEL, [TYPE, MOBILE]], [
  8134. /[\s\(;](xbox(?:\sone)?)[\s\);]/i // Microsoft Xbox
  8135. ], [MODEL, [VENDOR, 'Microsoft'], [TYPE, CONSOLE]], [
  8136. /(kin\.[onetw]{3})/i // Microsoft Kin
  8137. ], [[MODEL, /\./g, ' '], [VENDOR, 'Microsoft'], [TYPE, MOBILE]], [
  8138. // Motorola
  8139. /\s(milestone|droid(?:[2-4x]|\s(?:bionic|x2|pro|razr))?:?(\s4g)?)[\w\s]+build\//i,
  8140. /mot[\s-]?(\w*)/i,
  8141. /(XT\d{3,4}) build\//i,
  8142. /(nexus\s6)/i
  8143. ], [MODEL, [VENDOR, 'Motorola'], [TYPE, MOBILE]], [
  8144. /android.+\s(mz60\d|xoom[\s2]{0,2})\sbuild\//i
  8145. ], [MODEL, [VENDOR, 'Motorola'], [TYPE, TABLET]], [
  8146. /hbbtv\/\d+\.\d+\.\d+\s+\([\w\s]*;\s*(\w[^;]*);([^;]*)/i // HbbTV devices
  8147. ], [[VENDOR, util.trim], [MODEL, util.trim], [TYPE, SMARTTV]], [
  8148. /hbbtv.+maple;(\d+)/i
  8149. ], [[MODEL, /^/, 'SmartTV'], [VENDOR, 'Samsung'], [TYPE, SMARTTV]], [
  8150. /\(dtv[\);].+(aquos)/i // Sharp
  8151. ], [MODEL, [VENDOR, 'Sharp'], [TYPE, SMARTTV]], [
  8152. /android.+((sch-i[89]0\d|shw-m380s|gt-p\d{4}|gt-n\d+|sgh-t8[56]9|nexus 10))/i,
  8153. /((SM-T\w+))/i
  8154. ], [[VENDOR, 'Samsung'], MODEL, [TYPE, TABLET]], [ // Samsung
  8155. /smart-tv.+(samsung)/i
  8156. ], [VENDOR, [TYPE, SMARTTV], MODEL], [
  8157. /((s[cgp]h-\w+|gt-\w+|galaxy\snexus|sm-\w[\w\d]+))/i,
  8158. /(sam[sung]*)[\s-]*(\w+-?[\w-]*)/i,
  8159. /sec-((sgh\w+))/i
  8160. ], [[VENDOR, 'Samsung'], MODEL, [TYPE, MOBILE]], [
  8161. /sie-(\w*)/i // Siemens
  8162. ], [MODEL, [VENDOR, 'Siemens'], [TYPE, MOBILE]], [
  8163. /(maemo|nokia).*(n900|lumia\s\d+)/i, // Nokia
  8164. /(nokia)[\s_-]?([\w-]*)/i
  8165. ], [[VENDOR, 'Nokia'], MODEL, [TYPE, MOBILE]], [
  8166. /android[x\d\.\s;]+\s([ab][1-7]\-?[0178a]\d\d?)/i // Acer
  8167. ], [MODEL, [VENDOR, 'Acer'], [TYPE, TABLET]], [
  8168. /android.+([vl]k\-?\d{3})\s+build/i // LG Tablet
  8169. ], [MODEL, [VENDOR, 'LG'], [TYPE, TABLET]], [
  8170. /android\s3\.[\s\w;-]{10}(lg?)-([06cv9]{3,4})/i // LG Tablet
  8171. ], [[VENDOR, 'LG'], MODEL, [TYPE, TABLET]], [
  8172. /(lg) netcast\.tv/i // LG SmartTV
  8173. ], [VENDOR, MODEL, [TYPE, SMARTTV]], [
  8174. /(nexus\s[45])/i, // LG
  8175. /lg[e;\s\/-]+(\w*)/i,
  8176. /android.+lg(\-?[\d\w]+)\s+build/i
  8177. ], [MODEL, [VENDOR, 'LG'], [TYPE, MOBILE]], [
  8178. /(lenovo)\s?(s(?:5000|6000)(?:[\w-]+)|tab(?:[\s\w]+))/i // Lenovo tablets
  8179. ], [VENDOR, MODEL, [TYPE, TABLET]], [
  8180. /android.+(ideatab[a-z0-9\-\s]+)/i // Lenovo
  8181. ], [MODEL, [VENDOR, 'Lenovo'], [TYPE, TABLET]], [
  8182. /(lenovo)[_\s-]?([\w-]+)/i
  8183. ], [VENDOR, MODEL, [TYPE, MOBILE]], [
  8184. /linux;.+((jolla));/i // Jolla
  8185. ], [VENDOR, MODEL, [TYPE, MOBILE]], [
  8186. /((pebble))app\/[\d\.]+\s/i // Pebble
  8187. ], [VENDOR, MODEL, [TYPE, WEARABLE]], [
  8188. /android.+;\s(oppo)\s?([\w\s]+)\sbuild/i // OPPO
  8189. ], [VENDOR, MODEL, [TYPE, MOBILE]], [
  8190. /crkey/i // Google Chromecast
  8191. ], [[MODEL, 'Chromecast'], [VENDOR, 'Google'], [TYPE, SMARTTV]], [
  8192. /android.+;\s(glass)\s\d/i // Google Glass
  8193. ], [MODEL, [VENDOR, 'Google'], [TYPE, WEARABLE]], [
  8194. /android.+;\s(pixel c)[\s)]/i // Google Pixel C
  8195. ], [MODEL, [VENDOR, 'Google'], [TYPE, TABLET]], [
  8196. /android.+;\s(pixel( [23])?( xl)?)[\s)]/i // Google Pixel
  8197. ], [MODEL, [VENDOR, 'Google'], [TYPE, MOBILE]], [
  8198. /android.+;\s(\w+)\s+build\/hm\1/i, // Xiaomi Hongmi 'numeric' models
  8199. /android.+(hm[\s\-_]*note?[\s_]*(?:\d\w)?)\s+build/i, // Xiaomi Hongmi
  8200. /android.+(mi[\s\-_]*(?:a\d|one|one[\s_]plus|note lte)?[\s_]*(?:\d?\w?)[\s_]*(?:plus)?)\s+build/i,
  8201. // Xiaomi Mi
  8202. /android.+(redmi[\s\-_]*(?:note)?(?:[\s_]*[\w\s]+))\s+build/i // Redmi Phones
  8203. ], [[MODEL, /_/g, ' '], [VENDOR, 'Xiaomi'], [TYPE, MOBILE]], [
  8204. /android.+(mi[\s\-_]*(?:pad)(?:[\s_]*[\w\s]+))\s+build/i // Mi Pad tablets
  8205. ],[[MODEL, /_/g, ' '], [VENDOR, 'Xiaomi'], [TYPE, TABLET]], [
  8206. /android.+;\s(m[1-5]\snote)\sbuild/i // Meizu
  8207. ], [MODEL, [VENDOR, 'Meizu'], [TYPE, MOBILE]], [
  8208. /(mz)-([\w-]{2,})/i
  8209. ], [[VENDOR, 'Meizu'], MODEL, [TYPE, MOBILE]], [
  8210. /android.+a000(1)\s+build/i, // OnePlus
  8211. /android.+oneplus\s(a\d{4})[\s)]/i
  8212. ], [MODEL, [VENDOR, 'OnePlus'], [TYPE, MOBILE]], [
  8213. /android.+[;\/]\s*(RCT[\d\w]+)\s+build/i // RCA Tablets
  8214. ], [MODEL, [VENDOR, 'RCA'], [TYPE, TABLET]], [
  8215. /android.+[;\/\s]+(Venue[\d\s]{2,7})\s+build/i // Dell Venue Tablets
  8216. ], [MODEL, [VENDOR, 'Dell'], [TYPE, TABLET]], [
  8217. /android.+[;\/]\s*(Q[T|M][\d\w]+)\s+build/i // Verizon Tablet
  8218. ], [MODEL, [VENDOR, 'Verizon'], [TYPE, TABLET]], [
  8219. /android.+[;\/]\s+(Barnes[&\s]+Noble\s+|BN[RT])(V?.*)\s+build/i // Barnes & Noble Tablet
  8220. ], [[VENDOR, 'Barnes & Noble'], MODEL, [TYPE, TABLET]], [
  8221. /android.+[;\/]\s+(TM\d{3}.*\b)\s+build/i // Barnes & Noble Tablet
  8222. ], [MODEL, [VENDOR, 'NuVision'], [TYPE, TABLET]], [
  8223. /android.+;\s(k88)\sbuild/i // ZTE K Series Tablet
  8224. ], [MODEL, [VENDOR, 'ZTE'], [TYPE, TABLET]], [
  8225. /android.+[;\/]\s*(gen\d{3})\s+build.*49h/i // Swiss GEN Mobile
  8226. ], [MODEL, [VENDOR, 'Swiss'], [TYPE, MOBILE]], [
  8227. /android.+[;\/]\s*(zur\d{3})\s+build/i // Swiss ZUR Tablet
  8228. ], [MODEL, [VENDOR, 'Swiss'], [TYPE, TABLET]], [
  8229. /android.+[;\/]\s*((Zeki)?TB.*\b)\s+build/i // Zeki Tablets
  8230. ], [MODEL, [VENDOR, 'Zeki'], [TYPE, TABLET]], [
  8231. /(android).+[;\/]\s+([YR]\d{2})\s+build/i,
  8232. /android.+[;\/]\s+(Dragon[\-\s]+Touch\s+|DT)(\w{5})\sbuild/i // Dragon Touch Tablet
  8233. ], [[VENDOR, 'Dragon Touch'], MODEL, [TYPE, TABLET]], [
  8234. /android.+[;\/]\s*(NS-?\w{0,9})\sbuild/i // Insignia Tablets
  8235. ], [MODEL, [VENDOR, 'Insignia'], [TYPE, TABLET]], [
  8236. /android.+[;\/]\s*((NX|Next)-?\w{0,9})\s+build/i // NextBook Tablets
  8237. ], [MODEL, [VENDOR, 'NextBook'], [TYPE, TABLET]], [
  8238. /android.+[;\/]\s*(Xtreme\_)?(V(1[045]|2[015]|30|40|60|7[05]|90))\s+build/i
  8239. ], [[VENDOR, 'Voice'], MODEL, [TYPE, MOBILE]], [ // Voice Xtreme Phones
  8240. /android.+[;\/]\s*(LVTEL\-)?(V1[12])\s+build/i // LvTel Phones
  8241. ], [[VENDOR, 'LvTel'], MODEL, [TYPE, MOBILE]], [
  8242. /android.+;\s(PH-1)\s/i
  8243. ], [MODEL, [VENDOR, 'Essential'], [TYPE, MOBILE]], [ // Essential PH-1
  8244. /android.+[;\/]\s*(V(100MD|700NA|7011|917G).*\b)\s+build/i // Envizen Tablets
  8245. ], [MODEL, [VENDOR, 'Envizen'], [TYPE, TABLET]], [
  8246. /android.+[;\/]\s*(Le[\s\-]+Pan)[\s\-]+(\w{1,9})\s+build/i // Le Pan Tablets
  8247. ], [VENDOR, MODEL, [TYPE, TABLET]], [
  8248. /android.+[;\/]\s*(Trio[\s\-]*.*)\s+build/i // MachSpeed Tablets
  8249. ], [MODEL, [VENDOR, 'MachSpeed'], [TYPE, TABLET]], [
  8250. /android.+[;\/]\s*(Trinity)[\-\s]*(T\d{3})\s+build/i // Trinity Tablets
  8251. ], [VENDOR, MODEL, [TYPE, TABLET]], [
  8252. /android.+[;\/]\s*TU_(1491)\s+build/i // Rotor Tablets
  8253. ], [MODEL, [VENDOR, 'Rotor'], [TYPE, TABLET]], [
  8254. /android.+(KS(.+))\s+build/i // Amazon Kindle Tablets
  8255. ], [MODEL, [VENDOR, 'Amazon'], [TYPE, TABLET]], [
  8256. /android.+(Gigaset)[\s\-]+(Q\w{1,9})\s+build/i // Gigaset Tablets
  8257. ], [VENDOR, MODEL, [TYPE, TABLET]], [
  8258. /\s(tablet|tab)[;\/]/i, // Unidentifiable Tablet
  8259. /\s(mobile)(?:[;\/]|\ssafari)/i // Unidentifiable Mobile
  8260. ], [[TYPE, util.lowerize], VENDOR, MODEL], [
  8261. /[\s\/\(](smart-?tv)[;\)]/i // SmartTV
  8262. ], [[TYPE, SMARTTV]], [
  8263. /(android[\w\.\s\-]{0,9});.+build/i // Generic Android Device
  8264. ], [MODEL, [VENDOR, 'Generic']]
  8265. ],
  8266. engine : [[
  8267. /windows.+\sedge\/([\w\.]+)/i // EdgeHTML
  8268. ], [VERSION, [NAME, 'EdgeHTML']], [
  8269. /webkit\/537\.36.+chrome\/(?!27)([\w\.]+)/i // Blink
  8270. ], [VERSION, [NAME, 'Blink']], [
  8271. /(presto)\/([\w\.]+)/i, // Presto
  8272. /(webkit|trident|netfront|netsurf|amaya|lynx|w3m|goanna)\/([\w\.]+)/i,
  8273. // WebKit/Trident/NetFront/NetSurf/Amaya/Lynx/w3m/Goanna
  8274. /(khtml|tasman|links)[\/\s]\(?([\w\.]+)/i, // KHTML/Tasman/Links
  8275. /(icab)[\/\s]([23]\.[\d\.]+)/i // iCab
  8276. ], [NAME, VERSION], [
  8277. /rv\:([\w\.]{1,9}).+(gecko)/i // Gecko
  8278. ], [VERSION, NAME]
  8279. ],
  8280. os : [[
  8281. // Windows based
  8282. /microsoft\s(windows)\s(vista|xp)/i // Windows (iTunes)
  8283. ], [NAME, VERSION], [
  8284. /(windows)\snt\s6\.2;\s(arm)/i, // Windows RT
  8285. /(windows\sphone(?:\sos)*)[\s\/]?([\d\.\s\w]*)/i, // Windows Phone
  8286. /(windows\smobile|windows)[\s\/]?([ntce\d\.\s]+\w)/i
  8287. ], [NAME, [VERSION, mapper.str, maps.os.windows.version]], [
  8288. /(win(?=3|9|n)|win\s9x\s)([nt\d\.]+)/i
  8289. ], [[NAME, 'Windows'], [VERSION, mapper.str, maps.os.windows.version]], [
  8290. // Mobile/Embedded OS
  8291. /\((bb)(10);/i // BlackBerry 10
  8292. ], [[NAME, 'BlackBerry'], VERSION], [
  8293. /(blackberry)\w*\/?([\w\.]*)/i, // Blackberry
  8294. /(tizen|kaios)[\/\s]([\w\.]+)/i, // Tizen/KaiOS
  8295. /(android|webos|palm\sos|qnx|bada|rim\stablet\sos|meego|sailfish|contiki)[\/\s-]?([\w\.]*)/i
  8296. // Android/WebOS/Palm/QNX/Bada/RIM/MeeGo/Contiki/Sailfish OS
  8297. ], [NAME, VERSION], [
  8298. /(symbian\s?os|symbos|s60(?=;))[\/\s-]?([\w\.]*)/i // Symbian
  8299. ], [[NAME, 'Symbian'], VERSION], [
  8300. /\((series40);/i // Series 40
  8301. ], [NAME], [
  8302. /mozilla.+\(mobile;.+gecko.+firefox/i // Firefox OS
  8303. ], [[NAME, 'Firefox OS'], VERSION], [
  8304. // Console
  8305. /(nintendo|playstation)\s([wids34portablevu]+)/i, // Nintendo/Playstation
  8306. // GNU/Linux based
  8307. /(mint)[\/\s\(]?(\w*)/i, // Mint
  8308. /(mageia|vectorlinux)[;\s]/i, // Mageia/VectorLinux
  8309. /(joli|[kxln]?ubuntu|debian|suse|opensuse|gentoo|(?=\s)arch|slackware|fedora|mandriva|centos|pclinuxos|redhat|zenwalk|linpus)[\/\s-]?(?!chrom)([\w\.-]*)/i,
  8310. // Joli/Ubuntu/Debian/SUSE/Gentoo/Arch/Slackware
  8311. // Fedora/Mandriva/CentOS/PCLinuxOS/RedHat/Zenwalk/Linpus
  8312. /(hurd|linux)\s?([\w\.]*)/i, // Hurd/Linux
  8313. /(gnu)\s?([\w\.]*)/i // GNU
  8314. ], [NAME, VERSION], [
  8315. /(cros)\s[\w]+\s([\w\.]+\w)/i // Chromium OS
  8316. ], [[NAME, 'Chromium OS'], VERSION],[
  8317. // Solaris
  8318. /(sunos)\s?([\w\.\d]*)/i // Solaris
  8319. ], [[NAME, 'Solaris'], VERSION], [
  8320. // BSD based
  8321. /\s([frentopc-]{0,4}bsd|dragonfly)\s?([\w\.]*)/i // FreeBSD/NetBSD/OpenBSD/PC-BSD/DragonFly
  8322. ], [NAME, VERSION],[
  8323. /(haiku)\s(\w+)/i // Haiku
  8324. ], [NAME, VERSION],[
  8325. /cfnetwork\/.+darwin/i,
  8326. /ip[honead]{2,4}(?:.*os\s([\w]+)\slike\smac|;\sopera)/i // iOS
  8327. ], [[VERSION, /_/g, '.'], [NAME, 'iOS']], [
  8328. /(mac\sos\sx)\s?([\w\s\.]*)/i,
  8329. /(macintosh|mac(?=_powerpc)\s)/i // Mac OS
  8330. ], [[NAME, 'Mac OS'], [VERSION, /_/g, '.']], [
  8331. // Other
  8332. /((?:open)?solaris)[\/\s-]?([\w\.]*)/i, // Solaris
  8333. /(aix)\s((\d)(?=\.|\)|\s)[\w\.])*/i, // AIX
  8334. /(plan\s9|minix|beos|os\/2|amigaos|morphos|risc\sos|openvms|fuchsia)/i,
  8335. // Plan9/Minix/BeOS/OS2/AmigaOS/MorphOS/RISCOS/OpenVMS/Fuchsia
  8336. /(unix)\s?([\w\.]*)/i // UNIX
  8337. ], [NAME, VERSION]
  8338. ]
  8339. };
  8340. /////////////////
  8341. // Constructor
  8342. ////////////////
  8343. var UAParser = function (uastring, extensions) {
  8344. if (typeof uastring === 'object') {
  8345. extensions = uastring;
  8346. uastring = undefined$1;
  8347. }
  8348. if (!(this instanceof UAParser)) {
  8349. return new UAParser(uastring, extensions).getResult();
  8350. }
  8351. var ua = uastring || ((window && window.navigator && window.navigator.userAgent) ? window.navigator.userAgent : EMPTY);
  8352. var rgxmap = extensions ? util.extend(regexes, extensions) : regexes;
  8353. this.getBrowser = function () {
  8354. var browser = { name: undefined$1, version: undefined$1 };
  8355. mapper.rgx.call(browser, ua, rgxmap.browser);
  8356. browser.major = util.major(browser.version); // deprecated
  8357. return browser;
  8358. };
  8359. this.getCPU = function () {
  8360. var cpu = { architecture: undefined$1 };
  8361. mapper.rgx.call(cpu, ua, rgxmap.cpu);
  8362. return cpu;
  8363. };
  8364. this.getDevice = function () {
  8365. var device = { vendor: undefined$1, model: undefined$1, type: undefined$1 };
  8366. mapper.rgx.call(device, ua, rgxmap.device);
  8367. return device;
  8368. };
  8369. this.getEngine = function () {
  8370. var engine = { name: undefined$1, version: undefined$1 };
  8371. mapper.rgx.call(engine, ua, rgxmap.engine);
  8372. return engine;
  8373. };
  8374. this.getOS = function () {
  8375. var os = { name: undefined$1, version: undefined$1 };
  8376. mapper.rgx.call(os, ua, rgxmap.os);
  8377. return os;
  8378. };
  8379. this.getResult = function () {
  8380. return {
  8381. ua : this.getUA(),
  8382. browser : this.getBrowser(),
  8383. engine : this.getEngine(),
  8384. os : this.getOS(),
  8385. device : this.getDevice(),
  8386. cpu : this.getCPU()
  8387. };
  8388. };
  8389. this.getUA = function () {
  8390. return ua;
  8391. };
  8392. this.setUA = function (uastring) {
  8393. ua = uastring;
  8394. return this;
  8395. };
  8396. return this;
  8397. };
  8398. UAParser.VERSION = LIBVERSION;
  8399. UAParser.BROWSER = {
  8400. NAME : NAME,
  8401. MAJOR : MAJOR, // deprecated
  8402. VERSION : VERSION
  8403. };
  8404. UAParser.CPU = {
  8405. ARCHITECTURE : ARCHITECTURE
  8406. };
  8407. UAParser.DEVICE = {
  8408. MODEL : MODEL,
  8409. VENDOR : VENDOR,
  8410. TYPE : TYPE,
  8411. CONSOLE : CONSOLE,
  8412. MOBILE : MOBILE,
  8413. SMARTTV : SMARTTV,
  8414. TABLET : TABLET,
  8415. WEARABLE: WEARABLE,
  8416. EMBEDDED: EMBEDDED
  8417. };
  8418. UAParser.ENGINE = {
  8419. NAME : NAME,
  8420. VERSION : VERSION
  8421. };
  8422. UAParser.OS = {
  8423. NAME : NAME,
  8424. VERSION : VERSION
  8425. };
  8426. ///////////
  8427. // Export
  8428. //////////
  8429. // check js environment
  8430. {
  8431. // nodejs env
  8432. if ( module.exports) {
  8433. exports = module.exports = UAParser;
  8434. }
  8435. exports.UAParser = UAParser;
  8436. }
  8437. // jQuery/Zepto specific (optional)
  8438. // Note:
  8439. // In AMD env the global scope should be kept clean, but jQuery is an exception.
  8440. // jQuery always exports to global scope, unless jQuery.noConflict(true) is used,
  8441. // and we should catch that.
  8442. var $ = window && (window.jQuery || window.Zepto);
  8443. if ($ && !$.ua) {
  8444. var parser = new UAParser();
  8445. $.ua = parser.getResult();
  8446. $.ua.get = function () {
  8447. return parser.getUA();
  8448. };
  8449. $.ua.set = function (uastring) {
  8450. parser.setUA(uastring);
  8451. var result = parser.getResult();
  8452. for (var prop in result) {
  8453. $.ua[prop] = result[prop];
  8454. }
  8455. };
  8456. }
  8457. })(typeof window === 'object' ? window : _commonjsHelpers.commonjsGlobal);
  8458. });
  8459. var uaParser_1 = uaParser.UAParser;
  8460. var UNKNOWN = 'Unknown';
  8461. var PLATFORM_MAP = {
  8462. 'Mac OS': 'Mac OS X'
  8463. };
  8464. /**
  8465. * Convert from UAParser platform name to what we expect.
  8466. */
  8467. function convertPlatformName(name) {
  8468. return PLATFORM_MAP[name] || name;
  8469. }
  8470. /**
  8471. * Get the version number in parts. This is very naive. We actually get major
  8472. * version as a part of UAParser already, which is generally good enough, but
  8473. * let's get the minor just in case.
  8474. */
  8475. function getBrowserVersion(version) {
  8476. if (!version) {
  8477. return {
  8478. major: '',
  8479. minor: ''
  8480. };
  8481. }
  8482. var parts = version.split('.');
  8483. return {
  8484. major: parts[0],
  8485. minor: parts[1]
  8486. };
  8487. }
  8488. /**
  8489. * Get the UA data fom UAParser and then convert it to the format we're
  8490. * expecting for our APIS.
  8491. */
  8492. var parser = new uaParser();
  8493. var results = parser.getResult();
  8494. // Do some conversion first.
  8495. var browserVersionData = getBrowserVersion(results.browser.version);
  8496. var uaData = {
  8497. browserArchitecture: results.cpu.architecture || UNKNOWN,
  8498. browserFullVersion: results.browser.version || UNKNOWN,
  8499. browserMinorVersion: browserVersionData.minor || UNKNOWN,
  8500. browserName: results.browser.name || UNKNOWN,
  8501. browserVersion: results.browser.major || UNKNOWN,
  8502. deviceName: results.device.model || UNKNOWN,
  8503. engineName: results.engine.name || UNKNOWN,
  8504. engineVersion: results.engine.version || UNKNOWN,
  8505. platformArchitecture: results.cpu.architecture || UNKNOWN,
  8506. platformName: convertPlatformName(results.os.name) || UNKNOWN,
  8507. platformVersion: results.os.version || UNKNOWN,
  8508. platformFullVersion: results.os.version || UNKNOWN
  8509. };
  8510. var UserAgentData = uaData;
  8511. var componentRegex = /\./;
  8512. var orRegex = /\|\|/;
  8513. var rangeRegex = /\s+\-\s+/;
  8514. var modifierRegex = /^(<=|<|=|>=|~>|~|>|)?\s*(.+)/;
  8515. var numericRegex = /^(\d*)(.*)/;
  8516. /**
  8517. * Splits input `range` on "||" and returns true if any subrange matches
  8518. * `version`.
  8519. *
  8520. * @param {string} range
  8521. * @param {string} version
  8522. * @returns {boolean}
  8523. */
  8524. function checkOrExpression(range, version) {
  8525. var expressions = range.split(orRegex);
  8526. if (expressions.length > 1) {
  8527. return expressions.some(function (range) {
  8528. return VersionRange.contains(range, version);
  8529. });
  8530. } else {
  8531. range = expressions[0].trim();
  8532. return checkRangeExpression(range, version);
  8533. }
  8534. }
  8535. /**
  8536. * Splits input `range` on " - " (the surrounding whitespace is required) and
  8537. * returns true if version falls between the two operands.
  8538. *
  8539. * @param {string} range
  8540. * @param {string} version
  8541. * @returns {boolean}
  8542. */
  8543. function checkRangeExpression(range, version) {
  8544. var expressions = range.split(rangeRegex);
  8545. !(expressions.length > 0 && expressions.length <= 2) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'the "-" operator expects exactly 2 operands') : invariant_1(false) : void 0;
  8546. if (expressions.length === 1) {
  8547. return checkSimpleExpression(expressions[0], version);
  8548. } else {
  8549. var startVersion = expressions[0],
  8550. endVersion = expressions[1];
  8551. !(isSimpleVersion(startVersion) && isSimpleVersion(endVersion)) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'operands to the "-" operator must be simple (no modifiers)') : invariant_1(false) : void 0;
  8552. return checkSimpleExpression('>=' + startVersion, version) && checkSimpleExpression('<=' + endVersion, version);
  8553. }
  8554. }
  8555. /**
  8556. * Checks if `range` matches `version`. `range` should be a "simple" range (ie.
  8557. * not a compound range using the " - " or "||" operators).
  8558. *
  8559. * @param {string} range
  8560. * @param {string} version
  8561. * @returns {boolean}
  8562. */
  8563. function checkSimpleExpression(range, version) {
  8564. range = range.trim();
  8565. if (range === '') {
  8566. return true;
  8567. }
  8568. var versionComponents = version.split(componentRegex);
  8569. var _getModifierAndCompon = getModifierAndComponents(range),
  8570. modifier = _getModifierAndCompon.modifier,
  8571. rangeComponents = _getModifierAndCompon.rangeComponents;
  8572. switch (modifier) {
  8573. case '<':
  8574. return checkLessThan(versionComponents, rangeComponents);
  8575. case '<=':
  8576. return checkLessThanOrEqual(versionComponents, rangeComponents);
  8577. case '>=':
  8578. return checkGreaterThanOrEqual(versionComponents, rangeComponents);
  8579. case '>':
  8580. return checkGreaterThan(versionComponents, rangeComponents);
  8581. case '~':
  8582. case '~>':
  8583. return checkApproximateVersion(versionComponents, rangeComponents);
  8584. default:
  8585. return checkEqual(versionComponents, rangeComponents);
  8586. }
  8587. }
  8588. /**
  8589. * Checks whether `a` is less than `b`.
  8590. *
  8591. * @param {array<string>} a
  8592. * @param {array<string>} b
  8593. * @returns {boolean}
  8594. */
  8595. function checkLessThan(a, b) {
  8596. return compareComponents(a, b) === -1;
  8597. }
  8598. /**
  8599. * Checks whether `a` is less than or equal to `b`.
  8600. *
  8601. * @param {array<string>} a
  8602. * @param {array<string>} b
  8603. * @returns {boolean}
  8604. */
  8605. function checkLessThanOrEqual(a, b) {
  8606. var result = compareComponents(a, b);
  8607. return result === -1 || result === 0;
  8608. }
  8609. /**
  8610. * Checks whether `a` is equal to `b`.
  8611. *
  8612. * @param {array<string>} a
  8613. * @param {array<string>} b
  8614. * @returns {boolean}
  8615. */
  8616. function checkEqual(a, b) {
  8617. return compareComponents(a, b) === 0;
  8618. }
  8619. /**
  8620. * Checks whether `a` is greater than or equal to `b`.
  8621. *
  8622. * @param {array<string>} a
  8623. * @param {array<string>} b
  8624. * @returns {boolean}
  8625. */
  8626. function checkGreaterThanOrEqual(a, b) {
  8627. var result = compareComponents(a, b);
  8628. return result === 1 || result === 0;
  8629. }
  8630. /**
  8631. * Checks whether `a` is greater than `b`.
  8632. *
  8633. * @param {array<string>} a
  8634. * @param {array<string>} b
  8635. * @returns {boolean}
  8636. */
  8637. function checkGreaterThan(a, b) {
  8638. return compareComponents(a, b) === 1;
  8639. }
  8640. /**
  8641. * Checks whether `a` is "reasonably close" to `b` (as described in
  8642. * https://www.npmjs.org/doc/misc/semver.html). For example, if `b` is "1.3.1"
  8643. * then "reasonably close" is defined as ">= 1.3.1 and < 1.4".
  8644. *
  8645. * @param {array<string>} a
  8646. * @param {array<string>} b
  8647. * @returns {boolean}
  8648. */
  8649. function checkApproximateVersion(a, b) {
  8650. var lowerBound = b.slice();
  8651. var upperBound = b.slice();
  8652. if (upperBound.length > 1) {
  8653. upperBound.pop();
  8654. }
  8655. var lastIndex = upperBound.length - 1;
  8656. var numeric = parseInt(upperBound[lastIndex], 10);
  8657. if (isNumber(numeric)) {
  8658. upperBound[lastIndex] = numeric + 1 + '';
  8659. }
  8660. return checkGreaterThanOrEqual(a, lowerBound) && checkLessThan(a, upperBound);
  8661. }
  8662. /**
  8663. * Extracts the optional modifier (<, <=, =, >=, >, ~, ~>) and version
  8664. * components from `range`.
  8665. *
  8666. * For example, given `range` ">= 1.2.3" returns an object with a `modifier` of
  8667. * `">="` and `components` of `[1, 2, 3]`.
  8668. *
  8669. * @param {string} range
  8670. * @returns {object}
  8671. */
  8672. function getModifierAndComponents(range) {
  8673. var rangeComponents = range.split(componentRegex);
  8674. var matches = rangeComponents[0].match(modifierRegex);
  8675. !matches ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'expected regex to match but it did not') : invariant_1(false) : void 0;
  8676. return {
  8677. modifier: matches[1],
  8678. rangeComponents: [matches[2]].concat(rangeComponents.slice(1))
  8679. };
  8680. }
  8681. /**
  8682. * Determines if `number` is a number.
  8683. *
  8684. * @param {mixed} number
  8685. * @returns {boolean}
  8686. */
  8687. function isNumber(number) {
  8688. return !isNaN(number) && isFinite(number);
  8689. }
  8690. /**
  8691. * Tests whether `range` is a "simple" version number without any modifiers
  8692. * (">", "~" etc).
  8693. *
  8694. * @param {string} range
  8695. * @returns {boolean}
  8696. */
  8697. function isSimpleVersion(range) {
  8698. return !getModifierAndComponents(range).modifier;
  8699. }
  8700. /**
  8701. * Zero-pads array `array` until it is at least `length` long.
  8702. *
  8703. * @param {array} array
  8704. * @param {number} length
  8705. */
  8706. function zeroPad(array, length) {
  8707. for (var i = array.length; i < length; i++) {
  8708. array[i] = '0';
  8709. }
  8710. }
  8711. /**
  8712. * Normalizes `a` and `b` in preparation for comparison by doing the following:
  8713. *
  8714. * - zero-pads `a` and `b`
  8715. * - marks any "x", "X" or "*" component in `b` as equivalent by zero-ing it out
  8716. * in both `a` and `b`
  8717. * - marks any final "*" component in `b` as a greedy wildcard by zero-ing it
  8718. * and all of its successors in `a`
  8719. *
  8720. * @param {array<string>} a
  8721. * @param {array<string>} b
  8722. * @returns {array<array<string>>}
  8723. */
  8724. function normalizeVersions(a, b) {
  8725. a = a.slice();
  8726. b = b.slice();
  8727. zeroPad(a, b.length);
  8728. // mark "x" and "*" components as equal
  8729. for (var i = 0; i < b.length; i++) {
  8730. var matches = b[i].match(/^[x*]$/i);
  8731. if (matches) {
  8732. b[i] = a[i] = '0';
  8733. // final "*" greedily zeros all remaining components
  8734. if (matches[0] === '*' && i === b.length - 1) {
  8735. for (var j = i; j < a.length; j++) {
  8736. a[j] = '0';
  8737. }
  8738. }
  8739. }
  8740. }
  8741. zeroPad(b, a.length);
  8742. return [a, b];
  8743. }
  8744. /**
  8745. * Returns the numerical -- not the lexicographical -- ordering of `a` and `b`.
  8746. *
  8747. * For example, `10-alpha` is greater than `2-beta`.
  8748. *
  8749. * @param {string} a
  8750. * @param {string} b
  8751. * @returns {number} -1, 0 or 1 to indicate whether `a` is less than, equal to,
  8752. * or greater than `b`, respectively
  8753. */
  8754. function compareNumeric(a, b) {
  8755. var aPrefix = a.match(numericRegex)[1];
  8756. var bPrefix = b.match(numericRegex)[1];
  8757. var aNumeric = parseInt(aPrefix, 10);
  8758. var bNumeric = parseInt(bPrefix, 10);
  8759. if (isNumber(aNumeric) && isNumber(bNumeric) && aNumeric !== bNumeric) {
  8760. return compare(aNumeric, bNumeric);
  8761. } else {
  8762. return compare(a, b);
  8763. }
  8764. }
  8765. /**
  8766. * Returns the ordering of `a` and `b`.
  8767. *
  8768. * @param {string|number} a
  8769. * @param {string|number} b
  8770. * @returns {number} -1, 0 or 1 to indicate whether `a` is less than, equal to,
  8771. * or greater than `b`, respectively
  8772. */
  8773. function compare(a, b) {
  8774. !(typeof a === typeof b) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, '"a" and "b" must be of the same type') : invariant_1(false) : void 0;
  8775. if (a > b) {
  8776. return 1;
  8777. } else if (a < b) {
  8778. return -1;
  8779. } else {
  8780. return 0;
  8781. }
  8782. }
  8783. /**
  8784. * Compares arrays of version components.
  8785. *
  8786. * @param {array<string>} a
  8787. * @param {array<string>} b
  8788. * @returns {number} -1, 0 or 1 to indicate whether `a` is less than, equal to,
  8789. * or greater than `b`, respectively
  8790. */
  8791. function compareComponents(a, b) {
  8792. var _normalizeVersions = normalizeVersions(a, b),
  8793. aNormalized = _normalizeVersions[0],
  8794. bNormalized = _normalizeVersions[1];
  8795. for (var i = 0; i < bNormalized.length; i++) {
  8796. var result = compareNumeric(aNormalized[i], bNormalized[i]);
  8797. if (result) {
  8798. return result;
  8799. }
  8800. }
  8801. return 0;
  8802. }
  8803. var VersionRange = {
  8804. /**
  8805. * Checks whether `version` satisfies the `range` specification.
  8806. *
  8807. * We support a subset of the expressions defined in
  8808. * https://www.npmjs.org/doc/misc/semver.html:
  8809. *
  8810. * version Must match version exactly
  8811. * =version Same as just version
  8812. * >version Must be greater than version
  8813. * >=version Must be greater than or equal to version
  8814. * <version Must be less than version
  8815. * <=version Must be less than or equal to version
  8816. * ~version Must be at least version, but less than the next significant
  8817. * revision above version:
  8818. * "~1.2.3" is equivalent to ">= 1.2.3 and < 1.3"
  8819. * ~>version Equivalent to ~version
  8820. * 1.2.x Must match "1.2.x", where "x" is a wildcard that matches
  8821. * anything
  8822. * 1.2.* Similar to "1.2.x", but "*" in the trailing position is a
  8823. * "greedy" wildcard, so will match any number of additional
  8824. * components:
  8825. * "1.2.*" will match "1.2.1", "1.2.1.1", "1.2.1.1.1" etc
  8826. * * Any version
  8827. * "" (Empty string) Same as *
  8828. * v1 - v2 Equivalent to ">= v1 and <= v2"
  8829. * r1 || r2 Passes if either r1 or r2 are satisfied
  8830. *
  8831. * @param {string} range
  8832. * @param {string} version
  8833. * @returns {boolean}
  8834. */
  8835. contains: function contains(range, version) {
  8836. return checkOrExpression(range.trim(), version.trim());
  8837. }
  8838. };
  8839. var VersionRange_1 = VersionRange;
  8840. /**
  8841. * Copyright (c) 2013-present, Facebook, Inc.
  8842. *
  8843. * This source code is licensed under the MIT license found in the
  8844. * LICENSE file in the root directory of this source tree.
  8845. *
  8846. */
  8847. var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
  8848. /**
  8849. * Executes the provided `callback` once for each enumerable own property in the
  8850. * object and constructs a new object from the results. The `callback` is
  8851. * invoked with three arguments:
  8852. *
  8853. * - the property value
  8854. * - the property name
  8855. * - the object being traversed
  8856. *
  8857. * Properties that are added after the call to `mapObject` will not be visited
  8858. * by `callback`. If the values of existing properties are changed, the value
  8859. * passed to `callback` will be the value at the time `mapObject` visits them.
  8860. * Properties that are deleted before being visited are not visited.
  8861. *
  8862. * @grep function objectMap()
  8863. * @grep function objMap()
  8864. *
  8865. * @param {?object} object
  8866. * @param {function} callback
  8867. * @param {*} context
  8868. * @return {?object}
  8869. */
  8870. function mapObject(object, callback, context) {
  8871. if (!object) {
  8872. return null;
  8873. }
  8874. var result = {};
  8875. for (var name in object) {
  8876. if (hasOwnProperty$1.call(object, name)) {
  8877. result[name] = callback.call(context, object[name], name, object);
  8878. }
  8879. }
  8880. return result;
  8881. }
  8882. var mapObject_1 = mapObject;
  8883. /**
  8884. * Copyright (c) 2013-present, Facebook, Inc.
  8885. *
  8886. * This source code is licensed under the MIT license found in the
  8887. * LICENSE file in the root directory of this source tree.
  8888. *
  8889. *
  8890. * @typechecks static-only
  8891. */
  8892. /**
  8893. * Memoizes the return value of a function that accepts one string argument.
  8894. */
  8895. function memoizeStringOnly(callback) {
  8896. var cache = {};
  8897. return function (string) {
  8898. if (!cache.hasOwnProperty(string)) {
  8899. cache[string] = callback.call(this, string);
  8900. }
  8901. return cache[string];
  8902. };
  8903. }
  8904. var memoizeStringOnly_1 = memoizeStringOnly;
  8905. /**
  8906. * Checks to see whether `name` and `version` satisfy `query`.
  8907. *
  8908. * @param {string} name Name of the browser, device, engine or platform
  8909. * @param {?string} version Version of the browser, engine or platform
  8910. * @param {string} query Query of form "Name [range expression]"
  8911. * @param {?function} normalizer Optional pre-processor for range expression
  8912. * @return {boolean}
  8913. */
  8914. function compare$1(name, version, query, normalizer) {
  8915. // check for exact match with no version
  8916. if (name === query) {
  8917. return true;
  8918. }
  8919. // check for non-matching names
  8920. if (!query.startsWith(name)) {
  8921. return false;
  8922. }
  8923. // full comparison with version
  8924. var range = query.slice(name.length);
  8925. if (version) {
  8926. range = normalizer ? normalizer(range) : range;
  8927. return VersionRange_1.contains(range, version);
  8928. }
  8929. return false;
  8930. }
  8931. /**
  8932. * Normalizes `version` by stripping any "NT" prefix, but only on the Windows
  8933. * platform.
  8934. *
  8935. * Mimics the stripping performed by the `UserAgentWindowsPlatform` PHP class.
  8936. *
  8937. * @param {string} version
  8938. * @return {string}
  8939. */
  8940. function normalizePlatformVersion(version) {
  8941. if (UserAgentData.platformName === 'Windows') {
  8942. return version.replace(/^\s*NT/, '');
  8943. }
  8944. return version;
  8945. }
  8946. /**
  8947. * Provides client-side access to the authoritative PHP-generated User Agent
  8948. * information supplied by the server.
  8949. */
  8950. var UserAgent = {
  8951. /**
  8952. * Check if the User Agent browser matches `query`.
  8953. *
  8954. * `query` should be a string like "Chrome" or "Chrome > 33".
  8955. *
  8956. * Valid browser names include:
  8957. *
  8958. * - ACCESS NetFront
  8959. * - AOL
  8960. * - Amazon Silk
  8961. * - Android
  8962. * - BlackBerry
  8963. * - BlackBerry PlayBook
  8964. * - Chrome
  8965. * - Chrome for iOS
  8966. * - Chrome frame
  8967. * - Facebook PHP SDK
  8968. * - Facebook for iOS
  8969. * - Firefox
  8970. * - IE
  8971. * - IE Mobile
  8972. * - Mobile Safari
  8973. * - Motorola Internet Browser
  8974. * - Nokia
  8975. * - Openwave Mobile Browser
  8976. * - Opera
  8977. * - Opera Mini
  8978. * - Opera Mobile
  8979. * - Safari
  8980. * - UIWebView
  8981. * - Unknown
  8982. * - webOS
  8983. * - etc...
  8984. *
  8985. * An authoritative list can be found in the PHP `BrowserDetector` class and
  8986. * related classes in the same file (see calls to `new UserAgentBrowser` here:
  8987. * https://fburl.com/50728104).
  8988. *
  8989. * @note Function results are memoized
  8990. *
  8991. * @param {string} query Query of the form "Name [range expression]"
  8992. * @return {boolean}
  8993. */
  8994. isBrowser: function isBrowser(query) {
  8995. return compare$1(UserAgentData.browserName, UserAgentData.browserFullVersion, query);
  8996. },
  8997. /**
  8998. * Check if the User Agent browser uses a 32 or 64 bit architecture.
  8999. *
  9000. * @note Function results are memoized
  9001. *
  9002. * @param {string} query Query of the form "32" or "64".
  9003. * @return {boolean}
  9004. */
  9005. isBrowserArchitecture: function isBrowserArchitecture(query) {
  9006. return compare$1(UserAgentData.browserArchitecture, null, query);
  9007. },
  9008. /**
  9009. * Check if the User Agent device matches `query`.
  9010. *
  9011. * `query` should be a string like "iPhone" or "iPad".
  9012. *
  9013. * Valid device names include:
  9014. *
  9015. * - Kindle
  9016. * - Kindle Fire
  9017. * - Unknown
  9018. * - iPad
  9019. * - iPhone
  9020. * - iPod
  9021. * - etc...
  9022. *
  9023. * An authoritative list can be found in the PHP `DeviceDetector` class and
  9024. * related classes in the same file (see calls to `new UserAgentDevice` here:
  9025. * https://fburl.com/50728332).
  9026. *
  9027. * @note Function results are memoized
  9028. *
  9029. * @param {string} query Query of the form "Name"
  9030. * @return {boolean}
  9031. */
  9032. isDevice: function isDevice(query) {
  9033. return compare$1(UserAgentData.deviceName, null, query);
  9034. },
  9035. /**
  9036. * Check if the User Agent rendering engine matches `query`.
  9037. *
  9038. * `query` should be a string like "WebKit" or "WebKit >= 537".
  9039. *
  9040. * Valid engine names include:
  9041. *
  9042. * - Gecko
  9043. * - Presto
  9044. * - Trident
  9045. * - WebKit
  9046. * - etc...
  9047. *
  9048. * An authoritative list can be found in the PHP `RenderingEngineDetector`
  9049. * class related classes in the same file (see calls to `new
  9050. * UserAgentRenderingEngine` here: https://fburl.com/50728617).
  9051. *
  9052. * @note Function results are memoized
  9053. *
  9054. * @param {string} query Query of the form "Name [range expression]"
  9055. * @return {boolean}
  9056. */
  9057. isEngine: function isEngine(query) {
  9058. return compare$1(UserAgentData.engineName, UserAgentData.engineVersion, query);
  9059. },
  9060. /**
  9061. * Check if the User Agent platform matches `query`.
  9062. *
  9063. * `query` should be a string like "Windows" or "iOS 5 - 6".
  9064. *
  9065. * Valid platform names include:
  9066. *
  9067. * - Android
  9068. * - BlackBerry OS
  9069. * - Java ME
  9070. * - Linux
  9071. * - Mac OS X
  9072. * - Mac OS X Calendar
  9073. * - Mac OS X Internet Account
  9074. * - Symbian
  9075. * - SymbianOS
  9076. * - Windows
  9077. * - Windows Mobile
  9078. * - Windows Phone
  9079. * - iOS
  9080. * - iOS Facebook Integration Account
  9081. * - iOS Facebook Social Sharing UI
  9082. * - webOS
  9083. * - Chrome OS
  9084. * - etc...
  9085. *
  9086. * An authoritative list can be found in the PHP `PlatformDetector` class and
  9087. * related classes in the same file (see calls to `new UserAgentPlatform`
  9088. * here: https://fburl.com/50729226).
  9089. *
  9090. * @note Function results are memoized
  9091. *
  9092. * @param {string} query Query of the form "Name [range expression]"
  9093. * @return {boolean}
  9094. */
  9095. isPlatform: function isPlatform(query) {
  9096. return compare$1(UserAgentData.platformName, UserAgentData.platformFullVersion, query, normalizePlatformVersion);
  9097. },
  9098. /**
  9099. * Check if the User Agent platform is a 32 or 64 bit architecture.
  9100. *
  9101. * @note Function results are memoized
  9102. *
  9103. * @param {string} query Query of the form "32" or "64".
  9104. * @return {boolean}
  9105. */
  9106. isPlatformArchitecture: function isPlatformArchitecture(query) {
  9107. return compare$1(UserAgentData.platformArchitecture, null, query);
  9108. }
  9109. };
  9110. var UserAgent_1 = mapObject_1(UserAgent, memoizeStringOnly_1);
  9111. function _classCallCheck$9(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9112. function _possibleConstructorReturn$6(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  9113. function _inherits$6(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  9114. // In IE, spans with <br> tags render as two newlines. By rendering a span
  9115. // with only a newline character, we can be sure to render a single line.
  9116. var useNewlineChar = UserAgent_1.isBrowser('IE <= 11');
  9117. /**
  9118. * Check whether the node should be considered a newline.
  9119. */
  9120. function isNewline(node) {
  9121. return useNewlineChar ? node.textContent === '\n' : node.tagName === 'BR';
  9122. }
  9123. /**
  9124. * Placeholder elements for empty text content.
  9125. *
  9126. * What is this `data-text` attribute, anyway? It turns out that we need to
  9127. * put an attribute on the lowest-level text node in order to preserve correct
  9128. * spellcheck handling. If the <span> is naked, Chrome and Safari may do
  9129. * bizarre things to do the DOM -- split text nodes, create extra spans, etc.
  9130. * If the <span> has an attribute, this appears not to happen.
  9131. * See http://jsfiddle.net/9khdavod/ for the failure case, and
  9132. * http://jsfiddle.net/7pg143f7/ for the fixed case.
  9133. */
  9134. var NEWLINE_A = useNewlineChar ? React__default.createElement(
  9135. 'span',
  9136. { key: 'A', 'data-text': 'true' },
  9137. '\n'
  9138. ) : React__default.createElement('br', { key: 'A', 'data-text': 'true' });
  9139. var NEWLINE_B = useNewlineChar ? React__default.createElement(
  9140. 'span',
  9141. { key: 'B', 'data-text': 'true' },
  9142. '\n'
  9143. ) : React__default.createElement('br', { key: 'B', 'data-text': 'true' });
  9144. /**
  9145. * The lowest-level component in a `DraftEditor`, the text node component
  9146. * replaces the default React text node implementation. This allows us to
  9147. * perform custom handling of newline behavior and avoid re-rendering text
  9148. * nodes with DOM state that already matches the expectations of our immutable
  9149. * editor state.
  9150. */
  9151. var DraftEditorTextNode = function (_React$Component) {
  9152. _inherits$6(DraftEditorTextNode, _React$Component);
  9153. function DraftEditorTextNode(props) {
  9154. _classCallCheck$9(this, DraftEditorTextNode);
  9155. // By flipping this flag, we also keep flipping keys which forces
  9156. // React to remount this node every time it rerenders.
  9157. var _this = _possibleConstructorReturn$6(this, _React$Component.call(this, props));
  9158. _this._forceFlag = false;
  9159. return _this;
  9160. }
  9161. DraftEditorTextNode.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
  9162. var node = reactDom__default.findDOMNode(this);
  9163. var shouldBeNewline = nextProps.children === '';
  9164. !(node instanceof Element) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'node is not an Element') : invariant_1(false) : void 0;
  9165. if (shouldBeNewline) {
  9166. return !isNewline(node);
  9167. }
  9168. return node.textContent !== nextProps.children;
  9169. };
  9170. DraftEditorTextNode.prototype.componentDidMount = function componentDidMount() {
  9171. this._forceFlag = !this._forceFlag;
  9172. };
  9173. DraftEditorTextNode.prototype.componentDidUpdate = function componentDidUpdate() {
  9174. this._forceFlag = !this._forceFlag;
  9175. };
  9176. DraftEditorTextNode.prototype.render = function render() {
  9177. if (this.props.children === '') {
  9178. return this._forceFlag ? NEWLINE_A : NEWLINE_B;
  9179. }
  9180. return React__default.createElement(
  9181. 'span',
  9182. { key: this._forceFlag ? 'A' : 'B', 'data-text': 'true' },
  9183. this.props.children
  9184. );
  9185. };
  9186. return DraftEditorTextNode;
  9187. }(React__default.Component);
  9188. var DraftEditorTextNode_react = DraftEditorTextNode;
  9189. /**
  9190. * Copyright (c) 2013-present, Facebook, Inc.
  9191. * All rights reserved.
  9192. *
  9193. * This source code is licensed under the BSD-style license found in the
  9194. * LICENSE file in the root directory of this source tree. An additional grant
  9195. * of patent rights can be found in the PATENTS file in the same directory.
  9196. *
  9197. * @providesModule DraftJsDebugLogging
  9198. */
  9199. var DraftJsDebugLogging = {
  9200. logSelectionStateFailure: function logSelectionStateFailure() {
  9201. return null;
  9202. }
  9203. };
  9204. /**
  9205. * Copyright (c) 2013-present, Facebook, Inc.
  9206. *
  9207. * This source code is licensed under the MIT license found in the
  9208. * LICENSE file in the root directory of this source tree.
  9209. *
  9210. * @typechecks
  9211. */
  9212. /**
  9213. * @param {*} object The object to check.
  9214. * @return {boolean} Whether or not the object is a DOM node.
  9215. */
  9216. function isNode(object) {
  9217. var doc = object ? object.ownerDocument || object : document;
  9218. var defaultView = doc.defaultView || window;
  9219. return !!(object && (typeof defaultView.Node === 'function' ? object instanceof defaultView.Node : typeof object === 'object' && typeof object.nodeType === 'number' && typeof object.nodeName === 'string'));
  9220. }
  9221. var isNode_1 = isNode;
  9222. /**
  9223. * Copyright (c) 2013-present, Facebook, Inc.
  9224. *
  9225. * This source code is licensed under the MIT license found in the
  9226. * LICENSE file in the root directory of this source tree.
  9227. *
  9228. * @typechecks
  9229. */
  9230. /**
  9231. * @param {*} object The object to check.
  9232. * @return {boolean} Whether or not the object is a DOM text node.
  9233. */
  9234. function isTextNode(object) {
  9235. return isNode_1(object) && object.nodeType == 3;
  9236. }
  9237. var isTextNode_1 = isTextNode;
  9238. /**
  9239. * Copyright (c) 2013-present, Facebook, Inc.
  9240. *
  9241. * This source code is licensed under the MIT license found in the
  9242. * LICENSE file in the root directory of this source tree.
  9243. *
  9244. *
  9245. */
  9246. /*eslint-disable no-bitwise */
  9247. /**
  9248. * Checks if a given DOM node contains or is another DOM node.
  9249. */
  9250. function containsNode(outerNode, innerNode) {
  9251. if (!outerNode || !innerNode) {
  9252. return false;
  9253. } else if (outerNode === innerNode) {
  9254. return true;
  9255. } else if (isTextNode_1(outerNode)) {
  9256. return false;
  9257. } else if (isTextNode_1(innerNode)) {
  9258. return containsNode(outerNode, innerNode.parentNode);
  9259. } else if ('contains' in outerNode) {
  9260. return outerNode.contains(innerNode);
  9261. } else if (outerNode.compareDocumentPosition) {
  9262. return !!(outerNode.compareDocumentPosition(innerNode) & 16);
  9263. } else {
  9264. return false;
  9265. }
  9266. }
  9267. var containsNode_1 = containsNode;
  9268. /**
  9269. * Copyright (c) 2013-present, Facebook, Inc.
  9270. *
  9271. * This source code is licensed under the MIT license found in the
  9272. * LICENSE file in the root directory of this source tree.
  9273. *
  9274. * @typechecks
  9275. */
  9276. /* eslint-disable fb-www/typeof-undefined */
  9277. /**
  9278. * Same as document.activeElement but wraps in a try-catch block. In IE it is
  9279. * not safe to call document.activeElement if there is nothing focused.
  9280. *
  9281. * The activeElement will be null only if the document or document body is not
  9282. * yet defined.
  9283. *
  9284. * @param {?DOMDocument} doc Defaults to current document.
  9285. * @return {?DOMElement}
  9286. */
  9287. function getActiveElement(doc) /*?DOMElement*/{
  9288. doc = doc || (typeof document !== 'undefined' ? document : undefined);
  9289. if (typeof doc === 'undefined') {
  9290. return null;
  9291. }
  9292. try {
  9293. return doc.activeElement || doc.body;
  9294. } catch (e) {
  9295. return doc.body;
  9296. }
  9297. }
  9298. var getActiveElement_1 = getActiveElement;
  9299. function getAnonymizedDOM(node, getNodeLabels) {
  9300. if (!node) {
  9301. return '[empty]';
  9302. }
  9303. var anonymized = anonymizeTextWithin(node, getNodeLabels);
  9304. if (anonymized.nodeType === Node.TEXT_NODE) {
  9305. return anonymized.textContent;
  9306. }
  9307. !(anonymized instanceof Element) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Node must be an Element if it is not a text node.') : invariant_1(false) : void 0;
  9308. return anonymized.outerHTML;
  9309. }
  9310. function anonymizeTextWithin(node, getNodeLabels) {
  9311. var labels = getNodeLabels !== undefined ? getNodeLabels(node) : [];
  9312. if (node.nodeType === Node.TEXT_NODE) {
  9313. var length = node.textContent.length;
  9314. return document.createTextNode('[text ' + length + (labels.length ? ' | ' + labels.join(', ') : '') + ']');
  9315. }
  9316. var clone = node.cloneNode();
  9317. if (clone.nodeType === 1 && labels.length) {
  9318. clone.setAttribute('data-labels', labels.join(', '));
  9319. }
  9320. var childNodes = node.childNodes;
  9321. for (var ii = 0; ii < childNodes.length; ii++) {
  9322. clone.appendChild(anonymizeTextWithin(childNodes[ii], getNodeLabels));
  9323. }
  9324. return clone;
  9325. }
  9326. function getAnonymizedEditorDOM(node, getNodeLabels) {
  9327. // grabbing the DOM content of the Draft editor
  9328. var currentNode = node;
  9329. while (currentNode) {
  9330. if (currentNode instanceof Element && currentNode.hasAttribute('contenteditable')) {
  9331. // found the Draft editor container
  9332. return getAnonymizedDOM(currentNode, getNodeLabels);
  9333. } else {
  9334. currentNode = currentNode.parentNode;
  9335. }
  9336. }
  9337. return 'Could not find contentEditable parent of node';
  9338. }
  9339. function getNodeLength(node) {
  9340. return node.nodeValue === null ? node.childNodes.length : node.nodeValue.length;
  9341. }
  9342. /**
  9343. * In modern non-IE browsers, we can support both forward and backward
  9344. * selections.
  9345. *
  9346. * Note: IE10+ supports the Selection object, but it does not support
  9347. * the `extend` method, which means that even in modern IE, it's not possible
  9348. * to programatically create a backward selection. Thus, for all IE
  9349. * versions, we use the old IE API to create our selections.
  9350. */
  9351. function setDraftEditorSelection(selectionState, node, blockKey, nodeStart, nodeEnd) {
  9352. // It's possible that the editor has been removed from the DOM but
  9353. // our selection code doesn't know it yet. Forcing selection in
  9354. // this case may lead to errors, so just bail now.
  9355. if (!containsNode_1(document.documentElement, node)) {
  9356. return;
  9357. }
  9358. var selection = _commonjsHelpers.commonjsGlobal.getSelection();
  9359. var anchorKey = selectionState.getAnchorKey();
  9360. var anchorOffset = selectionState.getAnchorOffset();
  9361. var focusKey = selectionState.getFocusKey();
  9362. var focusOffset = selectionState.getFocusOffset();
  9363. var isBackward = selectionState.getIsBackward();
  9364. // IE doesn't support backward selection. Swap key/offset pairs.
  9365. if (!selection.extend && isBackward) {
  9366. var tempKey = anchorKey;
  9367. var tempOffset = anchorOffset;
  9368. anchorKey = focusKey;
  9369. anchorOffset = focusOffset;
  9370. focusKey = tempKey;
  9371. focusOffset = tempOffset;
  9372. isBackward = false;
  9373. }
  9374. var hasAnchor = anchorKey === blockKey && nodeStart <= anchorOffset && nodeEnd >= anchorOffset;
  9375. var hasFocus = focusKey === blockKey && nodeStart <= focusOffset && nodeEnd >= focusOffset;
  9376. // If the selection is entirely bound within this node, set the selection
  9377. // and be done.
  9378. if (hasAnchor && hasFocus) {
  9379. selection.removeAllRanges();
  9380. addPointToSelection(selection, node, anchorOffset - nodeStart, selectionState);
  9381. addFocusToSelection(selection, node, focusOffset - nodeStart, selectionState);
  9382. return;
  9383. }
  9384. if (!isBackward) {
  9385. // If the anchor is within this node, set the range start.
  9386. if (hasAnchor) {
  9387. selection.removeAllRanges();
  9388. addPointToSelection(selection, node, anchorOffset - nodeStart, selectionState);
  9389. }
  9390. // If the focus is within this node, we can assume that we have
  9391. // already set the appropriate start range on the selection, and
  9392. // can simply extend the selection.
  9393. if (hasFocus) {
  9394. addFocusToSelection(selection, node, focusOffset - nodeStart, selectionState);
  9395. }
  9396. } else {
  9397. // If this node has the focus, set the selection range to be a
  9398. // collapsed range beginning here. Later, when we encounter the anchor,
  9399. // we'll use this information to extend the selection.
  9400. if (hasFocus) {
  9401. selection.removeAllRanges();
  9402. addPointToSelection(selection, node, focusOffset - nodeStart, selectionState);
  9403. }
  9404. // If this node has the anchor, we may assume that the correct
  9405. // focus information is already stored on the selection object.
  9406. // We keep track of it, reset the selection range, and extend it
  9407. // back to the focus point.
  9408. if (hasAnchor) {
  9409. var storedFocusNode = selection.focusNode;
  9410. var storedFocusOffset = selection.focusOffset;
  9411. selection.removeAllRanges();
  9412. addPointToSelection(selection, node, anchorOffset - nodeStart, selectionState);
  9413. addFocusToSelection(selection, storedFocusNode, storedFocusOffset, selectionState);
  9414. }
  9415. }
  9416. }
  9417. /**
  9418. * Extend selection towards focus point.
  9419. */
  9420. function addFocusToSelection(selection, node, offset, selectionState) {
  9421. var activeElement = getActiveElement_1();
  9422. if (selection.extend && containsNode_1(activeElement, node)) {
  9423. // If `extend` is called while another element has focus, an error is
  9424. // thrown. We therefore disable `extend` if the active element is somewhere
  9425. // other than the node we are selecting. This should only occur in Firefox,
  9426. // since it is the only browser to support multiple selections.
  9427. // See https://bugzilla.mozilla.org/show_bug.cgi?id=921444.
  9428. // logging to catch bug that is being reported in t16250795
  9429. if (offset > getNodeLength(node)) {
  9430. // the call to 'selection.extend' is about to throw
  9431. DraftJsDebugLogging.logSelectionStateFailure({
  9432. anonymizedDom: getAnonymizedEditorDOM(node),
  9433. extraParams: JSON.stringify({ offset: offset }),
  9434. selectionState: JSON.stringify(selectionState.toJS())
  9435. });
  9436. }
  9437. // logging to catch bug that is being reported in t18110632
  9438. var nodeWasFocus = node === selection.focusNode;
  9439. try {
  9440. selection.extend(node, offset);
  9441. } catch (e) {
  9442. DraftJsDebugLogging.logSelectionStateFailure({
  9443. anonymizedDom: getAnonymizedEditorDOM(node, function (n) {
  9444. var labels = [];
  9445. if (n === activeElement) {
  9446. labels.push('active element');
  9447. }
  9448. if (n === selection.anchorNode) {
  9449. labels.push('selection anchor node');
  9450. }
  9451. if (n === selection.focusNode) {
  9452. labels.push('selection focus node');
  9453. }
  9454. return labels;
  9455. }),
  9456. extraParams: JSON.stringify({
  9457. activeElementName: activeElement ? activeElement.nodeName : null,
  9458. nodeIsFocus: node === selection.focusNode,
  9459. nodeWasFocus: nodeWasFocus,
  9460. selectionRangeCount: selection.rangeCount,
  9461. selectionAnchorNodeName: selection.anchorNode ? selection.anchorNode.nodeName : null,
  9462. selectionAnchorOffset: selection.anchorOffset,
  9463. selectionFocusNodeName: selection.focusNode ? selection.focusNode.nodeName : null,
  9464. selectionFocusOffset: selection.focusOffset,
  9465. message: e ? '' + e : null,
  9466. offset: offset
  9467. }, null, 2),
  9468. selectionState: JSON.stringify(selectionState.toJS(), null, 2)
  9469. });
  9470. // allow the error to be thrown -
  9471. // better than continuing in a broken state
  9472. throw e;
  9473. }
  9474. } else {
  9475. // IE doesn't support extend. This will mean no backward selection.
  9476. // Extract the existing selection range and add focus to it.
  9477. // Additionally, clone the selection range. IE11 throws an
  9478. // InvalidStateError when attempting to access selection properties
  9479. // after the range is detached.
  9480. var range = selection.getRangeAt(0);
  9481. range.setEnd(node, offset);
  9482. selection.addRange(range.cloneRange());
  9483. }
  9484. }
  9485. function addPointToSelection(selection, node, offset, selectionState) {
  9486. var range = document.createRange();
  9487. // logging to catch bug that is being reported in t16250795
  9488. if (offset > getNodeLength(node)) {
  9489. // in this case we know that the call to 'range.setStart' is about to throw
  9490. DraftJsDebugLogging.logSelectionStateFailure({
  9491. anonymizedDom: getAnonymizedEditorDOM(node),
  9492. extraParams: JSON.stringify({ offset: offset }),
  9493. selectionState: JSON.stringify(selectionState.toJS())
  9494. });
  9495. }
  9496. range.setStart(node, offset);
  9497. selection.addRange(range);
  9498. }
  9499. var setDraftEditorSelection_1 = setDraftEditorSelection;
  9500. function _classCallCheck$a(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9501. function _possibleConstructorReturn$7(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  9502. function _inherits$7(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  9503. /**
  9504. * All leaf nodes in the editor are spans with single text nodes. Leaf
  9505. * elements are styled based on the merging of an optional custom style map
  9506. * and a default style map.
  9507. *
  9508. * `DraftEditorLeaf` also provides a wrapper for calling into the imperative
  9509. * DOM Selection API. In this way, top-level components can declaratively
  9510. * maintain the selection state.
  9511. */
  9512. var DraftEditorLeaf = function (_React$Component) {
  9513. _inherits$7(DraftEditorLeaf, _React$Component);
  9514. function DraftEditorLeaf() {
  9515. _classCallCheck$a(this, DraftEditorLeaf);
  9516. return _possibleConstructorReturn$7(this, _React$Component.apply(this, arguments));
  9517. }
  9518. DraftEditorLeaf.prototype._setSelection = function _setSelection() {
  9519. var selection = this.props.selection;
  9520. // If selection state is irrelevant to the parent block, no-op.
  9521. if (selection == null || !selection.getHasFocus()) {
  9522. return;
  9523. }
  9524. var _props = this.props,
  9525. block = _props.block,
  9526. start = _props.start,
  9527. text = _props.text;
  9528. var blockKey = block.getKey();
  9529. var end = start + text.length;
  9530. if (!selection.hasEdgeWithin(blockKey, start, end)) {
  9531. return;
  9532. }
  9533. // Determine the appropriate target node for selection. If the child
  9534. // is not a text node, it is a <br /> spacer. In this case, use the
  9535. // <span> itself as the selection target.
  9536. var node = reactDom__default.findDOMNode(this);
  9537. !node ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing node') : invariant_1(false) : void 0;
  9538. var child = node.firstChild;
  9539. !child ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing child') : invariant_1(false) : void 0;
  9540. var targetNode = void 0;
  9541. if (child.nodeType === Node.TEXT_NODE) {
  9542. targetNode = child;
  9543. } else if (child.tagName === 'BR') {
  9544. targetNode = node;
  9545. } else {
  9546. targetNode = child.firstChild;
  9547. !targetNode ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing targetNode') : invariant_1(false) : void 0;
  9548. }
  9549. setDraftEditorSelection_1(selection, targetNode, blockKey, start, end);
  9550. };
  9551. /**
  9552. * By making individual leaf instances aware of their context within
  9553. * the text of the editor, we can set our selection range more
  9554. * easily than we could in the non-React world.
  9555. *
  9556. * Note that this depends on our maintaining tight control over the
  9557. * DOM structure of the DraftEditor component. If leaves had multiple
  9558. * text nodes, this would be harder.
  9559. */
  9560. DraftEditorLeaf.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
  9561. var leafNode = reactDom__default.findDOMNode(this.leaf);
  9562. !leafNode ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing leafNode') : invariant_1(false) : void 0;
  9563. return leafNode.textContent !== nextProps.text || nextProps.styleSet !== this.props.styleSet || nextProps.forceSelection;
  9564. };
  9565. DraftEditorLeaf.prototype.componentDidUpdate = function componentDidUpdate() {
  9566. this._setSelection();
  9567. };
  9568. DraftEditorLeaf.prototype.componentDidMount = function componentDidMount() {
  9569. this._setSelection();
  9570. };
  9571. DraftEditorLeaf.prototype.render = function render() {
  9572. var _this2 = this;
  9573. var block = this.props.block;
  9574. var text = this.props.text;
  9575. // If the leaf is at the end of its block and ends in a soft newline, append
  9576. // an extra line feed character. Browsers collapse trailing newline
  9577. // characters, which leaves the cursor in the wrong place after a
  9578. // shift+enter. The extra character repairs this.
  9579. if (text.endsWith('\n') && this.props.isLast) {
  9580. text += '\n';
  9581. }
  9582. var _props2 = this.props,
  9583. customStyleMap = _props2.customStyleMap,
  9584. customStyleFn = _props2.customStyleFn,
  9585. offsetKey = _props2.offsetKey,
  9586. styleSet = _props2.styleSet;
  9587. var styleObj = styleSet.reduce(function (map, styleName) {
  9588. var mergedStyles = {};
  9589. var style = customStyleMap[styleName];
  9590. if (style !== undefined && map.textDecoration !== style.textDecoration) {
  9591. // .trim() is necessary for IE9/10/11 and Edge
  9592. mergedStyles.textDecoration = [map.textDecoration, style.textDecoration].join(' ').trim();
  9593. }
  9594. return objectAssign(map, style, mergedStyles);
  9595. }, {});
  9596. if (customStyleFn) {
  9597. var newStyles = customStyleFn(styleSet, block);
  9598. styleObj = objectAssign(styleObj, newStyles);
  9599. }
  9600. return React__default.createElement(
  9601. 'span',
  9602. {
  9603. 'data-offset-key': offsetKey,
  9604. ref: function ref(_ref) {
  9605. return _this2.leaf = _ref;
  9606. },
  9607. style: styleObj },
  9608. React__default.createElement(
  9609. DraftEditorTextNode_react,
  9610. null,
  9611. text
  9612. )
  9613. );
  9614. };
  9615. return DraftEditorLeaf;
  9616. }(React__default.Component);
  9617. var DraftEditorLeaf_react = DraftEditorLeaf;
  9618. /**
  9619. * Copyright (c) 2013-present, Facebook, Inc.
  9620. * All rights reserved.
  9621. *
  9622. * This source code is licensed under the BSD-style license found in the
  9623. * LICENSE file in the root directory of this source tree. An additional grant
  9624. * of patent rights can be found in the PATENTS file in the same directory.
  9625. *
  9626. * @providesModule DraftOffsetKey
  9627. * @format
  9628. *
  9629. */
  9630. var KEY_DELIMITER = '-';
  9631. var DraftOffsetKey = {
  9632. encode: function encode(blockKey, decoratorKey, leafKey) {
  9633. return blockKey + KEY_DELIMITER + decoratorKey + KEY_DELIMITER + leafKey;
  9634. },
  9635. decode: function decode(offsetKey) {
  9636. var _offsetKey$split = offsetKey.split(KEY_DELIMITER),
  9637. blockKey = _offsetKey$split[0],
  9638. decoratorKey = _offsetKey$split[1],
  9639. leafKey = _offsetKey$split[2];
  9640. return {
  9641. blockKey: blockKey,
  9642. decoratorKey: parseInt(decoratorKey, 10),
  9643. leafKey: parseInt(leafKey, 10)
  9644. };
  9645. }
  9646. };
  9647. var DraftOffsetKey_1 = DraftOffsetKey;
  9648. /**
  9649. * Copyright (c) 2013-present, Facebook, Inc.
  9650. *
  9651. * This source code is licensed under the MIT license found in the
  9652. * LICENSE file in the root directory of this source tree.
  9653. *
  9654. */
  9655. /**
  9656. * @param {DOMElement} element
  9657. * @param {DOMDocument} doc
  9658. * @return {boolean}
  9659. */
  9660. function _isViewportScrollElement(element, doc) {
  9661. return !!doc && (element === doc.documentElement || element === doc.body);
  9662. }
  9663. /**
  9664. * Scroll Module. This class contains 4 simple static functions
  9665. * to be used to access Element.scrollTop/scrollLeft properties.
  9666. * To solve the inconsistencies between browsers when either
  9667. * document.body or document.documentElement is supplied,
  9668. * below logic will be used to alleviate the issue:
  9669. *
  9670. * 1. If 'element' is either 'document.body' or 'document.documentElement,
  9671. * get whichever element's 'scroll{Top,Left}' is larger.
  9672. * 2. If 'element' is either 'document.body' or 'document.documentElement',
  9673. * set the 'scroll{Top,Left}' on both elements.
  9674. */
  9675. var Scroll = {
  9676. /**
  9677. * @param {DOMElement} element
  9678. * @return {number}
  9679. */
  9680. getTop: function getTop(element) {
  9681. var doc = element.ownerDocument;
  9682. return _isViewportScrollElement(element, doc) ?
  9683. // In practice, they will either both have the same value,
  9684. // or one will be zero and the other will be the scroll position
  9685. // of the viewport. So we can use `X || Y` instead of `Math.max(X, Y)`
  9686. doc.body.scrollTop || doc.documentElement.scrollTop : element.scrollTop;
  9687. },
  9688. /**
  9689. * @param {DOMElement} element
  9690. * @param {number} newTop
  9691. */
  9692. setTop: function setTop(element, newTop) {
  9693. var doc = element.ownerDocument;
  9694. if (_isViewportScrollElement(element, doc)) {
  9695. doc.body.scrollTop = doc.documentElement.scrollTop = newTop;
  9696. } else {
  9697. element.scrollTop = newTop;
  9698. }
  9699. },
  9700. /**
  9701. * @param {DOMElement} element
  9702. * @return {number}
  9703. */
  9704. getLeft: function getLeft(element) {
  9705. var doc = element.ownerDocument;
  9706. return _isViewportScrollElement(element, doc) ? doc.body.scrollLeft || doc.documentElement.scrollLeft : element.scrollLeft;
  9707. },
  9708. /**
  9709. * @param {DOMElement} element
  9710. * @param {number} newLeft
  9711. */
  9712. setLeft: function setLeft(element, newLeft) {
  9713. var doc = element.ownerDocument;
  9714. if (_isViewportScrollElement(element, doc)) {
  9715. doc.body.scrollLeft = doc.documentElement.scrollLeft = newLeft;
  9716. } else {
  9717. element.scrollLeft = newLeft;
  9718. }
  9719. }
  9720. };
  9721. var Scroll_1 = Scroll;
  9722. /**
  9723. * Copyright (c) 2013-present, Facebook, Inc.
  9724. *
  9725. * This source code is licensed under the MIT license found in the
  9726. * LICENSE file in the root directory of this source tree.
  9727. *
  9728. * @typechecks
  9729. */
  9730. var _hyphenPattern = /-(.)/g;
  9731. /**
  9732. * Camelcases a hyphenated string, for example:
  9733. *
  9734. * > camelize('background-color')
  9735. * < "backgroundColor"
  9736. *
  9737. * @param {string} string
  9738. * @return {string}
  9739. */
  9740. function camelize(string) {
  9741. return string.replace(_hyphenPattern, function (_, character) {
  9742. return character.toUpperCase();
  9743. });
  9744. }
  9745. var camelize_1 = camelize;
  9746. /**
  9747. * Copyright (c) 2013-present, Facebook, Inc.
  9748. *
  9749. * This source code is licensed under the MIT license found in the
  9750. * LICENSE file in the root directory of this source tree.
  9751. *
  9752. * @typechecks
  9753. */
  9754. var _uppercasePattern = /([A-Z])/g;
  9755. /**
  9756. * Hyphenates a camelcased string, for example:
  9757. *
  9758. * > hyphenate('backgroundColor')
  9759. * < "background-color"
  9760. *
  9761. * For CSS style names, use `hyphenateStyleName` instead which works properly
  9762. * with all vendor prefixes, including `ms`.
  9763. *
  9764. * @param {string} string
  9765. * @return {string}
  9766. */
  9767. function hyphenate(string) {
  9768. return string.replace(_uppercasePattern, '-$1').toLowerCase();
  9769. }
  9770. var hyphenate_1 = hyphenate;
  9771. /**
  9772. * Copyright (c) 2013-present, Facebook, Inc.
  9773. *
  9774. * This source code is licensed under the MIT license found in the
  9775. * LICENSE file in the root directory of this source tree.
  9776. *
  9777. * @typechecks
  9778. */
  9779. function asString(value) /*?string*/{
  9780. return value == null ? value : String(value);
  9781. }
  9782. function getStyleProperty( /*DOMNode*/node, /*string*/name) /*?string*/{
  9783. var computedStyle = void 0;
  9784. // W3C Standard
  9785. if (window.getComputedStyle) {
  9786. // In certain cases such as within an iframe in FF3, this returns null.
  9787. computedStyle = window.getComputedStyle(node, null);
  9788. if (computedStyle) {
  9789. return asString(computedStyle.getPropertyValue(hyphenate_1(name)));
  9790. }
  9791. }
  9792. // Safari
  9793. if (document.defaultView && document.defaultView.getComputedStyle) {
  9794. computedStyle = document.defaultView.getComputedStyle(node, null);
  9795. // A Safari bug causes this to return null for `display: none` elements.
  9796. if (computedStyle) {
  9797. return asString(computedStyle.getPropertyValue(hyphenate_1(name)));
  9798. }
  9799. if (name === 'display') {
  9800. return 'none';
  9801. }
  9802. }
  9803. // Internet Explorer
  9804. if (node.currentStyle) {
  9805. if (name === 'float') {
  9806. return asString(node.currentStyle.cssFloat || node.currentStyle.styleFloat);
  9807. }
  9808. return asString(node.currentStyle[camelize_1(name)]);
  9809. }
  9810. return asString(node.style && node.style[camelize_1(name)]);
  9811. }
  9812. var getStyleProperty_1 = getStyleProperty;
  9813. /**
  9814. * Copyright (c) 2013-present, Facebook, Inc.
  9815. *
  9816. * This source code is licensed under the MIT license found in the
  9817. * LICENSE file in the root directory of this source tree.
  9818. *
  9819. * @typechecks
  9820. */
  9821. /**
  9822. * @param {DOMNode} element [description]
  9823. * @param {string} name Overflow style property name.
  9824. * @return {boolean} True if the supplied ndoe is scrollable.
  9825. */
  9826. function _isNodeScrollable(element, name) {
  9827. var overflow = Style.get(element, name);
  9828. return overflow === 'auto' || overflow === 'scroll';
  9829. }
  9830. /**
  9831. * Utilities for querying and mutating style properties.
  9832. */
  9833. var Style = {
  9834. /**
  9835. * Gets the style property for the supplied node. This will return either the
  9836. * computed style, if available, or the declared style.
  9837. *
  9838. * @param {DOMNode} node
  9839. * @param {string} name Style property name.
  9840. * @return {?string} Style property value.
  9841. */
  9842. get: getStyleProperty_1,
  9843. /**
  9844. * Determines the nearest ancestor of a node that is scrollable.
  9845. *
  9846. * NOTE: This can be expensive if used repeatedly or on a node nested deeply.
  9847. *
  9848. * @param {?DOMNode} node Node from which to start searching.
  9849. * @return {?DOMWindow|DOMElement} Scroll parent of the supplied node.
  9850. */
  9851. getScrollParent: function getScrollParent(node) {
  9852. if (!node) {
  9853. return null;
  9854. }
  9855. var ownerDocument = node.ownerDocument;
  9856. while (node && node !== ownerDocument.body) {
  9857. if (_isNodeScrollable(node, 'overflow') || _isNodeScrollable(node, 'overflowY') || _isNodeScrollable(node, 'overflowX')) {
  9858. return node;
  9859. }
  9860. node = node.parentNode;
  9861. }
  9862. return ownerDocument.defaultView || ownerDocument.parentWindow;
  9863. }
  9864. };
  9865. var Style_1 = Style;
  9866. /**
  9867. * Copyright (c) 2013-present, Facebook, Inc.
  9868. *
  9869. * This source code is licensed under the MIT license found in the
  9870. * LICENSE file in the root directory of this source tree.
  9871. *
  9872. * @typechecks
  9873. */
  9874. /**
  9875. * Gets an element's bounding rect in pixels relative to the viewport.
  9876. *
  9877. * @param {DOMElement} elem
  9878. * @return {object}
  9879. */
  9880. function getElementRect(elem) {
  9881. var docElem = elem.ownerDocument.documentElement;
  9882. // FF 2, Safari 3 and Opera 9.5- do not support getBoundingClientRect().
  9883. // IE9- will throw if the element is not in the document.
  9884. if (!('getBoundingClientRect' in elem) || !containsNode_1(docElem, elem)) {
  9885. return {
  9886. left: 0,
  9887. right: 0,
  9888. top: 0,
  9889. bottom: 0
  9890. };
  9891. }
  9892. // Subtracts clientTop/Left because IE8- added a 2px border to the
  9893. // <html> element (see http://fburl.com/1493213). IE 7 in
  9894. // Quicksmode does not report clientLeft/clientTop so there
  9895. // will be an unaccounted offset of 2px when in quirksmode
  9896. var rect = elem.getBoundingClientRect();
  9897. return {
  9898. left: Math.round(rect.left) - docElem.clientLeft,
  9899. right: Math.round(rect.right) - docElem.clientLeft,
  9900. top: Math.round(rect.top) - docElem.clientTop,
  9901. bottom: Math.round(rect.bottom) - docElem.clientTop
  9902. };
  9903. }
  9904. var getElementRect_1 = getElementRect;
  9905. /**
  9906. * Copyright (c) 2013-present, Facebook, Inc.
  9907. *
  9908. * This source code is licensed under the MIT license found in the
  9909. * LICENSE file in the root directory of this source tree.
  9910. *
  9911. * @typechecks
  9912. */
  9913. /**
  9914. * Gets an element's position in pixels relative to the viewport. The returned
  9915. * object represents the position of the element's top left corner.
  9916. *
  9917. * @param {DOMElement} element
  9918. * @return {object}
  9919. */
  9920. function getElementPosition(element) {
  9921. var rect = getElementRect_1(element);
  9922. return {
  9923. x: rect.left,
  9924. y: rect.top,
  9925. width: rect.right - rect.left,
  9926. height: rect.bottom - rect.top
  9927. };
  9928. }
  9929. var getElementPosition_1 = getElementPosition;
  9930. /**
  9931. * Copyright (c) 2013-present, Facebook, Inc.
  9932. *
  9933. * This source code is licensed under the MIT license found in the
  9934. * LICENSE file in the root directory of this source tree.
  9935. *
  9936. * @typechecks
  9937. */
  9938. var isWebkit = typeof navigator !== 'undefined' && navigator.userAgent.indexOf('AppleWebKit') > -1;
  9939. /**
  9940. * Gets the element with the document scroll properties such as `scrollLeft` and
  9941. * `scrollHeight`. This may differ across different browsers.
  9942. *
  9943. * NOTE: The return value can be null if the DOM is not yet ready.
  9944. *
  9945. * @param {?DOMDocument} doc Defaults to current document.
  9946. * @return {?DOMElement}
  9947. */
  9948. function getDocumentScrollElement(doc) {
  9949. doc = doc || document;
  9950. if (doc.scrollingElement) {
  9951. return doc.scrollingElement;
  9952. }
  9953. return !isWebkit && doc.compatMode === 'CSS1Compat' ? doc.documentElement : doc.body;
  9954. }
  9955. var getDocumentScrollElement_1 = getDocumentScrollElement;
  9956. /**
  9957. * Copyright (c) 2013-present, Facebook, Inc.
  9958. *
  9959. * This source code is licensed under the MIT license found in the
  9960. * LICENSE file in the root directory of this source tree.
  9961. *
  9962. * @typechecks
  9963. */
  9964. /**
  9965. * Gets the scroll position of the supplied element or window.
  9966. *
  9967. * The return values are unbounded, unlike `getScrollPosition`. This means they
  9968. * may be negative or exceed the element boundaries (which is possible using
  9969. * inertial scrolling).
  9970. *
  9971. * @param {DOMWindow|DOMElement} scrollable
  9972. * @return {object} Map with `x` and `y` keys.
  9973. */
  9974. function getUnboundedScrollPosition(scrollable) {
  9975. if (scrollable.Window && scrollable instanceof scrollable.Window) {
  9976. return {
  9977. x: scrollable.pageXOffset || scrollable.document.documentElement.scrollLeft,
  9978. y: scrollable.pageYOffset || scrollable.document.documentElement.scrollTop
  9979. };
  9980. }
  9981. return {
  9982. x: scrollable.scrollLeft,
  9983. y: scrollable.scrollTop
  9984. };
  9985. }
  9986. var getUnboundedScrollPosition_1 = getUnboundedScrollPosition;
  9987. /**
  9988. * Gets the scroll position of the supplied element or window.
  9989. *
  9990. * The return values are bounded. This means that if the scroll position is
  9991. * negative or exceeds the element boundaries (which is possible using inertial
  9992. * scrolling), you will get zero or the maximum scroll position, respectively.
  9993. *
  9994. * If you need the unbound scroll position, use `getUnboundedScrollPosition`.
  9995. *
  9996. * @param {DOMWindow|DOMElement} scrollable
  9997. * @return {object} Map with `x` and `y` keys.
  9998. */
  9999. function getScrollPosition(scrollable) {
  10000. var documentScrollElement = getDocumentScrollElement_1(scrollable.ownerDocument || scrollable.document);
  10001. if (scrollable.Window && scrollable instanceof scrollable.Window) {
  10002. scrollable = documentScrollElement;
  10003. }
  10004. var scrollPosition = getUnboundedScrollPosition_1(scrollable);
  10005. var viewport = scrollable === documentScrollElement ? scrollable.ownerDocument.documentElement : scrollable;
  10006. var xMax = scrollable.scrollWidth - viewport.clientWidth;
  10007. var yMax = scrollable.scrollHeight - viewport.clientHeight;
  10008. scrollPosition.x = Math.max(0, Math.min(scrollPosition.x, xMax));
  10009. scrollPosition.y = Math.max(0, Math.min(scrollPosition.y, yMax));
  10010. return scrollPosition;
  10011. }
  10012. var getScrollPosition_1 = getScrollPosition;
  10013. function getViewportWidth() {
  10014. var width = void 0;
  10015. if (document.documentElement) {
  10016. width = document.documentElement.clientWidth;
  10017. }
  10018. if (!width && document.body) {
  10019. width = document.body.clientWidth;
  10020. }
  10021. return width || 0;
  10022. } /**
  10023. * Copyright (c) 2013-present, Facebook, Inc.
  10024. *
  10025. * This source code is licensed under the MIT license found in the
  10026. * LICENSE file in the root directory of this source tree.
  10027. *
  10028. *
  10029. * @typechecks
  10030. */
  10031. function getViewportHeight() {
  10032. var height = void 0;
  10033. if (document.documentElement) {
  10034. height = document.documentElement.clientHeight;
  10035. }
  10036. if (!height && document.body) {
  10037. height = document.body.clientHeight;
  10038. }
  10039. return height || 0;
  10040. }
  10041. /**
  10042. * Gets the viewport dimensions including any scrollbars.
  10043. */
  10044. function getViewportDimensions() {
  10045. return {
  10046. width: window.innerWidth || getViewportWidth(),
  10047. height: window.innerHeight || getViewportHeight()
  10048. };
  10049. }
  10050. /**
  10051. * Gets the viewport dimensions excluding any scrollbars.
  10052. */
  10053. getViewportDimensions.withoutScrollbars = function () {
  10054. return {
  10055. width: getViewportWidth(),
  10056. height: getViewportHeight()
  10057. };
  10058. };
  10059. var getViewportDimensions_1 = getViewportDimensions;
  10060. var _extends$2 = objectAssign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  10061. function _classCallCheck$b(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10062. function _possibleConstructorReturn$8(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  10063. function _inherits$8(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  10064. var SCROLL_BUFFER = 10;
  10065. /**
  10066. * Return whether a block overlaps with either edge of the `SelectionState`.
  10067. */
  10068. var isBlockOnSelectionEdge = function isBlockOnSelectionEdge(selection, key) {
  10069. return selection.getAnchorKey() === key || selection.getFocusKey() === key;
  10070. };
  10071. /**
  10072. * The default block renderer for a `DraftEditor` component.
  10073. *
  10074. * A `DraftEditorBlock` is able to render a given `ContentBlock` to its
  10075. * appropriate decorator and inline style components.
  10076. */
  10077. var DraftEditorBlock = function (_React$Component) {
  10078. _inherits$8(DraftEditorBlock, _React$Component);
  10079. function DraftEditorBlock() {
  10080. _classCallCheck$b(this, DraftEditorBlock);
  10081. return _possibleConstructorReturn$8(this, _React$Component.apply(this, arguments));
  10082. }
  10083. DraftEditorBlock.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
  10084. return this.props.block !== nextProps.block || this.props.tree !== nextProps.tree || this.props.direction !== nextProps.direction || isBlockOnSelectionEdge(nextProps.selection, nextProps.block.getKey()) && nextProps.forceSelection;
  10085. };
  10086. /**
  10087. * When a block is mounted and overlaps the selection state, we need to make
  10088. * sure that the cursor is visible to match native behavior. This may not
  10089. * be the case if the user has pressed `RETURN` or pasted some content, since
  10090. * programatically creating these new blocks and setting the DOM selection
  10091. * will miss out on the browser natively scrolling to that position.
  10092. *
  10093. * To replicate native behavior, if the block overlaps the selection state
  10094. * on mount, force the scroll position. Check the scroll state of the scroll
  10095. * parent, and adjust it to align the entire block to the bottom of the
  10096. * scroll parent.
  10097. */
  10098. DraftEditorBlock.prototype.componentDidMount = function componentDidMount() {
  10099. var selection = this.props.selection;
  10100. var endKey = selection.getEndKey();
  10101. if (!selection.getHasFocus() || endKey !== this.props.block.getKey()) {
  10102. return;
  10103. }
  10104. var blockNode = reactDom__default.findDOMNode(this);
  10105. var scrollParent = Style_1.getScrollParent(blockNode);
  10106. var scrollPosition = getScrollPosition_1(scrollParent);
  10107. var scrollDelta = void 0;
  10108. if (scrollParent === window) {
  10109. var nodePosition = getElementPosition_1(blockNode);
  10110. var nodeBottom = nodePosition.y + nodePosition.height;
  10111. var viewportHeight = getViewportDimensions_1().height;
  10112. scrollDelta = nodeBottom - viewportHeight;
  10113. if (scrollDelta > 0) {
  10114. window.scrollTo(scrollPosition.x, scrollPosition.y + scrollDelta + SCROLL_BUFFER);
  10115. }
  10116. } else {
  10117. !(blockNode instanceof HTMLElement) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'blockNode is not an HTMLElement') : invariant_1(false) : void 0;
  10118. var blockBottom = blockNode.offsetHeight + blockNode.offsetTop;
  10119. var scrollBottom = scrollParent.offsetHeight + scrollPosition.y;
  10120. scrollDelta = blockBottom - scrollBottom;
  10121. if (scrollDelta > 0) {
  10122. Scroll_1.setTop(scrollParent, Scroll_1.getTop(scrollParent) + scrollDelta + SCROLL_BUFFER);
  10123. }
  10124. }
  10125. };
  10126. DraftEditorBlock.prototype._renderChildren = function _renderChildren() {
  10127. var _this2 = this;
  10128. var block = this.props.block;
  10129. var blockKey = block.getKey();
  10130. var text = block.getText();
  10131. var lastLeafSet = this.props.tree.size - 1;
  10132. var hasSelection = isBlockOnSelectionEdge(this.props.selection, blockKey);
  10133. return this.props.tree.map(function (leafSet, ii) {
  10134. var leavesForLeafSet = leafSet.get('leaves');
  10135. var lastLeaf = leavesForLeafSet.size - 1;
  10136. var leaves = leavesForLeafSet.map(function (leaf, jj) {
  10137. var offsetKey = DraftOffsetKey_1.encode(blockKey, ii, jj);
  10138. var start = leaf.get('start');
  10139. var end = leaf.get('end');
  10140. return React__default.createElement(DraftEditorLeaf_react, {
  10141. key: offsetKey,
  10142. offsetKey: offsetKey,
  10143. block: block,
  10144. start: start,
  10145. selection: hasSelection ? _this2.props.selection : null,
  10146. forceSelection: _this2.props.forceSelection,
  10147. text: text.slice(start, end),
  10148. styleSet: block.getInlineStyleAt(start),
  10149. customStyleMap: _this2.props.customStyleMap,
  10150. customStyleFn: _this2.props.customStyleFn,
  10151. isLast: ii === lastLeafSet && jj === lastLeaf
  10152. });
  10153. }).toArray();
  10154. var decoratorKey = leafSet.get('decoratorKey');
  10155. if (decoratorKey == null) {
  10156. return leaves;
  10157. }
  10158. if (!_this2.props.decorator) {
  10159. return leaves;
  10160. }
  10161. var decorator = nullthrows_1(_this2.props.decorator);
  10162. var DecoratorComponent = decorator.getComponentForKey(decoratorKey);
  10163. if (!DecoratorComponent) {
  10164. return leaves;
  10165. }
  10166. var decoratorProps = decorator.getPropsForKey(decoratorKey);
  10167. var decoratorOffsetKey = DraftOffsetKey_1.encode(blockKey, ii, 0);
  10168. var decoratedText = text.slice(leavesForLeafSet.first().get('start'), leavesForLeafSet.last().get('end'));
  10169. // Resetting dir to the same value on a child node makes Chrome/Firefox
  10170. // confused on cursor movement. See http://jsfiddle.net/d157kLck/3/
  10171. var dir = UnicodeBidiDirection_1.getHTMLDirIfDifferent(UnicodeBidi_1.getDirection(decoratedText), _this2.props.direction);
  10172. return React__default.createElement(
  10173. DecoratorComponent,
  10174. _extends$2({}, decoratorProps, {
  10175. contentState: _this2.props.contentState,
  10176. decoratedText: decoratedText,
  10177. dir: dir,
  10178. key: decoratorOffsetKey,
  10179. entityKey: block.getEntityAt(leafSet.get('start')),
  10180. offsetKey: decoratorOffsetKey }),
  10181. leaves
  10182. );
  10183. }).toArray();
  10184. };
  10185. DraftEditorBlock.prototype.render = function render() {
  10186. var _props = this.props,
  10187. direction = _props.direction,
  10188. offsetKey = _props.offsetKey;
  10189. var className = cx_1({
  10190. 'public/DraftStyleDefault/block': true,
  10191. 'public/DraftStyleDefault/ltr': direction === 'LTR',
  10192. 'public/DraftStyleDefault/rtl': direction === 'RTL'
  10193. });
  10194. return React__default.createElement(
  10195. 'div',
  10196. { 'data-offset-key': offsetKey, className: className },
  10197. this._renderChildren()
  10198. );
  10199. };
  10200. return DraftEditorBlock;
  10201. }(React__default.Component);
  10202. var DraftEditorBlock_react = DraftEditorBlock;
  10203. /**
  10204. * Copyright (c) 2013-present, Facebook, Inc.
  10205. *
  10206. * This source code is licensed under the MIT license found in the
  10207. * LICENSE file in the root directory of this source tree.
  10208. *
  10209. * @typechecks static-only
  10210. */
  10211. /**
  10212. * Combines multiple className strings into one.
  10213. * http://jsperf.com/joinclasses-args-vs-array
  10214. *
  10215. * @param {...?string} className
  10216. * @return {string}
  10217. */
  10218. function joinClasses(className /*, ... */) {
  10219. if (!className) {
  10220. className = '';
  10221. }
  10222. var nextClass = void 0;
  10223. var argLength = arguments.length;
  10224. if (argLength > 1) {
  10225. for (var ii = 1; ii < argLength; ii++) {
  10226. nextClass = arguments[ii];
  10227. if (nextClass) {
  10228. className = (className ? className + ' ' : '') + nextClass;
  10229. }
  10230. }
  10231. }
  10232. return className;
  10233. }
  10234. var joinClasses_1 = joinClasses;
  10235. var _extends$3 = objectAssign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  10236. function _classCallCheck$c(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10237. function _possibleConstructorReturn$9(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  10238. function _inherits$9(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  10239. /**
  10240. * Provide default styling for list items. This way, lists will be styled with
  10241. * proper counters and indentation even if the caller does not specify
  10242. * their own styling at all. If more than five levels of nesting are needed,
  10243. * the necessary CSS classes can be provided via `blockStyleFn` configuration.
  10244. */
  10245. var getListItemClasses = function getListItemClasses(type, depth, shouldResetCount, direction) {
  10246. return cx_1({
  10247. 'public/DraftStyleDefault/unorderedListItem': type === 'unordered-list-item',
  10248. 'public/DraftStyleDefault/orderedListItem': type === 'ordered-list-item',
  10249. 'public/DraftStyleDefault/reset': shouldResetCount,
  10250. 'public/DraftStyleDefault/depth0': depth === 0,
  10251. 'public/DraftStyleDefault/depth1': depth === 1,
  10252. 'public/DraftStyleDefault/depth2': depth === 2,
  10253. 'public/DraftStyleDefault/depth3': depth === 3,
  10254. 'public/DraftStyleDefault/depth4': depth === 4,
  10255. 'public/DraftStyleDefault/listLTR': direction === 'LTR',
  10256. 'public/DraftStyleDefault/listRTL': direction === 'RTL'
  10257. });
  10258. };
  10259. /**
  10260. * `DraftEditorContents` is the container component for all block components
  10261. * rendered for a `DraftEditor`. It is optimized to aggressively avoid
  10262. * re-rendering blocks whenever possible.
  10263. *
  10264. * This component is separate from `DraftEditor` because certain props
  10265. * (for instance, ARIA props) must be allowed to update without affecting
  10266. * the contents of the editor.
  10267. */
  10268. var DraftEditorContents = function (_React$Component) {
  10269. _inherits$9(DraftEditorContents, _React$Component);
  10270. function DraftEditorContents() {
  10271. _classCallCheck$c(this, DraftEditorContents);
  10272. return _possibleConstructorReturn$9(this, _React$Component.apply(this, arguments));
  10273. }
  10274. DraftEditorContents.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
  10275. var prevEditorState = this.props.editorState;
  10276. var nextEditorState = nextProps.editorState;
  10277. var prevDirectionMap = prevEditorState.getDirectionMap();
  10278. var nextDirectionMap = nextEditorState.getDirectionMap();
  10279. // Text direction has changed for one or more blocks. We must re-render.
  10280. if (prevDirectionMap !== nextDirectionMap) {
  10281. return true;
  10282. }
  10283. var didHaveFocus = prevEditorState.getSelection().getHasFocus();
  10284. var nowHasFocus = nextEditorState.getSelection().getHasFocus();
  10285. if (didHaveFocus !== nowHasFocus) {
  10286. return true;
  10287. }
  10288. var nextNativeContent = nextEditorState.getNativelyRenderedContent();
  10289. var wasComposing = prevEditorState.isInCompositionMode();
  10290. var nowComposing = nextEditorState.isInCompositionMode();
  10291. // If the state is unchanged or we're currently rendering a natively
  10292. // rendered state, there's nothing new to be done.
  10293. if (prevEditorState === nextEditorState || nextNativeContent !== null && nextEditorState.getCurrentContent() === nextNativeContent || wasComposing && nowComposing) {
  10294. return false;
  10295. }
  10296. var prevContent = prevEditorState.getCurrentContent();
  10297. var nextContent = nextEditorState.getCurrentContent();
  10298. var prevDecorator = prevEditorState.getDecorator();
  10299. var nextDecorator = nextEditorState.getDecorator();
  10300. return wasComposing !== nowComposing || prevContent !== nextContent || prevDecorator !== nextDecorator || nextEditorState.mustForceSelection();
  10301. };
  10302. DraftEditorContents.prototype.render = function render() {
  10303. var _props = this.props,
  10304. blockRenderMap = _props.blockRenderMap,
  10305. blockRendererFn = _props.blockRendererFn,
  10306. blockStyleFn = _props.blockStyleFn,
  10307. customStyleMap = _props.customStyleMap,
  10308. customStyleFn = _props.customStyleFn,
  10309. editorState = _props.editorState,
  10310. editorKey = _props.editorKey,
  10311. textDirectionality = _props.textDirectionality;
  10312. var content = editorState.getCurrentContent();
  10313. var selection = editorState.getSelection();
  10314. var forceSelection = editorState.mustForceSelection();
  10315. var decorator = editorState.getDecorator();
  10316. var directionMap = nullthrows_1(editorState.getDirectionMap());
  10317. var blocksAsArray = content.getBlocksAsArray();
  10318. var processedBlocks = [];
  10319. var currentDepth = null;
  10320. var lastWrapperTemplate = null;
  10321. for (var ii = 0; ii < blocksAsArray.length; ii++) {
  10322. var _block = blocksAsArray[ii];
  10323. var key = _block.getKey();
  10324. var blockType = _block.getType();
  10325. var customRenderer = blockRendererFn(_block);
  10326. var CustomComponent = void 0,
  10327. customProps = void 0,
  10328. customEditable = void 0;
  10329. if (customRenderer) {
  10330. CustomComponent = customRenderer.component;
  10331. customProps = customRenderer.props;
  10332. customEditable = customRenderer.editable;
  10333. }
  10334. var direction = textDirectionality ? textDirectionality : directionMap.get(key);
  10335. var offsetKey = DraftOffsetKey_1.encode(key, 0, 0);
  10336. var componentProps = {
  10337. contentState: content,
  10338. block: _block,
  10339. blockProps: customProps,
  10340. blockStyleFn: blockStyleFn,
  10341. customStyleMap: customStyleMap,
  10342. customStyleFn: customStyleFn,
  10343. decorator: decorator,
  10344. direction: direction,
  10345. forceSelection: forceSelection,
  10346. key: key,
  10347. offsetKey: offsetKey,
  10348. selection: selection,
  10349. tree: editorState.getBlockTree(key)
  10350. };
  10351. var configForType = blockRenderMap.get(blockType) || blockRenderMap.get('unstyled');
  10352. var wrapperTemplate = configForType.wrapper;
  10353. var Element = configForType.element || blockRenderMap.get('unstyled').element;
  10354. var depth = _block.getDepth();
  10355. var className = '';
  10356. if (blockStyleFn) {
  10357. className = blockStyleFn(_block);
  10358. }
  10359. // List items are special snowflakes, since we handle nesting and
  10360. // counters manually.
  10361. if (Element === 'li') {
  10362. var shouldResetCount = lastWrapperTemplate !== wrapperTemplate || currentDepth === null || depth > currentDepth;
  10363. className = joinClasses_1(className, getListItemClasses(blockType, depth, shouldResetCount, direction));
  10364. }
  10365. var Component = CustomComponent || DraftEditorBlock_react;
  10366. var childProps = {
  10367. className: className,
  10368. 'data-block': true,
  10369. 'data-editor': editorKey,
  10370. 'data-offset-key': offsetKey,
  10371. key: key
  10372. };
  10373. if (customEditable !== undefined) {
  10374. childProps = _extends$3({}, childProps, {
  10375. contentEditable: customEditable,
  10376. suppressContentEditableWarning: true
  10377. });
  10378. }
  10379. var child = React__default.createElement(Element, childProps, React__default.createElement(Component, componentProps));
  10380. processedBlocks.push({
  10381. block: child,
  10382. wrapperTemplate: wrapperTemplate,
  10383. key: key,
  10384. offsetKey: offsetKey
  10385. });
  10386. if (wrapperTemplate) {
  10387. currentDepth = _block.getDepth();
  10388. } else {
  10389. currentDepth = null;
  10390. }
  10391. lastWrapperTemplate = wrapperTemplate;
  10392. }
  10393. // Group contiguous runs of blocks that have the same wrapperTemplate
  10394. var outputBlocks = [];
  10395. for (var _ii = 0; _ii < processedBlocks.length;) {
  10396. var info = processedBlocks[_ii];
  10397. if (info.wrapperTemplate) {
  10398. var blocks = [];
  10399. do {
  10400. blocks.push(processedBlocks[_ii].block);
  10401. _ii++;
  10402. } while (_ii < processedBlocks.length && processedBlocks[_ii].wrapperTemplate === info.wrapperTemplate);
  10403. var wrapperElement = React__default.cloneElement(info.wrapperTemplate, {
  10404. key: info.key + '-wrap',
  10405. 'data-offset-key': info.offsetKey
  10406. }, blocks);
  10407. outputBlocks.push(wrapperElement);
  10408. } else {
  10409. outputBlocks.push(info.block);
  10410. _ii++;
  10411. }
  10412. }
  10413. return React__default.createElement(
  10414. 'div',
  10415. { 'data-contents': 'true' },
  10416. outputBlocks
  10417. );
  10418. };
  10419. return DraftEditorContents;
  10420. }(React__default.Component);
  10421. var DraftEditorContentsCore_react = DraftEditorContents;
  10422. var DraftEditorContents_react = DraftEditorContentsCore_react;
  10423. /**
  10424. * Copyright (c) 2013-present, Facebook, Inc.
  10425. *
  10426. * This source code is licensed under the MIT license found in the
  10427. * LICENSE file in the root directory of this source tree.
  10428. *
  10429. */
  10430. var PhotosMimeType = {
  10431. isImage: function isImage(mimeString) {
  10432. return getParts(mimeString)[0] === 'image';
  10433. },
  10434. isJpeg: function isJpeg(mimeString) {
  10435. var parts = getParts(mimeString);
  10436. return PhotosMimeType.isImage(mimeString) && (
  10437. // see http://fburl.com/10972194
  10438. parts[1] === 'jpeg' || parts[1] === 'pjpeg');
  10439. }
  10440. };
  10441. function getParts(mimeString) {
  10442. return mimeString.split('/');
  10443. }
  10444. var PhotosMimeType_1 = PhotosMimeType;
  10445. /**
  10446. * Copyright (c) 2013-present, Facebook, Inc.
  10447. *
  10448. * This source code is licensed under the MIT license found in the
  10449. * LICENSE file in the root directory of this source tree.
  10450. *
  10451. * @typechecks
  10452. */
  10453. /**
  10454. * Convert array-like objects to arrays.
  10455. *
  10456. * This API assumes the caller knows the contents of the data type. For less
  10457. * well defined inputs use createArrayFromMixed.
  10458. *
  10459. * @param {object|function|filelist} obj
  10460. * @return {array}
  10461. */
  10462. function toArray(obj) {
  10463. var length = obj.length;
  10464. // Some browsers builtin objects can report typeof 'function' (e.g. NodeList
  10465. // in old versions of Safari).
  10466. !(!Array.isArray(obj) && (typeof obj === 'object' || typeof obj === 'function')) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'toArray: Array-like object expected') : invariant_1(false) : void 0;
  10467. !(typeof length === 'number') ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'toArray: Object needs a length property') : invariant_1(false) : void 0;
  10468. !(length === 0 || length - 1 in obj) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'toArray: Object should have keys for indices') : invariant_1(false) : void 0;
  10469. !(typeof obj.callee !== 'function') ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'toArray: Object can\'t be `arguments`. Use rest params ' + '(function(...args) {}) or Array.from() instead.') : invariant_1(false) : void 0;
  10470. // Old IE doesn't give collections access to hasOwnProperty. Assume inputs
  10471. // without method will throw during the slice call and skip straight to the
  10472. // fallback.
  10473. if (obj.hasOwnProperty) {
  10474. try {
  10475. return Array.prototype.slice.call(obj);
  10476. } catch (e) {
  10477. // IE < 9 does not support Array#slice on collections objects
  10478. }
  10479. }
  10480. // Fall back to copying key by key. This assumes all keys have a value,
  10481. // so will not preserve sparsely populated inputs.
  10482. var ret = Array(length);
  10483. for (var ii = 0; ii < length; ii++) {
  10484. ret[ii] = obj[ii];
  10485. }
  10486. return ret;
  10487. }
  10488. /**
  10489. * Perform a heuristic test to determine if an object is "array-like".
  10490. *
  10491. * A monk asked Joshu, a Zen master, "Has a dog Buddha nature?"
  10492. * Joshu replied: "Mu."
  10493. *
  10494. * This function determines if its argument has "array nature": it returns
  10495. * true if the argument is an actual array, an `arguments' object, or an
  10496. * HTMLCollection (e.g. node.childNodes or node.getElementsByTagName()).
  10497. *
  10498. * It will return false for other array-like objects like Filelist.
  10499. *
  10500. * @param {*} obj
  10501. * @return {boolean}
  10502. */
  10503. function hasArrayNature(obj) {
  10504. return (
  10505. // not null/false
  10506. !!obj && (
  10507. // arrays are objects, NodeLists are functions in Safari
  10508. typeof obj == 'object' || typeof obj == 'function') &&
  10509. // quacks like an array
  10510. 'length' in obj &&
  10511. // not window
  10512. !('setInterval' in obj) &&
  10513. // no DOM node should be considered an array-like
  10514. // a 'select' element has 'length' and 'item' properties on IE8
  10515. typeof obj.nodeType != 'number' && (
  10516. // a real array
  10517. Array.isArray(obj) ||
  10518. // arguments
  10519. 'callee' in obj ||
  10520. // HTMLCollection/NodeList
  10521. 'item' in obj)
  10522. );
  10523. }
  10524. /**
  10525. * Ensure that the argument is an array by wrapping it in an array if it is not.
  10526. * Creates a copy of the argument if it is already an array.
  10527. *
  10528. * This is mostly useful idiomatically:
  10529. *
  10530. * var createArrayFromMixed = require('createArrayFromMixed');
  10531. *
  10532. * function takesOneOrMoreThings(things) {
  10533. * things = createArrayFromMixed(things);
  10534. * ...
  10535. * }
  10536. *
  10537. * This allows you to treat `things' as an array, but accept scalars in the API.
  10538. *
  10539. * If you need to convert an array-like object, like `arguments`, into an array
  10540. * use toArray instead.
  10541. *
  10542. * @param {*} obj
  10543. * @return {array}
  10544. */
  10545. function createArrayFromMixed(obj) {
  10546. if (!hasArrayNature(obj)) {
  10547. return [obj];
  10548. } else if (Array.isArray(obj)) {
  10549. return obj.slice();
  10550. } else {
  10551. return toArray(obj);
  10552. }
  10553. }
  10554. var createArrayFromMixed_1 = createArrayFromMixed;
  10555. function _classCallCheck$d(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10556. /**
  10557. * Copyright (c) 2013-present, Facebook, Inc.
  10558. *
  10559. * This source code is licensed under the MIT license found in the
  10560. * LICENSE file in the root directory of this source tree.
  10561. *
  10562. * @typechecks
  10563. */
  10564. var CR_LF_REGEX = new RegExp('\r\n', 'g');
  10565. var LF_ONLY = '\n';
  10566. var RICH_TEXT_TYPES = {
  10567. 'text/rtf': 1,
  10568. 'text/html': 1
  10569. };
  10570. /**
  10571. * If DataTransferItem is a file then return the Blob of data.
  10572. *
  10573. * @param {object} item
  10574. * @return {?blob}
  10575. */
  10576. function getFileFromDataTransfer(item) {
  10577. if (item.kind == 'file') {
  10578. return item.getAsFile();
  10579. }
  10580. }
  10581. var DataTransfer = function () {
  10582. /**
  10583. * @param {object} data
  10584. */
  10585. function DataTransfer(data) {
  10586. _classCallCheck$d(this, DataTransfer);
  10587. this.data = data;
  10588. // Types could be DOMStringList or array
  10589. this.types = data.types ? createArrayFromMixed_1(data.types) : [];
  10590. }
  10591. /**
  10592. * Is this likely to be a rich text data transfer?
  10593. *
  10594. * @return {boolean}
  10595. */
  10596. DataTransfer.prototype.isRichText = function isRichText() {
  10597. // If HTML is available, treat this data as rich text. This way, we avoid
  10598. // using a pasted image if it is packaged with HTML -- this may occur with
  10599. // pastes from MS Word, for example. However this is only rich text if
  10600. // there's accompanying text.
  10601. if (this.getHTML() && this.getText()) {
  10602. return true;
  10603. }
  10604. // When an image is copied from a preview window, you end up with two
  10605. // DataTransferItems one of which is a file's metadata as text. Skip those.
  10606. if (this.isImage()) {
  10607. return false;
  10608. }
  10609. return this.types.some(function (type) {
  10610. return RICH_TEXT_TYPES[type];
  10611. });
  10612. };
  10613. /**
  10614. * Get raw text.
  10615. *
  10616. * @return {?string}
  10617. */
  10618. DataTransfer.prototype.getText = function getText() {
  10619. var text;
  10620. if (this.data.getData) {
  10621. if (!this.types.length) {
  10622. text = this.data.getData('Text');
  10623. } else if (this.types.indexOf('text/plain') != -1) {
  10624. text = this.data.getData('text/plain');
  10625. }
  10626. }
  10627. return text ? text.replace(CR_LF_REGEX, LF_ONLY) : null;
  10628. };
  10629. /**
  10630. * Get HTML paste data
  10631. *
  10632. * @return {?string}
  10633. */
  10634. DataTransfer.prototype.getHTML = function getHTML() {
  10635. if (this.data.getData) {
  10636. if (!this.types.length) {
  10637. return this.data.getData('Text');
  10638. } else if (this.types.indexOf('text/html') != -1) {
  10639. return this.data.getData('text/html');
  10640. }
  10641. }
  10642. };
  10643. /**
  10644. * Is this a link data transfer?
  10645. *
  10646. * @return {boolean}
  10647. */
  10648. DataTransfer.prototype.isLink = function isLink() {
  10649. return this.types.some(function (type) {
  10650. return type.indexOf('Url') != -1 || type.indexOf('text/uri-list') != -1 || type.indexOf('text/x-moz-url');
  10651. });
  10652. };
  10653. /**
  10654. * Get a link url.
  10655. *
  10656. * @return {?string}
  10657. */
  10658. DataTransfer.prototype.getLink = function getLink() {
  10659. if (this.data.getData) {
  10660. if (this.types.indexOf('text/x-moz-url') != -1) {
  10661. var url = this.data.getData('text/x-moz-url').split('\n');
  10662. return url[0];
  10663. }
  10664. return this.types.indexOf('text/uri-list') != -1 ? this.data.getData('text/uri-list') : this.data.getData('url');
  10665. }
  10666. return null;
  10667. };
  10668. /**
  10669. * Is this an image data transfer?
  10670. *
  10671. * @return {boolean}
  10672. */
  10673. DataTransfer.prototype.isImage = function isImage() {
  10674. var isImage = this.types.some(function (type) {
  10675. // Firefox will have a type of application/x-moz-file for images during
  10676. // dragging
  10677. return type.indexOf('application/x-moz-file') != -1;
  10678. });
  10679. if (isImage) {
  10680. return true;
  10681. }
  10682. var items = this.getFiles();
  10683. for (var i = 0; i < items.length; i++) {
  10684. var type = items[i].type;
  10685. if (!PhotosMimeType_1.isImage(type)) {
  10686. return false;
  10687. }
  10688. }
  10689. return true;
  10690. };
  10691. DataTransfer.prototype.getCount = function getCount() {
  10692. if (this.data.hasOwnProperty('items')) {
  10693. return this.data.items.length;
  10694. } else if (this.data.hasOwnProperty('mozItemCount')) {
  10695. return this.data.mozItemCount;
  10696. } else if (this.data.files) {
  10697. return this.data.files.length;
  10698. }
  10699. return null;
  10700. };
  10701. /**
  10702. * Get files.
  10703. *
  10704. * @return {array}
  10705. */
  10706. DataTransfer.prototype.getFiles = function getFiles() {
  10707. if (this.data.items) {
  10708. // createArrayFromMixed doesn't properly handle DataTransferItemLists.
  10709. return Array.prototype.slice.call(this.data.items).map(getFileFromDataTransfer).filter(emptyFunction_1.thatReturnsArgument);
  10710. } else if (this.data.files) {
  10711. return Array.prototype.slice.call(this.data.files);
  10712. } else {
  10713. return [];
  10714. }
  10715. };
  10716. /**
  10717. * Are there any files to fetch?
  10718. *
  10719. * @return {boolean}
  10720. */
  10721. DataTransfer.prototype.hasFiles = function hasFiles() {
  10722. return this.getFiles().length > 0;
  10723. };
  10724. return DataTransfer;
  10725. }();
  10726. var DataTransfer_1 = DataTransfer;
  10727. /**
  10728. * Copyright (c) 2013-present, Facebook, Inc.
  10729. * All rights reserved.
  10730. *
  10731. * This source code is licensed under the BSD-style license found in the
  10732. * LICENSE file in the root directory of this source tree. An additional grant
  10733. * of patent rights can be found in the PATENTS file in the same directory.
  10734. *
  10735. * @providesModule getSelectionOffsetKeyForNode
  10736. * @format
  10737. *
  10738. */
  10739. /**
  10740. * Get offset key from a node or it's child nodes. Return the first offset key
  10741. * found on the DOM tree of given node.
  10742. */
  10743. function getSelectionOffsetKeyForNode(node) {
  10744. if (node instanceof Element) {
  10745. var offsetKey = node.getAttribute('data-offset-key');
  10746. if (offsetKey) {
  10747. return offsetKey;
  10748. }
  10749. for (var ii = 0; ii < node.childNodes.length; ii++) {
  10750. var childOffsetKey = getSelectionOffsetKeyForNode(node.childNodes[ii]);
  10751. if (childOffsetKey) {
  10752. return childOffsetKey;
  10753. }
  10754. }
  10755. }
  10756. return null;
  10757. }
  10758. var getSelectionOffsetKeyForNode_1 = getSelectionOffsetKeyForNode;
  10759. /**
  10760. * Get the key from the node's nearest offset-aware ancestor.
  10761. */
  10762. function findAncestorOffsetKey(node) {
  10763. var searchNode = node;
  10764. while (searchNode && searchNode !== document.documentElement) {
  10765. var key = getSelectionOffsetKeyForNode_1(searchNode);
  10766. if (key != null) {
  10767. return key;
  10768. }
  10769. searchNode = searchNode.parentNode;
  10770. }
  10771. return null;
  10772. }
  10773. var findAncestorOffsetKey_1 = findAncestorOffsetKey;
  10774. var TEXT_CLIPPING_REGEX = /\.textClipping$/;
  10775. var TEXT_TYPES = {
  10776. 'text/plain': true,
  10777. 'text/html': true,
  10778. 'text/rtf': true
  10779. };
  10780. // Somewhat arbitrary upper bound on text size. Let's not lock up the browser.
  10781. var TEXT_SIZE_UPPER_BOUND = 5000;
  10782. /**
  10783. * Extract the text content from a file list.
  10784. */
  10785. function getTextContentFromFiles(files, callback) {
  10786. var readCount = 0;
  10787. var results = [];
  10788. files.forEach(function ( /*blob*/file) {
  10789. readFile(file, function ( /*string*/text) {
  10790. readCount++;
  10791. text && results.push(text.slice(0, TEXT_SIZE_UPPER_BOUND));
  10792. if (readCount == files.length) {
  10793. callback(results.join('\r'));
  10794. }
  10795. });
  10796. });
  10797. }
  10798. /**
  10799. * todo isaac: Do work to turn html/rtf into a content fragment.
  10800. */
  10801. function readFile(file, callback) {
  10802. if (!_commonjsHelpers.commonjsGlobal.FileReader || file.type && !(file.type in TEXT_TYPES)) {
  10803. callback('');
  10804. return;
  10805. }
  10806. if (file.type === '') {
  10807. var contents = '';
  10808. // Special-case text clippings, which have an empty type but include
  10809. // `.textClipping` in the file name. `readAsText` results in an empty
  10810. // string for text clippings, so we force the file name to serve
  10811. // as the text value for the file.
  10812. if (TEXT_CLIPPING_REGEX.test(file.name)) {
  10813. contents = file.name.replace(TEXT_CLIPPING_REGEX, '');
  10814. }
  10815. callback(contents);
  10816. return;
  10817. }
  10818. var reader = new FileReader();
  10819. reader.onload = function () {
  10820. var result = reader.result;
  10821. !(typeof result === 'string') ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'We should be calling "FileReader.readAsText" which returns a string') : invariant_1(false) : void 0;
  10822. callback(result);
  10823. };
  10824. reader.onerror = function () {
  10825. callback('');
  10826. };
  10827. reader.readAsText(file);
  10828. }
  10829. var getTextContentFromFiles_1 = getTextContentFromFiles;
  10830. function getUpdatedSelectionState(editorState, anchorKey, anchorOffset, focusKey, focusOffset) {
  10831. var selection = nullthrows_1(editorState.getSelection());
  10832. if (process.env.NODE_ENV !== 'production') {
  10833. if (!anchorKey || !focusKey) {
  10834. /*eslint-disable no-console */
  10835. console.warn('Invalid selection state.', arguments, editorState.toJS());
  10836. /*eslint-enable no-console */
  10837. return selection;
  10838. }
  10839. }
  10840. var anchorPath = DraftOffsetKey_1.decode(anchorKey);
  10841. var anchorBlockKey = anchorPath.blockKey;
  10842. var anchorLeaf = editorState.getBlockTree(anchorBlockKey).getIn([anchorPath.decoratorKey, 'leaves', anchorPath.leafKey]);
  10843. var focusPath = DraftOffsetKey_1.decode(focusKey);
  10844. var focusBlockKey = focusPath.blockKey;
  10845. var focusLeaf = editorState.getBlockTree(focusBlockKey).getIn([focusPath.decoratorKey, 'leaves', focusPath.leafKey]);
  10846. var anchorLeafStart = anchorLeaf.get('start');
  10847. var focusLeafStart = focusLeaf.get('start');
  10848. var anchorBlockOffset = anchorLeaf ? anchorLeafStart + anchorOffset : null;
  10849. var focusBlockOffset = focusLeaf ? focusLeafStart + focusOffset : null;
  10850. var areEqual = selection.getAnchorKey() === anchorBlockKey && selection.getAnchorOffset() === anchorBlockOffset && selection.getFocusKey() === focusBlockKey && selection.getFocusOffset() === focusBlockOffset;
  10851. if (areEqual) {
  10852. return selection;
  10853. }
  10854. var isBackward = false;
  10855. if (anchorBlockKey === focusBlockKey) {
  10856. var anchorLeafEnd = anchorLeaf.get('end');
  10857. var focusLeafEnd = focusLeaf.get('end');
  10858. if (focusLeafStart === anchorLeafStart && focusLeafEnd === anchorLeafEnd) {
  10859. isBackward = focusOffset < anchorOffset;
  10860. } else {
  10861. isBackward = focusLeafStart < anchorLeafStart;
  10862. }
  10863. } else {
  10864. var startKey = editorState.getCurrentContent().getBlockMap().keySeq().skipUntil(function (v) {
  10865. return v === anchorBlockKey || v === focusBlockKey;
  10866. }).first();
  10867. isBackward = startKey === focusBlockKey;
  10868. }
  10869. return selection.merge({
  10870. anchorKey: anchorBlockKey,
  10871. anchorOffset: anchorBlockOffset,
  10872. focusKey: focusBlockKey,
  10873. focusOffset: focusBlockOffset,
  10874. isBackward: isBackward
  10875. });
  10876. }
  10877. var getUpdatedSelectionState_1 = getUpdatedSelectionState;
  10878. /**
  10879. * Get a SelectionState for the supplied mouse event.
  10880. */
  10881. function getSelectionForEvent(event, editorState) {
  10882. var node = null;
  10883. var offset = null;
  10884. if (typeof document.caretRangeFromPoint === 'function') {
  10885. var dropRange = document.caretRangeFromPoint(event.x, event.y);
  10886. node = dropRange.startContainer;
  10887. offset = dropRange.startOffset;
  10888. } else if (event.rangeParent) {
  10889. node = event.rangeParent;
  10890. offset = event.rangeOffset;
  10891. } else {
  10892. return null;
  10893. }
  10894. node = nullthrows_1(node);
  10895. offset = nullthrows_1(offset);
  10896. var offsetKey = nullthrows_1(findAncestorOffsetKey_1(node));
  10897. return getUpdatedSelectionState_1(editorState, offsetKey, offset, offsetKey, offset);
  10898. }
  10899. var DraftEditorDragHandler = {
  10900. /**
  10901. * Drag originating from input terminated.
  10902. */
  10903. onDragEnd: function onDragEnd(editor) {
  10904. editor.exitCurrentMode();
  10905. },
  10906. /**
  10907. * Handle data being dropped.
  10908. */
  10909. onDrop: function onDrop(editor, e) {
  10910. var data = new DataTransfer_1(e.nativeEvent.dataTransfer);
  10911. var editorState = editor._latestEditorState;
  10912. var dropSelection = getSelectionForEvent(e.nativeEvent, editorState);
  10913. e.preventDefault();
  10914. editor.exitCurrentMode();
  10915. if (dropSelection == null) {
  10916. return;
  10917. }
  10918. var files = data.getFiles();
  10919. if (files.length > 0) {
  10920. if (editor.props.handleDroppedFiles && isEventHandled_1(editor.props.handleDroppedFiles(dropSelection, files))) {
  10921. return;
  10922. }
  10923. getTextContentFromFiles_1(files, function (fileText) {
  10924. fileText && editor.update(insertTextAtSelection(editorState, dropSelection, fileText));
  10925. });
  10926. return;
  10927. }
  10928. var dragType = editor._internalDrag ? 'internal' : 'external';
  10929. if (editor.props.handleDrop && isEventHandled_1(editor.props.handleDrop(dropSelection, data, dragType))) {
  10930. return;
  10931. }
  10932. if (editor._internalDrag) {
  10933. editor.update(moveText(editorState, dropSelection));
  10934. return;
  10935. }
  10936. editor.update(insertTextAtSelection(editorState, dropSelection, data.getText()));
  10937. }
  10938. };
  10939. function moveText(editorState, targetSelection) {
  10940. var newContentState = DraftModifier_1.moveText(editorState.getCurrentContent(), editorState.getSelection(), targetSelection);
  10941. return EditorState_1.push(editorState, newContentState, 'insert-fragment');
  10942. }
  10943. /**
  10944. * Insert text at a specified selection.
  10945. */
  10946. function insertTextAtSelection(editorState, selection, text) {
  10947. var newContentState = DraftModifier_1.insertText(editorState.getCurrentContent(), selection, text, editorState.getCurrentInlineStyle());
  10948. return EditorState_1.push(editorState, newContentState, 'insert-fragment');
  10949. }
  10950. var DraftEditorDragHandler_1 = DraftEditorDragHandler;
  10951. (function (global, undefined$1) {
  10952. if (global.setImmediate) {
  10953. return;
  10954. }
  10955. var nextHandle = 1; // Spec says greater than zero
  10956. var tasksByHandle = {};
  10957. var currentlyRunningATask = false;
  10958. var doc = global.document;
  10959. var registerImmediate;
  10960. function setImmediate(callback) {
  10961. // Callback can either be a function or a string
  10962. if (typeof callback !== "function") {
  10963. callback = new Function("" + callback);
  10964. }
  10965. // Copy function arguments
  10966. var args = new Array(arguments.length - 1);
  10967. for (var i = 0; i < args.length; i++) {
  10968. args[i] = arguments[i + 1];
  10969. }
  10970. // Store and register the task
  10971. var task = { callback: callback, args: args };
  10972. tasksByHandle[nextHandle] = task;
  10973. registerImmediate(nextHandle);
  10974. return nextHandle++;
  10975. }
  10976. function clearImmediate(handle) {
  10977. delete tasksByHandle[handle];
  10978. }
  10979. function run(task) {
  10980. var callback = task.callback;
  10981. var args = task.args;
  10982. switch (args.length) {
  10983. case 0:
  10984. callback();
  10985. break;
  10986. case 1:
  10987. callback(args[0]);
  10988. break;
  10989. case 2:
  10990. callback(args[0], args[1]);
  10991. break;
  10992. case 3:
  10993. callback(args[0], args[1], args[2]);
  10994. break;
  10995. default:
  10996. callback.apply(undefined$1, args);
  10997. break;
  10998. }
  10999. }
  11000. function runIfPresent(handle) {
  11001. // From the spec: "Wait until any invocations of this algorithm started before this one have completed."
  11002. // So if we're currently running a task, we'll need to delay this invocation.
  11003. if (currentlyRunningATask) {
  11004. // Delay by doing a setTimeout. setImmediate was tried instead, but in Firefox 7 it generated a
  11005. // "too much recursion" error.
  11006. setTimeout(runIfPresent, 0, handle);
  11007. } else {
  11008. var task = tasksByHandle[handle];
  11009. if (task) {
  11010. currentlyRunningATask = true;
  11011. try {
  11012. run(task);
  11013. } finally {
  11014. clearImmediate(handle);
  11015. currentlyRunningATask = false;
  11016. }
  11017. }
  11018. }
  11019. }
  11020. function installNextTickImplementation() {
  11021. registerImmediate = function(handle) {
  11022. process.nextTick(function () { runIfPresent(handle); });
  11023. };
  11024. }
  11025. function canUsePostMessage() {
  11026. // The test against `importScripts` prevents this implementation from being installed inside a web worker,
  11027. // where `global.postMessage` means something completely different and can't be used for this purpose.
  11028. if (global.postMessage && !global.importScripts) {
  11029. var postMessageIsAsynchronous = true;
  11030. var oldOnMessage = global.onmessage;
  11031. global.onmessage = function() {
  11032. postMessageIsAsynchronous = false;
  11033. };
  11034. global.postMessage("", "*");
  11035. global.onmessage = oldOnMessage;
  11036. return postMessageIsAsynchronous;
  11037. }
  11038. }
  11039. function installPostMessageImplementation() {
  11040. // Installs an event handler on `global` for the `message` event: see
  11041. // * https://developer.mozilla.org/en/DOM/window.postMessage
  11042. // * http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html#crossDocumentMessages
  11043. var messagePrefix = "setImmediate$" + Math.random() + "$";
  11044. var onGlobalMessage = function(event) {
  11045. if (event.source === global &&
  11046. typeof event.data === "string" &&
  11047. event.data.indexOf(messagePrefix) === 0) {
  11048. runIfPresent(+event.data.slice(messagePrefix.length));
  11049. }
  11050. };
  11051. if (global.addEventListener) {
  11052. global.addEventListener("message", onGlobalMessage, false);
  11053. } else {
  11054. global.attachEvent("onmessage", onGlobalMessage);
  11055. }
  11056. registerImmediate = function(handle) {
  11057. global.postMessage(messagePrefix + handle, "*");
  11058. };
  11059. }
  11060. function installMessageChannelImplementation() {
  11061. var channel = new MessageChannel();
  11062. channel.port1.onmessage = function(event) {
  11063. var handle = event.data;
  11064. runIfPresent(handle);
  11065. };
  11066. registerImmediate = function(handle) {
  11067. channel.port2.postMessage(handle);
  11068. };
  11069. }
  11070. function installReadyStateChangeImplementation() {
  11071. var html = doc.documentElement;
  11072. registerImmediate = function(handle) {
  11073. // Create a <script> element; its readystatechange event will be fired asynchronously once it is inserted
  11074. // into the document. Do so, thus queuing up the task. Remember to clean up once it's been called.
  11075. var script = doc.createElement("script");
  11076. script.onreadystatechange = function () {
  11077. runIfPresent(handle);
  11078. script.onreadystatechange = null;
  11079. html.removeChild(script);
  11080. script = null;
  11081. };
  11082. html.appendChild(script);
  11083. };
  11084. }
  11085. function installSetTimeoutImplementation() {
  11086. registerImmediate = function(handle) {
  11087. setTimeout(runIfPresent, 0, handle);
  11088. };
  11089. }
  11090. // If supported, we should attach to the prototype of global, since that is where setTimeout et al. live.
  11091. var attachTo = Object.getPrototypeOf && Object.getPrototypeOf(global);
  11092. attachTo = attachTo && attachTo.setTimeout ? attachTo : global;
  11093. // Don't get fooled by e.g. browserify environments.
  11094. if ({}.toString.call(global.process) === "[object process]") {
  11095. // For Node.js before 0.9
  11096. installNextTickImplementation();
  11097. } else if (canUsePostMessage()) {
  11098. // For non-IE10 modern browsers
  11099. installPostMessageImplementation();
  11100. } else if (global.MessageChannel) {
  11101. // For web workers, where supported
  11102. installMessageChannelImplementation();
  11103. } else if (doc && "onreadystatechange" in doc.createElement("script")) {
  11104. // For IE 6–8
  11105. installReadyStateChangeImplementation();
  11106. } else {
  11107. // For older browsers
  11108. installSetTimeoutImplementation();
  11109. }
  11110. attachTo.setImmediate = setImmediate;
  11111. attachTo.clearImmediate = clearImmediate;
  11112. }(typeof self === "undefined" ? typeof _commonjsHelpers.commonjsGlobal === "undefined" ? _commonjsHelpers.commonjsGlobal : _commonjsHelpers.commonjsGlobal : self));
  11113. // setimmediate adds setImmediate to the global. We want to make sure we export
  11114. // the actual function.
  11115. var setImmediate = _commonjsHelpers.commonjsGlobal.setImmediate;
  11116. // When nothing is focused, Firefox regards two characters, `'` and `/`, as
  11117. // commands that should open and focus the "quickfind" search bar. This should
  11118. // *never* happen while a contenteditable is focused, but as of v28, it
  11119. // sometimes does, even when the keypress event target is the contenteditable.
  11120. // This breaks the input. Special case these characters to ensure that when
  11121. // they are typed, we prevent default on the event to make sure not to
  11122. // trigger quickfind.
  11123. var FF_QUICKFIND_CHAR = "'";
  11124. var FF_QUICKFIND_LINK_CHAR = '/';
  11125. var isFirefox = UserAgent_1.isBrowser('Firefox');
  11126. function mustPreventDefaultForCharacter(character) {
  11127. return isFirefox && (character == FF_QUICKFIND_CHAR || character == FF_QUICKFIND_LINK_CHAR);
  11128. }
  11129. /**
  11130. * Replace the current selection with the specified text string, with the
  11131. * inline style and entity key applied to the newly inserted text.
  11132. */
  11133. function replaceText(editorState, text, inlineStyle, entityKey) {
  11134. var contentState = DraftModifier_1.replaceText(editorState.getCurrentContent(), editorState.getSelection(), text, inlineStyle, entityKey);
  11135. return EditorState_1.push(editorState, contentState, 'insert-characters');
  11136. }
  11137. /**
  11138. * When `onBeforeInput` executes, the browser is attempting to insert a
  11139. * character into the editor. Apply this character data to the document,
  11140. * allowing native insertion if possible.
  11141. *
  11142. * Native insertion is encouraged in order to limit re-rendering and to
  11143. * preserve spellcheck highlighting, which disappears or flashes if re-render
  11144. * occurs on the relevant text nodes.
  11145. */
  11146. function editOnBeforeInput(editor, e) {
  11147. if (editor._pendingStateFromBeforeInput !== undefined) {
  11148. editor.update(editor._pendingStateFromBeforeInput);
  11149. editor._pendingStateFromBeforeInput = undefined;
  11150. }
  11151. var editorState = editor._latestEditorState;
  11152. var chars = e.data;
  11153. // In some cases (ex: IE ideographic space insertion) no character data
  11154. // is provided. There's nothing to do when this happens.
  11155. if (!chars) {
  11156. return;
  11157. }
  11158. // Allow the top-level component to handle the insertion manually. This is
  11159. // useful when triggering interesting behaviors for a character insertion,
  11160. // Simple examples: replacing a raw text ':)' with a smile emoji or image
  11161. // decorator, or setting a block to be a list item after typing '- ' at the
  11162. // start of the block.
  11163. if (editor.props.handleBeforeInput && isEventHandled_1(editor.props.handleBeforeInput(chars, editorState))) {
  11164. e.preventDefault();
  11165. return;
  11166. }
  11167. // If selection is collapsed, conditionally allow native behavior. This
  11168. // reduces re-renders and preserves spellcheck highlighting. If the selection
  11169. // is not collapsed, we will re-render.
  11170. var selection = editorState.getSelection();
  11171. var selectionStart = selection.getStartOffset();
  11172. var selectionEnd = selection.getEndOffset();
  11173. var anchorKey = selection.getAnchorKey();
  11174. if (!selection.isCollapsed()) {
  11175. e.preventDefault();
  11176. // If the currently selected text matches what the user is trying to
  11177. // replace it with, let's just update the `SelectionState`. If not, update
  11178. // the `ContentState` with the new text.
  11179. var currentlySelectedChars = editorState.getCurrentContent().getPlainText().slice(selectionStart, selectionEnd);
  11180. if (chars === currentlySelectedChars) {
  11181. editor.update(EditorState_1.forceSelection(editorState, selection.merge({
  11182. focusOffset: selectionEnd
  11183. })));
  11184. } else {
  11185. editor.update(replaceText(editorState, chars, editorState.getCurrentInlineStyle(), getEntityKeyForSelection_1(editorState.getCurrentContent(), editorState.getSelection())));
  11186. }
  11187. return;
  11188. }
  11189. var newEditorState = replaceText(editorState, chars, editorState.getCurrentInlineStyle(), getEntityKeyForSelection_1(editorState.getCurrentContent(), editorState.getSelection()));
  11190. // Bunch of different cases follow where we need to prevent native insertion.
  11191. var mustPreventNative = false;
  11192. if (!mustPreventNative) {
  11193. // Browsers tend to insert text in weird places in the DOM when typing at
  11194. // the start of a leaf, so we'll handle it ourselves.
  11195. mustPreventNative = isSelectionAtLeafStart_1(editor._latestCommittedEditorState);
  11196. }
  11197. if (!mustPreventNative) {
  11198. // Chrome will also split up a node into two pieces if it contains a Tab
  11199. // char, for no explicable reason. Seemingly caused by this commit:
  11200. // https://chromium.googlesource.com/chromium/src/+/013ac5eaf3%5E%21/
  11201. var nativeSelection = _commonjsHelpers.commonjsGlobal.getSelection();
  11202. // Selection is necessarily collapsed at this point due to earlier check.
  11203. if (nativeSelection.anchorNode && nativeSelection.anchorNode.nodeType === Node.TEXT_NODE) {
  11204. // See isTabHTMLSpanElement in chromium EditingUtilities.cpp.
  11205. var parentNode = nativeSelection.anchorNode.parentNode;
  11206. mustPreventNative = parentNode.nodeName === 'SPAN' && parentNode.firstChild.nodeType === Node.TEXT_NODE && parentNode.firstChild.nodeValue.indexOf('\t') !== -1;
  11207. }
  11208. }
  11209. if (!mustPreventNative) {
  11210. // Check the old and new "fingerprints" of the current block to determine
  11211. // whether this insertion requires any addition or removal of text nodes,
  11212. // in which case we would prevent the native character insertion.
  11213. var originalFingerprint = BlockTree_1.getFingerprint(editorState.getBlockTree(anchorKey));
  11214. var newFingerprint = BlockTree_1.getFingerprint(newEditorState.getBlockTree(anchorKey));
  11215. mustPreventNative = originalFingerprint !== newFingerprint;
  11216. }
  11217. if (!mustPreventNative) {
  11218. mustPreventNative = mustPreventDefaultForCharacter(chars);
  11219. }
  11220. if (!mustPreventNative) {
  11221. mustPreventNative = nullthrows_1(newEditorState.getDirectionMap()).get(anchorKey) !== nullthrows_1(editorState.getDirectionMap()).get(anchorKey);
  11222. }
  11223. if (mustPreventNative) {
  11224. e.preventDefault();
  11225. editor.update(newEditorState);
  11226. return;
  11227. }
  11228. // We made it all the way! Let the browser do its thing and insert the char.
  11229. newEditorState = EditorState_1.set(newEditorState, {
  11230. nativelyRenderedContent: newEditorState.getCurrentContent()
  11231. });
  11232. // The native event is allowed to occur. To allow user onChange handlers to
  11233. // change the inserted text, we wait until the text is actually inserted
  11234. // before we actually update our state. That way when we rerender, the text
  11235. // we see in the DOM will already have been inserted properly.
  11236. editor._pendingStateFromBeforeInput = newEditorState;
  11237. setImmediate(function () {
  11238. if (editor._pendingStateFromBeforeInput !== undefined) {
  11239. editor.update(editor._pendingStateFromBeforeInput);
  11240. editor._pendingStateFromBeforeInput = undefined;
  11241. }
  11242. });
  11243. }
  11244. var editOnBeforeInput_1 = editOnBeforeInput;
  11245. function editOnBlur(editor, e) {
  11246. // In a contentEditable element, when you select a range and then click
  11247. // another active element, this does trigger a `blur` event but will not
  11248. // remove the DOM selection from the contenteditable.
  11249. // This is consistent across all browsers, but we prefer that the editor
  11250. // behave like a textarea, where a `blur` event clears the DOM selection.
  11251. // We therefore force the issue to be certain, checking whether the active
  11252. // element is `body` to force it when blurring occurs within the window (as
  11253. // opposed to clicking to another tab or window).
  11254. if (getActiveElement_1() === document.body) {
  11255. var _selection = _commonjsHelpers.commonjsGlobal.getSelection();
  11256. var editorNode = editor.editor;
  11257. if (_selection.rangeCount === 1 && containsNode_1(editorNode, _selection.anchorNode) && containsNode_1(editorNode, _selection.focusNode)) {
  11258. _selection.removeAllRanges();
  11259. }
  11260. }
  11261. var editorState = editor._latestEditorState;
  11262. var currentSelection = editorState.getSelection();
  11263. if (!currentSelection.getHasFocus()) {
  11264. return;
  11265. }
  11266. var selection = currentSelection.set('hasFocus', false);
  11267. editor.props.onBlur && editor.props.onBlur(e);
  11268. editor.update(EditorState_1.acceptSelection(editorState, selection));
  11269. }
  11270. var editOnBlur_1 = editOnBlur;
  11271. /**
  11272. * The user has begun using an IME input system. Switching to `composite` mode
  11273. * allows handling composition input and disables other edit behavior.
  11274. */
  11275. function editOnCompositionStart(editor, e) {
  11276. editor.setMode('composite');
  11277. editor.update(EditorState_1.set(editor._latestEditorState, { inCompositionMode: true }));
  11278. // Allow composition handler to interpret the compositionstart event
  11279. editor._onCompositionStart(e);
  11280. }
  11281. var editOnCompositionStart_1 = editOnCompositionStart;
  11282. function getFragmentFromSelection(editorState) {
  11283. var selectionState = editorState.getSelection();
  11284. if (selectionState.isCollapsed()) {
  11285. return null;
  11286. }
  11287. return getContentStateFragment_1(editorState.getCurrentContent(), selectionState);
  11288. }
  11289. var getFragmentFromSelection_1 = getFragmentFromSelection;
  11290. /**
  11291. * If we have a selection, create a ContentState fragment and store
  11292. * it in our internal clipboard. Subsequent paste events will use this
  11293. * fragment if no external clipboard data is supplied.
  11294. */
  11295. function editOnCopy(editor, e) {
  11296. var editorState = editor._latestEditorState;
  11297. var selection = editorState.getSelection();
  11298. // No selection, so there's nothing to copy.
  11299. if (selection.isCollapsed()) {
  11300. e.preventDefault();
  11301. return;
  11302. }
  11303. editor.setClipboard(getFragmentFromSelection_1(editor._latestEditorState));
  11304. }
  11305. var editOnCopy_1 = editOnCopy;
  11306. /**
  11307. * On `cut` events, native behavior is allowed to occur so that the system
  11308. * clipboard is set properly. This means that we need to take steps to recover
  11309. * the editor DOM state after the `cut` has occurred in order to maintain
  11310. * control of the component.
  11311. *
  11312. * In addition, we can keep a copy of the removed fragment, including all
  11313. * styles and entities, for use as an internal paste.
  11314. */
  11315. function editOnCut(editor, e) {
  11316. var editorState = editor._latestEditorState;
  11317. var selection = editorState.getSelection();
  11318. var element = e.target;
  11319. var scrollPosition = void 0;
  11320. // No selection, so there's nothing to cut.
  11321. if (selection.isCollapsed()) {
  11322. e.preventDefault();
  11323. return;
  11324. }
  11325. // Track the current scroll position so that it can be forced back in place
  11326. // after the editor regains control of the DOM.
  11327. if (element instanceof Node) {
  11328. scrollPosition = getScrollPosition_1(Style_1.getScrollParent(element));
  11329. }
  11330. var fragment = getFragmentFromSelection_1(editorState);
  11331. editor.setClipboard(fragment);
  11332. // Set `cut` mode to disable all event handling temporarily.
  11333. editor.setMode('cut');
  11334. // Let native `cut` behavior occur, then recover control.
  11335. setTimeout(function () {
  11336. editor.restoreEditorDOM(scrollPosition);
  11337. editor.exitCurrentMode();
  11338. editor.update(removeFragment(editorState));
  11339. }, 0);
  11340. }
  11341. function removeFragment(editorState) {
  11342. var newContent = DraftModifier_1.removeRange(editorState.getCurrentContent(), editorState.getSelection(), 'forward');
  11343. return EditorState_1.push(editorState, newContent, 'remove-range');
  11344. }
  11345. var editOnCut_1 = editOnCut;
  11346. /**
  11347. * Copyright (c) 2013-present, Facebook, Inc.
  11348. * All rights reserved.
  11349. *
  11350. * This source code is licensed under the BSD-style license found in the
  11351. * LICENSE file in the root directory of this source tree. An additional grant
  11352. * of patent rights can be found in the PATENTS file in the same directory.
  11353. *
  11354. * @providesModule editOnDragOver
  11355. * @format
  11356. *
  11357. */
  11358. /**
  11359. * Drag behavior has begun from outside the editor element.
  11360. */
  11361. function editOnDragOver(editor, e) {
  11362. editor._internalDrag = false;
  11363. editor.setMode('drag');
  11364. e.preventDefault();
  11365. }
  11366. var editOnDragOver_1 = editOnDragOver;
  11367. /**
  11368. * Copyright (c) 2013-present, Facebook, Inc.
  11369. * All rights reserved.
  11370. *
  11371. * This source code is licensed under the BSD-style license found in the
  11372. * LICENSE file in the root directory of this source tree. An additional grant
  11373. * of patent rights can be found in the PATENTS file in the same directory.
  11374. *
  11375. * @providesModule editOnDragStart
  11376. * @format
  11377. *
  11378. */
  11379. /**
  11380. * A `dragstart` event has begun within the text editor component.
  11381. */
  11382. function editOnDragStart(editor) {
  11383. editor._internalDrag = true;
  11384. editor.setMode('drag');
  11385. }
  11386. var editOnDragStart_1 = editOnDragStart;
  11387. function editOnFocus(editor, e) {
  11388. var editorState = editor._latestEditorState;
  11389. var currentSelection = editorState.getSelection();
  11390. if (currentSelection.getHasFocus()) {
  11391. return;
  11392. }
  11393. var selection = currentSelection.set('hasFocus', true);
  11394. editor.props.onFocus && editor.props.onFocus(e);
  11395. // When the tab containing this text editor is hidden and the user does a
  11396. // find-in-page in a _different_ tab, Chrome on Mac likes to forget what the
  11397. // selection was right after sending this focus event and (if you let it)
  11398. // moves the cursor back to the beginning of the editor, so we force the
  11399. // selection here instead of simply accepting it in order to preserve the
  11400. // old cursor position. See https://crbug.com/540004.
  11401. // But it looks like this is fixed in Chrome 60.0.3081.0.
  11402. // Other browsers also don't have this bug, so we prefer to acceptSelection
  11403. // when possible, to ensure that unfocusing and refocusing a Draft editor
  11404. // doesn't preserve the selection, matching how textareas work.
  11405. if (UserAgent_1.isBrowser('Chrome < 60.0.3081.0')) {
  11406. editor.update(EditorState_1.forceSelection(editorState, selection));
  11407. } else {
  11408. editor.update(EditorState_1.acceptSelection(editorState, selection));
  11409. }
  11410. }
  11411. var editOnFocus_1 = editOnFocus;
  11412. var isGecko = UserAgent_1.isEngine('Gecko');
  11413. var DOUBLE_NEWLINE = '\n\n';
  11414. /**
  11415. * This function is intended to handle spellcheck and autocorrect changes,
  11416. * which occur in the DOM natively without any opportunity to observe or
  11417. * interpret the changes before they occur.
  11418. *
  11419. * The `input` event fires in contentEditable elements reliably for non-IE
  11420. * browsers, immediately after changes occur to the editor DOM. Since our other
  11421. * handlers override or otherwise handle cover other varieties of text input,
  11422. * the DOM state should match the model in all controlled input cases. Thus,
  11423. * when an `input` change leads to a DOM/model mismatch, the change should be
  11424. * due to a spellcheck change, and we can incorporate it into our model.
  11425. */
  11426. function editOnInput(editor) {
  11427. if (editor._pendingStateFromBeforeInput !== undefined) {
  11428. editor.update(editor._pendingStateFromBeforeInput);
  11429. editor._pendingStateFromBeforeInput = undefined;
  11430. }
  11431. var domSelection = _commonjsHelpers.commonjsGlobal.getSelection();
  11432. var anchorNode = domSelection.anchorNode,
  11433. isCollapsed = domSelection.isCollapsed;
  11434. var isNotTextNode = anchorNode.nodeType !== Node.TEXT_NODE;
  11435. var isNotTextOrElementNode = anchorNode.nodeType !== Node.TEXT_NODE && anchorNode.nodeType !== Node.ELEMENT_NODE;
  11436. {
  11437. if (isNotTextOrElementNode) {
  11438. // TODO: (t16149272) figure out context for this change
  11439. return;
  11440. }
  11441. }
  11442. if (anchorNode.nodeType === Node.TEXT_NODE && (anchorNode.previousSibling !== null || anchorNode.nextSibling !== null)) {
  11443. // When typing at the beginning of a visual line, Chrome splits the text
  11444. // nodes into two. Why? No one knows. This commit is suspicious:
  11445. // https://chromium.googlesource.com/chromium/src/+/a3b600981286b135632371477f902214c55a1724
  11446. // To work around, we'll merge the sibling text nodes back into this one.
  11447. var span = anchorNode.parentNode;
  11448. anchorNode.nodeValue = span.textContent;
  11449. for (var child = span.firstChild; child !== null; child = child.nextSibling) {
  11450. if (child !== anchorNode) {
  11451. span.removeChild(child);
  11452. }
  11453. }
  11454. }
  11455. var domText = anchorNode.textContent;
  11456. var editorState = editor._latestEditorState;
  11457. var offsetKey = nullthrows_1(findAncestorOffsetKey_1(anchorNode));
  11458. var _DraftOffsetKey$decod = DraftOffsetKey_1.decode(offsetKey),
  11459. blockKey = _DraftOffsetKey$decod.blockKey,
  11460. decoratorKey = _DraftOffsetKey$decod.decoratorKey,
  11461. leafKey = _DraftOffsetKey$decod.leafKey;
  11462. var _editorState$getBlock = editorState.getBlockTree(blockKey).getIn([decoratorKey, 'leaves', leafKey]),
  11463. start = _editorState$getBlock.start,
  11464. end = _editorState$getBlock.end;
  11465. var content = editorState.getCurrentContent();
  11466. var block = content.getBlockForKey(blockKey);
  11467. var modelText = block.getText().slice(start, end);
  11468. // Special-case soft newlines here. If the DOM text ends in a soft newline,
  11469. // we will have manually inserted an extra soft newline in DraftEditorLeaf.
  11470. // We want to remove this extra newline for the purpose of our comparison
  11471. // of DOM and model text.
  11472. if (domText.endsWith(DOUBLE_NEWLINE)) {
  11473. domText = domText.slice(0, -1);
  11474. }
  11475. // No change -- the DOM is up to date. Nothing to do here.
  11476. if (domText === modelText) {
  11477. // This can be buggy for some Android keyboards because they don't fire
  11478. // standard onkeydown/pressed events and only fired editOnInput
  11479. // so domText is already changed by the browser and ends up being equal
  11480. // to modelText unexpectedly
  11481. return;
  11482. }
  11483. var selection = editorState.getSelection();
  11484. // We'll replace the entire leaf with the text content of the target.
  11485. var targetRange = selection.merge({
  11486. anchorOffset: start,
  11487. focusOffset: end,
  11488. isBackward: false
  11489. });
  11490. var entityKey = block.getEntityAt(start);
  11491. var entity = entityKey && content.getEntity(entityKey);
  11492. var entityType = entity && entity.getMutability();
  11493. var preserveEntity = entityType === 'MUTABLE';
  11494. // Immutable or segmented entities cannot properly be handled by the
  11495. // default browser undo, so we have to use a different change type to
  11496. // force using our internal undo method instead of falling through to the
  11497. // native browser undo.
  11498. var changeType = preserveEntity ? 'spellcheck-change' : 'apply-entity';
  11499. var newContent = DraftModifier_1.replaceText(content, targetRange, domText, block.getInlineStyleAt(start), preserveEntity ? block.getEntityAt(start) : null);
  11500. var anchorOffset, focusOffset, startOffset, endOffset;
  11501. if (isGecko) {
  11502. // Firefox selection does not change while the context menu is open, so
  11503. // we preserve the anchor and focus values of the DOM selection.
  11504. anchorOffset = domSelection.anchorOffset;
  11505. focusOffset = domSelection.focusOffset;
  11506. startOffset = start + Math.min(anchorOffset, focusOffset);
  11507. endOffset = startOffset + Math.abs(anchorOffset - focusOffset);
  11508. anchorOffset = startOffset;
  11509. focusOffset = endOffset;
  11510. } else {
  11511. // Browsers other than Firefox may adjust DOM selection while the context
  11512. // menu is open, and Safari autocorrect is prone to providing an inaccurate
  11513. // DOM selection. Don't trust it. Instead, use our existing SelectionState
  11514. // and adjust it based on the number of characters changed during the
  11515. // mutation.
  11516. var charDelta = domText.length - modelText.length;
  11517. startOffset = selection.getStartOffset();
  11518. endOffset = selection.getEndOffset();
  11519. anchorOffset = isCollapsed ? endOffset + charDelta : startOffset;
  11520. focusOffset = endOffset + charDelta;
  11521. }
  11522. // Segmented entities are completely or partially removed when their
  11523. // text content changes. For this case we do not want any text to be selected
  11524. // after the change, so we are not merging the selection.
  11525. var contentWithAdjustedDOMSelection = newContent.merge({
  11526. selectionBefore: content.getSelectionAfter(),
  11527. selectionAfter: selection.merge({ anchorOffset: anchorOffset, focusOffset: focusOffset })
  11528. });
  11529. editor.update(EditorState_1.push(editorState, contentWithAdjustedDOMSelection, changeType));
  11530. }
  11531. var editOnInput_1 = editOnInput;
  11532. var isOSX = UserAgent_1.isPlatform('Mac OS X');
  11533. var KeyBindingUtil = {
  11534. /**
  11535. * Check whether the ctrlKey modifier is *not* being used in conjunction with
  11536. * the altKey modifier. If they are combined, the result is an `altGraph`
  11537. * key modifier, which should not be handled by this set of key bindings.
  11538. */
  11539. isCtrlKeyCommand: function isCtrlKeyCommand(e) {
  11540. return !!e.ctrlKey && !e.altKey;
  11541. },
  11542. isOptionKeyCommand: function isOptionKeyCommand(e) {
  11543. return isOSX && e.altKey;
  11544. },
  11545. hasCommandModifier: function hasCommandModifier(e) {
  11546. return isOSX ? !!e.metaKey && !e.altKey : KeyBindingUtil.isCtrlKeyCommand(e);
  11547. }
  11548. };
  11549. var KeyBindingUtil_1 = KeyBindingUtil;
  11550. var clipboard = null;
  11551. /**
  11552. * Some systems offer a "secondary" clipboard to allow quick internal cut
  11553. * and paste behavior. For instance, Ctrl+K (cut) and Ctrl+Y (paste).
  11554. */
  11555. var SecondaryClipboard = {
  11556. cut: function cut(editorState) {
  11557. var content = editorState.getCurrentContent();
  11558. var selection = editorState.getSelection();
  11559. var targetRange = null;
  11560. if (selection.isCollapsed()) {
  11561. var anchorKey = selection.getAnchorKey();
  11562. var blockEnd = content.getBlockForKey(anchorKey).getLength();
  11563. if (blockEnd === selection.getAnchorOffset()) {
  11564. return editorState;
  11565. }
  11566. targetRange = selection.set('focusOffset', blockEnd);
  11567. } else {
  11568. targetRange = selection;
  11569. }
  11570. targetRange = nullthrows_1(targetRange);
  11571. clipboard = getContentStateFragment_1(content, targetRange);
  11572. var afterRemoval = DraftModifier_1.removeRange(content, targetRange, 'forward');
  11573. if (afterRemoval === content) {
  11574. return editorState;
  11575. }
  11576. return EditorState_1.push(editorState, afterRemoval, 'remove-range');
  11577. },
  11578. paste: function paste(editorState) {
  11579. if (!clipboard) {
  11580. return editorState;
  11581. }
  11582. var newContent = DraftModifier_1.replaceWithFragment(editorState.getCurrentContent(), editorState.getSelection(), clipboard);
  11583. return EditorState_1.push(editorState, newContent, 'insert-fragment');
  11584. }
  11585. };
  11586. var SecondaryClipboard_1 = SecondaryClipboard;
  11587. // These two ranges are consecutive so anything in [HIGH_START, LOW_END] is a
  11588. // surrogate code unit.
  11589. var SURROGATE_HIGH_START = 0xD800;
  11590. var SURROGATE_HIGH_END = 0xDBFF;
  11591. var SURROGATE_LOW_START = 0xDC00;
  11592. var SURROGATE_LOW_END = 0xDFFF;
  11593. var SURROGATE_UNITS_REGEX = /[\uD800-\uDFFF]/;
  11594. /**
  11595. * @param {number} codeUnit A Unicode code-unit, in range [0, 0x10FFFF]
  11596. * @return {boolean} Whether code-unit is in a surrogate (hi/low) range
  11597. */
  11598. function isCodeUnitInSurrogateRange(codeUnit) {
  11599. return SURROGATE_HIGH_START <= codeUnit && codeUnit <= SURROGATE_LOW_END;
  11600. }
  11601. /**
  11602. * Returns whether the two characters starting at `index` form a surrogate pair.
  11603. * For example, given the string s = "\uD83D\uDE0A", (s, 0) returns true and
  11604. * (s, 1) returns false.
  11605. *
  11606. * @param {string} str
  11607. * @param {number} index
  11608. * @return {boolean}
  11609. */
  11610. function isSurrogatePair(str, index) {
  11611. !(0 <= index && index < str.length) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'isSurrogatePair: Invalid index %s for string length %s.', index, str.length) : invariant_1(false) : void 0;
  11612. if (index + 1 === str.length) {
  11613. return false;
  11614. }
  11615. var first = str.charCodeAt(index);
  11616. var second = str.charCodeAt(index + 1);
  11617. return SURROGATE_HIGH_START <= first && first <= SURROGATE_HIGH_END && SURROGATE_LOW_START <= second && second <= SURROGATE_LOW_END;
  11618. }
  11619. /**
  11620. * @param {string} str Non-empty string
  11621. * @return {boolean} True if the input includes any surrogate code units
  11622. */
  11623. function hasSurrogateUnit(str) {
  11624. return SURROGATE_UNITS_REGEX.test(str);
  11625. }
  11626. /**
  11627. * Return the length of the original Unicode character at given position in the
  11628. * String by looking into the UTF-16 code unit; that is equal to 1 for any
  11629. * non-surrogate characters in BMP ([U+0000..U+D7FF] and [U+E000, U+FFFF]); and
  11630. * returns 2 for the hi/low surrogates ([U+D800..U+DFFF]), which are in fact
  11631. * representing non-BMP characters ([U+10000..U+10FFFF]).
  11632. *
  11633. * Examples:
  11634. * - '\u0020' => 1
  11635. * - '\u3020' => 1
  11636. * - '\uD835' => 2
  11637. * - '\uD835\uDDEF' => 2
  11638. * - '\uDDEF' => 2
  11639. *
  11640. * @param {string} str Non-empty string
  11641. * @param {number} pos Position in the string to look for one code unit
  11642. * @return {number} Number 1 or 2
  11643. */
  11644. function getUTF16Length(str, pos) {
  11645. return 1 + isCodeUnitInSurrogateRange(str.charCodeAt(pos));
  11646. }
  11647. /**
  11648. * Fully Unicode-enabled replacement for String#length
  11649. *
  11650. * @param {string} str Valid Unicode string
  11651. * @return {number} The number of Unicode characters in the string
  11652. */
  11653. function strlen(str) {
  11654. // Call the native functions if there's no surrogate char
  11655. if (!hasSurrogateUnit(str)) {
  11656. return str.length;
  11657. }
  11658. var len = 0;
  11659. for (var pos = 0; pos < str.length; pos += getUTF16Length(str, pos)) {
  11660. len++;
  11661. }
  11662. return len;
  11663. }
  11664. /**
  11665. * Fully Unicode-enabled replacement for String#substr()
  11666. *
  11667. * @param {string} str Valid Unicode string
  11668. * @param {number} start Location in Unicode sequence to begin extracting
  11669. * @param {?number} length The number of Unicode characters to extract
  11670. * (default: to the end of the string)
  11671. * @return {string} Extracted sub-string
  11672. */
  11673. function substr(str, start, length) {
  11674. start = start || 0;
  11675. length = length === undefined ? Infinity : length || 0;
  11676. // Call the native functions if there's no surrogate char
  11677. if (!hasSurrogateUnit(str)) {
  11678. return str.substr(start, length);
  11679. }
  11680. // Obvious cases
  11681. var size = str.length;
  11682. if (size <= 0 || start > size || length <= 0) {
  11683. return '';
  11684. }
  11685. // Find the actual starting position
  11686. var posA = 0;
  11687. if (start > 0) {
  11688. for (; start > 0 && posA < size; start--) {
  11689. posA += getUTF16Length(str, posA);
  11690. }
  11691. if (posA >= size) {
  11692. return '';
  11693. }
  11694. } else if (start < 0) {
  11695. for (posA = size; start < 0 && 0 < posA; start++) {
  11696. posA -= getUTF16Length(str, posA - 1);
  11697. }
  11698. if (posA < 0) {
  11699. posA = 0;
  11700. }
  11701. }
  11702. // Find the actual ending position
  11703. var posB = size;
  11704. if (length < size) {
  11705. for (posB = posA; length > 0 && posB < size; length--) {
  11706. posB += getUTF16Length(str, posB);
  11707. }
  11708. }
  11709. return str.substring(posA, posB);
  11710. }
  11711. /**
  11712. * Fully Unicode-enabled replacement for String#substring()
  11713. *
  11714. * @param {string} str Valid Unicode string
  11715. * @param {number} start Location in Unicode sequence to begin extracting
  11716. * @param {?number} end Location in Unicode sequence to end extracting
  11717. * (default: end of the string)
  11718. * @return {string} Extracted sub-string
  11719. */
  11720. function substring(str, start, end) {
  11721. start = start || 0;
  11722. end = end === undefined ? Infinity : end || 0;
  11723. if (start < 0) {
  11724. start = 0;
  11725. }
  11726. if (end < 0) {
  11727. end = 0;
  11728. }
  11729. var length = Math.abs(end - start);
  11730. start = start < end ? start : end;
  11731. return substr(str, start, length);
  11732. }
  11733. /**
  11734. * Get a list of Unicode code-points from a String
  11735. *
  11736. * @param {string} str Valid Unicode string
  11737. * @return {array<number>} A list of code-points in [0..0x10FFFF]
  11738. */
  11739. function getCodePoints(str) {
  11740. var codePoints = [];
  11741. for (var pos = 0; pos < str.length; pos += getUTF16Length(str, pos)) {
  11742. codePoints.push(str.codePointAt(pos));
  11743. }
  11744. return codePoints;
  11745. }
  11746. var UnicodeUtils = {
  11747. getCodePoints: getCodePoints,
  11748. getUTF16Length: getUTF16Length,
  11749. hasSurrogateUnit: hasSurrogateUnit,
  11750. isCodeUnitInSurrogateRange: isCodeUnitInSurrogateRange,
  11751. isSurrogatePair: isSurrogatePair,
  11752. strlen: strlen,
  11753. substring: substring,
  11754. substr: substr
  11755. };
  11756. var UnicodeUtils_1 = UnicodeUtils;
  11757. var isChrome = UserAgent_1.isBrowser('Chrome');
  11758. // In Chrome, the client rects will include the entire bounds of all nodes that
  11759. // begin (have a start tag) within the selection, even if the selection does
  11760. // not overlap the entire node. To resolve this, we split the range at each
  11761. // start tag and join the client rects together.
  11762. // https://code.google.com/p/chromium/issues/detail?id=324437
  11763. /* eslint-disable consistent-return */
  11764. function getRangeClientRectsChrome(range) {
  11765. var tempRange = range.cloneRange();
  11766. var clientRects = [];
  11767. for (var ancestor = range.endContainer; ancestor != null; ancestor = ancestor.parentNode) {
  11768. // If we've climbed up to the common ancestor, we can now use the
  11769. // original start point and stop climbing the tree.
  11770. var atCommonAncestor = ancestor === range.commonAncestorContainer;
  11771. if (atCommonAncestor) {
  11772. tempRange.setStart(range.startContainer, range.startOffset);
  11773. } else {
  11774. tempRange.setStart(tempRange.endContainer, 0);
  11775. }
  11776. var rects = Array.from(tempRange.getClientRects());
  11777. clientRects.push(rects);
  11778. if (atCommonAncestor) {
  11779. var _ref;
  11780. clientRects.reverse();
  11781. return (_ref = []).concat.apply(_ref, clientRects);
  11782. }
  11783. tempRange.setEndBefore(ancestor);
  11784. }
  11785. process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Found an unexpected detached subtree when getting range client rects.') : invariant_1(false) ;
  11786. }
  11787. /* eslint-enable consistent-return */
  11788. /**
  11789. * Like range.getClientRects() but normalizes for browser bugs.
  11790. */
  11791. var getRangeClientRects = isChrome ? getRangeClientRectsChrome : function (range) {
  11792. return Array.from(range.getClientRects());
  11793. };
  11794. var getRangeClientRects_1 = getRangeClientRects;
  11795. /**
  11796. * Copyright (c) 2013-present, Facebook, Inc.
  11797. * All rights reserved.
  11798. *
  11799. * This source code is licensed under the BSD-style license found in the
  11800. * LICENSE file in the root directory of this source tree. An additional grant
  11801. * of patent rights can be found in the PATENTS file in the same directory.
  11802. *
  11803. * @providesModule expandRangeToStartOfLine
  11804. * @format
  11805. *
  11806. */
  11807. /**
  11808. * Return the computed line height, in pixels, for the provided element.
  11809. */
  11810. function getLineHeightPx(element) {
  11811. var computed = getComputedStyle(element);
  11812. var div = document.createElement('div');
  11813. div.style.fontFamily = computed.fontFamily;
  11814. div.style.fontSize = computed.fontSize;
  11815. div.style.fontStyle = computed.fontStyle;
  11816. div.style.fontWeight = computed.fontWeight;
  11817. div.style.lineHeight = computed.lineHeight;
  11818. div.style.position = 'absolute';
  11819. div.textContent = 'M';
  11820. var documentBody = document.body;
  11821. !documentBody ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing document.body') : invariant_1(false) : void 0;
  11822. // forced layout here
  11823. documentBody.appendChild(div);
  11824. var rect = div.getBoundingClientRect();
  11825. documentBody.removeChild(div);
  11826. return rect.height;
  11827. }
  11828. /**
  11829. * Return whether every ClientRect in the provided list lies on the same line.
  11830. *
  11831. * We assume that the rects on the same line all contain the baseline, so the
  11832. * lowest top line needs to be above the highest bottom line (i.e., if you were
  11833. * to project the rects onto the y-axis, their intersection would be nonempty).
  11834. *
  11835. * In addition, we require that no two boxes are lineHeight (or more) apart at
  11836. * either top or bottom, which helps protect against false positives for fonts
  11837. * with extremely large glyph heights (e.g., with a font size of 17px, Zapfino
  11838. * produces rects of height 58px!).
  11839. */
  11840. function areRectsOnOneLine(rects, lineHeight) {
  11841. var minTop = Infinity;
  11842. var minBottom = Infinity;
  11843. var maxTop = -Infinity;
  11844. var maxBottom = -Infinity;
  11845. for (var ii = 0; ii < rects.length; ii++) {
  11846. var rect = rects[ii];
  11847. if (rect.width === 0 || rect.width === 1) {
  11848. // When a range starts or ends a soft wrap, many browsers (Chrome, IE,
  11849. // Safari) include an empty rect on the previous or next line. When the
  11850. // text lies in a container whose position is not integral (e.g., from
  11851. // margin: auto), Safari makes these empty rects have width 1 (instead of
  11852. // 0). Having one-pixel-wide characters seems unlikely (and most browsers
  11853. // report widths in subpixel precision anyway) so it's relatively safe to
  11854. // skip over them.
  11855. continue;
  11856. }
  11857. minTop = Math.min(minTop, rect.top);
  11858. minBottom = Math.min(minBottom, rect.bottom);
  11859. maxTop = Math.max(maxTop, rect.top);
  11860. maxBottom = Math.max(maxBottom, rect.bottom);
  11861. }
  11862. return maxTop <= minBottom && maxTop - minTop < lineHeight && maxBottom - minBottom < lineHeight;
  11863. }
  11864. /**
  11865. * Return the length of a node, as used by Range offsets.
  11866. */
  11867. function getNodeLength$1(node) {
  11868. // http://www.w3.org/TR/dom/#concept-node-length
  11869. switch (node.nodeType) {
  11870. case Node.DOCUMENT_TYPE_NODE:
  11871. return 0;
  11872. case Node.TEXT_NODE:
  11873. case Node.PROCESSING_INSTRUCTION_NODE:
  11874. case Node.COMMENT_NODE:
  11875. return node.length;
  11876. default:
  11877. return node.childNodes.length;
  11878. }
  11879. }
  11880. /**
  11881. * Given a collapsed range, move the start position backwards as far as
  11882. * possible while the range still spans only a single line.
  11883. */
  11884. function expandRangeToStartOfLine(range) {
  11885. !range.collapsed ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'expandRangeToStartOfLine: Provided range is not collapsed.') : invariant_1(false) : void 0;
  11886. range = range.cloneRange();
  11887. var containingElement = range.startContainer;
  11888. if (containingElement.nodeType !== 1) {
  11889. containingElement = containingElement.parentNode;
  11890. }
  11891. var lineHeight = getLineHeightPx(containingElement);
  11892. // Imagine our text looks like:
  11893. // <div><span>once upon a time, there was a <em>boy
  11894. // who lived</em> </span><q><strong>under^ the
  11895. // stairs</strong> in a small closet.</q></div>
  11896. // where the caret represents the cursor. First, we crawl up the tree until
  11897. // the range spans multiple lines (setting the start point to before
  11898. // "<strong>", then before "<div>"), then at each level we do a search to
  11899. // find the latest point which is still on a previous line. We'll find that
  11900. // the break point is inside the span, then inside the <em>, then in its text
  11901. // node child, the actual break point before "who".
  11902. var bestContainer = range.endContainer;
  11903. var bestOffset = range.endOffset;
  11904. range.setStart(range.startContainer, 0);
  11905. while (areRectsOnOneLine(getRangeClientRects_1(range), lineHeight)) {
  11906. bestContainer = range.startContainer;
  11907. bestOffset = range.startOffset;
  11908. !bestContainer.parentNode ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Found unexpected detached subtree when traversing.') : invariant_1(false) : void 0;
  11909. range.setStartBefore(bestContainer);
  11910. if (bestContainer.nodeType === 1 && getComputedStyle(bestContainer).display !== 'inline') {
  11911. // The start of the line is never in a different block-level container.
  11912. break;
  11913. }
  11914. }
  11915. // In the above example, range now spans from "<div>" to "under",
  11916. // bestContainer is <div>, and bestOffset is 1 (index of <q> inside <div>)].
  11917. // Picking out which child to recurse into here is a special case since we
  11918. // don't want to check past <q> -- once we find that the final range starts
  11919. // in <span>, we can look at all of its children (and all of their children)
  11920. // to find the break point.
  11921. // At all times, (bestContainer, bestOffset) is the latest single-line start
  11922. // point that we know of.
  11923. var currentContainer = bestContainer;
  11924. var maxIndexToConsider = bestOffset - 1;
  11925. do {
  11926. var nodeValue = currentContainer.nodeValue;
  11927. for (var ii = maxIndexToConsider; ii >= 0; ii--) {
  11928. if (nodeValue != null && ii > 0 && UnicodeUtils_1.isSurrogatePair(nodeValue, ii - 1)) {
  11929. // We're in the middle of a surrogate pair -- skip over so we never
  11930. // return a range with an endpoint in the middle of a code point.
  11931. continue;
  11932. }
  11933. range.setStart(currentContainer, ii);
  11934. if (areRectsOnOneLine(getRangeClientRects_1(range), lineHeight)) {
  11935. bestContainer = currentContainer;
  11936. bestOffset = ii;
  11937. } else {
  11938. break;
  11939. }
  11940. }
  11941. if (ii === -1 || currentContainer.childNodes.length === 0) {
  11942. // If ii === -1, then (bestContainer, bestOffset), which is equal to
  11943. // (currentContainer, 0), was a single-line start point but a start
  11944. // point before currentContainer wasn't, so the line break seems to
  11945. // have occurred immediately after currentContainer's start tag
  11946. //
  11947. // If currentContainer.childNodes.length === 0, we're already at a
  11948. // terminal node (e.g., text node) and should return our current best.
  11949. break;
  11950. }
  11951. currentContainer = currentContainer.childNodes[ii];
  11952. maxIndexToConsider = getNodeLength$1(currentContainer);
  11953. } while (true);
  11954. range.setStart(bestContainer, bestOffset);
  11955. return range;
  11956. }
  11957. var expandRangeToStartOfLine_1 = expandRangeToStartOfLine;
  11958. /**
  11959. * Convert the current selection range to an anchor/focus pair of offset keys
  11960. * and values that can be interpreted by components.
  11961. */
  11962. function getDraftEditorSelectionWithNodes(editorState, root, anchorNode, anchorOffset, focusNode, focusOffset) {
  11963. var anchorIsTextNode = anchorNode.nodeType === Node.TEXT_NODE;
  11964. var focusIsTextNode = focusNode.nodeType === Node.TEXT_NODE;
  11965. // If the selection range lies only on text nodes, the task is simple.
  11966. // Find the nearest offset-aware elements and use the
  11967. // offset values supplied by the selection range.
  11968. if (anchorIsTextNode && focusIsTextNode) {
  11969. return {
  11970. selectionState: getUpdatedSelectionState_1(editorState, nullthrows_1(findAncestorOffsetKey_1(anchorNode)), anchorOffset, nullthrows_1(findAncestorOffsetKey_1(focusNode)), focusOffset),
  11971. needsRecovery: false
  11972. };
  11973. }
  11974. var anchorPoint = null;
  11975. var focusPoint = null;
  11976. var needsRecovery = true;
  11977. // An element is selected. Convert this selection range into leaf offset
  11978. // keys and offset values for consumption at the component level. This
  11979. // is common in Firefox, where select-all and triple click behavior leads
  11980. // to entire elements being selected.
  11981. //
  11982. // Note that we use the `needsRecovery` parameter in the callback here. This
  11983. // is because when certain elements are selected, the behavior for subsequent
  11984. // cursor movement (e.g. via arrow keys) is uncertain and may not match
  11985. // expectations at the component level. For example, if an entire <div> is
  11986. // selected and the user presses the right arrow, Firefox keeps the selection
  11987. // on the <div>. If we allow subsequent keypresses to insert characters
  11988. // natively, they will be inserted into a browser-created text node to the
  11989. // right of that <div>. This is obviously undesirable.
  11990. //
  11991. // With the `needsRecovery` flag, we inform the caller that it is responsible
  11992. // for manually setting the selection state on the rendered document to
  11993. // ensure proper selection state maintenance.
  11994. if (anchorIsTextNode) {
  11995. anchorPoint = {
  11996. key: nullthrows_1(findAncestorOffsetKey_1(anchorNode)),
  11997. offset: anchorOffset
  11998. };
  11999. focusPoint = getPointForNonTextNode(root, focusNode, focusOffset);
  12000. } else if (focusIsTextNode) {
  12001. focusPoint = {
  12002. key: nullthrows_1(findAncestorOffsetKey_1(focusNode)),
  12003. offset: focusOffset
  12004. };
  12005. anchorPoint = getPointForNonTextNode(root, anchorNode, anchorOffset);
  12006. } else {
  12007. anchorPoint = getPointForNonTextNode(root, anchorNode, anchorOffset);
  12008. focusPoint = getPointForNonTextNode(root, focusNode, focusOffset);
  12009. // If the selection is collapsed on an empty block, don't force recovery.
  12010. // This way, on arrow key selection changes, the browser can move the
  12011. // cursor from a non-zero offset on one block, through empty blocks,
  12012. // to a matching non-zero offset on other text blocks.
  12013. if (anchorNode === focusNode && anchorOffset === focusOffset) {
  12014. needsRecovery = !!anchorNode.firstChild && anchorNode.firstChild.nodeName !== 'BR';
  12015. }
  12016. }
  12017. return {
  12018. selectionState: getUpdatedSelectionState_1(editorState, anchorPoint.key, anchorPoint.offset, focusPoint.key, focusPoint.offset),
  12019. needsRecovery: needsRecovery
  12020. };
  12021. }
  12022. /**
  12023. * Identify the first leaf descendant for the given node.
  12024. */
  12025. function getFirstLeaf(node) {
  12026. while (node.firstChild && (
  12027. // data-blocks has no offset
  12028. node.firstChild instanceof Element && node.firstChild.getAttribute('data-blocks') === 'true' || getSelectionOffsetKeyForNode_1(node.firstChild))) {
  12029. node = node.firstChild;
  12030. }
  12031. return node;
  12032. }
  12033. /**
  12034. * Identify the last leaf descendant for the given node.
  12035. */
  12036. function getLastLeaf(node) {
  12037. while (node.lastChild && (
  12038. // data-blocks has no offset
  12039. node.lastChild instanceof Element && node.lastChild.getAttribute('data-blocks') === 'true' || getSelectionOffsetKeyForNode_1(node.lastChild))) {
  12040. node = node.lastChild;
  12041. }
  12042. return node;
  12043. }
  12044. function getPointForNonTextNode(editorRoot, startNode, childOffset) {
  12045. var node = startNode;
  12046. var offsetKey = findAncestorOffsetKey_1(node);
  12047. !(offsetKey != null || editorRoot && (editorRoot === node || editorRoot.firstChild === node)) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Unknown node in selection range.') : invariant_1(false) : void 0;
  12048. // If the editorRoot is the selection, step downward into the content
  12049. // wrapper.
  12050. if (editorRoot === node) {
  12051. node = node.firstChild;
  12052. !(node instanceof Element && node.getAttribute('data-contents') === 'true') ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Invalid DraftEditorContents structure.') : invariant_1(false) : void 0;
  12053. if (childOffset > 0) {
  12054. childOffset = node.childNodes.length;
  12055. }
  12056. }
  12057. // If the child offset is zero and we have an offset key, we're done.
  12058. // If there's no offset key because the entire editor is selected,
  12059. // find the leftmost ("first") leaf in the tree and use that as the offset
  12060. // key.
  12061. if (childOffset === 0) {
  12062. var key = null;
  12063. if (offsetKey != null) {
  12064. key = offsetKey;
  12065. } else {
  12066. var firstLeaf = getFirstLeaf(node);
  12067. key = nullthrows_1(getSelectionOffsetKeyForNode_1(firstLeaf));
  12068. }
  12069. return { key: key, offset: 0 };
  12070. }
  12071. var nodeBeforeCursor = node.childNodes[childOffset - 1];
  12072. var leafKey = null;
  12073. var textLength = null;
  12074. if (!getSelectionOffsetKeyForNode_1(nodeBeforeCursor)) {
  12075. // Our target node may be a leaf or a text node, in which case we're
  12076. // already where we want to be and can just use the child's length as
  12077. // our offset.
  12078. leafKey = nullthrows_1(offsetKey);
  12079. textLength = getTextContentLength(nodeBeforeCursor);
  12080. } else {
  12081. // Otherwise, we'll look at the child to the left of the cursor and find
  12082. // the last leaf node in its subtree.
  12083. var lastLeaf = getLastLeaf(nodeBeforeCursor);
  12084. leafKey = nullthrows_1(getSelectionOffsetKeyForNode_1(lastLeaf));
  12085. textLength = getTextContentLength(lastLeaf);
  12086. }
  12087. return {
  12088. key: leafKey,
  12089. offset: textLength
  12090. };
  12091. }
  12092. /**
  12093. * Return the length of a node's textContent, regarding single newline
  12094. * characters as zero-length. This allows us to avoid problems with identifying
  12095. * the correct selection offset for empty blocks in IE, in which we
  12096. * render newlines instead of break tags.
  12097. */
  12098. function getTextContentLength(node) {
  12099. var textContent = node.textContent;
  12100. return textContent === '\n' ? 0 : textContent.length;
  12101. }
  12102. var getDraftEditorSelectionWithNodes_1 = getDraftEditorSelectionWithNodes;
  12103. /**
  12104. * Copyright (c) 2013-present, Facebook, Inc.
  12105. * All rights reserved.
  12106. *
  12107. * This source code is licensed under the BSD-style license found in the
  12108. * LICENSE file in the root directory of this source tree. An additional grant
  12109. * of patent rights can be found in the PATENTS file in the same directory.
  12110. *
  12111. * @providesModule moveSelectionBackward
  12112. * @format
  12113. *
  12114. */
  12115. /**
  12116. * Given a collapsed selection, move the focus `maxDistance` backward within
  12117. * the selected block. If the selection will go beyond the start of the block,
  12118. * move focus to the end of the previous block, but no further.
  12119. *
  12120. * This function is not Unicode-aware, so surrogate pairs will be treated
  12121. * as having length 2.
  12122. */
  12123. function moveSelectionBackward(editorState, maxDistance) {
  12124. var selection = editorState.getSelection();
  12125. var content = editorState.getCurrentContent();
  12126. var key = selection.getStartKey();
  12127. var offset = selection.getStartOffset();
  12128. var focusKey = key;
  12129. var focusOffset = 0;
  12130. if (maxDistance > offset) {
  12131. var keyBefore = content.getKeyBefore(key);
  12132. if (keyBefore == null) {
  12133. focusKey = key;
  12134. } else {
  12135. focusKey = keyBefore;
  12136. var blockBefore = content.getBlockForKey(keyBefore);
  12137. focusOffset = blockBefore.getText().length;
  12138. }
  12139. } else {
  12140. focusOffset = offset - maxDistance;
  12141. }
  12142. return selection.merge({
  12143. focusKey: focusKey,
  12144. focusOffset: focusOffset,
  12145. isBackward: true
  12146. });
  12147. }
  12148. var moveSelectionBackward_1 = moveSelectionBackward;
  12149. /**
  12150. * For a collapsed selection state, remove text based on the specified strategy.
  12151. * If the selection state is not collapsed, remove the entire selected range.
  12152. */
  12153. function removeTextWithStrategy(editorState, strategy, direction) {
  12154. var selection = editorState.getSelection();
  12155. var content = editorState.getCurrentContent();
  12156. var target = selection;
  12157. if (selection.isCollapsed()) {
  12158. if (direction === 'forward') {
  12159. if (editorState.isSelectionAtEndOfContent()) {
  12160. return content;
  12161. }
  12162. } else if (editorState.isSelectionAtStartOfContent()) {
  12163. return content;
  12164. }
  12165. target = strategy(editorState);
  12166. if (target === selection) {
  12167. return content;
  12168. }
  12169. }
  12170. return DraftModifier_1.removeRange(content, target, direction);
  12171. }
  12172. var removeTextWithStrategy_1 = removeTextWithStrategy;
  12173. function keyCommandBackspaceToStartOfLine(editorState) {
  12174. var afterRemoval = removeTextWithStrategy_1(editorState, function (strategyState) {
  12175. var selection = strategyState.getSelection();
  12176. if (selection.isCollapsed() && selection.getAnchorOffset() === 0) {
  12177. return moveSelectionBackward_1(strategyState, 1);
  12178. }
  12179. var domSelection = _commonjsHelpers.commonjsGlobal.getSelection();
  12180. var range = domSelection.getRangeAt(0);
  12181. range = expandRangeToStartOfLine_1(range);
  12182. return getDraftEditorSelectionWithNodes_1(strategyState, null, range.endContainer, range.endOffset, range.startContainer, range.startOffset).selectionState;
  12183. }, 'backward');
  12184. if (afterRemoval === editorState.getCurrentContent()) {
  12185. return editorState;
  12186. }
  12187. return EditorState_1.push(editorState, afterRemoval, 'remove-range');
  12188. }
  12189. var keyCommandBackspaceToStartOfLine_1 = keyCommandBackspaceToStartOfLine;
  12190. /**
  12191. * Copyright (c) 2013-present, Facebook, Inc.
  12192. *
  12193. * This source code is licensed under the MIT license found in the
  12194. * LICENSE file in the root directory of this source tree.
  12195. *
  12196. * @typechecks
  12197. * @stub
  12198. *
  12199. */
  12200. // \u00a1-\u00b1\u00b4-\u00b8\u00ba\u00bb\u00bf
  12201. // is latin supplement punctuation except fractions and superscript
  12202. // numbers
  12203. // \u2010-\u2027\u2030-\u205e
  12204. // is punctuation from the general punctuation block:
  12205. // weird quotes, commas, bullets, dashes, etc.
  12206. // \u30fb\u3001\u3002\u3008-\u3011\u3014-\u301f
  12207. // is CJK punctuation
  12208. // \uff1a-\uff1f\uff01-\uff0f\uff3b-\uff40\uff5b-\uff65
  12209. // is some full-width/half-width punctuation
  12210. // \u2E2E\u061f\u066a-\u066c\u061b\u060c\u060d\uFD3e\uFD3F
  12211. // is some Arabic punctuation marks
  12212. // \u1801\u0964\u104a\u104b
  12213. // is misc. other language punctuation marks
  12214. 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]';
  12215. var TokenizeUtil = {
  12216. getPunctuation: function getPunctuation() {
  12217. return PUNCTUATION;
  12218. }
  12219. };
  12220. var punctuation = TokenizeUtil.getPunctuation();
  12221. // The apostrophe and curly single quotes behave in a curious way: when
  12222. // surrounded on both sides by word characters, they behave as word chars; when
  12223. // either neighbor is punctuation or an end of the string, they behave as
  12224. // punctuation.
  12225. var CHAMELEON_CHARS = '[\'\u2018\u2019]';
  12226. // Remove the underscore, which should count as part of the removable word. The
  12227. // "chameleon chars" also count as punctuation in this regex.
  12228. var WHITESPACE_AND_PUNCTUATION = '\\s|(?![_])' + punctuation;
  12229. var DELETE_STRING = '^' + '(?:' + WHITESPACE_AND_PUNCTUATION + ')*' + '(?:' + CHAMELEON_CHARS + '|(?!' + WHITESPACE_AND_PUNCTUATION + ').)*' + '(?:(?!' + WHITESPACE_AND_PUNCTUATION + ').)';
  12230. var DELETE_REGEX = new RegExp(DELETE_STRING);
  12231. var BACKSPACE_STRING = '(?:(?!' + WHITESPACE_AND_PUNCTUATION + ').)' + '(?:' + CHAMELEON_CHARS + '|(?!' + WHITESPACE_AND_PUNCTUATION + ').)*' + '(?:' + WHITESPACE_AND_PUNCTUATION + ')*' + '$';
  12232. var BACKSPACE_REGEX = new RegExp(BACKSPACE_STRING);
  12233. function getRemovableWord(text, isBackward) {
  12234. var matches = isBackward ? BACKSPACE_REGEX.exec(text) : DELETE_REGEX.exec(text);
  12235. return matches ? matches[0] : text;
  12236. }
  12237. var DraftRemovableWord = {
  12238. getBackward: function getBackward(text) {
  12239. return getRemovableWord(text, true);
  12240. },
  12241. getForward: function getForward(text) {
  12242. return getRemovableWord(text, false);
  12243. }
  12244. };
  12245. var DraftRemovableWord_1 = DraftRemovableWord;
  12246. /**
  12247. * Delete the word that is left of the cursor, as well as any spaces or
  12248. * punctuation after the word.
  12249. */
  12250. function keyCommandBackspaceWord(editorState) {
  12251. var afterRemoval = removeTextWithStrategy_1(editorState, function (strategyState) {
  12252. var selection = strategyState.getSelection();
  12253. var offset = selection.getStartOffset();
  12254. // If there are no words before the cursor, remove the preceding newline.
  12255. if (offset === 0) {
  12256. return moveSelectionBackward_1(strategyState, 1);
  12257. }
  12258. var key = selection.getStartKey();
  12259. var content = strategyState.getCurrentContent();
  12260. var text = content.getBlockForKey(key).getText().slice(0, offset);
  12261. var toRemove = DraftRemovableWord_1.getBackward(text);
  12262. return moveSelectionBackward_1(strategyState, toRemove.length || 1);
  12263. }, 'backward');
  12264. if (afterRemoval === editorState.getCurrentContent()) {
  12265. return editorState;
  12266. }
  12267. return EditorState_1.push(editorState, afterRemoval, 'remove-range');
  12268. }
  12269. var keyCommandBackspaceWord_1 = keyCommandBackspaceWord;
  12270. /**
  12271. * Copyright (c) 2013-present, Facebook, Inc.
  12272. * All rights reserved.
  12273. *
  12274. * This source code is licensed under the BSD-style license found in the
  12275. * LICENSE file in the root directory of this source tree. An additional grant
  12276. * of patent rights can be found in the PATENTS file in the same directory.
  12277. *
  12278. * @providesModule moveSelectionForward
  12279. * @format
  12280. *
  12281. */
  12282. /**
  12283. * Given a collapsed selection, move the focus `maxDistance` forward within
  12284. * the selected block. If the selection will go beyond the end of the block,
  12285. * move focus to the start of the next block, but no further.
  12286. *
  12287. * This function is not Unicode-aware, so surrogate pairs will be treated
  12288. * as having length 2.
  12289. */
  12290. function moveSelectionForward(editorState, maxDistance) {
  12291. var selection = editorState.getSelection();
  12292. var key = selection.getStartKey();
  12293. var offset = selection.getStartOffset();
  12294. var content = editorState.getCurrentContent();
  12295. var focusKey = key;
  12296. var focusOffset;
  12297. var block = content.getBlockForKey(key);
  12298. if (maxDistance > block.getText().length - offset) {
  12299. focusKey = content.getKeyAfter(key);
  12300. focusOffset = 0;
  12301. } else {
  12302. focusOffset = offset + maxDistance;
  12303. }
  12304. return selection.merge({ focusKey: focusKey, focusOffset: focusOffset });
  12305. }
  12306. var moveSelectionForward_1 = moveSelectionForward;
  12307. /**
  12308. * Delete the word that is right of the cursor, as well as any spaces or
  12309. * punctuation before the word.
  12310. */
  12311. function keyCommandDeleteWord(editorState) {
  12312. var afterRemoval = removeTextWithStrategy_1(editorState, function (strategyState) {
  12313. var selection = strategyState.getSelection();
  12314. var offset = selection.getStartOffset();
  12315. var key = selection.getStartKey();
  12316. var content = strategyState.getCurrentContent();
  12317. var text = content.getBlockForKey(key).getText().slice(offset);
  12318. var toRemove = DraftRemovableWord_1.getForward(text);
  12319. // If there are no words in front of the cursor, remove the newline.
  12320. return moveSelectionForward_1(strategyState, toRemove.length || 1);
  12321. }, 'forward');
  12322. if (afterRemoval === editorState.getCurrentContent()) {
  12323. return editorState;
  12324. }
  12325. return EditorState_1.push(editorState, afterRemoval, 'remove-range');
  12326. }
  12327. var keyCommandDeleteWord_1 = keyCommandDeleteWord;
  12328. function keyCommandInsertNewline(editorState) {
  12329. var contentState = DraftModifier_1.splitBlock(editorState.getCurrentContent(), editorState.getSelection());
  12330. return EditorState_1.push(editorState, contentState, 'split-block');
  12331. }
  12332. var keyCommandInsertNewline_1 = keyCommandInsertNewline;
  12333. /**
  12334. * See comment for `moveSelectionToStartOfBlock`.
  12335. */
  12336. function keyCommandMoveSelectionToEndOfBlock(editorState) {
  12337. var selection = editorState.getSelection();
  12338. var endKey = selection.getEndKey();
  12339. var content = editorState.getCurrentContent();
  12340. var textLength = content.getBlockForKey(endKey).getLength();
  12341. return EditorState_1.set(editorState, {
  12342. selection: selection.merge({
  12343. anchorKey: endKey,
  12344. anchorOffset: textLength,
  12345. focusKey: endKey,
  12346. focusOffset: textLength,
  12347. isBackward: false
  12348. }),
  12349. forceSelection: true
  12350. });
  12351. }
  12352. var keyCommandMoveSelectionToEndOfBlock_1 = keyCommandMoveSelectionToEndOfBlock;
  12353. /**
  12354. * Collapse selection at the start of the first selected block. This is used
  12355. * for Firefox versions that attempt to navigate forward/backward instead of
  12356. * moving the cursor. Other browsers are able to move the cursor natively.
  12357. */
  12358. function keyCommandMoveSelectionToStartOfBlock(editorState) {
  12359. var selection = editorState.getSelection();
  12360. var startKey = selection.getStartKey();
  12361. return EditorState_1.set(editorState, {
  12362. selection: selection.merge({
  12363. anchorKey: startKey,
  12364. anchorOffset: 0,
  12365. focusKey: startKey,
  12366. focusOffset: 0,
  12367. isBackward: false
  12368. }),
  12369. forceSelection: true
  12370. });
  12371. }
  12372. var keyCommandMoveSelectionToStartOfBlock_1 = keyCommandMoveSelectionToStartOfBlock;
  12373. /**
  12374. * Remove the selected range. If the cursor is collapsed, remove the preceding
  12375. * character. This operation is Unicode-aware, so removing a single character
  12376. * will remove a surrogate pair properly as well.
  12377. */
  12378. function keyCommandPlainBackspace(editorState) {
  12379. var afterRemoval = removeTextWithStrategy_1(editorState, function (strategyState) {
  12380. var selection = strategyState.getSelection();
  12381. var content = strategyState.getCurrentContent();
  12382. var key = selection.getAnchorKey();
  12383. var offset = selection.getAnchorOffset();
  12384. var charBehind = content.getBlockForKey(key).getText()[offset - 1];
  12385. return moveSelectionBackward_1(strategyState, charBehind ? UnicodeUtils_1.getUTF16Length(charBehind, 0) : 1);
  12386. }, 'backward');
  12387. if (afterRemoval === editorState.getCurrentContent()) {
  12388. return editorState;
  12389. }
  12390. var selection = editorState.getSelection();
  12391. return EditorState_1.push(editorState, afterRemoval.set('selectionBefore', selection), selection.isCollapsed() ? 'backspace-character' : 'remove-range');
  12392. }
  12393. var keyCommandPlainBackspace_1 = keyCommandPlainBackspace;
  12394. /**
  12395. * Remove the selected range. If the cursor is collapsed, remove the following
  12396. * character. This operation is Unicode-aware, so removing a single character
  12397. * will remove a surrogate pair properly as well.
  12398. */
  12399. function keyCommandPlainDelete(editorState) {
  12400. var afterRemoval = removeTextWithStrategy_1(editorState, function (strategyState) {
  12401. var selection = strategyState.getSelection();
  12402. var content = strategyState.getCurrentContent();
  12403. var key = selection.getAnchorKey();
  12404. var offset = selection.getAnchorOffset();
  12405. var charAhead = content.getBlockForKey(key).getText()[offset];
  12406. return moveSelectionForward_1(strategyState, charAhead ? UnicodeUtils_1.getUTF16Length(charAhead, 0) : 1);
  12407. }, 'forward');
  12408. if (afterRemoval === editorState.getCurrentContent()) {
  12409. return editorState;
  12410. }
  12411. var selection = editorState.getSelection();
  12412. return EditorState_1.push(editorState, afterRemoval.set('selectionBefore', selection), selection.isCollapsed() ? 'delete-character' : 'remove-range');
  12413. }
  12414. var keyCommandPlainDelete_1 = keyCommandPlainDelete;
  12415. /**
  12416. * Transpose the characters on either side of a collapsed cursor, or
  12417. * if the cursor is at the end of the block, transpose the last two
  12418. * characters.
  12419. */
  12420. function keyCommandTransposeCharacters(editorState) {
  12421. var selection = editorState.getSelection();
  12422. if (!selection.isCollapsed()) {
  12423. return editorState;
  12424. }
  12425. var offset = selection.getAnchorOffset();
  12426. if (offset === 0) {
  12427. return editorState;
  12428. }
  12429. var blockKey = selection.getAnchorKey();
  12430. var content = editorState.getCurrentContent();
  12431. var block = content.getBlockForKey(blockKey);
  12432. var length = block.getLength();
  12433. // Nothing to transpose if there aren't two characters.
  12434. if (length <= 1) {
  12435. return editorState;
  12436. }
  12437. var removalRange;
  12438. var finalSelection;
  12439. if (offset === length) {
  12440. // The cursor is at the end of the block. Swap the last two characters.
  12441. removalRange = selection.set('anchorOffset', offset - 1);
  12442. finalSelection = selection;
  12443. } else {
  12444. removalRange = selection.set('focusOffset', offset + 1);
  12445. finalSelection = removalRange.set('anchorOffset', offset + 1);
  12446. }
  12447. // Extract the character to move as a fragment. This preserves its
  12448. // styling and entity, if any.
  12449. var movedFragment = getContentStateFragment_1(content, removalRange);
  12450. var afterRemoval = DraftModifier_1.removeRange(content, removalRange, 'backward');
  12451. // After the removal, the insertion target is one character back.
  12452. var selectionAfter = afterRemoval.getSelectionAfter();
  12453. var targetOffset = selectionAfter.getAnchorOffset() - 1;
  12454. var targetRange = selectionAfter.merge({
  12455. anchorOffset: targetOffset,
  12456. focusOffset: targetOffset
  12457. });
  12458. var afterInsert = DraftModifier_1.replaceWithFragment(afterRemoval, targetRange, movedFragment);
  12459. var newEditorState = EditorState_1.push(editorState, afterInsert, 'insert-fragment');
  12460. return EditorState_1.acceptSelection(newEditorState, finalSelection);
  12461. }
  12462. var keyCommandTransposeCharacters_1 = keyCommandTransposeCharacters;
  12463. function keyCommandUndo(e, editorState, updateFn) {
  12464. var undoneState = EditorState_1.undo(editorState);
  12465. // If the last change to occur was a spellcheck change, allow the undo
  12466. // event to fall through to the browser. This allows the browser to record
  12467. // the unwanted change, which should soon lead it to learn not to suggest
  12468. // the correction again.
  12469. if (editorState.getLastChangeType() === 'spellcheck-change') {
  12470. var nativelyRenderedContent = undoneState.getCurrentContent();
  12471. updateFn(EditorState_1.set(undoneState, { nativelyRenderedContent: nativelyRenderedContent }));
  12472. return;
  12473. }
  12474. // Otheriwse, manage the undo behavior manually.
  12475. e.preventDefault();
  12476. if (!editorState.getNativelyRenderedContent()) {
  12477. updateFn(undoneState);
  12478. return;
  12479. }
  12480. // Trigger a re-render with the current content state to ensure that the
  12481. // component tree has up-to-date props for comparison.
  12482. updateFn(EditorState_1.set(editorState, { nativelyRenderedContent: null }));
  12483. // Wait to ensure that the re-render has occurred before performing
  12484. // the undo action.
  12485. setTimeout(function () {
  12486. updateFn(undoneState);
  12487. }, 0);
  12488. }
  12489. var keyCommandUndo_1 = keyCommandUndo;
  12490. var isOptionKeyCommand = KeyBindingUtil_1.isOptionKeyCommand;
  12491. var isChrome$1 = UserAgent_1.isBrowser('Chrome');
  12492. /**
  12493. * Map a `DraftEditorCommand` command value to a corresponding function.
  12494. */
  12495. function onKeyCommand(command, editorState) {
  12496. switch (command) {
  12497. case 'redo':
  12498. return EditorState_1.redo(editorState);
  12499. case 'delete':
  12500. return keyCommandPlainDelete_1(editorState);
  12501. case 'delete-word':
  12502. return keyCommandDeleteWord_1(editorState);
  12503. case 'backspace':
  12504. return keyCommandPlainBackspace_1(editorState);
  12505. case 'backspace-word':
  12506. return keyCommandBackspaceWord_1(editorState);
  12507. case 'backspace-to-start-of-line':
  12508. return keyCommandBackspaceToStartOfLine_1(editorState);
  12509. case 'split-block':
  12510. return keyCommandInsertNewline_1(editorState);
  12511. case 'transpose-characters':
  12512. return keyCommandTransposeCharacters_1(editorState);
  12513. case 'move-selection-to-start-of-block':
  12514. return keyCommandMoveSelectionToStartOfBlock_1(editorState);
  12515. case 'move-selection-to-end-of-block':
  12516. return keyCommandMoveSelectionToEndOfBlock_1(editorState);
  12517. case 'secondary-cut':
  12518. return SecondaryClipboard_1.cut(editorState);
  12519. case 'secondary-paste':
  12520. return SecondaryClipboard_1.paste(editorState);
  12521. default:
  12522. return editorState;
  12523. }
  12524. }
  12525. /**
  12526. * Intercept keydown behavior to handle keys and commands manually, if desired.
  12527. *
  12528. * Keydown combinations may be mapped to `DraftCommand` values, which may
  12529. * correspond to command functions that modify the editor or its contents.
  12530. *
  12531. * See `getDefaultKeyBinding` for defaults. Alternatively, the top-level
  12532. * component may provide a custom mapping via the `keyBindingFn` prop.
  12533. */
  12534. function editOnKeyDown(editor, e) {
  12535. var keyCode = e.which;
  12536. var editorState = editor._latestEditorState;
  12537. switch (keyCode) {
  12538. case Keys.RETURN:
  12539. e.preventDefault();
  12540. // The top-level component may manually handle newline insertion. If
  12541. // no special handling is performed, fall through to command handling.
  12542. if (editor.props.handleReturn && isEventHandled_1(editor.props.handleReturn(e, editorState))) {
  12543. return;
  12544. }
  12545. break;
  12546. case Keys.ESC:
  12547. e.preventDefault();
  12548. editor.props.onEscape && editor.props.onEscape(e);
  12549. return;
  12550. case Keys.TAB:
  12551. editor.props.onTab && editor.props.onTab(e);
  12552. return;
  12553. case Keys.UP:
  12554. editor.props.onUpArrow && editor.props.onUpArrow(e);
  12555. return;
  12556. case Keys.RIGHT:
  12557. editor.props.onRightArrow && editor.props.onRightArrow(e);
  12558. return;
  12559. case Keys.DOWN:
  12560. editor.props.onDownArrow && editor.props.onDownArrow(e);
  12561. return;
  12562. case Keys.LEFT:
  12563. editor.props.onLeftArrow && editor.props.onLeftArrow(e);
  12564. return;
  12565. case Keys.SPACE:
  12566. // Handling for OSX where option + space scrolls.
  12567. if (isChrome$1 && isOptionKeyCommand(e)) {
  12568. e.preventDefault();
  12569. // Insert a nbsp into the editor.
  12570. var contentState = DraftModifier_1.replaceText(editorState.getCurrentContent(), editorState.getSelection(), '\xA0');
  12571. editor.update(EditorState_1.push(editorState, contentState, 'insert-characters'));
  12572. return;
  12573. }
  12574. }
  12575. var command = editor.props.keyBindingFn(e);
  12576. // If no command is specified, allow keydown event to continue.
  12577. if (!command) {
  12578. return;
  12579. }
  12580. if (command === 'undo') {
  12581. // Since undo requires some special updating behavior to keep the editor
  12582. // in sync, handle it separately.
  12583. keyCommandUndo_1(e, editorState, editor.update);
  12584. return;
  12585. }
  12586. // At this point, we know that we're handling a command of some kind, so
  12587. // we don't want to insert a character following the keydown.
  12588. e.preventDefault();
  12589. // Allow components higher up the tree to handle the command first.
  12590. if (editor.props.handleKeyCommand && isEventHandled_1(editor.props.handleKeyCommand(command, editorState))) {
  12591. return;
  12592. }
  12593. var newState = onKeyCommand(command, editorState);
  12594. if (newState !== editorState) {
  12595. editor.update(newState);
  12596. }
  12597. }
  12598. var editOnKeyDown_1 = editOnKeyDown;
  12599. /**
  12600. * Copyright (c) 2013-present, Facebook, Inc.
  12601. *
  12602. * This source code is licensed under the MIT license found in the
  12603. * LICENSE file in the root directory of this source tree.
  12604. *
  12605. *
  12606. */
  12607. function _classCallCheck$e(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  12608. var URI = function () {
  12609. function URI(uri) {
  12610. _classCallCheck$e(this, URI);
  12611. this._uri = uri;
  12612. }
  12613. URI.prototype.toString = function toString() {
  12614. return this._uri;
  12615. };
  12616. return URI;
  12617. }();
  12618. var URI_1 = URI;
  12619. var isOldIE = UserAgent_1.isBrowser('IE <= 9');
  12620. // Provides a dom node that will not execute scripts
  12621. // https://developer.mozilla.org/en-US/docs/Web/API/DOMImplementation.createHTMLDocument
  12622. // https://developer.mozilla.org/en-US/Add-ons/Code_snippets/HTML_to_DOM
  12623. function getSafeBodyFromHTML(html) {
  12624. var doc;
  12625. var root = null;
  12626. // Provides a safe context
  12627. if (!isOldIE && document.implementation && document.implementation.createHTMLDocument) {
  12628. doc = document.implementation.createHTMLDocument('foo');
  12629. !doc.documentElement ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing doc.documentElement') : invariant_1(false) : void 0;
  12630. doc.documentElement.innerHTML = html;
  12631. root = doc.getElementsByTagName('body')[0];
  12632. }
  12633. return root;
  12634. }
  12635. var getSafeBodyFromHTML_1 = getSafeBodyFromHTML;
  12636. var _extends$4 = objectAssign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  12637. var _knownListItemDepthCl;
  12638. 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; }
  12639. var _require = immutable,
  12640. Set = _require.Set;
  12641. var experimentalTreeDataSupport = DraftFeatureFlags_1.draft_tree_data_support;
  12642. var List$a = immutable.List,
  12643. OrderedSet$5 = immutable.OrderedSet;
  12644. var NBSP = '&nbsp;';
  12645. var SPACE = ' ';
  12646. // Arbitrary max indent
  12647. var MAX_DEPTH = 4;
  12648. // used for replacing characters in HTML
  12649. var REGEX_CR = new RegExp('\r', 'g');
  12650. var REGEX_LF = new RegExp('\n', 'g');
  12651. var REGEX_NBSP = new RegExp(NBSP, 'g');
  12652. var REGEX_CARRIAGE = new RegExp('&#13;?', 'g');
  12653. var REGEX_ZWS = new RegExp('&#8203;?', 'g');
  12654. // https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight
  12655. var boldValues = ['bold', 'bolder', '500', '600', '700', '800', '900'];
  12656. var notBoldValues = ['light', 'lighter', '100', '200', '300', '400'];
  12657. // Block tag flow is different because LIs do not have
  12658. // a deterministic style ;_;
  12659. var inlineTags = {
  12660. b: 'BOLD',
  12661. code: 'CODE',
  12662. del: 'STRIKETHROUGH',
  12663. em: 'ITALIC',
  12664. i: 'ITALIC',
  12665. s: 'STRIKETHROUGH',
  12666. strike: 'STRIKETHROUGH',
  12667. strong: 'BOLD',
  12668. u: 'UNDERLINE'
  12669. };
  12670. var knownListItemDepthClasses = (_knownListItemDepthCl = {}, _defineProperty(_knownListItemDepthCl, cx_1('public/DraftStyleDefault/depth0'), 0), _defineProperty(_knownListItemDepthCl, cx_1('public/DraftStyleDefault/depth1'), 1), _defineProperty(_knownListItemDepthCl, cx_1('public/DraftStyleDefault/depth2'), 2), _defineProperty(_knownListItemDepthCl, cx_1('public/DraftStyleDefault/depth3'), 3), _defineProperty(_knownListItemDepthCl, cx_1('public/DraftStyleDefault/depth4'), 4), _knownListItemDepthCl);
  12671. var anchorAttr = ['className', 'href', 'rel', 'target', 'title'];
  12672. var imgAttr = ['alt', 'className', 'height', 'src', 'width'];
  12673. var lastBlock = void 0;
  12674. var EMPTY_CHUNK = {
  12675. text: '',
  12676. inlines: [],
  12677. entities: [],
  12678. blocks: []
  12679. };
  12680. var EMPTY_BLOCK = {
  12681. children: List$a(),
  12682. depth: 0,
  12683. key: '',
  12684. type: ''
  12685. };
  12686. var getListBlockType = function getListBlockType(tag, lastList) {
  12687. if (tag === 'li') {
  12688. return lastList === 'ol' ? 'ordered-list-item' : 'unordered-list-item';
  12689. }
  12690. return null;
  12691. };
  12692. var getBlockMapSupportedTags = function getBlockMapSupportedTags(blockRenderMap) {
  12693. var unstyledElement = blockRenderMap.get('unstyled').element;
  12694. var tags = Set([]);
  12695. blockRenderMap.forEach(function (draftBlock) {
  12696. if (draftBlock.aliasedElements) {
  12697. draftBlock.aliasedElements.forEach(function (tag) {
  12698. tags = tags.add(tag);
  12699. });
  12700. }
  12701. tags = tags.add(draftBlock.element);
  12702. });
  12703. return tags.filter(function (tag) {
  12704. return tag && tag !== unstyledElement;
  12705. }).toArray().sort();
  12706. };
  12707. // custom element conversions
  12708. var getMultiMatchedType = function getMultiMatchedType(tag, lastList, multiMatchExtractor) {
  12709. for (var ii = 0; ii < multiMatchExtractor.length; ii++) {
  12710. var matchType = multiMatchExtractor[ii](tag, lastList);
  12711. if (matchType) {
  12712. return matchType;
  12713. }
  12714. }
  12715. return null;
  12716. };
  12717. var getBlockTypeForTag = function getBlockTypeForTag(tag, lastList, blockRenderMap) {
  12718. var matchedTypes = blockRenderMap.filter(function (draftBlock) {
  12719. return draftBlock.element === tag || draftBlock.wrapper === tag || draftBlock.aliasedElements && draftBlock.aliasedElements.some(function (alias) {
  12720. return alias === tag;
  12721. });
  12722. }).keySeq().toSet().toArray().sort();
  12723. // if we dont have any matched type, return unstyled
  12724. // if we have one matched type return it
  12725. // if we have multi matched types use the multi-match function to gather type
  12726. switch (matchedTypes.length) {
  12727. case 0:
  12728. return 'unstyled';
  12729. case 1:
  12730. return matchedTypes[0];
  12731. default:
  12732. return getMultiMatchedType(tag, lastList, [getListBlockType]) || 'unstyled';
  12733. }
  12734. };
  12735. var processInlineTag = function processInlineTag(tag, node, currentStyle) {
  12736. var styleToCheck = inlineTags[tag];
  12737. if (styleToCheck) {
  12738. currentStyle = currentStyle.add(styleToCheck).toOrderedSet();
  12739. } else if (node instanceof HTMLElement) {
  12740. var htmlElement = node;
  12741. currentStyle = currentStyle.withMutations(function (style) {
  12742. var fontWeight = htmlElement.style.fontWeight;
  12743. var fontStyle = htmlElement.style.fontStyle;
  12744. var textDecoration = htmlElement.style.textDecoration;
  12745. if (boldValues.indexOf(fontWeight) >= 0) {
  12746. style.add('BOLD');
  12747. } else if (notBoldValues.indexOf(fontWeight) >= 0) {
  12748. style.remove('BOLD');
  12749. }
  12750. if (fontStyle === 'italic') {
  12751. style.add('ITALIC');
  12752. } else if (fontStyle === 'normal') {
  12753. style.remove('ITALIC');
  12754. }
  12755. if (textDecoration === 'underline') {
  12756. style.add('UNDERLINE');
  12757. }
  12758. if (textDecoration === 'line-through') {
  12759. style.add('STRIKETHROUGH');
  12760. }
  12761. if (textDecoration === 'none') {
  12762. style.remove('UNDERLINE');
  12763. style.remove('STRIKETHROUGH');
  12764. }
  12765. }).toOrderedSet();
  12766. }
  12767. return currentStyle;
  12768. };
  12769. var joinChunks = function joinChunks(A, B, experimentalHasNestedBlocks) {
  12770. // Sometimes two blocks will touch in the DOM and we need to strip the
  12771. // extra delimiter to preserve niceness.
  12772. var lastInA = A.text.slice(-1);
  12773. var firstInB = B.text.slice(0, 1);
  12774. if (lastInA === '\r' && firstInB === '\r' && !experimentalHasNestedBlocks) {
  12775. A.text = A.text.slice(0, -1);
  12776. A.inlines.pop();
  12777. A.entities.pop();
  12778. A.blocks.pop();
  12779. }
  12780. // Kill whitespace after blocks
  12781. if (lastInA === '\r') {
  12782. if (B.text === SPACE || B.text === '\n') {
  12783. return A;
  12784. } else if (firstInB === SPACE || firstInB === '\n') {
  12785. B.text = B.text.slice(1);
  12786. B.inlines.shift();
  12787. B.entities.shift();
  12788. }
  12789. }
  12790. return {
  12791. text: A.text + B.text,
  12792. inlines: A.inlines.concat(B.inlines),
  12793. entities: A.entities.concat(B.entities),
  12794. blocks: A.blocks.concat(B.blocks)
  12795. };
  12796. };
  12797. /**
  12798. * Check to see if we have anything like <p> <blockquote> <h1>... to create
  12799. * block tags from. If we do, we can use those and ignore <div> tags. If we
  12800. * don't, we can treat <div> tags as meaningful (unstyled) blocks.
  12801. */
  12802. var containsSemanticBlockMarkup = function containsSemanticBlockMarkup(html, blockTags) {
  12803. return blockTags.some(function (tag) {
  12804. return html.indexOf('<' + tag) !== -1;
  12805. });
  12806. };
  12807. var hasValidLinkText = function hasValidLinkText(link) {
  12808. !(link instanceof HTMLAnchorElement) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Link must be an HTMLAnchorElement.') : invariant_1(false) : void 0;
  12809. var protocol = link.protocol;
  12810. return protocol === 'http:' || protocol === 'https:' || protocol === 'mailto:';
  12811. };
  12812. var getWhitespaceChunk = function getWhitespaceChunk(inEntity) {
  12813. var entities = new Array(1);
  12814. if (inEntity) {
  12815. entities[0] = inEntity;
  12816. }
  12817. return _extends$4({}, EMPTY_CHUNK, {
  12818. text: SPACE,
  12819. inlines: [OrderedSet$5()],
  12820. entities: entities
  12821. });
  12822. };
  12823. var getSoftNewlineChunk = function getSoftNewlineChunk() {
  12824. return _extends$4({}, EMPTY_CHUNK, {
  12825. text: '\n',
  12826. inlines: [OrderedSet$5()],
  12827. entities: new Array(1)
  12828. });
  12829. };
  12830. var getChunkedBlock = function getChunkedBlock() {
  12831. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  12832. return _extends$4({}, EMPTY_BLOCK, props);
  12833. };
  12834. var getBlockDividerChunk = function getBlockDividerChunk(block, depth) {
  12835. var parentKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  12836. return {
  12837. text: '\r',
  12838. inlines: [OrderedSet$5()],
  12839. entities: new Array(1),
  12840. blocks: [getChunkedBlock({
  12841. parent: parentKey,
  12842. key: generateRandomKey_1(),
  12843. type: block,
  12844. depth: Math.max(0, Math.min(MAX_DEPTH, depth))
  12845. })]
  12846. };
  12847. };
  12848. /**
  12849. * If we're pasting from one DraftEditor to another we can check to see if
  12850. * existing list item depth classes are being used and preserve this style
  12851. */
  12852. var getListItemDepth = function getListItemDepth(node) {
  12853. var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  12854. Object.keys(knownListItemDepthClasses).some(function (depthClass) {
  12855. if (node.classList.contains(depthClass)) {
  12856. depth = knownListItemDepthClasses[depthClass];
  12857. }
  12858. });
  12859. return depth;
  12860. };
  12861. var genFragment = function genFragment(entityMap, node, inlineStyle, lastList, inBlock, blockTags, depth, blockRenderMap, inEntity, parentKey) {
  12862. var lastLastBlock = lastBlock;
  12863. var nodeName = node.nodeName.toLowerCase();
  12864. var newEntityMap = entityMap;
  12865. var nextBlockType = 'unstyled';
  12866. var newBlock = false;
  12867. var inBlockType = inBlock && getBlockTypeForTag(inBlock, lastList, blockRenderMap);
  12868. var chunk = _extends$4({}, EMPTY_CHUNK);
  12869. var newChunk = null;
  12870. var blockKey = void 0;
  12871. // Base Case
  12872. if (nodeName === '#text') {
  12873. var _text = node.textContent;
  12874. var nodeTextContent = _text.trim();
  12875. // We should not create blocks for leading spaces that are
  12876. // existing around ol/ul and their children list items
  12877. if (lastList && nodeTextContent === '' && node.parentElement) {
  12878. var parentNodeName = node.parentElement.nodeName.toLowerCase();
  12879. if (parentNodeName === 'ol' || parentNodeName === 'ul') {
  12880. return { chunk: _extends$4({}, EMPTY_CHUNK), entityMap: entityMap };
  12881. }
  12882. }
  12883. if (nodeTextContent === '' && inBlock !== 'pre') {
  12884. return { chunk: getWhitespaceChunk(inEntity), entityMap: entityMap };
  12885. }
  12886. if (inBlock !== 'pre') {
  12887. // Can't use empty string because MSWord
  12888. _text = _text.replace(REGEX_LF, SPACE);
  12889. }
  12890. // save the last block so we can use it later
  12891. lastBlock = nodeName;
  12892. return {
  12893. chunk: {
  12894. text: _text,
  12895. inlines: Array(_text.length).fill(inlineStyle),
  12896. entities: Array(_text.length).fill(inEntity),
  12897. blocks: []
  12898. },
  12899. entityMap: entityMap
  12900. };
  12901. }
  12902. // save the last block so we can use it later
  12903. lastBlock = nodeName;
  12904. // BR tags
  12905. if (nodeName === 'br') {
  12906. if (lastLastBlock === 'br' && (!inBlock || inBlockType === 'unstyled')) {
  12907. return {
  12908. chunk: getBlockDividerChunk('unstyled', depth, parentKey),
  12909. entityMap: entityMap
  12910. };
  12911. }
  12912. return { chunk: getSoftNewlineChunk(), entityMap: entityMap };
  12913. }
  12914. // IMG tags
  12915. if (nodeName === 'img' && node instanceof HTMLImageElement && node.attributes.getNamedItem('src') && node.attributes.getNamedItem('src').value) {
  12916. var image = node;
  12917. var entityConfig = {};
  12918. imgAttr.forEach(function (attr) {
  12919. var imageAttribute = image.getAttribute(attr);
  12920. if (imageAttribute) {
  12921. entityConfig[attr] = imageAttribute;
  12922. }
  12923. });
  12924. // Forcing this node to have children because otherwise no entity will be
  12925. // created for this node.
  12926. // The child text node cannot just have a space or return as content -
  12927. // we strip those out.
  12928. // See https://github.com/facebook/draft-js/issues/231 for some context.
  12929. node.textContent = '\uD83D\uDCF7';
  12930. // TODO: update this when we remove DraftEntity entirely
  12931. inEntity = DraftEntity_1.__create('IMAGE', 'MUTABLE', entityConfig || {});
  12932. }
  12933. // Inline tags
  12934. inlineStyle = processInlineTag(nodeName, node, inlineStyle);
  12935. // Handle lists
  12936. if (nodeName === 'ul' || nodeName === 'ol') {
  12937. if (lastList) {
  12938. depth += 1;
  12939. }
  12940. lastList = nodeName;
  12941. }
  12942. if ( nodeName === 'li' && node instanceof HTMLElement) {
  12943. depth = getListItemDepth(node, depth);
  12944. }
  12945. var blockType = getBlockTypeForTag(nodeName, lastList, blockRenderMap);
  12946. var inListBlock = lastList && inBlock === 'li' && nodeName === 'li';
  12947. var inBlockOrHasNestedBlocks = (!inBlock || experimentalTreeDataSupport) && blockTags.indexOf(nodeName) !== -1;
  12948. // Block Tags
  12949. if (inListBlock || inBlockOrHasNestedBlocks) {
  12950. chunk = getBlockDividerChunk(blockType, depth, parentKey);
  12951. blockKey = chunk.blocks[0].key;
  12952. inBlock = nodeName;
  12953. newBlock = !experimentalTreeDataSupport;
  12954. }
  12955. // this is required so that we can handle 'ul' and 'ol'
  12956. if (inListBlock) {
  12957. nextBlockType = lastList === 'ul' ? 'unordered-list-item' : 'ordered-list-item';
  12958. }
  12959. // Recurse through children
  12960. var child = node.firstChild;
  12961. if (child != null) {
  12962. nodeName = child.nodeName.toLowerCase();
  12963. }
  12964. var entityId = null;
  12965. while (child) {
  12966. if (child instanceof HTMLAnchorElement && child.href && hasValidLinkText(child)) {
  12967. (function () {
  12968. var anchor = child;
  12969. var entityConfig = {};
  12970. anchorAttr.forEach(function (attr) {
  12971. var anchorAttribute = anchor.getAttribute(attr);
  12972. if (anchorAttribute) {
  12973. entityConfig[attr] = anchorAttribute;
  12974. }
  12975. });
  12976. entityConfig.url = new URI_1(anchor.href).toString();
  12977. // TODO: update this when we remove DraftEntity completely
  12978. entityId = DraftEntity_1.__create('LINK', 'MUTABLE', entityConfig || {});
  12979. })();
  12980. } else {
  12981. entityId = undefined;
  12982. }
  12983. var _genFragment = genFragment(newEntityMap, child, inlineStyle, lastList, inBlock, blockTags, depth, blockRenderMap, entityId || inEntity, null),
  12984. generatedChunk = _genFragment.chunk,
  12985. maybeUpdatedEntityMap = _genFragment.entityMap;
  12986. newChunk = generatedChunk;
  12987. newEntityMap = maybeUpdatedEntityMap;
  12988. chunk = joinChunks(chunk, newChunk, experimentalTreeDataSupport);
  12989. var sibling = child.nextSibling;
  12990. // Put in a newline to break up blocks inside blocks
  12991. if (!parentKey && sibling && blockTags.indexOf(nodeName) >= 0 && inBlock) {
  12992. chunk = joinChunks(chunk, getSoftNewlineChunk());
  12993. }
  12994. if (sibling) {
  12995. nodeName = sibling.nodeName.toLowerCase();
  12996. }
  12997. child = sibling;
  12998. }
  12999. if (newBlock) {
  13000. chunk = joinChunks(chunk, getBlockDividerChunk(nextBlockType, depth, parentKey));
  13001. }
  13002. return { chunk: chunk, entityMap: newEntityMap };
  13003. };
  13004. var getChunkForHTML = function getChunkForHTML(html, DOMBuilder, blockRenderMap, entityMap) {
  13005. html = html.trim().replace(REGEX_CR, '').replace(REGEX_NBSP, SPACE).replace(REGEX_CARRIAGE, '').replace(REGEX_ZWS, '');
  13006. var supportedBlockTags = getBlockMapSupportedTags(blockRenderMap);
  13007. var safeBody = DOMBuilder(html);
  13008. if (!safeBody) {
  13009. return null;
  13010. }
  13011. lastBlock = null;
  13012. // Sometimes we aren't dealing with content that contains nice semantic
  13013. // tags. In this case, use divs to separate everything out into paragraphs
  13014. // and hope for the best.
  13015. var workingBlocks = containsSemanticBlockMarkup(html, supportedBlockTags) ? supportedBlockTags : ['div'];
  13016. // Start with -1 block depth to offset the fact that we are passing in a fake
  13017. // UL block to start with.
  13018. var fragment = genFragment(entityMap, safeBody, OrderedSet$5(), 'ul', null, workingBlocks, -1, blockRenderMap);
  13019. var chunk = fragment.chunk;
  13020. var newEntityMap = fragment.entityMap;
  13021. // join with previous block to prevent weirdness on paste
  13022. if (chunk.text.indexOf('\r') === 0) {
  13023. chunk = {
  13024. text: chunk.text.slice(1),
  13025. inlines: chunk.inlines.slice(1),
  13026. entities: chunk.entities.slice(1),
  13027. blocks: chunk.blocks
  13028. };
  13029. }
  13030. // Kill block delimiter at the end
  13031. if (chunk.text.slice(-1) === '\r') {
  13032. chunk.text = chunk.text.slice(0, -1);
  13033. chunk.inlines = chunk.inlines.slice(0, -1);
  13034. chunk.entities = chunk.entities.slice(0, -1);
  13035. chunk.blocks.pop();
  13036. }
  13037. // If we saw no block tags, put an unstyled one in
  13038. if (chunk.blocks.length === 0) {
  13039. chunk.blocks.push(_extends$4({}, EMPTY_CHUNK, {
  13040. type: 'unstyled',
  13041. depth: 0
  13042. }));
  13043. }
  13044. // Sometimes we start with text that isn't in a block, which is then
  13045. // followed by blocks. Need to fix up the blocks to add in
  13046. // an unstyled block for this content
  13047. if (chunk.text.split('\r').length === chunk.blocks.length + 1) {
  13048. chunk.blocks.unshift({ type: 'unstyled', depth: 0 });
  13049. }
  13050. return { chunk: chunk, entityMap: newEntityMap };
  13051. };
  13052. var convertChunkToContentBlocks = function convertChunkToContentBlocks(chunk) {
  13053. if (!chunk || !chunk.text || !Array.isArray(chunk.blocks)) {
  13054. return null;
  13055. }
  13056. var initialState = {
  13057. cacheRef: {},
  13058. contentBlocks: []
  13059. };
  13060. var start = 0;
  13061. var rawBlocks = chunk.blocks,
  13062. rawInlines = chunk.inlines,
  13063. rawEntities = chunk.entities;
  13064. var BlockNodeRecord = ContentBlock_1;
  13065. return chunk.text.split('\r').reduce(function (acc, textBlock, index) {
  13066. // Make absolutely certain that our text is acceptable.
  13067. textBlock = sanitizeDraftText_1(textBlock);
  13068. var block = rawBlocks[index];
  13069. var end = start + textBlock.length;
  13070. var inlines = rawInlines.slice(start, end);
  13071. var entities = rawEntities.slice(start, end);
  13072. var characterList = List$a(inlines.map(function (style, index) {
  13073. var data = { style: style, entity: null };
  13074. if (entities[index]) {
  13075. data.entity = entities[index];
  13076. }
  13077. return CharacterMetadata_1.create(data);
  13078. }));
  13079. start = end + 1;
  13080. var depth = block.depth,
  13081. type = block.type,
  13082. parent = block.parent;
  13083. var key = block.key || generateRandomKey_1();
  13084. var parentTextNodeKey = null; // will be used to store container text nodes
  13085. // childrens add themselves to their parents since we are iterating in order
  13086. if (parent) {
  13087. var parentIndex = acc.cacheRef[parent];
  13088. var parentRecord = acc.contentBlocks[parentIndex];
  13089. // if parent has text we need to split it into a separate unstyled element
  13090. if (parentRecord.getChildKeys().isEmpty() && parentRecord.getText()) {
  13091. var parentCharacterList = parentRecord.getCharacterList();
  13092. var parentText = parentRecord.getText();
  13093. parentTextNodeKey = generateRandomKey_1();
  13094. var textNode = new ContentBlockNode_1({
  13095. key: parentTextNodeKey,
  13096. text: parentText,
  13097. characterList: parentCharacterList,
  13098. parent: parent,
  13099. nextSibling: key
  13100. });
  13101. acc.contentBlocks.push(textNode);
  13102. parentRecord = parentRecord.withMutations(function (block) {
  13103. block.set('characterList', List$a()).set('text', '').set('children', parentRecord.children.push(textNode.getKey()));
  13104. });
  13105. }
  13106. acc.contentBlocks[parentIndex] = parentRecord.set('children', parentRecord.children.push(key));
  13107. }
  13108. var blockNode = new BlockNodeRecord({
  13109. key: key,
  13110. parent: parent,
  13111. type: type,
  13112. depth: depth,
  13113. text: textBlock,
  13114. characterList: characterList,
  13115. prevSibling: parentTextNodeKey || (index === 0 || rawBlocks[index - 1].parent !== parent ? null : rawBlocks[index - 1].key),
  13116. nextSibling: index === rawBlocks.length - 1 || rawBlocks[index + 1].parent !== parent ? null : rawBlocks[index + 1].key
  13117. });
  13118. // insert node
  13119. acc.contentBlocks.push(blockNode);
  13120. // cache ref for building links
  13121. acc.cacheRef[blockNode.key] = index;
  13122. return acc;
  13123. }, initialState).contentBlocks;
  13124. };
  13125. var convertFromHTMLtoContentBlocks = function convertFromHTMLtoContentBlocks(html) {
  13126. var DOMBuilder = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : getSafeBodyFromHTML_1;
  13127. var blockRenderMap = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DefaultDraftBlockRenderMap_1;
  13128. // Be ABSOLUTELY SURE that the dom builder you pass here won't execute
  13129. // arbitrary code in whatever environment you're running this in. For an
  13130. // example of how we try to do this in-browser, see getSafeBodyFromHTML.
  13131. // TODO: replace DraftEntity with an OrderedMap here
  13132. var chunkData = getChunkForHTML(html, DOMBuilder, blockRenderMap, DraftEntity_1);
  13133. if (chunkData == null) {
  13134. return null;
  13135. }
  13136. var chunk = chunkData.chunk,
  13137. entityMap = chunkData.entityMap;
  13138. var contentBlocks = convertChunkToContentBlocks(chunk);
  13139. return {
  13140. contentBlocks: contentBlocks,
  13141. entityMap: entityMap
  13142. };
  13143. };
  13144. var convertFromHTMLToContentBlocks = convertFromHTMLtoContentBlocks;
  13145. var List$b = immutable.List,
  13146. Repeat$6 = immutable.Repeat;
  13147. var ContentBlockRecord$2 = ContentBlock_1;
  13148. var DraftPasteProcessor = {
  13149. processHTML: function processHTML(html, blockRenderMap) {
  13150. return convertFromHTMLToContentBlocks(html, getSafeBodyFromHTML_1, blockRenderMap);
  13151. },
  13152. processText: function processText(textBlocks, character, type) {
  13153. return textBlocks.reduce(function (acc, textLine, index) {
  13154. textLine = sanitizeDraftText_1(textLine);
  13155. var key = generateRandomKey_1();
  13156. var blockNodeConfig = {
  13157. key: key,
  13158. type: type,
  13159. text: textLine,
  13160. characterList: List$b(Repeat$6(character, textLine.length))
  13161. };
  13162. acc.push(new ContentBlockRecord$2(blockNodeConfig));
  13163. return acc;
  13164. }, []);
  13165. }
  13166. };
  13167. var DraftPasteProcessor_1 = DraftPasteProcessor;
  13168. /**
  13169. * Copyright (c) 2013-present, Facebook, Inc.
  13170. * All rights reserved.
  13171. *
  13172. * This source code is licensed under the BSD-style license found in the
  13173. * LICENSE file in the root directory of this source tree. An additional grant
  13174. * of patent rights can be found in the PATENTS file in the same directory.
  13175. *
  13176. * @providesModule adjustBlockDepthForContentState
  13177. * @format
  13178. *
  13179. */
  13180. function adjustBlockDepthForContentState(contentState, selectionState, adjustment, maxDepth) {
  13181. var startKey = selectionState.getStartKey();
  13182. var endKey = selectionState.getEndKey();
  13183. var blockMap = contentState.getBlockMap();
  13184. var blocks = blockMap.toSeq().skipUntil(function (_, k) {
  13185. return k === startKey;
  13186. }).takeUntil(function (_, k) {
  13187. return k === endKey;
  13188. }).concat([[endKey, blockMap.get(endKey)]]).map(function (block) {
  13189. var depth = block.getDepth() + adjustment;
  13190. depth = Math.max(0, Math.min(depth, maxDepth));
  13191. return block.set('depth', depth);
  13192. });
  13193. blockMap = blockMap.merge(blocks);
  13194. return contentState.merge({
  13195. blockMap: blockMap,
  13196. selectionBefore: selectionState,
  13197. selectionAfter: selectionState
  13198. });
  13199. }
  13200. var adjustBlockDepthForContentState_1 = adjustBlockDepthForContentState;
  13201. var RichTextEditorUtil = {
  13202. currentBlockContainsLink: function currentBlockContainsLink(editorState) {
  13203. var selection = editorState.getSelection();
  13204. var contentState = editorState.getCurrentContent();
  13205. var entityMap = contentState.getEntityMap();
  13206. return contentState.getBlockForKey(selection.getAnchorKey()).getCharacterList().slice(selection.getStartOffset(), selection.getEndOffset()).some(function (v) {
  13207. var entity = v.getEntity();
  13208. return !!entity && entityMap.__get(entity).getType() === 'LINK';
  13209. });
  13210. },
  13211. getCurrentBlockType: function getCurrentBlockType(editorState) {
  13212. var selection = editorState.getSelection();
  13213. return editorState.getCurrentContent().getBlockForKey(selection.getStartKey()).getType();
  13214. },
  13215. getDataObjectForLinkURL: function getDataObjectForLinkURL(uri) {
  13216. return { url: uri.toString() };
  13217. },
  13218. handleKeyCommand: function handleKeyCommand(editorState, command) {
  13219. switch (command) {
  13220. case 'bold':
  13221. return RichTextEditorUtil.toggleInlineStyle(editorState, 'BOLD');
  13222. case 'italic':
  13223. return RichTextEditorUtil.toggleInlineStyle(editorState, 'ITALIC');
  13224. case 'underline':
  13225. return RichTextEditorUtil.toggleInlineStyle(editorState, 'UNDERLINE');
  13226. case 'code':
  13227. return RichTextEditorUtil.toggleCode(editorState);
  13228. case 'backspace':
  13229. case 'backspace-word':
  13230. case 'backspace-to-start-of-line':
  13231. return RichTextEditorUtil.onBackspace(editorState);
  13232. case 'delete':
  13233. case 'delete-word':
  13234. case 'delete-to-end-of-block':
  13235. return RichTextEditorUtil.onDelete(editorState);
  13236. default:
  13237. // they may have custom editor commands; ignore those
  13238. return null;
  13239. }
  13240. },
  13241. insertSoftNewline: function insertSoftNewline(editorState) {
  13242. var contentState = DraftModifier_1.insertText(editorState.getCurrentContent(), editorState.getSelection(), '\n', editorState.getCurrentInlineStyle(), null);
  13243. var newEditorState = EditorState_1.push(editorState, contentState, 'insert-characters');
  13244. return EditorState_1.forceSelection(newEditorState, contentState.getSelectionAfter());
  13245. },
  13246. /**
  13247. * For collapsed selections at the start of styled blocks, backspace should
  13248. * just remove the existing style.
  13249. */
  13250. onBackspace: function onBackspace(editorState) {
  13251. var selection = editorState.getSelection();
  13252. if (!selection.isCollapsed() || selection.getAnchorOffset() || selection.getFocusOffset()) {
  13253. return null;
  13254. }
  13255. // First, try to remove a preceding atomic block.
  13256. var content = editorState.getCurrentContent();
  13257. var startKey = selection.getStartKey();
  13258. var blockBefore = content.getBlockBefore(startKey);
  13259. if (blockBefore && blockBefore.getType() === 'atomic') {
  13260. var blockMap = content.getBlockMap()['delete'](blockBefore.getKey());
  13261. var withoutAtomicBlock = content.merge({
  13262. blockMap: blockMap,
  13263. selectionAfter: selection
  13264. });
  13265. if (withoutAtomicBlock !== content) {
  13266. return EditorState_1.push(editorState, withoutAtomicBlock, 'remove-range');
  13267. }
  13268. }
  13269. // If that doesn't succeed, try to remove the current block style.
  13270. var withoutBlockStyle = RichTextEditorUtil.tryToRemoveBlockStyle(editorState);
  13271. if (withoutBlockStyle) {
  13272. return EditorState_1.push(editorState, withoutBlockStyle, 'change-block-type');
  13273. }
  13274. return null;
  13275. },
  13276. onDelete: function onDelete(editorState) {
  13277. var selection = editorState.getSelection();
  13278. if (!selection.isCollapsed()) {
  13279. return null;
  13280. }
  13281. var content = editorState.getCurrentContent();
  13282. var startKey = selection.getStartKey();
  13283. var block = content.getBlockForKey(startKey);
  13284. var length = block.getLength();
  13285. // The cursor is somewhere within the text. Behave normally.
  13286. if (selection.getStartOffset() < length) {
  13287. return null;
  13288. }
  13289. var blockAfter = content.getBlockAfter(startKey);
  13290. if (!blockAfter || blockAfter.getType() !== 'atomic') {
  13291. return null;
  13292. }
  13293. var atomicBlockTarget = selection.merge({
  13294. focusKey: blockAfter.getKey(),
  13295. focusOffset: blockAfter.getLength()
  13296. });
  13297. var withoutAtomicBlock = DraftModifier_1.removeRange(content, atomicBlockTarget, 'forward');
  13298. if (withoutAtomicBlock !== content) {
  13299. return EditorState_1.push(editorState, withoutAtomicBlock, 'remove-range');
  13300. }
  13301. return null;
  13302. },
  13303. onTab: function onTab(event, editorState, maxDepth) {
  13304. var selection = editorState.getSelection();
  13305. var key = selection.getAnchorKey();
  13306. if (key !== selection.getFocusKey()) {
  13307. return editorState;
  13308. }
  13309. var content = editorState.getCurrentContent();
  13310. var block = content.getBlockForKey(key);
  13311. var type = block.getType();
  13312. if (type !== 'unordered-list-item' && type !== 'ordered-list-item') {
  13313. return editorState;
  13314. }
  13315. event.preventDefault();
  13316. // Only allow indenting one level beyond the block above, and only if
  13317. // the block above is a list item as well.
  13318. var blockAbove = content.getBlockBefore(key);
  13319. if (!blockAbove) {
  13320. return editorState;
  13321. }
  13322. var typeAbove = blockAbove.getType();
  13323. if (typeAbove !== 'unordered-list-item' && typeAbove !== 'ordered-list-item') {
  13324. return editorState;
  13325. }
  13326. var depth = block.getDepth();
  13327. if (!event.shiftKey && depth === maxDepth) {
  13328. return editorState;
  13329. }
  13330. maxDepth = Math.min(blockAbove.getDepth() + 1, maxDepth);
  13331. var withAdjustment = adjustBlockDepthForContentState_1(content, selection, event.shiftKey ? -1 : 1, maxDepth);
  13332. return EditorState_1.push(editorState, withAdjustment, 'adjust-depth');
  13333. },
  13334. toggleBlockType: function toggleBlockType(editorState, blockType) {
  13335. var selection = editorState.getSelection();
  13336. var startKey = selection.getStartKey();
  13337. var endKey = selection.getEndKey();
  13338. var content = editorState.getCurrentContent();
  13339. var target = selection;
  13340. // Triple-click can lead to a selection that includes offset 0 of the
  13341. // following block. The `SelectionState` for this case is accurate, but
  13342. // we should avoid toggling block type for the trailing block because it
  13343. // is a confusing interaction.
  13344. if (startKey !== endKey && selection.getEndOffset() === 0) {
  13345. var blockBefore = nullthrows_1(content.getBlockBefore(endKey));
  13346. endKey = blockBefore.getKey();
  13347. target = target.merge({
  13348. anchorKey: startKey,
  13349. anchorOffset: selection.getStartOffset(),
  13350. focusKey: endKey,
  13351. focusOffset: blockBefore.getLength(),
  13352. isBackward: false
  13353. });
  13354. }
  13355. var hasAtomicBlock = content.getBlockMap().skipWhile(function (_, k) {
  13356. return k !== startKey;
  13357. }).reverse().skipWhile(function (_, k) {
  13358. return k !== endKey;
  13359. }).some(function (v) {
  13360. return v.getType() === 'atomic';
  13361. });
  13362. if (hasAtomicBlock) {
  13363. return editorState;
  13364. }
  13365. var typeToSet = content.getBlockForKey(startKey).getType() === blockType ? 'unstyled' : blockType;
  13366. return EditorState_1.push(editorState, DraftModifier_1.setBlockType(content, target, typeToSet), 'change-block-type');
  13367. },
  13368. toggleCode: function toggleCode(editorState) {
  13369. var selection = editorState.getSelection();
  13370. var anchorKey = selection.getAnchorKey();
  13371. var focusKey = selection.getFocusKey();
  13372. if (selection.isCollapsed() || anchorKey !== focusKey) {
  13373. return RichTextEditorUtil.toggleBlockType(editorState, 'code-block');
  13374. }
  13375. return RichTextEditorUtil.toggleInlineStyle(editorState, 'CODE');
  13376. },
  13377. /**
  13378. * Toggle the specified inline style for the selection. If the
  13379. * user's selection is collapsed, apply or remove the style for the
  13380. * internal state. If it is not collapsed, apply the change directly
  13381. * to the document state.
  13382. */
  13383. toggleInlineStyle: function toggleInlineStyle(editorState, inlineStyle) {
  13384. var selection = editorState.getSelection();
  13385. var currentStyle = editorState.getCurrentInlineStyle();
  13386. // If the selection is collapsed, toggle the specified style on or off and
  13387. // set the result as the new inline style override. This will then be
  13388. // used as the inline style for the next character to be inserted.
  13389. if (selection.isCollapsed()) {
  13390. return EditorState_1.setInlineStyleOverride(editorState, currentStyle.has(inlineStyle) ? currentStyle.remove(inlineStyle) : currentStyle.add(inlineStyle));
  13391. }
  13392. // If characters are selected, immediately apply or remove the
  13393. // inline style on the document state itself.
  13394. var content = editorState.getCurrentContent();
  13395. var newContent;
  13396. // If the style is already present for the selection range, remove it.
  13397. // Otherwise, apply it.
  13398. if (currentStyle.has(inlineStyle)) {
  13399. newContent = DraftModifier_1.removeInlineStyle(content, selection, inlineStyle);
  13400. } else {
  13401. newContent = DraftModifier_1.applyInlineStyle(content, selection, inlineStyle);
  13402. }
  13403. return EditorState_1.push(editorState, newContent, 'change-inline-style');
  13404. },
  13405. toggleLink: function toggleLink(editorState, targetSelection, entityKey) {
  13406. var withoutLink = DraftModifier_1.applyEntity(editorState.getCurrentContent(), targetSelection, entityKey);
  13407. return EditorState_1.push(editorState, withoutLink, 'apply-entity');
  13408. },
  13409. /**
  13410. * When a collapsed cursor is at the start of the first styled block, or
  13411. * an empty styled block, changes block to 'unstyled'. Returns null if
  13412. * block or selection does not meet that criteria.
  13413. */
  13414. tryToRemoveBlockStyle: function tryToRemoveBlockStyle(editorState) {
  13415. var selection = editorState.getSelection();
  13416. var offset = selection.getAnchorOffset();
  13417. if (selection.isCollapsed() && offset === 0) {
  13418. var key = selection.getAnchorKey();
  13419. var content = editorState.getCurrentContent();
  13420. var block = content.getBlockForKey(key);
  13421. var firstBlock = content.getFirstBlock();
  13422. if (block.getLength() > 0 && block !== firstBlock) {
  13423. return null;
  13424. }
  13425. var type = block.getType();
  13426. var blockBefore = content.getBlockBefore(key);
  13427. if (type === 'code-block' && blockBefore && blockBefore.getType() === 'code-block' && blockBefore.getLength() !== 0) {
  13428. return null;
  13429. }
  13430. if (type !== 'unstyled') {
  13431. return DraftModifier_1.setBlockType(content, selection, 'unstyled');
  13432. }
  13433. }
  13434. return null;
  13435. }
  13436. };
  13437. var RichTextEditorUtil_1 = RichTextEditorUtil;
  13438. /**
  13439. * Copyright (c) 2013-present, Facebook, Inc.
  13440. * All rights reserved.
  13441. *
  13442. * This source code is licensed under the BSD-style license found in the
  13443. * LICENSE file in the root directory of this source tree. An additional grant
  13444. * of patent rights can be found in the PATENTS file in the same directory.
  13445. *
  13446. * @providesModule splitTextIntoTextBlocks
  13447. * @format
  13448. *
  13449. */
  13450. var NEWLINE_REGEX = /\r\n?|\n/g;
  13451. function splitTextIntoTextBlocks(text) {
  13452. return text.split(NEWLINE_REGEX);
  13453. }
  13454. var splitTextIntoTextBlocks_1 = splitTextIntoTextBlocks;
  13455. /**
  13456. * Paste content.
  13457. */
  13458. function editOnPaste(editor, e) {
  13459. e.preventDefault();
  13460. var data = new DataTransfer_1(e.clipboardData);
  13461. // Get files, unless this is likely to be a string the user wants inline.
  13462. if (!data.isRichText()) {
  13463. var files = data.getFiles();
  13464. var defaultFileText = data.getText();
  13465. if (files.length > 0) {
  13466. // Allow customized paste handling for images, etc. Otherwise, fall
  13467. // through to insert text contents into the editor.
  13468. if (editor.props.handlePastedFiles && isEventHandled_1(editor.props.handlePastedFiles(files))) {
  13469. return;
  13470. }
  13471. getTextContentFromFiles_1(files, function ( /*string*/fileText) {
  13472. fileText = fileText || defaultFileText;
  13473. if (!fileText) {
  13474. return;
  13475. }
  13476. var editorState = editor._latestEditorState;
  13477. var blocks = splitTextIntoTextBlocks_1(fileText);
  13478. var character = CharacterMetadata_1.create({
  13479. style: editorState.getCurrentInlineStyle(),
  13480. entity: getEntityKeyForSelection_1(editorState.getCurrentContent(), editorState.getSelection())
  13481. });
  13482. var currentBlockType = RichTextEditorUtil_1.getCurrentBlockType(editorState);
  13483. var text = DraftPasteProcessor_1.processText(blocks, character, currentBlockType);
  13484. var fragment = BlockMapBuilder_1.createFromArray(text);
  13485. var withInsertedText = DraftModifier_1.replaceWithFragment(editorState.getCurrentContent(), editorState.getSelection(), fragment);
  13486. editor.update(EditorState_1.push(editorState, withInsertedText, 'insert-fragment'));
  13487. });
  13488. return;
  13489. }
  13490. }
  13491. var textBlocks = [];
  13492. var text = data.getText();
  13493. var html = data.getHTML();
  13494. var editorState = editor._latestEditorState;
  13495. if (editor.props.handlePastedText && isEventHandled_1(editor.props.handlePastedText(text, html, editorState))) {
  13496. return;
  13497. }
  13498. if (text) {
  13499. textBlocks = splitTextIntoTextBlocks_1(text);
  13500. }
  13501. if (!editor.props.stripPastedStyles) {
  13502. // If the text from the paste event is rich content that matches what we
  13503. // already have on the internal clipboard, assume that we should just use
  13504. // the clipboard fragment for the paste. This will allow us to preserve
  13505. // styling and entities, if any are present. Note that newlines are
  13506. // stripped during comparison -- this is because copy/paste within the
  13507. // editor in Firefox and IE will not include empty lines. The resulting
  13508. // paste will preserve the newlines correctly.
  13509. var internalClipboard = editor.getClipboard();
  13510. if (data.isRichText() && internalClipboard) {
  13511. if (
  13512. // If the editorKey is present in the pasted HTML, it should be safe to
  13513. // assume this is an internal paste.
  13514. html.indexOf(editor.getEditorKey()) !== -1 ||
  13515. // The copy may have been made within a single block, in which case the
  13516. // editor key won't be part of the paste. In this case, just check
  13517. // whether the pasted text matches the internal clipboard.
  13518. textBlocks.length === 1 && internalClipboard.size === 1 && internalClipboard.first().getText() === text) {
  13519. editor.update(insertFragment$1(editor._latestEditorState, internalClipboard));
  13520. return;
  13521. }
  13522. } else if (internalClipboard && data.types.includes('com.apple.webarchive') && !data.types.includes('text/html') && areTextBlocksAndClipboardEqual(textBlocks, internalClipboard)) {
  13523. // Safari does not properly store text/html in some cases.
  13524. // Use the internalClipboard if present and equal to what is on
  13525. // the clipboard. See https://bugs.webkit.org/show_bug.cgi?id=19893.
  13526. editor.update(insertFragment$1(editor._latestEditorState, internalClipboard));
  13527. return;
  13528. }
  13529. // If there is html paste data, try to parse that.
  13530. if (html) {
  13531. var htmlFragment = DraftPasteProcessor_1.processHTML(html, editor.props.blockRenderMap);
  13532. if (htmlFragment) {
  13533. var contentBlocks = htmlFragment.contentBlocks,
  13534. entityMap = htmlFragment.entityMap;
  13535. if (contentBlocks) {
  13536. var htmlMap = BlockMapBuilder_1.createFromArray(contentBlocks);
  13537. editor.update(insertFragment$1(editor._latestEditorState, htmlMap, entityMap));
  13538. return;
  13539. }
  13540. }
  13541. }
  13542. // Otherwise, create a new fragment from our pasted text. Also
  13543. // empty the internal clipboard, since it's no longer valid.
  13544. editor.setClipboard(null);
  13545. }
  13546. if (textBlocks.length) {
  13547. var character = CharacterMetadata_1.create({
  13548. style: editorState.getCurrentInlineStyle(),
  13549. entity: getEntityKeyForSelection_1(editorState.getCurrentContent(), editorState.getSelection())
  13550. });
  13551. var currentBlockType = RichTextEditorUtil_1.getCurrentBlockType(editorState);
  13552. var textFragment = DraftPasteProcessor_1.processText(textBlocks, character, currentBlockType);
  13553. var textMap = BlockMapBuilder_1.createFromArray(textFragment);
  13554. editor.update(insertFragment$1(editor._latestEditorState, textMap));
  13555. }
  13556. }
  13557. function insertFragment$1(editorState, fragment, entityMap) {
  13558. var newContent = DraftModifier_1.replaceWithFragment(editorState.getCurrentContent(), editorState.getSelection(), fragment);
  13559. // TODO: merge the entity map once we stop using DraftEntity
  13560. // like this:
  13561. // const mergedEntityMap = newContent.getEntityMap().merge(entityMap);
  13562. return EditorState_1.push(editorState, newContent.set('entityMap', entityMap), 'insert-fragment');
  13563. }
  13564. function areTextBlocksAndClipboardEqual(textBlocks, blockMap) {
  13565. return textBlocks.length === blockMap.size && blockMap.valueSeq().every(function (block, ii) {
  13566. return block.getText() === textBlocks[ii];
  13567. });
  13568. }
  13569. var editOnPaste_1 = editOnPaste;
  13570. /**
  13571. * Convert the current selection range to an anchor/focus pair of offset keys
  13572. * and values that can be interpreted by components.
  13573. */
  13574. function getDraftEditorSelection(editorState, root) {
  13575. var selection = _commonjsHelpers.commonjsGlobal.getSelection();
  13576. // No active selection.
  13577. if (selection.rangeCount === 0) {
  13578. return {
  13579. selectionState: editorState.getSelection().set('hasFocus', false),
  13580. needsRecovery: false
  13581. };
  13582. }
  13583. return getDraftEditorSelectionWithNodes_1(editorState, root, selection.anchorNode, selection.anchorOffset, selection.focusNode, selection.focusOffset);
  13584. }
  13585. var getDraftEditorSelection_1 = getDraftEditorSelection;
  13586. function editOnSelect(editor) {
  13587. if (editor._blockSelectEvents || editor._latestEditorState !== editor.props.editorState) {
  13588. return;
  13589. }
  13590. var editorState = editor.props.editorState;
  13591. var editorNode = reactDom__default.findDOMNode(editor.editorContainer);
  13592. !editorNode ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing editorNode') : invariant_1(false) : void 0;
  13593. !(editorNode.firstChild instanceof HTMLElement) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'editorNode.firstChild is not an HTMLElement') : invariant_1(false) : void 0;
  13594. var documentSelection = getDraftEditorSelection_1(editorState, editorNode.firstChild);
  13595. var updatedSelectionState = documentSelection.selectionState;
  13596. if (updatedSelectionState !== editorState.getSelection()) {
  13597. if (documentSelection.needsRecovery) {
  13598. editorState = EditorState_1.forceSelection(editorState, updatedSelectionState);
  13599. } else {
  13600. editorState = EditorState_1.acceptSelection(editorState, updatedSelectionState);
  13601. }
  13602. editor.update(editorState);
  13603. }
  13604. }
  13605. var editOnSelect_1 = editOnSelect;
  13606. var DraftEditorEditHandler = {
  13607. onBeforeInput: editOnBeforeInput_1,
  13608. onBlur: editOnBlur_1,
  13609. onCompositionStart: editOnCompositionStart_1,
  13610. onCopy: editOnCopy_1,
  13611. onCut: editOnCut_1,
  13612. onDragOver: editOnDragOver_1,
  13613. onDragStart: editOnDragStart_1,
  13614. onFocus: editOnFocus_1,
  13615. onInput: editOnInput_1,
  13616. onKeyDown: editOnKeyDown_1,
  13617. onPaste: editOnPaste_1,
  13618. onSelect: editOnSelect_1
  13619. };
  13620. var DraftEditorEditHandler_1 = DraftEditorEditHandler;
  13621. function _classCallCheck$f(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13622. function _possibleConstructorReturn$a(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  13623. function _inherits$a(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  13624. /**
  13625. * This component is responsible for rendering placeholder text for the
  13626. * `DraftEditor` component.
  13627. *
  13628. * Override placeholder style via CSS.
  13629. */
  13630. var DraftEditorPlaceholder = function (_React$Component) {
  13631. _inherits$a(DraftEditorPlaceholder, _React$Component);
  13632. function DraftEditorPlaceholder() {
  13633. _classCallCheck$f(this, DraftEditorPlaceholder);
  13634. return _possibleConstructorReturn$a(this, _React$Component.apply(this, arguments));
  13635. }
  13636. DraftEditorPlaceholder.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
  13637. return this.props.text !== nextProps.text || this.props.editorState.getSelection().getHasFocus() !== nextProps.editorState.getSelection().getHasFocus();
  13638. };
  13639. DraftEditorPlaceholder.prototype.render = function render() {
  13640. var hasFocus = this.props.editorState.getSelection().getHasFocus();
  13641. var className = cx_1({
  13642. 'public/DraftEditorPlaceholder/root': true,
  13643. 'public/DraftEditorPlaceholder/hasFocus': hasFocus
  13644. });
  13645. var contentStyle = {
  13646. whiteSpace: 'pre-wrap'
  13647. };
  13648. return React__default.createElement(
  13649. 'div',
  13650. { className: className },
  13651. React__default.createElement(
  13652. 'div',
  13653. {
  13654. className: cx_1('public/DraftEditorPlaceholder/inner'),
  13655. id: this.props.accessibilityID,
  13656. style: contentStyle },
  13657. this.props.text
  13658. )
  13659. );
  13660. };
  13661. return DraftEditorPlaceholder;
  13662. }(React__default.Component);
  13663. var DraftEditorPlaceholder_react = DraftEditorPlaceholder;
  13664. var isOSX$1 = UserAgent_1.isPlatform('Mac OS X');
  13665. var isWindows = UserAgent_1.isPlatform('Windows');
  13666. // Firefox on OSX had a bug resulting in navigation instead of cursor movement.
  13667. // This bug was fixed in Firefox 29. Feature detection is virtually impossible
  13668. // so we just check the version number. See #342765.
  13669. var shouldFixFirefoxMovement = isOSX$1 && UserAgent_1.isBrowser('Firefox < 29');
  13670. var hasCommandModifier = KeyBindingUtil_1.hasCommandModifier,
  13671. isCtrlKeyCommand = KeyBindingUtil_1.isCtrlKeyCommand;
  13672. function shouldRemoveWord(e) {
  13673. return isOSX$1 && e.altKey || isCtrlKeyCommand(e);
  13674. }
  13675. /**
  13676. * Get the appropriate undo/redo command for a Z key command.
  13677. */
  13678. function getZCommand(e) {
  13679. if (!hasCommandModifier(e)) {
  13680. return null;
  13681. }
  13682. return e.shiftKey ? 'redo' : 'undo';
  13683. }
  13684. function getDeleteCommand(e) {
  13685. // Allow default "cut" behavior for Windows on Shift + Delete.
  13686. if (isWindows && e.shiftKey) {
  13687. return null;
  13688. }
  13689. return shouldRemoveWord(e) ? 'delete-word' : 'delete';
  13690. }
  13691. function getBackspaceCommand(e) {
  13692. if (hasCommandModifier(e) && isOSX$1) {
  13693. return 'backspace-to-start-of-line';
  13694. }
  13695. return shouldRemoveWord(e) ? 'backspace-word' : 'backspace';
  13696. }
  13697. /**
  13698. * Retrieve a bound key command for the given event.
  13699. */
  13700. function getDefaultKeyBinding(e) {
  13701. switch (e.keyCode) {
  13702. case 66:
  13703. // B
  13704. return hasCommandModifier(e) ? 'bold' : null;
  13705. case 68:
  13706. // D
  13707. return isCtrlKeyCommand(e) ? 'delete' : null;
  13708. case 72:
  13709. // H
  13710. return isCtrlKeyCommand(e) ? 'backspace' : null;
  13711. case 73:
  13712. // I
  13713. return hasCommandModifier(e) ? 'italic' : null;
  13714. case 74:
  13715. // J
  13716. return hasCommandModifier(e) ? 'code' : null;
  13717. case 75:
  13718. // K
  13719. return !isWindows && isCtrlKeyCommand(e) ? 'secondary-cut' : null;
  13720. case 77:
  13721. // M
  13722. return isCtrlKeyCommand(e) ? 'split-block' : null;
  13723. case 79:
  13724. // O
  13725. return isCtrlKeyCommand(e) ? 'split-block' : null;
  13726. case 84:
  13727. // T
  13728. return isOSX$1 && isCtrlKeyCommand(e) ? 'transpose-characters' : null;
  13729. case 85:
  13730. // U
  13731. return hasCommandModifier(e) ? 'underline' : null;
  13732. case 87:
  13733. // W
  13734. return isOSX$1 && isCtrlKeyCommand(e) ? 'backspace-word' : null;
  13735. case 89:
  13736. // Y
  13737. if (isCtrlKeyCommand(e)) {
  13738. return isWindows ? 'redo' : 'secondary-paste';
  13739. }
  13740. return null;
  13741. case 90:
  13742. // Z
  13743. return getZCommand(e) || null;
  13744. case Keys.RETURN:
  13745. return 'split-block';
  13746. case Keys.DELETE:
  13747. return getDeleteCommand(e);
  13748. case Keys.BACKSPACE:
  13749. return getBackspaceCommand(e);
  13750. // LEFT/RIGHT handlers serve as a workaround for a Firefox bug.
  13751. case Keys.LEFT:
  13752. return shouldFixFirefoxMovement && hasCommandModifier(e) ? 'move-selection-to-start-of-block' : null;
  13753. case Keys.RIGHT:
  13754. return shouldFixFirefoxMovement && hasCommandModifier(e) ? 'move-selection-to-end-of-block' : null;
  13755. default:
  13756. return null;
  13757. }
  13758. }
  13759. var getDefaultKeyBinding_1 = getDefaultKeyBinding;
  13760. var _extends$5 = objectAssign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  13761. function _classCallCheck$g(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13762. function _possibleConstructorReturn$b(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  13763. function _inherits$b(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  13764. var isIE = UserAgent_1.isBrowser('IE');
  13765. // IE does not support the `input` event on contentEditable, so we can't
  13766. // observe spellcheck behavior.
  13767. var allowSpellCheck = !isIE;
  13768. // Define a set of handler objects to correspond to each possible `mode`
  13769. // of editor behavior.
  13770. var handlerMap = {
  13771. edit: DraftEditorEditHandler_1,
  13772. composite: DraftEditorCompositionHandler_1,
  13773. drag: DraftEditorDragHandler_1,
  13774. cut: null,
  13775. render: null
  13776. };
  13777. /**
  13778. * `DraftEditor` is the root editor component. It composes a `contentEditable`
  13779. * div, and provides a wide variety of useful function props for managing the
  13780. * state of the editor. See `DraftEditorProps` for details.
  13781. */
  13782. var DraftEditor = function (_React$Component) {
  13783. _inherits$b(DraftEditor, _React$Component);
  13784. function DraftEditor(props) {
  13785. _classCallCheck$g(this, DraftEditor);
  13786. var _this = _possibleConstructorReturn$b(this, _React$Component.call(this, props));
  13787. _this.focus = function (scrollPosition) {
  13788. var editorState = _this.props.editorState;
  13789. var alreadyHasFocus = editorState.getSelection().getHasFocus();
  13790. var editorNode = reactDom__default.findDOMNode(_this.editor);
  13791. if (!editorNode) {
  13792. // once in a while people call 'focus' in a setTimeout, and the node has
  13793. // been deleted, so it can be null in that case.
  13794. return;
  13795. }
  13796. var scrollParent = Style_1.getScrollParent(editorNode);
  13797. var _ref = scrollPosition || getScrollPosition_1(scrollParent),
  13798. x = _ref.x,
  13799. y = _ref.y;
  13800. !(editorNode instanceof HTMLElement) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'editorNode is not an HTMLElement') : invariant_1(false) : void 0;
  13801. editorNode.focus();
  13802. // Restore scroll position
  13803. if (scrollParent === window) {
  13804. window.scrollTo(x, y);
  13805. } else {
  13806. Scroll_1.setTop(scrollParent, y);
  13807. }
  13808. // On Chrome and Safari, calling focus on contenteditable focuses the
  13809. // cursor at the first character. This is something you don't expect when
  13810. // you're clicking on an input element but not directly on a character.
  13811. // Put the cursor back where it was before the blur.
  13812. if (!alreadyHasFocus) {
  13813. _this.update(EditorState_1.forceSelection(editorState, editorState.getSelection()));
  13814. }
  13815. };
  13816. _this.blur = function () {
  13817. var editorNode = reactDom__default.findDOMNode(_this.editor);
  13818. !(editorNode instanceof HTMLElement) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'editorNode is not an HTMLElement') : invariant_1(false) : void 0;
  13819. editorNode.blur();
  13820. };
  13821. _this.setMode = function (mode) {
  13822. _this._handler = handlerMap[mode];
  13823. };
  13824. _this.exitCurrentMode = function () {
  13825. _this.setMode('edit');
  13826. };
  13827. _this.restoreEditorDOM = function (scrollPosition) {
  13828. _this.setState({ contentsKey: _this.state.contentsKey + 1 }, function () {
  13829. _this.focus(scrollPosition);
  13830. });
  13831. };
  13832. _this.setClipboard = function (clipboard) {
  13833. _this._clipboard = clipboard;
  13834. };
  13835. _this.getClipboard = function () {
  13836. return _this._clipboard;
  13837. };
  13838. _this.update = function (editorState) {
  13839. _this._latestEditorState = editorState;
  13840. _this.props.onChange(editorState);
  13841. };
  13842. _this.onDragEnter = function () {
  13843. _this._dragCount++;
  13844. };
  13845. _this.onDragLeave = function () {
  13846. _this._dragCount--;
  13847. if (_this._dragCount === 0) {
  13848. _this.exitCurrentMode();
  13849. }
  13850. };
  13851. _this._blockSelectEvents = false;
  13852. _this._clipboard = null;
  13853. _this._handler = null;
  13854. _this._dragCount = 0;
  13855. _this._editorKey = props.editorKey || generateRandomKey_1();
  13856. _this._placeholderAccessibilityID = 'placeholder-' + _this._editorKey;
  13857. _this._latestEditorState = props.editorState;
  13858. _this._latestCommittedEditorState = props.editorState;
  13859. _this._onBeforeInput = _this._buildHandler('onBeforeInput');
  13860. _this._onBlur = _this._buildHandler('onBlur');
  13861. _this._onCharacterData = _this._buildHandler('onCharacterData');
  13862. _this._onCompositionEnd = _this._buildHandler('onCompositionEnd');
  13863. _this._onCompositionStart = _this._buildHandler('onCompositionStart');
  13864. _this._onCopy = _this._buildHandler('onCopy');
  13865. _this._onCut = _this._buildHandler('onCut');
  13866. _this._onDragEnd = _this._buildHandler('onDragEnd');
  13867. _this._onDragOver = _this._buildHandler('onDragOver');
  13868. _this._onDragStart = _this._buildHandler('onDragStart');
  13869. _this._onDrop = _this._buildHandler('onDrop');
  13870. _this._onInput = _this._buildHandler('onInput');
  13871. _this._onFocus = _this._buildHandler('onFocus');
  13872. _this._onKeyDown = _this._buildHandler('onKeyDown');
  13873. _this._onKeyPress = _this._buildHandler('onKeyPress');
  13874. _this._onKeyUp = _this._buildHandler('onKeyUp');
  13875. _this._onMouseDown = _this._buildHandler('onMouseDown');
  13876. _this._onMouseUp = _this._buildHandler('onMouseUp');
  13877. _this._onPaste = _this._buildHandler('onPaste');
  13878. _this._onSelect = _this._buildHandler('onSelect');
  13879. _this.getEditorKey = function () {
  13880. return _this._editorKey;
  13881. };
  13882. // See `restoreEditorDOM()`.
  13883. _this.state = { contentsKey: 0 };
  13884. return _this;
  13885. }
  13886. /**
  13887. * Build a method that will pass the event to the specified handler method.
  13888. * This allows us to look up the correct handler function for the current
  13889. * editor mode, if any has been specified.
  13890. */
  13891. /**
  13892. * Define proxies that can route events to the current handler.
  13893. */
  13894. DraftEditor.prototype._buildHandler = function _buildHandler(eventName) {
  13895. var _this2 = this;
  13896. return function (e) {
  13897. if (!_this2.props.readOnly) {
  13898. var method = _this2._handler && _this2._handler[eventName];
  13899. method && method(_this2, e);
  13900. }
  13901. };
  13902. };
  13903. DraftEditor.prototype._showPlaceholder = function _showPlaceholder() {
  13904. return !!this.props.placeholder && !this.props.editorState.isInCompositionMode() && !this.props.editorState.getCurrentContent().hasText();
  13905. };
  13906. DraftEditor.prototype._renderPlaceholder = function _renderPlaceholder() {
  13907. if (this._showPlaceholder()) {
  13908. var placeHolderProps = {
  13909. text: nullthrows_1(this.props.placeholder),
  13910. editorState: this.props.editorState,
  13911. textAlignment: this.props.textAlignment,
  13912. accessibilityID: this._placeholderAccessibilityID
  13913. };
  13914. return React__default.createElement(DraftEditorPlaceholder_react, placeHolderProps);
  13915. }
  13916. return null;
  13917. };
  13918. DraftEditor.prototype.render = function render() {
  13919. var _this3 = this;
  13920. var _props = this.props,
  13921. blockRenderMap = _props.blockRenderMap,
  13922. blockRendererFn = _props.blockRendererFn,
  13923. blockStyleFn = _props.blockStyleFn,
  13924. customStyleFn = _props.customStyleFn,
  13925. customStyleMap = _props.customStyleMap,
  13926. editorState = _props.editorState,
  13927. readOnly = _props.readOnly,
  13928. textAlignment = _props.textAlignment,
  13929. textDirectionality = _props.textDirectionality;
  13930. var rootClass = cx_1({
  13931. 'DraftEditor/root': true,
  13932. 'DraftEditor/alignLeft': textAlignment === 'left',
  13933. 'DraftEditor/alignRight': textAlignment === 'right',
  13934. 'DraftEditor/alignCenter': textAlignment === 'center'
  13935. });
  13936. var contentStyle = {
  13937. outline: 'none',
  13938. // fix parent-draggable Safari bug. #1326
  13939. userSelect: 'text',
  13940. WebkitUserSelect: 'text',
  13941. whiteSpace: 'pre-wrap',
  13942. wordWrap: 'break-word'
  13943. };
  13944. // The aria-expanded and aria-haspopup properties should only be rendered
  13945. // for a combobox.
  13946. var ariaRole = this.props.role || 'textbox';
  13947. var ariaExpanded = ariaRole === 'combobox' ? !!this.props.ariaExpanded : null;
  13948. var editorContentsProps = {
  13949. blockRenderMap: blockRenderMap,
  13950. blockRendererFn: blockRendererFn,
  13951. blockStyleFn: blockStyleFn,
  13952. customStyleMap: _extends$5({}, DefaultDraftInlineStyle, customStyleMap),
  13953. customStyleFn: customStyleFn,
  13954. editorKey: this._editorKey,
  13955. editorState: editorState,
  13956. key: 'contents' + this.state.contentsKey,
  13957. textDirectionality: textDirectionality
  13958. };
  13959. return React__default.createElement(
  13960. 'div',
  13961. { className: rootClass },
  13962. this._renderPlaceholder(),
  13963. React__default.createElement(
  13964. 'div',
  13965. {
  13966. className: cx_1('DraftEditor/editorContainer'),
  13967. ref: function ref(_ref3) {
  13968. return _this3.editorContainer = _ref3;
  13969. } },
  13970. React__default.createElement(
  13971. 'div',
  13972. {
  13973. 'aria-activedescendant': readOnly ? null : this.props.ariaActiveDescendantID,
  13974. 'aria-autocomplete': readOnly ? null : this.props.ariaAutoComplete,
  13975. 'aria-controls': readOnly ? null : this.props.ariaControls,
  13976. 'aria-describedby': this.props.ariaDescribedBy || this._placeholderAccessibilityID,
  13977. 'aria-expanded': readOnly ? null : ariaExpanded,
  13978. 'aria-label': this.props.ariaLabel,
  13979. 'aria-labelledby': this.props.ariaLabelledBy,
  13980. 'aria-multiline': this.props.ariaMultiline,
  13981. autoCapitalize: this.props.autoCapitalize,
  13982. autoComplete: this.props.autoComplete,
  13983. autoCorrect: this.props.autoCorrect,
  13984. className: cx_1({
  13985. // Chrome's built-in translation feature mutates the DOM in ways
  13986. // that Draft doesn't expect (ex: adding <font> tags inside
  13987. // DraftEditorLeaf spans) and causes problems. We add notranslate
  13988. // here which makes its autotranslation skip over this subtree.
  13989. notranslate: !readOnly,
  13990. 'public/DraftEditor/content': true
  13991. }),
  13992. contentEditable: !readOnly,
  13993. 'data-testid': this.props.webDriverTestID,
  13994. onBeforeInput: this._onBeforeInput,
  13995. onBlur: this._onBlur,
  13996. onCompositionEnd: this._onCompositionEnd,
  13997. onCompositionStart: this._onCompositionStart,
  13998. onCopy: this._onCopy,
  13999. onCut: this._onCut,
  14000. onDragEnd: this._onDragEnd,
  14001. onDragEnter: this.onDragEnter,
  14002. onDragLeave: this.onDragLeave,
  14003. onDragOver: this._onDragOver,
  14004. onDragStart: this._onDragStart,
  14005. onDrop: this._onDrop,
  14006. onFocus: this._onFocus,
  14007. onInput: this._onInput,
  14008. onKeyDown: this._onKeyDown,
  14009. onKeyPress: this._onKeyPress,
  14010. onKeyUp: this._onKeyUp,
  14011. onMouseUp: this._onMouseUp,
  14012. onPaste: this._onPaste,
  14013. onSelect: this._onSelect,
  14014. ref: function ref(_ref2) {
  14015. return _this3.editor = _ref2;
  14016. },
  14017. role: readOnly ? null : ariaRole,
  14018. spellCheck: allowSpellCheck && this.props.spellCheck,
  14019. style: contentStyle,
  14020. suppressContentEditableWarning: true,
  14021. tabIndex: this.props.tabIndex },
  14022. React__default.createElement(DraftEditorContents_react, editorContentsProps)
  14023. )
  14024. )
  14025. );
  14026. };
  14027. DraftEditor.prototype.componentDidMount = function componentDidMount() {
  14028. this.setMode('edit');
  14029. /**
  14030. * IE has a hardcoded "feature" that attempts to convert link text into
  14031. * anchors in contentEditable DOM. This breaks the editor's expectations of
  14032. * the DOM, and control is lost. Disable it to make IE behave.
  14033. * See: http://blogs.msdn.com/b/ieinternals/archive/2010/09/15/
  14034. * ie9-beta-minor-change-list.aspx
  14035. */
  14036. if (isIE) {
  14037. document.execCommand('AutoUrlDetect', false, false);
  14038. }
  14039. };
  14040. /**
  14041. * Prevent selection events from affecting the current editor state. This
  14042. * is mostly intended to defend against IE, which fires off `selectionchange`
  14043. * events regardless of whether the selection is set via the browser or
  14044. * programmatically. We only care about selection events that occur because
  14045. * of browser interaction, not re-renders and forced selections.
  14046. */
  14047. DraftEditor.prototype.componentWillUpdate = function componentWillUpdate(nextProps) {
  14048. this._blockSelectEvents = true;
  14049. this._latestEditorState = nextProps.editorState;
  14050. };
  14051. DraftEditor.prototype.componentDidUpdate = function componentDidUpdate() {
  14052. this._blockSelectEvents = false;
  14053. this._latestCommittedEditorState = this.props.editorState;
  14054. };
  14055. /**
  14056. * Used via `this.focus()`.
  14057. *
  14058. * Force focus back onto the editor node.
  14059. *
  14060. * We attempt to preserve scroll position when focusing. You can also pass
  14061. * a specified scroll position (for cases like `cut` behavior where it should
  14062. * be restored to a known position).
  14063. */
  14064. /**
  14065. * Used via `this.setMode(...)`.
  14066. *
  14067. * Set the behavior mode for the editor component. This switches the current
  14068. * handler module to ensure that DOM events are managed appropriately for
  14069. * the active mode.
  14070. */
  14071. /**
  14072. * Used via `this.restoreEditorDOM()`.
  14073. *
  14074. * Force a complete re-render of the DraftEditorContents based on the current
  14075. * EditorState. This is useful when we know we are going to lose control of
  14076. * the DOM state (cut command, IME) and we want to make sure that
  14077. * reconciliation occurs on a version of the DOM that is synchronized with
  14078. * our EditorState.
  14079. */
  14080. /**
  14081. * Used via `this.setClipboard(...)`.
  14082. *
  14083. * Set the clipboard state for a cut/copy event.
  14084. */
  14085. /**
  14086. * Used via `this.getClipboard()`.
  14087. *
  14088. * Retrieve the clipboard state for a cut/copy event.
  14089. */
  14090. /**
  14091. * Used via `this.update(...)`.
  14092. *
  14093. * Propagate a new `EditorState` object to higher-level components. This is
  14094. * the method by which event handlers inform the `DraftEditor` component of
  14095. * state changes. A component that composes a `DraftEditor` **must** provide
  14096. * an `onChange` prop to receive state updates passed along from this
  14097. * function.
  14098. */
  14099. /**
  14100. * Used in conjunction with `onDragLeave()`, by counting the number of times
  14101. * a dragged element enters and leaves the editor (or any of its children),
  14102. * to determine when the dragged element absolutely leaves the editor.
  14103. */
  14104. /**
  14105. * See `onDragEnter()`.
  14106. */
  14107. return DraftEditor;
  14108. }(React__default.Component);
  14109. DraftEditor.defaultProps = {
  14110. blockRenderMap: DefaultDraftBlockRenderMap_1,
  14111. blockRendererFn: emptyFunction_1.thatReturnsNull,
  14112. blockStyleFn: emptyFunction_1.thatReturns(''),
  14113. keyBindingFn: getDefaultKeyBinding_1,
  14114. readOnly: false,
  14115. spellCheck: false,
  14116. stripPastedStyles: false
  14117. };
  14118. var DraftEditor_react = DraftEditor;
  14119. /**
  14120. * Copyright (c) 2013-present, Facebook, Inc.
  14121. * All rights reserved.
  14122. *
  14123. * This source code is licensed under the BSD-style license found in the
  14124. * LICENSE file in the root directory of this source tree. An additional grant
  14125. * of patent rights can be found in the PATENTS file in the same directory.
  14126. *
  14127. * @providesModule DraftStringKey
  14128. * @format
  14129. *
  14130. */
  14131. var DraftStringKey = {
  14132. stringify: function stringify(key) {
  14133. return '_' + String(key);
  14134. },
  14135. unstringify: function unstringify(key) {
  14136. return key.slice(1);
  14137. }
  14138. };
  14139. var DraftStringKey_1 = DraftStringKey;
  14140. var strlen$1 = UnicodeUtils_1.strlen;
  14141. /**
  14142. * Convert to UTF-8 character counts for storage.
  14143. */
  14144. function encodeEntityRanges(block, storageMap) {
  14145. var encoded = [];
  14146. block.findEntityRanges(function (character) {
  14147. return !!character.getEntity();
  14148. }, function ( /*number*/start, /*number*/end) {
  14149. var text = block.getText();
  14150. var key = block.getEntityAt(start);
  14151. encoded.push({
  14152. offset: strlen$1(text.slice(0, start)),
  14153. length: strlen$1(text.slice(start, end)),
  14154. // Encode the key as a number for range storage.
  14155. key: Number(storageMap[DraftStringKey_1.stringify(key)])
  14156. });
  14157. });
  14158. return encoded;
  14159. }
  14160. var encodeEntityRanges_1 = encodeEntityRanges;
  14161. var areEqual$1 = function areEqual(a, b) {
  14162. return a === b;
  14163. };
  14164. var isTruthy = function isTruthy(a) {
  14165. return !!a;
  14166. };
  14167. var EMPTY_ARRAY = [];
  14168. /**
  14169. * Helper function for getting encoded styles for each inline style. Convert
  14170. * to UTF-8 character counts for storage.
  14171. */
  14172. function getEncodedInlinesForType(block, styleList, styleToEncode) {
  14173. var ranges = [];
  14174. // Obtain an array with ranges for only the specified style.
  14175. var filteredInlines = styleList.map(function (style) {
  14176. return style.has(styleToEncode);
  14177. }).toList();
  14178. findRangesImmutable_1(filteredInlines, areEqual$1,
  14179. // We only want to keep ranges with nonzero style values.
  14180. isTruthy, function (start, end) {
  14181. var text = block.getText();
  14182. ranges.push({
  14183. offset: UnicodeUtils_1.strlen(text.slice(0, start)),
  14184. length: UnicodeUtils_1.strlen(text.slice(start, end)),
  14185. style: styleToEncode
  14186. });
  14187. });
  14188. return ranges;
  14189. }
  14190. /*
  14191. * Retrieve the encoded arrays of inline styles, with each individual style
  14192. * treated separately.
  14193. */
  14194. function encodeInlineStyleRanges(block) {
  14195. var styleList = block.getCharacterList().map(function (c) {
  14196. return c.getStyle();
  14197. }).toList();
  14198. var ranges = styleList.flatten().toSet().map(function (style) {
  14199. return getEncodedInlinesForType(block, styleList, style);
  14200. });
  14201. return Array.prototype.concat.apply(EMPTY_ARRAY, ranges.toJS());
  14202. }
  14203. var encodeInlineStyleRanges_1 = encodeInlineStyleRanges;
  14204. var _extends$6 = objectAssign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  14205. var createRawBlock = function createRawBlock(block, entityStorageMap) {
  14206. return {
  14207. key: block.getKey(),
  14208. text: block.getText(),
  14209. type: block.getType(),
  14210. depth: block.getDepth(),
  14211. inlineStyleRanges: encodeInlineStyleRanges_1(block),
  14212. entityRanges: encodeEntityRanges_1(block, entityStorageMap),
  14213. data: block.getData().toObject()
  14214. };
  14215. };
  14216. var insertRawBlock = function insertRawBlock(block, entityMap, rawBlocks, blockCacheRef) {
  14217. if (block instanceof ContentBlock_1) {
  14218. rawBlocks.push(createRawBlock(block, entityMap));
  14219. return;
  14220. }
  14221. !(block instanceof ContentBlockNode_1) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'block is not a BlockNode') : invariant_1(false) : void 0;
  14222. var parentKey = block.getParentKey();
  14223. var rawBlock = blockCacheRef[block.getKey()] = _extends$6({}, createRawBlock(block, entityMap), {
  14224. children: []
  14225. });
  14226. if (parentKey) {
  14227. blockCacheRef[parentKey].children.push(rawBlock);
  14228. return;
  14229. }
  14230. rawBlocks.push(rawBlock);
  14231. };
  14232. var encodeRawBlocks = function encodeRawBlocks(contentState, rawState) {
  14233. var entityMap = rawState.entityMap;
  14234. var rawBlocks = [];
  14235. var blockCacheRef = {};
  14236. var entityCacheRef = {};
  14237. var entityStorageKey = 0;
  14238. contentState.getBlockMap().forEach(function (block) {
  14239. block.findEntityRanges(function (character) {
  14240. return character.getEntity() !== null;
  14241. }, function (start) {
  14242. var entityKey = block.getEntityAt(start);
  14243. // Stringify to maintain order of otherwise numeric keys.
  14244. var stringifiedEntityKey = DraftStringKey_1.stringify(entityKey);
  14245. // This makes this function resilient to two entities
  14246. // erroneously having the same key
  14247. if (entityCacheRef[stringifiedEntityKey]) {
  14248. return;
  14249. }
  14250. entityCacheRef[stringifiedEntityKey] = entityKey;
  14251. // we need the `any` casting here since this is a temporary state
  14252. // where we will later on flip the entity map and populate it with
  14253. // real entity, at this stage we just need to map back the entity
  14254. // key used by the BlockNode
  14255. entityMap[stringifiedEntityKey] = '' + entityStorageKey;
  14256. entityStorageKey++;
  14257. });
  14258. insertRawBlock(block, entityMap, rawBlocks, blockCacheRef);
  14259. });
  14260. return {
  14261. blocks: rawBlocks,
  14262. entityMap: entityMap
  14263. };
  14264. };
  14265. // Flip storage map so that our storage keys map to global
  14266. // DraftEntity keys.
  14267. var encodeRawEntityMap = function encodeRawEntityMap(contentState, rawState) {
  14268. var blocks = rawState.blocks,
  14269. entityMap = rawState.entityMap;
  14270. var rawEntityMap = {};
  14271. Object.keys(entityMap).forEach(function (key, index) {
  14272. var entity = contentState.getEntity(DraftStringKey_1.unstringify(key));
  14273. rawEntityMap[index] = {
  14274. type: entity.getType(),
  14275. mutability: entity.getMutability(),
  14276. data: entity.getData()
  14277. };
  14278. });
  14279. return {
  14280. blocks: blocks,
  14281. entityMap: rawEntityMap
  14282. };
  14283. };
  14284. var convertFromDraftStateToRaw = function convertFromDraftStateToRaw(contentState) {
  14285. var rawDraftContentState = {
  14286. entityMap: {},
  14287. blocks: []
  14288. };
  14289. // add blocks
  14290. rawDraftContentState = encodeRawBlocks(contentState, rawDraftContentState);
  14291. // add entities
  14292. rawDraftContentState = encodeRawEntityMap(contentState, rawDraftContentState);
  14293. return rawDraftContentState;
  14294. };
  14295. var convertFromDraftStateToRaw_1 = convertFromDraftStateToRaw;
  14296. var _extends$7 = objectAssign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  14297. /**
  14298. * Copyright (c) 2013-present, Facebook, Inc.
  14299. * All rights reserved.
  14300. *
  14301. * This source code is licensed under the BSD-style license found in the
  14302. * LICENSE file in the root directory of this source tree. An additional grant
  14303. * of patent rights can be found in the PATENTS file in the same directory.
  14304. *
  14305. * @providesModule DraftTreeAdapter
  14306. * @format
  14307. *
  14308. *
  14309. * This is unstable and not part of the public API and should not be used by
  14310. * production systems. This file may be update/removed without notice.
  14311. */
  14312. var traverseInDepthOrder = function traverseInDepthOrder(blocks, fn) {
  14313. var stack = [].concat(blocks).reverse();
  14314. while (stack.length) {
  14315. var _block = stack.pop();
  14316. fn(_block);
  14317. var children = _block.children;
  14318. !Array.isArray(children) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Invalid tree raw block') : invariant_1(false) : void 0;
  14319. stack = stack.concat([].concat(children.reverse()));
  14320. }
  14321. };
  14322. var isListBlock = function isListBlock(block) {
  14323. if (!(block && block.type)) {
  14324. return false;
  14325. }
  14326. var type = block.type;
  14327. return type === 'unordered-list-item' || type === 'ordered-list-item';
  14328. };
  14329. var addDepthToChildren = function addDepthToChildren(block) {
  14330. if (Array.isArray(block.children)) {
  14331. block.children = block.children.map(function (child) {
  14332. return child.type === block.type ? _extends$7({}, child, { depth: (block.depth || 0) + 1 }) : child;
  14333. });
  14334. }
  14335. };
  14336. /**
  14337. * This adapter is intended to be be used as an adapter to draft tree data
  14338. *
  14339. * draft state <=====> draft tree state
  14340. */
  14341. var DraftTreeAdapter = {
  14342. /**
  14343. * Converts from a tree raw state back to draft raw state
  14344. */
  14345. fromRawTreeStateToRawState: function fromRawTreeStateToRawState(draftTreeState) {
  14346. var blocks = draftTreeState.blocks;
  14347. var transformedBlocks = [];
  14348. !Array.isArray(blocks) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Invalid raw state') : invariant_1(false) : void 0;
  14349. if (!Array.isArray(blocks) || !blocks.length) {
  14350. return draftTreeState;
  14351. }
  14352. traverseInDepthOrder(blocks, function (block) {
  14353. var newBlock = _extends$7({}, block);
  14354. if (isListBlock(block)) {
  14355. newBlock.depth = newBlock.depth || 0;
  14356. addDepthToChildren(block);
  14357. }
  14358. delete newBlock.children;
  14359. transformedBlocks.push(newBlock);
  14360. });
  14361. draftTreeState.blocks = transformedBlocks;
  14362. return _extends$7({}, draftTreeState, {
  14363. blocks: transformedBlocks
  14364. });
  14365. },
  14366. /**
  14367. * Converts from draft raw state to tree draft state
  14368. */
  14369. fromRawStateToRawTreeState: function fromRawStateToRawTreeState(draftState) {
  14370. var lastListDepthCacheRef = {};
  14371. var transformedBlocks = [];
  14372. draftState.blocks.forEach(function (block) {
  14373. var isList = isListBlock(block);
  14374. var depth = block.depth || 0;
  14375. var treeBlock = _extends$7({}, block, {
  14376. children: []
  14377. });
  14378. if (!isList) {
  14379. // reset the cache path
  14380. lastListDepthCacheRef = {};
  14381. transformedBlocks.push(treeBlock);
  14382. return;
  14383. }
  14384. // update our depth cache reference path
  14385. lastListDepthCacheRef[depth] = treeBlock;
  14386. // if we are greater than zero we must have seen a parent already
  14387. if (depth > 0) {
  14388. var parent = lastListDepthCacheRef[depth - 1];
  14389. !parent ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Invalid depth for RawDraftContentBlock') : invariant_1(false) : void 0;
  14390. // push nested list blocks
  14391. parent.children.push(treeBlock);
  14392. return;
  14393. }
  14394. // push root list blocks
  14395. transformedBlocks.push(treeBlock);
  14396. });
  14397. return _extends$7({}, draftState, {
  14398. blocks: transformedBlocks
  14399. });
  14400. }
  14401. };
  14402. var DraftTreeAdapter_1 = DraftTreeAdapter;
  14403. var List$c = immutable.List;
  14404. function createCharacterList(inlineStyles, entities) {
  14405. var characterArray = inlineStyles.map(function (style, ii) {
  14406. var entity = entities[ii];
  14407. return CharacterMetadata_1.create({ style: style, entity: entity });
  14408. });
  14409. return List$c(characterArray);
  14410. }
  14411. var createCharacterList_1 = createCharacterList;
  14412. var substr$1 = UnicodeUtils_1.substr;
  14413. /**
  14414. * Convert to native JavaScript string lengths to determine ranges.
  14415. */
  14416. function decodeEntityRanges(text, ranges) {
  14417. var entities = Array(text.length).fill(null);
  14418. if (ranges) {
  14419. ranges.forEach(function (range) {
  14420. // Using Unicode-enabled substrings converted to JavaScript lengths,
  14421. // fill the output array with entity keys.
  14422. var start = substr$1(text, 0, range.offset).length;
  14423. var end = start + substr$1(text, range.offset, range.length).length;
  14424. for (var ii = start; ii < end; ii++) {
  14425. entities[ii] = range.key;
  14426. }
  14427. });
  14428. }
  14429. return entities;
  14430. }
  14431. var decodeEntityRanges_1 = decodeEntityRanges;
  14432. var OrderedSet$6 = immutable.OrderedSet;
  14433. var substr$2 = UnicodeUtils_1.substr;
  14434. var EMPTY_SET$3 = OrderedSet$6();
  14435. /**
  14436. * Convert to native JavaScript string lengths to determine ranges.
  14437. */
  14438. function decodeInlineStyleRanges(text, ranges) {
  14439. var styles = Array(text.length).fill(EMPTY_SET$3);
  14440. if (ranges) {
  14441. ranges.forEach(function ( /*object*/range) {
  14442. var cursor = substr$2(text, 0, range.offset).length;
  14443. var end = cursor + substr$2(text, range.offset, range.length).length;
  14444. while (cursor < end) {
  14445. styles[cursor] = styles[cursor].add(range.style);
  14446. cursor++;
  14447. }
  14448. });
  14449. }
  14450. return styles;
  14451. }
  14452. var decodeInlineStyleRanges_1 = decodeInlineStyleRanges;
  14453. var _extends$8 = objectAssign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  14454. var List$d = immutable.List,
  14455. Map$9 = immutable.Map,
  14456. OrderedMap$4 = immutable.OrderedMap;
  14457. var decodeBlockNodeConfig = function decodeBlockNodeConfig(block, entityMap) {
  14458. var key = block.key,
  14459. type = block.type,
  14460. data = block.data,
  14461. text = block.text,
  14462. depth = block.depth;
  14463. var blockNodeConfig = {
  14464. text: text,
  14465. depth: depth || 0,
  14466. type: type || 'unstyled',
  14467. key: key || generateRandomKey_1(),
  14468. data: Map$9(data),
  14469. characterList: decodeCharacterList(block, entityMap)
  14470. };
  14471. return blockNodeConfig;
  14472. };
  14473. var decodeCharacterList = function decodeCharacterList(block, entityMap) {
  14474. var text = block.text,
  14475. rawEntityRanges = block.entityRanges,
  14476. rawInlineStyleRanges = block.inlineStyleRanges;
  14477. var entityRanges = rawEntityRanges || [];
  14478. var inlineStyleRanges = rawInlineStyleRanges || [];
  14479. // Translate entity range keys to the DraftEntity map.
  14480. return createCharacterList_1(decodeInlineStyleRanges_1(text, inlineStyleRanges), decodeEntityRanges_1(text, entityRanges.filter(function (range) {
  14481. return entityMap.hasOwnProperty(range.key);
  14482. }).map(function (range) {
  14483. return _extends$8({}, range, { key: entityMap[range.key] });
  14484. })));
  14485. };
  14486. var decodeContentBlocks = function decodeContentBlocks(blocks, entityMap) {
  14487. return OrderedMap$4(blocks.map(function (block) {
  14488. var contentBlock = new ContentBlock_1(decodeBlockNodeConfig(block, entityMap));
  14489. return [contentBlock.getKey(), contentBlock];
  14490. }));
  14491. };
  14492. var decodeRawBlocks = function decodeRawBlocks(rawState, entityMap) {
  14493. var isTreeRawBlock = Array.isArray(rawState.blocks[0].children);
  14494. var rawBlocks = rawState.blocks;
  14495. {
  14496. return decodeContentBlocks(isTreeRawBlock ? DraftTreeAdapter_1.fromRawTreeStateToRawState(rawState).blocks : rawBlocks, entityMap);
  14497. }
  14498. };
  14499. var decodeRawEntityMap = function decodeRawEntityMap(rawState) {
  14500. var rawEntityMap = rawState.entityMap;
  14501. var entityMap = {};
  14502. // TODO: Update this once we completely remove DraftEntity
  14503. Object.keys(rawEntityMap).forEach(function (rawEntityKey) {
  14504. var _rawEntityMap$rawEnti = rawEntityMap[rawEntityKey],
  14505. type = _rawEntityMap$rawEnti.type,
  14506. mutability = _rawEntityMap$rawEnti.mutability,
  14507. data = _rawEntityMap$rawEnti.data;
  14508. // get the key reference to created entity
  14509. entityMap[rawEntityKey] = DraftEntity_1.__create(type, mutability, data || {});
  14510. });
  14511. return entityMap;
  14512. };
  14513. var convertFromRawToDraftState = function convertFromRawToDraftState(rawState) {
  14514. !Array.isArray(rawState.blocks) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'invalid RawDraftContentState') : invariant_1(false) : void 0;
  14515. // decode entities
  14516. var entityMap = decodeRawEntityMap(rawState);
  14517. // decode blockMap
  14518. var blockMap = decodeRawBlocks(rawState, entityMap);
  14519. // create initial selection
  14520. var selectionState = blockMap.isEmpty() ? new SelectionState_1() : SelectionState_1.createEmpty(blockMap.first().getKey());
  14521. return new ContentState_1({
  14522. blockMap: blockMap,
  14523. entityMap: entityMap,
  14524. selectionBefore: selectionState,
  14525. selectionAfter: selectionState
  14526. });
  14527. };
  14528. var convertFromRawToDraftState_1 = convertFromRawToDraftState;
  14529. /**
  14530. * Like range.getBoundingClientRect() but normalizes for browser bugs.
  14531. */
  14532. function getRangeBoundingClientRect(range) {
  14533. // "Return a DOMRect object describing the smallest rectangle that includes
  14534. // the first rectangle in list and all of the remaining rectangles of which
  14535. // the height or width is not zero."
  14536. // http://www.w3.org/TR/cssom-view/#dom-range-getboundingclientrect
  14537. var rects = getRangeClientRects_1(range);
  14538. var top = 0;
  14539. var right = 0;
  14540. var bottom = 0;
  14541. var left = 0;
  14542. if (rects.length) {
  14543. // If the first rectangle has 0 width, we use the second, this is needed
  14544. // because Chrome renders a 0 width rectangle when the selection contains
  14545. // a line break.
  14546. if (rects.length > 1 && rects[0].width === 0) {
  14547. var _rects$ = rects[1];
  14548. top = _rects$.top;
  14549. right = _rects$.right;
  14550. bottom = _rects$.bottom;
  14551. left = _rects$.left;
  14552. } else {
  14553. var _rects$2 = rects[0];
  14554. top = _rects$2.top;
  14555. right = _rects$2.right;
  14556. bottom = _rects$2.bottom;
  14557. left = _rects$2.left;
  14558. }
  14559. for (var ii = 1; ii < rects.length; ii++) {
  14560. var rect = rects[ii];
  14561. if (rect.height !== 0 && rect.width !== 0) {
  14562. top = Math.min(top, rect.top);
  14563. right = Math.max(right, rect.right);
  14564. bottom = Math.max(bottom, rect.bottom);
  14565. left = Math.min(left, rect.left);
  14566. }
  14567. }
  14568. }
  14569. return {
  14570. top: top,
  14571. right: right,
  14572. bottom: bottom,
  14573. left: left,
  14574. width: right - left,
  14575. height: bottom - top
  14576. };
  14577. }
  14578. var getRangeBoundingClientRect_1 = getRangeBoundingClientRect;
  14579. /**
  14580. * Return the bounding ClientRect for the visible DOM selection, if any.
  14581. * In cases where there are no selected ranges or the bounding rect is
  14582. * temporarily invalid, return null.
  14583. */
  14584. function getVisibleSelectionRect(global) {
  14585. var selection = global.getSelection();
  14586. if (!selection.rangeCount) {
  14587. return null;
  14588. }
  14589. var range = selection.getRangeAt(0);
  14590. var boundingRect = getRangeBoundingClientRect_1(range);
  14591. var top = boundingRect.top,
  14592. right = boundingRect.right,
  14593. bottom = boundingRect.bottom,
  14594. left = boundingRect.left;
  14595. // When a re-render leads to a node being removed, the DOM selection will
  14596. // temporarily be placed on an ancestor node, which leads to an invalid
  14597. // bounding rect. Discard this state.
  14598. if (top === 0 && right === 0 && bottom === 0 && left === 0) {
  14599. return null;
  14600. }
  14601. return boundingRect;
  14602. }
  14603. var getVisibleSelectionRect_1 = getVisibleSelectionRect;
  14604. var DraftPublic = {
  14605. Editor: DraftEditor_react,
  14606. EditorBlock: DraftEditorBlock_react,
  14607. EditorState: EditorState_1,
  14608. CompositeDecorator: CompositeDraftDecorator_1,
  14609. Entity: DraftEntity_1,
  14610. EntityInstance: DraftEntityInstance_1,
  14611. BlockMapBuilder: BlockMapBuilder_1,
  14612. CharacterMetadata: CharacterMetadata_1,
  14613. ContentBlock: ContentBlock_1,
  14614. ContentState: ContentState_1,
  14615. SelectionState: SelectionState_1,
  14616. AtomicBlockUtils: AtomicBlockUtils_1,
  14617. KeyBindingUtil: KeyBindingUtil_1,
  14618. Modifier: DraftModifier_1,
  14619. RichUtils: RichTextEditorUtil_1,
  14620. DefaultDraftBlockRenderMap: DefaultDraftBlockRenderMap_1,
  14621. DefaultDraftInlineStyle: DefaultDraftInlineStyle,
  14622. convertFromHTML: convertFromHTMLToContentBlocks,
  14623. convertFromRaw: convertFromRawToDraftState_1,
  14624. convertToRaw: convertFromDraftStateToRaw_1,
  14625. genKey: generateRandomKey_1,
  14626. getDefaultKeyBinding: getDefaultKeyBinding_1,
  14627. getVisibleSelectionRect: getVisibleSelectionRect_1
  14628. };
  14629. var Draft = DraftPublic;
  14630. var immutable$1 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
  14631. /**
  14632. * Copyright (c) 2014-2015, Facebook, Inc.
  14633. * All rights reserved.
  14634. *
  14635. * This source code is licensed under the BSD-style license found in the
  14636. * LICENSE file in the root directory of this source tree. An additional grant
  14637. * of patent rights can be found in the PATENTS file in the same directory.
  14638. */
  14639. (function (global, factory) {
  14640. module.exports = factory() ;
  14641. }(_commonjsHelpers.commonjsGlobal, function () {var SLICE$0 = Array.prototype.slice;
  14642. function createClass(ctor, superClass) {
  14643. if (superClass) {
  14644. ctor.prototype = Object.create(superClass.prototype);
  14645. }
  14646. ctor.prototype.constructor = ctor;
  14647. }
  14648. function Iterable(value) {
  14649. return isIterable(value) ? value : Seq(value);
  14650. }
  14651. createClass(KeyedIterable, Iterable);
  14652. function KeyedIterable(value) {
  14653. return isKeyed(value) ? value : KeyedSeq(value);
  14654. }
  14655. createClass(IndexedIterable, Iterable);
  14656. function IndexedIterable(value) {
  14657. return isIndexed(value) ? value : IndexedSeq(value);
  14658. }
  14659. createClass(SetIterable, Iterable);
  14660. function SetIterable(value) {
  14661. return isIterable(value) && !isAssociative(value) ? value : SetSeq(value);
  14662. }
  14663. function isIterable(maybeIterable) {
  14664. return !!(maybeIterable && maybeIterable[IS_ITERABLE_SENTINEL]);
  14665. }
  14666. function isKeyed(maybeKeyed) {
  14667. return !!(maybeKeyed && maybeKeyed[IS_KEYED_SENTINEL]);
  14668. }
  14669. function isIndexed(maybeIndexed) {
  14670. return !!(maybeIndexed && maybeIndexed[IS_INDEXED_SENTINEL]);
  14671. }
  14672. function isAssociative(maybeAssociative) {
  14673. return isKeyed(maybeAssociative) || isIndexed(maybeAssociative);
  14674. }
  14675. function isOrdered(maybeOrdered) {
  14676. return !!(maybeOrdered && maybeOrdered[IS_ORDERED_SENTINEL]);
  14677. }
  14678. Iterable.isIterable = isIterable;
  14679. Iterable.isKeyed = isKeyed;
  14680. Iterable.isIndexed = isIndexed;
  14681. Iterable.isAssociative = isAssociative;
  14682. Iterable.isOrdered = isOrdered;
  14683. Iterable.Keyed = KeyedIterable;
  14684. Iterable.Indexed = IndexedIterable;
  14685. Iterable.Set = SetIterable;
  14686. var IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
  14687. var IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
  14688. var IS_INDEXED_SENTINEL = '@@__IMMUTABLE_INDEXED__@@';
  14689. var IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
  14690. // Used for setting prototype methods that IE8 chokes on.
  14691. var DELETE = 'delete';
  14692. // Constants describing the size of trie nodes.
  14693. var SHIFT = 5; // Resulted in best performance after ______?
  14694. var SIZE = 1 << SHIFT;
  14695. var MASK = SIZE - 1;
  14696. // A consistent shared value representing "not set" which equals nothing other
  14697. // than itself, and nothing that could be provided externally.
  14698. var NOT_SET = {};
  14699. // Boolean references, Rough equivalent of `bool &`.
  14700. var CHANGE_LENGTH = { value: false };
  14701. var DID_ALTER = { value: false };
  14702. function MakeRef(ref) {
  14703. ref.value = false;
  14704. return ref;
  14705. }
  14706. function SetRef(ref) {
  14707. ref && (ref.value = true);
  14708. }
  14709. // A function which returns a value representing an "owner" for transient writes
  14710. // to tries. The return value will only ever equal itself, and will not equal
  14711. // the return of any subsequent call of this function.
  14712. function OwnerID() {}
  14713. // http://jsperf.com/copy-array-inline
  14714. function arrCopy(arr, offset) {
  14715. offset = offset || 0;
  14716. var len = Math.max(0, arr.length - offset);
  14717. var newArr = new Array(len);
  14718. for (var ii = 0; ii < len; ii++) {
  14719. newArr[ii] = arr[ii + offset];
  14720. }
  14721. return newArr;
  14722. }
  14723. function ensureSize(iter) {
  14724. if (iter.size === undefined) {
  14725. iter.size = iter.__iterate(returnTrue);
  14726. }
  14727. return iter.size;
  14728. }
  14729. function wrapIndex(iter, index) {
  14730. // This implements "is array index" which the ECMAString spec defines as:
  14731. //
  14732. // A String property name P is an array index if and only if
  14733. // ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal
  14734. // to 2^32−1.
  14735. //
  14736. // http://www.ecma-international.org/ecma-262/6.0/#sec-array-exotic-objects
  14737. if (typeof index !== 'number') {
  14738. var uint32Index = index >>> 0; // N >>> 0 is shorthand for ToUint32
  14739. if ('' + uint32Index !== index || uint32Index === 4294967295) {
  14740. return NaN;
  14741. }
  14742. index = uint32Index;
  14743. }
  14744. return index < 0 ? ensureSize(iter) + index : index;
  14745. }
  14746. function returnTrue() {
  14747. return true;
  14748. }
  14749. function wholeSlice(begin, end, size) {
  14750. return (begin === 0 || (size !== undefined && begin <= -size)) &&
  14751. (end === undefined || (size !== undefined && end >= size));
  14752. }
  14753. function resolveBegin(begin, size) {
  14754. return resolveIndex(begin, size, 0);
  14755. }
  14756. function resolveEnd(end, size) {
  14757. return resolveIndex(end, size, size);
  14758. }
  14759. function resolveIndex(index, size, defaultIndex) {
  14760. return index === undefined ?
  14761. defaultIndex :
  14762. index < 0 ?
  14763. Math.max(0, size + index) :
  14764. size === undefined ?
  14765. index :
  14766. Math.min(size, index);
  14767. }
  14768. /* global Symbol */
  14769. var ITERATE_KEYS = 0;
  14770. var ITERATE_VALUES = 1;
  14771. var ITERATE_ENTRIES = 2;
  14772. var REAL_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
  14773. var FAUX_ITERATOR_SYMBOL = '@@iterator';
  14774. var ITERATOR_SYMBOL = REAL_ITERATOR_SYMBOL || FAUX_ITERATOR_SYMBOL;
  14775. function Iterator(next) {
  14776. this.next = next;
  14777. }
  14778. Iterator.prototype.toString = function() {
  14779. return '[Iterator]';
  14780. };
  14781. Iterator.KEYS = ITERATE_KEYS;
  14782. Iterator.VALUES = ITERATE_VALUES;
  14783. Iterator.ENTRIES = ITERATE_ENTRIES;
  14784. Iterator.prototype.inspect =
  14785. Iterator.prototype.toSource = function () { return this.toString(); };
  14786. Iterator.prototype[ITERATOR_SYMBOL] = function () {
  14787. return this;
  14788. };
  14789. function iteratorValue(type, k, v, iteratorResult) {
  14790. var value = type === 0 ? k : type === 1 ? v : [k, v];
  14791. iteratorResult ? (iteratorResult.value = value) : (iteratorResult = {
  14792. value: value, done: false
  14793. });
  14794. return iteratorResult;
  14795. }
  14796. function iteratorDone() {
  14797. return { value: undefined, done: true };
  14798. }
  14799. function hasIterator(maybeIterable) {
  14800. return !!getIteratorFn(maybeIterable);
  14801. }
  14802. function isIterator(maybeIterator) {
  14803. return maybeIterator && typeof maybeIterator.next === 'function';
  14804. }
  14805. function getIterator(iterable) {
  14806. var iteratorFn = getIteratorFn(iterable);
  14807. return iteratorFn && iteratorFn.call(iterable);
  14808. }
  14809. function getIteratorFn(iterable) {
  14810. var iteratorFn = iterable && (
  14811. (REAL_ITERATOR_SYMBOL && iterable[REAL_ITERATOR_SYMBOL]) ||
  14812. iterable[FAUX_ITERATOR_SYMBOL]
  14813. );
  14814. if (typeof iteratorFn === 'function') {
  14815. return iteratorFn;
  14816. }
  14817. }
  14818. function isArrayLike(value) {
  14819. return value && typeof value.length === 'number';
  14820. }
  14821. createClass(Seq, Iterable);
  14822. function Seq(value) {
  14823. return value === null || value === undefined ? emptySequence() :
  14824. isIterable(value) ? value.toSeq() : seqFromValue(value);
  14825. }
  14826. Seq.of = function(/*...values*/) {
  14827. return Seq(arguments);
  14828. };
  14829. Seq.prototype.toSeq = function() {
  14830. return this;
  14831. };
  14832. Seq.prototype.toString = function() {
  14833. return this.__toString('Seq {', '}');
  14834. };
  14835. Seq.prototype.cacheResult = function() {
  14836. if (!this._cache && this.__iterateUncached) {
  14837. this._cache = this.entrySeq().toArray();
  14838. this.size = this._cache.length;
  14839. }
  14840. return this;
  14841. };
  14842. // abstract __iterateUncached(fn, reverse)
  14843. Seq.prototype.__iterate = function(fn, reverse) {
  14844. return seqIterate(this, fn, reverse, true);
  14845. };
  14846. // abstract __iteratorUncached(type, reverse)
  14847. Seq.prototype.__iterator = function(type, reverse) {
  14848. return seqIterator(this, type, reverse, true);
  14849. };
  14850. createClass(KeyedSeq, Seq);
  14851. function KeyedSeq(value) {
  14852. return value === null || value === undefined ?
  14853. emptySequence().toKeyedSeq() :
  14854. isIterable(value) ?
  14855. (isKeyed(value) ? value.toSeq() : value.fromEntrySeq()) :
  14856. keyedSeqFromValue(value);
  14857. }
  14858. KeyedSeq.prototype.toKeyedSeq = function() {
  14859. return this;
  14860. };
  14861. createClass(IndexedSeq, Seq);
  14862. function IndexedSeq(value) {
  14863. return value === null || value === undefined ? emptySequence() :
  14864. !isIterable(value) ? indexedSeqFromValue(value) :
  14865. isKeyed(value) ? value.entrySeq() : value.toIndexedSeq();
  14866. }
  14867. IndexedSeq.of = function(/*...values*/) {
  14868. return IndexedSeq(arguments);
  14869. };
  14870. IndexedSeq.prototype.toIndexedSeq = function() {
  14871. return this;
  14872. };
  14873. IndexedSeq.prototype.toString = function() {
  14874. return this.__toString('Seq [', ']');
  14875. };
  14876. IndexedSeq.prototype.__iterate = function(fn, reverse) {
  14877. return seqIterate(this, fn, reverse, false);
  14878. };
  14879. IndexedSeq.prototype.__iterator = function(type, reverse) {
  14880. return seqIterator(this, type, reverse, false);
  14881. };
  14882. createClass(SetSeq, Seq);
  14883. function SetSeq(value) {
  14884. return (
  14885. value === null || value === undefined ? emptySequence() :
  14886. !isIterable(value) ? indexedSeqFromValue(value) :
  14887. isKeyed(value) ? value.entrySeq() : value
  14888. ).toSetSeq();
  14889. }
  14890. SetSeq.of = function(/*...values*/) {
  14891. return SetSeq(arguments);
  14892. };
  14893. SetSeq.prototype.toSetSeq = function() {
  14894. return this;
  14895. };
  14896. Seq.isSeq = isSeq;
  14897. Seq.Keyed = KeyedSeq;
  14898. Seq.Set = SetSeq;
  14899. Seq.Indexed = IndexedSeq;
  14900. var IS_SEQ_SENTINEL = '@@__IMMUTABLE_SEQ__@@';
  14901. Seq.prototype[IS_SEQ_SENTINEL] = true;
  14902. createClass(ArraySeq, IndexedSeq);
  14903. function ArraySeq(array) {
  14904. this._array = array;
  14905. this.size = array.length;
  14906. }
  14907. ArraySeq.prototype.get = function(index, notSetValue) {
  14908. return this.has(index) ? this._array[wrapIndex(this, index)] : notSetValue;
  14909. };
  14910. ArraySeq.prototype.__iterate = function(fn, reverse) {
  14911. var array = this._array;
  14912. var maxIndex = array.length - 1;
  14913. for (var ii = 0; ii <= maxIndex; ii++) {
  14914. if (fn(array[reverse ? maxIndex - ii : ii], ii, this) === false) {
  14915. return ii + 1;
  14916. }
  14917. }
  14918. return ii;
  14919. };
  14920. ArraySeq.prototype.__iterator = function(type, reverse) {
  14921. var array = this._array;
  14922. var maxIndex = array.length - 1;
  14923. var ii = 0;
  14924. return new Iterator(function()
  14925. {return ii > maxIndex ?
  14926. iteratorDone() :
  14927. iteratorValue(type, ii, array[reverse ? maxIndex - ii++ : ii++])}
  14928. );
  14929. };
  14930. createClass(ObjectSeq, KeyedSeq);
  14931. function ObjectSeq(object) {
  14932. var keys = Object.keys(object);
  14933. this._object = object;
  14934. this._keys = keys;
  14935. this.size = keys.length;
  14936. }
  14937. ObjectSeq.prototype.get = function(key, notSetValue) {
  14938. if (notSetValue !== undefined && !this.has(key)) {
  14939. return notSetValue;
  14940. }
  14941. return this._object[key];
  14942. };
  14943. ObjectSeq.prototype.has = function(key) {
  14944. return this._object.hasOwnProperty(key);
  14945. };
  14946. ObjectSeq.prototype.__iterate = function(fn, reverse) {
  14947. var object = this._object;
  14948. var keys = this._keys;
  14949. var maxIndex = keys.length - 1;
  14950. for (var ii = 0; ii <= maxIndex; ii++) {
  14951. var key = keys[reverse ? maxIndex - ii : ii];
  14952. if (fn(object[key], key, this) === false) {
  14953. return ii + 1;
  14954. }
  14955. }
  14956. return ii;
  14957. };
  14958. ObjectSeq.prototype.__iterator = function(type, reverse) {
  14959. var object = this._object;
  14960. var keys = this._keys;
  14961. var maxIndex = keys.length - 1;
  14962. var ii = 0;
  14963. return new Iterator(function() {
  14964. var key = keys[reverse ? maxIndex - ii : ii];
  14965. return ii++ > maxIndex ?
  14966. iteratorDone() :
  14967. iteratorValue(type, key, object[key]);
  14968. });
  14969. };
  14970. ObjectSeq.prototype[IS_ORDERED_SENTINEL] = true;
  14971. createClass(IterableSeq, IndexedSeq);
  14972. function IterableSeq(iterable) {
  14973. this._iterable = iterable;
  14974. this.size = iterable.length || iterable.size;
  14975. }
  14976. IterableSeq.prototype.__iterateUncached = function(fn, reverse) {
  14977. if (reverse) {
  14978. return this.cacheResult().__iterate(fn, reverse);
  14979. }
  14980. var iterable = this._iterable;
  14981. var iterator = getIterator(iterable);
  14982. var iterations = 0;
  14983. if (isIterator(iterator)) {
  14984. var step;
  14985. while (!(step = iterator.next()).done) {
  14986. if (fn(step.value, iterations++, this) === false) {
  14987. break;
  14988. }
  14989. }
  14990. }
  14991. return iterations;
  14992. };
  14993. IterableSeq.prototype.__iteratorUncached = function(type, reverse) {
  14994. if (reverse) {
  14995. return this.cacheResult().__iterator(type, reverse);
  14996. }
  14997. var iterable = this._iterable;
  14998. var iterator = getIterator(iterable);
  14999. if (!isIterator(iterator)) {
  15000. return new Iterator(iteratorDone);
  15001. }
  15002. var iterations = 0;
  15003. return new Iterator(function() {
  15004. var step = iterator.next();
  15005. return step.done ? step : iteratorValue(type, iterations++, step.value);
  15006. });
  15007. };
  15008. createClass(IteratorSeq, IndexedSeq);
  15009. function IteratorSeq(iterator) {
  15010. this._iterator = iterator;
  15011. this._iteratorCache = [];
  15012. }
  15013. IteratorSeq.prototype.__iterateUncached = function(fn, reverse) {
  15014. if (reverse) {
  15015. return this.cacheResult().__iterate(fn, reverse);
  15016. }
  15017. var iterator = this._iterator;
  15018. var cache = this._iteratorCache;
  15019. var iterations = 0;
  15020. while (iterations < cache.length) {
  15021. if (fn(cache[iterations], iterations++, this) === false) {
  15022. return iterations;
  15023. }
  15024. }
  15025. var step;
  15026. while (!(step = iterator.next()).done) {
  15027. var val = step.value;
  15028. cache[iterations] = val;
  15029. if (fn(val, iterations++, this) === false) {
  15030. break;
  15031. }
  15032. }
  15033. return iterations;
  15034. };
  15035. IteratorSeq.prototype.__iteratorUncached = function(type, reverse) {
  15036. if (reverse) {
  15037. return this.cacheResult().__iterator(type, reverse);
  15038. }
  15039. var iterator = this._iterator;
  15040. var cache = this._iteratorCache;
  15041. var iterations = 0;
  15042. return new Iterator(function() {
  15043. if (iterations >= cache.length) {
  15044. var step = iterator.next();
  15045. if (step.done) {
  15046. return step;
  15047. }
  15048. cache[iterations] = step.value;
  15049. }
  15050. return iteratorValue(type, iterations, cache[iterations++]);
  15051. });
  15052. };
  15053. // # pragma Helper functions
  15054. function isSeq(maybeSeq) {
  15055. return !!(maybeSeq && maybeSeq[IS_SEQ_SENTINEL]);
  15056. }
  15057. var EMPTY_SEQ;
  15058. function emptySequence() {
  15059. return EMPTY_SEQ || (EMPTY_SEQ = new ArraySeq([]));
  15060. }
  15061. function keyedSeqFromValue(value) {
  15062. var seq =
  15063. Array.isArray(value) ? new ArraySeq(value).fromEntrySeq() :
  15064. isIterator(value) ? new IteratorSeq(value).fromEntrySeq() :
  15065. hasIterator(value) ? new IterableSeq(value).fromEntrySeq() :
  15066. typeof value === 'object' ? new ObjectSeq(value) :
  15067. undefined;
  15068. if (!seq) {
  15069. throw new TypeError(
  15070. 'Expected Array or iterable object of [k, v] entries, '+
  15071. 'or keyed object: ' + value
  15072. );
  15073. }
  15074. return seq;
  15075. }
  15076. function indexedSeqFromValue(value) {
  15077. var seq = maybeIndexedSeqFromValue(value);
  15078. if (!seq) {
  15079. throw new TypeError(
  15080. 'Expected Array or iterable object of values: ' + value
  15081. );
  15082. }
  15083. return seq;
  15084. }
  15085. function seqFromValue(value) {
  15086. var seq = maybeIndexedSeqFromValue(value) ||
  15087. (typeof value === 'object' && new ObjectSeq(value));
  15088. if (!seq) {
  15089. throw new TypeError(
  15090. 'Expected Array or iterable object of values, or keyed object: ' + value
  15091. );
  15092. }
  15093. return seq;
  15094. }
  15095. function maybeIndexedSeqFromValue(value) {
  15096. return (
  15097. isArrayLike(value) ? new ArraySeq(value) :
  15098. isIterator(value) ? new IteratorSeq(value) :
  15099. hasIterator(value) ? new IterableSeq(value) :
  15100. undefined
  15101. );
  15102. }
  15103. function seqIterate(seq, fn, reverse, useKeys) {
  15104. var cache = seq._cache;
  15105. if (cache) {
  15106. var maxIndex = cache.length - 1;
  15107. for (var ii = 0; ii <= maxIndex; ii++) {
  15108. var entry = cache[reverse ? maxIndex - ii : ii];
  15109. if (fn(entry[1], useKeys ? entry[0] : ii, seq) === false) {
  15110. return ii + 1;
  15111. }
  15112. }
  15113. return ii;
  15114. }
  15115. return seq.__iterateUncached(fn, reverse);
  15116. }
  15117. function seqIterator(seq, type, reverse, useKeys) {
  15118. var cache = seq._cache;
  15119. if (cache) {
  15120. var maxIndex = cache.length - 1;
  15121. var ii = 0;
  15122. return new Iterator(function() {
  15123. var entry = cache[reverse ? maxIndex - ii : ii];
  15124. return ii++ > maxIndex ?
  15125. iteratorDone() :
  15126. iteratorValue(type, useKeys ? entry[0] : ii - 1, entry[1]);
  15127. });
  15128. }
  15129. return seq.__iteratorUncached(type, reverse);
  15130. }
  15131. function fromJS(json, converter) {
  15132. return converter ?
  15133. fromJSWith(converter, json, '', {'': json}) :
  15134. fromJSDefault(json);
  15135. }
  15136. function fromJSWith(converter, json, key, parentJSON) {
  15137. if (Array.isArray(json)) {
  15138. return converter.call(parentJSON, key, IndexedSeq(json).map(function(v, k) {return fromJSWith(converter, v, k, json)}));
  15139. }
  15140. if (isPlainObj(json)) {
  15141. return converter.call(parentJSON, key, KeyedSeq(json).map(function(v, k) {return fromJSWith(converter, v, k, json)}));
  15142. }
  15143. return json;
  15144. }
  15145. function fromJSDefault(json) {
  15146. if (Array.isArray(json)) {
  15147. return IndexedSeq(json).map(fromJSDefault).toList();
  15148. }
  15149. if (isPlainObj(json)) {
  15150. return KeyedSeq(json).map(fromJSDefault).toMap();
  15151. }
  15152. return json;
  15153. }
  15154. function isPlainObj(value) {
  15155. return value && (value.constructor === Object || value.constructor === undefined);
  15156. }
  15157. /**
  15158. * An extension of the "same-value" algorithm as [described for use by ES6 Map
  15159. * and Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map#Key_equality)
  15160. *
  15161. * NaN is considered the same as NaN, however -0 and 0 are considered the same
  15162. * value, which is different from the algorithm described by
  15163. * [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is).
  15164. *
  15165. * This is extended further to allow Objects to describe the values they
  15166. * represent, by way of `valueOf` or `equals` (and `hashCode`).
  15167. *
  15168. * Note: because of this extension, the key equality of Immutable.Map and the
  15169. * value equality of Immutable.Set will differ from ES6 Map and Set.
  15170. *
  15171. * ### Defining custom values
  15172. *
  15173. * The easiest way to describe the value an object represents is by implementing
  15174. * `valueOf`. For example, `Date` represents a value by returning a unix
  15175. * timestamp for `valueOf`:
  15176. *
  15177. * var date1 = new Date(1234567890000); // Fri Feb 13 2009 ...
  15178. * var date2 = new Date(1234567890000);
  15179. * date1.valueOf(); // 1234567890000
  15180. * assert( date1 !== date2 );
  15181. * assert( Immutable.is( date1, date2 ) );
  15182. *
  15183. * Note: overriding `valueOf` may have other implications if you use this object
  15184. * where JavaScript expects a primitive, such as implicit string coercion.
  15185. *
  15186. * For more complex types, especially collections, implementing `valueOf` may
  15187. * not be performant. An alternative is to implement `equals` and `hashCode`.
  15188. *
  15189. * `equals` takes another object, presumably of similar type, and returns true
  15190. * if the it is equal. Equality is symmetrical, so the same result should be
  15191. * returned if this and the argument are flipped.
  15192. *
  15193. * assert( a.equals(b) === b.equals(a) );
  15194. *
  15195. * `hashCode` returns a 32bit integer number representing the object which will
  15196. * be used to determine how to store the value object in a Map or Set. You must
  15197. * provide both or neither methods, one must not exist without the other.
  15198. *
  15199. * Also, an important relationship between these methods must be upheld: if two
  15200. * values are equal, they *must* return the same hashCode. If the values are not
  15201. * equal, they might have the same hashCode; this is called a hash collision,
  15202. * and while undesirable for performance reasons, it is acceptable.
  15203. *
  15204. * if (a.equals(b)) {
  15205. * assert( a.hashCode() === b.hashCode() );
  15206. * }
  15207. *
  15208. * All Immutable collections implement `equals` and `hashCode`.
  15209. *
  15210. */
  15211. function is(valueA, valueB) {
  15212. if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
  15213. return true;
  15214. }
  15215. if (!valueA || !valueB) {
  15216. return false;
  15217. }
  15218. if (typeof valueA.valueOf === 'function' &&
  15219. typeof valueB.valueOf === 'function') {
  15220. valueA = valueA.valueOf();
  15221. valueB = valueB.valueOf();
  15222. if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
  15223. return true;
  15224. }
  15225. if (!valueA || !valueB) {
  15226. return false;
  15227. }
  15228. }
  15229. if (typeof valueA.equals === 'function' &&
  15230. typeof valueB.equals === 'function' &&
  15231. valueA.equals(valueB)) {
  15232. return true;
  15233. }
  15234. return false;
  15235. }
  15236. function deepEqual(a, b) {
  15237. if (a === b) {
  15238. return true;
  15239. }
  15240. if (
  15241. !isIterable(b) ||
  15242. a.size !== undefined && b.size !== undefined && a.size !== b.size ||
  15243. a.__hash !== undefined && b.__hash !== undefined && a.__hash !== b.__hash ||
  15244. isKeyed(a) !== isKeyed(b) ||
  15245. isIndexed(a) !== isIndexed(b) ||
  15246. isOrdered(a) !== isOrdered(b)
  15247. ) {
  15248. return false;
  15249. }
  15250. if (a.size === 0 && b.size === 0) {
  15251. return true;
  15252. }
  15253. var notAssociative = !isAssociative(a);
  15254. if (isOrdered(a)) {
  15255. var entries = a.entries();
  15256. return b.every(function(v, k) {
  15257. var entry = entries.next().value;
  15258. return entry && is(entry[1], v) && (notAssociative || is(entry[0], k));
  15259. }) && entries.next().done;
  15260. }
  15261. var flipped = false;
  15262. if (a.size === undefined) {
  15263. if (b.size === undefined) {
  15264. if (typeof a.cacheResult === 'function') {
  15265. a.cacheResult();
  15266. }
  15267. } else {
  15268. flipped = true;
  15269. var _ = a;
  15270. a = b;
  15271. b = _;
  15272. }
  15273. }
  15274. var allEqual = true;
  15275. var bSize = b.__iterate(function(v, k) {
  15276. if (notAssociative ? !a.has(v) :
  15277. flipped ? !is(v, a.get(k, NOT_SET)) : !is(a.get(k, NOT_SET), v)) {
  15278. allEqual = false;
  15279. return false;
  15280. }
  15281. });
  15282. return allEqual && a.size === bSize;
  15283. }
  15284. createClass(Repeat, IndexedSeq);
  15285. function Repeat(value, times) {
  15286. if (!(this instanceof Repeat)) {
  15287. return new Repeat(value, times);
  15288. }
  15289. this._value = value;
  15290. this.size = times === undefined ? Infinity : Math.max(0, times);
  15291. if (this.size === 0) {
  15292. if (EMPTY_REPEAT) {
  15293. return EMPTY_REPEAT;
  15294. }
  15295. EMPTY_REPEAT = this;
  15296. }
  15297. }
  15298. Repeat.prototype.toString = function() {
  15299. if (this.size === 0) {
  15300. return 'Repeat []';
  15301. }
  15302. return 'Repeat [ ' + this._value + ' ' + this.size + ' times ]';
  15303. };
  15304. Repeat.prototype.get = function(index, notSetValue) {
  15305. return this.has(index) ? this._value : notSetValue;
  15306. };
  15307. Repeat.prototype.includes = function(searchValue) {
  15308. return is(this._value, searchValue);
  15309. };
  15310. Repeat.prototype.slice = function(begin, end) {
  15311. var size = this.size;
  15312. return wholeSlice(begin, end, size) ? this :
  15313. new Repeat(this._value, resolveEnd(end, size) - resolveBegin(begin, size));
  15314. };
  15315. Repeat.prototype.reverse = function() {
  15316. return this;
  15317. };
  15318. Repeat.prototype.indexOf = function(searchValue) {
  15319. if (is(this._value, searchValue)) {
  15320. return 0;
  15321. }
  15322. return -1;
  15323. };
  15324. Repeat.prototype.lastIndexOf = function(searchValue) {
  15325. if (is(this._value, searchValue)) {
  15326. return this.size;
  15327. }
  15328. return -1;
  15329. };
  15330. Repeat.prototype.__iterate = function(fn, reverse) {
  15331. for (var ii = 0; ii < this.size; ii++) {
  15332. if (fn(this._value, ii, this) === false) {
  15333. return ii + 1;
  15334. }
  15335. }
  15336. return ii;
  15337. };
  15338. Repeat.prototype.__iterator = function(type, reverse) {var this$0 = this;
  15339. var ii = 0;
  15340. return new Iterator(function()
  15341. {return ii < this$0.size ? iteratorValue(type, ii++, this$0._value) : iteratorDone()}
  15342. );
  15343. };
  15344. Repeat.prototype.equals = function(other) {
  15345. return other instanceof Repeat ?
  15346. is(this._value, other._value) :
  15347. deepEqual(other);
  15348. };
  15349. var EMPTY_REPEAT;
  15350. function invariant(condition, error) {
  15351. if (!condition) throw new Error(error);
  15352. }
  15353. createClass(Range, IndexedSeq);
  15354. function Range(start, end, step) {
  15355. if (!(this instanceof Range)) {
  15356. return new Range(start, end, step);
  15357. }
  15358. invariant(step !== 0, 'Cannot step a Range by 0');
  15359. start = start || 0;
  15360. if (end === undefined) {
  15361. end = Infinity;
  15362. }
  15363. step = step === undefined ? 1 : Math.abs(step);
  15364. if (end < start) {
  15365. step = -step;
  15366. }
  15367. this._start = start;
  15368. this._end = end;
  15369. this._step = step;
  15370. this.size = Math.max(0, Math.ceil((end - start) / step - 1) + 1);
  15371. if (this.size === 0) {
  15372. if (EMPTY_RANGE) {
  15373. return EMPTY_RANGE;
  15374. }
  15375. EMPTY_RANGE = this;
  15376. }
  15377. }
  15378. Range.prototype.toString = function() {
  15379. if (this.size === 0) {
  15380. return 'Range []';
  15381. }
  15382. return 'Range [ ' +
  15383. this._start + '...' + this._end +
  15384. (this._step > 1 ? ' by ' + this._step : '') +
  15385. ' ]';
  15386. };
  15387. Range.prototype.get = function(index, notSetValue) {
  15388. return this.has(index) ?
  15389. this._start + wrapIndex(this, index) * this._step :
  15390. notSetValue;
  15391. };
  15392. Range.prototype.includes = function(searchValue) {
  15393. var possibleIndex = (searchValue - this._start) / this._step;
  15394. return possibleIndex >= 0 &&
  15395. possibleIndex < this.size &&
  15396. possibleIndex === Math.floor(possibleIndex);
  15397. };
  15398. Range.prototype.slice = function(begin, end) {
  15399. if (wholeSlice(begin, end, this.size)) {
  15400. return this;
  15401. }
  15402. begin = resolveBegin(begin, this.size);
  15403. end = resolveEnd(end, this.size);
  15404. if (end <= begin) {
  15405. return new Range(0, 0);
  15406. }
  15407. return new Range(this.get(begin, this._end), this.get(end, this._end), this._step);
  15408. };
  15409. Range.prototype.indexOf = function(searchValue) {
  15410. var offsetValue = searchValue - this._start;
  15411. if (offsetValue % this._step === 0) {
  15412. var index = offsetValue / this._step;
  15413. if (index >= 0 && index < this.size) {
  15414. return index
  15415. }
  15416. }
  15417. return -1;
  15418. };
  15419. Range.prototype.lastIndexOf = function(searchValue) {
  15420. return this.indexOf(searchValue);
  15421. };
  15422. Range.prototype.__iterate = function(fn, reverse) {
  15423. var maxIndex = this.size - 1;
  15424. var step = this._step;
  15425. var value = reverse ? this._start + maxIndex * step : this._start;
  15426. for (var ii = 0; ii <= maxIndex; ii++) {
  15427. if (fn(value, ii, this) === false) {
  15428. return ii + 1;
  15429. }
  15430. value += reverse ? -step : step;
  15431. }
  15432. return ii;
  15433. };
  15434. Range.prototype.__iterator = function(type, reverse) {
  15435. var maxIndex = this.size - 1;
  15436. var step = this._step;
  15437. var value = reverse ? this._start + maxIndex * step : this._start;
  15438. var ii = 0;
  15439. return new Iterator(function() {
  15440. var v = value;
  15441. value += reverse ? -step : step;
  15442. return ii > maxIndex ? iteratorDone() : iteratorValue(type, ii++, v);
  15443. });
  15444. };
  15445. Range.prototype.equals = function(other) {
  15446. return other instanceof Range ?
  15447. this._start === other._start &&
  15448. this._end === other._end &&
  15449. this._step === other._step :
  15450. deepEqual(this, other);
  15451. };
  15452. var EMPTY_RANGE;
  15453. createClass(Collection, Iterable);
  15454. function Collection() {
  15455. throw TypeError('Abstract');
  15456. }
  15457. createClass(KeyedCollection, Collection);function KeyedCollection() {}
  15458. createClass(IndexedCollection, Collection);function IndexedCollection() {}
  15459. createClass(SetCollection, Collection);function SetCollection() {}
  15460. Collection.Keyed = KeyedCollection;
  15461. Collection.Indexed = IndexedCollection;
  15462. Collection.Set = SetCollection;
  15463. var imul =
  15464. typeof Math.imul === 'function' && Math.imul(0xffffffff, 2) === -2 ?
  15465. Math.imul :
  15466. function imul(a, b) {
  15467. a = a | 0; // int
  15468. b = b | 0; // int
  15469. var c = a & 0xffff;
  15470. var d = b & 0xffff;
  15471. // Shift by 0 fixes the sign on the high part.
  15472. return (c * d) + ((((a >>> 16) * d + c * (b >>> 16)) << 16) >>> 0) | 0; // int
  15473. };
  15474. // v8 has an optimization for storing 31-bit signed numbers.
  15475. // Values which have either 00 or 11 as the high order bits qualify.
  15476. // This function drops the highest order bit in a signed number, maintaining
  15477. // the sign bit.
  15478. function smi(i32) {
  15479. return ((i32 >>> 1) & 0x40000000) | (i32 & 0xBFFFFFFF);
  15480. }
  15481. function hash(o) {
  15482. if (o === false || o === null || o === undefined) {
  15483. return 0;
  15484. }
  15485. if (typeof o.valueOf === 'function') {
  15486. o = o.valueOf();
  15487. if (o === false || o === null || o === undefined) {
  15488. return 0;
  15489. }
  15490. }
  15491. if (o === true) {
  15492. return 1;
  15493. }
  15494. var type = typeof o;
  15495. if (type === 'number') {
  15496. var h = o | 0;
  15497. if (h !== o) {
  15498. h ^= o * 0xFFFFFFFF;
  15499. }
  15500. while (o > 0xFFFFFFFF) {
  15501. o /= 0xFFFFFFFF;
  15502. h ^= o;
  15503. }
  15504. return smi(h);
  15505. }
  15506. if (type === 'string') {
  15507. return o.length > STRING_HASH_CACHE_MIN_STRLEN ? cachedHashString(o) : hashString(o);
  15508. }
  15509. if (typeof o.hashCode === 'function') {
  15510. return o.hashCode();
  15511. }
  15512. if (type === 'object') {
  15513. return hashJSObj(o);
  15514. }
  15515. if (typeof o.toString === 'function') {
  15516. return hashString(o.toString());
  15517. }
  15518. throw new Error('Value type ' + type + ' cannot be hashed.');
  15519. }
  15520. function cachedHashString(string) {
  15521. var hash = stringHashCache[string];
  15522. if (hash === undefined) {
  15523. hash = hashString(string);
  15524. if (STRING_HASH_CACHE_SIZE === STRING_HASH_CACHE_MAX_SIZE) {
  15525. STRING_HASH_CACHE_SIZE = 0;
  15526. stringHashCache = {};
  15527. }
  15528. STRING_HASH_CACHE_SIZE++;
  15529. stringHashCache[string] = hash;
  15530. }
  15531. return hash;
  15532. }
  15533. // http://jsperf.com/hashing-strings
  15534. function hashString(string) {
  15535. // This is the hash from JVM
  15536. // The hash code for a string is computed as
  15537. // s[0] * 31 ^ (n - 1) + s[1] * 31 ^ (n - 2) + ... + s[n - 1],
  15538. // where s[i] is the ith character of the string and n is the length of
  15539. // the string. We "mod" the result to make it between 0 (inclusive) and 2^31
  15540. // (exclusive) by dropping high bits.
  15541. var hash = 0;
  15542. for (var ii = 0; ii < string.length; ii++) {
  15543. hash = 31 * hash + string.charCodeAt(ii) | 0;
  15544. }
  15545. return smi(hash);
  15546. }
  15547. function hashJSObj(obj) {
  15548. var hash;
  15549. if (usingWeakMap) {
  15550. hash = weakMap.get(obj);
  15551. if (hash !== undefined) {
  15552. return hash;
  15553. }
  15554. }
  15555. hash = obj[UID_HASH_KEY];
  15556. if (hash !== undefined) {
  15557. return hash;
  15558. }
  15559. if (!canDefineProperty) {
  15560. hash = obj.propertyIsEnumerable && obj.propertyIsEnumerable[UID_HASH_KEY];
  15561. if (hash !== undefined) {
  15562. return hash;
  15563. }
  15564. hash = getIENodeHash(obj);
  15565. if (hash !== undefined) {
  15566. return hash;
  15567. }
  15568. }
  15569. hash = ++objHashUID;
  15570. if (objHashUID & 0x40000000) {
  15571. objHashUID = 0;
  15572. }
  15573. if (usingWeakMap) {
  15574. weakMap.set(obj, hash);
  15575. } else if (isExtensible !== undefined && isExtensible(obj) === false) {
  15576. throw new Error('Non-extensible objects are not allowed as keys.');
  15577. } else if (canDefineProperty) {
  15578. Object.defineProperty(obj, UID_HASH_KEY, {
  15579. 'enumerable': false,
  15580. 'configurable': false,
  15581. 'writable': false,
  15582. 'value': hash
  15583. });
  15584. } else if (obj.propertyIsEnumerable !== undefined &&
  15585. obj.propertyIsEnumerable === obj.constructor.prototype.propertyIsEnumerable) {
  15586. // Since we can't define a non-enumerable property on the object
  15587. // we'll hijack one of the less-used non-enumerable properties to
  15588. // save our hash on it. Since this is a function it will not show up in
  15589. // `JSON.stringify` which is what we want.
  15590. obj.propertyIsEnumerable = function() {
  15591. return this.constructor.prototype.propertyIsEnumerable.apply(this, arguments);
  15592. };
  15593. obj.propertyIsEnumerable[UID_HASH_KEY] = hash;
  15594. } else if (obj.nodeType !== undefined) {
  15595. // At this point we couldn't get the IE `uniqueID` to use as a hash
  15596. // and we couldn't use a non-enumerable property to exploit the
  15597. // dontEnum bug so we simply add the `UID_HASH_KEY` on the node
  15598. // itself.
  15599. obj[UID_HASH_KEY] = hash;
  15600. } else {
  15601. throw new Error('Unable to set a non-enumerable property on object.');
  15602. }
  15603. return hash;
  15604. }
  15605. // Get references to ES5 object methods.
  15606. var isExtensible = Object.isExtensible;
  15607. // True if Object.defineProperty works as expected. IE8 fails this test.
  15608. var canDefineProperty = (function() {
  15609. try {
  15610. Object.defineProperty({}, '@', {});
  15611. return true;
  15612. } catch (e) {
  15613. return false;
  15614. }
  15615. }());
  15616. // IE has a `uniqueID` property on DOM nodes. We can construct the hash from it
  15617. // and avoid memory leaks from the IE cloneNode bug.
  15618. function getIENodeHash(node) {
  15619. if (node && node.nodeType > 0) {
  15620. switch (node.nodeType) {
  15621. case 1: // Element
  15622. return node.uniqueID;
  15623. case 9: // Document
  15624. return node.documentElement && node.documentElement.uniqueID;
  15625. }
  15626. }
  15627. }
  15628. // If possible, use a WeakMap.
  15629. var usingWeakMap = typeof WeakMap === 'function';
  15630. var weakMap;
  15631. if (usingWeakMap) {
  15632. weakMap = new WeakMap();
  15633. }
  15634. var objHashUID = 0;
  15635. var UID_HASH_KEY = '__immutablehash__';
  15636. if (typeof Symbol === 'function') {
  15637. UID_HASH_KEY = Symbol(UID_HASH_KEY);
  15638. }
  15639. var STRING_HASH_CACHE_MIN_STRLEN = 16;
  15640. var STRING_HASH_CACHE_MAX_SIZE = 255;
  15641. var STRING_HASH_CACHE_SIZE = 0;
  15642. var stringHashCache = {};
  15643. function assertNotInfinite(size) {
  15644. invariant(
  15645. size !== Infinity,
  15646. 'Cannot perform this action with an infinite size.'
  15647. );
  15648. }
  15649. createClass(Map, KeyedCollection);
  15650. // @pragma Construction
  15651. function Map(value) {
  15652. return value === null || value === undefined ? emptyMap() :
  15653. isMap(value) && !isOrdered(value) ? value :
  15654. emptyMap().withMutations(function(map ) {
  15655. var iter = KeyedIterable(value);
  15656. assertNotInfinite(iter.size);
  15657. iter.forEach(function(v, k) {return map.set(k, v)});
  15658. });
  15659. }
  15660. Map.prototype.toString = function() {
  15661. return this.__toString('Map {', '}');
  15662. };
  15663. // @pragma Access
  15664. Map.prototype.get = function(k, notSetValue) {
  15665. return this._root ?
  15666. this._root.get(0, undefined, k, notSetValue) :
  15667. notSetValue;
  15668. };
  15669. // @pragma Modification
  15670. Map.prototype.set = function(k, v) {
  15671. return updateMap(this, k, v);
  15672. };
  15673. Map.prototype.setIn = function(keyPath, v) {
  15674. return this.updateIn(keyPath, NOT_SET, function() {return v});
  15675. };
  15676. Map.prototype.remove = function(k) {
  15677. return updateMap(this, k, NOT_SET);
  15678. };
  15679. Map.prototype.deleteIn = function(keyPath) {
  15680. return this.updateIn(keyPath, function() {return NOT_SET});
  15681. };
  15682. Map.prototype.update = function(k, notSetValue, updater) {
  15683. return arguments.length === 1 ?
  15684. k(this) :
  15685. this.updateIn([k], notSetValue, updater);
  15686. };
  15687. Map.prototype.updateIn = function(keyPath, notSetValue, updater) {
  15688. if (!updater) {
  15689. updater = notSetValue;
  15690. notSetValue = undefined;
  15691. }
  15692. var updatedValue = updateInDeepMap(
  15693. this,
  15694. forceIterator(keyPath),
  15695. notSetValue,
  15696. updater
  15697. );
  15698. return updatedValue === NOT_SET ? undefined : updatedValue;
  15699. };
  15700. Map.prototype.clear = function() {
  15701. if (this.size === 0) {
  15702. return this;
  15703. }
  15704. if (this.__ownerID) {
  15705. this.size = 0;
  15706. this._root = null;
  15707. this.__hash = undefined;
  15708. this.__altered = true;
  15709. return this;
  15710. }
  15711. return emptyMap();
  15712. };
  15713. // @pragma Composition
  15714. Map.prototype.merge = function(/*...iters*/) {
  15715. return mergeIntoMapWith(this, undefined, arguments);
  15716. };
  15717. Map.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  15718. return mergeIntoMapWith(this, merger, iters);
  15719. };
  15720. Map.prototype.mergeIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1);
  15721. return this.updateIn(
  15722. keyPath,
  15723. emptyMap(),
  15724. function(m ) {return typeof m.merge === 'function' ?
  15725. m.merge.apply(m, iters) :
  15726. iters[iters.length - 1]}
  15727. );
  15728. };
  15729. Map.prototype.mergeDeep = function(/*...iters*/) {
  15730. return mergeIntoMapWith(this, deepMerger, arguments);
  15731. };
  15732. Map.prototype.mergeDeepWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  15733. return mergeIntoMapWith(this, deepMergerWith(merger), iters);
  15734. };
  15735. Map.prototype.mergeDeepIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1);
  15736. return this.updateIn(
  15737. keyPath,
  15738. emptyMap(),
  15739. function(m ) {return typeof m.mergeDeep === 'function' ?
  15740. m.mergeDeep.apply(m, iters) :
  15741. iters[iters.length - 1]}
  15742. );
  15743. };
  15744. Map.prototype.sort = function(comparator) {
  15745. // Late binding
  15746. return OrderedMap(sortFactory(this, comparator));
  15747. };
  15748. Map.prototype.sortBy = function(mapper, comparator) {
  15749. // Late binding
  15750. return OrderedMap(sortFactory(this, comparator, mapper));
  15751. };
  15752. // @pragma Mutability
  15753. Map.prototype.withMutations = function(fn) {
  15754. var mutable = this.asMutable();
  15755. fn(mutable);
  15756. return mutable.wasAltered() ? mutable.__ensureOwner(this.__ownerID) : this;
  15757. };
  15758. Map.prototype.asMutable = function() {
  15759. return this.__ownerID ? this : this.__ensureOwner(new OwnerID());
  15760. };
  15761. Map.prototype.asImmutable = function() {
  15762. return this.__ensureOwner();
  15763. };
  15764. Map.prototype.wasAltered = function() {
  15765. return this.__altered;
  15766. };
  15767. Map.prototype.__iterator = function(type, reverse) {
  15768. return new MapIterator(this, type, reverse);
  15769. };
  15770. Map.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  15771. var iterations = 0;
  15772. this._root && this._root.iterate(function(entry ) {
  15773. iterations++;
  15774. return fn(entry[1], entry[0], this$0);
  15775. }, reverse);
  15776. return iterations;
  15777. };
  15778. Map.prototype.__ensureOwner = function(ownerID) {
  15779. if (ownerID === this.__ownerID) {
  15780. return this;
  15781. }
  15782. if (!ownerID) {
  15783. this.__ownerID = ownerID;
  15784. this.__altered = false;
  15785. return this;
  15786. }
  15787. return makeMap(this.size, this._root, ownerID, this.__hash);
  15788. };
  15789. function isMap(maybeMap) {
  15790. return !!(maybeMap && maybeMap[IS_MAP_SENTINEL]);
  15791. }
  15792. Map.isMap = isMap;
  15793. var IS_MAP_SENTINEL = '@@__IMMUTABLE_MAP__@@';
  15794. var MapPrototype = Map.prototype;
  15795. MapPrototype[IS_MAP_SENTINEL] = true;
  15796. MapPrototype[DELETE] = MapPrototype.remove;
  15797. MapPrototype.removeIn = MapPrototype.deleteIn;
  15798. // #pragma Trie Nodes
  15799. function ArrayMapNode(ownerID, entries) {
  15800. this.ownerID = ownerID;
  15801. this.entries = entries;
  15802. }
  15803. ArrayMapNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  15804. var entries = this.entries;
  15805. for (var ii = 0, len = entries.length; ii < len; ii++) {
  15806. if (is(key, entries[ii][0])) {
  15807. return entries[ii][1];
  15808. }
  15809. }
  15810. return notSetValue;
  15811. };
  15812. ArrayMapNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  15813. var removed = value === NOT_SET;
  15814. var entries = this.entries;
  15815. var idx = 0;
  15816. for (var len = entries.length; idx < len; idx++) {
  15817. if (is(key, entries[idx][0])) {
  15818. break;
  15819. }
  15820. }
  15821. var exists = idx < len;
  15822. if (exists ? entries[idx][1] === value : removed) {
  15823. return this;
  15824. }
  15825. SetRef(didAlter);
  15826. (removed || !exists) && SetRef(didChangeSize);
  15827. if (removed && entries.length === 1) {
  15828. return; // undefined
  15829. }
  15830. if (!exists && !removed && entries.length >= MAX_ARRAY_MAP_SIZE) {
  15831. return createNodes(ownerID, entries, key, value);
  15832. }
  15833. var isEditable = ownerID && ownerID === this.ownerID;
  15834. var newEntries = isEditable ? entries : arrCopy(entries);
  15835. if (exists) {
  15836. if (removed) {
  15837. idx === len - 1 ? newEntries.pop() : (newEntries[idx] = newEntries.pop());
  15838. } else {
  15839. newEntries[idx] = [key, value];
  15840. }
  15841. } else {
  15842. newEntries.push([key, value]);
  15843. }
  15844. if (isEditable) {
  15845. this.entries = newEntries;
  15846. return this;
  15847. }
  15848. return new ArrayMapNode(ownerID, newEntries);
  15849. };
  15850. function BitmapIndexedNode(ownerID, bitmap, nodes) {
  15851. this.ownerID = ownerID;
  15852. this.bitmap = bitmap;
  15853. this.nodes = nodes;
  15854. }
  15855. BitmapIndexedNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  15856. if (keyHash === undefined) {
  15857. keyHash = hash(key);
  15858. }
  15859. var bit = (1 << ((shift === 0 ? keyHash : keyHash >>> shift) & MASK));
  15860. var bitmap = this.bitmap;
  15861. return (bitmap & bit) === 0 ? notSetValue :
  15862. this.nodes[popCount(bitmap & (bit - 1))].get(shift + SHIFT, keyHash, key, notSetValue);
  15863. };
  15864. BitmapIndexedNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  15865. if (keyHash === undefined) {
  15866. keyHash = hash(key);
  15867. }
  15868. var keyHashFrag = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  15869. var bit = 1 << keyHashFrag;
  15870. var bitmap = this.bitmap;
  15871. var exists = (bitmap & bit) !== 0;
  15872. if (!exists && value === NOT_SET) {
  15873. return this;
  15874. }
  15875. var idx = popCount(bitmap & (bit - 1));
  15876. var nodes = this.nodes;
  15877. var node = exists ? nodes[idx] : undefined;
  15878. var newNode = updateNode(node, ownerID, shift + SHIFT, keyHash, key, value, didChangeSize, didAlter);
  15879. if (newNode === node) {
  15880. return this;
  15881. }
  15882. if (!exists && newNode && nodes.length >= MAX_BITMAP_INDEXED_SIZE) {
  15883. return expandNodes(ownerID, nodes, bitmap, keyHashFrag, newNode);
  15884. }
  15885. if (exists && !newNode && nodes.length === 2 && isLeafNode(nodes[idx ^ 1])) {
  15886. return nodes[idx ^ 1];
  15887. }
  15888. if (exists && newNode && nodes.length === 1 && isLeafNode(newNode)) {
  15889. return newNode;
  15890. }
  15891. var isEditable = ownerID && ownerID === this.ownerID;
  15892. var newBitmap = exists ? newNode ? bitmap : bitmap ^ bit : bitmap | bit;
  15893. var newNodes = exists ? newNode ?
  15894. setIn(nodes, idx, newNode, isEditable) :
  15895. spliceOut(nodes, idx, isEditable) :
  15896. spliceIn(nodes, idx, newNode, isEditable);
  15897. if (isEditable) {
  15898. this.bitmap = newBitmap;
  15899. this.nodes = newNodes;
  15900. return this;
  15901. }
  15902. return new BitmapIndexedNode(ownerID, newBitmap, newNodes);
  15903. };
  15904. function HashArrayMapNode(ownerID, count, nodes) {
  15905. this.ownerID = ownerID;
  15906. this.count = count;
  15907. this.nodes = nodes;
  15908. }
  15909. HashArrayMapNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  15910. if (keyHash === undefined) {
  15911. keyHash = hash(key);
  15912. }
  15913. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  15914. var node = this.nodes[idx];
  15915. return node ? node.get(shift + SHIFT, keyHash, key, notSetValue) : notSetValue;
  15916. };
  15917. HashArrayMapNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  15918. if (keyHash === undefined) {
  15919. keyHash = hash(key);
  15920. }
  15921. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  15922. var removed = value === NOT_SET;
  15923. var nodes = this.nodes;
  15924. var node = nodes[idx];
  15925. if (removed && !node) {
  15926. return this;
  15927. }
  15928. var newNode = updateNode(node, ownerID, shift + SHIFT, keyHash, key, value, didChangeSize, didAlter);
  15929. if (newNode === node) {
  15930. return this;
  15931. }
  15932. var newCount = this.count;
  15933. if (!node) {
  15934. newCount++;
  15935. } else if (!newNode) {
  15936. newCount--;
  15937. if (newCount < MIN_HASH_ARRAY_MAP_SIZE) {
  15938. return packNodes(ownerID, nodes, newCount, idx);
  15939. }
  15940. }
  15941. var isEditable = ownerID && ownerID === this.ownerID;
  15942. var newNodes = setIn(nodes, idx, newNode, isEditable);
  15943. if (isEditable) {
  15944. this.count = newCount;
  15945. this.nodes = newNodes;
  15946. return this;
  15947. }
  15948. return new HashArrayMapNode(ownerID, newCount, newNodes);
  15949. };
  15950. function HashCollisionNode(ownerID, keyHash, entries) {
  15951. this.ownerID = ownerID;
  15952. this.keyHash = keyHash;
  15953. this.entries = entries;
  15954. }
  15955. HashCollisionNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  15956. var entries = this.entries;
  15957. for (var ii = 0, len = entries.length; ii < len; ii++) {
  15958. if (is(key, entries[ii][0])) {
  15959. return entries[ii][1];
  15960. }
  15961. }
  15962. return notSetValue;
  15963. };
  15964. HashCollisionNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  15965. if (keyHash === undefined) {
  15966. keyHash = hash(key);
  15967. }
  15968. var removed = value === NOT_SET;
  15969. if (keyHash !== this.keyHash) {
  15970. if (removed) {
  15971. return this;
  15972. }
  15973. SetRef(didAlter);
  15974. SetRef(didChangeSize);
  15975. return mergeIntoNode(this, ownerID, shift, keyHash, [key, value]);
  15976. }
  15977. var entries = this.entries;
  15978. var idx = 0;
  15979. for (var len = entries.length; idx < len; idx++) {
  15980. if (is(key, entries[idx][0])) {
  15981. break;
  15982. }
  15983. }
  15984. var exists = idx < len;
  15985. if (exists ? entries[idx][1] === value : removed) {
  15986. return this;
  15987. }
  15988. SetRef(didAlter);
  15989. (removed || !exists) && SetRef(didChangeSize);
  15990. if (removed && len === 2) {
  15991. return new ValueNode(ownerID, this.keyHash, entries[idx ^ 1]);
  15992. }
  15993. var isEditable = ownerID && ownerID === this.ownerID;
  15994. var newEntries = isEditable ? entries : arrCopy(entries);
  15995. if (exists) {
  15996. if (removed) {
  15997. idx === len - 1 ? newEntries.pop() : (newEntries[idx] = newEntries.pop());
  15998. } else {
  15999. newEntries[idx] = [key, value];
  16000. }
  16001. } else {
  16002. newEntries.push([key, value]);
  16003. }
  16004. if (isEditable) {
  16005. this.entries = newEntries;
  16006. return this;
  16007. }
  16008. return new HashCollisionNode(ownerID, this.keyHash, newEntries);
  16009. };
  16010. function ValueNode(ownerID, keyHash, entry) {
  16011. this.ownerID = ownerID;
  16012. this.keyHash = keyHash;
  16013. this.entry = entry;
  16014. }
  16015. ValueNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  16016. return is(key, this.entry[0]) ? this.entry[1] : notSetValue;
  16017. };
  16018. ValueNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  16019. var removed = value === NOT_SET;
  16020. var keyMatch = is(key, this.entry[0]);
  16021. if (keyMatch ? value === this.entry[1] : removed) {
  16022. return this;
  16023. }
  16024. SetRef(didAlter);
  16025. if (removed) {
  16026. SetRef(didChangeSize);
  16027. return; // undefined
  16028. }
  16029. if (keyMatch) {
  16030. if (ownerID && ownerID === this.ownerID) {
  16031. this.entry[1] = value;
  16032. return this;
  16033. }
  16034. return new ValueNode(ownerID, this.keyHash, [key, value]);
  16035. }
  16036. SetRef(didChangeSize);
  16037. return mergeIntoNode(this, ownerID, shift, hash(key), [key, value]);
  16038. };
  16039. // #pragma Iterators
  16040. ArrayMapNode.prototype.iterate =
  16041. HashCollisionNode.prototype.iterate = function (fn, reverse) {
  16042. var entries = this.entries;
  16043. for (var ii = 0, maxIndex = entries.length - 1; ii <= maxIndex; ii++) {
  16044. if (fn(entries[reverse ? maxIndex - ii : ii]) === false) {
  16045. return false;
  16046. }
  16047. }
  16048. };
  16049. BitmapIndexedNode.prototype.iterate =
  16050. HashArrayMapNode.prototype.iterate = function (fn, reverse) {
  16051. var nodes = this.nodes;
  16052. for (var ii = 0, maxIndex = nodes.length - 1; ii <= maxIndex; ii++) {
  16053. var node = nodes[reverse ? maxIndex - ii : ii];
  16054. if (node && node.iterate(fn, reverse) === false) {
  16055. return false;
  16056. }
  16057. }
  16058. };
  16059. ValueNode.prototype.iterate = function (fn, reverse) {
  16060. return fn(this.entry);
  16061. };
  16062. createClass(MapIterator, Iterator);
  16063. function MapIterator(map, type, reverse) {
  16064. this._type = type;
  16065. this._reverse = reverse;
  16066. this._stack = map._root && mapIteratorFrame(map._root);
  16067. }
  16068. MapIterator.prototype.next = function() {
  16069. var type = this._type;
  16070. var stack = this._stack;
  16071. while (stack) {
  16072. var node = stack.node;
  16073. var index = stack.index++;
  16074. var maxIndex;
  16075. if (node.entry) {
  16076. if (index === 0) {
  16077. return mapIteratorValue(type, node.entry);
  16078. }
  16079. } else if (node.entries) {
  16080. maxIndex = node.entries.length - 1;
  16081. if (index <= maxIndex) {
  16082. return mapIteratorValue(type, node.entries[this._reverse ? maxIndex - index : index]);
  16083. }
  16084. } else {
  16085. maxIndex = node.nodes.length - 1;
  16086. if (index <= maxIndex) {
  16087. var subNode = node.nodes[this._reverse ? maxIndex - index : index];
  16088. if (subNode) {
  16089. if (subNode.entry) {
  16090. return mapIteratorValue(type, subNode.entry);
  16091. }
  16092. stack = this._stack = mapIteratorFrame(subNode, stack);
  16093. }
  16094. continue;
  16095. }
  16096. }
  16097. stack = this._stack = this._stack.__prev;
  16098. }
  16099. return iteratorDone();
  16100. };
  16101. function mapIteratorValue(type, entry) {
  16102. return iteratorValue(type, entry[0], entry[1]);
  16103. }
  16104. function mapIteratorFrame(node, prev) {
  16105. return {
  16106. node: node,
  16107. index: 0,
  16108. __prev: prev
  16109. };
  16110. }
  16111. function makeMap(size, root, ownerID, hash) {
  16112. var map = Object.create(MapPrototype);
  16113. map.size = size;
  16114. map._root = root;
  16115. map.__ownerID = ownerID;
  16116. map.__hash = hash;
  16117. map.__altered = false;
  16118. return map;
  16119. }
  16120. var EMPTY_MAP;
  16121. function emptyMap() {
  16122. return EMPTY_MAP || (EMPTY_MAP = makeMap(0));
  16123. }
  16124. function updateMap(map, k, v) {
  16125. var newRoot;
  16126. var newSize;
  16127. if (!map._root) {
  16128. if (v === NOT_SET) {
  16129. return map;
  16130. }
  16131. newSize = 1;
  16132. newRoot = new ArrayMapNode(map.__ownerID, [[k, v]]);
  16133. } else {
  16134. var didChangeSize = MakeRef(CHANGE_LENGTH);
  16135. var didAlter = MakeRef(DID_ALTER);
  16136. newRoot = updateNode(map._root, map.__ownerID, 0, undefined, k, v, didChangeSize, didAlter);
  16137. if (!didAlter.value) {
  16138. return map;
  16139. }
  16140. newSize = map.size + (didChangeSize.value ? v === NOT_SET ? -1 : 1 : 0);
  16141. }
  16142. if (map.__ownerID) {
  16143. map.size = newSize;
  16144. map._root = newRoot;
  16145. map.__hash = undefined;
  16146. map.__altered = true;
  16147. return map;
  16148. }
  16149. return newRoot ? makeMap(newSize, newRoot) : emptyMap();
  16150. }
  16151. function updateNode(node, ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  16152. if (!node) {
  16153. if (value === NOT_SET) {
  16154. return node;
  16155. }
  16156. SetRef(didAlter);
  16157. SetRef(didChangeSize);
  16158. return new ValueNode(ownerID, keyHash, [key, value]);
  16159. }
  16160. return node.update(ownerID, shift, keyHash, key, value, didChangeSize, didAlter);
  16161. }
  16162. function isLeafNode(node) {
  16163. return node.constructor === ValueNode || node.constructor === HashCollisionNode;
  16164. }
  16165. function mergeIntoNode(node, ownerID, shift, keyHash, entry) {
  16166. if (node.keyHash === keyHash) {
  16167. return new HashCollisionNode(ownerID, keyHash, [node.entry, entry]);
  16168. }
  16169. var idx1 = (shift === 0 ? node.keyHash : node.keyHash >>> shift) & MASK;
  16170. var idx2 = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  16171. var newNode;
  16172. var nodes = idx1 === idx2 ?
  16173. [mergeIntoNode(node, ownerID, shift + SHIFT, keyHash, entry)] :
  16174. ((newNode = new ValueNode(ownerID, keyHash, entry)), idx1 < idx2 ? [node, newNode] : [newNode, node]);
  16175. return new BitmapIndexedNode(ownerID, (1 << idx1) | (1 << idx2), nodes);
  16176. }
  16177. function createNodes(ownerID, entries, key, value) {
  16178. if (!ownerID) {
  16179. ownerID = new OwnerID();
  16180. }
  16181. var node = new ValueNode(ownerID, hash(key), [key, value]);
  16182. for (var ii = 0; ii < entries.length; ii++) {
  16183. var entry = entries[ii];
  16184. node = node.update(ownerID, 0, undefined, entry[0], entry[1]);
  16185. }
  16186. return node;
  16187. }
  16188. function packNodes(ownerID, nodes, count, excluding) {
  16189. var bitmap = 0;
  16190. var packedII = 0;
  16191. var packedNodes = new Array(count);
  16192. for (var ii = 0, bit = 1, len = nodes.length; ii < len; ii++, bit <<= 1) {
  16193. var node = nodes[ii];
  16194. if (node !== undefined && ii !== excluding) {
  16195. bitmap |= bit;
  16196. packedNodes[packedII++] = node;
  16197. }
  16198. }
  16199. return new BitmapIndexedNode(ownerID, bitmap, packedNodes);
  16200. }
  16201. function expandNodes(ownerID, nodes, bitmap, including, node) {
  16202. var count = 0;
  16203. var expandedNodes = new Array(SIZE);
  16204. for (var ii = 0; bitmap !== 0; ii++, bitmap >>>= 1) {
  16205. expandedNodes[ii] = bitmap & 1 ? nodes[count++] : undefined;
  16206. }
  16207. expandedNodes[including] = node;
  16208. return new HashArrayMapNode(ownerID, count + 1, expandedNodes);
  16209. }
  16210. function mergeIntoMapWith(map, merger, iterables) {
  16211. var iters = [];
  16212. for (var ii = 0; ii < iterables.length; ii++) {
  16213. var value = iterables[ii];
  16214. var iter = KeyedIterable(value);
  16215. if (!isIterable(value)) {
  16216. iter = iter.map(function(v ) {return fromJS(v)});
  16217. }
  16218. iters.push(iter);
  16219. }
  16220. return mergeIntoCollectionWith(map, merger, iters);
  16221. }
  16222. function deepMerger(existing, value, key) {
  16223. return existing && existing.mergeDeep && isIterable(value) ?
  16224. existing.mergeDeep(value) :
  16225. is(existing, value) ? existing : value;
  16226. }
  16227. function deepMergerWith(merger) {
  16228. return function(existing, value, key) {
  16229. if (existing && existing.mergeDeepWith && isIterable(value)) {
  16230. return existing.mergeDeepWith(merger, value);
  16231. }
  16232. var nextValue = merger(existing, value, key);
  16233. return is(existing, nextValue) ? existing : nextValue;
  16234. };
  16235. }
  16236. function mergeIntoCollectionWith(collection, merger, iters) {
  16237. iters = iters.filter(function(x ) {return x.size !== 0});
  16238. if (iters.length === 0) {
  16239. return collection;
  16240. }
  16241. if (collection.size === 0 && !collection.__ownerID && iters.length === 1) {
  16242. return collection.constructor(iters[0]);
  16243. }
  16244. return collection.withMutations(function(collection ) {
  16245. var mergeIntoMap = merger ?
  16246. function(value, key) {
  16247. collection.update(key, NOT_SET, function(existing )
  16248. {return existing === NOT_SET ? value : merger(existing, value, key)}
  16249. );
  16250. } :
  16251. function(value, key) {
  16252. collection.set(key, value);
  16253. };
  16254. for (var ii = 0; ii < iters.length; ii++) {
  16255. iters[ii].forEach(mergeIntoMap);
  16256. }
  16257. });
  16258. }
  16259. function updateInDeepMap(existing, keyPathIter, notSetValue, updater) {
  16260. var isNotSet = existing === NOT_SET;
  16261. var step = keyPathIter.next();
  16262. if (step.done) {
  16263. var existingValue = isNotSet ? notSetValue : existing;
  16264. var newValue = updater(existingValue);
  16265. return newValue === existingValue ? existing : newValue;
  16266. }
  16267. invariant(
  16268. isNotSet || (existing && existing.set),
  16269. 'invalid keyPath'
  16270. );
  16271. var key = step.value;
  16272. var nextExisting = isNotSet ? NOT_SET : existing.get(key, NOT_SET);
  16273. var nextUpdated = updateInDeepMap(
  16274. nextExisting,
  16275. keyPathIter,
  16276. notSetValue,
  16277. updater
  16278. );
  16279. return nextUpdated === nextExisting ? existing :
  16280. nextUpdated === NOT_SET ? existing.remove(key) :
  16281. (isNotSet ? emptyMap() : existing).set(key, nextUpdated);
  16282. }
  16283. function popCount(x) {
  16284. x = x - ((x >> 1) & 0x55555555);
  16285. x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
  16286. x = (x + (x >> 4)) & 0x0f0f0f0f;
  16287. x = x + (x >> 8);
  16288. x = x + (x >> 16);
  16289. return x & 0x7f;
  16290. }
  16291. function setIn(array, idx, val, canEdit) {
  16292. var newArray = canEdit ? array : arrCopy(array);
  16293. newArray[idx] = val;
  16294. return newArray;
  16295. }
  16296. function spliceIn(array, idx, val, canEdit) {
  16297. var newLen = array.length + 1;
  16298. if (canEdit && idx + 1 === newLen) {
  16299. array[idx] = val;
  16300. return array;
  16301. }
  16302. var newArray = new Array(newLen);
  16303. var after = 0;
  16304. for (var ii = 0; ii < newLen; ii++) {
  16305. if (ii === idx) {
  16306. newArray[ii] = val;
  16307. after = -1;
  16308. } else {
  16309. newArray[ii] = array[ii + after];
  16310. }
  16311. }
  16312. return newArray;
  16313. }
  16314. function spliceOut(array, idx, canEdit) {
  16315. var newLen = array.length - 1;
  16316. if (canEdit && idx === newLen) {
  16317. array.pop();
  16318. return array;
  16319. }
  16320. var newArray = new Array(newLen);
  16321. var after = 0;
  16322. for (var ii = 0; ii < newLen; ii++) {
  16323. if (ii === idx) {
  16324. after = 1;
  16325. }
  16326. newArray[ii] = array[ii + after];
  16327. }
  16328. return newArray;
  16329. }
  16330. var MAX_ARRAY_MAP_SIZE = SIZE / 4;
  16331. var MAX_BITMAP_INDEXED_SIZE = SIZE / 2;
  16332. var MIN_HASH_ARRAY_MAP_SIZE = SIZE / 4;
  16333. createClass(List, IndexedCollection);
  16334. // @pragma Construction
  16335. function List(value) {
  16336. var empty = emptyList();
  16337. if (value === null || value === undefined) {
  16338. return empty;
  16339. }
  16340. if (isList(value)) {
  16341. return value;
  16342. }
  16343. var iter = IndexedIterable(value);
  16344. var size = iter.size;
  16345. if (size === 0) {
  16346. return empty;
  16347. }
  16348. assertNotInfinite(size);
  16349. if (size > 0 && size < SIZE) {
  16350. return makeList(0, size, SHIFT, null, new VNode(iter.toArray()));
  16351. }
  16352. return empty.withMutations(function(list ) {
  16353. list.setSize(size);
  16354. iter.forEach(function(v, i) {return list.set(i, v)});
  16355. });
  16356. }
  16357. List.of = function(/*...values*/) {
  16358. return this(arguments);
  16359. };
  16360. List.prototype.toString = function() {
  16361. return this.__toString('List [', ']');
  16362. };
  16363. // @pragma Access
  16364. List.prototype.get = function(index, notSetValue) {
  16365. index = wrapIndex(this, index);
  16366. if (index >= 0 && index < this.size) {
  16367. index += this._origin;
  16368. var node = listNodeFor(this, index);
  16369. return node && node.array[index & MASK];
  16370. }
  16371. return notSetValue;
  16372. };
  16373. // @pragma Modification
  16374. List.prototype.set = function(index, value) {
  16375. return updateList(this, index, value);
  16376. };
  16377. List.prototype.remove = function(index) {
  16378. return !this.has(index) ? this :
  16379. index === 0 ? this.shift() :
  16380. index === this.size - 1 ? this.pop() :
  16381. this.splice(index, 1);
  16382. };
  16383. List.prototype.insert = function(index, value) {
  16384. return this.splice(index, 0, value);
  16385. };
  16386. List.prototype.clear = function() {
  16387. if (this.size === 0) {
  16388. return this;
  16389. }
  16390. if (this.__ownerID) {
  16391. this.size = this._origin = this._capacity = 0;
  16392. this._level = SHIFT;
  16393. this._root = this._tail = null;
  16394. this.__hash = undefined;
  16395. this.__altered = true;
  16396. return this;
  16397. }
  16398. return emptyList();
  16399. };
  16400. List.prototype.push = function(/*...values*/) {
  16401. var values = arguments;
  16402. var oldSize = this.size;
  16403. return this.withMutations(function(list ) {
  16404. setListBounds(list, 0, oldSize + values.length);
  16405. for (var ii = 0; ii < values.length; ii++) {
  16406. list.set(oldSize + ii, values[ii]);
  16407. }
  16408. });
  16409. };
  16410. List.prototype.pop = function() {
  16411. return setListBounds(this, 0, -1);
  16412. };
  16413. List.prototype.unshift = function(/*...values*/) {
  16414. var values = arguments;
  16415. return this.withMutations(function(list ) {
  16416. setListBounds(list, -values.length);
  16417. for (var ii = 0; ii < values.length; ii++) {
  16418. list.set(ii, values[ii]);
  16419. }
  16420. });
  16421. };
  16422. List.prototype.shift = function() {
  16423. return setListBounds(this, 1);
  16424. };
  16425. // @pragma Composition
  16426. List.prototype.merge = function(/*...iters*/) {
  16427. return mergeIntoListWith(this, undefined, arguments);
  16428. };
  16429. List.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  16430. return mergeIntoListWith(this, merger, iters);
  16431. };
  16432. List.prototype.mergeDeep = function(/*...iters*/) {
  16433. return mergeIntoListWith(this, deepMerger, arguments);
  16434. };
  16435. List.prototype.mergeDeepWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  16436. return mergeIntoListWith(this, deepMergerWith(merger), iters);
  16437. };
  16438. List.prototype.setSize = function(size) {
  16439. return setListBounds(this, 0, size);
  16440. };
  16441. // @pragma Iteration
  16442. List.prototype.slice = function(begin, end) {
  16443. var size = this.size;
  16444. if (wholeSlice(begin, end, size)) {
  16445. return this;
  16446. }
  16447. return setListBounds(
  16448. this,
  16449. resolveBegin(begin, size),
  16450. resolveEnd(end, size)
  16451. );
  16452. };
  16453. List.prototype.__iterator = function(type, reverse) {
  16454. var index = 0;
  16455. var values = iterateList(this, reverse);
  16456. return new Iterator(function() {
  16457. var value = values();
  16458. return value === DONE ?
  16459. iteratorDone() :
  16460. iteratorValue(type, index++, value);
  16461. });
  16462. };
  16463. List.prototype.__iterate = function(fn, reverse) {
  16464. var index = 0;
  16465. var values = iterateList(this, reverse);
  16466. var value;
  16467. while ((value = values()) !== DONE) {
  16468. if (fn(value, index++, this) === false) {
  16469. break;
  16470. }
  16471. }
  16472. return index;
  16473. };
  16474. List.prototype.__ensureOwner = function(ownerID) {
  16475. if (ownerID === this.__ownerID) {
  16476. return this;
  16477. }
  16478. if (!ownerID) {
  16479. this.__ownerID = ownerID;
  16480. return this;
  16481. }
  16482. return makeList(this._origin, this._capacity, this._level, this._root, this._tail, ownerID, this.__hash);
  16483. };
  16484. function isList(maybeList) {
  16485. return !!(maybeList && maybeList[IS_LIST_SENTINEL]);
  16486. }
  16487. List.isList = isList;
  16488. var IS_LIST_SENTINEL = '@@__IMMUTABLE_LIST__@@';
  16489. var ListPrototype = List.prototype;
  16490. ListPrototype[IS_LIST_SENTINEL] = true;
  16491. ListPrototype[DELETE] = ListPrototype.remove;
  16492. ListPrototype.setIn = MapPrototype.setIn;
  16493. ListPrototype.deleteIn =
  16494. ListPrototype.removeIn = MapPrototype.removeIn;
  16495. ListPrototype.update = MapPrototype.update;
  16496. ListPrototype.updateIn = MapPrototype.updateIn;
  16497. ListPrototype.mergeIn = MapPrototype.mergeIn;
  16498. ListPrototype.mergeDeepIn = MapPrototype.mergeDeepIn;
  16499. ListPrototype.withMutations = MapPrototype.withMutations;
  16500. ListPrototype.asMutable = MapPrototype.asMutable;
  16501. ListPrototype.asImmutable = MapPrototype.asImmutable;
  16502. ListPrototype.wasAltered = MapPrototype.wasAltered;
  16503. function VNode(array, ownerID) {
  16504. this.array = array;
  16505. this.ownerID = ownerID;
  16506. }
  16507. // TODO: seems like these methods are very similar
  16508. VNode.prototype.removeBefore = function(ownerID, level, index) {
  16509. if (index === level ? 1 << level : this.array.length === 0) {
  16510. return this;
  16511. }
  16512. var originIndex = (index >>> level) & MASK;
  16513. if (originIndex >= this.array.length) {
  16514. return new VNode([], ownerID);
  16515. }
  16516. var removingFirst = originIndex === 0;
  16517. var newChild;
  16518. if (level > 0) {
  16519. var oldChild = this.array[originIndex];
  16520. newChild = oldChild && oldChild.removeBefore(ownerID, level - SHIFT, index);
  16521. if (newChild === oldChild && removingFirst) {
  16522. return this;
  16523. }
  16524. }
  16525. if (removingFirst && !newChild) {
  16526. return this;
  16527. }
  16528. var editable = editableVNode(this, ownerID);
  16529. if (!removingFirst) {
  16530. for (var ii = 0; ii < originIndex; ii++) {
  16531. editable.array[ii] = undefined;
  16532. }
  16533. }
  16534. if (newChild) {
  16535. editable.array[originIndex] = newChild;
  16536. }
  16537. return editable;
  16538. };
  16539. VNode.prototype.removeAfter = function(ownerID, level, index) {
  16540. if (index === (level ? 1 << level : 0) || this.array.length === 0) {
  16541. return this;
  16542. }
  16543. var sizeIndex = ((index - 1) >>> level) & MASK;
  16544. if (sizeIndex >= this.array.length) {
  16545. return this;
  16546. }
  16547. var newChild;
  16548. if (level > 0) {
  16549. var oldChild = this.array[sizeIndex];
  16550. newChild = oldChild && oldChild.removeAfter(ownerID, level - SHIFT, index);
  16551. if (newChild === oldChild && sizeIndex === this.array.length - 1) {
  16552. return this;
  16553. }
  16554. }
  16555. var editable = editableVNode(this, ownerID);
  16556. editable.array.splice(sizeIndex + 1);
  16557. if (newChild) {
  16558. editable.array[sizeIndex] = newChild;
  16559. }
  16560. return editable;
  16561. };
  16562. var DONE = {};
  16563. function iterateList(list, reverse) {
  16564. var left = list._origin;
  16565. var right = list._capacity;
  16566. var tailPos = getTailOffset(right);
  16567. var tail = list._tail;
  16568. return iterateNodeOrLeaf(list._root, list._level, 0);
  16569. function iterateNodeOrLeaf(node, level, offset) {
  16570. return level === 0 ?
  16571. iterateLeaf(node, offset) :
  16572. iterateNode(node, level, offset);
  16573. }
  16574. function iterateLeaf(node, offset) {
  16575. var array = offset === tailPos ? tail && tail.array : node && node.array;
  16576. var from = offset > left ? 0 : left - offset;
  16577. var to = right - offset;
  16578. if (to > SIZE) {
  16579. to = SIZE;
  16580. }
  16581. return function() {
  16582. if (from === to) {
  16583. return DONE;
  16584. }
  16585. var idx = reverse ? --to : from++;
  16586. return array && array[idx];
  16587. };
  16588. }
  16589. function iterateNode(node, level, offset) {
  16590. var values;
  16591. var array = node && node.array;
  16592. var from = offset > left ? 0 : (left - offset) >> level;
  16593. var to = ((right - offset) >> level) + 1;
  16594. if (to > SIZE) {
  16595. to = SIZE;
  16596. }
  16597. return function() {
  16598. do {
  16599. if (values) {
  16600. var value = values();
  16601. if (value !== DONE) {
  16602. return value;
  16603. }
  16604. values = null;
  16605. }
  16606. if (from === to) {
  16607. return DONE;
  16608. }
  16609. var idx = reverse ? --to : from++;
  16610. values = iterateNodeOrLeaf(
  16611. array && array[idx], level - SHIFT, offset + (idx << level)
  16612. );
  16613. } while (true);
  16614. };
  16615. }
  16616. }
  16617. function makeList(origin, capacity, level, root, tail, ownerID, hash) {
  16618. var list = Object.create(ListPrototype);
  16619. list.size = capacity - origin;
  16620. list._origin = origin;
  16621. list._capacity = capacity;
  16622. list._level = level;
  16623. list._root = root;
  16624. list._tail = tail;
  16625. list.__ownerID = ownerID;
  16626. list.__hash = hash;
  16627. list.__altered = false;
  16628. return list;
  16629. }
  16630. var EMPTY_LIST;
  16631. function emptyList() {
  16632. return EMPTY_LIST || (EMPTY_LIST = makeList(0, 0, SHIFT));
  16633. }
  16634. function updateList(list, index, value) {
  16635. index = wrapIndex(list, index);
  16636. if (index !== index) {
  16637. return list;
  16638. }
  16639. if (index >= list.size || index < 0) {
  16640. return list.withMutations(function(list ) {
  16641. index < 0 ?
  16642. setListBounds(list, index).set(0, value) :
  16643. setListBounds(list, 0, index + 1).set(index, value);
  16644. });
  16645. }
  16646. index += list._origin;
  16647. var newTail = list._tail;
  16648. var newRoot = list._root;
  16649. var didAlter = MakeRef(DID_ALTER);
  16650. if (index >= getTailOffset(list._capacity)) {
  16651. newTail = updateVNode(newTail, list.__ownerID, 0, index, value, didAlter);
  16652. } else {
  16653. newRoot = updateVNode(newRoot, list.__ownerID, list._level, index, value, didAlter);
  16654. }
  16655. if (!didAlter.value) {
  16656. return list;
  16657. }
  16658. if (list.__ownerID) {
  16659. list._root = newRoot;
  16660. list._tail = newTail;
  16661. list.__hash = undefined;
  16662. list.__altered = true;
  16663. return list;
  16664. }
  16665. return makeList(list._origin, list._capacity, list._level, newRoot, newTail);
  16666. }
  16667. function updateVNode(node, ownerID, level, index, value, didAlter) {
  16668. var idx = (index >>> level) & MASK;
  16669. var nodeHas = node && idx < node.array.length;
  16670. if (!nodeHas && value === undefined) {
  16671. return node;
  16672. }
  16673. var newNode;
  16674. if (level > 0) {
  16675. var lowerNode = node && node.array[idx];
  16676. var newLowerNode = updateVNode(lowerNode, ownerID, level - SHIFT, index, value, didAlter);
  16677. if (newLowerNode === lowerNode) {
  16678. return node;
  16679. }
  16680. newNode = editableVNode(node, ownerID);
  16681. newNode.array[idx] = newLowerNode;
  16682. return newNode;
  16683. }
  16684. if (nodeHas && node.array[idx] === value) {
  16685. return node;
  16686. }
  16687. SetRef(didAlter);
  16688. newNode = editableVNode(node, ownerID);
  16689. if (value === undefined && idx === newNode.array.length - 1) {
  16690. newNode.array.pop();
  16691. } else {
  16692. newNode.array[idx] = value;
  16693. }
  16694. return newNode;
  16695. }
  16696. function editableVNode(node, ownerID) {
  16697. if (ownerID && node && ownerID === node.ownerID) {
  16698. return node;
  16699. }
  16700. return new VNode(node ? node.array.slice() : [], ownerID);
  16701. }
  16702. function listNodeFor(list, rawIndex) {
  16703. if (rawIndex >= getTailOffset(list._capacity)) {
  16704. return list._tail;
  16705. }
  16706. if (rawIndex < 1 << (list._level + SHIFT)) {
  16707. var node = list._root;
  16708. var level = list._level;
  16709. while (node && level > 0) {
  16710. node = node.array[(rawIndex >>> level) & MASK];
  16711. level -= SHIFT;
  16712. }
  16713. return node;
  16714. }
  16715. }
  16716. function setListBounds(list, begin, end) {
  16717. // Sanitize begin & end using this shorthand for ToInt32(argument)
  16718. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  16719. if (begin !== undefined) {
  16720. begin = begin | 0;
  16721. }
  16722. if (end !== undefined) {
  16723. end = end | 0;
  16724. }
  16725. var owner = list.__ownerID || new OwnerID();
  16726. var oldOrigin = list._origin;
  16727. var oldCapacity = list._capacity;
  16728. var newOrigin = oldOrigin + begin;
  16729. var newCapacity = end === undefined ? oldCapacity : end < 0 ? oldCapacity + end : oldOrigin + end;
  16730. if (newOrigin === oldOrigin && newCapacity === oldCapacity) {
  16731. return list;
  16732. }
  16733. // If it's going to end after it starts, it's empty.
  16734. if (newOrigin >= newCapacity) {
  16735. return list.clear();
  16736. }
  16737. var newLevel = list._level;
  16738. var newRoot = list._root;
  16739. // New origin might need creating a higher root.
  16740. var offsetShift = 0;
  16741. while (newOrigin + offsetShift < 0) {
  16742. newRoot = new VNode(newRoot && newRoot.array.length ? [undefined, newRoot] : [], owner);
  16743. newLevel += SHIFT;
  16744. offsetShift += 1 << newLevel;
  16745. }
  16746. if (offsetShift) {
  16747. newOrigin += offsetShift;
  16748. oldOrigin += offsetShift;
  16749. newCapacity += offsetShift;
  16750. oldCapacity += offsetShift;
  16751. }
  16752. var oldTailOffset = getTailOffset(oldCapacity);
  16753. var newTailOffset = getTailOffset(newCapacity);
  16754. // New size might need creating a higher root.
  16755. while (newTailOffset >= 1 << (newLevel + SHIFT)) {
  16756. newRoot = new VNode(newRoot && newRoot.array.length ? [newRoot] : [], owner);
  16757. newLevel += SHIFT;
  16758. }
  16759. // Locate or create the new tail.
  16760. var oldTail = list._tail;
  16761. var newTail = newTailOffset < oldTailOffset ?
  16762. listNodeFor(list, newCapacity - 1) :
  16763. newTailOffset > oldTailOffset ? new VNode([], owner) : oldTail;
  16764. // Merge Tail into tree.
  16765. if (oldTail && newTailOffset > oldTailOffset && newOrigin < oldCapacity && oldTail.array.length) {
  16766. newRoot = editableVNode(newRoot, owner);
  16767. var node = newRoot;
  16768. for (var level = newLevel; level > SHIFT; level -= SHIFT) {
  16769. var idx = (oldTailOffset >>> level) & MASK;
  16770. node = node.array[idx] = editableVNode(node.array[idx], owner);
  16771. }
  16772. node.array[(oldTailOffset >>> SHIFT) & MASK] = oldTail;
  16773. }
  16774. // If the size has been reduced, there's a chance the tail needs to be trimmed.
  16775. if (newCapacity < oldCapacity) {
  16776. newTail = newTail && newTail.removeAfter(owner, 0, newCapacity);
  16777. }
  16778. // If the new origin is within the tail, then we do not need a root.
  16779. if (newOrigin >= newTailOffset) {
  16780. newOrigin -= newTailOffset;
  16781. newCapacity -= newTailOffset;
  16782. newLevel = SHIFT;
  16783. newRoot = null;
  16784. newTail = newTail && newTail.removeBefore(owner, 0, newOrigin);
  16785. // Otherwise, if the root has been trimmed, garbage collect.
  16786. } else if (newOrigin > oldOrigin || newTailOffset < oldTailOffset) {
  16787. offsetShift = 0;
  16788. // Identify the new top root node of the subtree of the old root.
  16789. while (newRoot) {
  16790. var beginIndex = (newOrigin >>> newLevel) & MASK;
  16791. if (beginIndex !== (newTailOffset >>> newLevel) & MASK) {
  16792. break;
  16793. }
  16794. if (beginIndex) {
  16795. offsetShift += (1 << newLevel) * beginIndex;
  16796. }
  16797. newLevel -= SHIFT;
  16798. newRoot = newRoot.array[beginIndex];
  16799. }
  16800. // Trim the new sides of the new root.
  16801. if (newRoot && newOrigin > oldOrigin) {
  16802. newRoot = newRoot.removeBefore(owner, newLevel, newOrigin - offsetShift);
  16803. }
  16804. if (newRoot && newTailOffset < oldTailOffset) {
  16805. newRoot = newRoot.removeAfter(owner, newLevel, newTailOffset - offsetShift);
  16806. }
  16807. if (offsetShift) {
  16808. newOrigin -= offsetShift;
  16809. newCapacity -= offsetShift;
  16810. }
  16811. }
  16812. if (list.__ownerID) {
  16813. list.size = newCapacity - newOrigin;
  16814. list._origin = newOrigin;
  16815. list._capacity = newCapacity;
  16816. list._level = newLevel;
  16817. list._root = newRoot;
  16818. list._tail = newTail;
  16819. list.__hash = undefined;
  16820. list.__altered = true;
  16821. return list;
  16822. }
  16823. return makeList(newOrigin, newCapacity, newLevel, newRoot, newTail);
  16824. }
  16825. function mergeIntoListWith(list, merger, iterables) {
  16826. var iters = [];
  16827. var maxSize = 0;
  16828. for (var ii = 0; ii < iterables.length; ii++) {
  16829. var value = iterables[ii];
  16830. var iter = IndexedIterable(value);
  16831. if (iter.size > maxSize) {
  16832. maxSize = iter.size;
  16833. }
  16834. if (!isIterable(value)) {
  16835. iter = iter.map(function(v ) {return fromJS(v)});
  16836. }
  16837. iters.push(iter);
  16838. }
  16839. if (maxSize > list.size) {
  16840. list = list.setSize(maxSize);
  16841. }
  16842. return mergeIntoCollectionWith(list, merger, iters);
  16843. }
  16844. function getTailOffset(size) {
  16845. return size < SIZE ? 0 : (((size - 1) >>> SHIFT) << SHIFT);
  16846. }
  16847. createClass(OrderedMap, Map);
  16848. // @pragma Construction
  16849. function OrderedMap(value) {
  16850. return value === null || value === undefined ? emptyOrderedMap() :
  16851. isOrderedMap(value) ? value :
  16852. emptyOrderedMap().withMutations(function(map ) {
  16853. var iter = KeyedIterable(value);
  16854. assertNotInfinite(iter.size);
  16855. iter.forEach(function(v, k) {return map.set(k, v)});
  16856. });
  16857. }
  16858. OrderedMap.of = function(/*...values*/) {
  16859. return this(arguments);
  16860. };
  16861. OrderedMap.prototype.toString = function() {
  16862. return this.__toString('OrderedMap {', '}');
  16863. };
  16864. // @pragma Access
  16865. OrderedMap.prototype.get = function(k, notSetValue) {
  16866. var index = this._map.get(k);
  16867. return index !== undefined ? this._list.get(index)[1] : notSetValue;
  16868. };
  16869. // @pragma Modification
  16870. OrderedMap.prototype.clear = function() {
  16871. if (this.size === 0) {
  16872. return this;
  16873. }
  16874. if (this.__ownerID) {
  16875. this.size = 0;
  16876. this._map.clear();
  16877. this._list.clear();
  16878. return this;
  16879. }
  16880. return emptyOrderedMap();
  16881. };
  16882. OrderedMap.prototype.set = function(k, v) {
  16883. return updateOrderedMap(this, k, v);
  16884. };
  16885. OrderedMap.prototype.remove = function(k) {
  16886. return updateOrderedMap(this, k, NOT_SET);
  16887. };
  16888. OrderedMap.prototype.wasAltered = function() {
  16889. return this._map.wasAltered() || this._list.wasAltered();
  16890. };
  16891. OrderedMap.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  16892. return this._list.__iterate(
  16893. function(entry ) {return entry && fn(entry[1], entry[0], this$0)},
  16894. reverse
  16895. );
  16896. };
  16897. OrderedMap.prototype.__iterator = function(type, reverse) {
  16898. return this._list.fromEntrySeq().__iterator(type, reverse);
  16899. };
  16900. OrderedMap.prototype.__ensureOwner = function(ownerID) {
  16901. if (ownerID === this.__ownerID) {
  16902. return this;
  16903. }
  16904. var newMap = this._map.__ensureOwner(ownerID);
  16905. var newList = this._list.__ensureOwner(ownerID);
  16906. if (!ownerID) {
  16907. this.__ownerID = ownerID;
  16908. this._map = newMap;
  16909. this._list = newList;
  16910. return this;
  16911. }
  16912. return makeOrderedMap(newMap, newList, ownerID, this.__hash);
  16913. };
  16914. function isOrderedMap(maybeOrderedMap) {
  16915. return isMap(maybeOrderedMap) && isOrdered(maybeOrderedMap);
  16916. }
  16917. OrderedMap.isOrderedMap = isOrderedMap;
  16918. OrderedMap.prototype[IS_ORDERED_SENTINEL] = true;
  16919. OrderedMap.prototype[DELETE] = OrderedMap.prototype.remove;
  16920. function makeOrderedMap(map, list, ownerID, hash) {
  16921. var omap = Object.create(OrderedMap.prototype);
  16922. omap.size = map ? map.size : 0;
  16923. omap._map = map;
  16924. omap._list = list;
  16925. omap.__ownerID = ownerID;
  16926. omap.__hash = hash;
  16927. return omap;
  16928. }
  16929. var EMPTY_ORDERED_MAP;
  16930. function emptyOrderedMap() {
  16931. return EMPTY_ORDERED_MAP || (EMPTY_ORDERED_MAP = makeOrderedMap(emptyMap(), emptyList()));
  16932. }
  16933. function updateOrderedMap(omap, k, v) {
  16934. var map = omap._map;
  16935. var list = omap._list;
  16936. var i = map.get(k);
  16937. var has = i !== undefined;
  16938. var newMap;
  16939. var newList;
  16940. if (v === NOT_SET) { // removed
  16941. if (!has) {
  16942. return omap;
  16943. }
  16944. if (list.size >= SIZE && list.size >= map.size * 2) {
  16945. newList = list.filter(function(entry, idx) {return entry !== undefined && i !== idx});
  16946. newMap = newList.toKeyedSeq().map(function(entry ) {return entry[0]}).flip().toMap();
  16947. if (omap.__ownerID) {
  16948. newMap.__ownerID = newList.__ownerID = omap.__ownerID;
  16949. }
  16950. } else {
  16951. newMap = map.remove(k);
  16952. newList = i === list.size - 1 ? list.pop() : list.set(i, undefined);
  16953. }
  16954. } else {
  16955. if (has) {
  16956. if (v === list.get(i)[1]) {
  16957. return omap;
  16958. }
  16959. newMap = map;
  16960. newList = list.set(i, [k, v]);
  16961. } else {
  16962. newMap = map.set(k, list.size);
  16963. newList = list.set(list.size, [k, v]);
  16964. }
  16965. }
  16966. if (omap.__ownerID) {
  16967. omap.size = newMap.size;
  16968. omap._map = newMap;
  16969. omap._list = newList;
  16970. omap.__hash = undefined;
  16971. return omap;
  16972. }
  16973. return makeOrderedMap(newMap, newList);
  16974. }
  16975. createClass(ToKeyedSequence, KeyedSeq);
  16976. function ToKeyedSequence(indexed, useKeys) {
  16977. this._iter = indexed;
  16978. this._useKeys = useKeys;
  16979. this.size = indexed.size;
  16980. }
  16981. ToKeyedSequence.prototype.get = function(key, notSetValue) {
  16982. return this._iter.get(key, notSetValue);
  16983. };
  16984. ToKeyedSequence.prototype.has = function(key) {
  16985. return this._iter.has(key);
  16986. };
  16987. ToKeyedSequence.prototype.valueSeq = function() {
  16988. return this._iter.valueSeq();
  16989. };
  16990. ToKeyedSequence.prototype.reverse = function() {var this$0 = this;
  16991. var reversedSequence = reverseFactory(this, true);
  16992. if (!this._useKeys) {
  16993. reversedSequence.valueSeq = function() {return this$0._iter.toSeq().reverse()};
  16994. }
  16995. return reversedSequence;
  16996. };
  16997. ToKeyedSequence.prototype.map = function(mapper, context) {var this$0 = this;
  16998. var mappedSequence = mapFactory(this, mapper, context);
  16999. if (!this._useKeys) {
  17000. mappedSequence.valueSeq = function() {return this$0._iter.toSeq().map(mapper, context)};
  17001. }
  17002. return mappedSequence;
  17003. };
  17004. ToKeyedSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  17005. var ii;
  17006. return this._iter.__iterate(
  17007. this._useKeys ?
  17008. function(v, k) {return fn(v, k, this$0)} :
  17009. ((ii = reverse ? resolveSize(this) : 0),
  17010. function(v ) {return fn(v, reverse ? --ii : ii++, this$0)}),
  17011. reverse
  17012. );
  17013. };
  17014. ToKeyedSequence.prototype.__iterator = function(type, reverse) {
  17015. if (this._useKeys) {
  17016. return this._iter.__iterator(type, reverse);
  17017. }
  17018. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  17019. var ii = reverse ? resolveSize(this) : 0;
  17020. return new Iterator(function() {
  17021. var step = iterator.next();
  17022. return step.done ? step :
  17023. iteratorValue(type, reverse ? --ii : ii++, step.value, step);
  17024. });
  17025. };
  17026. ToKeyedSequence.prototype[IS_ORDERED_SENTINEL] = true;
  17027. createClass(ToIndexedSequence, IndexedSeq);
  17028. function ToIndexedSequence(iter) {
  17029. this._iter = iter;
  17030. this.size = iter.size;
  17031. }
  17032. ToIndexedSequence.prototype.includes = function(value) {
  17033. return this._iter.includes(value);
  17034. };
  17035. ToIndexedSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  17036. var iterations = 0;
  17037. return this._iter.__iterate(function(v ) {return fn(v, iterations++, this$0)}, reverse);
  17038. };
  17039. ToIndexedSequence.prototype.__iterator = function(type, reverse) {
  17040. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  17041. var iterations = 0;
  17042. return new Iterator(function() {
  17043. var step = iterator.next();
  17044. return step.done ? step :
  17045. iteratorValue(type, iterations++, step.value, step)
  17046. });
  17047. };
  17048. createClass(ToSetSequence, SetSeq);
  17049. function ToSetSequence(iter) {
  17050. this._iter = iter;
  17051. this.size = iter.size;
  17052. }
  17053. ToSetSequence.prototype.has = function(key) {
  17054. return this._iter.includes(key);
  17055. };
  17056. ToSetSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  17057. return this._iter.__iterate(function(v ) {return fn(v, v, this$0)}, reverse);
  17058. };
  17059. ToSetSequence.prototype.__iterator = function(type, reverse) {
  17060. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  17061. return new Iterator(function() {
  17062. var step = iterator.next();
  17063. return step.done ? step :
  17064. iteratorValue(type, step.value, step.value, step);
  17065. });
  17066. };
  17067. createClass(FromEntriesSequence, KeyedSeq);
  17068. function FromEntriesSequence(entries) {
  17069. this._iter = entries;
  17070. this.size = entries.size;
  17071. }
  17072. FromEntriesSequence.prototype.entrySeq = function() {
  17073. return this._iter.toSeq();
  17074. };
  17075. FromEntriesSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  17076. return this._iter.__iterate(function(entry ) {
  17077. // Check if entry exists first so array access doesn't throw for holes
  17078. // in the parent iteration.
  17079. if (entry) {
  17080. validateEntry(entry);
  17081. var indexedIterable = isIterable(entry);
  17082. return fn(
  17083. indexedIterable ? entry.get(1) : entry[1],
  17084. indexedIterable ? entry.get(0) : entry[0],
  17085. this$0
  17086. );
  17087. }
  17088. }, reverse);
  17089. };
  17090. FromEntriesSequence.prototype.__iterator = function(type, reverse) {
  17091. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  17092. return new Iterator(function() {
  17093. while (true) {
  17094. var step = iterator.next();
  17095. if (step.done) {
  17096. return step;
  17097. }
  17098. var entry = step.value;
  17099. // Check if entry exists first so array access doesn't throw for holes
  17100. // in the parent iteration.
  17101. if (entry) {
  17102. validateEntry(entry);
  17103. var indexedIterable = isIterable(entry);
  17104. return iteratorValue(
  17105. type,
  17106. indexedIterable ? entry.get(0) : entry[0],
  17107. indexedIterable ? entry.get(1) : entry[1],
  17108. step
  17109. );
  17110. }
  17111. }
  17112. });
  17113. };
  17114. ToIndexedSequence.prototype.cacheResult =
  17115. ToKeyedSequence.prototype.cacheResult =
  17116. ToSetSequence.prototype.cacheResult =
  17117. FromEntriesSequence.prototype.cacheResult =
  17118. cacheResultThrough;
  17119. function flipFactory(iterable) {
  17120. var flipSequence = makeSequence(iterable);
  17121. flipSequence._iter = iterable;
  17122. flipSequence.size = iterable.size;
  17123. flipSequence.flip = function() {return iterable};
  17124. flipSequence.reverse = function () {
  17125. var reversedSequence = iterable.reverse.apply(this); // super.reverse()
  17126. reversedSequence.flip = function() {return iterable.reverse()};
  17127. return reversedSequence;
  17128. };
  17129. flipSequence.has = function(key ) {return iterable.includes(key)};
  17130. flipSequence.includes = function(key ) {return iterable.has(key)};
  17131. flipSequence.cacheResult = cacheResultThrough;
  17132. flipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  17133. return iterable.__iterate(function(v, k) {return fn(k, v, this$0) !== false}, reverse);
  17134. };
  17135. flipSequence.__iteratorUncached = function(type, reverse) {
  17136. if (type === ITERATE_ENTRIES) {
  17137. var iterator = iterable.__iterator(type, reverse);
  17138. return new Iterator(function() {
  17139. var step = iterator.next();
  17140. if (!step.done) {
  17141. var k = step.value[0];
  17142. step.value[0] = step.value[1];
  17143. step.value[1] = k;
  17144. }
  17145. return step;
  17146. });
  17147. }
  17148. return iterable.__iterator(
  17149. type === ITERATE_VALUES ? ITERATE_KEYS : ITERATE_VALUES,
  17150. reverse
  17151. );
  17152. };
  17153. return flipSequence;
  17154. }
  17155. function mapFactory(iterable, mapper, context) {
  17156. var mappedSequence = makeSequence(iterable);
  17157. mappedSequence.size = iterable.size;
  17158. mappedSequence.has = function(key ) {return iterable.has(key)};
  17159. mappedSequence.get = function(key, notSetValue) {
  17160. var v = iterable.get(key, NOT_SET);
  17161. return v === NOT_SET ?
  17162. notSetValue :
  17163. mapper.call(context, v, key, iterable);
  17164. };
  17165. mappedSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  17166. return iterable.__iterate(
  17167. function(v, k, c) {return fn(mapper.call(context, v, k, c), k, this$0) !== false},
  17168. reverse
  17169. );
  17170. };
  17171. mappedSequence.__iteratorUncached = function (type, reverse) {
  17172. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  17173. return new Iterator(function() {
  17174. var step = iterator.next();
  17175. if (step.done) {
  17176. return step;
  17177. }
  17178. var entry = step.value;
  17179. var key = entry[0];
  17180. return iteratorValue(
  17181. type,
  17182. key,
  17183. mapper.call(context, entry[1], key, iterable),
  17184. step
  17185. );
  17186. });
  17187. };
  17188. return mappedSequence;
  17189. }
  17190. function reverseFactory(iterable, useKeys) {
  17191. var reversedSequence = makeSequence(iterable);
  17192. reversedSequence._iter = iterable;
  17193. reversedSequence.size = iterable.size;
  17194. reversedSequence.reverse = function() {return iterable};
  17195. if (iterable.flip) {
  17196. reversedSequence.flip = function () {
  17197. var flipSequence = flipFactory(iterable);
  17198. flipSequence.reverse = function() {return iterable.flip()};
  17199. return flipSequence;
  17200. };
  17201. }
  17202. reversedSequence.get = function(key, notSetValue)
  17203. {return iterable.get(useKeys ? key : -1 - key, notSetValue)};
  17204. reversedSequence.has = function(key )
  17205. {return iterable.has(useKeys ? key : -1 - key)};
  17206. reversedSequence.includes = function(value ) {return iterable.includes(value)};
  17207. reversedSequence.cacheResult = cacheResultThrough;
  17208. reversedSequence.__iterate = function (fn, reverse) {var this$0 = this;
  17209. return iterable.__iterate(function(v, k) {return fn(v, k, this$0)}, !reverse);
  17210. };
  17211. reversedSequence.__iterator =
  17212. function(type, reverse) {return iterable.__iterator(type, !reverse)};
  17213. return reversedSequence;
  17214. }
  17215. function filterFactory(iterable, predicate, context, useKeys) {
  17216. var filterSequence = makeSequence(iterable);
  17217. if (useKeys) {
  17218. filterSequence.has = function(key ) {
  17219. var v = iterable.get(key, NOT_SET);
  17220. return v !== NOT_SET && !!predicate.call(context, v, key, iterable);
  17221. };
  17222. filterSequence.get = function(key, notSetValue) {
  17223. var v = iterable.get(key, NOT_SET);
  17224. return v !== NOT_SET && predicate.call(context, v, key, iterable) ?
  17225. v : notSetValue;
  17226. };
  17227. }
  17228. filterSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  17229. var iterations = 0;
  17230. iterable.__iterate(function(v, k, c) {
  17231. if (predicate.call(context, v, k, c)) {
  17232. iterations++;
  17233. return fn(v, useKeys ? k : iterations - 1, this$0);
  17234. }
  17235. }, reverse);
  17236. return iterations;
  17237. };
  17238. filterSequence.__iteratorUncached = function (type, reverse) {
  17239. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  17240. var iterations = 0;
  17241. return new Iterator(function() {
  17242. while (true) {
  17243. var step = iterator.next();
  17244. if (step.done) {
  17245. return step;
  17246. }
  17247. var entry = step.value;
  17248. var key = entry[0];
  17249. var value = entry[1];
  17250. if (predicate.call(context, value, key, iterable)) {
  17251. return iteratorValue(type, useKeys ? key : iterations++, value, step);
  17252. }
  17253. }
  17254. });
  17255. };
  17256. return filterSequence;
  17257. }
  17258. function countByFactory(iterable, grouper, context) {
  17259. var groups = Map().asMutable();
  17260. iterable.__iterate(function(v, k) {
  17261. groups.update(
  17262. grouper.call(context, v, k, iterable),
  17263. 0,
  17264. function(a ) {return a + 1}
  17265. );
  17266. });
  17267. return groups.asImmutable();
  17268. }
  17269. function groupByFactory(iterable, grouper, context) {
  17270. var isKeyedIter = isKeyed(iterable);
  17271. var groups = (isOrdered(iterable) ? OrderedMap() : Map()).asMutable();
  17272. iterable.__iterate(function(v, k) {
  17273. groups.update(
  17274. grouper.call(context, v, k, iterable),
  17275. function(a ) {return (a = a || [], a.push(isKeyedIter ? [k, v] : v), a)}
  17276. );
  17277. });
  17278. var coerce = iterableClass(iterable);
  17279. return groups.map(function(arr ) {return reify(iterable, coerce(arr))});
  17280. }
  17281. function sliceFactory(iterable, begin, end, useKeys) {
  17282. var originalSize = iterable.size;
  17283. // Sanitize begin & end using this shorthand for ToInt32(argument)
  17284. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  17285. if (begin !== undefined) {
  17286. begin = begin | 0;
  17287. }
  17288. if (end !== undefined) {
  17289. end = end | 0;
  17290. }
  17291. if (wholeSlice(begin, end, originalSize)) {
  17292. return iterable;
  17293. }
  17294. var resolvedBegin = resolveBegin(begin, originalSize);
  17295. var resolvedEnd = resolveEnd(end, originalSize);
  17296. // begin or end will be NaN if they were provided as negative numbers and
  17297. // this iterable's size is unknown. In that case, cache first so there is
  17298. // a known size and these do not resolve to NaN.
  17299. if (resolvedBegin !== resolvedBegin || resolvedEnd !== resolvedEnd) {
  17300. return sliceFactory(iterable.toSeq().cacheResult(), begin, end, useKeys);
  17301. }
  17302. // Note: resolvedEnd is undefined when the original sequence's length is
  17303. // unknown and this slice did not supply an end and should contain all
  17304. // elements after resolvedBegin.
  17305. // In that case, resolvedSize will be NaN and sliceSize will remain undefined.
  17306. var resolvedSize = resolvedEnd - resolvedBegin;
  17307. var sliceSize;
  17308. if (resolvedSize === resolvedSize) {
  17309. sliceSize = resolvedSize < 0 ? 0 : resolvedSize;
  17310. }
  17311. var sliceSeq = makeSequence(iterable);
  17312. // If iterable.size is undefined, the size of the realized sliceSeq is
  17313. // unknown at this point unless the number of items to slice is 0
  17314. sliceSeq.size = sliceSize === 0 ? sliceSize : iterable.size && sliceSize || undefined;
  17315. if (!useKeys && isSeq(iterable) && sliceSize >= 0) {
  17316. sliceSeq.get = function (index, notSetValue) {
  17317. index = wrapIndex(this, index);
  17318. return index >= 0 && index < sliceSize ?
  17319. iterable.get(index + resolvedBegin, notSetValue) :
  17320. notSetValue;
  17321. };
  17322. }
  17323. sliceSeq.__iterateUncached = function(fn, reverse) {var this$0 = this;
  17324. if (sliceSize === 0) {
  17325. return 0;
  17326. }
  17327. if (reverse) {
  17328. return this.cacheResult().__iterate(fn, reverse);
  17329. }
  17330. var skipped = 0;
  17331. var isSkipping = true;
  17332. var iterations = 0;
  17333. iterable.__iterate(function(v, k) {
  17334. if (!(isSkipping && (isSkipping = skipped++ < resolvedBegin))) {
  17335. iterations++;
  17336. return fn(v, useKeys ? k : iterations - 1, this$0) !== false &&
  17337. iterations !== sliceSize;
  17338. }
  17339. });
  17340. return iterations;
  17341. };
  17342. sliceSeq.__iteratorUncached = function(type, reverse) {
  17343. if (sliceSize !== 0 && reverse) {
  17344. return this.cacheResult().__iterator(type, reverse);
  17345. }
  17346. // Don't bother instantiating parent iterator if taking 0.
  17347. var iterator = sliceSize !== 0 && iterable.__iterator(type, reverse);
  17348. var skipped = 0;
  17349. var iterations = 0;
  17350. return new Iterator(function() {
  17351. while (skipped++ < resolvedBegin) {
  17352. iterator.next();
  17353. }
  17354. if (++iterations > sliceSize) {
  17355. return iteratorDone();
  17356. }
  17357. var step = iterator.next();
  17358. if (useKeys || type === ITERATE_VALUES) {
  17359. return step;
  17360. } else if (type === ITERATE_KEYS) {
  17361. return iteratorValue(type, iterations - 1, undefined, step);
  17362. } else {
  17363. return iteratorValue(type, iterations - 1, step.value[1], step);
  17364. }
  17365. });
  17366. };
  17367. return sliceSeq;
  17368. }
  17369. function takeWhileFactory(iterable, predicate, context) {
  17370. var takeSequence = makeSequence(iterable);
  17371. takeSequence.__iterateUncached = function(fn, reverse) {var this$0 = this;
  17372. if (reverse) {
  17373. return this.cacheResult().__iterate(fn, reverse);
  17374. }
  17375. var iterations = 0;
  17376. iterable.__iterate(function(v, k, c)
  17377. {return predicate.call(context, v, k, c) && ++iterations && fn(v, k, this$0)}
  17378. );
  17379. return iterations;
  17380. };
  17381. takeSequence.__iteratorUncached = function(type, reverse) {var this$0 = this;
  17382. if (reverse) {
  17383. return this.cacheResult().__iterator(type, reverse);
  17384. }
  17385. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  17386. var iterating = true;
  17387. return new Iterator(function() {
  17388. if (!iterating) {
  17389. return iteratorDone();
  17390. }
  17391. var step = iterator.next();
  17392. if (step.done) {
  17393. return step;
  17394. }
  17395. var entry = step.value;
  17396. var k = entry[0];
  17397. var v = entry[1];
  17398. if (!predicate.call(context, v, k, this$0)) {
  17399. iterating = false;
  17400. return iteratorDone();
  17401. }
  17402. return type === ITERATE_ENTRIES ? step :
  17403. iteratorValue(type, k, v, step);
  17404. });
  17405. };
  17406. return takeSequence;
  17407. }
  17408. function skipWhileFactory(iterable, predicate, context, useKeys) {
  17409. var skipSequence = makeSequence(iterable);
  17410. skipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  17411. if (reverse) {
  17412. return this.cacheResult().__iterate(fn, reverse);
  17413. }
  17414. var isSkipping = true;
  17415. var iterations = 0;
  17416. iterable.__iterate(function(v, k, c) {
  17417. if (!(isSkipping && (isSkipping = predicate.call(context, v, k, c)))) {
  17418. iterations++;
  17419. return fn(v, useKeys ? k : iterations - 1, this$0);
  17420. }
  17421. });
  17422. return iterations;
  17423. };
  17424. skipSequence.__iteratorUncached = function(type, reverse) {var this$0 = this;
  17425. if (reverse) {
  17426. return this.cacheResult().__iterator(type, reverse);
  17427. }
  17428. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  17429. var skipping = true;
  17430. var iterations = 0;
  17431. return new Iterator(function() {
  17432. var step, k, v;
  17433. do {
  17434. step = iterator.next();
  17435. if (step.done) {
  17436. if (useKeys || type === ITERATE_VALUES) {
  17437. return step;
  17438. } else if (type === ITERATE_KEYS) {
  17439. return iteratorValue(type, iterations++, undefined, step);
  17440. } else {
  17441. return iteratorValue(type, iterations++, step.value[1], step);
  17442. }
  17443. }
  17444. var entry = step.value;
  17445. k = entry[0];
  17446. v = entry[1];
  17447. skipping && (skipping = predicate.call(context, v, k, this$0));
  17448. } while (skipping);
  17449. return type === ITERATE_ENTRIES ? step :
  17450. iteratorValue(type, k, v, step);
  17451. });
  17452. };
  17453. return skipSequence;
  17454. }
  17455. function concatFactory(iterable, values) {
  17456. var isKeyedIterable = isKeyed(iterable);
  17457. var iters = [iterable].concat(values).map(function(v ) {
  17458. if (!isIterable(v)) {
  17459. v = isKeyedIterable ?
  17460. keyedSeqFromValue(v) :
  17461. indexedSeqFromValue(Array.isArray(v) ? v : [v]);
  17462. } else if (isKeyedIterable) {
  17463. v = KeyedIterable(v);
  17464. }
  17465. return v;
  17466. }).filter(function(v ) {return v.size !== 0});
  17467. if (iters.length === 0) {
  17468. return iterable;
  17469. }
  17470. if (iters.length === 1) {
  17471. var singleton = iters[0];
  17472. if (singleton === iterable ||
  17473. isKeyedIterable && isKeyed(singleton) ||
  17474. isIndexed(iterable) && isIndexed(singleton)) {
  17475. return singleton;
  17476. }
  17477. }
  17478. var concatSeq = new ArraySeq(iters);
  17479. if (isKeyedIterable) {
  17480. concatSeq = concatSeq.toKeyedSeq();
  17481. } else if (!isIndexed(iterable)) {
  17482. concatSeq = concatSeq.toSetSeq();
  17483. }
  17484. concatSeq = concatSeq.flatten(true);
  17485. concatSeq.size = iters.reduce(
  17486. function(sum, seq) {
  17487. if (sum !== undefined) {
  17488. var size = seq.size;
  17489. if (size !== undefined) {
  17490. return sum + size;
  17491. }
  17492. }
  17493. },
  17494. 0
  17495. );
  17496. return concatSeq;
  17497. }
  17498. function flattenFactory(iterable, depth, useKeys) {
  17499. var flatSequence = makeSequence(iterable);
  17500. flatSequence.__iterateUncached = function(fn, reverse) {
  17501. var iterations = 0;
  17502. var stopped = false;
  17503. function flatDeep(iter, currentDepth) {var this$0 = this;
  17504. iter.__iterate(function(v, k) {
  17505. if ((!depth || currentDepth < depth) && isIterable(v)) {
  17506. flatDeep(v, currentDepth + 1);
  17507. } else if (fn(v, useKeys ? k : iterations++, this$0) === false) {
  17508. stopped = true;
  17509. }
  17510. return !stopped;
  17511. }, reverse);
  17512. }
  17513. flatDeep(iterable, 0);
  17514. return iterations;
  17515. };
  17516. flatSequence.__iteratorUncached = function(type, reverse) {
  17517. var iterator = iterable.__iterator(type, reverse);
  17518. var stack = [];
  17519. var iterations = 0;
  17520. return new Iterator(function() {
  17521. while (iterator) {
  17522. var step = iterator.next();
  17523. if (step.done !== false) {
  17524. iterator = stack.pop();
  17525. continue;
  17526. }
  17527. var v = step.value;
  17528. if (type === ITERATE_ENTRIES) {
  17529. v = v[1];
  17530. }
  17531. if ((!depth || stack.length < depth) && isIterable(v)) {
  17532. stack.push(iterator);
  17533. iterator = v.__iterator(type, reverse);
  17534. } else {
  17535. return useKeys ? step : iteratorValue(type, iterations++, v, step);
  17536. }
  17537. }
  17538. return iteratorDone();
  17539. });
  17540. };
  17541. return flatSequence;
  17542. }
  17543. function flatMapFactory(iterable, mapper, context) {
  17544. var coerce = iterableClass(iterable);
  17545. return iterable.toSeq().map(
  17546. function(v, k) {return coerce(mapper.call(context, v, k, iterable))}
  17547. ).flatten(true);
  17548. }
  17549. function interposeFactory(iterable, separator) {
  17550. var interposedSequence = makeSequence(iterable);
  17551. interposedSequence.size = iterable.size && iterable.size * 2 -1;
  17552. interposedSequence.__iterateUncached = function(fn, reverse) {var this$0 = this;
  17553. var iterations = 0;
  17554. iterable.__iterate(function(v, k)
  17555. {return (!iterations || fn(separator, iterations++, this$0) !== false) &&
  17556. fn(v, iterations++, this$0) !== false},
  17557. reverse
  17558. );
  17559. return iterations;
  17560. };
  17561. interposedSequence.__iteratorUncached = function(type, reverse) {
  17562. var iterator = iterable.__iterator(ITERATE_VALUES, reverse);
  17563. var iterations = 0;
  17564. var step;
  17565. return new Iterator(function() {
  17566. if (!step || iterations % 2) {
  17567. step = iterator.next();
  17568. if (step.done) {
  17569. return step;
  17570. }
  17571. }
  17572. return iterations % 2 ?
  17573. iteratorValue(type, iterations++, separator) :
  17574. iteratorValue(type, iterations++, step.value, step);
  17575. });
  17576. };
  17577. return interposedSequence;
  17578. }
  17579. function sortFactory(iterable, comparator, mapper) {
  17580. if (!comparator) {
  17581. comparator = defaultComparator;
  17582. }
  17583. var isKeyedIterable = isKeyed(iterable);
  17584. var index = 0;
  17585. var entries = iterable.toSeq().map(
  17586. function(v, k) {return [k, v, index++, mapper ? mapper(v, k, iterable) : v]}
  17587. ).toArray();
  17588. entries.sort(function(a, b) {return comparator(a[3], b[3]) || a[2] - b[2]}).forEach(
  17589. isKeyedIterable ?
  17590. function(v, i) { entries[i].length = 2; } :
  17591. function(v, i) { entries[i] = v[1]; }
  17592. );
  17593. return isKeyedIterable ? KeyedSeq(entries) :
  17594. isIndexed(iterable) ? IndexedSeq(entries) :
  17595. SetSeq(entries);
  17596. }
  17597. function maxFactory(iterable, comparator, mapper) {
  17598. if (!comparator) {
  17599. comparator = defaultComparator;
  17600. }
  17601. if (mapper) {
  17602. var entry = iterable.toSeq()
  17603. .map(function(v, k) {return [v, mapper(v, k, iterable)]})
  17604. .reduce(function(a, b) {return maxCompare(comparator, a[1], b[1]) ? b : a});
  17605. return entry && entry[0];
  17606. } else {
  17607. return iterable.reduce(function(a, b) {return maxCompare(comparator, a, b) ? b : a});
  17608. }
  17609. }
  17610. function maxCompare(comparator, a, b) {
  17611. var comp = comparator(b, a);
  17612. // b is considered the new max if the comparator declares them equal, but
  17613. // they are not equal and b is in fact a nullish value.
  17614. return (comp === 0 && b !== a && (b === undefined || b === null || b !== b)) || comp > 0;
  17615. }
  17616. function zipWithFactory(keyIter, zipper, iters) {
  17617. var zipSequence = makeSequence(keyIter);
  17618. zipSequence.size = new ArraySeq(iters).map(function(i ) {return i.size}).min();
  17619. // Note: this a generic base implementation of __iterate in terms of
  17620. // __iterator which may be more generically useful in the future.
  17621. zipSequence.__iterate = function(fn, reverse) {
  17622. /* generic:
  17623. var iterator = this.__iterator(ITERATE_ENTRIES, reverse);
  17624. var step;
  17625. var iterations = 0;
  17626. while (!(step = iterator.next()).done) {
  17627. iterations++;
  17628. if (fn(step.value[1], step.value[0], this) === false) {
  17629. break;
  17630. }
  17631. }
  17632. return iterations;
  17633. */
  17634. // indexed:
  17635. var iterator = this.__iterator(ITERATE_VALUES, reverse);
  17636. var step;
  17637. var iterations = 0;
  17638. while (!(step = iterator.next()).done) {
  17639. if (fn(step.value, iterations++, this) === false) {
  17640. break;
  17641. }
  17642. }
  17643. return iterations;
  17644. };
  17645. zipSequence.__iteratorUncached = function(type, reverse) {
  17646. var iterators = iters.map(function(i )
  17647. {return (i = Iterable(i), getIterator(reverse ? i.reverse() : i))}
  17648. );
  17649. var iterations = 0;
  17650. var isDone = false;
  17651. return new Iterator(function() {
  17652. var steps;
  17653. if (!isDone) {
  17654. steps = iterators.map(function(i ) {return i.next()});
  17655. isDone = steps.some(function(s ) {return s.done});
  17656. }
  17657. if (isDone) {
  17658. return iteratorDone();
  17659. }
  17660. return iteratorValue(
  17661. type,
  17662. iterations++,
  17663. zipper.apply(null, steps.map(function(s ) {return s.value}))
  17664. );
  17665. });
  17666. };
  17667. return zipSequence
  17668. }
  17669. // #pragma Helper Functions
  17670. function reify(iter, seq) {
  17671. return isSeq(iter) ? seq : iter.constructor(seq);
  17672. }
  17673. function validateEntry(entry) {
  17674. if (entry !== Object(entry)) {
  17675. throw new TypeError('Expected [K, V] tuple: ' + entry);
  17676. }
  17677. }
  17678. function resolveSize(iter) {
  17679. assertNotInfinite(iter.size);
  17680. return ensureSize(iter);
  17681. }
  17682. function iterableClass(iterable) {
  17683. return isKeyed(iterable) ? KeyedIterable :
  17684. isIndexed(iterable) ? IndexedIterable :
  17685. SetIterable;
  17686. }
  17687. function makeSequence(iterable) {
  17688. return Object.create(
  17689. (
  17690. isKeyed(iterable) ? KeyedSeq :
  17691. isIndexed(iterable) ? IndexedSeq :
  17692. SetSeq
  17693. ).prototype
  17694. );
  17695. }
  17696. function cacheResultThrough() {
  17697. if (this._iter.cacheResult) {
  17698. this._iter.cacheResult();
  17699. this.size = this._iter.size;
  17700. return this;
  17701. } else {
  17702. return Seq.prototype.cacheResult.call(this);
  17703. }
  17704. }
  17705. function defaultComparator(a, b) {
  17706. return a > b ? 1 : a < b ? -1 : 0;
  17707. }
  17708. function forceIterator(keyPath) {
  17709. var iter = getIterator(keyPath);
  17710. if (!iter) {
  17711. // Array might not be iterable in this environment, so we need a fallback
  17712. // to our wrapped type.
  17713. if (!isArrayLike(keyPath)) {
  17714. throw new TypeError('Expected iterable or array-like: ' + keyPath);
  17715. }
  17716. iter = getIterator(Iterable(keyPath));
  17717. }
  17718. return iter;
  17719. }
  17720. createClass(Record, KeyedCollection);
  17721. function Record(defaultValues, name) {
  17722. var hasInitialized;
  17723. var RecordType = function Record(values) {
  17724. if (values instanceof RecordType) {
  17725. return values;
  17726. }
  17727. if (!(this instanceof RecordType)) {
  17728. return new RecordType(values);
  17729. }
  17730. if (!hasInitialized) {
  17731. hasInitialized = true;
  17732. var keys = Object.keys(defaultValues);
  17733. setProps(RecordTypePrototype, keys);
  17734. RecordTypePrototype.size = keys.length;
  17735. RecordTypePrototype._name = name;
  17736. RecordTypePrototype._keys = keys;
  17737. RecordTypePrototype._defaultValues = defaultValues;
  17738. }
  17739. this._map = Map(values);
  17740. };
  17741. var RecordTypePrototype = RecordType.prototype = Object.create(RecordPrototype);
  17742. RecordTypePrototype.constructor = RecordType;
  17743. return RecordType;
  17744. }
  17745. Record.prototype.toString = function() {
  17746. return this.__toString(recordName(this) + ' {', '}');
  17747. };
  17748. // @pragma Access
  17749. Record.prototype.has = function(k) {
  17750. return this._defaultValues.hasOwnProperty(k);
  17751. };
  17752. Record.prototype.get = function(k, notSetValue) {
  17753. if (!this.has(k)) {
  17754. return notSetValue;
  17755. }
  17756. var defaultVal = this._defaultValues[k];
  17757. return this._map ? this._map.get(k, defaultVal) : defaultVal;
  17758. };
  17759. // @pragma Modification
  17760. Record.prototype.clear = function() {
  17761. if (this.__ownerID) {
  17762. this._map && this._map.clear();
  17763. return this;
  17764. }
  17765. var RecordType = this.constructor;
  17766. return RecordType._empty || (RecordType._empty = makeRecord(this, emptyMap()));
  17767. };
  17768. Record.prototype.set = function(k, v) {
  17769. if (!this.has(k)) {
  17770. throw new Error('Cannot set unknown key "' + k + '" on ' + recordName(this));
  17771. }
  17772. var newMap = this._map && this._map.set(k, v);
  17773. if (this.__ownerID || newMap === this._map) {
  17774. return this;
  17775. }
  17776. return makeRecord(this, newMap);
  17777. };
  17778. Record.prototype.remove = function(k) {
  17779. if (!this.has(k)) {
  17780. return this;
  17781. }
  17782. var newMap = this._map && this._map.remove(k);
  17783. if (this.__ownerID || newMap === this._map) {
  17784. return this;
  17785. }
  17786. return makeRecord(this, newMap);
  17787. };
  17788. Record.prototype.wasAltered = function() {
  17789. return this._map.wasAltered();
  17790. };
  17791. Record.prototype.__iterator = function(type, reverse) {var this$0 = this;
  17792. return KeyedIterable(this._defaultValues).map(function(_, k) {return this$0.get(k)}).__iterator(type, reverse);
  17793. };
  17794. Record.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  17795. return KeyedIterable(this._defaultValues).map(function(_, k) {return this$0.get(k)}).__iterate(fn, reverse);
  17796. };
  17797. Record.prototype.__ensureOwner = function(ownerID) {
  17798. if (ownerID === this.__ownerID) {
  17799. return this;
  17800. }
  17801. var newMap = this._map && this._map.__ensureOwner(ownerID);
  17802. if (!ownerID) {
  17803. this.__ownerID = ownerID;
  17804. this._map = newMap;
  17805. return this;
  17806. }
  17807. return makeRecord(this, newMap, ownerID);
  17808. };
  17809. var RecordPrototype = Record.prototype;
  17810. RecordPrototype[DELETE] = RecordPrototype.remove;
  17811. RecordPrototype.deleteIn =
  17812. RecordPrototype.removeIn = MapPrototype.removeIn;
  17813. RecordPrototype.merge = MapPrototype.merge;
  17814. RecordPrototype.mergeWith = MapPrototype.mergeWith;
  17815. RecordPrototype.mergeIn = MapPrototype.mergeIn;
  17816. RecordPrototype.mergeDeep = MapPrototype.mergeDeep;
  17817. RecordPrototype.mergeDeepWith = MapPrototype.mergeDeepWith;
  17818. RecordPrototype.mergeDeepIn = MapPrototype.mergeDeepIn;
  17819. RecordPrototype.setIn = MapPrototype.setIn;
  17820. RecordPrototype.update = MapPrototype.update;
  17821. RecordPrototype.updateIn = MapPrototype.updateIn;
  17822. RecordPrototype.withMutations = MapPrototype.withMutations;
  17823. RecordPrototype.asMutable = MapPrototype.asMutable;
  17824. RecordPrototype.asImmutable = MapPrototype.asImmutable;
  17825. function makeRecord(likeRecord, map, ownerID) {
  17826. var record = Object.create(Object.getPrototypeOf(likeRecord));
  17827. record._map = map;
  17828. record.__ownerID = ownerID;
  17829. return record;
  17830. }
  17831. function recordName(record) {
  17832. return record._name || record.constructor.name || 'Record';
  17833. }
  17834. function setProps(prototype, names) {
  17835. try {
  17836. names.forEach(setProp.bind(undefined, prototype));
  17837. } catch (error) {
  17838. // Object.defineProperty failed. Probably IE8.
  17839. }
  17840. }
  17841. function setProp(prototype, name) {
  17842. Object.defineProperty(prototype, name, {
  17843. get: function() {
  17844. return this.get(name);
  17845. },
  17846. set: function(value) {
  17847. invariant(this.__ownerID, 'Cannot set on an immutable record.');
  17848. this.set(name, value);
  17849. }
  17850. });
  17851. }
  17852. createClass(Set, SetCollection);
  17853. // @pragma Construction
  17854. function Set(value) {
  17855. return value === null || value === undefined ? emptySet() :
  17856. isSet(value) && !isOrdered(value) ? value :
  17857. emptySet().withMutations(function(set ) {
  17858. var iter = SetIterable(value);
  17859. assertNotInfinite(iter.size);
  17860. iter.forEach(function(v ) {return set.add(v)});
  17861. });
  17862. }
  17863. Set.of = function(/*...values*/) {
  17864. return this(arguments);
  17865. };
  17866. Set.fromKeys = function(value) {
  17867. return this(KeyedIterable(value).keySeq());
  17868. };
  17869. Set.prototype.toString = function() {
  17870. return this.__toString('Set {', '}');
  17871. };
  17872. // @pragma Access
  17873. Set.prototype.has = function(value) {
  17874. return this._map.has(value);
  17875. };
  17876. // @pragma Modification
  17877. Set.prototype.add = function(value) {
  17878. return updateSet(this, this._map.set(value, true));
  17879. };
  17880. Set.prototype.remove = function(value) {
  17881. return updateSet(this, this._map.remove(value));
  17882. };
  17883. Set.prototype.clear = function() {
  17884. return updateSet(this, this._map.clear());
  17885. };
  17886. // @pragma Composition
  17887. Set.prototype.union = function() {var iters = SLICE$0.call(arguments, 0);
  17888. iters = iters.filter(function(x ) {return x.size !== 0});
  17889. if (iters.length === 0) {
  17890. return this;
  17891. }
  17892. if (this.size === 0 && !this.__ownerID && iters.length === 1) {
  17893. return this.constructor(iters[0]);
  17894. }
  17895. return this.withMutations(function(set ) {
  17896. for (var ii = 0; ii < iters.length; ii++) {
  17897. SetIterable(iters[ii]).forEach(function(value ) {return set.add(value)});
  17898. }
  17899. });
  17900. };
  17901. Set.prototype.intersect = function() {var iters = SLICE$0.call(arguments, 0);
  17902. if (iters.length === 0) {
  17903. return this;
  17904. }
  17905. iters = iters.map(function(iter ) {return SetIterable(iter)});
  17906. var originalSet = this;
  17907. return this.withMutations(function(set ) {
  17908. originalSet.forEach(function(value ) {
  17909. if (!iters.every(function(iter ) {return iter.includes(value)})) {
  17910. set.remove(value);
  17911. }
  17912. });
  17913. });
  17914. };
  17915. Set.prototype.subtract = function() {var iters = SLICE$0.call(arguments, 0);
  17916. if (iters.length === 0) {
  17917. return this;
  17918. }
  17919. iters = iters.map(function(iter ) {return SetIterable(iter)});
  17920. var originalSet = this;
  17921. return this.withMutations(function(set ) {
  17922. originalSet.forEach(function(value ) {
  17923. if (iters.some(function(iter ) {return iter.includes(value)})) {
  17924. set.remove(value);
  17925. }
  17926. });
  17927. });
  17928. };
  17929. Set.prototype.merge = function() {
  17930. return this.union.apply(this, arguments);
  17931. };
  17932. Set.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  17933. return this.union.apply(this, iters);
  17934. };
  17935. Set.prototype.sort = function(comparator) {
  17936. // Late binding
  17937. return OrderedSet(sortFactory(this, comparator));
  17938. };
  17939. Set.prototype.sortBy = function(mapper, comparator) {
  17940. // Late binding
  17941. return OrderedSet(sortFactory(this, comparator, mapper));
  17942. };
  17943. Set.prototype.wasAltered = function() {
  17944. return this._map.wasAltered();
  17945. };
  17946. Set.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  17947. return this._map.__iterate(function(_, k) {return fn(k, k, this$0)}, reverse);
  17948. };
  17949. Set.prototype.__iterator = function(type, reverse) {
  17950. return this._map.map(function(_, k) {return k}).__iterator(type, reverse);
  17951. };
  17952. Set.prototype.__ensureOwner = function(ownerID) {
  17953. if (ownerID === this.__ownerID) {
  17954. return this;
  17955. }
  17956. var newMap = this._map.__ensureOwner(ownerID);
  17957. if (!ownerID) {
  17958. this.__ownerID = ownerID;
  17959. this._map = newMap;
  17960. return this;
  17961. }
  17962. return this.__make(newMap, ownerID);
  17963. };
  17964. function isSet(maybeSet) {
  17965. return !!(maybeSet && maybeSet[IS_SET_SENTINEL]);
  17966. }
  17967. Set.isSet = isSet;
  17968. var IS_SET_SENTINEL = '@@__IMMUTABLE_SET__@@';
  17969. var SetPrototype = Set.prototype;
  17970. SetPrototype[IS_SET_SENTINEL] = true;
  17971. SetPrototype[DELETE] = SetPrototype.remove;
  17972. SetPrototype.mergeDeep = SetPrototype.merge;
  17973. SetPrototype.mergeDeepWith = SetPrototype.mergeWith;
  17974. SetPrototype.withMutations = MapPrototype.withMutations;
  17975. SetPrototype.asMutable = MapPrototype.asMutable;
  17976. SetPrototype.asImmutable = MapPrototype.asImmutable;
  17977. SetPrototype.__empty = emptySet;
  17978. SetPrototype.__make = makeSet;
  17979. function updateSet(set, newMap) {
  17980. if (set.__ownerID) {
  17981. set.size = newMap.size;
  17982. set._map = newMap;
  17983. return set;
  17984. }
  17985. return newMap === set._map ? set :
  17986. newMap.size === 0 ? set.__empty() :
  17987. set.__make(newMap);
  17988. }
  17989. function makeSet(map, ownerID) {
  17990. var set = Object.create(SetPrototype);
  17991. set.size = map ? map.size : 0;
  17992. set._map = map;
  17993. set.__ownerID = ownerID;
  17994. return set;
  17995. }
  17996. var EMPTY_SET;
  17997. function emptySet() {
  17998. return EMPTY_SET || (EMPTY_SET = makeSet(emptyMap()));
  17999. }
  18000. createClass(OrderedSet, Set);
  18001. // @pragma Construction
  18002. function OrderedSet(value) {
  18003. return value === null || value === undefined ? emptyOrderedSet() :
  18004. isOrderedSet(value) ? value :
  18005. emptyOrderedSet().withMutations(function(set ) {
  18006. var iter = SetIterable(value);
  18007. assertNotInfinite(iter.size);
  18008. iter.forEach(function(v ) {return set.add(v)});
  18009. });
  18010. }
  18011. OrderedSet.of = function(/*...values*/) {
  18012. return this(arguments);
  18013. };
  18014. OrderedSet.fromKeys = function(value) {
  18015. return this(KeyedIterable(value).keySeq());
  18016. };
  18017. OrderedSet.prototype.toString = function() {
  18018. return this.__toString('OrderedSet {', '}');
  18019. };
  18020. function isOrderedSet(maybeOrderedSet) {
  18021. return isSet(maybeOrderedSet) && isOrdered(maybeOrderedSet);
  18022. }
  18023. OrderedSet.isOrderedSet = isOrderedSet;
  18024. var OrderedSetPrototype = OrderedSet.prototype;
  18025. OrderedSetPrototype[IS_ORDERED_SENTINEL] = true;
  18026. OrderedSetPrototype.__empty = emptyOrderedSet;
  18027. OrderedSetPrototype.__make = makeOrderedSet;
  18028. function makeOrderedSet(map, ownerID) {
  18029. var set = Object.create(OrderedSetPrototype);
  18030. set.size = map ? map.size : 0;
  18031. set._map = map;
  18032. set.__ownerID = ownerID;
  18033. return set;
  18034. }
  18035. var EMPTY_ORDERED_SET;
  18036. function emptyOrderedSet() {
  18037. return EMPTY_ORDERED_SET || (EMPTY_ORDERED_SET = makeOrderedSet(emptyOrderedMap()));
  18038. }
  18039. createClass(Stack, IndexedCollection);
  18040. // @pragma Construction
  18041. function Stack(value) {
  18042. return value === null || value === undefined ? emptyStack() :
  18043. isStack(value) ? value :
  18044. emptyStack().unshiftAll(value);
  18045. }
  18046. Stack.of = function(/*...values*/) {
  18047. return this(arguments);
  18048. };
  18049. Stack.prototype.toString = function() {
  18050. return this.__toString('Stack [', ']');
  18051. };
  18052. // @pragma Access
  18053. Stack.prototype.get = function(index, notSetValue) {
  18054. var head = this._head;
  18055. index = wrapIndex(this, index);
  18056. while (head && index--) {
  18057. head = head.next;
  18058. }
  18059. return head ? head.value : notSetValue;
  18060. };
  18061. Stack.prototype.peek = function() {
  18062. return this._head && this._head.value;
  18063. };
  18064. // @pragma Modification
  18065. Stack.prototype.push = function(/*...values*/) {
  18066. if (arguments.length === 0) {
  18067. return this;
  18068. }
  18069. var newSize = this.size + arguments.length;
  18070. var head = this._head;
  18071. for (var ii = arguments.length - 1; ii >= 0; ii--) {
  18072. head = {
  18073. value: arguments[ii],
  18074. next: head
  18075. };
  18076. }
  18077. if (this.__ownerID) {
  18078. this.size = newSize;
  18079. this._head = head;
  18080. this.__hash = undefined;
  18081. this.__altered = true;
  18082. return this;
  18083. }
  18084. return makeStack(newSize, head);
  18085. };
  18086. Stack.prototype.pushAll = function(iter) {
  18087. iter = IndexedIterable(iter);
  18088. if (iter.size === 0) {
  18089. return this;
  18090. }
  18091. assertNotInfinite(iter.size);
  18092. var newSize = this.size;
  18093. var head = this._head;
  18094. iter.reverse().forEach(function(value ) {
  18095. newSize++;
  18096. head = {
  18097. value: value,
  18098. next: head
  18099. };
  18100. });
  18101. if (this.__ownerID) {
  18102. this.size = newSize;
  18103. this._head = head;
  18104. this.__hash = undefined;
  18105. this.__altered = true;
  18106. return this;
  18107. }
  18108. return makeStack(newSize, head);
  18109. };
  18110. Stack.prototype.pop = function() {
  18111. return this.slice(1);
  18112. };
  18113. Stack.prototype.unshift = function(/*...values*/) {
  18114. return this.push.apply(this, arguments);
  18115. };
  18116. Stack.prototype.unshiftAll = function(iter) {
  18117. return this.pushAll(iter);
  18118. };
  18119. Stack.prototype.shift = function() {
  18120. return this.pop.apply(this, arguments);
  18121. };
  18122. Stack.prototype.clear = function() {
  18123. if (this.size === 0) {
  18124. return this;
  18125. }
  18126. if (this.__ownerID) {
  18127. this.size = 0;
  18128. this._head = undefined;
  18129. this.__hash = undefined;
  18130. this.__altered = true;
  18131. return this;
  18132. }
  18133. return emptyStack();
  18134. };
  18135. Stack.prototype.slice = function(begin, end) {
  18136. if (wholeSlice(begin, end, this.size)) {
  18137. return this;
  18138. }
  18139. var resolvedBegin = resolveBegin(begin, this.size);
  18140. var resolvedEnd = resolveEnd(end, this.size);
  18141. if (resolvedEnd !== this.size) {
  18142. // super.slice(begin, end);
  18143. return IndexedCollection.prototype.slice.call(this, begin, end);
  18144. }
  18145. var newSize = this.size - resolvedBegin;
  18146. var head = this._head;
  18147. while (resolvedBegin--) {
  18148. head = head.next;
  18149. }
  18150. if (this.__ownerID) {
  18151. this.size = newSize;
  18152. this._head = head;
  18153. this.__hash = undefined;
  18154. this.__altered = true;
  18155. return this;
  18156. }
  18157. return makeStack(newSize, head);
  18158. };
  18159. // @pragma Mutability
  18160. Stack.prototype.__ensureOwner = function(ownerID) {
  18161. if (ownerID === this.__ownerID) {
  18162. return this;
  18163. }
  18164. if (!ownerID) {
  18165. this.__ownerID = ownerID;
  18166. this.__altered = false;
  18167. return this;
  18168. }
  18169. return makeStack(this.size, this._head, ownerID, this.__hash);
  18170. };
  18171. // @pragma Iteration
  18172. Stack.prototype.__iterate = function(fn, reverse) {
  18173. if (reverse) {
  18174. return this.reverse().__iterate(fn);
  18175. }
  18176. var iterations = 0;
  18177. var node = this._head;
  18178. while (node) {
  18179. if (fn(node.value, iterations++, this) === false) {
  18180. break;
  18181. }
  18182. node = node.next;
  18183. }
  18184. return iterations;
  18185. };
  18186. Stack.prototype.__iterator = function(type, reverse) {
  18187. if (reverse) {
  18188. return this.reverse().__iterator(type);
  18189. }
  18190. var iterations = 0;
  18191. var node = this._head;
  18192. return new Iterator(function() {
  18193. if (node) {
  18194. var value = node.value;
  18195. node = node.next;
  18196. return iteratorValue(type, iterations++, value);
  18197. }
  18198. return iteratorDone();
  18199. });
  18200. };
  18201. function isStack(maybeStack) {
  18202. return !!(maybeStack && maybeStack[IS_STACK_SENTINEL]);
  18203. }
  18204. Stack.isStack = isStack;
  18205. var IS_STACK_SENTINEL = '@@__IMMUTABLE_STACK__@@';
  18206. var StackPrototype = Stack.prototype;
  18207. StackPrototype[IS_STACK_SENTINEL] = true;
  18208. StackPrototype.withMutations = MapPrototype.withMutations;
  18209. StackPrototype.asMutable = MapPrototype.asMutable;
  18210. StackPrototype.asImmutable = MapPrototype.asImmutable;
  18211. StackPrototype.wasAltered = MapPrototype.wasAltered;
  18212. function makeStack(size, head, ownerID, hash) {
  18213. var map = Object.create(StackPrototype);
  18214. map.size = size;
  18215. map._head = head;
  18216. map.__ownerID = ownerID;
  18217. map.__hash = hash;
  18218. map.__altered = false;
  18219. return map;
  18220. }
  18221. var EMPTY_STACK;
  18222. function emptyStack() {
  18223. return EMPTY_STACK || (EMPTY_STACK = makeStack(0));
  18224. }
  18225. /**
  18226. * Contributes additional methods to a constructor
  18227. */
  18228. function mixin(ctor, methods) {
  18229. var keyCopier = function(key ) { ctor.prototype[key] = methods[key]; };
  18230. Object.keys(methods).forEach(keyCopier);
  18231. Object.getOwnPropertySymbols &&
  18232. Object.getOwnPropertySymbols(methods).forEach(keyCopier);
  18233. return ctor;
  18234. }
  18235. Iterable.Iterator = Iterator;
  18236. mixin(Iterable, {
  18237. // ### Conversion to other types
  18238. toArray: function() {
  18239. assertNotInfinite(this.size);
  18240. var array = new Array(this.size || 0);
  18241. this.valueSeq().__iterate(function(v, i) { array[i] = v; });
  18242. return array;
  18243. },
  18244. toIndexedSeq: function() {
  18245. return new ToIndexedSequence(this);
  18246. },
  18247. toJS: function() {
  18248. return this.toSeq().map(
  18249. function(value ) {return value && typeof value.toJS === 'function' ? value.toJS() : value}
  18250. ).__toJS();
  18251. },
  18252. toJSON: function() {
  18253. return this.toSeq().map(
  18254. function(value ) {return value && typeof value.toJSON === 'function' ? value.toJSON() : value}
  18255. ).__toJS();
  18256. },
  18257. toKeyedSeq: function() {
  18258. return new ToKeyedSequence(this, true);
  18259. },
  18260. toMap: function() {
  18261. // Use Late Binding here to solve the circular dependency.
  18262. return Map(this.toKeyedSeq());
  18263. },
  18264. toObject: function() {
  18265. assertNotInfinite(this.size);
  18266. var object = {};
  18267. this.__iterate(function(v, k) { object[k] = v; });
  18268. return object;
  18269. },
  18270. toOrderedMap: function() {
  18271. // Use Late Binding here to solve the circular dependency.
  18272. return OrderedMap(this.toKeyedSeq());
  18273. },
  18274. toOrderedSet: function() {
  18275. // Use Late Binding here to solve the circular dependency.
  18276. return OrderedSet(isKeyed(this) ? this.valueSeq() : this);
  18277. },
  18278. toSet: function() {
  18279. // Use Late Binding here to solve the circular dependency.
  18280. return Set(isKeyed(this) ? this.valueSeq() : this);
  18281. },
  18282. toSetSeq: function() {
  18283. return new ToSetSequence(this);
  18284. },
  18285. toSeq: function() {
  18286. return isIndexed(this) ? this.toIndexedSeq() :
  18287. isKeyed(this) ? this.toKeyedSeq() :
  18288. this.toSetSeq();
  18289. },
  18290. toStack: function() {
  18291. // Use Late Binding here to solve the circular dependency.
  18292. return Stack(isKeyed(this) ? this.valueSeq() : this);
  18293. },
  18294. toList: function() {
  18295. // Use Late Binding here to solve the circular dependency.
  18296. return List(isKeyed(this) ? this.valueSeq() : this);
  18297. },
  18298. // ### Common JavaScript methods and properties
  18299. toString: function() {
  18300. return '[Iterable]';
  18301. },
  18302. __toString: function(head, tail) {
  18303. if (this.size === 0) {
  18304. return head + tail;
  18305. }
  18306. return head + ' ' + this.toSeq().map(this.__toStringMapper).join(', ') + ' ' + tail;
  18307. },
  18308. // ### ES6 Collection methods (ES6 Array and Map)
  18309. concat: function() {var values = SLICE$0.call(arguments, 0);
  18310. return reify(this, concatFactory(this, values));
  18311. },
  18312. includes: function(searchValue) {
  18313. return this.some(function(value ) {return is(value, searchValue)});
  18314. },
  18315. entries: function() {
  18316. return this.__iterator(ITERATE_ENTRIES);
  18317. },
  18318. every: function(predicate, context) {
  18319. assertNotInfinite(this.size);
  18320. var returnValue = true;
  18321. this.__iterate(function(v, k, c) {
  18322. if (!predicate.call(context, v, k, c)) {
  18323. returnValue = false;
  18324. return false;
  18325. }
  18326. });
  18327. return returnValue;
  18328. },
  18329. filter: function(predicate, context) {
  18330. return reify(this, filterFactory(this, predicate, context, true));
  18331. },
  18332. find: function(predicate, context, notSetValue) {
  18333. var entry = this.findEntry(predicate, context);
  18334. return entry ? entry[1] : notSetValue;
  18335. },
  18336. findEntry: function(predicate, context) {
  18337. var found;
  18338. this.__iterate(function(v, k, c) {
  18339. if (predicate.call(context, v, k, c)) {
  18340. found = [k, v];
  18341. return false;
  18342. }
  18343. });
  18344. return found;
  18345. },
  18346. findLastEntry: function(predicate, context) {
  18347. return this.toSeq().reverse().findEntry(predicate, context);
  18348. },
  18349. forEach: function(sideEffect, context) {
  18350. assertNotInfinite(this.size);
  18351. return this.__iterate(context ? sideEffect.bind(context) : sideEffect);
  18352. },
  18353. join: function(separator) {
  18354. assertNotInfinite(this.size);
  18355. separator = separator !== undefined ? '' + separator : ',';
  18356. var joined = '';
  18357. var isFirst = true;
  18358. this.__iterate(function(v ) {
  18359. isFirst ? (isFirst = false) : (joined += separator);
  18360. joined += v !== null && v !== undefined ? v.toString() : '';
  18361. });
  18362. return joined;
  18363. },
  18364. keys: function() {
  18365. return this.__iterator(ITERATE_KEYS);
  18366. },
  18367. map: function(mapper, context) {
  18368. return reify(this, mapFactory(this, mapper, context));
  18369. },
  18370. reduce: function(reducer, initialReduction, context) {
  18371. assertNotInfinite(this.size);
  18372. var reduction;
  18373. var useFirst;
  18374. if (arguments.length < 2) {
  18375. useFirst = true;
  18376. } else {
  18377. reduction = initialReduction;
  18378. }
  18379. this.__iterate(function(v, k, c) {
  18380. if (useFirst) {
  18381. useFirst = false;
  18382. reduction = v;
  18383. } else {
  18384. reduction = reducer.call(context, reduction, v, k, c);
  18385. }
  18386. });
  18387. return reduction;
  18388. },
  18389. reduceRight: function(reducer, initialReduction, context) {
  18390. var reversed = this.toKeyedSeq().reverse();
  18391. return reversed.reduce.apply(reversed, arguments);
  18392. },
  18393. reverse: function() {
  18394. return reify(this, reverseFactory(this, true));
  18395. },
  18396. slice: function(begin, end) {
  18397. return reify(this, sliceFactory(this, begin, end, true));
  18398. },
  18399. some: function(predicate, context) {
  18400. return !this.every(not(predicate), context);
  18401. },
  18402. sort: function(comparator) {
  18403. return reify(this, sortFactory(this, comparator));
  18404. },
  18405. values: function() {
  18406. return this.__iterator(ITERATE_VALUES);
  18407. },
  18408. // ### More sequential methods
  18409. butLast: function() {
  18410. return this.slice(0, -1);
  18411. },
  18412. isEmpty: function() {
  18413. return this.size !== undefined ? this.size === 0 : !this.some(function() {return true});
  18414. },
  18415. count: function(predicate, context) {
  18416. return ensureSize(
  18417. predicate ? this.toSeq().filter(predicate, context) : this
  18418. );
  18419. },
  18420. countBy: function(grouper, context) {
  18421. return countByFactory(this, grouper, context);
  18422. },
  18423. equals: function(other) {
  18424. return deepEqual(this, other);
  18425. },
  18426. entrySeq: function() {
  18427. var iterable = this;
  18428. if (iterable._cache) {
  18429. // We cache as an entries array, so we can just return the cache!
  18430. return new ArraySeq(iterable._cache);
  18431. }
  18432. var entriesSequence = iterable.toSeq().map(entryMapper).toIndexedSeq();
  18433. entriesSequence.fromEntrySeq = function() {return iterable.toSeq()};
  18434. return entriesSequence;
  18435. },
  18436. filterNot: function(predicate, context) {
  18437. return this.filter(not(predicate), context);
  18438. },
  18439. findLast: function(predicate, context, notSetValue) {
  18440. return this.toKeyedSeq().reverse().find(predicate, context, notSetValue);
  18441. },
  18442. first: function() {
  18443. return this.find(returnTrue);
  18444. },
  18445. flatMap: function(mapper, context) {
  18446. return reify(this, flatMapFactory(this, mapper, context));
  18447. },
  18448. flatten: function(depth) {
  18449. return reify(this, flattenFactory(this, depth, true));
  18450. },
  18451. fromEntrySeq: function() {
  18452. return new FromEntriesSequence(this);
  18453. },
  18454. get: function(searchKey, notSetValue) {
  18455. return this.find(function(_, key) {return is(key, searchKey)}, undefined, notSetValue);
  18456. },
  18457. getIn: function(searchKeyPath, notSetValue) {
  18458. var nested = this;
  18459. // Note: in an ES6 environment, we would prefer:
  18460. // for (var key of searchKeyPath) {
  18461. var iter = forceIterator(searchKeyPath);
  18462. var step;
  18463. while (!(step = iter.next()).done) {
  18464. var key = step.value;
  18465. nested = nested && nested.get ? nested.get(key, NOT_SET) : NOT_SET;
  18466. if (nested === NOT_SET) {
  18467. return notSetValue;
  18468. }
  18469. }
  18470. return nested;
  18471. },
  18472. groupBy: function(grouper, context) {
  18473. return groupByFactory(this, grouper, context);
  18474. },
  18475. has: function(searchKey) {
  18476. return this.get(searchKey, NOT_SET) !== NOT_SET;
  18477. },
  18478. hasIn: function(searchKeyPath) {
  18479. return this.getIn(searchKeyPath, NOT_SET) !== NOT_SET;
  18480. },
  18481. isSubset: function(iter) {
  18482. iter = typeof iter.includes === 'function' ? iter : Iterable(iter);
  18483. return this.every(function(value ) {return iter.includes(value)});
  18484. },
  18485. isSuperset: function(iter) {
  18486. iter = typeof iter.isSubset === 'function' ? iter : Iterable(iter);
  18487. return iter.isSubset(this);
  18488. },
  18489. keySeq: function() {
  18490. return this.toSeq().map(keyMapper).toIndexedSeq();
  18491. },
  18492. last: function() {
  18493. return this.toSeq().reverse().first();
  18494. },
  18495. max: function(comparator) {
  18496. return maxFactory(this, comparator);
  18497. },
  18498. maxBy: function(mapper, comparator) {
  18499. return maxFactory(this, comparator, mapper);
  18500. },
  18501. min: function(comparator) {
  18502. return maxFactory(this, comparator ? neg(comparator) : defaultNegComparator);
  18503. },
  18504. minBy: function(mapper, comparator) {
  18505. return maxFactory(this, comparator ? neg(comparator) : defaultNegComparator, mapper);
  18506. },
  18507. rest: function() {
  18508. return this.slice(1);
  18509. },
  18510. skip: function(amount) {
  18511. return this.slice(Math.max(0, amount));
  18512. },
  18513. skipLast: function(amount) {
  18514. return reify(this, this.toSeq().reverse().skip(amount).reverse());
  18515. },
  18516. skipWhile: function(predicate, context) {
  18517. return reify(this, skipWhileFactory(this, predicate, context, true));
  18518. },
  18519. skipUntil: function(predicate, context) {
  18520. return this.skipWhile(not(predicate), context);
  18521. },
  18522. sortBy: function(mapper, comparator) {
  18523. return reify(this, sortFactory(this, comparator, mapper));
  18524. },
  18525. take: function(amount) {
  18526. return this.slice(0, Math.max(0, amount));
  18527. },
  18528. takeLast: function(amount) {
  18529. return reify(this, this.toSeq().reverse().take(amount).reverse());
  18530. },
  18531. takeWhile: function(predicate, context) {
  18532. return reify(this, takeWhileFactory(this, predicate, context));
  18533. },
  18534. takeUntil: function(predicate, context) {
  18535. return this.takeWhile(not(predicate), context);
  18536. },
  18537. valueSeq: function() {
  18538. return this.toIndexedSeq();
  18539. },
  18540. // ### Hashable Object
  18541. hashCode: function() {
  18542. return this.__hash || (this.__hash = hashIterable(this));
  18543. }
  18544. // ### Internal
  18545. // abstract __iterate(fn, reverse)
  18546. // abstract __iterator(type, reverse)
  18547. });
  18548. // var IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
  18549. // var IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
  18550. // var IS_INDEXED_SENTINEL = '@@__IMMUTABLE_INDEXED__@@';
  18551. // var IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
  18552. var IterablePrototype = Iterable.prototype;
  18553. IterablePrototype[IS_ITERABLE_SENTINEL] = true;
  18554. IterablePrototype[ITERATOR_SYMBOL] = IterablePrototype.values;
  18555. IterablePrototype.__toJS = IterablePrototype.toArray;
  18556. IterablePrototype.__toStringMapper = quoteString;
  18557. IterablePrototype.inspect =
  18558. IterablePrototype.toSource = function() { return this.toString(); };
  18559. IterablePrototype.chain = IterablePrototype.flatMap;
  18560. IterablePrototype.contains = IterablePrototype.includes;
  18561. // Temporary warning about using length
  18562. (function () {
  18563. try {
  18564. Object.defineProperty(IterablePrototype, 'length', {
  18565. get: function () {
  18566. if (!Iterable.noLengthWarning) {
  18567. var stack;
  18568. try {
  18569. throw new Error();
  18570. } catch (error) {
  18571. stack = error.stack;
  18572. }
  18573. if (stack.indexOf('_wrapObject') === -1) {
  18574. console && console.warn && console.warn(
  18575. 'iterable.length has been deprecated, '+
  18576. 'use iterable.size or iterable.count(). '+
  18577. 'This warning will become a silent error in a future version. ' +
  18578. stack
  18579. );
  18580. return this.size;
  18581. }
  18582. }
  18583. }
  18584. });
  18585. } catch (e) {}
  18586. })();
  18587. mixin(KeyedIterable, {
  18588. // ### More sequential methods
  18589. flip: function() {
  18590. return reify(this, flipFactory(this));
  18591. },
  18592. findKey: function(predicate, context) {
  18593. var entry = this.findEntry(predicate, context);
  18594. return entry && entry[0];
  18595. },
  18596. findLastKey: function(predicate, context) {
  18597. return this.toSeq().reverse().findKey(predicate, context);
  18598. },
  18599. keyOf: function(searchValue) {
  18600. return this.findKey(function(value ) {return is(value, searchValue)});
  18601. },
  18602. lastKeyOf: function(searchValue) {
  18603. return this.findLastKey(function(value ) {return is(value, searchValue)});
  18604. },
  18605. mapEntries: function(mapper, context) {var this$0 = this;
  18606. var iterations = 0;
  18607. return reify(this,
  18608. this.toSeq().map(
  18609. function(v, k) {return mapper.call(context, [k, v], iterations++, this$0)}
  18610. ).fromEntrySeq()
  18611. );
  18612. },
  18613. mapKeys: function(mapper, context) {var this$0 = this;
  18614. return reify(this,
  18615. this.toSeq().flip().map(
  18616. function(k, v) {return mapper.call(context, k, v, this$0)}
  18617. ).flip()
  18618. );
  18619. }
  18620. });
  18621. var KeyedIterablePrototype = KeyedIterable.prototype;
  18622. KeyedIterablePrototype[IS_KEYED_SENTINEL] = true;
  18623. KeyedIterablePrototype[ITERATOR_SYMBOL] = IterablePrototype.entries;
  18624. KeyedIterablePrototype.__toJS = IterablePrototype.toObject;
  18625. KeyedIterablePrototype.__toStringMapper = function(v, k) {return JSON.stringify(k) + ': ' + quoteString(v)};
  18626. mixin(IndexedIterable, {
  18627. // ### Conversion to other types
  18628. toKeyedSeq: function() {
  18629. return new ToKeyedSequence(this, false);
  18630. },
  18631. // ### ES6 Collection methods (ES6 Array and Map)
  18632. filter: function(predicate, context) {
  18633. return reify(this, filterFactory(this, predicate, context, false));
  18634. },
  18635. findIndex: function(predicate, context) {
  18636. var entry = this.findEntry(predicate, context);
  18637. return entry ? entry[0] : -1;
  18638. },
  18639. indexOf: function(searchValue) {
  18640. var key = this.toKeyedSeq().keyOf(searchValue);
  18641. return key === undefined ? -1 : key;
  18642. },
  18643. lastIndexOf: function(searchValue) {
  18644. var key = this.toKeyedSeq().reverse().keyOf(searchValue);
  18645. return key === undefined ? -1 : key;
  18646. // var index =
  18647. // return this.toSeq().reverse().indexOf(searchValue);
  18648. },
  18649. reverse: function() {
  18650. return reify(this, reverseFactory(this, false));
  18651. },
  18652. slice: function(begin, end) {
  18653. return reify(this, sliceFactory(this, begin, end, false));
  18654. },
  18655. splice: function(index, removeNum /*, ...values*/) {
  18656. var numArgs = arguments.length;
  18657. removeNum = Math.max(removeNum | 0, 0);
  18658. if (numArgs === 0 || (numArgs === 2 && !removeNum)) {
  18659. return this;
  18660. }
  18661. // If index is negative, it should resolve relative to the size of the
  18662. // collection. However size may be expensive to compute if not cached, so
  18663. // only call count() if the number is in fact negative.
  18664. index = resolveBegin(index, index < 0 ? this.count() : this.size);
  18665. var spliced = this.slice(0, index);
  18666. return reify(
  18667. this,
  18668. numArgs === 1 ?
  18669. spliced :
  18670. spliced.concat(arrCopy(arguments, 2), this.slice(index + removeNum))
  18671. );
  18672. },
  18673. // ### More collection methods
  18674. findLastIndex: function(predicate, context) {
  18675. var key = this.toKeyedSeq().findLastKey(predicate, context);
  18676. return key === undefined ? -1 : key;
  18677. },
  18678. first: function() {
  18679. return this.get(0);
  18680. },
  18681. flatten: function(depth) {
  18682. return reify(this, flattenFactory(this, depth, false));
  18683. },
  18684. get: function(index, notSetValue) {
  18685. index = wrapIndex(this, index);
  18686. return (index < 0 || (this.size === Infinity ||
  18687. (this.size !== undefined && index > this.size))) ?
  18688. notSetValue :
  18689. this.find(function(_, key) {return key === index}, undefined, notSetValue);
  18690. },
  18691. has: function(index) {
  18692. index = wrapIndex(this, index);
  18693. return index >= 0 && (this.size !== undefined ?
  18694. this.size === Infinity || index < this.size :
  18695. this.indexOf(index) !== -1
  18696. );
  18697. },
  18698. interpose: function(separator) {
  18699. return reify(this, interposeFactory(this, separator));
  18700. },
  18701. interleave: function(/*...iterables*/) {
  18702. var iterables = [this].concat(arrCopy(arguments));
  18703. var zipped = zipWithFactory(this.toSeq(), IndexedSeq.of, iterables);
  18704. var interleaved = zipped.flatten(true);
  18705. if (zipped.size) {
  18706. interleaved.size = zipped.size * iterables.length;
  18707. }
  18708. return reify(this, interleaved);
  18709. },
  18710. last: function() {
  18711. return this.get(-1);
  18712. },
  18713. skipWhile: function(predicate, context) {
  18714. return reify(this, skipWhileFactory(this, predicate, context, false));
  18715. },
  18716. zip: function(/*, ...iterables */) {
  18717. var iterables = [this].concat(arrCopy(arguments));
  18718. return reify(this, zipWithFactory(this, defaultZipper, iterables));
  18719. },
  18720. zipWith: function(zipper/*, ...iterables */) {
  18721. var iterables = arrCopy(arguments);
  18722. iterables[0] = this;
  18723. return reify(this, zipWithFactory(this, zipper, iterables));
  18724. }
  18725. });
  18726. IndexedIterable.prototype[IS_INDEXED_SENTINEL] = true;
  18727. IndexedIterable.prototype[IS_ORDERED_SENTINEL] = true;
  18728. mixin(SetIterable, {
  18729. // ### ES6 Collection methods (ES6 Array and Map)
  18730. get: function(value, notSetValue) {
  18731. return this.has(value) ? value : notSetValue;
  18732. },
  18733. includes: function(value) {
  18734. return this.has(value);
  18735. },
  18736. // ### More sequential methods
  18737. keySeq: function() {
  18738. return this.valueSeq();
  18739. }
  18740. });
  18741. SetIterable.prototype.has = IterablePrototype.includes;
  18742. // Mixin subclasses
  18743. mixin(KeyedSeq, KeyedIterable.prototype);
  18744. mixin(IndexedSeq, IndexedIterable.prototype);
  18745. mixin(SetSeq, SetIterable.prototype);
  18746. mixin(KeyedCollection, KeyedIterable.prototype);
  18747. mixin(IndexedCollection, IndexedIterable.prototype);
  18748. mixin(SetCollection, SetIterable.prototype);
  18749. // #pragma Helper functions
  18750. function keyMapper(v, k) {
  18751. return k;
  18752. }
  18753. function entryMapper(v, k) {
  18754. return [k, v];
  18755. }
  18756. function not(predicate) {
  18757. return function() {
  18758. return !predicate.apply(this, arguments);
  18759. }
  18760. }
  18761. function neg(predicate) {
  18762. return function() {
  18763. return -predicate.apply(this, arguments);
  18764. }
  18765. }
  18766. function quoteString(value) {
  18767. return typeof value === 'string' ? JSON.stringify(value) : value;
  18768. }
  18769. function defaultZipper() {
  18770. return arrCopy(arguments);
  18771. }
  18772. function defaultNegComparator(a, b) {
  18773. return a < b ? 1 : a > b ? -1 : 0;
  18774. }
  18775. function hashIterable(iterable) {
  18776. if (iterable.size === Infinity) {
  18777. return 0;
  18778. }
  18779. var ordered = isOrdered(iterable);
  18780. var keyed = isKeyed(iterable);
  18781. var h = ordered ? 1 : 0;
  18782. var size = iterable.__iterate(
  18783. keyed ?
  18784. ordered ?
  18785. function(v, k) { h = 31 * h + hashMerge(hash(v), hash(k)) | 0; } :
  18786. function(v, k) { h = h + hashMerge(hash(v), hash(k)) | 0; } :
  18787. ordered ?
  18788. function(v ) { h = 31 * h + hash(v) | 0; } :
  18789. function(v ) { h = h + hash(v) | 0; }
  18790. );
  18791. return murmurHashOfSize(size, h);
  18792. }
  18793. function murmurHashOfSize(size, h) {
  18794. h = imul(h, 0xCC9E2D51);
  18795. h = imul(h << 15 | h >>> -15, 0x1B873593);
  18796. h = imul(h << 13 | h >>> -13, 5);
  18797. h = (h + 0xE6546B64 | 0) ^ size;
  18798. h = imul(h ^ h >>> 16, 0x85EBCA6B);
  18799. h = imul(h ^ h >>> 13, 0xC2B2AE35);
  18800. h = smi(h ^ h >>> 16);
  18801. return h;
  18802. }
  18803. function hashMerge(a, b) {
  18804. return a ^ b + 0x9E3779B9 + (a << 6) + (a >> 2) | 0; // int
  18805. }
  18806. var Immutable = {
  18807. Iterable: Iterable,
  18808. Seq: Seq,
  18809. Collection: Collection,
  18810. Map: Map,
  18811. OrderedMap: OrderedMap,
  18812. List: List,
  18813. Stack: Stack,
  18814. Set: Set,
  18815. OrderedSet: OrderedSet,
  18816. Record: Record,
  18817. Range: Range,
  18818. Repeat: Repeat,
  18819. is: is,
  18820. fromJS: fromJS
  18821. };
  18822. return Immutable;
  18823. }));
  18824. });
  18825. var draftjsUtils = _commonjsHelpers.createCommonjsModule(function (module, exports) {
  18826. !function(e,t){module.exports=t(Draft,immutable$1);}("undefined"!=typeof self?self:_commonjsHelpers.commonjsGlobal,function(e,t){return function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var n={};return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r});},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=3)}([function(t,n){t.exports=e;},function(e,t,n){function r(e){var t=e.getSelection(),n=e.getCurrentContent(),r=t.getStartKey(),o=t.getEndKey(),i=n.getBlockMap();return i.toSeq().skipUntil(function(e,t){return t===r}).takeUntil(function(e,t){return t===o}).concat([[o,i.get(o)]])}function o(e){return r(e).toList()}function i(e){if(e)return o(e).get(0)}function l(e){if(e){var t=i(e),n=e.getCurrentContent(),r=n.getBlockMap().toSeq().toList(),o=0;if(r.forEach(function(e,n){e.get("key")===t.get("key")&&(o=n-1);}),o>-1)return r.get(o)}}function c(e){return e?e.getCurrentContent().getBlockMap().toList():new v.List}function a(e){var t=o(e);if(!t.some(function(e){return e.type!==t.get(0).type}))return t.get(0).type}function f(e){var t=p.RichUtils.tryToRemoveBlockStyle(e);return t?p.EditorState.push(e,t,"change-block-type"):e}function u(e){var t="",n=e.getSelection(),r=n.getAnchorOffset(),i=n.getFocusOffset(),l=o(e);if(l.size>0){if(n.getIsBackward()){var c=r;r=i,i=c;}for(var a=0;a<l.size;a+=1){var f=0===a?r:0,u=a===l.size-1?i:l.get(a).getText().length;t+=l.get(a).getText().slice(f,u);}}return t}function s(e){var t=e.getCurrentContent(),n=e.getSelection(),r=p.Modifier.removeRange(t,n,"forward"),o=r.getSelectionAfter(),i=r.getBlockForKey(o.getStartKey());return r=p.Modifier.insertText(r,o,"\n",i.getInlineStyleAt(o.getStartOffset()),null),p.EditorState.push(e,r,"insert-fragment")}function g(e){var t=p.Modifier.splitBlock(e.getCurrentContent(),e.getSelection());return f(p.EditorState.push(e,t,"split-block"))}function d(e){var t=e.getCurrentContent().getBlockMap().toList(),n=e.getSelection().merge({anchorKey:t.first().get("key"),anchorOffset:0,focusKey:t.last().get("key"),focusOffset:t.last().getLength()}),r=p.Modifier.removeRange(e.getCurrentContent(),n,"forward");return p.EditorState.push(e,r,"remove-range")}function S(e,t){var n=p.Modifier.setBlockData(e.getCurrentContent(),e.getSelection(),t);return p.EditorState.push(e,n,"change-block-data")}function y(e){var t=new v.Map({}),n=o(e);if(n&&n.size>0)for(var r=0;r<n.size;r+=1){var i=function(e){var r=n.get(e).getData();if(!r||0===r.size)return t=t.clear(),"break";if(0===e)t=r;else if(t.forEach(function(e,n){r.get(n)&&r.get(n)===e||(t=t.delete(n));}),0===t.size)return t=t.clear(),"break"}(r);if("break"===i)break}return t}Object.defineProperty(t,"__esModule",{value:!0}),t.blockRenderMap=void 0,t.getSelectedBlocksMap=r,t.getSelectedBlocksList=o,t.getSelectedBlock=i,t.getBlockBeforeSelectedBlock=l,t.getAllBlocks=c,t.getSelectedBlocksType=a,t.removeSelectedBlocksStyle=f,t.getSelectionText=u,t.addLineBreakRemovingSelection=s,t.insertNewUnstyledBlock=g,t.clearEditorContent=d,t.setBlockData=S,t.getSelectedBlocksMetadata=y;var p=n(0),v=n(6),k=(0, v.Map)({code:{element:"pre"}});t.blockRenderMap=p.DefaultDraftBlockRenderMap.merge(k);},function(e,t,n){function r(e){if(e){var t=e.getType();return "unordered-list-item"===t||"ordered-list-item"===t}return !1}function o(e,t,n){var r=e.getSelection(),o=e.getCurrentContent(),i=o.getBlockMap(),l=(0, c.getSelectedBlocksMap)(e).map(function(e){var r=e.getDepth()+t;return r=Math.max(0,Math.min(r,n)),e.set("depth",r)});return i=i.merge(l),o.merge({blockMap:i,selectionBefore:r,selectionAfter:r})}function i(e,t,n){var r=e.getSelection(),i=void 0;i=r.getIsBackward()?r.getFocusKey():r.getAnchorKey();var c=e.getCurrentContent(),a=c.getBlockForKey(i),f=a.getType();if("unordered-list-item"!==f&&"ordered-list-item"!==f)return e;var u=c.getBlockBefore(i);if(!u)return e;if(u.getType()!==f)return e;var s=a.getDepth();if(1===t&&s===n)return e;var g=Math.min(u.getDepth()+1,n),d=o(e,t,g);return l.EditorState.push(e,d,"adjust-depth")}Object.defineProperty(t,"__esModule",{value:!0}),t.isListBlock=r,t.changeDepth=i;var l=n(0),c=n(1);},function(e,t,n){e.exports=n(4);},function(e,t,n){var r=n(5),o=n(1),i=n(7),l=function(e){return e&&e.__esModule?e:{default:e}}(i),c=n(2);e.exports={getSelectedBlocksMap:o.getSelectedBlocksMap,getSelectedBlocksList:o.getSelectedBlocksList,getSelectedBlock:o.getSelectedBlock,getBlockBeforeSelectedBlock:o.getBlockBeforeSelectedBlock,getAllBlocks:o.getAllBlocks,getSelectedBlocksType:o.getSelectedBlocksType,removeSelectedBlocksStyle:o.removeSelectedBlocksStyle,getSelectionText:o.getSelectionText,addLineBreakRemovingSelection:o.addLineBreakRemovingSelection,insertNewUnstyledBlock:o.insertNewUnstyledBlock,clearEditorContent:o.clearEditorContent,setBlockData:o.setBlockData,getSelectedBlocksMetadata:o.getSelectedBlocksMetadata,blockRenderMap:o.blockRenderMap,getEntityRange:r.getEntityRange,getCustomStyleMap:r.getCustomStyleMap,toggleCustomInlineStyle:r.toggleCustomInlineStyle,getSelectionEntity:r.getSelectionEntity,extractInlineStyle:r.extractInlineStyle,removeAllInlineStyles:r.removeAllInlineStyles,getSelectionInlineStyle:r.getSelectionInlineStyle,getSelectionCustomInlineStyle:r.getSelectionCustomInlineStyle,handleNewLine:l.default,isListBlock:c.isListBlock,changeDepth:c.changeDepth};},function(e,t,n){function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e){var t=e.getSelection();if(t.isCollapsed()){var n={},r=e.getCurrentInlineStyle().toList().toJS();if(r)return ["BOLD","ITALIC","UNDERLINE","STRIKETHROUGH","CODE","SUPERSCRIPT","SUBSCRIPT"].forEach(function(e){n[e]=r.indexOf(e)>=0;}),n}var o=t.getStartOffset(),i=t.getEndOffset(),l=(0, p.getSelectedBlocksList)(e);if(l.size>0){var c=function(){for(var e={BOLD:!0,ITALIC:!0,UNDERLINE:!0,STRIKETHROUGH:!0,CODE:!0,SUPERSCRIPT:!0,SUBSCRIPT:!0},t=0;t<l.size;t+=1){var n=0===t?o:0,r=t===l.size-1?i:l.get(t).getText().length;n===r&&0===n?(n=1,r=2):n===r&&(n-=1);for(var c=n;c<r;c+=1)!function(n){var r=l.get(t).getInlineStyleAt(n);["BOLD","ITALIC","UNDERLINE","STRIKETHROUGH","CODE","SUPERSCRIPT","SUBSCRIPT"].forEach(function(t){e[t]=e[t]&&r.get(t)===t;});}(c);}return {v:e}}();if("object"===(void 0===c?"undefined":S(c)))return c.v}return {}}function i(e){var t=void 0,n=e.getSelection(),r=n.getStartOffset(),o=n.getEndOffset();r===o&&0===r?o=1:r===o&&(r-=1);for(var i=(0, p.getSelectedBlock)(e),l=r;l<o;l+=1){var c=i.getEntityAt(l);if(!c){t=void 0;break}if(l===r)t=c;else if(t!==c){t=void 0;break}}return t}function l(e,t){var n=(0, p.getSelectedBlock)(e),r=void 0;return n.findEntityRanges(function(e){return e.get("entity")===t},function(e,t){r={start:e,end:t,text:n.get("text").slice(e,t)};}),r}function c(e,t,n){var r=e.getSelection(),o=Object.keys(v[t]).reduce(function(e,t){return y.Modifier.removeInlineStyle(e,r,t)},e.getCurrentContent()),i=y.EditorState.push(e,o,"changeinline-style"),l=e.getCurrentInlineStyle();if(r.isCollapsed()&&(i=l.reduce(function(e,t){return y.RichUtils.toggleInlineStyle(e,t)},i)),"SUPERSCRIPT"===t||"SUBSCRIPT"==t)l.has(n)||(i=y.RichUtils.toggleInlineStyle(i,n));else{var c="bgcolor"===t?"backgroundColor":t;l.has(c+"-"+n)||(i=y.RichUtils.toggleInlineStyle(i,t.toLowerCase()+"-"+n),k(t,c,n));}return i}function a(e){if(e){e.getCurrentContent().getBlockMap().map(function(e){return e.get("characterList")}).toList().flatten().forEach(function(e){e&&0===e.indexOf("color-")?k("color","color",e.substr(6)):e&&0===e.indexOf("bgcolor-")?k("bgcolor","backgroundColor",e.substr(8)):e&&0===e.indexOf("fontsize-")?k("fontSize","fontSize",+e.substr(9)):e&&0===e.indexOf("fontfamily-")&&k("fontFamily","fontFamily",e.substr(11));});}}function f(e,t,n){var r=e.getInlineStyleAt(n).toList(),o=r.filter(function(e){return e.startsWith(t.toLowerCase())});if(o&&o.size>0)return o.get(0)}function u(e,t){var n=e.getCurrentInlineStyle().toList(),r=n.filter(function(e){return e.startsWith(t.toLowerCase())});if(r&&r.size>0)return r.get(0)}function s(e,t){if(e&&t&&t.length>0){var n=function(){var n=e.getSelection(),r={};if(n.isCollapsed())return t.forEach(function(t){r[t]=u(e,t);}),{v:r};var o=n.getStartOffset(),i=n.getEndOffset(),l=(0, p.getSelectedBlocksList)(e);if(l.size>0){for(var c=0;c<l.size;c+=1)!function(e){var n=0===e?o:0,c=e===l.size-1?i:l.get(e).getText().length;n===c&&0===n?(n=1,c=2):n===c&&(n-=1);for(var a=n;a<c;a+=1)!function(o){o===n?t.forEach(function(t){r[t]=f(l.get(e),t,o);}):t.forEach(function(t){r[t]&&r[t]!==f(l.get(e),t,o)&&(r[t]=void 0);});}(a);}(c);return {v:r}}}();if("object"===(void 0===n?"undefined":S(n)))return n.v}return {}}function g(e){var t=e.getCurrentInlineStyle(),n=e.getCurrentContent();return t.forEach(function(t){n=y.Modifier.removeInlineStyle(n,e.getSelection(),t);}),y.EditorState.push(e,n,"change-inline-style")}Object.defineProperty(t,"__esModule",{value:!0}),t.getCustomStyleMap=void 0;var d=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r]);}return e},S="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};t.getSelectionInlineStyle=o,t.getSelectionEntity=i,t.getEntityRange=l,t.toggleCustomInlineStyle=c,t.extractInlineStyle=a,t.getSelectionCustomInlineStyle=s,t.removeAllInlineStyles=g;var y=n(0),p=n(1),v={color:{},bgcolor:{},fontSize:{},fontFamily:{},CODE:{fontFamily:"monospace",wordWrap:"break-word",background:"#f1f1f1",borderRadius:3,padding:"1px 3px"},SUPERSCRIPT:{fontSize:11,position:"relative",top:-8,display:"inline-flex"},SUBSCRIPT:{fontSize:11,position:"relative",bottom:-8,display:"inline-flex"}},k=function(e,t,n){v[e][e.toLowerCase()+"-"+n]=r({},""+t,n);};t.getCustomStyleMap=function(){return d({},v.color,v.bgcolor,v.fontSize,v.fontFamily,{CODE:v.CODE,SUPERSCRIPT:v.SUPERSCRIPT,SUBSCRIPT:v.SUBSCRIPT})};},function(e,n){e.exports=t;},function(e,t,n){function r(e){var t=e.getSelection();if(t.isCollapsed()){var n=e.getCurrentContent(),r=t.getStartKey(),o=n.getBlockForKey(r);if(!(0, a.isListBlock)(o)&&"unstyled"!==o.getType()&&o.getLength()===t.getStartOffset())return (0, c.insertNewUnstyledBlock)(e);if((0, a.isListBlock)(o)&&0===o.getLength()){var i=o.getDepth();if(0===i)return (0, c.removeSelectedBlocksStyle)(e);if(i>0)return (0, a.changeDepth)(e,-1,i)}}}function o(e){return 13===e.which&&(e.getModifierState("Shift")||e.getModifierState("Alt")||e.getModifierState("Control"))}function i(e,t){if(o(t)){return e.getSelection().isCollapsed()?l.RichUtils.insertSoftNewline(e):(0, c.addLineBreakRemovingSelection)(e)}return r(e)}Object.defineProperty(t,"__esModule",{value:!0}),t.default=i;var l=n(0),c=n(1),a=n(2);}])});
  18827. });
  18828. _commonjsHelpers.unwrapExports(draftjsUtils);
  18829. var draftjsUtils_1 = draftjsUtils.draftjsUtils;
  18830. var interopRequireDefault = _commonjsHelpers.createCommonjsModule(function (module) {
  18831. function _interopRequireDefault(obj) {
  18832. return obj && obj.__esModule ? obj : {
  18833. "default": obj
  18834. };
  18835. }
  18836. module.exports = _interopRequireDefault;
  18837. });
  18838. _commonjsHelpers.unwrapExports(interopRequireDefault);
  18839. /**
  18840. * Copyright (c) 2013-present, Facebook, Inc.
  18841. *
  18842. * This source code is licensed under the MIT license found in the
  18843. * LICENSE file in the root directory of this source tree.
  18844. */
  18845. /**
  18846. * Use invariant() to assert state which your program assumes to be true.
  18847. *
  18848. * Provide sprintf-style format (only %s is supported) and arguments
  18849. * to provide information about what broke and what you were
  18850. * expecting.
  18851. *
  18852. * The invariant message will be stripped in production, but the invariant
  18853. * will remain to ensure logic does not differ in production.
  18854. */
  18855. var invariant$1 = function(condition, format, a, b, c, d, e, f) {
  18856. if (process.env.NODE_ENV !== 'production') {
  18857. if (format === undefined) {
  18858. throw new Error('invariant requires an error message argument');
  18859. }
  18860. }
  18861. if (!condition) {
  18862. var error;
  18863. if (format === undefined) {
  18864. error = new Error(
  18865. 'Minified exception occurred; use the non-minified dev environment ' +
  18866. 'for the full error message and additional helpful warnings.'
  18867. );
  18868. } else {
  18869. var args = [a, b, c, d, e, f];
  18870. var argIndex = 0;
  18871. error = new Error(
  18872. format.replace(/%s/g, function() { return args[argIndex++]; })
  18873. );
  18874. error.name = 'Invariant Violation';
  18875. }
  18876. error.framesToPop = 1; // we don't care about invariant's own frame
  18877. throw error;
  18878. }
  18879. };
  18880. var browser = invariant$1;
  18881. function _arrayWithoutHoles(arr) {
  18882. if (Array.isArray(arr)) {
  18883. for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {
  18884. arr2[i] = arr[i];
  18885. }
  18886. return arr2;
  18887. }
  18888. }
  18889. var arrayWithoutHoles = _arrayWithoutHoles;
  18890. function _iterableToArray(iter) {
  18891. if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
  18892. }
  18893. var iterableToArray = _iterableToArray;
  18894. function _nonIterableSpread() {
  18895. throw new TypeError("Invalid attempt to spread non-iterable instance");
  18896. }
  18897. var nonIterableSpread = _nonIterableSpread;
  18898. function _toConsumableArray(arr) {
  18899. return arrayWithoutHoles(arr) || iterableToArray(arr) || nonIterableSpread();
  18900. }
  18901. var toConsumableArray = _toConsumableArray;
  18902. var updateMutation_1 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
  18903. Object.defineProperty(exports, "__esModule", {
  18904. value: true
  18905. });
  18906. exports["default"] = updateMutation;
  18907. function updateMutation(mutation, originalOffset, originalLength, newLength, prefixLength, suffixLength) {
  18908. // three cases we can reasonably adjust - disjoint mutations that
  18909. // happen later on where the offset will need to be changed,
  18910. // mutations that completely contain the new one where we can adjust
  18911. // the length, and mutations that occur partially within the new one.
  18912. var lengthDiff = newLength - originalLength;
  18913. var mutationAfterChange = originalOffset + originalLength <= mutation.offset;
  18914. if (mutationAfterChange) {
  18915. return Object.assign({}, mutation, {
  18916. offset: mutation.offset + lengthDiff
  18917. });
  18918. }
  18919. var mutationContainsChange = originalOffset >= mutation.offset && originalOffset + originalLength <= mutation.offset + mutation.length;
  18920. if (mutationContainsChange) {
  18921. return Object.assign({}, mutation, {
  18922. length: mutation.length + lengthDiff
  18923. });
  18924. }
  18925. var mutationWithinPrefixChange = mutation.offset >= originalOffset && mutation.offset + mutation.length <= originalOffset + originalLength && prefixLength > 0;
  18926. if (mutationWithinPrefixChange) {
  18927. return Object.assign({}, mutation, {
  18928. offset: mutation.offset + prefixLength
  18929. });
  18930. }
  18931. var mutationContainsPrefix = mutation.offset < originalOffset && mutation.offset + mutation.length <= originalOffset + originalLength && mutation.offset + mutation.length > originalOffset && prefixLength > 0;
  18932. if (mutationContainsPrefix) {
  18933. return [Object.assign({}, mutation, {
  18934. length: originalOffset - mutation.offset
  18935. }), Object.assign({}, mutation, {
  18936. offset: originalOffset + prefixLength,
  18937. length: mutation.offset - originalOffset + mutation.length
  18938. })];
  18939. }
  18940. var mutationContainsSuffix = mutation.offset >= originalOffset && mutation.offset + mutation.length > originalOffset + originalLength && originalOffset + originalLength > mutation.offset && suffixLength > 0;
  18941. if (mutationContainsSuffix) {
  18942. return [Object.assign({}, mutation, {
  18943. offset: mutation.offset + prefixLength,
  18944. length: originalOffset + originalLength - mutation.offset
  18945. }), Object.assign({}, mutation, {
  18946. offset: originalOffset + originalLength + prefixLength + suffixLength,
  18947. length: mutation.offset + mutation.length - (originalOffset + originalLength)
  18948. })];
  18949. }
  18950. return mutation;
  18951. }
  18952. });
  18953. _commonjsHelpers.unwrapExports(updateMutation_1);
  18954. var rangeSort = _commonjsHelpers.createCommonjsModule(function (module, exports) {
  18955. Object.defineProperty(exports, "__esModule", {
  18956. value: true
  18957. });
  18958. exports["default"] = void 0;
  18959. var _default = function _default(r1, r2) {
  18960. if (r1.offset === r2.offset) {
  18961. return r2.length - r1.length;
  18962. }
  18963. return r1.offset - r2.offset;
  18964. };
  18965. exports["default"] = _default;
  18966. });
  18967. _commonjsHelpers.unwrapExports(rangeSort);
  18968. var encodeBlock = _commonjsHelpers.createCommonjsModule(function (module, exports) {
  18969. Object.defineProperty(exports, "__esModule", {
  18970. value: true
  18971. });
  18972. exports["default"] = void 0;
  18973. var _toConsumableArray2 = interopRequireDefault(toConsumableArray);
  18974. var _updateMutation = interopRequireDefault(updateMutation_1);
  18975. var _rangeSort = interopRequireDefault(rangeSort);
  18976. var ENTITY_MAP = {
  18977. '&': '&amp;',
  18978. '<': '&lt;',
  18979. '>': '&gt;',
  18980. '"': '&quot;',
  18981. "'": '&#x27;',
  18982. '`': '&#x60;',
  18983. '\n': '<br/>'
  18984. };
  18985. var _default = function _default(block) {
  18986. var blockText = (0, _toConsumableArray2["default"])(block.text);
  18987. var entities = block.entityRanges.sort(_rangeSort["default"]);
  18988. var styles = block.inlineStyleRanges.sort(_rangeSort["default"]);
  18989. var resultText = '';
  18990. var _loop = function _loop(index) {
  18991. var _char = blockText[index];
  18992. if (ENTITY_MAP[_char] !== undefined) {
  18993. var encoded = ENTITY_MAP[_char];
  18994. var resultIndex = (0, _toConsumableArray2["default"])(resultText).length;
  18995. resultText += encoded;
  18996. var updateForChar = function updateForChar(mutation) {
  18997. return (0, _updateMutation["default"])(mutation, resultIndex, _char.length, encoded.length, 0, 0);
  18998. };
  18999. entities = entities.map(updateForChar);
  19000. styles = styles.map(updateForChar);
  19001. } else {
  19002. resultText += _char;
  19003. }
  19004. };
  19005. for (var index = 0; index < blockText.length; index++) {
  19006. _loop(index);
  19007. }
  19008. return Object.assign({}, block, {
  19009. text: resultText,
  19010. inlineStyleRanges: styles,
  19011. entityRanges: entities
  19012. });
  19013. };
  19014. exports["default"] = _default;
  19015. });
  19016. _commonjsHelpers.unwrapExports(encodeBlock);
  19017. var _typeof_1 = _commonjsHelpers.createCommonjsModule(function (module) {
  19018. function _typeof(obj) {
  19019. "@babel/helpers - typeof";
  19020. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  19021. module.exports = _typeof = function _typeof(obj) {
  19022. return typeof obj;
  19023. };
  19024. } else {
  19025. module.exports = _typeof = function _typeof(obj) {
  19026. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  19027. };
  19028. }
  19029. return _typeof(obj);
  19030. }
  19031. module.exports = _typeof;
  19032. });
  19033. var splitReactElement_1 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
  19034. Object.defineProperty(exports, "__esModule", {
  19035. value: true
  19036. });
  19037. exports["default"] = splitReactElement;
  19038. var _invariant = interopRequireDefault(browser);
  19039. var _react = interopRequireDefault(React__default);
  19040. var _server = interopRequireDefault(server);
  19041. // see http://w3c.github.io/html/syntax.html#writing-html-documents-elements
  19042. var VOID_TAGS = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr'];
  19043. function splitReactElement(element) {
  19044. if (VOID_TAGS.indexOf(element.type) !== -1) {
  19045. return _server["default"].renderToStaticMarkup(element);
  19046. }
  19047. var tags = _server["default"].renderToStaticMarkup(_react["default"].cloneElement(element, {}, '\r')).split('\r');
  19048. (0, _invariant["default"])(tags.length > 1, "convertToHTML: Element of type ".concat(element.type, " must render children"));
  19049. (0, _invariant["default"])(tags.length < 3, "convertToHTML: Element of type ".concat(element.type, " cannot use carriage return character"));
  19050. return {
  19051. start: tags[0],
  19052. end: tags[1]
  19053. };
  19054. }
  19055. });
  19056. _commonjsHelpers.unwrapExports(splitReactElement_1);
  19057. var getElementHTML_1 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
  19058. Object.defineProperty(exports, "__esModule", {
  19059. value: true
  19060. });
  19061. exports["default"] = getElementHTML;
  19062. var _typeof2 = interopRequireDefault(_typeof_1);
  19063. var _invariant = interopRequireDefault(browser);
  19064. var _react = interopRequireDefault(React__default);
  19065. var _server = interopRequireDefault(server);
  19066. var _splitReactElement = interopRequireDefault(splitReactElement_1);
  19067. function hasChildren(element) {
  19068. return _react["default"].isValidElement(element) && _react["default"].Children.count(element.props.children) > 0;
  19069. }
  19070. function getElementHTML(element) {
  19071. var text = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  19072. if (element === undefined || element === null) {
  19073. return element;
  19074. }
  19075. if (typeof element === 'string') {
  19076. return element;
  19077. }
  19078. if (_react["default"].isValidElement(element)) {
  19079. if (hasChildren(element)) {
  19080. return _server["default"].renderToStaticMarkup(element);
  19081. }
  19082. var tags = (0, _splitReactElement["default"])(element);
  19083. if (text !== null && (0, _typeof2["default"])(tags) === 'object') {
  19084. var start = tags.start,
  19085. end = tags.end;
  19086. return start + text + end;
  19087. }
  19088. return tags;
  19089. }
  19090. (0, _invariant["default"])(Object.prototype.hasOwnProperty.call(element, 'start') && Object.prototype.hasOwnProperty.call(element, 'end'), 'convertToHTML: received conversion data without either an HTML string, ReactElement or an object with start/end tags');
  19091. if (text !== null) {
  19092. var _start = element.start,
  19093. _end = element.end;
  19094. return _start + text + _end;
  19095. }
  19096. return element;
  19097. }
  19098. });
  19099. _commonjsHelpers.unwrapExports(getElementHTML_1);
  19100. var getElementTagLength_1 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
  19101. Object.defineProperty(exports, "__esModule", {
  19102. value: true
  19103. });
  19104. exports["default"] = void 0;
  19105. var _typeof2 = interopRequireDefault(_typeof_1);
  19106. var _react = interopRequireDefault(React__default);
  19107. var _splitReactElement = interopRequireDefault(splitReactElement_1);
  19108. var getElementTagLength = function getElementTagLength(element) {
  19109. var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'start';
  19110. if (_react["default"].isValidElement(element)) {
  19111. var splitElement = (0, _splitReactElement["default"])(element);
  19112. if (typeof splitElement === 'string') {
  19113. return 0;
  19114. }
  19115. var length = splitElement[type].length;
  19116. var child = _react["default"].Children.toArray(element.props.children)[0];
  19117. return length + (child && _react["default"].isValidElement(child) ? getElementTagLength(child, type) : 0);
  19118. }
  19119. if ((0, _typeof2["default"])(element) === 'object') {
  19120. return element[type] ? element[type].length : 0;
  19121. }
  19122. return 0;
  19123. };
  19124. var _default = getElementTagLength;
  19125. exports["default"] = _default;
  19126. });
  19127. _commonjsHelpers.unwrapExports(getElementTagLength_1);
  19128. var blockEntities = _commonjsHelpers.createCommonjsModule(function (module, exports) {
  19129. Object.defineProperty(exports, "__esModule", {
  19130. value: true
  19131. });
  19132. exports["default"] = void 0;
  19133. var _toConsumableArray2 = interopRequireDefault(toConsumableArray);
  19134. var _updateMutation = interopRequireDefault(updateMutation_1);
  19135. var _rangeSort = interopRequireDefault(rangeSort);
  19136. var _getElementHTML = interopRequireDefault(getElementHTML_1);
  19137. var _getElementTagLength = interopRequireDefault(getElementTagLength_1);
  19138. var converter = function converter() {
  19139. var originalText = arguments.length > 1 ? arguments[1] : undefined;
  19140. return originalText;
  19141. };
  19142. var _default = function _default(block, entityMap) {
  19143. var entityConverter = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : converter;
  19144. var resultText = (0, _toConsumableArray2["default"])(block.text);
  19145. var getEntityHTML = entityConverter;
  19146. if (entityConverter.__isMiddleware) {
  19147. getEntityHTML = entityConverter(converter);
  19148. }
  19149. if (Object.prototype.hasOwnProperty.call(block, 'entityRanges') && block.entityRanges.length > 0) {
  19150. var entities = block.entityRanges.sort(_rangeSort["default"]);
  19151. var styles = block.inlineStyleRanges;
  19152. var _loop = function _loop(index) {
  19153. var entityRange = entities[index];
  19154. var entity = entityMap[entityRange.key];
  19155. var originalText = resultText.slice(entityRange.offset, entityRange.offset + entityRange.length).join('');
  19156. var entityHTML = getEntityHTML(entity, originalText);
  19157. var converted = (0, _toConsumableArray2["default"])((0, _getElementHTML["default"])(entityHTML, originalText) || originalText);
  19158. var prefixLength = (0, _getElementTagLength["default"])(entityHTML, 'start');
  19159. var suffixLength = (0, _getElementTagLength["default"])(entityHTML, 'end');
  19160. var updateLaterMutation = function updateLaterMutation(mutation, mutationIndex) {
  19161. if (mutationIndex > index || Object.prototype.hasOwnProperty.call(mutation, 'style')) {
  19162. return (0, _updateMutation["default"])(mutation, entityRange.offset, entityRange.length, converted.length, prefixLength, suffixLength);
  19163. }
  19164. return mutation;
  19165. };
  19166. var updateLaterMutations = function updateLaterMutations(mutationList) {
  19167. return mutationList.reduce(function (acc, mutation, mutationIndex) {
  19168. var updatedMutation = updateLaterMutation(mutation, mutationIndex);
  19169. if (Array.isArray(updatedMutation)) {
  19170. return acc.concat(updatedMutation);
  19171. }
  19172. return acc.concat([updatedMutation]);
  19173. }, []);
  19174. };
  19175. entities = updateLaterMutations(entities);
  19176. styles = updateLaterMutations(styles);
  19177. resultText = [].concat((0, _toConsumableArray2["default"])(resultText.slice(0, entityRange.offset)), (0, _toConsumableArray2["default"])(converted), (0, _toConsumableArray2["default"])(resultText.slice(entityRange.offset + entityRange.length)));
  19178. };
  19179. for (var index = 0; index < entities.length; index++) {
  19180. _loop(index);
  19181. }
  19182. return Object.assign({}, block, {
  19183. text: resultText.join(''),
  19184. inlineStyleRanges: styles,
  19185. entityRanges: entities
  19186. });
  19187. }
  19188. return block;
  19189. };
  19190. exports["default"] = _default;
  19191. });
  19192. _commonjsHelpers.unwrapExports(blockEntities);
  19193. var styleObjectFunction = _commonjsHelpers.createCommonjsModule(function (module, exports) {
  19194. Object.defineProperty(exports, "__esModule", {
  19195. value: true
  19196. });
  19197. exports["default"] = void 0;
  19198. var _default = function _default(object) {
  19199. return function (style) {
  19200. if (typeof object === 'function') {
  19201. return object(style);
  19202. }
  19203. return object[style];
  19204. };
  19205. };
  19206. exports["default"] = _default;
  19207. });
  19208. _commonjsHelpers.unwrapExports(styleObjectFunction);
  19209. var accumulateFunction = _commonjsHelpers.createCommonjsModule(function (module, exports) {
  19210. Object.defineProperty(exports, "__esModule", {
  19211. value: true
  19212. });
  19213. exports["default"] = void 0;
  19214. var _default = function _default(newFn, rest) {
  19215. return function () {
  19216. var newResult = newFn.apply(void 0, arguments);
  19217. if (newResult !== undefined && newResult !== null) {
  19218. return newResult;
  19219. }
  19220. return rest.apply(void 0, arguments);
  19221. };
  19222. };
  19223. exports["default"] = _default;
  19224. });
  19225. _commonjsHelpers.unwrapExports(accumulateFunction);
  19226. var defaultInlineHTML_1 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
  19227. Object.defineProperty(exports, "__esModule", {
  19228. value: true
  19229. });
  19230. exports["default"] = defaultInlineHTML;
  19231. var _react = interopRequireDefault(React__default);
  19232. function defaultInlineHTML(style) {
  19233. switch (style) {
  19234. case 'BOLD':
  19235. return _react["default"].createElement("strong", null);
  19236. case 'ITALIC':
  19237. return _react["default"].createElement("em", null);
  19238. case 'UNDERLINE':
  19239. return _react["default"].createElement("u", null);
  19240. case 'CODE':
  19241. return _react["default"].createElement("code", null);
  19242. default:
  19243. return {
  19244. start: '',
  19245. end: ''
  19246. };
  19247. }
  19248. }
  19249. });
  19250. _commonjsHelpers.unwrapExports(defaultInlineHTML_1);
  19251. var blockInlineStyles = _commonjsHelpers.createCommonjsModule(function (module, exports) {
  19252. Object.defineProperty(exports, "__esModule", {
  19253. value: true
  19254. });
  19255. exports["default"] = void 0;
  19256. var _toConsumableArray2 = interopRequireDefault(toConsumableArray);
  19257. var _invariant = interopRequireDefault(browser);
  19258. var _styleObjectFunction = interopRequireDefault(styleObjectFunction);
  19259. var _accumulateFunction = interopRequireDefault(accumulateFunction);
  19260. var _getElementHTML = interopRequireDefault(getElementHTML_1);
  19261. var _rangeSort = interopRequireDefault(rangeSort);
  19262. var _defaultInlineHTML = interopRequireDefault(defaultInlineHTML_1);
  19263. var subtractStyles = function subtractStyles(original, toRemove) {
  19264. return original.filter(function (el) {
  19265. return !toRemove.some(function (elToRemove) {
  19266. return elToRemove.style === el.style;
  19267. });
  19268. });
  19269. };
  19270. var popEndingStyles = function popEndingStyles(styleStack, endingStyles) {
  19271. return endingStyles.reduceRight(function (stack, style) {
  19272. var styleToRemove = stack[stack.length - 1];
  19273. (0, _invariant["default"])(styleToRemove.style === style.style, "Style ".concat(styleToRemove.style, " to be removed doesn't match expected ").concat(style.style));
  19274. return stack.slice(0, -1);
  19275. }, styleStack);
  19276. };
  19277. var characterStyles = function characterStyles(offset, ranges) {
  19278. return ranges.filter(function (range) {
  19279. return offset >= range.offset && offset < range.offset + range.length;
  19280. });
  19281. };
  19282. var rangeIsSubset = function rangeIsSubset(firstRange, secondRange) {
  19283. // returns true if the second range is a subset of the first
  19284. var secondStartWithinFirst = firstRange.offset <= secondRange.offset;
  19285. var secondEndWithinFirst = firstRange.offset + firstRange.length >= secondRange.offset + secondRange.length;
  19286. return secondStartWithinFirst && secondEndWithinFirst;
  19287. };
  19288. var latestStyleLast = function latestStyleLast(s1, s2) {
  19289. // make sure longer-lasting styles are added first
  19290. var s2endIndex = s2.offset + s2.length;
  19291. var s1endIndex = s1.offset + s1.length;
  19292. return s2endIndex - s1endIndex;
  19293. };
  19294. var getStylesToReset = function getStylesToReset(remainingStyles, newStyles) {
  19295. var i = 0;
  19296. while (i < remainingStyles.length) {
  19297. if (newStyles.every(rangeIsSubset.bind(null, remainingStyles[i]))) {
  19298. i++;
  19299. } else {
  19300. return remainingStyles.slice(i);
  19301. }
  19302. }
  19303. return [];
  19304. };
  19305. var appendStartMarkup = function appendStartMarkup(inlineHTML, string, styleRange) {
  19306. return string + (0, _getElementHTML["default"])(inlineHTML(styleRange.style)).start;
  19307. };
  19308. var prependEndMarkup = function prependEndMarkup(inlineHTML, string, styleRange) {
  19309. return (0, _getElementHTML["default"])(inlineHTML(styleRange.style)).end + string;
  19310. };
  19311. var defaultCustomInlineHTML = function defaultCustomInlineHTML(next) {
  19312. return function (style) {
  19313. return next(style);
  19314. };
  19315. };
  19316. defaultCustomInlineHTML.__isMiddleware = true;
  19317. var _default = function _default(rawBlock) {
  19318. var customInlineHTML = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultCustomInlineHTML;
  19319. (0, _invariant["default"])(rawBlock !== null && rawBlock !== undefined, 'Expected raw block to be non-null');
  19320. var inlineHTML;
  19321. if (customInlineHTML.__isMiddleware === true) {
  19322. inlineHTML = customInlineHTML(_defaultInlineHTML["default"]);
  19323. } else {
  19324. inlineHTML = (0, _accumulateFunction["default"])((0, _styleObjectFunction["default"])(customInlineHTML), (0, _styleObjectFunction["default"])(_defaultInlineHTML["default"]));
  19325. }
  19326. var result = '';
  19327. var styleStack = [];
  19328. var sortedRanges = rawBlock.inlineStyleRanges.sort(_rangeSort["default"]);
  19329. var originalTextArray = (0, _toConsumableArray2["default"])(rawBlock.text);
  19330. for (var i = 0; i < originalTextArray.length; i++) {
  19331. var styles = characterStyles(i, sortedRanges);
  19332. var endingStyles = subtractStyles(styleStack, styles);
  19333. var newStyles = subtractStyles(styles, styleStack);
  19334. var remainingStyles = subtractStyles(styleStack, endingStyles); // reset styles: look for any already existing styles that will need to
  19335. // end before styles that are being added on this character. to solve this
  19336. // close out those current tags and all nested children,
  19337. // then open new ones nested within the new styles.
  19338. var resetStyles = getStylesToReset(remainingStyles, newStyles);
  19339. var openingStyles = resetStyles.concat(newStyles).sort(latestStyleLast);
  19340. var openingStyleTags = openingStyles.reduce(appendStartMarkup.bind(null, inlineHTML), '');
  19341. var endingStyleTags = endingStyles.concat(resetStyles).reduce(prependEndMarkup.bind(null, inlineHTML), '');
  19342. result += endingStyleTags + openingStyleTags + originalTextArray[i];
  19343. styleStack = popEndingStyles(styleStack, resetStyles.concat(endingStyles));
  19344. styleStack = styleStack.concat(openingStyles);
  19345. (0, _invariant["default"])(styleStack.length === styles.length, "Character ".concat(i, ": ").concat(styleStack.length - styles.length, " styles left on stack that should no longer be there"));
  19346. }
  19347. result = styleStack.reduceRight(function (res, openStyle) {
  19348. return res + (0, _getElementHTML["default"])(inlineHTML(openStyle.style)).end;
  19349. }, result);
  19350. return result;
  19351. };
  19352. exports["default"] = _default;
  19353. });
  19354. _commonjsHelpers.unwrapExports(blockInlineStyles);
  19355. var blockTypeObjectFunction = _commonjsHelpers.createCommonjsModule(function (module, exports) {
  19356. Object.defineProperty(exports, "__esModule", {
  19357. value: true
  19358. });
  19359. exports["default"] = void 0;
  19360. var _default = function _default(typeObject) {
  19361. return function (block) {
  19362. if (typeof typeObject === 'function') {
  19363. // handle case where typeObject is already a function
  19364. return typeObject(block);
  19365. }
  19366. return typeObject[block.type];
  19367. };
  19368. };
  19369. exports["default"] = _default;
  19370. });
  19371. _commonjsHelpers.unwrapExports(blockTypeObjectFunction);
  19372. var getBlockTags_1 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
  19373. Object.defineProperty(exports, "__esModule", {
  19374. value: true
  19375. });
  19376. exports["default"] = getBlockTags;
  19377. var _invariant = interopRequireDefault(browser);
  19378. var _react = interopRequireDefault(React__default);
  19379. var _server = interopRequireDefault(server);
  19380. var _splitReactElement = interopRequireDefault(splitReactElement_1);
  19381. function hasChildren(element) {
  19382. return _react["default"].isValidElement(element) && _react["default"].Children.count(element.props.children) > 0;
  19383. }
  19384. function getBlockTags(blockHTML) {
  19385. (0, _invariant["default"])(blockHTML !== null && blockHTML !== undefined, 'Expected block HTML value to be non-null');
  19386. if (typeof blockHTML === 'string') {
  19387. return blockHTML;
  19388. }
  19389. if (_react["default"].isValidElement(blockHTML)) {
  19390. if (hasChildren(blockHTML)) {
  19391. return _server["default"].renderToStaticMarkup(blockHTML);
  19392. }
  19393. return (0, _splitReactElement["default"])(blockHTML);
  19394. }
  19395. if (Object.prototype.hasOwnProperty.call(blockHTML, 'element') && _react["default"].isValidElement(blockHTML.element)) {
  19396. return Object.assign({}, blockHTML, (0, _splitReactElement["default"])(blockHTML.element));
  19397. }
  19398. (0, _invariant["default"])(Object.prototype.hasOwnProperty.call(blockHTML, 'start') && Object.prototype.hasOwnProperty.call(blockHTML, 'end'), 'convertToHTML: received block information without either a ReactElement or an object with start/end tags');
  19399. return blockHTML;
  19400. }
  19401. });
  19402. _commonjsHelpers.unwrapExports(getBlockTags_1);
  19403. var getNestedBlockTags_1 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
  19404. Object.defineProperty(exports, "__esModule", {
  19405. value: true
  19406. });
  19407. exports["default"] = getNestedBlockTags;
  19408. var _invariant = interopRequireDefault(browser);
  19409. var _react = interopRequireDefault(React__default);
  19410. var _splitReactElement2 = interopRequireDefault(splitReactElement_1);
  19411. function getNestedBlockTags(blockHTML) {
  19412. (0, _invariant["default"])(blockHTML !== null && blockHTML !== undefined, 'Expected block HTML value to be non-null');
  19413. if (_react["default"].isValidElement(blockHTML.nest)) {
  19414. var _splitReactElement = (0, _splitReactElement2["default"])(blockHTML.nest),
  19415. start = _splitReactElement.start,
  19416. end = _splitReactElement.end;
  19417. return Object.assign({}, blockHTML, {
  19418. nestStart: start,
  19419. nestEnd: end
  19420. });
  19421. }
  19422. (0, _invariant["default"])(Object.prototype.hasOwnProperty.call(blockHTML, 'nestStart') && Object.prototype.hasOwnProperty.call(blockHTML, 'nestEnd'), 'convertToHTML: received block information without either a ReactElement or an object with start/end tags');
  19423. return blockHTML;
  19424. }
  19425. });
  19426. _commonjsHelpers.unwrapExports(getNestedBlockTags_1);
  19427. var defaultBlockHTML = _commonjsHelpers.createCommonjsModule(function (module, exports) {
  19428. Object.defineProperty(exports, "__esModule", {
  19429. value: true
  19430. });
  19431. exports["default"] = void 0;
  19432. var _react = interopRequireDefault(React__default);
  19433. var _default = {
  19434. unstyled: _react["default"].createElement("p", null),
  19435. paragraph: _react["default"].createElement("p", null),
  19436. 'header-one': _react["default"].createElement("h1", null),
  19437. 'header-two': _react["default"].createElement("h2", null),
  19438. 'header-three': _react["default"].createElement("h3", null),
  19439. 'header-four': _react["default"].createElement("h4", null),
  19440. 'header-five': _react["default"].createElement("h5", null),
  19441. 'header-six': _react["default"].createElement("h6", null),
  19442. blockquote: _react["default"].createElement("blockquote", null),
  19443. 'unordered-list-item': {
  19444. element: _react["default"].createElement("li", null),
  19445. nest: _react["default"].createElement("ul", null)
  19446. },
  19447. 'ordered-list-item': {
  19448. element: _react["default"].createElement("li", null),
  19449. nest: _react["default"].createElement("ol", null)
  19450. },
  19451. media: _react["default"].createElement("figure", null),
  19452. atomic: _react["default"].createElement("figure", null)
  19453. };
  19454. exports["default"] = _default;
  19455. });
  19456. _commonjsHelpers.unwrapExports(defaultBlockHTML);
  19457. var convertToHTML_1 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
  19458. Object.defineProperty(exports, "__esModule", {
  19459. value: true
  19460. });
  19461. exports["default"] = void 0;
  19462. var _invariant = interopRequireDefault(browser);
  19463. var _react = interopRequireDefault(React__default);
  19464. var _server = interopRequireDefault(server);
  19465. var _encodeBlock = interopRequireDefault(encodeBlock);
  19466. var _blockEntities = interopRequireDefault(blockEntities);
  19467. var _blockInlineStyles = interopRequireDefault(blockInlineStyles);
  19468. var _accumulateFunction = interopRequireDefault(accumulateFunction);
  19469. var _blockTypeObjectFunction = interopRequireDefault(blockTypeObjectFunction);
  19470. var _getBlockTags = interopRequireDefault(getBlockTags_1);
  19471. var _getNestedBlockTags = interopRequireDefault(getNestedBlockTags_1);
  19472. var _defaultBlockHTML = interopRequireDefault(defaultBlockHTML);
  19473. // import Immutable from 'immutable'; // eslint-disable-line no-unused-vars
  19474. var defaultEntityToHTML = function defaultEntityToHTML(entity, originalText) {
  19475. return originalText;
  19476. };
  19477. var convertToHTML = function convertToHTML(_ref) {
  19478. var _ref$styleToHTML = _ref.styleToHTML,
  19479. styleToHTML = _ref$styleToHTML === void 0 ? {} : _ref$styleToHTML,
  19480. _ref$blockToHTML = _ref.blockToHTML,
  19481. blockToHTML = _ref$blockToHTML === void 0 ? {} : _ref$blockToHTML,
  19482. _ref$entityToHTML = _ref.entityToHTML,
  19483. entityToHTML = _ref$entityToHTML === void 0 ? defaultEntityToHTML : _ref$entityToHTML;
  19484. return function (contentState) {
  19485. (0, _invariant["default"])(contentState !== null && contentState !== undefined, 'Expected contentState to be non-null');
  19486. var getBlockHTML;
  19487. if (blockToHTML.__isMiddleware === true) {
  19488. getBlockHTML = blockToHTML((0, _blockTypeObjectFunction["default"])(_defaultBlockHTML["default"]));
  19489. } else {
  19490. getBlockHTML = (0, _accumulateFunction["default"])((0, _blockTypeObjectFunction["default"])(blockToHTML), (0, _blockTypeObjectFunction["default"])(_defaultBlockHTML["default"]));
  19491. }
  19492. var rawState = (0, Draft.convertToRaw)(contentState);
  19493. var listStack = [];
  19494. var result = rawState.blocks.map(function (block) {
  19495. var type = block.type,
  19496. depth = block.depth;
  19497. var closeNestTags = '';
  19498. var openNestTags = '';
  19499. var blockHTMLResult = getBlockHTML(block);
  19500. if (!blockHTMLResult) {
  19501. throw new Error("convertToHTML: missing HTML definition for block with type ".concat(block.type));
  19502. }
  19503. if (!blockHTMLResult.nest) {
  19504. // this block can't be nested, so reset all nesting if necessary
  19505. closeNestTags = listStack.reduceRight(function (string, nestedBlock) {
  19506. return string + (0, _getNestedBlockTags["default"])(getBlockHTML(nestedBlock)).nestEnd;
  19507. }, '');
  19508. listStack = [];
  19509. } else {
  19510. while (depth + 1 !== listStack.length || type !== listStack[depth].type) {
  19511. if (depth + 1 === listStack.length) {
  19512. // depth is right but doesn't match type
  19513. var blockToClose = listStack[depth];
  19514. closeNestTags += (0, _getNestedBlockTags["default"])(getBlockHTML(blockToClose)).nestEnd;
  19515. openNestTags += (0, _getNestedBlockTags["default"])(getBlockHTML(block)).nestStart;
  19516. listStack[depth] = block;
  19517. } else if (depth + 1 < listStack.length) {
  19518. var _blockToClose = listStack[listStack.length - 1];
  19519. closeNestTags += (0, _getNestedBlockTags["default"])(getBlockHTML(_blockToClose)).nestEnd;
  19520. listStack = listStack.slice(0, -1);
  19521. } else {
  19522. openNestTags += (0, _getNestedBlockTags["default"])(getBlockHTML(block)).nestStart;
  19523. listStack.push(block);
  19524. }
  19525. }
  19526. }
  19527. var innerHTML = (0, _blockInlineStyles["default"])((0, _blockEntities["default"])((0, _encodeBlock["default"])(block), rawState.entityMap, entityToHTML), styleToHTML);
  19528. var blockHTML = (0, _getBlockTags["default"])(getBlockHTML(block));
  19529. var html;
  19530. if (typeof blockHTML === 'string') {
  19531. html = blockHTML;
  19532. } else {
  19533. html = blockHTML.start + innerHTML + blockHTML.end;
  19534. }
  19535. if (innerHTML.length === 0 && Object.prototype.hasOwnProperty.call(blockHTML, 'empty')) {
  19536. if (_react["default"].isValidElement(blockHTML.empty)) {
  19537. html = _server["default"].renderToStaticMarkup(blockHTML.empty);
  19538. } else {
  19539. html = blockHTML.empty;
  19540. }
  19541. }
  19542. return closeNestTags + openNestTags + html;
  19543. }).join('');
  19544. result = listStack.reduce(function (res, nestBlock) {
  19545. return res + (0, _getNestedBlockTags["default"])(getBlockHTML(nestBlock)).nestEnd;
  19546. }, result);
  19547. return result;
  19548. };
  19549. };
  19550. var _default = function _default() {
  19551. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  19552. args[_key] = arguments[_key];
  19553. }
  19554. if (args.length === 1 && Object.prototype.hasOwnProperty.call(args[0], '_map') && args[0].getBlockMap != null) {
  19555. // skip higher-order function and use defaults
  19556. return convertToHTML({}).apply(void 0, args);
  19557. }
  19558. return convertToHTML.apply(void 0, args);
  19559. };
  19560. exports["default"] = _default;
  19561. });
  19562. _commonjsHelpers.unwrapExports(convertToHTML_1);
  19563. var immutable$2 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
  19564. /**
  19565. * Copyright (c) 2014-2015, Facebook, Inc.
  19566. * All rights reserved.
  19567. *
  19568. * This source code is licensed under the BSD-style license found in the
  19569. * LICENSE file in the root directory of this source tree. An additional grant
  19570. * of patent rights can be found in the PATENTS file in the same directory.
  19571. */
  19572. (function (global, factory) {
  19573. module.exports = factory() ;
  19574. }(_commonjsHelpers.commonjsGlobal, function () {var SLICE$0 = Array.prototype.slice;
  19575. function createClass(ctor, superClass) {
  19576. if (superClass) {
  19577. ctor.prototype = Object.create(superClass.prototype);
  19578. }
  19579. ctor.prototype.constructor = ctor;
  19580. }
  19581. function Iterable(value) {
  19582. return isIterable(value) ? value : Seq(value);
  19583. }
  19584. createClass(KeyedIterable, Iterable);
  19585. function KeyedIterable(value) {
  19586. return isKeyed(value) ? value : KeyedSeq(value);
  19587. }
  19588. createClass(IndexedIterable, Iterable);
  19589. function IndexedIterable(value) {
  19590. return isIndexed(value) ? value : IndexedSeq(value);
  19591. }
  19592. createClass(SetIterable, Iterable);
  19593. function SetIterable(value) {
  19594. return isIterable(value) && !isAssociative(value) ? value : SetSeq(value);
  19595. }
  19596. function isIterable(maybeIterable) {
  19597. return !!(maybeIterable && maybeIterable[IS_ITERABLE_SENTINEL]);
  19598. }
  19599. function isKeyed(maybeKeyed) {
  19600. return !!(maybeKeyed && maybeKeyed[IS_KEYED_SENTINEL]);
  19601. }
  19602. function isIndexed(maybeIndexed) {
  19603. return !!(maybeIndexed && maybeIndexed[IS_INDEXED_SENTINEL]);
  19604. }
  19605. function isAssociative(maybeAssociative) {
  19606. return isKeyed(maybeAssociative) || isIndexed(maybeAssociative);
  19607. }
  19608. function isOrdered(maybeOrdered) {
  19609. return !!(maybeOrdered && maybeOrdered[IS_ORDERED_SENTINEL]);
  19610. }
  19611. Iterable.isIterable = isIterable;
  19612. Iterable.isKeyed = isKeyed;
  19613. Iterable.isIndexed = isIndexed;
  19614. Iterable.isAssociative = isAssociative;
  19615. Iterable.isOrdered = isOrdered;
  19616. Iterable.Keyed = KeyedIterable;
  19617. Iterable.Indexed = IndexedIterable;
  19618. Iterable.Set = SetIterable;
  19619. var IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
  19620. var IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
  19621. var IS_INDEXED_SENTINEL = '@@__IMMUTABLE_INDEXED__@@';
  19622. var IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
  19623. // Used for setting prototype methods that IE8 chokes on.
  19624. var DELETE = 'delete';
  19625. // Constants describing the size of trie nodes.
  19626. var SHIFT = 5; // Resulted in best performance after ______?
  19627. var SIZE = 1 << SHIFT;
  19628. var MASK = SIZE - 1;
  19629. // A consistent shared value representing "not set" which equals nothing other
  19630. // than itself, and nothing that could be provided externally.
  19631. var NOT_SET = {};
  19632. // Boolean references, Rough equivalent of `bool &`.
  19633. var CHANGE_LENGTH = { value: false };
  19634. var DID_ALTER = { value: false };
  19635. function MakeRef(ref) {
  19636. ref.value = false;
  19637. return ref;
  19638. }
  19639. function SetRef(ref) {
  19640. ref && (ref.value = true);
  19641. }
  19642. // A function which returns a value representing an "owner" for transient writes
  19643. // to tries. The return value will only ever equal itself, and will not equal
  19644. // the return of any subsequent call of this function.
  19645. function OwnerID() {}
  19646. // http://jsperf.com/copy-array-inline
  19647. function arrCopy(arr, offset) {
  19648. offset = offset || 0;
  19649. var len = Math.max(0, arr.length - offset);
  19650. var newArr = new Array(len);
  19651. for (var ii = 0; ii < len; ii++) {
  19652. newArr[ii] = arr[ii + offset];
  19653. }
  19654. return newArr;
  19655. }
  19656. function ensureSize(iter) {
  19657. if (iter.size === undefined) {
  19658. iter.size = iter.__iterate(returnTrue);
  19659. }
  19660. return iter.size;
  19661. }
  19662. function wrapIndex(iter, index) {
  19663. // This implements "is array index" which the ECMAString spec defines as:
  19664. //
  19665. // A String property name P is an array index if and only if
  19666. // ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal
  19667. // to 2^32−1.
  19668. //
  19669. // http://www.ecma-international.org/ecma-262/6.0/#sec-array-exotic-objects
  19670. if (typeof index !== 'number') {
  19671. var uint32Index = index >>> 0; // N >>> 0 is shorthand for ToUint32
  19672. if ('' + uint32Index !== index || uint32Index === 4294967295) {
  19673. return NaN;
  19674. }
  19675. index = uint32Index;
  19676. }
  19677. return index < 0 ? ensureSize(iter) + index : index;
  19678. }
  19679. function returnTrue() {
  19680. return true;
  19681. }
  19682. function wholeSlice(begin, end, size) {
  19683. return (begin === 0 || (size !== undefined && begin <= -size)) &&
  19684. (end === undefined || (size !== undefined && end >= size));
  19685. }
  19686. function resolveBegin(begin, size) {
  19687. return resolveIndex(begin, size, 0);
  19688. }
  19689. function resolveEnd(end, size) {
  19690. return resolveIndex(end, size, size);
  19691. }
  19692. function resolveIndex(index, size, defaultIndex) {
  19693. return index === undefined ?
  19694. defaultIndex :
  19695. index < 0 ?
  19696. Math.max(0, size + index) :
  19697. size === undefined ?
  19698. index :
  19699. Math.min(size, index);
  19700. }
  19701. /* global Symbol */
  19702. var ITERATE_KEYS = 0;
  19703. var ITERATE_VALUES = 1;
  19704. var ITERATE_ENTRIES = 2;
  19705. var REAL_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
  19706. var FAUX_ITERATOR_SYMBOL = '@@iterator';
  19707. var ITERATOR_SYMBOL = REAL_ITERATOR_SYMBOL || FAUX_ITERATOR_SYMBOL;
  19708. function Iterator(next) {
  19709. this.next = next;
  19710. }
  19711. Iterator.prototype.toString = function() {
  19712. return '[Iterator]';
  19713. };
  19714. Iterator.KEYS = ITERATE_KEYS;
  19715. Iterator.VALUES = ITERATE_VALUES;
  19716. Iterator.ENTRIES = ITERATE_ENTRIES;
  19717. Iterator.prototype.inspect =
  19718. Iterator.prototype.toSource = function () { return this.toString(); };
  19719. Iterator.prototype[ITERATOR_SYMBOL] = function () {
  19720. return this;
  19721. };
  19722. function iteratorValue(type, k, v, iteratorResult) {
  19723. var value = type === 0 ? k : type === 1 ? v : [k, v];
  19724. iteratorResult ? (iteratorResult.value = value) : (iteratorResult = {
  19725. value: value, done: false
  19726. });
  19727. return iteratorResult;
  19728. }
  19729. function iteratorDone() {
  19730. return { value: undefined, done: true };
  19731. }
  19732. function hasIterator(maybeIterable) {
  19733. return !!getIteratorFn(maybeIterable);
  19734. }
  19735. function isIterator(maybeIterator) {
  19736. return maybeIterator && typeof maybeIterator.next === 'function';
  19737. }
  19738. function getIterator(iterable) {
  19739. var iteratorFn = getIteratorFn(iterable);
  19740. return iteratorFn && iteratorFn.call(iterable);
  19741. }
  19742. function getIteratorFn(iterable) {
  19743. var iteratorFn = iterable && (
  19744. (REAL_ITERATOR_SYMBOL && iterable[REAL_ITERATOR_SYMBOL]) ||
  19745. iterable[FAUX_ITERATOR_SYMBOL]
  19746. );
  19747. if (typeof iteratorFn === 'function') {
  19748. return iteratorFn;
  19749. }
  19750. }
  19751. function isArrayLike(value) {
  19752. return value && typeof value.length === 'number';
  19753. }
  19754. createClass(Seq, Iterable);
  19755. function Seq(value) {
  19756. return value === null || value === undefined ? emptySequence() :
  19757. isIterable(value) ? value.toSeq() : seqFromValue(value);
  19758. }
  19759. Seq.of = function(/*...values*/) {
  19760. return Seq(arguments);
  19761. };
  19762. Seq.prototype.toSeq = function() {
  19763. return this;
  19764. };
  19765. Seq.prototype.toString = function() {
  19766. return this.__toString('Seq {', '}');
  19767. };
  19768. Seq.prototype.cacheResult = function() {
  19769. if (!this._cache && this.__iterateUncached) {
  19770. this._cache = this.entrySeq().toArray();
  19771. this.size = this._cache.length;
  19772. }
  19773. return this;
  19774. };
  19775. // abstract __iterateUncached(fn, reverse)
  19776. Seq.prototype.__iterate = function(fn, reverse) {
  19777. return seqIterate(this, fn, reverse, true);
  19778. };
  19779. // abstract __iteratorUncached(type, reverse)
  19780. Seq.prototype.__iterator = function(type, reverse) {
  19781. return seqIterator(this, type, reverse, true);
  19782. };
  19783. createClass(KeyedSeq, Seq);
  19784. function KeyedSeq(value) {
  19785. return value === null || value === undefined ?
  19786. emptySequence().toKeyedSeq() :
  19787. isIterable(value) ?
  19788. (isKeyed(value) ? value.toSeq() : value.fromEntrySeq()) :
  19789. keyedSeqFromValue(value);
  19790. }
  19791. KeyedSeq.prototype.toKeyedSeq = function() {
  19792. return this;
  19793. };
  19794. createClass(IndexedSeq, Seq);
  19795. function IndexedSeq(value) {
  19796. return value === null || value === undefined ? emptySequence() :
  19797. !isIterable(value) ? indexedSeqFromValue(value) :
  19798. isKeyed(value) ? value.entrySeq() : value.toIndexedSeq();
  19799. }
  19800. IndexedSeq.of = function(/*...values*/) {
  19801. return IndexedSeq(arguments);
  19802. };
  19803. IndexedSeq.prototype.toIndexedSeq = function() {
  19804. return this;
  19805. };
  19806. IndexedSeq.prototype.toString = function() {
  19807. return this.__toString('Seq [', ']');
  19808. };
  19809. IndexedSeq.prototype.__iterate = function(fn, reverse) {
  19810. return seqIterate(this, fn, reverse, false);
  19811. };
  19812. IndexedSeq.prototype.__iterator = function(type, reverse) {
  19813. return seqIterator(this, type, reverse, false);
  19814. };
  19815. createClass(SetSeq, Seq);
  19816. function SetSeq(value) {
  19817. return (
  19818. value === null || value === undefined ? emptySequence() :
  19819. !isIterable(value) ? indexedSeqFromValue(value) :
  19820. isKeyed(value) ? value.entrySeq() : value
  19821. ).toSetSeq();
  19822. }
  19823. SetSeq.of = function(/*...values*/) {
  19824. return SetSeq(arguments);
  19825. };
  19826. SetSeq.prototype.toSetSeq = function() {
  19827. return this;
  19828. };
  19829. Seq.isSeq = isSeq;
  19830. Seq.Keyed = KeyedSeq;
  19831. Seq.Set = SetSeq;
  19832. Seq.Indexed = IndexedSeq;
  19833. var IS_SEQ_SENTINEL = '@@__IMMUTABLE_SEQ__@@';
  19834. Seq.prototype[IS_SEQ_SENTINEL] = true;
  19835. createClass(ArraySeq, IndexedSeq);
  19836. function ArraySeq(array) {
  19837. this._array = array;
  19838. this.size = array.length;
  19839. }
  19840. ArraySeq.prototype.get = function(index, notSetValue) {
  19841. return this.has(index) ? this._array[wrapIndex(this, index)] : notSetValue;
  19842. };
  19843. ArraySeq.prototype.__iterate = function(fn, reverse) {
  19844. var array = this._array;
  19845. var maxIndex = array.length - 1;
  19846. for (var ii = 0; ii <= maxIndex; ii++) {
  19847. if (fn(array[reverse ? maxIndex - ii : ii], ii, this) === false) {
  19848. return ii + 1;
  19849. }
  19850. }
  19851. return ii;
  19852. };
  19853. ArraySeq.prototype.__iterator = function(type, reverse) {
  19854. var array = this._array;
  19855. var maxIndex = array.length - 1;
  19856. var ii = 0;
  19857. return new Iterator(function()
  19858. {return ii > maxIndex ?
  19859. iteratorDone() :
  19860. iteratorValue(type, ii, array[reverse ? maxIndex - ii++ : ii++])}
  19861. );
  19862. };
  19863. createClass(ObjectSeq, KeyedSeq);
  19864. function ObjectSeq(object) {
  19865. var keys = Object.keys(object);
  19866. this._object = object;
  19867. this._keys = keys;
  19868. this.size = keys.length;
  19869. }
  19870. ObjectSeq.prototype.get = function(key, notSetValue) {
  19871. if (notSetValue !== undefined && !this.has(key)) {
  19872. return notSetValue;
  19873. }
  19874. return this._object[key];
  19875. };
  19876. ObjectSeq.prototype.has = function(key) {
  19877. return this._object.hasOwnProperty(key);
  19878. };
  19879. ObjectSeq.prototype.__iterate = function(fn, reverse) {
  19880. var object = this._object;
  19881. var keys = this._keys;
  19882. var maxIndex = keys.length - 1;
  19883. for (var ii = 0; ii <= maxIndex; ii++) {
  19884. var key = keys[reverse ? maxIndex - ii : ii];
  19885. if (fn(object[key], key, this) === false) {
  19886. return ii + 1;
  19887. }
  19888. }
  19889. return ii;
  19890. };
  19891. ObjectSeq.prototype.__iterator = function(type, reverse) {
  19892. var object = this._object;
  19893. var keys = this._keys;
  19894. var maxIndex = keys.length - 1;
  19895. var ii = 0;
  19896. return new Iterator(function() {
  19897. var key = keys[reverse ? maxIndex - ii : ii];
  19898. return ii++ > maxIndex ?
  19899. iteratorDone() :
  19900. iteratorValue(type, key, object[key]);
  19901. });
  19902. };
  19903. ObjectSeq.prototype[IS_ORDERED_SENTINEL] = true;
  19904. createClass(IterableSeq, IndexedSeq);
  19905. function IterableSeq(iterable) {
  19906. this._iterable = iterable;
  19907. this.size = iterable.length || iterable.size;
  19908. }
  19909. IterableSeq.prototype.__iterateUncached = function(fn, reverse) {
  19910. if (reverse) {
  19911. return this.cacheResult().__iterate(fn, reverse);
  19912. }
  19913. var iterable = this._iterable;
  19914. var iterator = getIterator(iterable);
  19915. var iterations = 0;
  19916. if (isIterator(iterator)) {
  19917. var step;
  19918. while (!(step = iterator.next()).done) {
  19919. if (fn(step.value, iterations++, this) === false) {
  19920. break;
  19921. }
  19922. }
  19923. }
  19924. return iterations;
  19925. };
  19926. IterableSeq.prototype.__iteratorUncached = function(type, reverse) {
  19927. if (reverse) {
  19928. return this.cacheResult().__iterator(type, reverse);
  19929. }
  19930. var iterable = this._iterable;
  19931. var iterator = getIterator(iterable);
  19932. if (!isIterator(iterator)) {
  19933. return new Iterator(iteratorDone);
  19934. }
  19935. var iterations = 0;
  19936. return new Iterator(function() {
  19937. var step = iterator.next();
  19938. return step.done ? step : iteratorValue(type, iterations++, step.value);
  19939. });
  19940. };
  19941. createClass(IteratorSeq, IndexedSeq);
  19942. function IteratorSeq(iterator) {
  19943. this._iterator = iterator;
  19944. this._iteratorCache = [];
  19945. }
  19946. IteratorSeq.prototype.__iterateUncached = function(fn, reverse) {
  19947. if (reverse) {
  19948. return this.cacheResult().__iterate(fn, reverse);
  19949. }
  19950. var iterator = this._iterator;
  19951. var cache = this._iteratorCache;
  19952. var iterations = 0;
  19953. while (iterations < cache.length) {
  19954. if (fn(cache[iterations], iterations++, this) === false) {
  19955. return iterations;
  19956. }
  19957. }
  19958. var step;
  19959. while (!(step = iterator.next()).done) {
  19960. var val = step.value;
  19961. cache[iterations] = val;
  19962. if (fn(val, iterations++, this) === false) {
  19963. break;
  19964. }
  19965. }
  19966. return iterations;
  19967. };
  19968. IteratorSeq.prototype.__iteratorUncached = function(type, reverse) {
  19969. if (reverse) {
  19970. return this.cacheResult().__iterator(type, reverse);
  19971. }
  19972. var iterator = this._iterator;
  19973. var cache = this._iteratorCache;
  19974. var iterations = 0;
  19975. return new Iterator(function() {
  19976. if (iterations >= cache.length) {
  19977. var step = iterator.next();
  19978. if (step.done) {
  19979. return step;
  19980. }
  19981. cache[iterations] = step.value;
  19982. }
  19983. return iteratorValue(type, iterations, cache[iterations++]);
  19984. });
  19985. };
  19986. // # pragma Helper functions
  19987. function isSeq(maybeSeq) {
  19988. return !!(maybeSeq && maybeSeq[IS_SEQ_SENTINEL]);
  19989. }
  19990. var EMPTY_SEQ;
  19991. function emptySequence() {
  19992. return EMPTY_SEQ || (EMPTY_SEQ = new ArraySeq([]));
  19993. }
  19994. function keyedSeqFromValue(value) {
  19995. var seq =
  19996. Array.isArray(value) ? new ArraySeq(value).fromEntrySeq() :
  19997. isIterator(value) ? new IteratorSeq(value).fromEntrySeq() :
  19998. hasIterator(value) ? new IterableSeq(value).fromEntrySeq() :
  19999. typeof value === 'object' ? new ObjectSeq(value) :
  20000. undefined;
  20001. if (!seq) {
  20002. throw new TypeError(
  20003. 'Expected Array or iterable object of [k, v] entries, '+
  20004. 'or keyed object: ' + value
  20005. );
  20006. }
  20007. return seq;
  20008. }
  20009. function indexedSeqFromValue(value) {
  20010. var seq = maybeIndexedSeqFromValue(value);
  20011. if (!seq) {
  20012. throw new TypeError(
  20013. 'Expected Array or iterable object of values: ' + value
  20014. );
  20015. }
  20016. return seq;
  20017. }
  20018. function seqFromValue(value) {
  20019. var seq = maybeIndexedSeqFromValue(value) ||
  20020. (typeof value === 'object' && new ObjectSeq(value));
  20021. if (!seq) {
  20022. throw new TypeError(
  20023. 'Expected Array or iterable object of values, or keyed object: ' + value
  20024. );
  20025. }
  20026. return seq;
  20027. }
  20028. function maybeIndexedSeqFromValue(value) {
  20029. return (
  20030. isArrayLike(value) ? new ArraySeq(value) :
  20031. isIterator(value) ? new IteratorSeq(value) :
  20032. hasIterator(value) ? new IterableSeq(value) :
  20033. undefined
  20034. );
  20035. }
  20036. function seqIterate(seq, fn, reverse, useKeys) {
  20037. var cache = seq._cache;
  20038. if (cache) {
  20039. var maxIndex = cache.length - 1;
  20040. for (var ii = 0; ii <= maxIndex; ii++) {
  20041. var entry = cache[reverse ? maxIndex - ii : ii];
  20042. if (fn(entry[1], useKeys ? entry[0] : ii, seq) === false) {
  20043. return ii + 1;
  20044. }
  20045. }
  20046. return ii;
  20047. }
  20048. return seq.__iterateUncached(fn, reverse);
  20049. }
  20050. function seqIterator(seq, type, reverse, useKeys) {
  20051. var cache = seq._cache;
  20052. if (cache) {
  20053. var maxIndex = cache.length - 1;
  20054. var ii = 0;
  20055. return new Iterator(function() {
  20056. var entry = cache[reverse ? maxIndex - ii : ii];
  20057. return ii++ > maxIndex ?
  20058. iteratorDone() :
  20059. iteratorValue(type, useKeys ? entry[0] : ii - 1, entry[1]);
  20060. });
  20061. }
  20062. return seq.__iteratorUncached(type, reverse);
  20063. }
  20064. function fromJS(json, converter) {
  20065. return converter ?
  20066. fromJSWith(converter, json, '', {'': json}) :
  20067. fromJSDefault(json);
  20068. }
  20069. function fromJSWith(converter, json, key, parentJSON) {
  20070. if (Array.isArray(json)) {
  20071. return converter.call(parentJSON, key, IndexedSeq(json).map(function(v, k) {return fromJSWith(converter, v, k, json)}));
  20072. }
  20073. if (isPlainObj(json)) {
  20074. return converter.call(parentJSON, key, KeyedSeq(json).map(function(v, k) {return fromJSWith(converter, v, k, json)}));
  20075. }
  20076. return json;
  20077. }
  20078. function fromJSDefault(json) {
  20079. if (Array.isArray(json)) {
  20080. return IndexedSeq(json).map(fromJSDefault).toList();
  20081. }
  20082. if (isPlainObj(json)) {
  20083. return KeyedSeq(json).map(fromJSDefault).toMap();
  20084. }
  20085. return json;
  20086. }
  20087. function isPlainObj(value) {
  20088. return value && (value.constructor === Object || value.constructor === undefined);
  20089. }
  20090. /**
  20091. * An extension of the "same-value" algorithm as [described for use by ES6 Map
  20092. * and Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map#Key_equality)
  20093. *
  20094. * NaN is considered the same as NaN, however -0 and 0 are considered the same
  20095. * value, which is different from the algorithm described by
  20096. * [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is).
  20097. *
  20098. * This is extended further to allow Objects to describe the values they
  20099. * represent, by way of `valueOf` or `equals` (and `hashCode`).
  20100. *
  20101. * Note: because of this extension, the key equality of Immutable.Map and the
  20102. * value equality of Immutable.Set will differ from ES6 Map and Set.
  20103. *
  20104. * ### Defining custom values
  20105. *
  20106. * The easiest way to describe the value an object represents is by implementing
  20107. * `valueOf`. For example, `Date` represents a value by returning a unix
  20108. * timestamp for `valueOf`:
  20109. *
  20110. * var date1 = new Date(1234567890000); // Fri Feb 13 2009 ...
  20111. * var date2 = new Date(1234567890000);
  20112. * date1.valueOf(); // 1234567890000
  20113. * assert( date1 !== date2 );
  20114. * assert( Immutable.is( date1, date2 ) );
  20115. *
  20116. * Note: overriding `valueOf` may have other implications if you use this object
  20117. * where JavaScript expects a primitive, such as implicit string coercion.
  20118. *
  20119. * For more complex types, especially collections, implementing `valueOf` may
  20120. * not be performant. An alternative is to implement `equals` and `hashCode`.
  20121. *
  20122. * `equals` takes another object, presumably of similar type, and returns true
  20123. * if the it is equal. Equality is symmetrical, so the same result should be
  20124. * returned if this and the argument are flipped.
  20125. *
  20126. * assert( a.equals(b) === b.equals(a) );
  20127. *
  20128. * `hashCode` returns a 32bit integer number representing the object which will
  20129. * be used to determine how to store the value object in a Map or Set. You must
  20130. * provide both or neither methods, one must not exist without the other.
  20131. *
  20132. * Also, an important relationship between these methods must be upheld: if two
  20133. * values are equal, they *must* return the same hashCode. If the values are not
  20134. * equal, they might have the same hashCode; this is called a hash collision,
  20135. * and while undesirable for performance reasons, it is acceptable.
  20136. *
  20137. * if (a.equals(b)) {
  20138. * assert( a.hashCode() === b.hashCode() );
  20139. * }
  20140. *
  20141. * All Immutable collections implement `equals` and `hashCode`.
  20142. *
  20143. */
  20144. function is(valueA, valueB) {
  20145. if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
  20146. return true;
  20147. }
  20148. if (!valueA || !valueB) {
  20149. return false;
  20150. }
  20151. if (typeof valueA.valueOf === 'function' &&
  20152. typeof valueB.valueOf === 'function') {
  20153. valueA = valueA.valueOf();
  20154. valueB = valueB.valueOf();
  20155. if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
  20156. return true;
  20157. }
  20158. if (!valueA || !valueB) {
  20159. return false;
  20160. }
  20161. }
  20162. if (typeof valueA.equals === 'function' &&
  20163. typeof valueB.equals === 'function' &&
  20164. valueA.equals(valueB)) {
  20165. return true;
  20166. }
  20167. return false;
  20168. }
  20169. function deepEqual(a, b) {
  20170. if (a === b) {
  20171. return true;
  20172. }
  20173. if (
  20174. !isIterable(b) ||
  20175. a.size !== undefined && b.size !== undefined && a.size !== b.size ||
  20176. a.__hash !== undefined && b.__hash !== undefined && a.__hash !== b.__hash ||
  20177. isKeyed(a) !== isKeyed(b) ||
  20178. isIndexed(a) !== isIndexed(b) ||
  20179. isOrdered(a) !== isOrdered(b)
  20180. ) {
  20181. return false;
  20182. }
  20183. if (a.size === 0 && b.size === 0) {
  20184. return true;
  20185. }
  20186. var notAssociative = !isAssociative(a);
  20187. if (isOrdered(a)) {
  20188. var entries = a.entries();
  20189. return b.every(function(v, k) {
  20190. var entry = entries.next().value;
  20191. return entry && is(entry[1], v) && (notAssociative || is(entry[0], k));
  20192. }) && entries.next().done;
  20193. }
  20194. var flipped = false;
  20195. if (a.size === undefined) {
  20196. if (b.size === undefined) {
  20197. if (typeof a.cacheResult === 'function') {
  20198. a.cacheResult();
  20199. }
  20200. } else {
  20201. flipped = true;
  20202. var _ = a;
  20203. a = b;
  20204. b = _;
  20205. }
  20206. }
  20207. var allEqual = true;
  20208. var bSize = b.__iterate(function(v, k) {
  20209. if (notAssociative ? !a.has(v) :
  20210. flipped ? !is(v, a.get(k, NOT_SET)) : !is(a.get(k, NOT_SET), v)) {
  20211. allEqual = false;
  20212. return false;
  20213. }
  20214. });
  20215. return allEqual && a.size === bSize;
  20216. }
  20217. createClass(Repeat, IndexedSeq);
  20218. function Repeat(value, times) {
  20219. if (!(this instanceof Repeat)) {
  20220. return new Repeat(value, times);
  20221. }
  20222. this._value = value;
  20223. this.size = times === undefined ? Infinity : Math.max(0, times);
  20224. if (this.size === 0) {
  20225. if (EMPTY_REPEAT) {
  20226. return EMPTY_REPEAT;
  20227. }
  20228. EMPTY_REPEAT = this;
  20229. }
  20230. }
  20231. Repeat.prototype.toString = function() {
  20232. if (this.size === 0) {
  20233. return 'Repeat []';
  20234. }
  20235. return 'Repeat [ ' + this._value + ' ' + this.size + ' times ]';
  20236. };
  20237. Repeat.prototype.get = function(index, notSetValue) {
  20238. return this.has(index) ? this._value : notSetValue;
  20239. };
  20240. Repeat.prototype.includes = function(searchValue) {
  20241. return is(this._value, searchValue);
  20242. };
  20243. Repeat.prototype.slice = function(begin, end) {
  20244. var size = this.size;
  20245. return wholeSlice(begin, end, size) ? this :
  20246. new Repeat(this._value, resolveEnd(end, size) - resolveBegin(begin, size));
  20247. };
  20248. Repeat.prototype.reverse = function() {
  20249. return this;
  20250. };
  20251. Repeat.prototype.indexOf = function(searchValue) {
  20252. if (is(this._value, searchValue)) {
  20253. return 0;
  20254. }
  20255. return -1;
  20256. };
  20257. Repeat.prototype.lastIndexOf = function(searchValue) {
  20258. if (is(this._value, searchValue)) {
  20259. return this.size;
  20260. }
  20261. return -1;
  20262. };
  20263. Repeat.prototype.__iterate = function(fn, reverse) {
  20264. for (var ii = 0; ii < this.size; ii++) {
  20265. if (fn(this._value, ii, this) === false) {
  20266. return ii + 1;
  20267. }
  20268. }
  20269. return ii;
  20270. };
  20271. Repeat.prototype.__iterator = function(type, reverse) {var this$0 = this;
  20272. var ii = 0;
  20273. return new Iterator(function()
  20274. {return ii < this$0.size ? iteratorValue(type, ii++, this$0._value) : iteratorDone()}
  20275. );
  20276. };
  20277. Repeat.prototype.equals = function(other) {
  20278. return other instanceof Repeat ?
  20279. is(this._value, other._value) :
  20280. deepEqual(other);
  20281. };
  20282. var EMPTY_REPEAT;
  20283. function invariant(condition, error) {
  20284. if (!condition) throw new Error(error);
  20285. }
  20286. createClass(Range, IndexedSeq);
  20287. function Range(start, end, step) {
  20288. if (!(this instanceof Range)) {
  20289. return new Range(start, end, step);
  20290. }
  20291. invariant(step !== 0, 'Cannot step a Range by 0');
  20292. start = start || 0;
  20293. if (end === undefined) {
  20294. end = Infinity;
  20295. }
  20296. step = step === undefined ? 1 : Math.abs(step);
  20297. if (end < start) {
  20298. step = -step;
  20299. }
  20300. this._start = start;
  20301. this._end = end;
  20302. this._step = step;
  20303. this.size = Math.max(0, Math.ceil((end - start) / step - 1) + 1);
  20304. if (this.size === 0) {
  20305. if (EMPTY_RANGE) {
  20306. return EMPTY_RANGE;
  20307. }
  20308. EMPTY_RANGE = this;
  20309. }
  20310. }
  20311. Range.prototype.toString = function() {
  20312. if (this.size === 0) {
  20313. return 'Range []';
  20314. }
  20315. return 'Range [ ' +
  20316. this._start + '...' + this._end +
  20317. (this._step > 1 ? ' by ' + this._step : '') +
  20318. ' ]';
  20319. };
  20320. Range.prototype.get = function(index, notSetValue) {
  20321. return this.has(index) ?
  20322. this._start + wrapIndex(this, index) * this._step :
  20323. notSetValue;
  20324. };
  20325. Range.prototype.includes = function(searchValue) {
  20326. var possibleIndex = (searchValue - this._start) / this._step;
  20327. return possibleIndex >= 0 &&
  20328. possibleIndex < this.size &&
  20329. possibleIndex === Math.floor(possibleIndex);
  20330. };
  20331. Range.prototype.slice = function(begin, end) {
  20332. if (wholeSlice(begin, end, this.size)) {
  20333. return this;
  20334. }
  20335. begin = resolveBegin(begin, this.size);
  20336. end = resolveEnd(end, this.size);
  20337. if (end <= begin) {
  20338. return new Range(0, 0);
  20339. }
  20340. return new Range(this.get(begin, this._end), this.get(end, this._end), this._step);
  20341. };
  20342. Range.prototype.indexOf = function(searchValue) {
  20343. var offsetValue = searchValue - this._start;
  20344. if (offsetValue % this._step === 0) {
  20345. var index = offsetValue / this._step;
  20346. if (index >= 0 && index < this.size) {
  20347. return index
  20348. }
  20349. }
  20350. return -1;
  20351. };
  20352. Range.prototype.lastIndexOf = function(searchValue) {
  20353. return this.indexOf(searchValue);
  20354. };
  20355. Range.prototype.__iterate = function(fn, reverse) {
  20356. var maxIndex = this.size - 1;
  20357. var step = this._step;
  20358. var value = reverse ? this._start + maxIndex * step : this._start;
  20359. for (var ii = 0; ii <= maxIndex; ii++) {
  20360. if (fn(value, ii, this) === false) {
  20361. return ii + 1;
  20362. }
  20363. value += reverse ? -step : step;
  20364. }
  20365. return ii;
  20366. };
  20367. Range.prototype.__iterator = function(type, reverse) {
  20368. var maxIndex = this.size - 1;
  20369. var step = this._step;
  20370. var value = reverse ? this._start + maxIndex * step : this._start;
  20371. var ii = 0;
  20372. return new Iterator(function() {
  20373. var v = value;
  20374. value += reverse ? -step : step;
  20375. return ii > maxIndex ? iteratorDone() : iteratorValue(type, ii++, v);
  20376. });
  20377. };
  20378. Range.prototype.equals = function(other) {
  20379. return other instanceof Range ?
  20380. this._start === other._start &&
  20381. this._end === other._end &&
  20382. this._step === other._step :
  20383. deepEqual(this, other);
  20384. };
  20385. var EMPTY_RANGE;
  20386. createClass(Collection, Iterable);
  20387. function Collection() {
  20388. throw TypeError('Abstract');
  20389. }
  20390. createClass(KeyedCollection, Collection);function KeyedCollection() {}
  20391. createClass(IndexedCollection, Collection);function IndexedCollection() {}
  20392. createClass(SetCollection, Collection);function SetCollection() {}
  20393. Collection.Keyed = KeyedCollection;
  20394. Collection.Indexed = IndexedCollection;
  20395. Collection.Set = SetCollection;
  20396. var imul =
  20397. typeof Math.imul === 'function' && Math.imul(0xffffffff, 2) === -2 ?
  20398. Math.imul :
  20399. function imul(a, b) {
  20400. a = a | 0; // int
  20401. b = b | 0; // int
  20402. var c = a & 0xffff;
  20403. var d = b & 0xffff;
  20404. // Shift by 0 fixes the sign on the high part.
  20405. return (c * d) + ((((a >>> 16) * d + c * (b >>> 16)) << 16) >>> 0) | 0; // int
  20406. };
  20407. // v8 has an optimization for storing 31-bit signed numbers.
  20408. // Values which have either 00 or 11 as the high order bits qualify.
  20409. // This function drops the highest order bit in a signed number, maintaining
  20410. // the sign bit.
  20411. function smi(i32) {
  20412. return ((i32 >>> 1) & 0x40000000) | (i32 & 0xBFFFFFFF);
  20413. }
  20414. function hash(o) {
  20415. if (o === false || o === null || o === undefined) {
  20416. return 0;
  20417. }
  20418. if (typeof o.valueOf === 'function') {
  20419. o = o.valueOf();
  20420. if (o === false || o === null || o === undefined) {
  20421. return 0;
  20422. }
  20423. }
  20424. if (o === true) {
  20425. return 1;
  20426. }
  20427. var type = typeof o;
  20428. if (type === 'number') {
  20429. var h = o | 0;
  20430. if (h !== o) {
  20431. h ^= o * 0xFFFFFFFF;
  20432. }
  20433. while (o > 0xFFFFFFFF) {
  20434. o /= 0xFFFFFFFF;
  20435. h ^= o;
  20436. }
  20437. return smi(h);
  20438. }
  20439. if (type === 'string') {
  20440. return o.length > STRING_HASH_CACHE_MIN_STRLEN ? cachedHashString(o) : hashString(o);
  20441. }
  20442. if (typeof o.hashCode === 'function') {
  20443. return o.hashCode();
  20444. }
  20445. if (type === 'object') {
  20446. return hashJSObj(o);
  20447. }
  20448. if (typeof o.toString === 'function') {
  20449. return hashString(o.toString());
  20450. }
  20451. throw new Error('Value type ' + type + ' cannot be hashed.');
  20452. }
  20453. function cachedHashString(string) {
  20454. var hash = stringHashCache[string];
  20455. if (hash === undefined) {
  20456. hash = hashString(string);
  20457. if (STRING_HASH_CACHE_SIZE === STRING_HASH_CACHE_MAX_SIZE) {
  20458. STRING_HASH_CACHE_SIZE = 0;
  20459. stringHashCache = {};
  20460. }
  20461. STRING_HASH_CACHE_SIZE++;
  20462. stringHashCache[string] = hash;
  20463. }
  20464. return hash;
  20465. }
  20466. // http://jsperf.com/hashing-strings
  20467. function hashString(string) {
  20468. // This is the hash from JVM
  20469. // The hash code for a string is computed as
  20470. // s[0] * 31 ^ (n - 1) + s[1] * 31 ^ (n - 2) + ... + s[n - 1],
  20471. // where s[i] is the ith character of the string and n is the length of
  20472. // the string. We "mod" the result to make it between 0 (inclusive) and 2^31
  20473. // (exclusive) by dropping high bits.
  20474. var hash = 0;
  20475. for (var ii = 0; ii < string.length; ii++) {
  20476. hash = 31 * hash + string.charCodeAt(ii) | 0;
  20477. }
  20478. return smi(hash);
  20479. }
  20480. function hashJSObj(obj) {
  20481. var hash;
  20482. if (usingWeakMap) {
  20483. hash = weakMap.get(obj);
  20484. if (hash !== undefined) {
  20485. return hash;
  20486. }
  20487. }
  20488. hash = obj[UID_HASH_KEY];
  20489. if (hash !== undefined) {
  20490. return hash;
  20491. }
  20492. if (!canDefineProperty) {
  20493. hash = obj.propertyIsEnumerable && obj.propertyIsEnumerable[UID_HASH_KEY];
  20494. if (hash !== undefined) {
  20495. return hash;
  20496. }
  20497. hash = getIENodeHash(obj);
  20498. if (hash !== undefined) {
  20499. return hash;
  20500. }
  20501. }
  20502. hash = ++objHashUID;
  20503. if (objHashUID & 0x40000000) {
  20504. objHashUID = 0;
  20505. }
  20506. if (usingWeakMap) {
  20507. weakMap.set(obj, hash);
  20508. } else if (isExtensible !== undefined && isExtensible(obj) === false) {
  20509. throw new Error('Non-extensible objects are not allowed as keys.');
  20510. } else if (canDefineProperty) {
  20511. Object.defineProperty(obj, UID_HASH_KEY, {
  20512. 'enumerable': false,
  20513. 'configurable': false,
  20514. 'writable': false,
  20515. 'value': hash
  20516. });
  20517. } else if (obj.propertyIsEnumerable !== undefined &&
  20518. obj.propertyIsEnumerable === obj.constructor.prototype.propertyIsEnumerable) {
  20519. // Since we can't define a non-enumerable property on the object
  20520. // we'll hijack one of the less-used non-enumerable properties to
  20521. // save our hash on it. Since this is a function it will not show up in
  20522. // `JSON.stringify` which is what we want.
  20523. obj.propertyIsEnumerable = function() {
  20524. return this.constructor.prototype.propertyIsEnumerable.apply(this, arguments);
  20525. };
  20526. obj.propertyIsEnumerable[UID_HASH_KEY] = hash;
  20527. } else if (obj.nodeType !== undefined) {
  20528. // At this point we couldn't get the IE `uniqueID` to use as a hash
  20529. // and we couldn't use a non-enumerable property to exploit the
  20530. // dontEnum bug so we simply add the `UID_HASH_KEY` on the node
  20531. // itself.
  20532. obj[UID_HASH_KEY] = hash;
  20533. } else {
  20534. throw new Error('Unable to set a non-enumerable property on object.');
  20535. }
  20536. return hash;
  20537. }
  20538. // Get references to ES5 object methods.
  20539. var isExtensible = Object.isExtensible;
  20540. // True if Object.defineProperty works as expected. IE8 fails this test.
  20541. var canDefineProperty = (function() {
  20542. try {
  20543. Object.defineProperty({}, '@', {});
  20544. return true;
  20545. } catch (e) {
  20546. return false;
  20547. }
  20548. }());
  20549. // IE has a `uniqueID` property on DOM nodes. We can construct the hash from it
  20550. // and avoid memory leaks from the IE cloneNode bug.
  20551. function getIENodeHash(node) {
  20552. if (node && node.nodeType > 0) {
  20553. switch (node.nodeType) {
  20554. case 1: // Element
  20555. return node.uniqueID;
  20556. case 9: // Document
  20557. return node.documentElement && node.documentElement.uniqueID;
  20558. }
  20559. }
  20560. }
  20561. // If possible, use a WeakMap.
  20562. var usingWeakMap = typeof WeakMap === 'function';
  20563. var weakMap;
  20564. if (usingWeakMap) {
  20565. weakMap = new WeakMap();
  20566. }
  20567. var objHashUID = 0;
  20568. var UID_HASH_KEY = '__immutablehash__';
  20569. if (typeof Symbol === 'function') {
  20570. UID_HASH_KEY = Symbol(UID_HASH_KEY);
  20571. }
  20572. var STRING_HASH_CACHE_MIN_STRLEN = 16;
  20573. var STRING_HASH_CACHE_MAX_SIZE = 255;
  20574. var STRING_HASH_CACHE_SIZE = 0;
  20575. var stringHashCache = {};
  20576. function assertNotInfinite(size) {
  20577. invariant(
  20578. size !== Infinity,
  20579. 'Cannot perform this action with an infinite size.'
  20580. );
  20581. }
  20582. createClass(Map, KeyedCollection);
  20583. // @pragma Construction
  20584. function Map(value) {
  20585. return value === null || value === undefined ? emptyMap() :
  20586. isMap(value) && !isOrdered(value) ? value :
  20587. emptyMap().withMutations(function(map ) {
  20588. var iter = KeyedIterable(value);
  20589. assertNotInfinite(iter.size);
  20590. iter.forEach(function(v, k) {return map.set(k, v)});
  20591. });
  20592. }
  20593. Map.prototype.toString = function() {
  20594. return this.__toString('Map {', '}');
  20595. };
  20596. // @pragma Access
  20597. Map.prototype.get = function(k, notSetValue) {
  20598. return this._root ?
  20599. this._root.get(0, undefined, k, notSetValue) :
  20600. notSetValue;
  20601. };
  20602. // @pragma Modification
  20603. Map.prototype.set = function(k, v) {
  20604. return updateMap(this, k, v);
  20605. };
  20606. Map.prototype.setIn = function(keyPath, v) {
  20607. return this.updateIn(keyPath, NOT_SET, function() {return v});
  20608. };
  20609. Map.prototype.remove = function(k) {
  20610. return updateMap(this, k, NOT_SET);
  20611. };
  20612. Map.prototype.deleteIn = function(keyPath) {
  20613. return this.updateIn(keyPath, function() {return NOT_SET});
  20614. };
  20615. Map.prototype.update = function(k, notSetValue, updater) {
  20616. return arguments.length === 1 ?
  20617. k(this) :
  20618. this.updateIn([k], notSetValue, updater);
  20619. };
  20620. Map.prototype.updateIn = function(keyPath, notSetValue, updater) {
  20621. if (!updater) {
  20622. updater = notSetValue;
  20623. notSetValue = undefined;
  20624. }
  20625. var updatedValue = updateInDeepMap(
  20626. this,
  20627. forceIterator(keyPath),
  20628. notSetValue,
  20629. updater
  20630. );
  20631. return updatedValue === NOT_SET ? undefined : updatedValue;
  20632. };
  20633. Map.prototype.clear = function() {
  20634. if (this.size === 0) {
  20635. return this;
  20636. }
  20637. if (this.__ownerID) {
  20638. this.size = 0;
  20639. this._root = null;
  20640. this.__hash = undefined;
  20641. this.__altered = true;
  20642. return this;
  20643. }
  20644. return emptyMap();
  20645. };
  20646. // @pragma Composition
  20647. Map.prototype.merge = function(/*...iters*/) {
  20648. return mergeIntoMapWith(this, undefined, arguments);
  20649. };
  20650. Map.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  20651. return mergeIntoMapWith(this, merger, iters);
  20652. };
  20653. Map.prototype.mergeIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1);
  20654. return this.updateIn(
  20655. keyPath,
  20656. emptyMap(),
  20657. function(m ) {return typeof m.merge === 'function' ?
  20658. m.merge.apply(m, iters) :
  20659. iters[iters.length - 1]}
  20660. );
  20661. };
  20662. Map.prototype.mergeDeep = function(/*...iters*/) {
  20663. return mergeIntoMapWith(this, deepMerger, arguments);
  20664. };
  20665. Map.prototype.mergeDeepWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  20666. return mergeIntoMapWith(this, deepMergerWith(merger), iters);
  20667. };
  20668. Map.prototype.mergeDeepIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1);
  20669. return this.updateIn(
  20670. keyPath,
  20671. emptyMap(),
  20672. function(m ) {return typeof m.mergeDeep === 'function' ?
  20673. m.mergeDeep.apply(m, iters) :
  20674. iters[iters.length - 1]}
  20675. );
  20676. };
  20677. Map.prototype.sort = function(comparator) {
  20678. // Late binding
  20679. return OrderedMap(sortFactory(this, comparator));
  20680. };
  20681. Map.prototype.sortBy = function(mapper, comparator) {
  20682. // Late binding
  20683. return OrderedMap(sortFactory(this, comparator, mapper));
  20684. };
  20685. // @pragma Mutability
  20686. Map.prototype.withMutations = function(fn) {
  20687. var mutable = this.asMutable();
  20688. fn(mutable);
  20689. return mutable.wasAltered() ? mutable.__ensureOwner(this.__ownerID) : this;
  20690. };
  20691. Map.prototype.asMutable = function() {
  20692. return this.__ownerID ? this : this.__ensureOwner(new OwnerID());
  20693. };
  20694. Map.prototype.asImmutable = function() {
  20695. return this.__ensureOwner();
  20696. };
  20697. Map.prototype.wasAltered = function() {
  20698. return this.__altered;
  20699. };
  20700. Map.prototype.__iterator = function(type, reverse) {
  20701. return new MapIterator(this, type, reverse);
  20702. };
  20703. Map.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  20704. var iterations = 0;
  20705. this._root && this._root.iterate(function(entry ) {
  20706. iterations++;
  20707. return fn(entry[1], entry[0], this$0);
  20708. }, reverse);
  20709. return iterations;
  20710. };
  20711. Map.prototype.__ensureOwner = function(ownerID) {
  20712. if (ownerID === this.__ownerID) {
  20713. return this;
  20714. }
  20715. if (!ownerID) {
  20716. this.__ownerID = ownerID;
  20717. this.__altered = false;
  20718. return this;
  20719. }
  20720. return makeMap(this.size, this._root, ownerID, this.__hash);
  20721. };
  20722. function isMap(maybeMap) {
  20723. return !!(maybeMap && maybeMap[IS_MAP_SENTINEL]);
  20724. }
  20725. Map.isMap = isMap;
  20726. var IS_MAP_SENTINEL = '@@__IMMUTABLE_MAP__@@';
  20727. var MapPrototype = Map.prototype;
  20728. MapPrototype[IS_MAP_SENTINEL] = true;
  20729. MapPrototype[DELETE] = MapPrototype.remove;
  20730. MapPrototype.removeIn = MapPrototype.deleteIn;
  20731. // #pragma Trie Nodes
  20732. function ArrayMapNode(ownerID, entries) {
  20733. this.ownerID = ownerID;
  20734. this.entries = entries;
  20735. }
  20736. ArrayMapNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  20737. var entries = this.entries;
  20738. for (var ii = 0, len = entries.length; ii < len; ii++) {
  20739. if (is(key, entries[ii][0])) {
  20740. return entries[ii][1];
  20741. }
  20742. }
  20743. return notSetValue;
  20744. };
  20745. ArrayMapNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  20746. var removed = value === NOT_SET;
  20747. var entries = this.entries;
  20748. var idx = 0;
  20749. for (var len = entries.length; idx < len; idx++) {
  20750. if (is(key, entries[idx][0])) {
  20751. break;
  20752. }
  20753. }
  20754. var exists = idx < len;
  20755. if (exists ? entries[idx][1] === value : removed) {
  20756. return this;
  20757. }
  20758. SetRef(didAlter);
  20759. (removed || !exists) && SetRef(didChangeSize);
  20760. if (removed && entries.length === 1) {
  20761. return; // undefined
  20762. }
  20763. if (!exists && !removed && entries.length >= MAX_ARRAY_MAP_SIZE) {
  20764. return createNodes(ownerID, entries, key, value);
  20765. }
  20766. var isEditable = ownerID && ownerID === this.ownerID;
  20767. var newEntries = isEditable ? entries : arrCopy(entries);
  20768. if (exists) {
  20769. if (removed) {
  20770. idx === len - 1 ? newEntries.pop() : (newEntries[idx] = newEntries.pop());
  20771. } else {
  20772. newEntries[idx] = [key, value];
  20773. }
  20774. } else {
  20775. newEntries.push([key, value]);
  20776. }
  20777. if (isEditable) {
  20778. this.entries = newEntries;
  20779. return this;
  20780. }
  20781. return new ArrayMapNode(ownerID, newEntries);
  20782. };
  20783. function BitmapIndexedNode(ownerID, bitmap, nodes) {
  20784. this.ownerID = ownerID;
  20785. this.bitmap = bitmap;
  20786. this.nodes = nodes;
  20787. }
  20788. BitmapIndexedNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  20789. if (keyHash === undefined) {
  20790. keyHash = hash(key);
  20791. }
  20792. var bit = (1 << ((shift === 0 ? keyHash : keyHash >>> shift) & MASK));
  20793. var bitmap = this.bitmap;
  20794. return (bitmap & bit) === 0 ? notSetValue :
  20795. this.nodes[popCount(bitmap & (bit - 1))].get(shift + SHIFT, keyHash, key, notSetValue);
  20796. };
  20797. BitmapIndexedNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  20798. if (keyHash === undefined) {
  20799. keyHash = hash(key);
  20800. }
  20801. var keyHashFrag = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  20802. var bit = 1 << keyHashFrag;
  20803. var bitmap = this.bitmap;
  20804. var exists = (bitmap & bit) !== 0;
  20805. if (!exists && value === NOT_SET) {
  20806. return this;
  20807. }
  20808. var idx = popCount(bitmap & (bit - 1));
  20809. var nodes = this.nodes;
  20810. var node = exists ? nodes[idx] : undefined;
  20811. var newNode = updateNode(node, ownerID, shift + SHIFT, keyHash, key, value, didChangeSize, didAlter);
  20812. if (newNode === node) {
  20813. return this;
  20814. }
  20815. if (!exists && newNode && nodes.length >= MAX_BITMAP_INDEXED_SIZE) {
  20816. return expandNodes(ownerID, nodes, bitmap, keyHashFrag, newNode);
  20817. }
  20818. if (exists && !newNode && nodes.length === 2 && isLeafNode(nodes[idx ^ 1])) {
  20819. return nodes[idx ^ 1];
  20820. }
  20821. if (exists && newNode && nodes.length === 1 && isLeafNode(newNode)) {
  20822. return newNode;
  20823. }
  20824. var isEditable = ownerID && ownerID === this.ownerID;
  20825. var newBitmap = exists ? newNode ? bitmap : bitmap ^ bit : bitmap | bit;
  20826. var newNodes = exists ? newNode ?
  20827. setIn(nodes, idx, newNode, isEditable) :
  20828. spliceOut(nodes, idx, isEditable) :
  20829. spliceIn(nodes, idx, newNode, isEditable);
  20830. if (isEditable) {
  20831. this.bitmap = newBitmap;
  20832. this.nodes = newNodes;
  20833. return this;
  20834. }
  20835. return new BitmapIndexedNode(ownerID, newBitmap, newNodes);
  20836. };
  20837. function HashArrayMapNode(ownerID, count, nodes) {
  20838. this.ownerID = ownerID;
  20839. this.count = count;
  20840. this.nodes = nodes;
  20841. }
  20842. HashArrayMapNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  20843. if (keyHash === undefined) {
  20844. keyHash = hash(key);
  20845. }
  20846. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  20847. var node = this.nodes[idx];
  20848. return node ? node.get(shift + SHIFT, keyHash, key, notSetValue) : notSetValue;
  20849. };
  20850. HashArrayMapNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  20851. if (keyHash === undefined) {
  20852. keyHash = hash(key);
  20853. }
  20854. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  20855. var removed = value === NOT_SET;
  20856. var nodes = this.nodes;
  20857. var node = nodes[idx];
  20858. if (removed && !node) {
  20859. return this;
  20860. }
  20861. var newNode = updateNode(node, ownerID, shift + SHIFT, keyHash, key, value, didChangeSize, didAlter);
  20862. if (newNode === node) {
  20863. return this;
  20864. }
  20865. var newCount = this.count;
  20866. if (!node) {
  20867. newCount++;
  20868. } else if (!newNode) {
  20869. newCount--;
  20870. if (newCount < MIN_HASH_ARRAY_MAP_SIZE) {
  20871. return packNodes(ownerID, nodes, newCount, idx);
  20872. }
  20873. }
  20874. var isEditable = ownerID && ownerID === this.ownerID;
  20875. var newNodes = setIn(nodes, idx, newNode, isEditable);
  20876. if (isEditable) {
  20877. this.count = newCount;
  20878. this.nodes = newNodes;
  20879. return this;
  20880. }
  20881. return new HashArrayMapNode(ownerID, newCount, newNodes);
  20882. };
  20883. function HashCollisionNode(ownerID, keyHash, entries) {
  20884. this.ownerID = ownerID;
  20885. this.keyHash = keyHash;
  20886. this.entries = entries;
  20887. }
  20888. HashCollisionNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  20889. var entries = this.entries;
  20890. for (var ii = 0, len = entries.length; ii < len; ii++) {
  20891. if (is(key, entries[ii][0])) {
  20892. return entries[ii][1];
  20893. }
  20894. }
  20895. return notSetValue;
  20896. };
  20897. HashCollisionNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  20898. if (keyHash === undefined) {
  20899. keyHash = hash(key);
  20900. }
  20901. var removed = value === NOT_SET;
  20902. if (keyHash !== this.keyHash) {
  20903. if (removed) {
  20904. return this;
  20905. }
  20906. SetRef(didAlter);
  20907. SetRef(didChangeSize);
  20908. return mergeIntoNode(this, ownerID, shift, keyHash, [key, value]);
  20909. }
  20910. var entries = this.entries;
  20911. var idx = 0;
  20912. for (var len = entries.length; idx < len; idx++) {
  20913. if (is(key, entries[idx][0])) {
  20914. break;
  20915. }
  20916. }
  20917. var exists = idx < len;
  20918. if (exists ? entries[idx][1] === value : removed) {
  20919. return this;
  20920. }
  20921. SetRef(didAlter);
  20922. (removed || !exists) && SetRef(didChangeSize);
  20923. if (removed && len === 2) {
  20924. return new ValueNode(ownerID, this.keyHash, entries[idx ^ 1]);
  20925. }
  20926. var isEditable = ownerID && ownerID === this.ownerID;
  20927. var newEntries = isEditable ? entries : arrCopy(entries);
  20928. if (exists) {
  20929. if (removed) {
  20930. idx === len - 1 ? newEntries.pop() : (newEntries[idx] = newEntries.pop());
  20931. } else {
  20932. newEntries[idx] = [key, value];
  20933. }
  20934. } else {
  20935. newEntries.push([key, value]);
  20936. }
  20937. if (isEditable) {
  20938. this.entries = newEntries;
  20939. return this;
  20940. }
  20941. return new HashCollisionNode(ownerID, this.keyHash, newEntries);
  20942. };
  20943. function ValueNode(ownerID, keyHash, entry) {
  20944. this.ownerID = ownerID;
  20945. this.keyHash = keyHash;
  20946. this.entry = entry;
  20947. }
  20948. ValueNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  20949. return is(key, this.entry[0]) ? this.entry[1] : notSetValue;
  20950. };
  20951. ValueNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  20952. var removed = value === NOT_SET;
  20953. var keyMatch = is(key, this.entry[0]);
  20954. if (keyMatch ? value === this.entry[1] : removed) {
  20955. return this;
  20956. }
  20957. SetRef(didAlter);
  20958. if (removed) {
  20959. SetRef(didChangeSize);
  20960. return; // undefined
  20961. }
  20962. if (keyMatch) {
  20963. if (ownerID && ownerID === this.ownerID) {
  20964. this.entry[1] = value;
  20965. return this;
  20966. }
  20967. return new ValueNode(ownerID, this.keyHash, [key, value]);
  20968. }
  20969. SetRef(didChangeSize);
  20970. return mergeIntoNode(this, ownerID, shift, hash(key), [key, value]);
  20971. };
  20972. // #pragma Iterators
  20973. ArrayMapNode.prototype.iterate =
  20974. HashCollisionNode.prototype.iterate = function (fn, reverse) {
  20975. var entries = this.entries;
  20976. for (var ii = 0, maxIndex = entries.length - 1; ii <= maxIndex; ii++) {
  20977. if (fn(entries[reverse ? maxIndex - ii : ii]) === false) {
  20978. return false;
  20979. }
  20980. }
  20981. };
  20982. BitmapIndexedNode.prototype.iterate =
  20983. HashArrayMapNode.prototype.iterate = function (fn, reverse) {
  20984. var nodes = this.nodes;
  20985. for (var ii = 0, maxIndex = nodes.length - 1; ii <= maxIndex; ii++) {
  20986. var node = nodes[reverse ? maxIndex - ii : ii];
  20987. if (node && node.iterate(fn, reverse) === false) {
  20988. return false;
  20989. }
  20990. }
  20991. };
  20992. ValueNode.prototype.iterate = function (fn, reverse) {
  20993. return fn(this.entry);
  20994. };
  20995. createClass(MapIterator, Iterator);
  20996. function MapIterator(map, type, reverse) {
  20997. this._type = type;
  20998. this._reverse = reverse;
  20999. this._stack = map._root && mapIteratorFrame(map._root);
  21000. }
  21001. MapIterator.prototype.next = function() {
  21002. var type = this._type;
  21003. var stack = this._stack;
  21004. while (stack) {
  21005. var node = stack.node;
  21006. var index = stack.index++;
  21007. var maxIndex;
  21008. if (node.entry) {
  21009. if (index === 0) {
  21010. return mapIteratorValue(type, node.entry);
  21011. }
  21012. } else if (node.entries) {
  21013. maxIndex = node.entries.length - 1;
  21014. if (index <= maxIndex) {
  21015. return mapIteratorValue(type, node.entries[this._reverse ? maxIndex - index : index]);
  21016. }
  21017. } else {
  21018. maxIndex = node.nodes.length - 1;
  21019. if (index <= maxIndex) {
  21020. var subNode = node.nodes[this._reverse ? maxIndex - index : index];
  21021. if (subNode) {
  21022. if (subNode.entry) {
  21023. return mapIteratorValue(type, subNode.entry);
  21024. }
  21025. stack = this._stack = mapIteratorFrame(subNode, stack);
  21026. }
  21027. continue;
  21028. }
  21029. }
  21030. stack = this._stack = this._stack.__prev;
  21031. }
  21032. return iteratorDone();
  21033. };
  21034. function mapIteratorValue(type, entry) {
  21035. return iteratorValue(type, entry[0], entry[1]);
  21036. }
  21037. function mapIteratorFrame(node, prev) {
  21038. return {
  21039. node: node,
  21040. index: 0,
  21041. __prev: prev
  21042. };
  21043. }
  21044. function makeMap(size, root, ownerID, hash) {
  21045. var map = Object.create(MapPrototype);
  21046. map.size = size;
  21047. map._root = root;
  21048. map.__ownerID = ownerID;
  21049. map.__hash = hash;
  21050. map.__altered = false;
  21051. return map;
  21052. }
  21053. var EMPTY_MAP;
  21054. function emptyMap() {
  21055. return EMPTY_MAP || (EMPTY_MAP = makeMap(0));
  21056. }
  21057. function updateMap(map, k, v) {
  21058. var newRoot;
  21059. var newSize;
  21060. if (!map._root) {
  21061. if (v === NOT_SET) {
  21062. return map;
  21063. }
  21064. newSize = 1;
  21065. newRoot = new ArrayMapNode(map.__ownerID, [[k, v]]);
  21066. } else {
  21067. var didChangeSize = MakeRef(CHANGE_LENGTH);
  21068. var didAlter = MakeRef(DID_ALTER);
  21069. newRoot = updateNode(map._root, map.__ownerID, 0, undefined, k, v, didChangeSize, didAlter);
  21070. if (!didAlter.value) {
  21071. return map;
  21072. }
  21073. newSize = map.size + (didChangeSize.value ? v === NOT_SET ? -1 : 1 : 0);
  21074. }
  21075. if (map.__ownerID) {
  21076. map.size = newSize;
  21077. map._root = newRoot;
  21078. map.__hash = undefined;
  21079. map.__altered = true;
  21080. return map;
  21081. }
  21082. return newRoot ? makeMap(newSize, newRoot) : emptyMap();
  21083. }
  21084. function updateNode(node, ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  21085. if (!node) {
  21086. if (value === NOT_SET) {
  21087. return node;
  21088. }
  21089. SetRef(didAlter);
  21090. SetRef(didChangeSize);
  21091. return new ValueNode(ownerID, keyHash, [key, value]);
  21092. }
  21093. return node.update(ownerID, shift, keyHash, key, value, didChangeSize, didAlter);
  21094. }
  21095. function isLeafNode(node) {
  21096. return node.constructor === ValueNode || node.constructor === HashCollisionNode;
  21097. }
  21098. function mergeIntoNode(node, ownerID, shift, keyHash, entry) {
  21099. if (node.keyHash === keyHash) {
  21100. return new HashCollisionNode(ownerID, keyHash, [node.entry, entry]);
  21101. }
  21102. var idx1 = (shift === 0 ? node.keyHash : node.keyHash >>> shift) & MASK;
  21103. var idx2 = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  21104. var newNode;
  21105. var nodes = idx1 === idx2 ?
  21106. [mergeIntoNode(node, ownerID, shift + SHIFT, keyHash, entry)] :
  21107. ((newNode = new ValueNode(ownerID, keyHash, entry)), idx1 < idx2 ? [node, newNode] : [newNode, node]);
  21108. return new BitmapIndexedNode(ownerID, (1 << idx1) | (1 << idx2), nodes);
  21109. }
  21110. function createNodes(ownerID, entries, key, value) {
  21111. if (!ownerID) {
  21112. ownerID = new OwnerID();
  21113. }
  21114. var node = new ValueNode(ownerID, hash(key), [key, value]);
  21115. for (var ii = 0; ii < entries.length; ii++) {
  21116. var entry = entries[ii];
  21117. node = node.update(ownerID, 0, undefined, entry[0], entry[1]);
  21118. }
  21119. return node;
  21120. }
  21121. function packNodes(ownerID, nodes, count, excluding) {
  21122. var bitmap = 0;
  21123. var packedII = 0;
  21124. var packedNodes = new Array(count);
  21125. for (var ii = 0, bit = 1, len = nodes.length; ii < len; ii++, bit <<= 1) {
  21126. var node = nodes[ii];
  21127. if (node !== undefined && ii !== excluding) {
  21128. bitmap |= bit;
  21129. packedNodes[packedII++] = node;
  21130. }
  21131. }
  21132. return new BitmapIndexedNode(ownerID, bitmap, packedNodes);
  21133. }
  21134. function expandNodes(ownerID, nodes, bitmap, including, node) {
  21135. var count = 0;
  21136. var expandedNodes = new Array(SIZE);
  21137. for (var ii = 0; bitmap !== 0; ii++, bitmap >>>= 1) {
  21138. expandedNodes[ii] = bitmap & 1 ? nodes[count++] : undefined;
  21139. }
  21140. expandedNodes[including] = node;
  21141. return new HashArrayMapNode(ownerID, count + 1, expandedNodes);
  21142. }
  21143. function mergeIntoMapWith(map, merger, iterables) {
  21144. var iters = [];
  21145. for (var ii = 0; ii < iterables.length; ii++) {
  21146. var value = iterables[ii];
  21147. var iter = KeyedIterable(value);
  21148. if (!isIterable(value)) {
  21149. iter = iter.map(function(v ) {return fromJS(v)});
  21150. }
  21151. iters.push(iter);
  21152. }
  21153. return mergeIntoCollectionWith(map, merger, iters);
  21154. }
  21155. function deepMerger(existing, value, key) {
  21156. return existing && existing.mergeDeep && isIterable(value) ?
  21157. existing.mergeDeep(value) :
  21158. is(existing, value) ? existing : value;
  21159. }
  21160. function deepMergerWith(merger) {
  21161. return function(existing, value, key) {
  21162. if (existing && existing.mergeDeepWith && isIterable(value)) {
  21163. return existing.mergeDeepWith(merger, value);
  21164. }
  21165. var nextValue = merger(existing, value, key);
  21166. return is(existing, nextValue) ? existing : nextValue;
  21167. };
  21168. }
  21169. function mergeIntoCollectionWith(collection, merger, iters) {
  21170. iters = iters.filter(function(x ) {return x.size !== 0});
  21171. if (iters.length === 0) {
  21172. return collection;
  21173. }
  21174. if (collection.size === 0 && !collection.__ownerID && iters.length === 1) {
  21175. return collection.constructor(iters[0]);
  21176. }
  21177. return collection.withMutations(function(collection ) {
  21178. var mergeIntoMap = merger ?
  21179. function(value, key) {
  21180. collection.update(key, NOT_SET, function(existing )
  21181. {return existing === NOT_SET ? value : merger(existing, value, key)}
  21182. );
  21183. } :
  21184. function(value, key) {
  21185. collection.set(key, value);
  21186. };
  21187. for (var ii = 0; ii < iters.length; ii++) {
  21188. iters[ii].forEach(mergeIntoMap);
  21189. }
  21190. });
  21191. }
  21192. function updateInDeepMap(existing, keyPathIter, notSetValue, updater) {
  21193. var isNotSet = existing === NOT_SET;
  21194. var step = keyPathIter.next();
  21195. if (step.done) {
  21196. var existingValue = isNotSet ? notSetValue : existing;
  21197. var newValue = updater(existingValue);
  21198. return newValue === existingValue ? existing : newValue;
  21199. }
  21200. invariant(
  21201. isNotSet || (existing && existing.set),
  21202. 'invalid keyPath'
  21203. );
  21204. var key = step.value;
  21205. var nextExisting = isNotSet ? NOT_SET : existing.get(key, NOT_SET);
  21206. var nextUpdated = updateInDeepMap(
  21207. nextExisting,
  21208. keyPathIter,
  21209. notSetValue,
  21210. updater
  21211. );
  21212. return nextUpdated === nextExisting ? existing :
  21213. nextUpdated === NOT_SET ? existing.remove(key) :
  21214. (isNotSet ? emptyMap() : existing).set(key, nextUpdated);
  21215. }
  21216. function popCount(x) {
  21217. x = x - ((x >> 1) & 0x55555555);
  21218. x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
  21219. x = (x + (x >> 4)) & 0x0f0f0f0f;
  21220. x = x + (x >> 8);
  21221. x = x + (x >> 16);
  21222. return x & 0x7f;
  21223. }
  21224. function setIn(array, idx, val, canEdit) {
  21225. var newArray = canEdit ? array : arrCopy(array);
  21226. newArray[idx] = val;
  21227. return newArray;
  21228. }
  21229. function spliceIn(array, idx, val, canEdit) {
  21230. var newLen = array.length + 1;
  21231. if (canEdit && idx + 1 === newLen) {
  21232. array[idx] = val;
  21233. return array;
  21234. }
  21235. var newArray = new Array(newLen);
  21236. var after = 0;
  21237. for (var ii = 0; ii < newLen; ii++) {
  21238. if (ii === idx) {
  21239. newArray[ii] = val;
  21240. after = -1;
  21241. } else {
  21242. newArray[ii] = array[ii + after];
  21243. }
  21244. }
  21245. return newArray;
  21246. }
  21247. function spliceOut(array, idx, canEdit) {
  21248. var newLen = array.length - 1;
  21249. if (canEdit && idx === newLen) {
  21250. array.pop();
  21251. return array;
  21252. }
  21253. var newArray = new Array(newLen);
  21254. var after = 0;
  21255. for (var ii = 0; ii < newLen; ii++) {
  21256. if (ii === idx) {
  21257. after = 1;
  21258. }
  21259. newArray[ii] = array[ii + after];
  21260. }
  21261. return newArray;
  21262. }
  21263. var MAX_ARRAY_MAP_SIZE = SIZE / 4;
  21264. var MAX_BITMAP_INDEXED_SIZE = SIZE / 2;
  21265. var MIN_HASH_ARRAY_MAP_SIZE = SIZE / 4;
  21266. createClass(List, IndexedCollection);
  21267. // @pragma Construction
  21268. function List(value) {
  21269. var empty = emptyList();
  21270. if (value === null || value === undefined) {
  21271. return empty;
  21272. }
  21273. if (isList(value)) {
  21274. return value;
  21275. }
  21276. var iter = IndexedIterable(value);
  21277. var size = iter.size;
  21278. if (size === 0) {
  21279. return empty;
  21280. }
  21281. assertNotInfinite(size);
  21282. if (size > 0 && size < SIZE) {
  21283. return makeList(0, size, SHIFT, null, new VNode(iter.toArray()));
  21284. }
  21285. return empty.withMutations(function(list ) {
  21286. list.setSize(size);
  21287. iter.forEach(function(v, i) {return list.set(i, v)});
  21288. });
  21289. }
  21290. List.of = function(/*...values*/) {
  21291. return this(arguments);
  21292. };
  21293. List.prototype.toString = function() {
  21294. return this.__toString('List [', ']');
  21295. };
  21296. // @pragma Access
  21297. List.prototype.get = function(index, notSetValue) {
  21298. index = wrapIndex(this, index);
  21299. if (index >= 0 && index < this.size) {
  21300. index += this._origin;
  21301. var node = listNodeFor(this, index);
  21302. return node && node.array[index & MASK];
  21303. }
  21304. return notSetValue;
  21305. };
  21306. // @pragma Modification
  21307. List.prototype.set = function(index, value) {
  21308. return updateList(this, index, value);
  21309. };
  21310. List.prototype.remove = function(index) {
  21311. return !this.has(index) ? this :
  21312. index === 0 ? this.shift() :
  21313. index === this.size - 1 ? this.pop() :
  21314. this.splice(index, 1);
  21315. };
  21316. List.prototype.insert = function(index, value) {
  21317. return this.splice(index, 0, value);
  21318. };
  21319. List.prototype.clear = function() {
  21320. if (this.size === 0) {
  21321. return this;
  21322. }
  21323. if (this.__ownerID) {
  21324. this.size = this._origin = this._capacity = 0;
  21325. this._level = SHIFT;
  21326. this._root = this._tail = null;
  21327. this.__hash = undefined;
  21328. this.__altered = true;
  21329. return this;
  21330. }
  21331. return emptyList();
  21332. };
  21333. List.prototype.push = function(/*...values*/) {
  21334. var values = arguments;
  21335. var oldSize = this.size;
  21336. return this.withMutations(function(list ) {
  21337. setListBounds(list, 0, oldSize + values.length);
  21338. for (var ii = 0; ii < values.length; ii++) {
  21339. list.set(oldSize + ii, values[ii]);
  21340. }
  21341. });
  21342. };
  21343. List.prototype.pop = function() {
  21344. return setListBounds(this, 0, -1);
  21345. };
  21346. List.prototype.unshift = function(/*...values*/) {
  21347. var values = arguments;
  21348. return this.withMutations(function(list ) {
  21349. setListBounds(list, -values.length);
  21350. for (var ii = 0; ii < values.length; ii++) {
  21351. list.set(ii, values[ii]);
  21352. }
  21353. });
  21354. };
  21355. List.prototype.shift = function() {
  21356. return setListBounds(this, 1);
  21357. };
  21358. // @pragma Composition
  21359. List.prototype.merge = function(/*...iters*/) {
  21360. return mergeIntoListWith(this, undefined, arguments);
  21361. };
  21362. List.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  21363. return mergeIntoListWith(this, merger, iters);
  21364. };
  21365. List.prototype.mergeDeep = function(/*...iters*/) {
  21366. return mergeIntoListWith(this, deepMerger, arguments);
  21367. };
  21368. List.prototype.mergeDeepWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  21369. return mergeIntoListWith(this, deepMergerWith(merger), iters);
  21370. };
  21371. List.prototype.setSize = function(size) {
  21372. return setListBounds(this, 0, size);
  21373. };
  21374. // @pragma Iteration
  21375. List.prototype.slice = function(begin, end) {
  21376. var size = this.size;
  21377. if (wholeSlice(begin, end, size)) {
  21378. return this;
  21379. }
  21380. return setListBounds(
  21381. this,
  21382. resolveBegin(begin, size),
  21383. resolveEnd(end, size)
  21384. );
  21385. };
  21386. List.prototype.__iterator = function(type, reverse) {
  21387. var index = 0;
  21388. var values = iterateList(this, reverse);
  21389. return new Iterator(function() {
  21390. var value = values();
  21391. return value === DONE ?
  21392. iteratorDone() :
  21393. iteratorValue(type, index++, value);
  21394. });
  21395. };
  21396. List.prototype.__iterate = function(fn, reverse) {
  21397. var index = 0;
  21398. var values = iterateList(this, reverse);
  21399. var value;
  21400. while ((value = values()) !== DONE) {
  21401. if (fn(value, index++, this) === false) {
  21402. break;
  21403. }
  21404. }
  21405. return index;
  21406. };
  21407. List.prototype.__ensureOwner = function(ownerID) {
  21408. if (ownerID === this.__ownerID) {
  21409. return this;
  21410. }
  21411. if (!ownerID) {
  21412. this.__ownerID = ownerID;
  21413. return this;
  21414. }
  21415. return makeList(this._origin, this._capacity, this._level, this._root, this._tail, ownerID, this.__hash);
  21416. };
  21417. function isList(maybeList) {
  21418. return !!(maybeList && maybeList[IS_LIST_SENTINEL]);
  21419. }
  21420. List.isList = isList;
  21421. var IS_LIST_SENTINEL = '@@__IMMUTABLE_LIST__@@';
  21422. var ListPrototype = List.prototype;
  21423. ListPrototype[IS_LIST_SENTINEL] = true;
  21424. ListPrototype[DELETE] = ListPrototype.remove;
  21425. ListPrototype.setIn = MapPrototype.setIn;
  21426. ListPrototype.deleteIn =
  21427. ListPrototype.removeIn = MapPrototype.removeIn;
  21428. ListPrototype.update = MapPrototype.update;
  21429. ListPrototype.updateIn = MapPrototype.updateIn;
  21430. ListPrototype.mergeIn = MapPrototype.mergeIn;
  21431. ListPrototype.mergeDeepIn = MapPrototype.mergeDeepIn;
  21432. ListPrototype.withMutations = MapPrototype.withMutations;
  21433. ListPrototype.asMutable = MapPrototype.asMutable;
  21434. ListPrototype.asImmutable = MapPrototype.asImmutable;
  21435. ListPrototype.wasAltered = MapPrototype.wasAltered;
  21436. function VNode(array, ownerID) {
  21437. this.array = array;
  21438. this.ownerID = ownerID;
  21439. }
  21440. // TODO: seems like these methods are very similar
  21441. VNode.prototype.removeBefore = function(ownerID, level, index) {
  21442. if (index === level ? 1 << level : this.array.length === 0) {
  21443. return this;
  21444. }
  21445. var originIndex = (index >>> level) & MASK;
  21446. if (originIndex >= this.array.length) {
  21447. return new VNode([], ownerID);
  21448. }
  21449. var removingFirst = originIndex === 0;
  21450. var newChild;
  21451. if (level > 0) {
  21452. var oldChild = this.array[originIndex];
  21453. newChild = oldChild && oldChild.removeBefore(ownerID, level - SHIFT, index);
  21454. if (newChild === oldChild && removingFirst) {
  21455. return this;
  21456. }
  21457. }
  21458. if (removingFirst && !newChild) {
  21459. return this;
  21460. }
  21461. var editable = editableVNode(this, ownerID);
  21462. if (!removingFirst) {
  21463. for (var ii = 0; ii < originIndex; ii++) {
  21464. editable.array[ii] = undefined;
  21465. }
  21466. }
  21467. if (newChild) {
  21468. editable.array[originIndex] = newChild;
  21469. }
  21470. return editable;
  21471. };
  21472. VNode.prototype.removeAfter = function(ownerID, level, index) {
  21473. if (index === (level ? 1 << level : 0) || this.array.length === 0) {
  21474. return this;
  21475. }
  21476. var sizeIndex = ((index - 1) >>> level) & MASK;
  21477. if (sizeIndex >= this.array.length) {
  21478. return this;
  21479. }
  21480. var newChild;
  21481. if (level > 0) {
  21482. var oldChild = this.array[sizeIndex];
  21483. newChild = oldChild && oldChild.removeAfter(ownerID, level - SHIFT, index);
  21484. if (newChild === oldChild && sizeIndex === this.array.length - 1) {
  21485. return this;
  21486. }
  21487. }
  21488. var editable = editableVNode(this, ownerID);
  21489. editable.array.splice(sizeIndex + 1);
  21490. if (newChild) {
  21491. editable.array[sizeIndex] = newChild;
  21492. }
  21493. return editable;
  21494. };
  21495. var DONE = {};
  21496. function iterateList(list, reverse) {
  21497. var left = list._origin;
  21498. var right = list._capacity;
  21499. var tailPos = getTailOffset(right);
  21500. var tail = list._tail;
  21501. return iterateNodeOrLeaf(list._root, list._level, 0);
  21502. function iterateNodeOrLeaf(node, level, offset) {
  21503. return level === 0 ?
  21504. iterateLeaf(node, offset) :
  21505. iterateNode(node, level, offset);
  21506. }
  21507. function iterateLeaf(node, offset) {
  21508. var array = offset === tailPos ? tail && tail.array : node && node.array;
  21509. var from = offset > left ? 0 : left - offset;
  21510. var to = right - offset;
  21511. if (to > SIZE) {
  21512. to = SIZE;
  21513. }
  21514. return function() {
  21515. if (from === to) {
  21516. return DONE;
  21517. }
  21518. var idx = reverse ? --to : from++;
  21519. return array && array[idx];
  21520. };
  21521. }
  21522. function iterateNode(node, level, offset) {
  21523. var values;
  21524. var array = node && node.array;
  21525. var from = offset > left ? 0 : (left - offset) >> level;
  21526. var to = ((right - offset) >> level) + 1;
  21527. if (to > SIZE) {
  21528. to = SIZE;
  21529. }
  21530. return function() {
  21531. do {
  21532. if (values) {
  21533. var value = values();
  21534. if (value !== DONE) {
  21535. return value;
  21536. }
  21537. values = null;
  21538. }
  21539. if (from === to) {
  21540. return DONE;
  21541. }
  21542. var idx = reverse ? --to : from++;
  21543. values = iterateNodeOrLeaf(
  21544. array && array[idx], level - SHIFT, offset + (idx << level)
  21545. );
  21546. } while (true);
  21547. };
  21548. }
  21549. }
  21550. function makeList(origin, capacity, level, root, tail, ownerID, hash) {
  21551. var list = Object.create(ListPrototype);
  21552. list.size = capacity - origin;
  21553. list._origin = origin;
  21554. list._capacity = capacity;
  21555. list._level = level;
  21556. list._root = root;
  21557. list._tail = tail;
  21558. list.__ownerID = ownerID;
  21559. list.__hash = hash;
  21560. list.__altered = false;
  21561. return list;
  21562. }
  21563. var EMPTY_LIST;
  21564. function emptyList() {
  21565. return EMPTY_LIST || (EMPTY_LIST = makeList(0, 0, SHIFT));
  21566. }
  21567. function updateList(list, index, value) {
  21568. index = wrapIndex(list, index);
  21569. if (index !== index) {
  21570. return list;
  21571. }
  21572. if (index >= list.size || index < 0) {
  21573. return list.withMutations(function(list ) {
  21574. index < 0 ?
  21575. setListBounds(list, index).set(0, value) :
  21576. setListBounds(list, 0, index + 1).set(index, value);
  21577. });
  21578. }
  21579. index += list._origin;
  21580. var newTail = list._tail;
  21581. var newRoot = list._root;
  21582. var didAlter = MakeRef(DID_ALTER);
  21583. if (index >= getTailOffset(list._capacity)) {
  21584. newTail = updateVNode(newTail, list.__ownerID, 0, index, value, didAlter);
  21585. } else {
  21586. newRoot = updateVNode(newRoot, list.__ownerID, list._level, index, value, didAlter);
  21587. }
  21588. if (!didAlter.value) {
  21589. return list;
  21590. }
  21591. if (list.__ownerID) {
  21592. list._root = newRoot;
  21593. list._tail = newTail;
  21594. list.__hash = undefined;
  21595. list.__altered = true;
  21596. return list;
  21597. }
  21598. return makeList(list._origin, list._capacity, list._level, newRoot, newTail);
  21599. }
  21600. function updateVNode(node, ownerID, level, index, value, didAlter) {
  21601. var idx = (index >>> level) & MASK;
  21602. var nodeHas = node && idx < node.array.length;
  21603. if (!nodeHas && value === undefined) {
  21604. return node;
  21605. }
  21606. var newNode;
  21607. if (level > 0) {
  21608. var lowerNode = node && node.array[idx];
  21609. var newLowerNode = updateVNode(lowerNode, ownerID, level - SHIFT, index, value, didAlter);
  21610. if (newLowerNode === lowerNode) {
  21611. return node;
  21612. }
  21613. newNode = editableVNode(node, ownerID);
  21614. newNode.array[idx] = newLowerNode;
  21615. return newNode;
  21616. }
  21617. if (nodeHas && node.array[idx] === value) {
  21618. return node;
  21619. }
  21620. SetRef(didAlter);
  21621. newNode = editableVNode(node, ownerID);
  21622. if (value === undefined && idx === newNode.array.length - 1) {
  21623. newNode.array.pop();
  21624. } else {
  21625. newNode.array[idx] = value;
  21626. }
  21627. return newNode;
  21628. }
  21629. function editableVNode(node, ownerID) {
  21630. if (ownerID && node && ownerID === node.ownerID) {
  21631. return node;
  21632. }
  21633. return new VNode(node ? node.array.slice() : [], ownerID);
  21634. }
  21635. function listNodeFor(list, rawIndex) {
  21636. if (rawIndex >= getTailOffset(list._capacity)) {
  21637. return list._tail;
  21638. }
  21639. if (rawIndex < 1 << (list._level + SHIFT)) {
  21640. var node = list._root;
  21641. var level = list._level;
  21642. while (node && level > 0) {
  21643. node = node.array[(rawIndex >>> level) & MASK];
  21644. level -= SHIFT;
  21645. }
  21646. return node;
  21647. }
  21648. }
  21649. function setListBounds(list, begin, end) {
  21650. // Sanitize begin & end using this shorthand for ToInt32(argument)
  21651. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  21652. if (begin !== undefined) {
  21653. begin = begin | 0;
  21654. }
  21655. if (end !== undefined) {
  21656. end = end | 0;
  21657. }
  21658. var owner = list.__ownerID || new OwnerID();
  21659. var oldOrigin = list._origin;
  21660. var oldCapacity = list._capacity;
  21661. var newOrigin = oldOrigin + begin;
  21662. var newCapacity = end === undefined ? oldCapacity : end < 0 ? oldCapacity + end : oldOrigin + end;
  21663. if (newOrigin === oldOrigin && newCapacity === oldCapacity) {
  21664. return list;
  21665. }
  21666. // If it's going to end after it starts, it's empty.
  21667. if (newOrigin >= newCapacity) {
  21668. return list.clear();
  21669. }
  21670. var newLevel = list._level;
  21671. var newRoot = list._root;
  21672. // New origin might need creating a higher root.
  21673. var offsetShift = 0;
  21674. while (newOrigin + offsetShift < 0) {
  21675. newRoot = new VNode(newRoot && newRoot.array.length ? [undefined, newRoot] : [], owner);
  21676. newLevel += SHIFT;
  21677. offsetShift += 1 << newLevel;
  21678. }
  21679. if (offsetShift) {
  21680. newOrigin += offsetShift;
  21681. oldOrigin += offsetShift;
  21682. newCapacity += offsetShift;
  21683. oldCapacity += offsetShift;
  21684. }
  21685. var oldTailOffset = getTailOffset(oldCapacity);
  21686. var newTailOffset = getTailOffset(newCapacity);
  21687. // New size might need creating a higher root.
  21688. while (newTailOffset >= 1 << (newLevel + SHIFT)) {
  21689. newRoot = new VNode(newRoot && newRoot.array.length ? [newRoot] : [], owner);
  21690. newLevel += SHIFT;
  21691. }
  21692. // Locate or create the new tail.
  21693. var oldTail = list._tail;
  21694. var newTail = newTailOffset < oldTailOffset ?
  21695. listNodeFor(list, newCapacity - 1) :
  21696. newTailOffset > oldTailOffset ? new VNode([], owner) : oldTail;
  21697. // Merge Tail into tree.
  21698. if (oldTail && newTailOffset > oldTailOffset && newOrigin < oldCapacity && oldTail.array.length) {
  21699. newRoot = editableVNode(newRoot, owner);
  21700. var node = newRoot;
  21701. for (var level = newLevel; level > SHIFT; level -= SHIFT) {
  21702. var idx = (oldTailOffset >>> level) & MASK;
  21703. node = node.array[idx] = editableVNode(node.array[idx], owner);
  21704. }
  21705. node.array[(oldTailOffset >>> SHIFT) & MASK] = oldTail;
  21706. }
  21707. // If the size has been reduced, there's a chance the tail needs to be trimmed.
  21708. if (newCapacity < oldCapacity) {
  21709. newTail = newTail && newTail.removeAfter(owner, 0, newCapacity);
  21710. }
  21711. // If the new origin is within the tail, then we do not need a root.
  21712. if (newOrigin >= newTailOffset) {
  21713. newOrigin -= newTailOffset;
  21714. newCapacity -= newTailOffset;
  21715. newLevel = SHIFT;
  21716. newRoot = null;
  21717. newTail = newTail && newTail.removeBefore(owner, 0, newOrigin);
  21718. // Otherwise, if the root has been trimmed, garbage collect.
  21719. } else if (newOrigin > oldOrigin || newTailOffset < oldTailOffset) {
  21720. offsetShift = 0;
  21721. // Identify the new top root node of the subtree of the old root.
  21722. while (newRoot) {
  21723. var beginIndex = (newOrigin >>> newLevel) & MASK;
  21724. if (beginIndex !== (newTailOffset >>> newLevel) & MASK) {
  21725. break;
  21726. }
  21727. if (beginIndex) {
  21728. offsetShift += (1 << newLevel) * beginIndex;
  21729. }
  21730. newLevel -= SHIFT;
  21731. newRoot = newRoot.array[beginIndex];
  21732. }
  21733. // Trim the new sides of the new root.
  21734. if (newRoot && newOrigin > oldOrigin) {
  21735. newRoot = newRoot.removeBefore(owner, newLevel, newOrigin - offsetShift);
  21736. }
  21737. if (newRoot && newTailOffset < oldTailOffset) {
  21738. newRoot = newRoot.removeAfter(owner, newLevel, newTailOffset - offsetShift);
  21739. }
  21740. if (offsetShift) {
  21741. newOrigin -= offsetShift;
  21742. newCapacity -= offsetShift;
  21743. }
  21744. }
  21745. if (list.__ownerID) {
  21746. list.size = newCapacity - newOrigin;
  21747. list._origin = newOrigin;
  21748. list._capacity = newCapacity;
  21749. list._level = newLevel;
  21750. list._root = newRoot;
  21751. list._tail = newTail;
  21752. list.__hash = undefined;
  21753. list.__altered = true;
  21754. return list;
  21755. }
  21756. return makeList(newOrigin, newCapacity, newLevel, newRoot, newTail);
  21757. }
  21758. function mergeIntoListWith(list, merger, iterables) {
  21759. var iters = [];
  21760. var maxSize = 0;
  21761. for (var ii = 0; ii < iterables.length; ii++) {
  21762. var value = iterables[ii];
  21763. var iter = IndexedIterable(value);
  21764. if (iter.size > maxSize) {
  21765. maxSize = iter.size;
  21766. }
  21767. if (!isIterable(value)) {
  21768. iter = iter.map(function(v ) {return fromJS(v)});
  21769. }
  21770. iters.push(iter);
  21771. }
  21772. if (maxSize > list.size) {
  21773. list = list.setSize(maxSize);
  21774. }
  21775. return mergeIntoCollectionWith(list, merger, iters);
  21776. }
  21777. function getTailOffset(size) {
  21778. return size < SIZE ? 0 : (((size - 1) >>> SHIFT) << SHIFT);
  21779. }
  21780. createClass(OrderedMap, Map);
  21781. // @pragma Construction
  21782. function OrderedMap(value) {
  21783. return value === null || value === undefined ? emptyOrderedMap() :
  21784. isOrderedMap(value) ? value :
  21785. emptyOrderedMap().withMutations(function(map ) {
  21786. var iter = KeyedIterable(value);
  21787. assertNotInfinite(iter.size);
  21788. iter.forEach(function(v, k) {return map.set(k, v)});
  21789. });
  21790. }
  21791. OrderedMap.of = function(/*...values*/) {
  21792. return this(arguments);
  21793. };
  21794. OrderedMap.prototype.toString = function() {
  21795. return this.__toString('OrderedMap {', '}');
  21796. };
  21797. // @pragma Access
  21798. OrderedMap.prototype.get = function(k, notSetValue) {
  21799. var index = this._map.get(k);
  21800. return index !== undefined ? this._list.get(index)[1] : notSetValue;
  21801. };
  21802. // @pragma Modification
  21803. OrderedMap.prototype.clear = function() {
  21804. if (this.size === 0) {
  21805. return this;
  21806. }
  21807. if (this.__ownerID) {
  21808. this.size = 0;
  21809. this._map.clear();
  21810. this._list.clear();
  21811. return this;
  21812. }
  21813. return emptyOrderedMap();
  21814. };
  21815. OrderedMap.prototype.set = function(k, v) {
  21816. return updateOrderedMap(this, k, v);
  21817. };
  21818. OrderedMap.prototype.remove = function(k) {
  21819. return updateOrderedMap(this, k, NOT_SET);
  21820. };
  21821. OrderedMap.prototype.wasAltered = function() {
  21822. return this._map.wasAltered() || this._list.wasAltered();
  21823. };
  21824. OrderedMap.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  21825. return this._list.__iterate(
  21826. function(entry ) {return entry && fn(entry[1], entry[0], this$0)},
  21827. reverse
  21828. );
  21829. };
  21830. OrderedMap.prototype.__iterator = function(type, reverse) {
  21831. return this._list.fromEntrySeq().__iterator(type, reverse);
  21832. };
  21833. OrderedMap.prototype.__ensureOwner = function(ownerID) {
  21834. if (ownerID === this.__ownerID) {
  21835. return this;
  21836. }
  21837. var newMap = this._map.__ensureOwner(ownerID);
  21838. var newList = this._list.__ensureOwner(ownerID);
  21839. if (!ownerID) {
  21840. this.__ownerID = ownerID;
  21841. this._map = newMap;
  21842. this._list = newList;
  21843. return this;
  21844. }
  21845. return makeOrderedMap(newMap, newList, ownerID, this.__hash);
  21846. };
  21847. function isOrderedMap(maybeOrderedMap) {
  21848. return isMap(maybeOrderedMap) && isOrdered(maybeOrderedMap);
  21849. }
  21850. OrderedMap.isOrderedMap = isOrderedMap;
  21851. OrderedMap.prototype[IS_ORDERED_SENTINEL] = true;
  21852. OrderedMap.prototype[DELETE] = OrderedMap.prototype.remove;
  21853. function makeOrderedMap(map, list, ownerID, hash) {
  21854. var omap = Object.create(OrderedMap.prototype);
  21855. omap.size = map ? map.size : 0;
  21856. omap._map = map;
  21857. omap._list = list;
  21858. omap.__ownerID = ownerID;
  21859. omap.__hash = hash;
  21860. return omap;
  21861. }
  21862. var EMPTY_ORDERED_MAP;
  21863. function emptyOrderedMap() {
  21864. return EMPTY_ORDERED_MAP || (EMPTY_ORDERED_MAP = makeOrderedMap(emptyMap(), emptyList()));
  21865. }
  21866. function updateOrderedMap(omap, k, v) {
  21867. var map = omap._map;
  21868. var list = omap._list;
  21869. var i = map.get(k);
  21870. var has = i !== undefined;
  21871. var newMap;
  21872. var newList;
  21873. if (v === NOT_SET) { // removed
  21874. if (!has) {
  21875. return omap;
  21876. }
  21877. if (list.size >= SIZE && list.size >= map.size * 2) {
  21878. newList = list.filter(function(entry, idx) {return entry !== undefined && i !== idx});
  21879. newMap = newList.toKeyedSeq().map(function(entry ) {return entry[0]}).flip().toMap();
  21880. if (omap.__ownerID) {
  21881. newMap.__ownerID = newList.__ownerID = omap.__ownerID;
  21882. }
  21883. } else {
  21884. newMap = map.remove(k);
  21885. newList = i === list.size - 1 ? list.pop() : list.set(i, undefined);
  21886. }
  21887. } else {
  21888. if (has) {
  21889. if (v === list.get(i)[1]) {
  21890. return omap;
  21891. }
  21892. newMap = map;
  21893. newList = list.set(i, [k, v]);
  21894. } else {
  21895. newMap = map.set(k, list.size);
  21896. newList = list.set(list.size, [k, v]);
  21897. }
  21898. }
  21899. if (omap.__ownerID) {
  21900. omap.size = newMap.size;
  21901. omap._map = newMap;
  21902. omap._list = newList;
  21903. omap.__hash = undefined;
  21904. return omap;
  21905. }
  21906. return makeOrderedMap(newMap, newList);
  21907. }
  21908. createClass(ToKeyedSequence, KeyedSeq);
  21909. function ToKeyedSequence(indexed, useKeys) {
  21910. this._iter = indexed;
  21911. this._useKeys = useKeys;
  21912. this.size = indexed.size;
  21913. }
  21914. ToKeyedSequence.prototype.get = function(key, notSetValue) {
  21915. return this._iter.get(key, notSetValue);
  21916. };
  21917. ToKeyedSequence.prototype.has = function(key) {
  21918. return this._iter.has(key);
  21919. };
  21920. ToKeyedSequence.prototype.valueSeq = function() {
  21921. return this._iter.valueSeq();
  21922. };
  21923. ToKeyedSequence.prototype.reverse = function() {var this$0 = this;
  21924. var reversedSequence = reverseFactory(this, true);
  21925. if (!this._useKeys) {
  21926. reversedSequence.valueSeq = function() {return this$0._iter.toSeq().reverse()};
  21927. }
  21928. return reversedSequence;
  21929. };
  21930. ToKeyedSequence.prototype.map = function(mapper, context) {var this$0 = this;
  21931. var mappedSequence = mapFactory(this, mapper, context);
  21932. if (!this._useKeys) {
  21933. mappedSequence.valueSeq = function() {return this$0._iter.toSeq().map(mapper, context)};
  21934. }
  21935. return mappedSequence;
  21936. };
  21937. ToKeyedSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  21938. var ii;
  21939. return this._iter.__iterate(
  21940. this._useKeys ?
  21941. function(v, k) {return fn(v, k, this$0)} :
  21942. ((ii = reverse ? resolveSize(this) : 0),
  21943. function(v ) {return fn(v, reverse ? --ii : ii++, this$0)}),
  21944. reverse
  21945. );
  21946. };
  21947. ToKeyedSequence.prototype.__iterator = function(type, reverse) {
  21948. if (this._useKeys) {
  21949. return this._iter.__iterator(type, reverse);
  21950. }
  21951. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  21952. var ii = reverse ? resolveSize(this) : 0;
  21953. return new Iterator(function() {
  21954. var step = iterator.next();
  21955. return step.done ? step :
  21956. iteratorValue(type, reverse ? --ii : ii++, step.value, step);
  21957. });
  21958. };
  21959. ToKeyedSequence.prototype[IS_ORDERED_SENTINEL] = true;
  21960. createClass(ToIndexedSequence, IndexedSeq);
  21961. function ToIndexedSequence(iter) {
  21962. this._iter = iter;
  21963. this.size = iter.size;
  21964. }
  21965. ToIndexedSequence.prototype.includes = function(value) {
  21966. return this._iter.includes(value);
  21967. };
  21968. ToIndexedSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  21969. var iterations = 0;
  21970. return this._iter.__iterate(function(v ) {return fn(v, iterations++, this$0)}, reverse);
  21971. };
  21972. ToIndexedSequence.prototype.__iterator = function(type, reverse) {
  21973. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  21974. var iterations = 0;
  21975. return new Iterator(function() {
  21976. var step = iterator.next();
  21977. return step.done ? step :
  21978. iteratorValue(type, iterations++, step.value, step)
  21979. });
  21980. };
  21981. createClass(ToSetSequence, SetSeq);
  21982. function ToSetSequence(iter) {
  21983. this._iter = iter;
  21984. this.size = iter.size;
  21985. }
  21986. ToSetSequence.prototype.has = function(key) {
  21987. return this._iter.includes(key);
  21988. };
  21989. ToSetSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  21990. return this._iter.__iterate(function(v ) {return fn(v, v, this$0)}, reverse);
  21991. };
  21992. ToSetSequence.prototype.__iterator = function(type, reverse) {
  21993. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  21994. return new Iterator(function() {
  21995. var step = iterator.next();
  21996. return step.done ? step :
  21997. iteratorValue(type, step.value, step.value, step);
  21998. });
  21999. };
  22000. createClass(FromEntriesSequence, KeyedSeq);
  22001. function FromEntriesSequence(entries) {
  22002. this._iter = entries;
  22003. this.size = entries.size;
  22004. }
  22005. FromEntriesSequence.prototype.entrySeq = function() {
  22006. return this._iter.toSeq();
  22007. };
  22008. FromEntriesSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  22009. return this._iter.__iterate(function(entry ) {
  22010. // Check if entry exists first so array access doesn't throw for holes
  22011. // in the parent iteration.
  22012. if (entry) {
  22013. validateEntry(entry);
  22014. var indexedIterable = isIterable(entry);
  22015. return fn(
  22016. indexedIterable ? entry.get(1) : entry[1],
  22017. indexedIterable ? entry.get(0) : entry[0],
  22018. this$0
  22019. );
  22020. }
  22021. }, reverse);
  22022. };
  22023. FromEntriesSequence.prototype.__iterator = function(type, reverse) {
  22024. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  22025. return new Iterator(function() {
  22026. while (true) {
  22027. var step = iterator.next();
  22028. if (step.done) {
  22029. return step;
  22030. }
  22031. var entry = step.value;
  22032. // Check if entry exists first so array access doesn't throw for holes
  22033. // in the parent iteration.
  22034. if (entry) {
  22035. validateEntry(entry);
  22036. var indexedIterable = isIterable(entry);
  22037. return iteratorValue(
  22038. type,
  22039. indexedIterable ? entry.get(0) : entry[0],
  22040. indexedIterable ? entry.get(1) : entry[1],
  22041. step
  22042. );
  22043. }
  22044. }
  22045. });
  22046. };
  22047. ToIndexedSequence.prototype.cacheResult =
  22048. ToKeyedSequence.prototype.cacheResult =
  22049. ToSetSequence.prototype.cacheResult =
  22050. FromEntriesSequence.prototype.cacheResult =
  22051. cacheResultThrough;
  22052. function flipFactory(iterable) {
  22053. var flipSequence = makeSequence(iterable);
  22054. flipSequence._iter = iterable;
  22055. flipSequence.size = iterable.size;
  22056. flipSequence.flip = function() {return iterable};
  22057. flipSequence.reverse = function () {
  22058. var reversedSequence = iterable.reverse.apply(this); // super.reverse()
  22059. reversedSequence.flip = function() {return iterable.reverse()};
  22060. return reversedSequence;
  22061. };
  22062. flipSequence.has = function(key ) {return iterable.includes(key)};
  22063. flipSequence.includes = function(key ) {return iterable.has(key)};
  22064. flipSequence.cacheResult = cacheResultThrough;
  22065. flipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  22066. return iterable.__iterate(function(v, k) {return fn(k, v, this$0) !== false}, reverse);
  22067. };
  22068. flipSequence.__iteratorUncached = function(type, reverse) {
  22069. if (type === ITERATE_ENTRIES) {
  22070. var iterator = iterable.__iterator(type, reverse);
  22071. return new Iterator(function() {
  22072. var step = iterator.next();
  22073. if (!step.done) {
  22074. var k = step.value[0];
  22075. step.value[0] = step.value[1];
  22076. step.value[1] = k;
  22077. }
  22078. return step;
  22079. });
  22080. }
  22081. return iterable.__iterator(
  22082. type === ITERATE_VALUES ? ITERATE_KEYS : ITERATE_VALUES,
  22083. reverse
  22084. );
  22085. };
  22086. return flipSequence;
  22087. }
  22088. function mapFactory(iterable, mapper, context) {
  22089. var mappedSequence = makeSequence(iterable);
  22090. mappedSequence.size = iterable.size;
  22091. mappedSequence.has = function(key ) {return iterable.has(key)};
  22092. mappedSequence.get = function(key, notSetValue) {
  22093. var v = iterable.get(key, NOT_SET);
  22094. return v === NOT_SET ?
  22095. notSetValue :
  22096. mapper.call(context, v, key, iterable);
  22097. };
  22098. mappedSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  22099. return iterable.__iterate(
  22100. function(v, k, c) {return fn(mapper.call(context, v, k, c), k, this$0) !== false},
  22101. reverse
  22102. );
  22103. };
  22104. mappedSequence.__iteratorUncached = function (type, reverse) {
  22105. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  22106. return new Iterator(function() {
  22107. var step = iterator.next();
  22108. if (step.done) {
  22109. return step;
  22110. }
  22111. var entry = step.value;
  22112. var key = entry[0];
  22113. return iteratorValue(
  22114. type,
  22115. key,
  22116. mapper.call(context, entry[1], key, iterable),
  22117. step
  22118. );
  22119. });
  22120. };
  22121. return mappedSequence;
  22122. }
  22123. function reverseFactory(iterable, useKeys) {
  22124. var reversedSequence = makeSequence(iterable);
  22125. reversedSequence._iter = iterable;
  22126. reversedSequence.size = iterable.size;
  22127. reversedSequence.reverse = function() {return iterable};
  22128. if (iterable.flip) {
  22129. reversedSequence.flip = function () {
  22130. var flipSequence = flipFactory(iterable);
  22131. flipSequence.reverse = function() {return iterable.flip()};
  22132. return flipSequence;
  22133. };
  22134. }
  22135. reversedSequence.get = function(key, notSetValue)
  22136. {return iterable.get(useKeys ? key : -1 - key, notSetValue)};
  22137. reversedSequence.has = function(key )
  22138. {return iterable.has(useKeys ? key : -1 - key)};
  22139. reversedSequence.includes = function(value ) {return iterable.includes(value)};
  22140. reversedSequence.cacheResult = cacheResultThrough;
  22141. reversedSequence.__iterate = function (fn, reverse) {var this$0 = this;
  22142. return iterable.__iterate(function(v, k) {return fn(v, k, this$0)}, !reverse);
  22143. };
  22144. reversedSequence.__iterator =
  22145. function(type, reverse) {return iterable.__iterator(type, !reverse)};
  22146. return reversedSequence;
  22147. }
  22148. function filterFactory(iterable, predicate, context, useKeys) {
  22149. var filterSequence = makeSequence(iterable);
  22150. if (useKeys) {
  22151. filterSequence.has = function(key ) {
  22152. var v = iterable.get(key, NOT_SET);
  22153. return v !== NOT_SET && !!predicate.call(context, v, key, iterable);
  22154. };
  22155. filterSequence.get = function(key, notSetValue) {
  22156. var v = iterable.get(key, NOT_SET);
  22157. return v !== NOT_SET && predicate.call(context, v, key, iterable) ?
  22158. v : notSetValue;
  22159. };
  22160. }
  22161. filterSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  22162. var iterations = 0;
  22163. iterable.__iterate(function(v, k, c) {
  22164. if (predicate.call(context, v, k, c)) {
  22165. iterations++;
  22166. return fn(v, useKeys ? k : iterations - 1, this$0);
  22167. }
  22168. }, reverse);
  22169. return iterations;
  22170. };
  22171. filterSequence.__iteratorUncached = function (type, reverse) {
  22172. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  22173. var iterations = 0;
  22174. return new Iterator(function() {
  22175. while (true) {
  22176. var step = iterator.next();
  22177. if (step.done) {
  22178. return step;
  22179. }
  22180. var entry = step.value;
  22181. var key = entry[0];
  22182. var value = entry[1];
  22183. if (predicate.call(context, value, key, iterable)) {
  22184. return iteratorValue(type, useKeys ? key : iterations++, value, step);
  22185. }
  22186. }
  22187. });
  22188. };
  22189. return filterSequence;
  22190. }
  22191. function countByFactory(iterable, grouper, context) {
  22192. var groups = Map().asMutable();
  22193. iterable.__iterate(function(v, k) {
  22194. groups.update(
  22195. grouper.call(context, v, k, iterable),
  22196. 0,
  22197. function(a ) {return a + 1}
  22198. );
  22199. });
  22200. return groups.asImmutable();
  22201. }
  22202. function groupByFactory(iterable, grouper, context) {
  22203. var isKeyedIter = isKeyed(iterable);
  22204. var groups = (isOrdered(iterable) ? OrderedMap() : Map()).asMutable();
  22205. iterable.__iterate(function(v, k) {
  22206. groups.update(
  22207. grouper.call(context, v, k, iterable),
  22208. function(a ) {return (a = a || [], a.push(isKeyedIter ? [k, v] : v), a)}
  22209. );
  22210. });
  22211. var coerce = iterableClass(iterable);
  22212. return groups.map(function(arr ) {return reify(iterable, coerce(arr))});
  22213. }
  22214. function sliceFactory(iterable, begin, end, useKeys) {
  22215. var originalSize = iterable.size;
  22216. // Sanitize begin & end using this shorthand for ToInt32(argument)
  22217. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  22218. if (begin !== undefined) {
  22219. begin = begin | 0;
  22220. }
  22221. if (end !== undefined) {
  22222. end = end | 0;
  22223. }
  22224. if (wholeSlice(begin, end, originalSize)) {
  22225. return iterable;
  22226. }
  22227. var resolvedBegin = resolveBegin(begin, originalSize);
  22228. var resolvedEnd = resolveEnd(end, originalSize);
  22229. // begin or end will be NaN if they were provided as negative numbers and
  22230. // this iterable's size is unknown. In that case, cache first so there is
  22231. // a known size and these do not resolve to NaN.
  22232. if (resolvedBegin !== resolvedBegin || resolvedEnd !== resolvedEnd) {
  22233. return sliceFactory(iterable.toSeq().cacheResult(), begin, end, useKeys);
  22234. }
  22235. // Note: resolvedEnd is undefined when the original sequence's length is
  22236. // unknown and this slice did not supply an end and should contain all
  22237. // elements after resolvedBegin.
  22238. // In that case, resolvedSize will be NaN and sliceSize will remain undefined.
  22239. var resolvedSize = resolvedEnd - resolvedBegin;
  22240. var sliceSize;
  22241. if (resolvedSize === resolvedSize) {
  22242. sliceSize = resolvedSize < 0 ? 0 : resolvedSize;
  22243. }
  22244. var sliceSeq = makeSequence(iterable);
  22245. // If iterable.size is undefined, the size of the realized sliceSeq is
  22246. // unknown at this point unless the number of items to slice is 0
  22247. sliceSeq.size = sliceSize === 0 ? sliceSize : iterable.size && sliceSize || undefined;
  22248. if (!useKeys && isSeq(iterable) && sliceSize >= 0) {
  22249. sliceSeq.get = function (index, notSetValue) {
  22250. index = wrapIndex(this, index);
  22251. return index >= 0 && index < sliceSize ?
  22252. iterable.get(index + resolvedBegin, notSetValue) :
  22253. notSetValue;
  22254. };
  22255. }
  22256. sliceSeq.__iterateUncached = function(fn, reverse) {var this$0 = this;
  22257. if (sliceSize === 0) {
  22258. return 0;
  22259. }
  22260. if (reverse) {
  22261. return this.cacheResult().__iterate(fn, reverse);
  22262. }
  22263. var skipped = 0;
  22264. var isSkipping = true;
  22265. var iterations = 0;
  22266. iterable.__iterate(function(v, k) {
  22267. if (!(isSkipping && (isSkipping = skipped++ < resolvedBegin))) {
  22268. iterations++;
  22269. return fn(v, useKeys ? k : iterations - 1, this$0) !== false &&
  22270. iterations !== sliceSize;
  22271. }
  22272. });
  22273. return iterations;
  22274. };
  22275. sliceSeq.__iteratorUncached = function(type, reverse) {
  22276. if (sliceSize !== 0 && reverse) {
  22277. return this.cacheResult().__iterator(type, reverse);
  22278. }
  22279. // Don't bother instantiating parent iterator if taking 0.
  22280. var iterator = sliceSize !== 0 && iterable.__iterator(type, reverse);
  22281. var skipped = 0;
  22282. var iterations = 0;
  22283. return new Iterator(function() {
  22284. while (skipped++ < resolvedBegin) {
  22285. iterator.next();
  22286. }
  22287. if (++iterations > sliceSize) {
  22288. return iteratorDone();
  22289. }
  22290. var step = iterator.next();
  22291. if (useKeys || type === ITERATE_VALUES) {
  22292. return step;
  22293. } else if (type === ITERATE_KEYS) {
  22294. return iteratorValue(type, iterations - 1, undefined, step);
  22295. } else {
  22296. return iteratorValue(type, iterations - 1, step.value[1], step);
  22297. }
  22298. });
  22299. };
  22300. return sliceSeq;
  22301. }
  22302. function takeWhileFactory(iterable, predicate, context) {
  22303. var takeSequence = makeSequence(iterable);
  22304. takeSequence.__iterateUncached = function(fn, reverse) {var this$0 = this;
  22305. if (reverse) {
  22306. return this.cacheResult().__iterate(fn, reverse);
  22307. }
  22308. var iterations = 0;
  22309. iterable.__iterate(function(v, k, c)
  22310. {return predicate.call(context, v, k, c) && ++iterations && fn(v, k, this$0)}
  22311. );
  22312. return iterations;
  22313. };
  22314. takeSequence.__iteratorUncached = function(type, reverse) {var this$0 = this;
  22315. if (reverse) {
  22316. return this.cacheResult().__iterator(type, reverse);
  22317. }
  22318. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  22319. var iterating = true;
  22320. return new Iterator(function() {
  22321. if (!iterating) {
  22322. return iteratorDone();
  22323. }
  22324. var step = iterator.next();
  22325. if (step.done) {
  22326. return step;
  22327. }
  22328. var entry = step.value;
  22329. var k = entry[0];
  22330. var v = entry[1];
  22331. if (!predicate.call(context, v, k, this$0)) {
  22332. iterating = false;
  22333. return iteratorDone();
  22334. }
  22335. return type === ITERATE_ENTRIES ? step :
  22336. iteratorValue(type, k, v, step);
  22337. });
  22338. };
  22339. return takeSequence;
  22340. }
  22341. function skipWhileFactory(iterable, predicate, context, useKeys) {
  22342. var skipSequence = makeSequence(iterable);
  22343. skipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  22344. if (reverse) {
  22345. return this.cacheResult().__iterate(fn, reverse);
  22346. }
  22347. var isSkipping = true;
  22348. var iterations = 0;
  22349. iterable.__iterate(function(v, k, c) {
  22350. if (!(isSkipping && (isSkipping = predicate.call(context, v, k, c)))) {
  22351. iterations++;
  22352. return fn(v, useKeys ? k : iterations - 1, this$0);
  22353. }
  22354. });
  22355. return iterations;
  22356. };
  22357. skipSequence.__iteratorUncached = function(type, reverse) {var this$0 = this;
  22358. if (reverse) {
  22359. return this.cacheResult().__iterator(type, reverse);
  22360. }
  22361. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  22362. var skipping = true;
  22363. var iterations = 0;
  22364. return new Iterator(function() {
  22365. var step, k, v;
  22366. do {
  22367. step = iterator.next();
  22368. if (step.done) {
  22369. if (useKeys || type === ITERATE_VALUES) {
  22370. return step;
  22371. } else if (type === ITERATE_KEYS) {
  22372. return iteratorValue(type, iterations++, undefined, step);
  22373. } else {
  22374. return iteratorValue(type, iterations++, step.value[1], step);
  22375. }
  22376. }
  22377. var entry = step.value;
  22378. k = entry[0];
  22379. v = entry[1];
  22380. skipping && (skipping = predicate.call(context, v, k, this$0));
  22381. } while (skipping);
  22382. return type === ITERATE_ENTRIES ? step :
  22383. iteratorValue(type, k, v, step);
  22384. });
  22385. };
  22386. return skipSequence;
  22387. }
  22388. function concatFactory(iterable, values) {
  22389. var isKeyedIterable = isKeyed(iterable);
  22390. var iters = [iterable].concat(values).map(function(v ) {
  22391. if (!isIterable(v)) {
  22392. v = isKeyedIterable ?
  22393. keyedSeqFromValue(v) :
  22394. indexedSeqFromValue(Array.isArray(v) ? v : [v]);
  22395. } else if (isKeyedIterable) {
  22396. v = KeyedIterable(v);
  22397. }
  22398. return v;
  22399. }).filter(function(v ) {return v.size !== 0});
  22400. if (iters.length === 0) {
  22401. return iterable;
  22402. }
  22403. if (iters.length === 1) {
  22404. var singleton = iters[0];
  22405. if (singleton === iterable ||
  22406. isKeyedIterable && isKeyed(singleton) ||
  22407. isIndexed(iterable) && isIndexed(singleton)) {
  22408. return singleton;
  22409. }
  22410. }
  22411. var concatSeq = new ArraySeq(iters);
  22412. if (isKeyedIterable) {
  22413. concatSeq = concatSeq.toKeyedSeq();
  22414. } else if (!isIndexed(iterable)) {
  22415. concatSeq = concatSeq.toSetSeq();
  22416. }
  22417. concatSeq = concatSeq.flatten(true);
  22418. concatSeq.size = iters.reduce(
  22419. function(sum, seq) {
  22420. if (sum !== undefined) {
  22421. var size = seq.size;
  22422. if (size !== undefined) {
  22423. return sum + size;
  22424. }
  22425. }
  22426. },
  22427. 0
  22428. );
  22429. return concatSeq;
  22430. }
  22431. function flattenFactory(iterable, depth, useKeys) {
  22432. var flatSequence = makeSequence(iterable);
  22433. flatSequence.__iterateUncached = function(fn, reverse) {
  22434. var iterations = 0;
  22435. var stopped = false;
  22436. function flatDeep(iter, currentDepth) {var this$0 = this;
  22437. iter.__iterate(function(v, k) {
  22438. if ((!depth || currentDepth < depth) && isIterable(v)) {
  22439. flatDeep(v, currentDepth + 1);
  22440. } else if (fn(v, useKeys ? k : iterations++, this$0) === false) {
  22441. stopped = true;
  22442. }
  22443. return !stopped;
  22444. }, reverse);
  22445. }
  22446. flatDeep(iterable, 0);
  22447. return iterations;
  22448. };
  22449. flatSequence.__iteratorUncached = function(type, reverse) {
  22450. var iterator = iterable.__iterator(type, reverse);
  22451. var stack = [];
  22452. var iterations = 0;
  22453. return new Iterator(function() {
  22454. while (iterator) {
  22455. var step = iterator.next();
  22456. if (step.done !== false) {
  22457. iterator = stack.pop();
  22458. continue;
  22459. }
  22460. var v = step.value;
  22461. if (type === ITERATE_ENTRIES) {
  22462. v = v[1];
  22463. }
  22464. if ((!depth || stack.length < depth) && isIterable(v)) {
  22465. stack.push(iterator);
  22466. iterator = v.__iterator(type, reverse);
  22467. } else {
  22468. return useKeys ? step : iteratorValue(type, iterations++, v, step);
  22469. }
  22470. }
  22471. return iteratorDone();
  22472. });
  22473. };
  22474. return flatSequence;
  22475. }
  22476. function flatMapFactory(iterable, mapper, context) {
  22477. var coerce = iterableClass(iterable);
  22478. return iterable.toSeq().map(
  22479. function(v, k) {return coerce(mapper.call(context, v, k, iterable))}
  22480. ).flatten(true);
  22481. }
  22482. function interposeFactory(iterable, separator) {
  22483. var interposedSequence = makeSequence(iterable);
  22484. interposedSequence.size = iterable.size && iterable.size * 2 -1;
  22485. interposedSequence.__iterateUncached = function(fn, reverse) {var this$0 = this;
  22486. var iterations = 0;
  22487. iterable.__iterate(function(v, k)
  22488. {return (!iterations || fn(separator, iterations++, this$0) !== false) &&
  22489. fn(v, iterations++, this$0) !== false},
  22490. reverse
  22491. );
  22492. return iterations;
  22493. };
  22494. interposedSequence.__iteratorUncached = function(type, reverse) {
  22495. var iterator = iterable.__iterator(ITERATE_VALUES, reverse);
  22496. var iterations = 0;
  22497. var step;
  22498. return new Iterator(function() {
  22499. if (!step || iterations % 2) {
  22500. step = iterator.next();
  22501. if (step.done) {
  22502. return step;
  22503. }
  22504. }
  22505. return iterations % 2 ?
  22506. iteratorValue(type, iterations++, separator) :
  22507. iteratorValue(type, iterations++, step.value, step);
  22508. });
  22509. };
  22510. return interposedSequence;
  22511. }
  22512. function sortFactory(iterable, comparator, mapper) {
  22513. if (!comparator) {
  22514. comparator = defaultComparator;
  22515. }
  22516. var isKeyedIterable = isKeyed(iterable);
  22517. var index = 0;
  22518. var entries = iterable.toSeq().map(
  22519. function(v, k) {return [k, v, index++, mapper ? mapper(v, k, iterable) : v]}
  22520. ).toArray();
  22521. entries.sort(function(a, b) {return comparator(a[3], b[3]) || a[2] - b[2]}).forEach(
  22522. isKeyedIterable ?
  22523. function(v, i) { entries[i].length = 2; } :
  22524. function(v, i) { entries[i] = v[1]; }
  22525. );
  22526. return isKeyedIterable ? KeyedSeq(entries) :
  22527. isIndexed(iterable) ? IndexedSeq(entries) :
  22528. SetSeq(entries);
  22529. }
  22530. function maxFactory(iterable, comparator, mapper) {
  22531. if (!comparator) {
  22532. comparator = defaultComparator;
  22533. }
  22534. if (mapper) {
  22535. var entry = iterable.toSeq()
  22536. .map(function(v, k) {return [v, mapper(v, k, iterable)]})
  22537. .reduce(function(a, b) {return maxCompare(comparator, a[1], b[1]) ? b : a});
  22538. return entry && entry[0];
  22539. } else {
  22540. return iterable.reduce(function(a, b) {return maxCompare(comparator, a, b) ? b : a});
  22541. }
  22542. }
  22543. function maxCompare(comparator, a, b) {
  22544. var comp = comparator(b, a);
  22545. // b is considered the new max if the comparator declares them equal, but
  22546. // they are not equal and b is in fact a nullish value.
  22547. return (comp === 0 && b !== a && (b === undefined || b === null || b !== b)) || comp > 0;
  22548. }
  22549. function zipWithFactory(keyIter, zipper, iters) {
  22550. var zipSequence = makeSequence(keyIter);
  22551. zipSequence.size = new ArraySeq(iters).map(function(i ) {return i.size}).min();
  22552. // Note: this a generic base implementation of __iterate in terms of
  22553. // __iterator which may be more generically useful in the future.
  22554. zipSequence.__iterate = function(fn, reverse) {
  22555. /* generic:
  22556. var iterator = this.__iterator(ITERATE_ENTRIES, reverse);
  22557. var step;
  22558. var iterations = 0;
  22559. while (!(step = iterator.next()).done) {
  22560. iterations++;
  22561. if (fn(step.value[1], step.value[0], this) === false) {
  22562. break;
  22563. }
  22564. }
  22565. return iterations;
  22566. */
  22567. // indexed:
  22568. var iterator = this.__iterator(ITERATE_VALUES, reverse);
  22569. var step;
  22570. var iterations = 0;
  22571. while (!(step = iterator.next()).done) {
  22572. if (fn(step.value, iterations++, this) === false) {
  22573. break;
  22574. }
  22575. }
  22576. return iterations;
  22577. };
  22578. zipSequence.__iteratorUncached = function(type, reverse) {
  22579. var iterators = iters.map(function(i )
  22580. {return (i = Iterable(i), getIterator(reverse ? i.reverse() : i))}
  22581. );
  22582. var iterations = 0;
  22583. var isDone = false;
  22584. return new Iterator(function() {
  22585. var steps;
  22586. if (!isDone) {
  22587. steps = iterators.map(function(i ) {return i.next()});
  22588. isDone = steps.some(function(s ) {return s.done});
  22589. }
  22590. if (isDone) {
  22591. return iteratorDone();
  22592. }
  22593. return iteratorValue(
  22594. type,
  22595. iterations++,
  22596. zipper.apply(null, steps.map(function(s ) {return s.value}))
  22597. );
  22598. });
  22599. };
  22600. return zipSequence
  22601. }
  22602. // #pragma Helper Functions
  22603. function reify(iter, seq) {
  22604. return isSeq(iter) ? seq : iter.constructor(seq);
  22605. }
  22606. function validateEntry(entry) {
  22607. if (entry !== Object(entry)) {
  22608. throw new TypeError('Expected [K, V] tuple: ' + entry);
  22609. }
  22610. }
  22611. function resolveSize(iter) {
  22612. assertNotInfinite(iter.size);
  22613. return ensureSize(iter);
  22614. }
  22615. function iterableClass(iterable) {
  22616. return isKeyed(iterable) ? KeyedIterable :
  22617. isIndexed(iterable) ? IndexedIterable :
  22618. SetIterable;
  22619. }
  22620. function makeSequence(iterable) {
  22621. return Object.create(
  22622. (
  22623. isKeyed(iterable) ? KeyedSeq :
  22624. isIndexed(iterable) ? IndexedSeq :
  22625. SetSeq
  22626. ).prototype
  22627. );
  22628. }
  22629. function cacheResultThrough() {
  22630. if (this._iter.cacheResult) {
  22631. this._iter.cacheResult();
  22632. this.size = this._iter.size;
  22633. return this;
  22634. } else {
  22635. return Seq.prototype.cacheResult.call(this);
  22636. }
  22637. }
  22638. function defaultComparator(a, b) {
  22639. return a > b ? 1 : a < b ? -1 : 0;
  22640. }
  22641. function forceIterator(keyPath) {
  22642. var iter = getIterator(keyPath);
  22643. if (!iter) {
  22644. // Array might not be iterable in this environment, so we need a fallback
  22645. // to our wrapped type.
  22646. if (!isArrayLike(keyPath)) {
  22647. throw new TypeError('Expected iterable or array-like: ' + keyPath);
  22648. }
  22649. iter = getIterator(Iterable(keyPath));
  22650. }
  22651. return iter;
  22652. }
  22653. createClass(Record, KeyedCollection);
  22654. function Record(defaultValues, name) {
  22655. var hasInitialized;
  22656. var RecordType = function Record(values) {
  22657. if (values instanceof RecordType) {
  22658. return values;
  22659. }
  22660. if (!(this instanceof RecordType)) {
  22661. return new RecordType(values);
  22662. }
  22663. if (!hasInitialized) {
  22664. hasInitialized = true;
  22665. var keys = Object.keys(defaultValues);
  22666. setProps(RecordTypePrototype, keys);
  22667. RecordTypePrototype.size = keys.length;
  22668. RecordTypePrototype._name = name;
  22669. RecordTypePrototype._keys = keys;
  22670. RecordTypePrototype._defaultValues = defaultValues;
  22671. }
  22672. this._map = Map(values);
  22673. };
  22674. var RecordTypePrototype = RecordType.prototype = Object.create(RecordPrototype);
  22675. RecordTypePrototype.constructor = RecordType;
  22676. return RecordType;
  22677. }
  22678. Record.prototype.toString = function() {
  22679. return this.__toString(recordName(this) + ' {', '}');
  22680. };
  22681. // @pragma Access
  22682. Record.prototype.has = function(k) {
  22683. return this._defaultValues.hasOwnProperty(k);
  22684. };
  22685. Record.prototype.get = function(k, notSetValue) {
  22686. if (!this.has(k)) {
  22687. return notSetValue;
  22688. }
  22689. var defaultVal = this._defaultValues[k];
  22690. return this._map ? this._map.get(k, defaultVal) : defaultVal;
  22691. };
  22692. // @pragma Modification
  22693. Record.prototype.clear = function() {
  22694. if (this.__ownerID) {
  22695. this._map && this._map.clear();
  22696. return this;
  22697. }
  22698. var RecordType = this.constructor;
  22699. return RecordType._empty || (RecordType._empty = makeRecord(this, emptyMap()));
  22700. };
  22701. Record.prototype.set = function(k, v) {
  22702. if (!this.has(k)) {
  22703. throw new Error('Cannot set unknown key "' + k + '" on ' + recordName(this));
  22704. }
  22705. var newMap = this._map && this._map.set(k, v);
  22706. if (this.__ownerID || newMap === this._map) {
  22707. return this;
  22708. }
  22709. return makeRecord(this, newMap);
  22710. };
  22711. Record.prototype.remove = function(k) {
  22712. if (!this.has(k)) {
  22713. return this;
  22714. }
  22715. var newMap = this._map && this._map.remove(k);
  22716. if (this.__ownerID || newMap === this._map) {
  22717. return this;
  22718. }
  22719. return makeRecord(this, newMap);
  22720. };
  22721. Record.prototype.wasAltered = function() {
  22722. return this._map.wasAltered();
  22723. };
  22724. Record.prototype.__iterator = function(type, reverse) {var this$0 = this;
  22725. return KeyedIterable(this._defaultValues).map(function(_, k) {return this$0.get(k)}).__iterator(type, reverse);
  22726. };
  22727. Record.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  22728. return KeyedIterable(this._defaultValues).map(function(_, k) {return this$0.get(k)}).__iterate(fn, reverse);
  22729. };
  22730. Record.prototype.__ensureOwner = function(ownerID) {
  22731. if (ownerID === this.__ownerID) {
  22732. return this;
  22733. }
  22734. var newMap = this._map && this._map.__ensureOwner(ownerID);
  22735. if (!ownerID) {
  22736. this.__ownerID = ownerID;
  22737. this._map = newMap;
  22738. return this;
  22739. }
  22740. return makeRecord(this, newMap, ownerID);
  22741. };
  22742. var RecordPrototype = Record.prototype;
  22743. RecordPrototype[DELETE] = RecordPrototype.remove;
  22744. RecordPrototype.deleteIn =
  22745. RecordPrototype.removeIn = MapPrototype.removeIn;
  22746. RecordPrototype.merge = MapPrototype.merge;
  22747. RecordPrototype.mergeWith = MapPrototype.mergeWith;
  22748. RecordPrototype.mergeIn = MapPrototype.mergeIn;
  22749. RecordPrototype.mergeDeep = MapPrototype.mergeDeep;
  22750. RecordPrototype.mergeDeepWith = MapPrototype.mergeDeepWith;
  22751. RecordPrototype.mergeDeepIn = MapPrototype.mergeDeepIn;
  22752. RecordPrototype.setIn = MapPrototype.setIn;
  22753. RecordPrototype.update = MapPrototype.update;
  22754. RecordPrototype.updateIn = MapPrototype.updateIn;
  22755. RecordPrototype.withMutations = MapPrototype.withMutations;
  22756. RecordPrototype.asMutable = MapPrototype.asMutable;
  22757. RecordPrototype.asImmutable = MapPrototype.asImmutable;
  22758. function makeRecord(likeRecord, map, ownerID) {
  22759. var record = Object.create(Object.getPrototypeOf(likeRecord));
  22760. record._map = map;
  22761. record.__ownerID = ownerID;
  22762. return record;
  22763. }
  22764. function recordName(record) {
  22765. return record._name || record.constructor.name || 'Record';
  22766. }
  22767. function setProps(prototype, names) {
  22768. try {
  22769. names.forEach(setProp.bind(undefined, prototype));
  22770. } catch (error) {
  22771. // Object.defineProperty failed. Probably IE8.
  22772. }
  22773. }
  22774. function setProp(prototype, name) {
  22775. Object.defineProperty(prototype, name, {
  22776. get: function() {
  22777. return this.get(name);
  22778. },
  22779. set: function(value) {
  22780. invariant(this.__ownerID, 'Cannot set on an immutable record.');
  22781. this.set(name, value);
  22782. }
  22783. });
  22784. }
  22785. createClass(Set, SetCollection);
  22786. // @pragma Construction
  22787. function Set(value) {
  22788. return value === null || value === undefined ? emptySet() :
  22789. isSet(value) && !isOrdered(value) ? value :
  22790. emptySet().withMutations(function(set ) {
  22791. var iter = SetIterable(value);
  22792. assertNotInfinite(iter.size);
  22793. iter.forEach(function(v ) {return set.add(v)});
  22794. });
  22795. }
  22796. Set.of = function(/*...values*/) {
  22797. return this(arguments);
  22798. };
  22799. Set.fromKeys = function(value) {
  22800. return this(KeyedIterable(value).keySeq());
  22801. };
  22802. Set.prototype.toString = function() {
  22803. return this.__toString('Set {', '}');
  22804. };
  22805. // @pragma Access
  22806. Set.prototype.has = function(value) {
  22807. return this._map.has(value);
  22808. };
  22809. // @pragma Modification
  22810. Set.prototype.add = function(value) {
  22811. return updateSet(this, this._map.set(value, true));
  22812. };
  22813. Set.prototype.remove = function(value) {
  22814. return updateSet(this, this._map.remove(value));
  22815. };
  22816. Set.prototype.clear = function() {
  22817. return updateSet(this, this._map.clear());
  22818. };
  22819. // @pragma Composition
  22820. Set.prototype.union = function() {var iters = SLICE$0.call(arguments, 0);
  22821. iters = iters.filter(function(x ) {return x.size !== 0});
  22822. if (iters.length === 0) {
  22823. return this;
  22824. }
  22825. if (this.size === 0 && !this.__ownerID && iters.length === 1) {
  22826. return this.constructor(iters[0]);
  22827. }
  22828. return this.withMutations(function(set ) {
  22829. for (var ii = 0; ii < iters.length; ii++) {
  22830. SetIterable(iters[ii]).forEach(function(value ) {return set.add(value)});
  22831. }
  22832. });
  22833. };
  22834. Set.prototype.intersect = function() {var iters = SLICE$0.call(arguments, 0);
  22835. if (iters.length === 0) {
  22836. return this;
  22837. }
  22838. iters = iters.map(function(iter ) {return SetIterable(iter)});
  22839. var originalSet = this;
  22840. return this.withMutations(function(set ) {
  22841. originalSet.forEach(function(value ) {
  22842. if (!iters.every(function(iter ) {return iter.includes(value)})) {
  22843. set.remove(value);
  22844. }
  22845. });
  22846. });
  22847. };
  22848. Set.prototype.subtract = function() {var iters = SLICE$0.call(arguments, 0);
  22849. if (iters.length === 0) {
  22850. return this;
  22851. }
  22852. iters = iters.map(function(iter ) {return SetIterable(iter)});
  22853. var originalSet = this;
  22854. return this.withMutations(function(set ) {
  22855. originalSet.forEach(function(value ) {
  22856. if (iters.some(function(iter ) {return iter.includes(value)})) {
  22857. set.remove(value);
  22858. }
  22859. });
  22860. });
  22861. };
  22862. Set.prototype.merge = function() {
  22863. return this.union.apply(this, arguments);
  22864. };
  22865. Set.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  22866. return this.union.apply(this, iters);
  22867. };
  22868. Set.prototype.sort = function(comparator) {
  22869. // Late binding
  22870. return OrderedSet(sortFactory(this, comparator));
  22871. };
  22872. Set.prototype.sortBy = function(mapper, comparator) {
  22873. // Late binding
  22874. return OrderedSet(sortFactory(this, comparator, mapper));
  22875. };
  22876. Set.prototype.wasAltered = function() {
  22877. return this._map.wasAltered();
  22878. };
  22879. Set.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  22880. return this._map.__iterate(function(_, k) {return fn(k, k, this$0)}, reverse);
  22881. };
  22882. Set.prototype.__iterator = function(type, reverse) {
  22883. return this._map.map(function(_, k) {return k}).__iterator(type, reverse);
  22884. };
  22885. Set.prototype.__ensureOwner = function(ownerID) {
  22886. if (ownerID === this.__ownerID) {
  22887. return this;
  22888. }
  22889. var newMap = this._map.__ensureOwner(ownerID);
  22890. if (!ownerID) {
  22891. this.__ownerID = ownerID;
  22892. this._map = newMap;
  22893. return this;
  22894. }
  22895. return this.__make(newMap, ownerID);
  22896. };
  22897. function isSet(maybeSet) {
  22898. return !!(maybeSet && maybeSet[IS_SET_SENTINEL]);
  22899. }
  22900. Set.isSet = isSet;
  22901. var IS_SET_SENTINEL = '@@__IMMUTABLE_SET__@@';
  22902. var SetPrototype = Set.prototype;
  22903. SetPrototype[IS_SET_SENTINEL] = true;
  22904. SetPrototype[DELETE] = SetPrototype.remove;
  22905. SetPrototype.mergeDeep = SetPrototype.merge;
  22906. SetPrototype.mergeDeepWith = SetPrototype.mergeWith;
  22907. SetPrototype.withMutations = MapPrototype.withMutations;
  22908. SetPrototype.asMutable = MapPrototype.asMutable;
  22909. SetPrototype.asImmutable = MapPrototype.asImmutable;
  22910. SetPrototype.__empty = emptySet;
  22911. SetPrototype.__make = makeSet;
  22912. function updateSet(set, newMap) {
  22913. if (set.__ownerID) {
  22914. set.size = newMap.size;
  22915. set._map = newMap;
  22916. return set;
  22917. }
  22918. return newMap === set._map ? set :
  22919. newMap.size === 0 ? set.__empty() :
  22920. set.__make(newMap);
  22921. }
  22922. function makeSet(map, ownerID) {
  22923. var set = Object.create(SetPrototype);
  22924. set.size = map ? map.size : 0;
  22925. set._map = map;
  22926. set.__ownerID = ownerID;
  22927. return set;
  22928. }
  22929. var EMPTY_SET;
  22930. function emptySet() {
  22931. return EMPTY_SET || (EMPTY_SET = makeSet(emptyMap()));
  22932. }
  22933. createClass(OrderedSet, Set);
  22934. // @pragma Construction
  22935. function OrderedSet(value) {
  22936. return value === null || value === undefined ? emptyOrderedSet() :
  22937. isOrderedSet(value) ? value :
  22938. emptyOrderedSet().withMutations(function(set ) {
  22939. var iter = SetIterable(value);
  22940. assertNotInfinite(iter.size);
  22941. iter.forEach(function(v ) {return set.add(v)});
  22942. });
  22943. }
  22944. OrderedSet.of = function(/*...values*/) {
  22945. return this(arguments);
  22946. };
  22947. OrderedSet.fromKeys = function(value) {
  22948. return this(KeyedIterable(value).keySeq());
  22949. };
  22950. OrderedSet.prototype.toString = function() {
  22951. return this.__toString('OrderedSet {', '}');
  22952. };
  22953. function isOrderedSet(maybeOrderedSet) {
  22954. return isSet(maybeOrderedSet) && isOrdered(maybeOrderedSet);
  22955. }
  22956. OrderedSet.isOrderedSet = isOrderedSet;
  22957. var OrderedSetPrototype = OrderedSet.prototype;
  22958. OrderedSetPrototype[IS_ORDERED_SENTINEL] = true;
  22959. OrderedSetPrototype.__empty = emptyOrderedSet;
  22960. OrderedSetPrototype.__make = makeOrderedSet;
  22961. function makeOrderedSet(map, ownerID) {
  22962. var set = Object.create(OrderedSetPrototype);
  22963. set.size = map ? map.size : 0;
  22964. set._map = map;
  22965. set.__ownerID = ownerID;
  22966. return set;
  22967. }
  22968. var EMPTY_ORDERED_SET;
  22969. function emptyOrderedSet() {
  22970. return EMPTY_ORDERED_SET || (EMPTY_ORDERED_SET = makeOrderedSet(emptyOrderedMap()));
  22971. }
  22972. createClass(Stack, IndexedCollection);
  22973. // @pragma Construction
  22974. function Stack(value) {
  22975. return value === null || value === undefined ? emptyStack() :
  22976. isStack(value) ? value :
  22977. emptyStack().unshiftAll(value);
  22978. }
  22979. Stack.of = function(/*...values*/) {
  22980. return this(arguments);
  22981. };
  22982. Stack.prototype.toString = function() {
  22983. return this.__toString('Stack [', ']');
  22984. };
  22985. // @pragma Access
  22986. Stack.prototype.get = function(index, notSetValue) {
  22987. var head = this._head;
  22988. index = wrapIndex(this, index);
  22989. while (head && index--) {
  22990. head = head.next;
  22991. }
  22992. return head ? head.value : notSetValue;
  22993. };
  22994. Stack.prototype.peek = function() {
  22995. return this._head && this._head.value;
  22996. };
  22997. // @pragma Modification
  22998. Stack.prototype.push = function(/*...values*/) {
  22999. if (arguments.length === 0) {
  23000. return this;
  23001. }
  23002. var newSize = this.size + arguments.length;
  23003. var head = this._head;
  23004. for (var ii = arguments.length - 1; ii >= 0; ii--) {
  23005. head = {
  23006. value: arguments[ii],
  23007. next: head
  23008. };
  23009. }
  23010. if (this.__ownerID) {
  23011. this.size = newSize;
  23012. this._head = head;
  23013. this.__hash = undefined;
  23014. this.__altered = true;
  23015. return this;
  23016. }
  23017. return makeStack(newSize, head);
  23018. };
  23019. Stack.prototype.pushAll = function(iter) {
  23020. iter = IndexedIterable(iter);
  23021. if (iter.size === 0) {
  23022. return this;
  23023. }
  23024. assertNotInfinite(iter.size);
  23025. var newSize = this.size;
  23026. var head = this._head;
  23027. iter.reverse().forEach(function(value ) {
  23028. newSize++;
  23029. head = {
  23030. value: value,
  23031. next: head
  23032. };
  23033. });
  23034. if (this.__ownerID) {
  23035. this.size = newSize;
  23036. this._head = head;
  23037. this.__hash = undefined;
  23038. this.__altered = true;
  23039. return this;
  23040. }
  23041. return makeStack(newSize, head);
  23042. };
  23043. Stack.prototype.pop = function() {
  23044. return this.slice(1);
  23045. };
  23046. Stack.prototype.unshift = function(/*...values*/) {
  23047. return this.push.apply(this, arguments);
  23048. };
  23049. Stack.prototype.unshiftAll = function(iter) {
  23050. return this.pushAll(iter);
  23051. };
  23052. Stack.prototype.shift = function() {
  23053. return this.pop.apply(this, arguments);
  23054. };
  23055. Stack.prototype.clear = function() {
  23056. if (this.size === 0) {
  23057. return this;
  23058. }
  23059. if (this.__ownerID) {
  23060. this.size = 0;
  23061. this._head = undefined;
  23062. this.__hash = undefined;
  23063. this.__altered = true;
  23064. return this;
  23065. }
  23066. return emptyStack();
  23067. };
  23068. Stack.prototype.slice = function(begin, end) {
  23069. if (wholeSlice(begin, end, this.size)) {
  23070. return this;
  23071. }
  23072. var resolvedBegin = resolveBegin(begin, this.size);
  23073. var resolvedEnd = resolveEnd(end, this.size);
  23074. if (resolvedEnd !== this.size) {
  23075. // super.slice(begin, end);
  23076. return IndexedCollection.prototype.slice.call(this, begin, end);
  23077. }
  23078. var newSize = this.size - resolvedBegin;
  23079. var head = this._head;
  23080. while (resolvedBegin--) {
  23081. head = head.next;
  23082. }
  23083. if (this.__ownerID) {
  23084. this.size = newSize;
  23085. this._head = head;
  23086. this.__hash = undefined;
  23087. this.__altered = true;
  23088. return this;
  23089. }
  23090. return makeStack(newSize, head);
  23091. };
  23092. // @pragma Mutability
  23093. Stack.prototype.__ensureOwner = function(ownerID) {
  23094. if (ownerID === this.__ownerID) {
  23095. return this;
  23096. }
  23097. if (!ownerID) {
  23098. this.__ownerID = ownerID;
  23099. this.__altered = false;
  23100. return this;
  23101. }
  23102. return makeStack(this.size, this._head, ownerID, this.__hash);
  23103. };
  23104. // @pragma Iteration
  23105. Stack.prototype.__iterate = function(fn, reverse) {
  23106. if (reverse) {
  23107. return this.reverse().__iterate(fn);
  23108. }
  23109. var iterations = 0;
  23110. var node = this._head;
  23111. while (node) {
  23112. if (fn(node.value, iterations++, this) === false) {
  23113. break;
  23114. }
  23115. node = node.next;
  23116. }
  23117. return iterations;
  23118. };
  23119. Stack.prototype.__iterator = function(type, reverse) {
  23120. if (reverse) {
  23121. return this.reverse().__iterator(type);
  23122. }
  23123. var iterations = 0;
  23124. var node = this._head;
  23125. return new Iterator(function() {
  23126. if (node) {
  23127. var value = node.value;
  23128. node = node.next;
  23129. return iteratorValue(type, iterations++, value);
  23130. }
  23131. return iteratorDone();
  23132. });
  23133. };
  23134. function isStack(maybeStack) {
  23135. return !!(maybeStack && maybeStack[IS_STACK_SENTINEL]);
  23136. }
  23137. Stack.isStack = isStack;
  23138. var IS_STACK_SENTINEL = '@@__IMMUTABLE_STACK__@@';
  23139. var StackPrototype = Stack.prototype;
  23140. StackPrototype[IS_STACK_SENTINEL] = true;
  23141. StackPrototype.withMutations = MapPrototype.withMutations;
  23142. StackPrototype.asMutable = MapPrototype.asMutable;
  23143. StackPrototype.asImmutable = MapPrototype.asImmutable;
  23144. StackPrototype.wasAltered = MapPrototype.wasAltered;
  23145. function makeStack(size, head, ownerID, hash) {
  23146. var map = Object.create(StackPrototype);
  23147. map.size = size;
  23148. map._head = head;
  23149. map.__ownerID = ownerID;
  23150. map.__hash = hash;
  23151. map.__altered = false;
  23152. return map;
  23153. }
  23154. var EMPTY_STACK;
  23155. function emptyStack() {
  23156. return EMPTY_STACK || (EMPTY_STACK = makeStack(0));
  23157. }
  23158. /**
  23159. * Contributes additional methods to a constructor
  23160. */
  23161. function mixin(ctor, methods) {
  23162. var keyCopier = function(key ) { ctor.prototype[key] = methods[key]; };
  23163. Object.keys(methods).forEach(keyCopier);
  23164. Object.getOwnPropertySymbols &&
  23165. Object.getOwnPropertySymbols(methods).forEach(keyCopier);
  23166. return ctor;
  23167. }
  23168. Iterable.Iterator = Iterator;
  23169. mixin(Iterable, {
  23170. // ### Conversion to other types
  23171. toArray: function() {
  23172. assertNotInfinite(this.size);
  23173. var array = new Array(this.size || 0);
  23174. this.valueSeq().__iterate(function(v, i) { array[i] = v; });
  23175. return array;
  23176. },
  23177. toIndexedSeq: function() {
  23178. return new ToIndexedSequence(this);
  23179. },
  23180. toJS: function() {
  23181. return this.toSeq().map(
  23182. function(value ) {return value && typeof value.toJS === 'function' ? value.toJS() : value}
  23183. ).__toJS();
  23184. },
  23185. toJSON: function() {
  23186. return this.toSeq().map(
  23187. function(value ) {return value && typeof value.toJSON === 'function' ? value.toJSON() : value}
  23188. ).__toJS();
  23189. },
  23190. toKeyedSeq: function() {
  23191. return new ToKeyedSequence(this, true);
  23192. },
  23193. toMap: function() {
  23194. // Use Late Binding here to solve the circular dependency.
  23195. return Map(this.toKeyedSeq());
  23196. },
  23197. toObject: function() {
  23198. assertNotInfinite(this.size);
  23199. var object = {};
  23200. this.__iterate(function(v, k) { object[k] = v; });
  23201. return object;
  23202. },
  23203. toOrderedMap: function() {
  23204. // Use Late Binding here to solve the circular dependency.
  23205. return OrderedMap(this.toKeyedSeq());
  23206. },
  23207. toOrderedSet: function() {
  23208. // Use Late Binding here to solve the circular dependency.
  23209. return OrderedSet(isKeyed(this) ? this.valueSeq() : this);
  23210. },
  23211. toSet: function() {
  23212. // Use Late Binding here to solve the circular dependency.
  23213. return Set(isKeyed(this) ? this.valueSeq() : this);
  23214. },
  23215. toSetSeq: function() {
  23216. return new ToSetSequence(this);
  23217. },
  23218. toSeq: function() {
  23219. return isIndexed(this) ? this.toIndexedSeq() :
  23220. isKeyed(this) ? this.toKeyedSeq() :
  23221. this.toSetSeq();
  23222. },
  23223. toStack: function() {
  23224. // Use Late Binding here to solve the circular dependency.
  23225. return Stack(isKeyed(this) ? this.valueSeq() : this);
  23226. },
  23227. toList: function() {
  23228. // Use Late Binding here to solve the circular dependency.
  23229. return List(isKeyed(this) ? this.valueSeq() : this);
  23230. },
  23231. // ### Common JavaScript methods and properties
  23232. toString: function() {
  23233. return '[Iterable]';
  23234. },
  23235. __toString: function(head, tail) {
  23236. if (this.size === 0) {
  23237. return head + tail;
  23238. }
  23239. return head + ' ' + this.toSeq().map(this.__toStringMapper).join(', ') + ' ' + tail;
  23240. },
  23241. // ### ES6 Collection methods (ES6 Array and Map)
  23242. concat: function() {var values = SLICE$0.call(arguments, 0);
  23243. return reify(this, concatFactory(this, values));
  23244. },
  23245. includes: function(searchValue) {
  23246. return this.some(function(value ) {return is(value, searchValue)});
  23247. },
  23248. entries: function() {
  23249. return this.__iterator(ITERATE_ENTRIES);
  23250. },
  23251. every: function(predicate, context) {
  23252. assertNotInfinite(this.size);
  23253. var returnValue = true;
  23254. this.__iterate(function(v, k, c) {
  23255. if (!predicate.call(context, v, k, c)) {
  23256. returnValue = false;
  23257. return false;
  23258. }
  23259. });
  23260. return returnValue;
  23261. },
  23262. filter: function(predicate, context) {
  23263. return reify(this, filterFactory(this, predicate, context, true));
  23264. },
  23265. find: function(predicate, context, notSetValue) {
  23266. var entry = this.findEntry(predicate, context);
  23267. return entry ? entry[1] : notSetValue;
  23268. },
  23269. findEntry: function(predicate, context) {
  23270. var found;
  23271. this.__iterate(function(v, k, c) {
  23272. if (predicate.call(context, v, k, c)) {
  23273. found = [k, v];
  23274. return false;
  23275. }
  23276. });
  23277. return found;
  23278. },
  23279. findLastEntry: function(predicate, context) {
  23280. return this.toSeq().reverse().findEntry(predicate, context);
  23281. },
  23282. forEach: function(sideEffect, context) {
  23283. assertNotInfinite(this.size);
  23284. return this.__iterate(context ? sideEffect.bind(context) : sideEffect);
  23285. },
  23286. join: function(separator) {
  23287. assertNotInfinite(this.size);
  23288. separator = separator !== undefined ? '' + separator : ',';
  23289. var joined = '';
  23290. var isFirst = true;
  23291. this.__iterate(function(v ) {
  23292. isFirst ? (isFirst = false) : (joined += separator);
  23293. joined += v !== null && v !== undefined ? v.toString() : '';
  23294. });
  23295. return joined;
  23296. },
  23297. keys: function() {
  23298. return this.__iterator(ITERATE_KEYS);
  23299. },
  23300. map: function(mapper, context) {
  23301. return reify(this, mapFactory(this, mapper, context));
  23302. },
  23303. reduce: function(reducer, initialReduction, context) {
  23304. assertNotInfinite(this.size);
  23305. var reduction;
  23306. var useFirst;
  23307. if (arguments.length < 2) {
  23308. useFirst = true;
  23309. } else {
  23310. reduction = initialReduction;
  23311. }
  23312. this.__iterate(function(v, k, c) {
  23313. if (useFirst) {
  23314. useFirst = false;
  23315. reduction = v;
  23316. } else {
  23317. reduction = reducer.call(context, reduction, v, k, c);
  23318. }
  23319. });
  23320. return reduction;
  23321. },
  23322. reduceRight: function(reducer, initialReduction, context) {
  23323. var reversed = this.toKeyedSeq().reverse();
  23324. return reversed.reduce.apply(reversed, arguments);
  23325. },
  23326. reverse: function() {
  23327. return reify(this, reverseFactory(this, true));
  23328. },
  23329. slice: function(begin, end) {
  23330. return reify(this, sliceFactory(this, begin, end, true));
  23331. },
  23332. some: function(predicate, context) {
  23333. return !this.every(not(predicate), context);
  23334. },
  23335. sort: function(comparator) {
  23336. return reify(this, sortFactory(this, comparator));
  23337. },
  23338. values: function() {
  23339. return this.__iterator(ITERATE_VALUES);
  23340. },
  23341. // ### More sequential methods
  23342. butLast: function() {
  23343. return this.slice(0, -1);
  23344. },
  23345. isEmpty: function() {
  23346. return this.size !== undefined ? this.size === 0 : !this.some(function() {return true});
  23347. },
  23348. count: function(predicate, context) {
  23349. return ensureSize(
  23350. predicate ? this.toSeq().filter(predicate, context) : this
  23351. );
  23352. },
  23353. countBy: function(grouper, context) {
  23354. return countByFactory(this, grouper, context);
  23355. },
  23356. equals: function(other) {
  23357. return deepEqual(this, other);
  23358. },
  23359. entrySeq: function() {
  23360. var iterable = this;
  23361. if (iterable._cache) {
  23362. // We cache as an entries array, so we can just return the cache!
  23363. return new ArraySeq(iterable._cache);
  23364. }
  23365. var entriesSequence = iterable.toSeq().map(entryMapper).toIndexedSeq();
  23366. entriesSequence.fromEntrySeq = function() {return iterable.toSeq()};
  23367. return entriesSequence;
  23368. },
  23369. filterNot: function(predicate, context) {
  23370. return this.filter(not(predicate), context);
  23371. },
  23372. findLast: function(predicate, context, notSetValue) {
  23373. return this.toKeyedSeq().reverse().find(predicate, context, notSetValue);
  23374. },
  23375. first: function() {
  23376. return this.find(returnTrue);
  23377. },
  23378. flatMap: function(mapper, context) {
  23379. return reify(this, flatMapFactory(this, mapper, context));
  23380. },
  23381. flatten: function(depth) {
  23382. return reify(this, flattenFactory(this, depth, true));
  23383. },
  23384. fromEntrySeq: function() {
  23385. return new FromEntriesSequence(this);
  23386. },
  23387. get: function(searchKey, notSetValue) {
  23388. return this.find(function(_, key) {return is(key, searchKey)}, undefined, notSetValue);
  23389. },
  23390. getIn: function(searchKeyPath, notSetValue) {
  23391. var nested = this;
  23392. // Note: in an ES6 environment, we would prefer:
  23393. // for (var key of searchKeyPath) {
  23394. var iter = forceIterator(searchKeyPath);
  23395. var step;
  23396. while (!(step = iter.next()).done) {
  23397. var key = step.value;
  23398. nested = nested && nested.get ? nested.get(key, NOT_SET) : NOT_SET;
  23399. if (nested === NOT_SET) {
  23400. return notSetValue;
  23401. }
  23402. }
  23403. return nested;
  23404. },
  23405. groupBy: function(grouper, context) {
  23406. return groupByFactory(this, grouper, context);
  23407. },
  23408. has: function(searchKey) {
  23409. return this.get(searchKey, NOT_SET) !== NOT_SET;
  23410. },
  23411. hasIn: function(searchKeyPath) {
  23412. return this.getIn(searchKeyPath, NOT_SET) !== NOT_SET;
  23413. },
  23414. isSubset: function(iter) {
  23415. iter = typeof iter.includes === 'function' ? iter : Iterable(iter);
  23416. return this.every(function(value ) {return iter.includes(value)});
  23417. },
  23418. isSuperset: function(iter) {
  23419. iter = typeof iter.isSubset === 'function' ? iter : Iterable(iter);
  23420. return iter.isSubset(this);
  23421. },
  23422. keySeq: function() {
  23423. return this.toSeq().map(keyMapper).toIndexedSeq();
  23424. },
  23425. last: function() {
  23426. return this.toSeq().reverse().first();
  23427. },
  23428. max: function(comparator) {
  23429. return maxFactory(this, comparator);
  23430. },
  23431. maxBy: function(mapper, comparator) {
  23432. return maxFactory(this, comparator, mapper);
  23433. },
  23434. min: function(comparator) {
  23435. return maxFactory(this, comparator ? neg(comparator) : defaultNegComparator);
  23436. },
  23437. minBy: function(mapper, comparator) {
  23438. return maxFactory(this, comparator ? neg(comparator) : defaultNegComparator, mapper);
  23439. },
  23440. rest: function() {
  23441. return this.slice(1);
  23442. },
  23443. skip: function(amount) {
  23444. return this.slice(Math.max(0, amount));
  23445. },
  23446. skipLast: function(amount) {
  23447. return reify(this, this.toSeq().reverse().skip(amount).reverse());
  23448. },
  23449. skipWhile: function(predicate, context) {
  23450. return reify(this, skipWhileFactory(this, predicate, context, true));
  23451. },
  23452. skipUntil: function(predicate, context) {
  23453. return this.skipWhile(not(predicate), context);
  23454. },
  23455. sortBy: function(mapper, comparator) {
  23456. return reify(this, sortFactory(this, comparator, mapper));
  23457. },
  23458. take: function(amount) {
  23459. return this.slice(0, Math.max(0, amount));
  23460. },
  23461. takeLast: function(amount) {
  23462. return reify(this, this.toSeq().reverse().take(amount).reverse());
  23463. },
  23464. takeWhile: function(predicate, context) {
  23465. return reify(this, takeWhileFactory(this, predicate, context));
  23466. },
  23467. takeUntil: function(predicate, context) {
  23468. return this.takeWhile(not(predicate), context);
  23469. },
  23470. valueSeq: function() {
  23471. return this.toIndexedSeq();
  23472. },
  23473. // ### Hashable Object
  23474. hashCode: function() {
  23475. return this.__hash || (this.__hash = hashIterable(this));
  23476. }
  23477. // ### Internal
  23478. // abstract __iterate(fn, reverse)
  23479. // abstract __iterator(type, reverse)
  23480. });
  23481. // var IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
  23482. // var IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
  23483. // var IS_INDEXED_SENTINEL = '@@__IMMUTABLE_INDEXED__@@';
  23484. // var IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
  23485. var IterablePrototype = Iterable.prototype;
  23486. IterablePrototype[IS_ITERABLE_SENTINEL] = true;
  23487. IterablePrototype[ITERATOR_SYMBOL] = IterablePrototype.values;
  23488. IterablePrototype.__toJS = IterablePrototype.toArray;
  23489. IterablePrototype.__toStringMapper = quoteString;
  23490. IterablePrototype.inspect =
  23491. IterablePrototype.toSource = function() { return this.toString(); };
  23492. IterablePrototype.chain = IterablePrototype.flatMap;
  23493. IterablePrototype.contains = IterablePrototype.includes;
  23494. // Temporary warning about using length
  23495. (function () {
  23496. try {
  23497. Object.defineProperty(IterablePrototype, 'length', {
  23498. get: function () {
  23499. if (!Iterable.noLengthWarning) {
  23500. var stack;
  23501. try {
  23502. throw new Error();
  23503. } catch (error) {
  23504. stack = error.stack;
  23505. }
  23506. if (stack.indexOf('_wrapObject') === -1) {
  23507. console && console.warn && console.warn(
  23508. 'iterable.length has been deprecated, '+
  23509. 'use iterable.size or iterable.count(). '+
  23510. 'This warning will become a silent error in a future version. ' +
  23511. stack
  23512. );
  23513. return this.size;
  23514. }
  23515. }
  23516. }
  23517. });
  23518. } catch (e) {}
  23519. })();
  23520. mixin(KeyedIterable, {
  23521. // ### More sequential methods
  23522. flip: function() {
  23523. return reify(this, flipFactory(this));
  23524. },
  23525. findKey: function(predicate, context) {
  23526. var entry = this.findEntry(predicate, context);
  23527. return entry && entry[0];
  23528. },
  23529. findLastKey: function(predicate, context) {
  23530. return this.toSeq().reverse().findKey(predicate, context);
  23531. },
  23532. keyOf: function(searchValue) {
  23533. return this.findKey(function(value ) {return is(value, searchValue)});
  23534. },
  23535. lastKeyOf: function(searchValue) {
  23536. return this.findLastKey(function(value ) {return is(value, searchValue)});
  23537. },
  23538. mapEntries: function(mapper, context) {var this$0 = this;
  23539. var iterations = 0;
  23540. return reify(this,
  23541. this.toSeq().map(
  23542. function(v, k) {return mapper.call(context, [k, v], iterations++, this$0)}
  23543. ).fromEntrySeq()
  23544. );
  23545. },
  23546. mapKeys: function(mapper, context) {var this$0 = this;
  23547. return reify(this,
  23548. this.toSeq().flip().map(
  23549. function(k, v) {return mapper.call(context, k, v, this$0)}
  23550. ).flip()
  23551. );
  23552. }
  23553. });
  23554. var KeyedIterablePrototype = KeyedIterable.prototype;
  23555. KeyedIterablePrototype[IS_KEYED_SENTINEL] = true;
  23556. KeyedIterablePrototype[ITERATOR_SYMBOL] = IterablePrototype.entries;
  23557. KeyedIterablePrototype.__toJS = IterablePrototype.toObject;
  23558. KeyedIterablePrototype.__toStringMapper = function(v, k) {return JSON.stringify(k) + ': ' + quoteString(v)};
  23559. mixin(IndexedIterable, {
  23560. // ### Conversion to other types
  23561. toKeyedSeq: function() {
  23562. return new ToKeyedSequence(this, false);
  23563. },
  23564. // ### ES6 Collection methods (ES6 Array and Map)
  23565. filter: function(predicate, context) {
  23566. return reify(this, filterFactory(this, predicate, context, false));
  23567. },
  23568. findIndex: function(predicate, context) {
  23569. var entry = this.findEntry(predicate, context);
  23570. return entry ? entry[0] : -1;
  23571. },
  23572. indexOf: function(searchValue) {
  23573. var key = this.toKeyedSeq().keyOf(searchValue);
  23574. return key === undefined ? -1 : key;
  23575. },
  23576. lastIndexOf: function(searchValue) {
  23577. var key = this.toKeyedSeq().reverse().keyOf(searchValue);
  23578. return key === undefined ? -1 : key;
  23579. // var index =
  23580. // return this.toSeq().reverse().indexOf(searchValue);
  23581. },
  23582. reverse: function() {
  23583. return reify(this, reverseFactory(this, false));
  23584. },
  23585. slice: function(begin, end) {
  23586. return reify(this, sliceFactory(this, begin, end, false));
  23587. },
  23588. splice: function(index, removeNum /*, ...values*/) {
  23589. var numArgs = arguments.length;
  23590. removeNum = Math.max(removeNum | 0, 0);
  23591. if (numArgs === 0 || (numArgs === 2 && !removeNum)) {
  23592. return this;
  23593. }
  23594. // If index is negative, it should resolve relative to the size of the
  23595. // collection. However size may be expensive to compute if not cached, so
  23596. // only call count() if the number is in fact negative.
  23597. index = resolveBegin(index, index < 0 ? this.count() : this.size);
  23598. var spliced = this.slice(0, index);
  23599. return reify(
  23600. this,
  23601. numArgs === 1 ?
  23602. spliced :
  23603. spliced.concat(arrCopy(arguments, 2), this.slice(index + removeNum))
  23604. );
  23605. },
  23606. // ### More collection methods
  23607. findLastIndex: function(predicate, context) {
  23608. var key = this.toKeyedSeq().findLastKey(predicate, context);
  23609. return key === undefined ? -1 : key;
  23610. },
  23611. first: function() {
  23612. return this.get(0);
  23613. },
  23614. flatten: function(depth) {
  23615. return reify(this, flattenFactory(this, depth, false));
  23616. },
  23617. get: function(index, notSetValue) {
  23618. index = wrapIndex(this, index);
  23619. return (index < 0 || (this.size === Infinity ||
  23620. (this.size !== undefined && index > this.size))) ?
  23621. notSetValue :
  23622. this.find(function(_, key) {return key === index}, undefined, notSetValue);
  23623. },
  23624. has: function(index) {
  23625. index = wrapIndex(this, index);
  23626. return index >= 0 && (this.size !== undefined ?
  23627. this.size === Infinity || index < this.size :
  23628. this.indexOf(index) !== -1
  23629. );
  23630. },
  23631. interpose: function(separator) {
  23632. return reify(this, interposeFactory(this, separator));
  23633. },
  23634. interleave: function(/*...iterables*/) {
  23635. var iterables = [this].concat(arrCopy(arguments));
  23636. var zipped = zipWithFactory(this.toSeq(), IndexedSeq.of, iterables);
  23637. var interleaved = zipped.flatten(true);
  23638. if (zipped.size) {
  23639. interleaved.size = zipped.size * iterables.length;
  23640. }
  23641. return reify(this, interleaved);
  23642. },
  23643. last: function() {
  23644. return this.get(-1);
  23645. },
  23646. skipWhile: function(predicate, context) {
  23647. return reify(this, skipWhileFactory(this, predicate, context, false));
  23648. },
  23649. zip: function(/*, ...iterables */) {
  23650. var iterables = [this].concat(arrCopy(arguments));
  23651. return reify(this, zipWithFactory(this, defaultZipper, iterables));
  23652. },
  23653. zipWith: function(zipper/*, ...iterables */) {
  23654. var iterables = arrCopy(arguments);
  23655. iterables[0] = this;
  23656. return reify(this, zipWithFactory(this, zipper, iterables));
  23657. }
  23658. });
  23659. IndexedIterable.prototype[IS_INDEXED_SENTINEL] = true;
  23660. IndexedIterable.prototype[IS_ORDERED_SENTINEL] = true;
  23661. mixin(SetIterable, {
  23662. // ### ES6 Collection methods (ES6 Array and Map)
  23663. get: function(value, notSetValue) {
  23664. return this.has(value) ? value : notSetValue;
  23665. },
  23666. includes: function(value) {
  23667. return this.has(value);
  23668. },
  23669. // ### More sequential methods
  23670. keySeq: function() {
  23671. return this.valueSeq();
  23672. }
  23673. });
  23674. SetIterable.prototype.has = IterablePrototype.includes;
  23675. // Mixin subclasses
  23676. mixin(KeyedSeq, KeyedIterable.prototype);
  23677. mixin(IndexedSeq, IndexedIterable.prototype);
  23678. mixin(SetSeq, SetIterable.prototype);
  23679. mixin(KeyedCollection, KeyedIterable.prototype);
  23680. mixin(IndexedCollection, IndexedIterable.prototype);
  23681. mixin(SetCollection, SetIterable.prototype);
  23682. // #pragma Helper functions
  23683. function keyMapper(v, k) {
  23684. return k;
  23685. }
  23686. function entryMapper(v, k) {
  23687. return [k, v];
  23688. }
  23689. function not(predicate) {
  23690. return function() {
  23691. return !predicate.apply(this, arguments);
  23692. }
  23693. }
  23694. function neg(predicate) {
  23695. return function() {
  23696. return -predicate.apply(this, arguments);
  23697. }
  23698. }
  23699. function quoteString(value) {
  23700. return typeof value === 'string' ? JSON.stringify(value) : value;
  23701. }
  23702. function defaultZipper() {
  23703. return arrCopy(arguments);
  23704. }
  23705. function defaultNegComparator(a, b) {
  23706. return a < b ? 1 : a > b ? -1 : 0;
  23707. }
  23708. function hashIterable(iterable) {
  23709. if (iterable.size === Infinity) {
  23710. return 0;
  23711. }
  23712. var ordered = isOrdered(iterable);
  23713. var keyed = isKeyed(iterable);
  23714. var h = ordered ? 1 : 0;
  23715. var size = iterable.__iterate(
  23716. keyed ?
  23717. ordered ?
  23718. function(v, k) { h = 31 * h + hashMerge(hash(v), hash(k)) | 0; } :
  23719. function(v, k) { h = h + hashMerge(hash(v), hash(k)) | 0; } :
  23720. ordered ?
  23721. function(v ) { h = 31 * h + hash(v) | 0; } :
  23722. function(v ) { h = h + hash(v) | 0; }
  23723. );
  23724. return murmurHashOfSize(size, h);
  23725. }
  23726. function murmurHashOfSize(size, h) {
  23727. h = imul(h, 0xCC9E2D51);
  23728. h = imul(h << 15 | h >>> -15, 0x1B873593);
  23729. h = imul(h << 13 | h >>> -13, 5);
  23730. h = (h + 0xE6546B64 | 0) ^ size;
  23731. h = imul(h ^ h >>> 16, 0x85EBCA6B);
  23732. h = imul(h ^ h >>> 13, 0xC2B2AE35);
  23733. h = smi(h ^ h >>> 16);
  23734. return h;
  23735. }
  23736. function hashMerge(a, b) {
  23737. return a ^ b + 0x9E3779B9 + (a << 6) + (a >> 2) | 0; // int
  23738. }
  23739. var Immutable = {
  23740. Iterable: Iterable,
  23741. Seq: Seq,
  23742. Collection: Collection,
  23743. Map: Map,
  23744. OrderedMap: OrderedMap,
  23745. List: List,
  23746. Stack: Stack,
  23747. Set: Set,
  23748. OrderedSet: OrderedSet,
  23749. Record: Record,
  23750. Range: Range,
  23751. Repeat: Repeat,
  23752. is: is,
  23753. fromJS: fromJS
  23754. };
  23755. return Immutable;
  23756. }));
  23757. });
  23758. var parseHTML_1 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
  23759. Object.defineProperty(exports, "__esModule", {
  23760. value: true
  23761. });
  23762. exports["default"] = parseHTML;
  23763. var fallback = function fallback(html) {
  23764. var doc = document.implementation.createHTMLDocument('');
  23765. doc.documentElement.innerHTML = html;
  23766. return doc;
  23767. };
  23768. function parseHTML(html) {
  23769. var doc;
  23770. if (typeof DOMParser !== 'undefined') {
  23771. var parser = new DOMParser();
  23772. doc = parser.parseFromString(html, 'text/html');
  23773. if (doc === null || doc.body === null) {
  23774. doc = fallback(html);
  23775. }
  23776. } else {
  23777. doc = fallback(html);
  23778. }
  23779. return doc.body;
  23780. }
  23781. });
  23782. _commonjsHelpers.unwrapExports(parseHTML_1);
  23783. var convertFromHTML_1 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
  23784. Object.defineProperty(exports, "__esModule", {
  23785. value: true
  23786. });
  23787. exports["default"] = void 0;
  23788. var _parseHTML = interopRequireDefault(parseHTML_1);
  23789. var _rangeSort = interopRequireDefault(rangeSort);
  23790. /**
  23791. * Copyright (c) 2013-present, Facebook, Inc.
  23792. * All rights reserved.
  23793. *
  23794. * Copyright (c) 2013-present, Facebook, Inc.
  23795. * All rights reserved.
  23796. *
  23797. * This source code is licensed under the BSD-style license found in the
  23798. * LICENSE file in the /src directory of this source tree. An additional grant
  23799. * of patent rights can be found in the PATENTS file in the same directory.
  23800. */
  23801. var NBSP = '&nbsp;';
  23802. var SPACE = ' '; // Arbitrary max indent
  23803. var MAX_DEPTH = 4; // used for replacing characters in HTML
  23804. /* eslint-disable no-control-regex */
  23805. var REGEX_CR = new RegExp('\r', 'g');
  23806. var REGEX_LF = new RegExp('\n', 'g');
  23807. var REGEX_NBSP = new RegExp(NBSP, 'g');
  23808. var REGEX_BLOCK_DELIMITER = new RegExp('\r', 'g');
  23809. /* eslint-enable no-control-regex */
  23810. // Block tag flow is different because LIs do not have
  23811. // a deterministic style ;_;
  23812. var blockTags = ['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'li', 'blockquote', 'pre'];
  23813. var inlineTags = {
  23814. b: 'BOLD',
  23815. code: 'CODE',
  23816. del: 'STRIKETHROUGH',
  23817. em: 'ITALIC',
  23818. i: 'ITALIC',
  23819. s: 'STRIKETHROUGH',
  23820. strike: 'STRIKETHROUGH',
  23821. strong: 'BOLD',
  23822. u: 'UNDERLINE'
  23823. };
  23824. var handleMiddleware = function handleMiddleware(maybeMiddleware, base) {
  23825. if (maybeMiddleware && maybeMiddleware.__isMiddleware === true) {
  23826. return maybeMiddleware(base);
  23827. }
  23828. return maybeMiddleware;
  23829. };
  23830. var defaultHTMLToBlock = function defaultHTMLToBlock(nodeName, node, lastList) {
  23831. return undefined;
  23832. };
  23833. var defaultHTMLToStyle = function defaultHTMLToStyle(nodeName, node, currentStyle) {
  23834. return currentStyle;
  23835. };
  23836. var defaultHTMLToEntity = function defaultHTMLToEntity(nodeName, node) {
  23837. return undefined;
  23838. };
  23839. var defaultTextToEntity = function defaultTextToEntity(text) {
  23840. return [];
  23841. };
  23842. var nullthrows = function nullthrows(x) {
  23843. if (x != null) {
  23844. return x;
  23845. }
  23846. throw new Error('Got unexpected null or undefined');
  23847. };
  23848. var sanitizeDraftText = function sanitizeDraftText(input) {
  23849. return input.replace(REGEX_BLOCK_DELIMITER, '');
  23850. };
  23851. function getEmptyChunk() {
  23852. return {
  23853. text: '',
  23854. inlines: [],
  23855. entities: [],
  23856. blocks: []
  23857. };
  23858. }
  23859. function getWhitespaceChunk(inEntity) {
  23860. var entities = new Array(1);
  23861. if (inEntity) {
  23862. entities[0] = inEntity;
  23863. }
  23864. return {
  23865. text: SPACE,
  23866. inlines: [(0, immutable$2.OrderedSet)()],
  23867. entities: entities,
  23868. blocks: []
  23869. };
  23870. }
  23871. function getSoftNewlineChunk(block, depth) {
  23872. var flat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  23873. var data = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : (0, immutable$2.Map)();
  23874. if (flat === true) {
  23875. return {
  23876. text: '\r',
  23877. inlines: [(0, immutable$2.OrderedSet)()],
  23878. entities: new Array(1),
  23879. blocks: [{
  23880. type: block,
  23881. data: data,
  23882. depth: Math.max(0, Math.min(MAX_DEPTH, depth))
  23883. }],
  23884. isNewline: true
  23885. };
  23886. }
  23887. return {
  23888. text: '\n',
  23889. inlines: [(0, immutable$2.OrderedSet)()],
  23890. entities: new Array(1),
  23891. blocks: []
  23892. };
  23893. }
  23894. function getBlockDividerChunk(block, depth) {
  23895. var data = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : (0, immutable$2.Map)();
  23896. return {
  23897. text: '\r',
  23898. inlines: [(0, immutable$2.OrderedSet)()],
  23899. entities: new Array(1),
  23900. blocks: [{
  23901. type: block,
  23902. data: data,
  23903. depth: Math.max(0, Math.min(MAX_DEPTH, depth))
  23904. }]
  23905. };
  23906. }
  23907. function getBlockTypeForTag(tag, lastList) {
  23908. switch (tag) {
  23909. case 'h1':
  23910. return 'header-one';
  23911. case 'h2':
  23912. return 'header-two';
  23913. case 'h3':
  23914. return 'header-three';
  23915. case 'h4':
  23916. return 'header-four';
  23917. case 'h5':
  23918. return 'header-five';
  23919. case 'h6':
  23920. return 'header-six';
  23921. case 'li':
  23922. if (lastList === 'ol') {
  23923. return 'ordered-list-item';
  23924. }
  23925. return 'unordered-list-item';
  23926. case 'blockquote':
  23927. return 'blockquote';
  23928. case 'pre':
  23929. return 'code-block';
  23930. case 'div':
  23931. case 'p':
  23932. return 'unstyled';
  23933. default:
  23934. return null;
  23935. }
  23936. }
  23937. function baseCheckBlockType(nodeName, node, lastList) {
  23938. return getBlockTypeForTag(nodeName, lastList);
  23939. }
  23940. function processInlineTag(tag, node, currentStyle) {
  23941. var styleToCheck = inlineTags[tag];
  23942. if (styleToCheck) {
  23943. currentStyle = currentStyle.add(styleToCheck).toOrderedSet();
  23944. } else if (node instanceof HTMLElement) {
  23945. var htmlElement = node;
  23946. currentStyle = currentStyle.withMutations(function (style) {
  23947. if (htmlElement.style.fontWeight === 'bold') {
  23948. style.add('BOLD');
  23949. }
  23950. if (htmlElement.style.fontStyle === 'italic') {
  23951. style.add('ITALIC');
  23952. }
  23953. if (htmlElement.style.textDecoration === 'underline') {
  23954. style.add('UNDERLINE');
  23955. }
  23956. if (htmlElement.style.textDecoration === 'line-through') {
  23957. style.add('STRIKETHROUGH');
  23958. }
  23959. }).toOrderedSet();
  23960. }
  23961. return currentStyle;
  23962. }
  23963. function baseProcessInlineTag(tag, node) {
  23964. var inlineStyles = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : (0, immutable$2.OrderedSet)();
  23965. return processInlineTag(tag, node, inlineStyles);
  23966. }
  23967. function joinChunks(A, B) {
  23968. var flat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  23969. // Sometimes two blocks will touch in the DOM and we need to strip the
  23970. // extra delimiter to preserve niceness.
  23971. var firstInB = B.text.slice(0, 1);
  23972. var lastInA = A.text.slice(-1);
  23973. var adjacentDividers = lastInA === '\r' && firstInB === '\r';
  23974. var isJoiningBlocks = A.text !== '\r' && B.text !== '\r'; // when joining two full blocks like this we want to pop one divider
  23975. var addingNewlineToEmptyBlock = A.text === '\r' && !A.isNewline && B.isNewline; // when joining a newline to an empty block we want to remove the newline
  23976. if (adjacentDividers && (isJoiningBlocks || addingNewlineToEmptyBlock)) {
  23977. A.text = A.text.slice(0, -1);
  23978. A.inlines.pop();
  23979. A.entities.pop();
  23980. A.blocks.pop();
  23981. } // Kill whitespace after blocks if flat mode is on
  23982. if (A.text.slice(-1) === '\r' && flat === true) {
  23983. if (B.text === SPACE || B.text === '\n') {
  23984. return A;
  23985. } else if (firstInB === SPACE || firstInB === '\n') {
  23986. B.text = B.text.slice(1);
  23987. B.inlines.shift();
  23988. B.entities.shift();
  23989. }
  23990. }
  23991. var isNewline = A.text.length === 0 && B.isNewline;
  23992. return {
  23993. text: A.text + B.text,
  23994. inlines: A.inlines.concat(B.inlines),
  23995. entities: A.entities.concat(B.entities),
  23996. blocks: A.blocks.concat(B.blocks),
  23997. isNewline: isNewline
  23998. };
  23999. }
  24000. /*
  24001. * Check to see if we have anything like <p> <blockquote> <h1>... to create
  24002. * block tags from. If we do, we can use those and ignore <div> tags. If we
  24003. * don't, we can treat <div> tags as meaningful (unstyled) blocks.
  24004. */
  24005. function containsSemanticBlockMarkup(html) {
  24006. return blockTags.some(function (tag) {
  24007. return html.indexOf("<".concat(tag)) !== -1;
  24008. });
  24009. }
  24010. function genFragment(node, inlineStyle, lastList, inBlock, fragmentBlockTags, depth, processCustomInlineStyles, checkEntityNode, checkEntityText, checkBlockType, createEntity, getEntity, mergeEntityData, replaceEntityData, options, inEntity) {
  24011. var nodeName = node.nodeName.toLowerCase();
  24012. var newBlock = false;
  24013. var nextBlockType = 'unstyled'; // Base Case
  24014. if (nodeName === '#text') {
  24015. var text = node.textContent;
  24016. if (text.trim() === '' && inBlock === null) {
  24017. return getEmptyChunk();
  24018. }
  24019. if (text.trim() === '' && inBlock !== 'code-block') {
  24020. return getWhitespaceChunk(inEntity);
  24021. }
  24022. if (inBlock !== 'code-block') {
  24023. // Can't use empty string because MSWord
  24024. text = text.replace(REGEX_LF, SPACE);
  24025. }
  24026. var entities = Array(text.length).fill(inEntity);
  24027. var offsetChange = 0;
  24028. var textEntities = checkEntityText(text, createEntity, getEntity, mergeEntityData, replaceEntityData).sort(_rangeSort["default"]);
  24029. textEntities.forEach(function (_ref) {
  24030. var entity = _ref.entity,
  24031. offset = _ref.offset,
  24032. length = _ref.length,
  24033. result = _ref.result;
  24034. var adjustedOffset = offset + offsetChange;
  24035. if (result === null || result === undefined) {
  24036. result = text.substr(adjustedOffset, length);
  24037. }
  24038. var textArray = text.split('');
  24039. textArray.splice.bind(textArray, adjustedOffset, length).apply(textArray, result.split(''));
  24040. text = textArray.join('');
  24041. entities.splice.bind(entities, adjustedOffset, length).apply(entities, Array(result.length).fill(entity));
  24042. offsetChange += result.length - length;
  24043. });
  24044. return {
  24045. text: text,
  24046. inlines: Array(text.length).fill(inlineStyle),
  24047. entities: entities,
  24048. blocks: []
  24049. };
  24050. } // BR tags
  24051. if (nodeName === 'br') {
  24052. var _blockType = inBlock;
  24053. if (_blockType === null) {
  24054. // BR tag is at top level, treat it as an unstyled block
  24055. return getSoftNewlineChunk('unstyled', depth, true);
  24056. }
  24057. return getSoftNewlineChunk(_blockType || 'unstyled', depth, options.flat);
  24058. }
  24059. var chunk = getEmptyChunk();
  24060. var newChunk = null; // Inline tags
  24061. inlineStyle = processInlineTag(nodeName, node, inlineStyle);
  24062. inlineStyle = processCustomInlineStyles(nodeName, node, inlineStyle); // Handle lists
  24063. if (nodeName === 'ul' || nodeName === 'ol') {
  24064. if (lastList) {
  24065. depth += 1;
  24066. }
  24067. lastList = nodeName;
  24068. inBlock = null;
  24069. } // Block Tags
  24070. var blockInfo = checkBlockType(nodeName, node, lastList, inBlock);
  24071. var blockType;
  24072. var blockDataMap;
  24073. if (blockInfo === false) {
  24074. return getEmptyChunk();
  24075. }
  24076. blockInfo = blockInfo || {};
  24077. if (typeof blockInfo === 'string') {
  24078. blockType = blockInfo;
  24079. blockDataMap = (0, immutable$2.Map)();
  24080. } else {
  24081. blockType = typeof blockInfo === 'string' ? blockInfo : blockInfo.type;
  24082. blockDataMap = blockInfo.data ? (0, immutable$2.Map)(blockInfo.data) : (0, immutable$2.Map)();
  24083. }
  24084. if (!inBlock && (fragmentBlockTags.indexOf(nodeName) !== -1 || blockType)) {
  24085. chunk = getBlockDividerChunk(blockType || getBlockTypeForTag(nodeName, lastList), depth, blockDataMap);
  24086. inBlock = blockType || getBlockTypeForTag(nodeName, lastList);
  24087. newBlock = true;
  24088. } else if (lastList && (inBlock === 'ordered-list-item' || inBlock === 'unordered-list-item') && nodeName === 'li') {
  24089. var listItemBlockType = getBlockTypeForTag(nodeName, lastList);
  24090. chunk = getBlockDividerChunk(listItemBlockType, depth);
  24091. inBlock = listItemBlockType;
  24092. newBlock = true;
  24093. nextBlockType = lastList === 'ul' ? 'unordered-list-item' : 'ordered-list-item';
  24094. } else if (inBlock && inBlock !== 'atomic' && blockType === 'atomic') {
  24095. inBlock = blockType;
  24096. newBlock = true;
  24097. chunk = getSoftNewlineChunk(blockType, depth, true, // atomic blocks within non-atomic blocks must always be split out
  24098. blockDataMap);
  24099. } // Recurse through children
  24100. var child = node.firstChild; // hack to allow conversion of atomic blocks from HTML (e.g. <figure><img
  24101. // src="..." /></figure>). since metadata must be stored on an entity text
  24102. // must exist for the entity to apply to. the way chunks are joined strips
  24103. // whitespace at the end so it cannot be a space character.
  24104. if (child == null && inEntity && (blockType === 'atomic' || inBlock === 'atomic')) {
  24105. child = document.createTextNode('a');
  24106. }
  24107. if (child != null) {
  24108. nodeName = child.nodeName.toLowerCase();
  24109. }
  24110. var entityId = null;
  24111. while (child) {
  24112. entityId = checkEntityNode(nodeName, child, createEntity, getEntity, mergeEntityData, replaceEntityData);
  24113. newChunk = genFragment(child, inlineStyle, lastList, inBlock, fragmentBlockTags, depth, processCustomInlineStyles, checkEntityNode, checkEntityText, checkBlockType, createEntity, getEntity, mergeEntityData, replaceEntityData, options, entityId || inEntity);
  24114. chunk = joinChunks(chunk, newChunk, options.flat);
  24115. var sibling = child.nextSibling; // Put in a newline to break up blocks inside blocks
  24116. if (sibling && fragmentBlockTags.indexOf(nodeName) >= 0 && inBlock) {
  24117. var newBlockInfo = checkBlockType(nodeName, child, lastList, inBlock);
  24118. var newBlockType = void 0;
  24119. var newBlockData = void 0;
  24120. if (newBlockInfo !== false) {
  24121. newBlockInfo = newBlockInfo || {};
  24122. if (typeof newBlockInfo === 'string') {
  24123. newBlockType = newBlockInfo;
  24124. newBlockData = (0, immutable$2.Map)();
  24125. } else {
  24126. newBlockType = newBlockInfo.type || getBlockTypeForTag(nodeName, lastList);
  24127. newBlockData = newBlockInfo.data ? (0, immutable$2.Map)(newBlockInfo.data) : (0, immutable$2.Map)();
  24128. }
  24129. chunk = joinChunks(chunk, getSoftNewlineChunk(newBlockType, depth, options.flat, newBlockData), options.flat);
  24130. }
  24131. }
  24132. if (sibling) {
  24133. nodeName = sibling.nodeName.toLowerCase();
  24134. }
  24135. child = sibling;
  24136. }
  24137. if (newBlock) {
  24138. chunk = joinChunks(chunk, getBlockDividerChunk(nextBlockType, depth, (0, immutable$2.Map)()), options.flat);
  24139. }
  24140. return chunk;
  24141. }
  24142. function getChunkForHTML(html, processCustomInlineStyles, checkEntityNode, checkEntityText, checkBlockType, createEntity, getEntity, mergeEntityData, replaceEntityData, options, DOMBuilder) {
  24143. html = html.trim().replace(REGEX_CR, '').replace(REGEX_NBSP, SPACE);
  24144. var safeBody = DOMBuilder(html);
  24145. if (!safeBody) {
  24146. return null;
  24147. } // Sometimes we aren't dealing with content that contains nice semantic
  24148. // tags. In this case, use divs to separate everything out into paragraphs
  24149. // and hope for the best.
  24150. var workingBlocks = containsSemanticBlockMarkup(html) ? blockTags.concat(['div']) : ['div']; // Start with -1 block depth to offset the fact that we are passing in a fake
  24151. // UL block to sta rt with.
  24152. var chunk = genFragment(safeBody, (0, immutable$2.OrderedSet)(), 'ul', null, workingBlocks, -1, processCustomInlineStyles, checkEntityNode, checkEntityText, checkBlockType, createEntity, getEntity, mergeEntityData, replaceEntityData, options); // join with previous block to prevent weirdness on paste
  24153. if (chunk.text.indexOf('\r') === 0) {
  24154. chunk = {
  24155. text: chunk.text.slice(1),
  24156. inlines: chunk.inlines.slice(1),
  24157. entities: chunk.entities.slice(1),
  24158. blocks: chunk.blocks
  24159. };
  24160. } // Kill block delimiter at the end
  24161. if (chunk.text.slice(-1) === '\r') {
  24162. chunk.text = chunk.text.slice(0, -1);
  24163. chunk.inlines = chunk.inlines.slice(0, -1);
  24164. chunk.entities = chunk.entities.slice(0, -1);
  24165. chunk.blocks.pop();
  24166. } // If we saw no block tags, put an unstyled one in
  24167. if (chunk.blocks.length === 0) {
  24168. chunk.blocks.push({
  24169. type: 'unstyled',
  24170. data: (0, immutable$2.Map)(),
  24171. depth: 0
  24172. });
  24173. } // Sometimes we start with text that isn't in a block, which is then
  24174. // followed by blocks. Need to fix up the blocks to add in
  24175. // an unstyled block for this content
  24176. if (chunk.text.split('\r').length === chunk.blocks.length + 1) {
  24177. chunk.blocks.unshift({
  24178. type: 'unstyled',
  24179. data: (0, immutable$2.Map)(),
  24180. depth: 0
  24181. });
  24182. }
  24183. return chunk;
  24184. }
  24185. function convertFromHTMLtoContentBlocks(html, processCustomInlineStyles, checkEntityNode, checkEntityText, checkBlockType, createEntity, getEntity, mergeEntityData, replaceEntityData, options, DOMBuilder, generateKey) {
  24186. // Be ABSOLUTELY SURE that the dom builder you pass hare won't execute
  24187. // arbitrary code in whatever environment you're running this in. For an
  24188. // example of how we try to do this in-browser, see getSafeBodyFromHTML.
  24189. var chunk = getChunkForHTML(html, processCustomInlineStyles, checkEntityNode, checkEntityText, checkBlockType, createEntity, getEntity, mergeEntityData, replaceEntityData, options, DOMBuilder);
  24190. if (chunk == null) {
  24191. return [];
  24192. }
  24193. var start = 0;
  24194. return chunk.text.split('\r').map(function (textBlock, blockIndex) {
  24195. // Make absolutely certain that our text is acceptable.
  24196. textBlock = sanitizeDraftText(textBlock);
  24197. var end = start + textBlock.length;
  24198. var inlines = nullthrows(chunk).inlines.slice(start, end);
  24199. var entities = nullthrows(chunk).entities.slice(start, end);
  24200. var characterList = (0, immutable$2.List)(inlines.map(function (style, entityIndex) {
  24201. var data = {
  24202. style: style,
  24203. entity: null
  24204. };
  24205. if (entities[entityIndex]) {
  24206. data.entity = entities[entityIndex];
  24207. }
  24208. return Draft.CharacterMetadata.create(data);
  24209. }));
  24210. start = end + 1;
  24211. return new Draft.ContentBlock({
  24212. key: generateKey(),
  24213. type: nullthrows(chunk).blocks[blockIndex].type,
  24214. data: nullthrows(chunk).blocks[blockIndex].data,
  24215. depth: nullthrows(chunk).blocks[blockIndex].depth,
  24216. text: textBlock,
  24217. characterList: characterList
  24218. });
  24219. });
  24220. }
  24221. var convertFromHTML = function convertFromHTML(_ref2) {
  24222. var _ref2$htmlToStyle = _ref2.htmlToStyle,
  24223. htmlToStyle = _ref2$htmlToStyle === void 0 ? defaultHTMLToStyle : _ref2$htmlToStyle,
  24224. _ref2$htmlToEntity = _ref2.htmlToEntity,
  24225. htmlToEntity = _ref2$htmlToEntity === void 0 ? defaultHTMLToEntity : _ref2$htmlToEntity,
  24226. _ref2$textToEntity = _ref2.textToEntity,
  24227. textToEntity = _ref2$textToEntity === void 0 ? defaultTextToEntity : _ref2$textToEntity,
  24228. _ref2$htmlToBlock = _ref2.htmlToBlock,
  24229. htmlToBlock = _ref2$htmlToBlock === void 0 ? defaultHTMLToBlock : _ref2$htmlToBlock;
  24230. return function (html) {
  24231. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
  24232. flat: false
  24233. };
  24234. var DOMBuilder = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _parseHTML["default"];
  24235. var generateKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : Draft.genKey;
  24236. var contentState = Draft.ContentState.createFromText('');
  24237. var createEntityWithContentState = function createEntityWithContentState() {
  24238. if (contentState.createEntity) {
  24239. var _contentState;
  24240. contentState = (_contentState = contentState).createEntity.apply(_contentState, arguments);
  24241. return contentState.getLastCreatedEntityKey();
  24242. }
  24243. return Draft.Entity.create.apply(Draft.Entity, arguments);
  24244. };
  24245. var getEntityWithContentState = function getEntityWithContentState() {
  24246. if (contentState.getEntity) {
  24247. var _contentState2;
  24248. return (_contentState2 = contentState).getEntity.apply(_contentState2, arguments);
  24249. }
  24250. return Draft.Entity.get.apply(Draft.Entity, arguments);
  24251. };
  24252. var mergeEntityDataWithContentState = function mergeEntityDataWithContentState() {
  24253. if (contentState.mergeEntityData) {
  24254. var _contentState3;
  24255. contentState = (_contentState3 = contentState).mergeEntityData.apply(_contentState3, arguments);
  24256. return;
  24257. }
  24258. Draft.Entity.mergeData.apply(Draft.Entity, arguments);
  24259. };
  24260. var replaceEntityDataWithContentState = function replaceEntityDataWithContentState() {
  24261. if (contentState.replaceEntityData) {
  24262. var _contentState4;
  24263. contentState = (_contentState4 = contentState).replaceEntityData.apply(_contentState4, arguments);
  24264. return;
  24265. }
  24266. Draft.Entity.replaceData.apply(Draft.Entity, arguments);
  24267. };
  24268. var contentBlocks = convertFromHTMLtoContentBlocks(html, handleMiddleware(htmlToStyle, baseProcessInlineTag), handleMiddleware(htmlToEntity, defaultHTMLToEntity), handleMiddleware(textToEntity, defaultTextToEntity), handleMiddleware(htmlToBlock, baseCheckBlockType), createEntityWithContentState, getEntityWithContentState, mergeEntityDataWithContentState, replaceEntityDataWithContentState, options, DOMBuilder, generateKey);
  24269. var blockMap = Draft.BlockMapBuilder.createFromArray(contentBlocks);
  24270. var firstBlockKey = contentBlocks[0].getKey();
  24271. return contentState.merge({
  24272. blockMap: blockMap,
  24273. selectionBefore: Draft.SelectionState.createEmpty(firstBlockKey),
  24274. selectionAfter: Draft.SelectionState.createEmpty(firstBlockKey)
  24275. });
  24276. };
  24277. };
  24278. var _default = function _default() {
  24279. if (arguments.length >= 1 && typeof (arguments.length <= 0 ? undefined : arguments[0]) === 'string') {
  24280. return convertFromHTML({}).apply(void 0, arguments);
  24281. }
  24282. return convertFromHTML.apply(void 0, arguments);
  24283. };
  24284. exports["default"] = _default;
  24285. });
  24286. _commonjsHelpers.unwrapExports(convertFromHTML_1);
  24287. var lib = _commonjsHelpers.createCommonjsModule(function (module, exports) {
  24288. Object.defineProperty(exports, "__esModule", {
  24289. value: true
  24290. });
  24291. Object.defineProperty(exports, "convertToHTML", {
  24292. enumerable: true,
  24293. get: function get() {
  24294. return _convertToHTML["default"];
  24295. }
  24296. });
  24297. Object.defineProperty(exports, "convertFromHTML", {
  24298. enumerable: true,
  24299. get: function get() {
  24300. return _convertFromHTML["default"];
  24301. }
  24302. });
  24303. Object.defineProperty(exports, "parseHTML", {
  24304. enumerable: true,
  24305. get: function get() {
  24306. return _parseHTML["default"];
  24307. }
  24308. });
  24309. var _convertToHTML = interopRequireDefault(convertToHTML_1);
  24310. var _convertFromHTML = interopRequireDefault(convertFromHTML_1);
  24311. var _parseHTML = interopRequireDefault(parseHTML_1);
  24312. });
  24313. _commonjsHelpers.unwrapExports(lib);
  24314. var configs = _commonjsHelpers.createCommonjsModule(function (module, exports) {
  24315. Object.defineProperty(exports, "__esModule", {
  24316. value: true
  24317. });
  24318. exports.getFromHTMLConfig = exports.getToHTMLConfig = exports.blocks = exports.getHexColor = exports.defaultFontFamilies = exports.namedColors = undefined;
  24319. var _extends = Object.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; };
  24320. var _react2 = _interopRequireDefault(React__default);
  24321. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  24322. function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
  24323. var namedColors = exports.namedColors = {
  24324. "aliceblue": "#f0f8ff",
  24325. "antiquewhite": "#faebd7",
  24326. "aqua": "#00ffff",
  24327. "aquamarine": "#7fffd4",
  24328. "azure": "#f0ffff",
  24329. "beige": "#f5f5dc",
  24330. "bisque": "#ffe4c4",
  24331. "black": "#000000",
  24332. "blanchedalmond": "#ffebcd",
  24333. "blue": "#0000ff",
  24334. "blueviolet": "#8a2be2",
  24335. "brown": "#a52a2a",
  24336. "burlywood": "#deb887",
  24337. "cadetblue": "#5f9ea0",
  24338. "chartreuse": "#7fff00",
  24339. "chocolate": "#d2691e",
  24340. "coral": "#ff7f50",
  24341. "cornflowerblue": "#6495ed",
  24342. "cornsilk": "#fff8dc",
  24343. "crimson": "#dc143c",
  24344. "cyan": "#00ffff",
  24345. "darkblue": "#00008b",
  24346. "darkcyan": "#008b8b",
  24347. "darkgoldenrod": "#b8860b",
  24348. "darkgray": "#a9a9a9",
  24349. "darkgreen": "#006400",
  24350. "darkkhaki": "#bdb76b",
  24351. "darkmagenta": "#8b008b",
  24352. "darkolivegreen": "#556b2f",
  24353. "darkorange": "#ff8c00",
  24354. "darkorchid": "#9932cc",
  24355. "darkred": "#8b0000",
  24356. "darksalmon": "#e9967a",
  24357. "darkseagreen": "#8fbc8f",
  24358. "darkslateblue": "#483d8b",
  24359. "darkslategray": "#2f4f4f",
  24360. "darkturquoise": "#00ced1",
  24361. "darkviolet": "#9400d3",
  24362. "deeppink": "#ff1493",
  24363. "deepskyblue": "#00bfff",
  24364. "dimgray": "#696969",
  24365. "dodgerblue": "#1e90ff",
  24366. "firebrick": "#b22222",
  24367. "floralwhite": "#fffaf0",
  24368. "forestgreen": "#228b22",
  24369. "fuchsia": "#ff00ff",
  24370. "gainsboro": "#dcdcdc",
  24371. "ghostwhite": "#f8f8ff",
  24372. "gold": "#ffd700",
  24373. "goldenrod": "#daa520",
  24374. "gray": "#808080",
  24375. "green": "#008000",
  24376. "greenyellow": "#adff2f",
  24377. "honeydew": "#f0fff0",
  24378. "hotpink": "#ff69b4",
  24379. "indianred ": "#cd5c5c",
  24380. "indigo": "#4b0082",
  24381. "ivory": "#fffff0",
  24382. "khaki": "#f0e68c",
  24383. "lavender": "#e6e6fa",
  24384. "lavenderblush": "#fff0f5",
  24385. "lawngreen": "#7cfc00",
  24386. "lemonchiffon": "#fffacd",
  24387. "lightblue": "#add8e6",
  24388. "lightcoral": "#f08080",
  24389. "lightcyan": "#e0ffff",
  24390. "lightgoldenrodyellow": "#fafad2",
  24391. "lightgrey": "#d3d3d3",
  24392. "lightgreen": "#90ee90",
  24393. "lightpink": "#ffb6c1",
  24394. "lightsalmon": "#ffa07a",
  24395. "lightseagreen": "#20b2aa",
  24396. "lightskyblue": "#87cefa",
  24397. "lightslategray": "#778899",
  24398. "lightsteelblue": "#b0c4de",
  24399. "lightyellow": "#ffffe0",
  24400. "lime": "#00ff00",
  24401. "limegreen": "#32cd32",
  24402. "linen": "#faf0e6",
  24403. "magenta": "#ff00ff",
  24404. "maroon": "#800000",
  24405. "mediumaquamarine": "#66cdaa",
  24406. "mediumblue": "#0000cd",
  24407. "mediumorchid": "#ba55d3",
  24408. "mediumpurple": "#9370d8",
  24409. "mediumseagreen": "#3cb371",
  24410. "mediumslateblue": "#7b68ee",
  24411. "mediumspringgreen": "#00fa9a",
  24412. "mediumturquoise": "#48d1cc",
  24413. "mediumvioletred": "#c71585",
  24414. "midnightblue": "#191970",
  24415. "mintcream": "#f5fffa",
  24416. "mistyrose": "#ffe4e1",
  24417. "moccasin": "#ffe4b5",
  24418. "navajowhite": "#ffdead",
  24419. "navy": "#000080",
  24420. "oldlace": "#fdf5e6",
  24421. "olive": "#808000",
  24422. "olivedrab": "#6b8e23",
  24423. "orange": "#ffa500",
  24424. "orangered": "#ff4500",
  24425. "orchid": "#da70d6",
  24426. "palegoldenrod": "#eee8aa",
  24427. "palegreen": "#98fb98",
  24428. "paleturquoise": "#afeeee",
  24429. "palevioletred": "#d87093",
  24430. "papayawhip": "#ffefd5",
  24431. "peachpuff": "#ffdab9",
  24432. "peru": "#cd853f",
  24433. "pink": "#ffc0cb",
  24434. "plum": "#dda0dd",
  24435. "powderblue": "#b0e0e6",
  24436. "purple": "#800080",
  24437. "rebeccapurple": "#663399",
  24438. "red": "#ff0000",
  24439. "rosybrown": "#bc8f8f",
  24440. "royalblue": "#4169e1",
  24441. "saddlebrown": "#8b4513",
  24442. "salmon": "#fa8072",
  24443. "sandybrown": "#f4a460",
  24444. "seagreen": "#2e8b57",
  24445. "seashell": "#fff5ee",
  24446. "sienna": "#a0522d",
  24447. "silver": "#c0c0c0",
  24448. "skyblue": "#87ceeb",
  24449. "slateblue": "#6a5acd",
  24450. "slategray": "#708090",
  24451. "snow": "#fffafa",
  24452. "springgreen": "#00ff7f",
  24453. "steelblue": "#4682b4",
  24454. "tan": "#d2b48c",
  24455. "teal": "#008080",
  24456. "thistle": "#d8bfd8",
  24457. "tomato": "#ff6347",
  24458. "turquoise": "#40e0d0",
  24459. "violet": "#ee82ee",
  24460. "wheat": "#f5deb3",
  24461. "white": "#ffffff",
  24462. "whitesmoke": "#f5f5f5",
  24463. "yellow": "#ffff00",
  24464. "yellowgreen": "#9acd32"
  24465. };
  24466. var getStyleValue = function getStyleValue(style) {
  24467. return style.split('-')[1];
  24468. };
  24469. var defaultUnitExportFn = function defaultUnitExportFn(unit) {
  24470. return unit + 'px';
  24471. };
  24472. var defaultUnitImportFn = function defaultUnitImportFn(unit) {
  24473. return unit.replace('px', '');
  24474. };
  24475. var ignoredNodeAttributes = ['style'];
  24476. var ignoredEntityNodeAttributes = ['style', 'href', 'target', 'alt', 'title', 'id', 'controls', 'autoplay', 'loop', 'poster'];
  24477. var spreadNodeAttributes = function spreadNodeAttributes(attributesObject) {
  24478. return Object.keys(attributesObject).reduce(function (attributeString, attributeName) {
  24479. return attributeString + " " + attributeName + "=\"" + attributesObject[attributeName] + "\"";
  24480. }, '').replace(/^\s$/, '');
  24481. };
  24482. var defaultFontFamilies = exports.defaultFontFamilies = [{
  24483. name: 'Araial',
  24484. family: 'Arial, Helvetica, sans-serif'
  24485. }, {
  24486. name: 'Georgia',
  24487. family: 'Georgia, serif'
  24488. }, {
  24489. name: 'Impact',
  24490. family: 'Impact, serif'
  24491. }, {
  24492. name: 'Monospace',
  24493. family: '"Courier New", Courier, monospace'
  24494. }, {
  24495. name: 'Tahoma',
  24496. family: "tahoma, arial, 'Hiragino Sans GB', 宋体, sans-serif"
  24497. }];
  24498. var getHexColor = exports.getHexColor = function getHexColor(color) {
  24499. color = color.replace('color:', '').replace(';', '').replace(' ', '');
  24500. if (/^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/.test(color)) {
  24501. return color;
  24502. } else if (namedColors[color]) {
  24503. return namedColors[color];
  24504. } else if (color.indexOf('rgb') === 0) {
  24505. var rgbArray = color.split(',');
  24506. var convertedColor = rgbArray.length < 3 ? null : '#' + [rgbArray[0], rgbArray[1], rgbArray[2]].map(function (x) {
  24507. var hex = parseInt(x.replace(/\D/g, ''), 10).toString(16);
  24508. return hex.length === 1 ? '0' + hex : hex;
  24509. }).join('');
  24510. return (/^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/.test(convertedColor) ? convertedColor : null
  24511. );
  24512. } else {
  24513. return null;
  24514. }
  24515. };
  24516. var blocks = exports.blocks = {
  24517. 'header-one': 'h1',
  24518. 'header-two': 'h2',
  24519. 'header-three': 'h3',
  24520. 'header-four': 'h4',
  24521. 'header-five': 'h5',
  24522. 'header-six': 'h6',
  24523. 'unstyled': 'p',
  24524. 'blockquote': 'blockquote'
  24525. };
  24526. var blockTypes = Object.keys(blocks);
  24527. var blockNames = blockTypes.map(function (key) {
  24528. return blocks[key];
  24529. });
  24530. var convertAtomicBlock = function convertAtomicBlock(block, contentState, blockNodeAttributes) {
  24531. if (!block || !block.key) {
  24532. return _react2.default.createElement("p", null);
  24533. }
  24534. var contentBlock = contentState.getBlockForKey(block.key);
  24535. var className = blockNodeAttributes.class,
  24536. nodeAttrAsProps = _objectWithoutProperties(blockNodeAttributes, ["class"]);
  24537. nodeAttrAsProps.className = className;
  24538. if (!contentBlock) {
  24539. return _react2.default.createElement("p", null);
  24540. }
  24541. var entityKey = contentBlock.getEntityAt(0);
  24542. if (!entityKey) {
  24543. return _react2.default.createElement("p", null);
  24544. }
  24545. var entity = contentState.getEntity(entityKey);
  24546. var mediaType = entity.getType().toLowerCase();
  24547. var _block$data = block.data,
  24548. float = _block$data.float,
  24549. alignment = _block$data.alignment;
  24550. var _entity$getData = entity.getData(),
  24551. url = _entity$getData.url,
  24552. link = _entity$getData.link,
  24553. link_target = _entity$getData.link_target,
  24554. width = _entity$getData.width,
  24555. height = _entity$getData.height,
  24556. meta = _entity$getData.meta;
  24557. if (mediaType === 'image') {
  24558. var imageWrapStyle = {};
  24559. var styledClassName = '';
  24560. if (float) {
  24561. imageWrapStyle.float = float;
  24562. styledClassName += ' float-' + float;
  24563. } else if (alignment) {
  24564. imageWrapStyle.textAlign = alignment;
  24565. styledClassName += ' align-' + alignment;
  24566. }
  24567. if (link) {
  24568. return _react2.default.createElement(
  24569. "div",
  24570. { className: "media-wrap image-wrap" + styledClassName, style: imageWrapStyle },
  24571. _react2.default.createElement(
  24572. "a",
  24573. { style: { display: 'inline-block' }, href: link, target: link_target },
  24574. _react2.default.createElement("img", _extends({}, nodeAttrAsProps, meta, { src: url, width: width, height: height, style: { width: width, height: height } }))
  24575. )
  24576. );
  24577. } else {
  24578. return _react2.default.createElement(
  24579. "div",
  24580. { className: "media-wrap image-wrap" + styledClassName, style: imageWrapStyle },
  24581. _react2.default.createElement("img", _extends({}, nodeAttrAsProps, meta, { src: url, width: width, height: height, style: { width: width, height: height } }))
  24582. );
  24583. }
  24584. } else if (mediaType === 'audio') {
  24585. return _react2.default.createElement(
  24586. "div",
  24587. { className: "media-wrap audio-wrap" },
  24588. _react2.default.createElement("audio", _extends({ controls: true }, nodeAttrAsProps, meta, { src: url }))
  24589. );
  24590. } else if (mediaType === 'video') {
  24591. return _react2.default.createElement(
  24592. "div",
  24593. { className: "media-wrap video-wrap" },
  24594. _react2.default.createElement("video", _extends({ controls: true }, nodeAttrAsProps, meta, { src: url, width: width, height: height }))
  24595. );
  24596. } else if (mediaType === 'embed') {
  24597. return _react2.default.createElement(
  24598. "div",
  24599. { className: "media-wrap embed-wrap" },
  24600. _react2.default.createElement("div", { dangerouslySetInnerHTML: { __html: url } })
  24601. );
  24602. } else if (mediaType === 'hr') {
  24603. return _react2.default.createElement("hr", null);
  24604. } else {
  24605. return _react2.default.createElement("p", null);
  24606. }
  24607. };
  24608. var entityToHTML = function entityToHTML(options) {
  24609. return function (entity, originalText) {
  24610. var entityExportFn = options.entityExportFn;
  24611. var entityType = entity.type.toLowerCase();
  24612. if (entityExportFn) {
  24613. var customOutput = entityExportFn(entity, originalText);
  24614. if (customOutput) {
  24615. return customOutput;
  24616. }
  24617. }
  24618. if (entityType === 'link') {
  24619. var _ref = entity.data.nodeAttributes || {},
  24620. className = _ref.class,
  24621. nodeAttrAsProps = _objectWithoutProperties(_ref, ["class"]);
  24622. nodeAttrAsProps.className = className;
  24623. return _react2.default.createElement("a", _extends({ href: entity.data.href, target: entity.data.target }, nodeAttrAsProps));
  24624. }
  24625. };
  24626. };
  24627. var styleToHTML = function styleToHTML(options) {
  24628. return function (style) {
  24629. var unitExportFn = options.unitExportFn || defaultUnitExportFn;
  24630. if (options.styleExportFn) {
  24631. var customOutput = options.styleExportFn(style, options);
  24632. if (customOutput) {
  24633. return customOutput;
  24634. }
  24635. }
  24636. style = style.toLowerCase();
  24637. if (style === 'strikethrough') {
  24638. return _react2.default.createElement("span", { style: { textDecoration: 'line-through' } });
  24639. } else if (style === 'superscript') {
  24640. return _react2.default.createElement("sup", null);
  24641. } else if (style === 'subscript') {
  24642. return _react2.default.createElement("sub", null);
  24643. } else if (style.indexOf('color-') === 0) {
  24644. return _react2.default.createElement("span", { style: { color: '#' + getStyleValue(style) } });
  24645. } else if (style.indexOf('bgcolor-') === 0) {
  24646. return _react2.default.createElement("span", { style: { backgroundColor: '#' + getStyleValue(style) } });
  24647. } else if (style.indexOf('fontsize-') === 0) {
  24648. return _react2.default.createElement("span", { style: { fontSize: unitExportFn(getStyleValue(style), 'font-size', 'html') } });
  24649. } else if (style.indexOf('lineheight-') === 0) {
  24650. return _react2.default.createElement("span", { style: { lineHeight: unitExportFn(getStyleValue(style), 'line-height', 'html') } });
  24651. } else if (style.indexOf('letterspacing-') === 0) {
  24652. return _react2.default.createElement("span", { style: { letterSpacing: unitExportFn(getStyleValue(style), 'letter-spacing', 'html') } });
  24653. } else if (style.indexOf('fontfamily-') === 0) {
  24654. var fontFamily = options.fontFamilies.find(function (item) {
  24655. return item.name.toLowerCase() === getStyleValue(style);
  24656. });
  24657. if (!fontFamily) return;
  24658. return _react2.default.createElement("span", { style: { fontFamily: fontFamily.family } });
  24659. }
  24660. };
  24661. };
  24662. var blockToHTML = function blockToHTML(options) {
  24663. return function (block) {
  24664. var blockExportFn = options.blockExportFn,
  24665. contentState = options.contentState;
  24666. if (blockExportFn) {
  24667. var customOutput = blockExportFn(contentState, block);
  24668. if (customOutput) {
  24669. return customOutput;
  24670. }
  24671. }
  24672. var blockStyle = '';
  24673. var blockType = block.type.toLowerCase();
  24674. var _block$data2 = block.data,
  24675. textAlign = _block$data2.textAlign,
  24676. textIndent = _block$data2.textIndent,
  24677. _block$data2$nodeAttr = _block$data2.nodeAttributes,
  24678. nodeAttributes = _block$data2$nodeAttr === undefined ? {} : _block$data2$nodeAttr;
  24679. var attributeString = spreadNodeAttributes(nodeAttributes);
  24680. if (textAlign || textIndent) {
  24681. blockStyle = ' style="';
  24682. if (textAlign) {
  24683. blockStyle += "text-align:" + textAlign + ";";
  24684. }
  24685. if (textIndent && !isNaN(textIndent) && textIndent > 0) {
  24686. blockStyle += "text-indent:" + textIndent * 2 + "em;";
  24687. }
  24688. blockStyle += '"';
  24689. }
  24690. if (blockType === 'atomic') {
  24691. return convertAtomicBlock(block, contentState, nodeAttributes);
  24692. } else if (blockType === 'code-block') {
  24693. var previousBlock = contentState.getBlockBefore(block.key);
  24694. var nextBlock = contentState.getBlockAfter(block.key);
  24695. var previousBlockType = previousBlock && previousBlock.getType();
  24696. var nextBlockType = nextBlock && nextBlock.getType();
  24697. var start = '';
  24698. var end = '';
  24699. if (previousBlockType !== 'code-block') {
  24700. start = "<pre" + attributeString + "><code>";
  24701. } else {
  24702. start = '';
  24703. }
  24704. if (nextBlockType !== 'code-block') {
  24705. end = '</code></pre>';
  24706. } else {
  24707. end = '<br/>';
  24708. }
  24709. return { start: start, end: end };
  24710. } else if (blocks[blockType]) {
  24711. return {
  24712. start: "<" + blocks[blockType] + blockStyle + attributeString + ">",
  24713. end: "</" + blocks[blockType] + ">"
  24714. };
  24715. } else if (blockType === 'unordered-list-item') {
  24716. return {
  24717. start: "<li" + blockStyle + attributeString + ">",
  24718. end: '</li>',
  24719. nest: _react2.default.createElement("ul", null)
  24720. };
  24721. } else if (blockType === 'ordered-list-item') {
  24722. return {
  24723. start: "<li" + blockStyle + attributeString + ">",
  24724. end: '</li>',
  24725. nest: _react2.default.createElement("ol", null)
  24726. };
  24727. }
  24728. };
  24729. };
  24730. var htmlToStyle = function htmlToStyle(options, source) {
  24731. return function (nodeName, node, currentStyle) {
  24732. if (!node || !node.style) {
  24733. return currentStyle;
  24734. }
  24735. var unitImportFn = options.unitImportFn || defaultUnitImportFn;
  24736. var newStyle = currentStyle;
  24737. [].forEach.call(node.style, function (style) {
  24738. if (nodeName === 'span' && style === 'color') {
  24739. var color = getHexColor(node.style.color);
  24740. newStyle = color ? newStyle.add('COLOR-' + color.replace('#', '').toUpperCase()) : newStyle;
  24741. } else if (nodeName === 'span' && style === 'background-color') {
  24742. var _color = getHexColor(node.style.backgroundColor);
  24743. newStyle = _color ? newStyle.add('BGCOLOR-' + _color.replace('#', '').toUpperCase()) : newStyle;
  24744. } else if (nodeName === 'span' && style === 'font-size') {
  24745. newStyle = newStyle.add('FONTSIZE-' + unitImportFn(node.style.fontSize, 'font-size', source));
  24746. } else if (nodeName === 'span' && style === 'line-height' && !isNaN(parseFloat(node.style.lineHeight, 10))) {
  24747. newStyle = newStyle.add('LINEHEIGHT-' + unitImportFn(node.style.lineHeight, 'line-height', source));
  24748. } else if (nodeName === 'span' && style === 'letter-spacing' && !isNaN(parseFloat(node.style.letterSpacing, 10))) {
  24749. newStyle = newStyle.add('LETTERSPACING-' + unitImportFn(node.style.letterSpacing, 'letter-spacing', source));
  24750. } else if (nodeName === 'span' && style === 'text-decoration') {
  24751. if (node.style.textDecoration === 'line-through') {
  24752. newStyle = newStyle.add('STRIKETHROUGH');
  24753. } else if (node.style.textDecoration === 'underline') {
  24754. newStyle = newStyle.add('UNDERLINE');
  24755. }
  24756. } else if (nodeName === 'span' && style === 'font-family') {
  24757. var fontFamily = options.fontFamilies.find(function (item) {
  24758. return item.family.toLowerCase() === node.style.fontFamily.toLowerCase();
  24759. });
  24760. if (!fontFamily) return;
  24761. newStyle = newStyle.add('FONTFAMILY-' + fontFamily.name.toUpperCase());
  24762. }
  24763. });
  24764. if (nodeName === 'sup') {
  24765. newStyle = newStyle.add('SUPERSCRIPT');
  24766. } else if (nodeName === 'sub') {
  24767. newStyle = newStyle.add('SUBSCRIPT');
  24768. }
  24769. options.styleImportFn && (newStyle = options.styleImportFn(nodeName, node, newStyle, source) || newStyle);
  24770. return newStyle;
  24771. };
  24772. };
  24773. var htmlToEntity = function htmlToEntity(options, source) {
  24774. return function (nodeName, node, createEntity) {
  24775. if (options && options.entityImportFn) {
  24776. var customInput = options.entityImportFn(nodeName, node, createEntity, source);
  24777. if (customInput) {
  24778. return customInput;
  24779. }
  24780. }
  24781. nodeName = nodeName.toLowerCase();
  24782. var alt = node.alt,
  24783. title = node.title,
  24784. id = node.id,
  24785. controls = node.controls,
  24786. autoplay = node.autoplay,
  24787. loop = node.loop,
  24788. poster = node.poster;
  24789. var meta = {};
  24790. var nodeAttributes = {};
  24791. id && (meta.id = id);
  24792. alt && (meta.alt = alt);
  24793. title && (meta.title = title);
  24794. controls && (meta.controls = controls);
  24795. autoplay && (meta.autoPlay = autoplay);
  24796. loop && (meta.loop = loop);
  24797. poster && (meta.poster = poster);
  24798. node.attributes && Object.keys(node.attributes).forEach(function (key) {
  24799. var attr = node.attributes[key];
  24800. ignoredEntityNodeAttributes.indexOf(attr.name) === -1 && (nodeAttributes[attr.name] = attr.value);
  24801. });
  24802. if (nodeName === 'a' && !node.querySelectorAll('img').length) {
  24803. var href = node.getAttribute('href');
  24804. var _target = node.getAttribute('target');
  24805. return createEntity('LINK', 'MUTABLE', { href: href, target: _target, nodeAttributes: nodeAttributes });
  24806. } else if (nodeName === 'audio') {
  24807. return createEntity('AUDIO', 'IMMUTABLE', { url: node.getAttribute('src'), meta: meta, nodeAttributes: nodeAttributes });
  24808. } else if (nodeName === 'video') {
  24809. return createEntity('VIDEO', 'IMMUTABLE', { url: node.getAttribute('src'), meta: meta, nodeAttributes: nodeAttributes });
  24810. } else if (nodeName === 'img') {
  24811. var parentNode = node.parentNode;
  24812. var entityData = { meta: meta };
  24813. var _node$style = node.style,
  24814. width = _node$style.width,
  24815. height = _node$style.height;
  24816. entityData.url = node.getAttribute('src');
  24817. width && (entityData.width = width);
  24818. height && (entityData.height = height);
  24819. if (parentNode.nodeName.toLowerCase() === 'a') {
  24820. entityData.link = parentNode.getAttribute('href');
  24821. entityData.link_target = parentNode.getAttribute('target');
  24822. }
  24823. return createEntity('IMAGE', 'IMMUTABLE', entityData);
  24824. } else if (nodeName === 'hr') {
  24825. return createEntity('HR', 'IMMUTABLE', {});
  24826. } else if (node.parentNode && node.parentNode.classList.contains('embed-wrap')) {
  24827. var embedContent = node.innerHTML || node.outerHTML;
  24828. if (embedContent) {
  24829. return createEntity('EMBED', 'IMMUTABLE', {
  24830. url: embedContent
  24831. });
  24832. }
  24833. }
  24834. };
  24835. };
  24836. var htmlToBlock = function htmlToBlock(options, source) {
  24837. return function (nodeName, node) {
  24838. if (options && options.blockImportFn) {
  24839. var customInput = options.blockImportFn(nodeName, node, source);
  24840. if (customInput) {
  24841. return customInput;
  24842. }
  24843. }
  24844. var nodeAttributes = {};
  24845. var nodeStyle = node.style || {};
  24846. node.attributes && Object.keys(node.attributes).forEach(function (key) {
  24847. var attr = node.attributes[key];
  24848. ignoredNodeAttributes.indexOf(attr.name) === -1 && (nodeAttributes[attr.name] = attr.value);
  24849. });
  24850. if (node.classList && node.classList.contains('media-wrap')) {
  24851. return {
  24852. type: 'atomic',
  24853. data: {
  24854. nodeAttributes: nodeAttributes,
  24855. float: nodeStyle.float,
  24856. alignment: nodeStyle.textAlign
  24857. }
  24858. };
  24859. } else if (nodeName === 'img') {
  24860. return {
  24861. type: 'atomic',
  24862. data: {
  24863. nodeAttributes: nodeAttributes,
  24864. float: nodeStyle.float,
  24865. alignment: nodeStyle.textAlign
  24866. }
  24867. };
  24868. } else if (nodeName === 'hr') {
  24869. return {
  24870. type: 'atomic',
  24871. data: { nodeAttributes: nodeAttributes }
  24872. };
  24873. } else if (nodeName === 'pre') {
  24874. node.innerHTML = node.innerHTML.replace(/<code(.*?)>/g, '').replace(/<\/code>/g, '');
  24875. return {
  24876. type: 'code-block',
  24877. data: { nodeAttributes: nodeAttributes }
  24878. };
  24879. } else if (blockNames.indexOf(nodeName) !== -1) {
  24880. var blockData = { nodeAttributes: nodeAttributes };
  24881. if (nodeStyle.textAlign) {
  24882. blockData.textAlign = nodeStyle.textAlign;
  24883. }
  24884. if (nodeStyle.textIndent) {
  24885. blockData.textIndent = /^\d+em$/.test(nodeStyle.textIndent) ? Math.ceil(parseInt(nodeStyle.textIndent, 10) / 2) : 1;
  24886. }
  24887. return {
  24888. type: blockTypes[blockNames.indexOf(nodeName)],
  24889. data: blockData
  24890. };
  24891. }
  24892. };
  24893. };
  24894. var getToHTMLConfig = exports.getToHTMLConfig = function getToHTMLConfig(options) {
  24895. return {
  24896. styleToHTML: styleToHTML(options),
  24897. entityToHTML: entityToHTML(options),
  24898. blockToHTML: blockToHTML(options)
  24899. };
  24900. };
  24901. var getFromHTMLConfig = exports.getFromHTMLConfig = function getFromHTMLConfig(options) {
  24902. var source = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'unknow';
  24903. return {
  24904. htmlToStyle: htmlToStyle(options, source),
  24905. htmlToEntity: htmlToEntity(options, source),
  24906. htmlToBlock: htmlToBlock(options, source)
  24907. };
  24908. };
  24909. });
  24910. _commonjsHelpers.unwrapExports(configs);
  24911. var configs_1 = configs.getFromHTMLConfig;
  24912. var configs_2 = configs.getToHTMLConfig;
  24913. var configs_3 = configs.blocks;
  24914. var configs_4 = configs.getHexColor;
  24915. var configs_5 = configs.defaultFontFamilies;
  24916. var configs_6 = configs.namedColors;
  24917. var dist = _commonjsHelpers.createCommonjsModule(function (module, exports) {
  24918. Object.defineProperty(exports, "__esModule", {
  24919. value: true
  24920. });
  24921. exports.convertRawToEditorState = exports.convertEditorStateToRaw = exports.convertHTMLToEditorState = exports.convertEditorStateToHTML = exports.convertHTMLToRaw = exports.convertRawToHTML = undefined;
  24922. var _extends = Object.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; };
  24923. var defaultConvertOptions = {
  24924. fontFamilies: configs.defaultFontFamilies
  24925. };
  24926. var convertRawToHTML = exports.convertRawToHTML = function convertRawToHTML(rawContent, options) {
  24927. options = _extends({}, defaultConvertOptions, options);
  24928. try {
  24929. var contentState = (0, Draft.convertFromRaw)(rawContent);
  24930. options.contentState = contentState;
  24931. return (0, lib.convertToHTML)((0, configs.getToHTMLConfig)(options))(contentState);
  24932. } catch (error) {
  24933. console.warn(error);
  24934. return '';
  24935. }
  24936. };
  24937. var convertHTMLToRaw = exports.convertHTMLToRaw = function convertHTMLToRaw(HTMLString, options, source) {
  24938. options = _extends({}, defaultConvertOptions, options);
  24939. try {
  24940. var contentState = (0, lib.convertFromHTML)((0, configs.getFromHTMLConfig)(options, source))(HTMLString);
  24941. return (0, Draft.convertToRaw)(contentState);
  24942. } catch (error) {
  24943. console.warn(error);
  24944. return {};
  24945. }
  24946. };
  24947. var convertEditorStateToHTML = exports.convertEditorStateToHTML = function convertEditorStateToHTML(editorState, options) {
  24948. options = _extends({}, defaultConvertOptions, options);
  24949. try {
  24950. var contentState = editorState.getCurrentContent();
  24951. options.contentState = contentState;
  24952. return (0, lib.convertToHTML)((0, configs.getToHTMLConfig)(options))(contentState);
  24953. } catch (error) {
  24954. console.warn(error);
  24955. return '';
  24956. }
  24957. };
  24958. var convertHTMLToEditorState = exports.convertHTMLToEditorState = function convertHTMLToEditorState(HTMLString, editorDecorators, options, source) {
  24959. options = _extends({}, defaultConvertOptions, options);
  24960. try {
  24961. return Draft.EditorState.createWithContent((0, lib.convertFromHTML)((0, configs.getFromHTMLConfig)(options, source))(HTMLString), editorDecorators);
  24962. } catch (error) {
  24963. console.warn(error);
  24964. return Draft.EditorState.createEmpty(editorDecorators);
  24965. }
  24966. };
  24967. var convertEditorStateToRaw = exports.convertEditorStateToRaw = function convertEditorStateToRaw(editorState) {
  24968. return (0, Draft.convertToRaw)(editorState.getCurrentContent());
  24969. };
  24970. var convertRawToEditorState = exports.convertRawToEditorState = function convertRawToEditorState(rawContent, editorDecorators) {
  24971. try {
  24972. return Draft.EditorState.createWithContent((0, Draft.convertFromRaw)(rawContent), editorDecorators);
  24973. } catch (error) {
  24974. console.warn(error);
  24975. return Draft.EditorState.createEmpty(editorDecorators);
  24976. }
  24977. };
  24978. });
  24979. _commonjsHelpers.unwrapExports(dist);
  24980. var dist_1 = dist.convertRawToEditorState;
  24981. var dist_2 = dist.convertEditorStateToRaw;
  24982. var dist_3 = dist.convertHTMLToEditorState;
  24983. var dist_4 = dist.convertEditorStateToHTML;
  24984. var dist_5 = dist.convertHTMLToRaw;
  24985. var dist_6 = dist.convertRawToHTML;
  24986. var content = _commonjsHelpers.createCommonjsModule(function (module, exports) {
  24987. Object.defineProperty(exports, "__esModule", {
  24988. value: true
  24989. });
  24990. exports.redo = exports.undo = exports.handleKeyCommand = exports.clear = exports.setMediaPosition = exports.removeMedia = exports.setMediaData = exports.insertMedias = exports.insertHorizontalLine = exports.insertAtomicBlock = exports.insertHTML = exports.insertText = exports.toggleSelectionLetterSpacing = exports.toggleSelectionFontFamily = exports.toggleSelectionLineHeight = exports.toggleSelectionFontSize = exports.toggleSelectionBackgroundColor = exports.toggleSelectionColor = exports.decreaseSelectionIndent = exports.increaseSelectionIndent = exports.toggleSelectionIndent = exports.toggleSelectionAlignment = exports.removeSelectionInlineStyles = exports.toggleSelectionInlineStyle = exports.selectionHasInlineStyle = exports.getSelectionInlineStyle = exports.toggleSelectionLink = exports.toggleSelectionEntity = exports.getSelectionEntityData = exports.getSelectionEntityType = exports.toggleSelectionBlockType = exports.getSelectionText = exports.getSelectionBlockType = exports.getSelectionBlockData = exports.setSelectionBlockData = exports.getSelectedBlocks = exports.updateEachCharacterOfSelection = exports.getSelectionBlock = exports.removeBlock = exports.selectNextBlock = exports.selectBlock = exports.selectionContainsStrictBlock = exports.selectionContainsBlockType = exports.isSelectionCollapsed = exports.createEditorState = exports.createEmptyEditorState = exports.isEditorState = exports.registerStrictBlockType = undefined;
  24991. var _immutable2 = _interopRequireDefault(immutable$1);
  24992. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  24993. var strictBlockTypes = ['atomic'];
  24994. var registerStrictBlockType = exports.registerStrictBlockType = function registerStrictBlockType(blockType) {
  24995. strictBlockTypes.indexOf(blockType) === -1 && strictBlockTypes.push(blockType);
  24996. };
  24997. var isEditorState = exports.isEditorState = function isEditorState(editorState) {
  24998. return editorState instanceof Draft.EditorState;
  24999. };
  25000. var createEmptyEditorState = exports.createEmptyEditorState = function createEmptyEditorState(editorDecorators) {
  25001. return Draft.EditorState.createEmpty(editorDecorators);
  25002. };
  25003. var createEditorState = exports.createEditorState = function createEditorState(contentState, editorDecorators) {
  25004. return Draft.EditorState.createWithContent(contentState, editorDecorators);
  25005. };
  25006. var isSelectionCollapsed = exports.isSelectionCollapsed = function isSelectionCollapsed(editorState) {
  25007. return editorState.getSelection().isCollapsed();
  25008. };
  25009. var selectionContainsBlockType = exports.selectionContainsBlockType = function selectionContainsBlockType(editorState, blockType) {
  25010. return getSelectedBlocks(editorState).find(function (block) {
  25011. return block.getType() === blockType;
  25012. });
  25013. };
  25014. var selectionContainsStrictBlock = exports.selectionContainsStrictBlock = function selectionContainsStrictBlock(editorState) {
  25015. return getSelectedBlocks(editorState).find(function (block) {
  25016. return ~strictBlockTypes.indexOf(block.getType());
  25017. });
  25018. };
  25019. var selectBlock = exports.selectBlock = function selectBlock(editorState, block) {
  25020. var blockKey = block.getKey();
  25021. return Draft.EditorState.forceSelection(editorState, new Draft.SelectionState({
  25022. anchorKey: blockKey,
  25023. anchorOffset: 0,
  25024. focusKey: blockKey,
  25025. focusOffset: block.getLength()
  25026. }));
  25027. };
  25028. var selectNextBlock = exports.selectNextBlock = function selectNextBlock(editorState, block) {
  25029. var nextBlock = editorState.getCurrentContent().getBlockAfter(block.getKey());
  25030. return nextBlock ? selectBlock(editorState, nextBlock) : editorState;
  25031. };
  25032. var removeBlock = exports.removeBlock = function removeBlock(editorState, block) {
  25033. var lastSelection = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  25034. var nextContentState = void 0,
  25035. nextEditorState = void 0;
  25036. var blockKey = block.getKey();
  25037. nextContentState = Draft.Modifier.removeRange(editorState.getCurrentContent(), new Draft.SelectionState({
  25038. anchorKey: blockKey,
  25039. anchorOffset: 0,
  25040. focusKey: blockKey,
  25041. focusOffset: block.getLength()
  25042. }), 'backward');
  25043. nextContentState = Draft.Modifier.setBlockType(nextContentState, nextContentState.getSelectionAfter(), 'unstyled');
  25044. nextEditorState = Draft.EditorState.push(editorState, nextContentState, 'remove-range');
  25045. return Draft.EditorState.forceSelection(nextEditorState, lastSelection || nextContentState.getSelectionAfter());
  25046. };
  25047. var getSelectionBlock = exports.getSelectionBlock = function getSelectionBlock(editorState) {
  25048. return editorState.getCurrentContent().getBlockForKey(editorState.getSelection().getAnchorKey());
  25049. };
  25050. var updateEachCharacterOfSelection = exports.updateEachCharacterOfSelection = function updateEachCharacterOfSelection(editorState, callback) {
  25051. var selectionState = editorState.getSelection();
  25052. var contentState = editorState.getCurrentContent();
  25053. var contentBlocks = contentState.getBlockMap();
  25054. var selectedBlocks = getSelectedBlocks(editorState);
  25055. if (selectedBlocks.length === 0) {
  25056. return editorState;
  25057. }
  25058. var startKey = selectionState.getStartKey();
  25059. var startOffset = selectionState.getStartOffset();
  25060. var endKey = selectionState.getEndKey();
  25061. var endOffset = selectionState.getEndOffset();
  25062. var nextContentBlocks = contentBlocks.map(function (block) {
  25063. if (selectedBlocks.indexOf(block) === -1) {
  25064. return block;
  25065. }
  25066. var blockKey = block.getKey();
  25067. var charactersList = block.getCharacterList();
  25068. var nextCharactersList = null;
  25069. if (blockKey === startKey && blockKey === endKey) {
  25070. nextCharactersList = charactersList.map(function (character, index) {
  25071. if (index >= startOffset && index < endOffset) {
  25072. return callback(character);
  25073. }
  25074. return character;
  25075. });
  25076. } else if (blockKey === startKey) {
  25077. nextCharactersList = charactersList.map(function (character, index) {
  25078. if (index >= startOffset) {
  25079. return callback(character);
  25080. }
  25081. return character;
  25082. });
  25083. } else if (blockKey === endKey) {
  25084. nextCharactersList = charactersList.map(function (character, index) {
  25085. if (index < endOffset) {
  25086. return callback(character);
  25087. }
  25088. return character;
  25089. });
  25090. } else {
  25091. nextCharactersList = charactersList.map(function (character) {
  25092. return callback(character);
  25093. });
  25094. }
  25095. return block.merge({
  25096. 'characterList': nextCharactersList
  25097. });
  25098. });
  25099. return Draft.EditorState.push(editorState, contentState.merge({
  25100. blockMap: nextContentBlocks,
  25101. selectionBefore: selectionState,
  25102. selectionAfter: selectionState
  25103. }), 'update-selection-character-list');
  25104. };
  25105. var getSelectedBlocks = exports.getSelectedBlocks = function getSelectedBlocks(editorState) {
  25106. var selectionState = editorState.getSelection();
  25107. var contentState = editorState.getCurrentContent();
  25108. var startKey = selectionState.getStartKey();
  25109. var endKey = selectionState.getEndKey();
  25110. var isSameBlock = startKey === endKey;
  25111. var startingBlock = contentState.getBlockForKey(startKey);
  25112. var selectedBlocks = [startingBlock];
  25113. if (!isSameBlock) {
  25114. var blockKey = startKey;
  25115. while (blockKey !== endKey) {
  25116. var nextBlock = contentState.getBlockAfter(blockKey);
  25117. selectedBlocks.push(nextBlock);
  25118. blockKey = nextBlock.getKey();
  25119. }
  25120. }
  25121. return selectedBlocks;
  25122. };
  25123. var setSelectionBlockData = exports.setSelectionBlockData = function setSelectionBlockData(editorState, blockData, override) {
  25124. var newBlockData = override ? blockData : Object.assign({}, getSelectionBlockData(editorState).toJS(), blockData);
  25125. Object.keys(newBlockData).forEach(function (key) {
  25126. if (newBlockData.hasOwnProperty(key) && newBlockData[key] === undefined) {
  25127. delete newBlockData[key];
  25128. }
  25129. });
  25130. return (0, draftjsUtils.setBlockData)(editorState, newBlockData);
  25131. };
  25132. var getSelectionBlockData = exports.getSelectionBlockData = function getSelectionBlockData(editorState, name) {
  25133. var blockData = getSelectionBlock(editorState).getData();
  25134. return name ? blockData.get(name) : blockData;
  25135. };
  25136. var getSelectionBlockType = exports.getSelectionBlockType = function getSelectionBlockType(editorState) {
  25137. return getSelectionBlock(editorState).getType();
  25138. };
  25139. var getSelectionText = exports.getSelectionText = function getSelectionText(editorState) {
  25140. var selectionState = editorState.getSelection();
  25141. var contentState = editorState.getCurrentContent();
  25142. if (selectionState.isCollapsed() || getSelectionBlockType(editorState) === 'atomic') {
  25143. return '';
  25144. }
  25145. var anchorKey = selectionState.getAnchorKey();
  25146. var currentContentBlock = contentState.getBlockForKey(anchorKey);
  25147. var start = selectionState.getStartOffset();
  25148. var end = selectionState.getEndOffset();
  25149. return currentContentBlock.getText().slice(start, end);
  25150. };
  25151. var toggleSelectionBlockType = exports.toggleSelectionBlockType = function toggleSelectionBlockType(editorState, blockType) {
  25152. if (selectionContainsStrictBlock(editorState)) {
  25153. return editorState;
  25154. }
  25155. return Draft.RichUtils.toggleBlockType(editorState, blockType);
  25156. };
  25157. var getSelectionEntityType = exports.getSelectionEntityType = function getSelectionEntityType(editorState) {
  25158. var entityKey = (0, draftjsUtils.getSelectionEntity)(editorState);
  25159. if (entityKey) {
  25160. var entity = editorState.getCurrentContent().getEntity(entityKey);
  25161. return entity ? entity.get('type') : null;
  25162. }
  25163. return null;
  25164. };
  25165. var getSelectionEntityData = exports.getSelectionEntityData = function getSelectionEntityData(editorState, type) {
  25166. var entityKey = (0, draftjsUtils.getSelectionEntity)(editorState);
  25167. if (entityKey) {
  25168. var entity = editorState.getCurrentContent().getEntity(entityKey);
  25169. if (entity && entity.get('type') === type) {
  25170. return entity.getData();
  25171. } else {
  25172. return {};
  25173. }
  25174. } else {
  25175. return {};
  25176. }
  25177. };
  25178. var toggleSelectionEntity = exports.toggleSelectionEntity = function toggleSelectionEntity(editorState, entity) {
  25179. var contentState = editorState.getCurrentContent();
  25180. var selectionState = editorState.getSelection();
  25181. if (selectionState.isCollapsed() || getSelectionBlockType(editorState) === 'atomic') {
  25182. return editorState;
  25183. }
  25184. if (!entity || !entity.type || getSelectionEntityType(editorState) === entity.type) {
  25185. return Draft.EditorState.push(editorState, Draft.Modifier.applyEntity(contentState, selectionState, null), 'apply-entity');
  25186. }
  25187. try {
  25188. var nextContentState = contentState.createEntity(entity.type, entity.mutability, entity.data);
  25189. var entityKey = nextContentState.getLastCreatedEntityKey();
  25190. var nextEditorState = Draft.EditorState.set(editorState, {
  25191. currentContent: nextContentState
  25192. });
  25193. return Draft.EditorState.push(nextEditorState, Draft.Modifier.applyEntity(nextContentState, selectionState, entityKey), 'apply-entity');
  25194. } catch (error) {
  25195. console.warn(error);
  25196. return editorState;
  25197. }
  25198. };
  25199. var toggleSelectionLink = exports.toggleSelectionLink = function toggleSelectionLink(editorState, href, target) {
  25200. var contentState = editorState.getCurrentContent();
  25201. var selectionState = editorState.getSelection();
  25202. var entityData = { href: href, target: target };
  25203. if (selectionState.isCollapsed() || getSelectionBlockType(editorState) === 'atomic') {
  25204. return editorState;
  25205. }
  25206. if (href === false) {
  25207. return Draft.RichUtils.toggleLink(editorState, selectionState, null);
  25208. }
  25209. if (href === null) {
  25210. delete entityData.href;
  25211. }
  25212. try {
  25213. var nextContentState = contentState.createEntity('LINK', 'MUTABLE', entityData);
  25214. var entityKey = nextContentState.getLastCreatedEntityKey();
  25215. var nextEditorState = Draft.EditorState.set(editorState, {
  25216. currentContent: nextContentState
  25217. });
  25218. nextEditorState = Draft.RichUtils.toggleLink(nextEditorState, selectionState, entityKey);
  25219. nextEditorState = Draft.EditorState.forceSelection(nextEditorState, selectionState.merge({
  25220. anchorOffset: selectionState.getEndOffset(),
  25221. focusOffset: selectionState.getEndOffset()
  25222. }));
  25223. nextEditorState = Draft.EditorState.push(nextEditorState, Draft.Modifier.insertText(nextEditorState.getCurrentContent(), nextEditorState.getSelection(), ''), 'insert-text');
  25224. return nextEditorState;
  25225. } catch (error) {
  25226. console.warn(error);
  25227. return editorState;
  25228. }
  25229. };
  25230. var getSelectionInlineStyle = exports.getSelectionInlineStyle = function getSelectionInlineStyle(editorState) {
  25231. return editorState.getCurrentInlineStyle();
  25232. };
  25233. var selectionHasInlineStyle = exports.selectionHasInlineStyle = function selectionHasInlineStyle(editorState, style) {
  25234. return getSelectionInlineStyle(editorState).has(style.toUpperCase());
  25235. };
  25236. var toggleSelectionInlineStyle = exports.toggleSelectionInlineStyle = function toggleSelectionInlineStyle(editorState, style) {
  25237. var prefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
  25238. var nextEditorState = editorState;
  25239. style = prefix + style.toUpperCase();
  25240. if (prefix) {
  25241. nextEditorState = updateEachCharacterOfSelection(nextEditorState, function (characterMetadata) {
  25242. return characterMetadata.toJS().style.reduce(function (characterMetadata, characterStyle) {
  25243. if (characterStyle.indexOf(prefix) === 0 && style !== characterStyle) {
  25244. return Draft.CharacterMetadata.removeStyle(characterMetadata, characterStyle);
  25245. } else {
  25246. return characterMetadata;
  25247. }
  25248. }, characterMetadata);
  25249. });
  25250. }
  25251. return Draft.RichUtils.toggleInlineStyle(nextEditorState, style);
  25252. };
  25253. var removeSelectionInlineStyles = exports.removeSelectionInlineStyles = function removeSelectionInlineStyles(editorState) {
  25254. return updateEachCharacterOfSelection(editorState, function (characterMetadata) {
  25255. return characterMetadata.merge({
  25256. style: _immutable2.default.OrderedSet([])
  25257. });
  25258. });
  25259. };
  25260. var toggleSelectionAlignment = exports.toggleSelectionAlignment = function toggleSelectionAlignment(editorState, alignment) {
  25261. return setSelectionBlockData(editorState, {
  25262. textAlign: getSelectionBlockData(editorState, 'textAlign') !== alignment ? alignment : undefined
  25263. });
  25264. };
  25265. var toggleSelectionIndent = exports.toggleSelectionIndent = function toggleSelectionIndent(editorState, textIndent) {
  25266. var maxIndent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 6;
  25267. return textIndent < 0 || textIndent > maxIndent || isNaN(textIndent) ? editorState : setSelectionBlockData(editorState, {
  25268. textIndent: textIndent || undefined
  25269. });
  25270. };
  25271. var increaseSelectionIndent = exports.increaseSelectionIndent = function increaseSelectionIndent(editorState) {
  25272. var maxIndent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 6;
  25273. var currentIndent = getSelectionBlockData(editorState, 'textIndent') || 0;
  25274. return toggleSelectionIndent(editorState, currentIndent + 1, maxIndent);
  25275. };
  25276. var decreaseSelectionIndent = exports.decreaseSelectionIndent = function decreaseSelectionIndent(editorState) {
  25277. var currentIndent = getSelectionBlockData(editorState, 'textIndent') || 0;
  25278. return toggleSelectionIndent(editorState, currentIndent - 1);
  25279. };
  25280. var toggleSelectionColor = exports.toggleSelectionColor = function toggleSelectionColor(editorState, color) {
  25281. return toggleSelectionInlineStyle(editorState, color.replace('#', ''), 'COLOR-');
  25282. };
  25283. var toggleSelectionBackgroundColor = exports.toggleSelectionBackgroundColor = function toggleSelectionBackgroundColor(editorState, color) {
  25284. return toggleSelectionInlineStyle(editorState, color.replace('#', ''), 'BGCOLOR-');
  25285. };
  25286. var toggleSelectionFontSize = exports.toggleSelectionFontSize = function toggleSelectionFontSize(editorState, fontSize) {
  25287. return toggleSelectionInlineStyle(editorState, fontSize, 'FONTSIZE-');
  25288. };
  25289. var toggleSelectionLineHeight = exports.toggleSelectionLineHeight = function toggleSelectionLineHeight(editorState, lineHeight) {
  25290. return toggleSelectionInlineStyle(editorState, lineHeight, 'LINEHEIGHT-');
  25291. };
  25292. var toggleSelectionFontFamily = exports.toggleSelectionFontFamily = function toggleSelectionFontFamily(editorState, fontFamily) {
  25293. return toggleSelectionInlineStyle(editorState, fontFamily, 'FONTFAMILY-');
  25294. };
  25295. var toggleSelectionLetterSpacing = exports.toggleSelectionLetterSpacing = function toggleSelectionLetterSpacing(editorState, letterSpacing) {
  25296. return toggleSelectionInlineStyle(editorState, letterSpacing, 'LETTERSPACING-');
  25297. };
  25298. var insertText = exports.insertText = function insertText(editorState, text, inlineStyle, entity) {
  25299. var selectionState = editorState.getSelection();
  25300. var currentSelectedBlockType = getSelectionBlockType(editorState);
  25301. if (currentSelectedBlockType === 'atomic') {
  25302. return editorState;
  25303. }
  25304. var entityKey = void 0;
  25305. var contentState = editorState.getCurrentContent();
  25306. if (entity && entity.type) {
  25307. contentState = contentState.createEntity(entity.type, entity.mutability || 'MUTABLE', entity.data || entityData);
  25308. entityKey = contentState.getLastCreatedEntityKey();
  25309. }
  25310. if (!selectionState.isCollapsed()) {
  25311. return Draft.EditorState.push(editorState, Draft.Modifier.replaceText(contentState, selectionState, text, inlineStyle, entityKey), 'replace-text');
  25312. } else {
  25313. return Draft.EditorState.push(editorState, Draft.Modifier.insertText(contentState, selectionState, text, inlineStyle, entityKey), 'insert-text');
  25314. }
  25315. };
  25316. var insertHTML = exports.insertHTML = function insertHTML(editorState, htmlString, source) {
  25317. if (!htmlString) {
  25318. return editorState;
  25319. }
  25320. var selectionState = editorState.getSelection();
  25321. var contentState = editorState.getCurrentContent();
  25322. var options = editorState.convertOptions || {};
  25323. try {
  25324. var _convertFromRaw = (0, Draft.convertFromRaw)((0, dist.convertHTMLToRaw)(htmlString, options, source)),
  25325. blockMap = _convertFromRaw.blockMap;
  25326. return Draft.EditorState.push(editorState, Draft.Modifier.replaceWithFragment(contentState, selectionState, blockMap), 'insert-fragment');
  25327. } catch (error) {
  25328. console.warn(error);
  25329. return editorState;
  25330. }
  25331. };
  25332. var insertAtomicBlock = exports.insertAtomicBlock = function insertAtomicBlock(editorState, type) {
  25333. var immutable = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
  25334. var data = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
  25335. if (selectionContainsStrictBlock(editorState)) {
  25336. return insertAtomicBlock(selectNextBlock(editorState, getSelectionBlock(editorState)), type, immutable, data);
  25337. }
  25338. var selectionState = editorState.getSelection();
  25339. var contentState = editorState.getCurrentContent();
  25340. if (!selectionState.isCollapsed() || getSelectionBlockType(editorState) === 'atomic') {
  25341. return editorState;
  25342. }
  25343. var contentStateWithEntity = contentState.createEntity(type, immutable ? 'IMMUTABLE' : 'MUTABLE', data);
  25344. var entityKey = contentStateWithEntity.getLastCreatedEntityKey();
  25345. var newEditorState = Draft.AtomicBlockUtils.insertAtomicBlock(editorState, entityKey, ' ');
  25346. return newEditorState;
  25347. };
  25348. var insertHorizontalLine = exports.insertHorizontalLine = function insertHorizontalLine(editorState) {
  25349. return insertAtomicBlock(editorState, 'HR');
  25350. };
  25351. var insertMedias = exports.insertMedias = function insertMedias(editorState) {
  25352. var medias = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  25353. if (!medias.length) {
  25354. return editorState;
  25355. }
  25356. return medias.reduce(function (editorState, media) {
  25357. var url = media.url,
  25358. link = media.link,
  25359. link_target = media.link_target,
  25360. name = media.name,
  25361. type = media.type,
  25362. width = media.width,
  25363. height = media.height,
  25364. meta = media.meta;
  25365. return insertAtomicBlock(editorState, type, true, { url: url, link: link, link_target: link_target, name: name, type: type, width: width, height: height, meta: meta });
  25366. }, editorState);
  25367. };
  25368. var setMediaData = exports.setMediaData = function setMediaData(editorState, entityKey, data) {
  25369. return Draft.EditorState.push(editorState, editorState.getCurrentContent().mergeEntityData(entityKey, data), 'change-block-data');
  25370. };
  25371. var removeMedia = exports.removeMedia = function removeMedia(editorState, mediaBlock) {
  25372. return removeBlock(editorState, mediaBlock);
  25373. };
  25374. var setMediaPosition = exports.setMediaPosition = function setMediaPosition(editorState, mediaBlock, position) {
  25375. var newPosition = {};
  25376. var float = position.float,
  25377. alignment = position.alignment;
  25378. if (typeof float !== 'undefined') {
  25379. newPosition.float = mediaBlock.getData().get('float') === float ? null : float;
  25380. }
  25381. if (typeof alignment !== 'undefined') {
  25382. newPosition.alignment = mediaBlock.getData().get('alignment') === alignment ? null : alignment;
  25383. }
  25384. return setSelectionBlockData(selectBlock(editorState, mediaBlock), newPosition);
  25385. };
  25386. var clear = exports.clear = function clear(editorState) {
  25387. var contentState = editorState.getCurrentContent();
  25388. var firstBlock = contentState.getFirstBlock();
  25389. var lastBlock = contentState.getLastBlock();
  25390. var allSelected = new Draft.SelectionState({
  25391. anchorKey: firstBlock.getKey(),
  25392. anchorOffset: 0,
  25393. focusKey: lastBlock.getKey(),
  25394. focusOffset: lastBlock.getLength(),
  25395. hasFocus: true
  25396. });
  25397. return Draft.RichUtils.toggleBlockType(Draft.EditorState.push(editorState, Draft.Modifier.removeRange(contentState, allSelected, 'backward'), 'remove-range'), 'unstyled');
  25398. };
  25399. var handleKeyCommand = exports.handleKeyCommand = function handleKeyCommand(editorState, command) {
  25400. return Draft.RichUtils.handleKeyCommand(editorState, command);
  25401. };
  25402. var undo = exports.undo = function undo(editorState) {
  25403. return Draft.EditorState.undo(editorState);
  25404. };
  25405. var redo = exports.redo = function redo(editorState) {
  25406. return Draft.EditorState.redo(editorState);
  25407. };
  25408. });
  25409. _commonjsHelpers.unwrapExports(content);
  25410. var content_1 = content.redo;
  25411. var content_2 = content.undo;
  25412. var content_3 = content.handleKeyCommand;
  25413. var content_4 = content.clear;
  25414. var content_5 = content.setMediaPosition;
  25415. var content_6 = content.removeMedia;
  25416. var content_7 = content.setMediaData;
  25417. var content_8 = content.insertMedias;
  25418. var content_9 = content.insertHorizontalLine;
  25419. var content_10 = content.insertAtomicBlock;
  25420. var content_11 = content.insertHTML;
  25421. var content_12 = content.insertText;
  25422. var content_13 = content.toggleSelectionLetterSpacing;
  25423. var content_14 = content.toggleSelectionFontFamily;
  25424. var content_15 = content.toggleSelectionLineHeight;
  25425. var content_16 = content.toggleSelectionFontSize;
  25426. var content_17 = content.toggleSelectionBackgroundColor;
  25427. var content_18 = content.toggleSelectionColor;
  25428. var content_19 = content.decreaseSelectionIndent;
  25429. var content_20 = content.increaseSelectionIndent;
  25430. var content_21 = content.toggleSelectionIndent;
  25431. var content_22 = content.toggleSelectionAlignment;
  25432. var content_23 = content.removeSelectionInlineStyles;
  25433. var content_24 = content.toggleSelectionInlineStyle;
  25434. var content_25 = content.selectionHasInlineStyle;
  25435. var content_26 = content.getSelectionInlineStyle;
  25436. var content_27 = content.toggleSelectionLink;
  25437. var content_28 = content.toggleSelectionEntity;
  25438. var content_29 = content.getSelectionEntityData;
  25439. var content_30 = content.getSelectionEntityType;
  25440. var content_31 = content.toggleSelectionBlockType;
  25441. var content_32 = content.getSelectionText;
  25442. var content_33 = content.getSelectionBlockType;
  25443. var content_34 = content.getSelectionBlockData;
  25444. var content_35 = content.setSelectionBlockData;
  25445. var content_36 = content.getSelectedBlocks;
  25446. var content_37 = content.updateEachCharacterOfSelection;
  25447. var content_38 = content.getSelectionBlock;
  25448. var content_39 = content.removeBlock;
  25449. var content_40 = content.selectNextBlock;
  25450. var content_41 = content.selectBlock;
  25451. var content_42 = content.selectionContainsStrictBlock;
  25452. var content_43 = content.selectionContainsBlockType;
  25453. var content_44 = content.isSelectionCollapsed;
  25454. var content_45 = content.createEditorState;
  25455. var content_46 = content.createEmptyEditorState;
  25456. var content_47 = content.isEditorState;
  25457. var content_48 = content.registerStrictBlockType;
  25458. var base = _commonjsHelpers.createCommonjsModule(function (module, exports) {
  25459. Object.defineProperty(exports, "__esModule", {
  25460. value: true
  25461. });
  25462. var braftUniqueIndex = 0;
  25463. var UniqueIndex = exports.UniqueIndex = function UniqueIndex() {
  25464. return braftUniqueIndex += 1;
  25465. };
  25466. });
  25467. _commonjsHelpers.unwrapExports(base);
  25468. var base_1 = base.UniqueIndex;
  25469. var color = _commonjsHelpers.createCommonjsModule(function (module, exports) {
  25470. Object.defineProperty(exports, "__esModule", {
  25471. value: true
  25472. });
  25473. var _namedColors = {
  25474. "aliceblue": "#f0f8ff",
  25475. "antiquewhite": "#faebd7",
  25476. "aqua": "#00ffff",
  25477. "aquamarine": "#7fffd4",
  25478. "azure": "#f0ffff",
  25479. "beige": "#f5f5dc",
  25480. "bisque": "#ffe4c4",
  25481. "black": "#000000",
  25482. "blanchedalmond": "#ffebcd",
  25483. "blue": "#0000ff",
  25484. "blueviolet": "#8a2be2",
  25485. "brown": "#a52a2a",
  25486. "burlywood": "#deb887",
  25487. "cadetblue": "#5f9ea0",
  25488. "chartreuse": "#7fff00",
  25489. "chocolate": "#d2691e",
  25490. "coral": "#ff7f50",
  25491. "cornflowerblue": "#6495ed",
  25492. "cornsilk": "#fff8dc",
  25493. "crimson": "#dc143c",
  25494. "cyan": "#00ffff",
  25495. "darkblue": "#00008b",
  25496. "darkcyan": "#008b8b",
  25497. "darkgoldenrod": "#b8860b",
  25498. "darkgray": "#a9a9a9",
  25499. "darkgreen": "#006400",
  25500. "darkkhaki": "#bdb76b",
  25501. "darkmagenta": "#8b008b",
  25502. "darkolivegreen": "#556b2f",
  25503. "darkorange": "#ff8c00",
  25504. "darkorchid": "#9932cc",
  25505. "darkred": "#8b0000",
  25506. "darksalmon": "#e9967a",
  25507. "darkseagreen": "#8fbc8f",
  25508. "darkslateblue": "#483d8b",
  25509. "darkslategray": "#2f4f4f",
  25510. "darkturquoise": "#00ced1",
  25511. "darkviolet": "#9400d3",
  25512. "deeppink": "#ff1493",
  25513. "deepskyblue": "#00bfff",
  25514. "dimgray": "#696969",
  25515. "dodgerblue": "#1e90ff",
  25516. "firebrick": "#b22222",
  25517. "floralwhite": "#fffaf0",
  25518. "forestgreen": "#228b22",
  25519. "fuchsia": "#ff00ff",
  25520. "gainsboro": "#dcdcdc",
  25521. "ghostwhite": "#f8f8ff",
  25522. "gold": "#ffd700",
  25523. "goldenrod": "#daa520",
  25524. "gray": "#808080",
  25525. "green": "#008000",
  25526. "greenyellow": "#adff2f",
  25527. "honeydew": "#f0fff0",
  25528. "hotpink": "#ff69b4",
  25529. "indianred ": "#cd5c5c",
  25530. "indigo": "#4b0082",
  25531. "ivory": "#fffff0",
  25532. "khaki": "#f0e68c",
  25533. "lavender": "#e6e6fa",
  25534. "lavenderblush": "#fff0f5",
  25535. "lawngreen": "#7cfc00",
  25536. "lemonchiffon": "#fffacd",
  25537. "lightblue": "#add8e6",
  25538. "lightcoral": "#f08080",
  25539. "lightcyan": "#e0ffff",
  25540. "lightgoldenrodyellow": "#fafad2",
  25541. "lightgrey": "#d3d3d3",
  25542. "lightgreen": "#90ee90",
  25543. "lightpink": "#ffb6c1",
  25544. "lightsalmon": "#ffa07a",
  25545. "lightseagreen": "#20b2aa",
  25546. "lightskyblue": "#87cefa",
  25547. "lightslategray": "#778899",
  25548. "lightsteelblue": "#b0c4de",
  25549. "lightyellow": "#ffffe0",
  25550. "lime": "#00ff00",
  25551. "limegreen": "#32cd32",
  25552. "linen": "#faf0e6",
  25553. "magenta": "#ff00ff",
  25554. "maroon": "#800000",
  25555. "mediumaquamarine": "#66cdaa",
  25556. "mediumblue": "#0000cd",
  25557. "mediumorchid": "#ba55d3",
  25558. "mediumpurple": "#9370d8",
  25559. "mediumseagreen": "#3cb371",
  25560. "mediumslateblue": "#7b68ee",
  25561. "mediumspringgreen": "#00fa9a",
  25562. "mediumturquoise": "#48d1cc",
  25563. "mediumvioletred": "#c71585",
  25564. "midnightblue": "#191970",
  25565. "mintcream": "#f5fffa",
  25566. "mistyrose": "#ffe4e1",
  25567. "moccasin": "#ffe4b5",
  25568. "navajowhite": "#ffdead",
  25569. "navy": "#000080",
  25570. "oldlace": "#fdf5e6",
  25571. "olive": "#808000",
  25572. "olivedrab": "#6b8e23",
  25573. "orange": "#ffa500",
  25574. "orangered": "#ff4500",
  25575. "orchid": "#da70d6",
  25576. "palegoldenrod": "#eee8aa",
  25577. "palegreen": "#98fb98",
  25578. "paleturquoise": "#afeeee",
  25579. "palevioletred": "#d87093",
  25580. "papayawhip": "#ffefd5",
  25581. "peachpuff": "#ffdab9",
  25582. "peru": "#cd853f",
  25583. "pink": "#ffc0cb",
  25584. "plum": "#dda0dd",
  25585. "powderblue": "#b0e0e6",
  25586. "purple": "#800080",
  25587. "rebeccapurple": "#663399",
  25588. "red": "#ff0000",
  25589. "rosybrown": "#bc8f8f",
  25590. "royalblue": "#4169e1",
  25591. "saddlebrown": "#8b4513",
  25592. "salmon": "#fa8072",
  25593. "sandybrown": "#f4a460",
  25594. "seagreen": "#2e8b57",
  25595. "seashell": "#fff5ee",
  25596. "sienna": "#a0522d",
  25597. "silver": "#c0c0c0",
  25598. "skyblue": "#87ceeb",
  25599. "slateblue": "#6a5acd",
  25600. "slategray": "#708090",
  25601. "snow": "#fffafa",
  25602. "springgreen": "#00ff7f",
  25603. "steelblue": "#4682b4",
  25604. "tan": "#d2b48c",
  25605. "teal": "#008080",
  25606. "thistle": "#d8bfd8",
  25607. "tomato": "#ff6347",
  25608. "turquoise": "#40e0d0",
  25609. "violet": "#ee82ee",
  25610. "wheat": "#f5deb3",
  25611. "white": "#ffffff",
  25612. "whitesmoke": "#f5f5f5",
  25613. "yellow": "#ffff00",
  25614. "yellowgreen": "#9acd32"
  25615. };
  25616. var _getHexColor = function _getHexColor(color) {
  25617. color = color.replace('color:', '').replace(';', '').replace(' ', '');
  25618. if (/^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/.test(color)) {
  25619. return color;
  25620. } else if (namedColors[color]) {
  25621. return namedColors[color];
  25622. } else if (color.indexOf('rgb') === 0) {
  25623. var rgbArray = color.split(',');
  25624. var convertedColor = rgbArray.length < 3 ? null : '#' + [rgbArray[0], rgbArray[1], rgbArray[2]].map(function (x) {
  25625. var hex = parseInt(x.replace(/\D/g, ''), 10).toString(16);
  25626. return hex.length === 1 ? '0' + hex : hex;
  25627. }).join('');
  25628. return (/^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/.test(convertedColor) ? convertedColor : null
  25629. );
  25630. } else {
  25631. return null;
  25632. }
  25633. };
  25634. var namedColors = exports.namedColors = _namedColors;
  25635. var getHexColor = exports.getHexColor = _getHexColor;
  25636. var detectColorsFromHTMLString = exports.detectColorsFromHTMLString = function detectColorsFromHTMLString(html) {
  25637. return typeof html !== 'string' ? [] : (html.match(/color:[^;]{3,24};/g) || []).map(getHexColor).filter(function (color) {
  25638. return color;
  25639. });
  25640. };
  25641. var detectColorsFromDraftState = exports.detectColorsFromDraftState = function detectColorsFromDraftState(draftState) {
  25642. var result = [];
  25643. if (!draftState || !draftState.blocks || !draftState.blocks.length) {
  25644. return result;
  25645. }
  25646. draftState.blocks.forEach(function (block) {
  25647. if (block && block.inlineStyleRanges && block.inlineStyleRanges.length) {
  25648. block.inlineStyleRanges.forEach(function (inlineStyle) {
  25649. if (inlineStyle.style && inlineStyle.style.indexOf('COLOR-') >= 0) {
  25650. result.push('#' + inlineStyle.style.split('COLOR-')[1]);
  25651. }
  25652. });
  25653. }
  25654. });
  25655. return result.filter(function (color) {
  25656. return color;
  25657. });
  25658. };
  25659. });
  25660. _commonjsHelpers.unwrapExports(color);
  25661. var color_1 = color.namedColors;
  25662. var color_2 = color.getHexColor;
  25663. var color_3 = color.detectColorsFromHTMLString;
  25664. var color_4 = color.detectColorsFromDraftState;
  25665. var dist$1 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
  25666. Object.defineProperty(exports, "__esModule", {
  25667. value: true
  25668. });
  25669. exports.ColorUtils = exports.BaseUtils = exports.ContentUtils = undefined;
  25670. var _ContentUtils = _interopRequireWildcard(content);
  25671. var _BaseUtils = _interopRequireWildcard(base);
  25672. var _ColorUtils = _interopRequireWildcard(color);
  25673. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  25674. var ContentUtils = exports.ContentUtils = _ContentUtils;
  25675. var BaseUtils = exports.BaseUtils = _BaseUtils;
  25676. var ColorUtils = exports.ColorUtils = _ColorUtils;
  25677. });
  25678. _commonjsHelpers.unwrapExports(dist$1);
  25679. var dist_1$1 = dist$1.ColorUtils;
  25680. var dist_2$1 = dist$1.BaseUtils;
  25681. var dist_3$1 = dist$1.ContentUtils;
  25682. var dist$2 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
  25683. (function webpackUniversalModuleDefinition(root, factory) {
  25684. module.exports = factory(React__default);
  25685. })(window, function(__WEBPACK_EXTERNAL_MODULE__2__) {
  25686. return /******/ (function(modules) { // webpackBootstrap
  25687. /******/ // The module cache
  25688. /******/ var installedModules = {};
  25689. /******/
  25690. /******/ // The require function
  25691. /******/ function __webpack_require__(moduleId) {
  25692. /******/
  25693. /******/ // Check if module is in cache
  25694. /******/ if(installedModules[moduleId]) {
  25695. /******/ return installedModules[moduleId].exports;
  25696. /******/ }
  25697. /******/ // Create a new module (and put it into the cache)
  25698. /******/ var module = installedModules[moduleId] = {
  25699. /******/ i: moduleId,
  25700. /******/ l: false,
  25701. /******/ exports: {}
  25702. /******/ };
  25703. /******/
  25704. /******/ // Execute the module function
  25705. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  25706. /******/
  25707. /******/ // Flag the module as loaded
  25708. /******/ module.l = true;
  25709. /******/
  25710. /******/ // Return the exports of the module
  25711. /******/ return module.exports;
  25712. /******/ }
  25713. /******/
  25714. /******/
  25715. /******/ // expose the modules object (__webpack_modules__)
  25716. /******/ __webpack_require__.m = modules;
  25717. /******/
  25718. /******/ // expose the module cache
  25719. /******/ __webpack_require__.c = installedModules;
  25720. /******/
  25721. /******/ // define getter function for harmony exports
  25722. /******/ __webpack_require__.d = function(exports, name, getter) {
  25723. /******/ if(!__webpack_require__.o(exports, name)) {
  25724. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  25725. /******/ }
  25726. /******/ };
  25727. /******/
  25728. /******/ // define __esModule on exports
  25729. /******/ __webpack_require__.r = function(exports) {
  25730. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  25731. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  25732. /******/ }
  25733. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  25734. /******/ };
  25735. /******/
  25736. /******/ // create a fake namespace object
  25737. /******/ // mode & 1: value is a module id, require it
  25738. /******/ // mode & 2: merge all properties of value into the ns
  25739. /******/ // mode & 4: return value when already ns object
  25740. /******/ // mode & 8|1: behave like require
  25741. /******/ __webpack_require__.t = function(value, mode) {
  25742. /******/ if(mode & 1) value = __webpack_require__(value);
  25743. /******/ if(mode & 8) return value;
  25744. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  25745. /******/ var ns = Object.create(null);
  25746. /******/ __webpack_require__.r(ns);
  25747. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  25748. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  25749. /******/ return ns;
  25750. /******/ };
  25751. /******/
  25752. /******/ // getDefaultExport function for compatibility with non-harmony modules
  25753. /******/ __webpack_require__.n = function(module) {
  25754. /******/ var getter = module && module.__esModule ?
  25755. /******/ function getDefault() { return module['default']; } :
  25756. /******/ function getModuleExports() { return module; };
  25757. /******/ __webpack_require__.d(getter, 'a', getter);
  25758. /******/ return getter;
  25759. /******/ };
  25760. /******/
  25761. /******/ // Object.prototype.hasOwnProperty.call
  25762. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  25763. /******/
  25764. /******/ // __webpack_public_path__
  25765. /******/ __webpack_require__.p = "/";
  25766. /******/
  25767. /******/
  25768. /******/ // Load entry module and return exports
  25769. /******/ return __webpack_require__(__webpack_require__.s = 20);
  25770. /******/ })
  25771. /************************************************************************/
  25772. /******/ ([
  25773. /* 0 */
  25774. /***/ (function(module, exports, __webpack_require__) {
  25775. Object.defineProperty(exports, "__esModule", {
  25776. value: true
  25777. });
  25778. var compressImage = exports.compressImage = function compressImage(url) {
  25779. var width = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1280;
  25780. var height = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 800;
  25781. return new Promise(function (resolve, reject) {
  25782. var image = new Image();
  25783. image.src = url;
  25784. image.onerror = function (error) {
  25785. reject(error);
  25786. };
  25787. image.onload = function () {
  25788. try {
  25789. var compressCanvas = document.createElement('canvas');
  25790. var scale = this.width > width || this.height > height ? this.width > this.height ? width / this.width : height / this.height : 1;
  25791. compressCanvas.width = this.width * scale;
  25792. compressCanvas.height = this.height * scale;
  25793. var canvasContext = compressCanvas.getContext('2d');
  25794. canvasContext.drawImage(this, 0, 0, compressCanvas.width, compressCanvas.height);
  25795. resolve({
  25796. url: compressCanvas.toDataURL('image/png', 1),
  25797. width: compressCanvas.width,
  25798. height: compressCanvas.height
  25799. });
  25800. } catch (error) {
  25801. reject(error);
  25802. }
  25803. };
  25804. });
  25805. };
  25806. /***/ }),
  25807. /* 1 */
  25808. /***/ (function(module, exports, __webpack_require__) {
  25809. Object.defineProperty(exports, "__esModule", {
  25810. value: true
  25811. });
  25812. var UniqueIndex = exports.UniqueIndex = function UniqueIndex() {
  25813. if (isNaN(window.__BRAFT_MM_UNIQUE_INDEX__)) {
  25814. window.__BRAFT_MM_UNIQUE_INDEX__ = 1;
  25815. } else {
  25816. window.__BRAFT_MM_UNIQUE_INDEX__ += 1;
  25817. }
  25818. return window.__BRAFT_MM_UNIQUE_INDEX__;
  25819. };
  25820. /***/ }),
  25821. /* 2 */
  25822. /***/ (function(module, exports) {
  25823. module.exports = __WEBPACK_EXTERNAL_MODULE__2__;
  25824. /***/ }),
  25825. /* 3 */
  25826. /***/ (function(module, exports, __webpack_require__) {
  25827. Object.defineProperty(exports, "__esModule", {
  25828. value: true
  25829. });
  25830. exports.default = {
  25831. remove: 'Kaldır',
  25832. cancel: 'İptal',
  25833. confirm: 'Onayla',
  25834. insert: 'Seçilenleri ekle',
  25835. width: 'Genişlik',
  25836. height: 'Yükseklik',
  25837. image: 'Resim',
  25838. video: 'Görüntü',
  25839. audio: 'Ses',
  25840. embed: 'Nesne göm',
  25841. caption: 'Kitaplık',
  25842. dragTip: 'Tıkla ya da dosya sürükle',
  25843. dropTip: 'Yüklemek için sürükleyin',
  25844. selectAll: 'Tümünü seç',
  25845. deselect: 'Seçimi kaldır',
  25846. removeSelected: 'Seçilenleri kaldır',
  25847. externalInputPlaceHolder: 'Kaynak adı|Kaynak bağlantısı',
  25848. externalInputTip: 'Kaynak asını ve bağlantısını "|" ile ayırın ve Enter\' a basın.',
  25849. addLocalFile: 'Yerel\' den ekle',
  25850. addExternalSource: 'Harici kaynaktan ekle',
  25851. unnamedItem: 'Adlandırılmamış giriş',
  25852. confirmInsert: 'Seçilenleri ekle'
  25853. };
  25854. /***/ }),
  25855. /* 4 */
  25856. /***/ (function(module, exports, __webpack_require__) {
  25857. Object.defineProperty(exports, "__esModule", {
  25858. value: true
  25859. });
  25860. exports.default = {
  25861. remove: '削除する',
  25862. cancel: 'キャンセル',
  25863. confirm: '確認する',
  25864. insert: '選択したアイテムを挿入',
  25865. width: '幅',
  25866. height: '身長',
  25867. image: '絵',
  25868. video: 'ビデオ',
  25869. audio: '音声',
  25870. embed: '埋め込みメディア',
  25871. caption: 'メディアライブラリー',
  25872. dragTip: 'ファイルをこの位置までクリックまたはドラッグします',
  25873. dropTip: 'アップロードするマウスを放します',
  25874. selectAll: 'すべて選択',
  25875. deselect: '選択を解除',
  25876. removeSelected: '選択したアイテムを削除',
  25877. externalInputPlaceHolder: 'リソース名|リソースアドレス',
  25878. externalInputTip: 'リソース名とリソースアドレスは "|"で区切ります。',
  25879. addLocalFile: 'ローカルリソースを追加する',
  25880. addExternalSource: 'ネットワークリソースを追加する',
  25881. unnamedItem: '名前のないアイテム',
  25882. confirmInsert: '選択したアイテムを挿入'
  25883. };
  25884. /***/ }),
  25885. /* 5 */
  25886. /***/ (function(module, exports, __webpack_require__) {
  25887. Object.defineProperty(exports, "__esModule", {
  25888. value: true
  25889. });
  25890. exports.default = {
  25891. remove: '삭제',
  25892. cancel: '취소',
  25893. confirm: '확인',
  25894. insert: '선택한항목삽입',
  25895. width: '너비',
  25896. height: '높이',
  25897. image: '그림',
  25898. video: '비디오',
  25899. audio: '오디오',
  25900. embed: '임베디드미디어',
  25901. caption: '미디어라이브러리',
  25902. dragTip: '파일을 클릭하거나이 지점으로 드래그하십시오.',
  25903. dropTip: '업로드하려면마우스를놓으십시오.',
  25904. selectAll: '모두 선택',
  25905. deselect: '선택 취소',
  25906. removeSelected: '선택한 항목 삭제',
  25907. externalInputPlaceHolder: '리소스 이름 | 리소스 주소',
  25908. externalInputTip: '자원 이름과 자원 주소를 "|"',
  25909. addLocalFile: '로컬 리소스 추가',
  25910. addExternalSource: '네트워크 리소스 추가',
  25911. unnamedItem: '이름없는 항목',
  25912. confirmInsert: '선택한 항목 삽입'
  25913. };
  25914. /***/ }),
  25915. /* 6 */
  25916. /***/ (function(module, exports, __webpack_require__) {
  25917. Object.defineProperty(exports, "__esModule", {
  25918. value: true
  25919. });
  25920. exports.default = {
  25921. remove: 'Usuń',
  25922. cancel: 'Anuluj',
  25923. confirm: 'Potwierdź',
  25924. insert: 'Wstaw wybrane elementy',
  25925. width: 'Szerokość',
  25926. height: 'Wysokość',
  25927. image: 'Obraz',
  25928. video: 'Wideo',
  25929. audio: 'Dźwięk',
  25930. embed: 'Obiekt',
  25931. caption: 'Biblioteka mediów',
  25932. dragTip: 'Kliknij lub przenieś tu pliki',
  25933. dropTip: 'Upuść aby dodać plik',
  25934. selectAll: 'Zaznacz wszystko',
  25935. deselect: 'Odznacz',
  25936. removeSelected: 'Usuń wybrane',
  25937. externalInputPlaceHolder: 'Nazwa źródła|Adres URL',
  25938. externalInputTip: 'Oddziel nazwę i adres URL źródła z pomocą "|", Potwierdź Enter-em',
  25939. addLocalFile: 'Dodaj z komputera',
  25940. addExternalSource: 'Dodaj z Internetu',
  25941. unnamedItem: 'Bez nazwy',
  25942. confirmInsert: 'Dodaj wybrane elementy'
  25943. };
  25944. /***/ }),
  25945. /* 7 */
  25946. /***/ (function(module, exports, __webpack_require__) {
  25947. Object.defineProperty(exports, "__esModule", {
  25948. value: true
  25949. });
  25950. exports.default = {
  25951. remove: '删除',
  25952. cancel: '取消',
  25953. confirm: '确认',
  25954. insert: '插入所选项目',
  25955. width: '宽度',
  25956. height: '高度',
  25957. image: '图片',
  25958. video: '视频',
  25959. audio: '音频',
  25960. embed: '嵌入式媒体',
  25961. caption: '媒体库',
  25962. dragTip: '点击或拖动文件至此',
  25963. dropTip: '放开鼠标以上传',
  25964. selectAll: '选择全部',
  25965. deselect: '取消选择',
  25966. removeSelected: '删除选中项目',
  25967. externalInputPlaceHolder: '资源名称|资源地址',
  25968. externalInputTip: '使用“|”分隔资源名称和资源地址',
  25969. addLocalFile: '添加本地资源',
  25970. addExternalSource: '添加网络资源',
  25971. unnamedItem: '未命名项目',
  25972. confirmInsert: '插入选中项目'
  25973. };
  25974. /***/ }),
  25975. /* 8 */
  25976. /***/ (function(module, exports, __webpack_require__) {
  25977. Object.defineProperty(exports, "__esModule", {
  25978. value: true
  25979. });
  25980. exports.default = {
  25981. remove: '删除',
  25982. cancel: '取消',
  25983. confirm: '确认',
  25984. insert: '插入所选项目',
  25985. width: '宽度',
  25986. height: '高度',
  25987. image: '图片',
  25988. video: '视频',
  25989. audio: '音频',
  25990. embed: '嵌入式媒体',
  25991. caption: '媒体库',
  25992. dragTip: '点击或拖动文件至此',
  25993. dropTip: '放开鼠标以上传',
  25994. selectAll: '选择全部',
  25995. deselect: '取消选择',
  25996. removeSelected: '删除选中项目',
  25997. externalInputPlaceHolder: '资源名称|资源地址',
  25998. externalInputTip: '使用“|”分隔资源名称和资源地址',
  25999. addLocalFile: '添加本地资源',
  26000. addExternalSource: '添加网络资源',
  26001. unnamedItem: '未命名项目',
  26002. confirmInsert: '插入选中项目'
  26003. };
  26004. /***/ }),
  26005. /* 9 */
  26006. /***/ (function(module, exports, __webpack_require__) {
  26007. Object.defineProperty(exports, "__esModule", {
  26008. value: true
  26009. });
  26010. exports.default = {
  26011. remove: 'Remove',
  26012. cancel: 'Cancel',
  26013. confirm: 'Confirm',
  26014. insert: 'Insert Selected Items',
  26015. width: 'Width',
  26016. height: 'Height',
  26017. image: 'Image',
  26018. video: 'Video',
  26019. audio: 'Audio',
  26020. embed: 'Embed',
  26021. caption: 'Media Library',
  26022. dragTip: 'Click Or Drag Files Here',
  26023. dropTip: 'Drop To Upload',
  26024. selectAll: 'Select All',
  26025. deselect: 'Deselect',
  26026. removeSelected: 'Remove Selected Items',
  26027. externalInputPlaceHolder: 'Source Name|Source URL',
  26028. externalInputTip: 'Split source name and source URL with "|", confirm by hit Enter.',
  26029. addLocalFile: 'Add from local',
  26030. addExternalSource: 'Add from Internet',
  26031. unnamedItem: 'Unnamed Item',
  26032. confirmInsert: 'Insert selected items'
  26033. };
  26034. /***/ }),
  26035. /* 10 */
  26036. /***/ (function(module, exports, __webpack_require__) {
  26037. Object.defineProperty(exports, "__esModule", {
  26038. value: true
  26039. });
  26040. var _en = __webpack_require__(9);
  26041. var _en2 = _interopRequireDefault(_en);
  26042. var _zh = __webpack_require__(8);
  26043. var _zh2 = _interopRequireDefault(_zh);
  26044. var _zhHant = __webpack_require__(7);
  26045. var _zhHant2 = _interopRequireDefault(_zhHant);
  26046. var _pl = __webpack_require__(6);
  26047. var _pl2 = _interopRequireDefault(_pl);
  26048. var _kr = __webpack_require__(5);
  26049. var _kr2 = _interopRequireDefault(_kr);
  26050. var _jpn = __webpack_require__(4);
  26051. var _jpn2 = _interopRequireDefault(_jpn);
  26052. var _tr = __webpack_require__(3);
  26053. var _tr2 = _interopRequireDefault(_tr);
  26054. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  26055. exports.default = {
  26056. "en": _en2.default,
  26057. "zh": _zh2.default,
  26058. "zh-hant": _zhHant2.default,
  26059. "pl": _pl2.default,
  26060. "kr": _kr2.default,
  26061. "jpn": _jpn2.default,
  26062. "tr": _tr2.default
  26063. };
  26064. /***/ }),
  26065. /* 11 */
  26066. /***/ (function(module, exports) {
  26067. /**
  26068. * When source maps are enabled, `style-loader` uses a link element with a data-uri to
  26069. * embed the css on the page. This breaks all relative urls because now they are relative to a
  26070. * bundle instead of the current page.
  26071. *
  26072. * One solution is to only use full urls, but that may be impossible.
  26073. *
  26074. * Instead, this function "fixes" the relative urls to be absolute according to the current page location.
  26075. *
  26076. * A rudimentary test suite is located at `test/fixUrls.js` and can be run via the `npm test` command.
  26077. *
  26078. */
  26079. module.exports = function (css) {
  26080. // get current location
  26081. var location = typeof window !== "undefined" && window.location;
  26082. if (!location) {
  26083. throw new Error("fixUrls requires window.location");
  26084. }
  26085. // blank or null?
  26086. if (!css || typeof css !== "string") {
  26087. return css;
  26088. }
  26089. var baseUrl = location.protocol + "//" + location.host;
  26090. var currentDir = baseUrl + location.pathname.replace(/\/[^\/]*$/, "/");
  26091. // convert each url(...)
  26092. /*
  26093. This regular expression is just a way to recursively match brackets within
  26094. a string.
  26095. /url\s*\( = Match on the word "url" with any whitespace after it and then a parens
  26096. ( = Start a capturing group
  26097. (?: = Start a non-capturing group
  26098. [^)(] = Match anything that isn't a parentheses
  26099. | = OR
  26100. \( = Match a start parentheses
  26101. (?: = Start another non-capturing groups
  26102. [^)(]+ = Match anything that isn't a parentheses
  26103. | = OR
  26104. \( = Match a start parentheses
  26105. [^)(]* = Match anything that isn't a parentheses
  26106. \) = Match a end parentheses
  26107. ) = End Group
  26108. *\) = Match anything and then a close parens
  26109. ) = Close non-capturing group
  26110. * = Match anything
  26111. ) = Close capturing group
  26112. \) = Match a close parens
  26113. /gi = Get all matches, not the first. Be case insensitive.
  26114. */
  26115. var fixedCss = css.replace(/url\s*\(((?:[^)(]|\((?:[^)(]+|\([^)(]*\))*\))*)\)/gi, function(fullMatch, origUrl) {
  26116. // strip quotes (if they exist)
  26117. var unquotedOrigUrl = origUrl
  26118. .trim()
  26119. .replace(/^"(.*)"$/, function(o, $1){ return $1; })
  26120. .replace(/^'(.*)'$/, function(o, $1){ return $1; });
  26121. // already a full url? no change
  26122. if (/^(#|data:|http:\/\/|https:\/\/|file:\/\/\/|\s*$)/i.test(unquotedOrigUrl)) {
  26123. return fullMatch;
  26124. }
  26125. // convert the url to a full url
  26126. var newUrl;
  26127. if (unquotedOrigUrl.indexOf("//") === 0) {
  26128. //TODO: should we add protocol?
  26129. newUrl = unquotedOrigUrl;
  26130. } else if (unquotedOrigUrl.indexOf("/") === 0) {
  26131. // path should be relative to the base url
  26132. newUrl = baseUrl + unquotedOrigUrl; // already starts with '/'
  26133. } else {
  26134. // path should be relative to current directory
  26135. newUrl = currentDir + unquotedOrigUrl.replace(/^\.\//, ""); // Strip leading './'
  26136. }
  26137. // send back the fixed url(...)
  26138. return "url(" + JSON.stringify(newUrl) + ")";
  26139. });
  26140. // send back the fixed css
  26141. return fixedCss;
  26142. };
  26143. /***/ }),
  26144. /* 12 */
  26145. /***/ (function(module, exports, __webpack_require__) {
  26146. /*
  26147. MIT License http://www.opensource.org/licenses/mit-license.php
  26148. Author Tobias Koppers @sokra
  26149. */
  26150. var stylesInDom = {};
  26151. var memoize = function (fn) {
  26152. var memo;
  26153. return function () {
  26154. if (typeof memo === "undefined") memo = fn.apply(this, arguments);
  26155. return memo;
  26156. };
  26157. };
  26158. var isOldIE = memoize(function () {
  26159. // Test for IE <= 9 as proposed by Browserhacks
  26160. // @see http://browserhacks.com/#hack-e71d8692f65334173fee715c222cb805
  26161. // Tests for existence of standard globals is to allow style-loader
  26162. // to operate correctly into non-standard environments
  26163. // @see https://github.com/webpack-contrib/style-loader/issues/177
  26164. return window && document && document.all && !window.atob;
  26165. });
  26166. var getTarget = function (target) {
  26167. return document.querySelector(target);
  26168. };
  26169. var getElement = (function (fn) {
  26170. var memo = {};
  26171. return function(target) {
  26172. // If passing function in options, then use it for resolve "head" element.
  26173. // Useful for Shadow Root style i.e
  26174. // {
  26175. // insertInto: function () { return document.querySelector("#foo").shadowRoot }
  26176. // }
  26177. if (typeof target === 'function') {
  26178. return target();
  26179. }
  26180. if (typeof memo[target] === "undefined") {
  26181. var styleTarget = getTarget.call(this, target);
  26182. // Special case to return head of iframe instead of iframe itself
  26183. if (window.HTMLIFrameElement && styleTarget instanceof window.HTMLIFrameElement) {
  26184. try {
  26185. // This will throw an exception if access to iframe is blocked
  26186. // due to cross-origin restrictions
  26187. styleTarget = styleTarget.contentDocument.head;
  26188. } catch(e) {
  26189. styleTarget = null;
  26190. }
  26191. }
  26192. memo[target] = styleTarget;
  26193. }
  26194. return memo[target]
  26195. };
  26196. })();
  26197. var singleton = null;
  26198. var singletonCounter = 0;
  26199. var stylesInsertedAtTop = [];
  26200. var fixUrls = __webpack_require__(11);
  26201. module.exports = function(list, options) {
  26202. if (typeof DEBUG !== "undefined" && DEBUG) {
  26203. if (typeof document !== "object") throw new Error("The style-loader cannot be used in a non-browser environment");
  26204. }
  26205. options = options || {};
  26206. options.attrs = typeof options.attrs === "object" ? options.attrs : {};
  26207. // Force single-tag solution on IE6-9, which has a hard limit on the # of <style>
  26208. // tags it will allow on a page
  26209. if (!options.singleton && typeof options.singleton !== "boolean") options.singleton = isOldIE();
  26210. // By default, add <style> tags to the <head> element
  26211. if (!options.insertInto) options.insertInto = "head";
  26212. // By default, add <style> tags to the bottom of the target
  26213. if (!options.insertAt) options.insertAt = "bottom";
  26214. var styles = listToStyles(list, options);
  26215. addStylesToDom(styles, options);
  26216. return function update (newList) {
  26217. var mayRemove = [];
  26218. for (var i = 0; i < styles.length; i++) {
  26219. var item = styles[i];
  26220. var domStyle = stylesInDom[item.id];
  26221. domStyle.refs--;
  26222. mayRemove.push(domStyle);
  26223. }
  26224. if(newList) {
  26225. var newStyles = listToStyles(newList, options);
  26226. addStylesToDom(newStyles, options);
  26227. }
  26228. for (var i = 0; i < mayRemove.length; i++) {
  26229. var domStyle = mayRemove[i];
  26230. if(domStyle.refs === 0) {
  26231. for (var j = 0; j < domStyle.parts.length; j++) domStyle.parts[j]();
  26232. delete stylesInDom[domStyle.id];
  26233. }
  26234. }
  26235. };
  26236. };
  26237. function addStylesToDom (styles, options) {
  26238. for (var i = 0; i < styles.length; i++) {
  26239. var item = styles[i];
  26240. var domStyle = stylesInDom[item.id];
  26241. if(domStyle) {
  26242. domStyle.refs++;
  26243. for(var j = 0; j < domStyle.parts.length; j++) {
  26244. domStyle.parts[j](item.parts[j]);
  26245. }
  26246. for(; j < item.parts.length; j++) {
  26247. domStyle.parts.push(addStyle(item.parts[j], options));
  26248. }
  26249. } else {
  26250. var parts = [];
  26251. for(var j = 0; j < item.parts.length; j++) {
  26252. parts.push(addStyle(item.parts[j], options));
  26253. }
  26254. stylesInDom[item.id] = {id: item.id, refs: 1, parts: parts};
  26255. }
  26256. }
  26257. }
  26258. function listToStyles (list, options) {
  26259. var styles = [];
  26260. var newStyles = {};
  26261. for (var i = 0; i < list.length; i++) {
  26262. var item = list[i];
  26263. var id = options.base ? item[0] + options.base : item[0];
  26264. var css = item[1];
  26265. var media = item[2];
  26266. var sourceMap = item[3];
  26267. var part = {css: css, media: media, sourceMap: sourceMap};
  26268. if(!newStyles[id]) styles.push(newStyles[id] = {id: id, parts: [part]});
  26269. else newStyles[id].parts.push(part);
  26270. }
  26271. return styles;
  26272. }
  26273. function insertStyleElement (options, style) {
  26274. var target = getElement(options.insertInto);
  26275. if (!target) {
  26276. throw new Error("Couldn't find a style target. This probably means that the value for the 'insertInto' parameter is invalid.");
  26277. }
  26278. var lastStyleElementInsertedAtTop = stylesInsertedAtTop[stylesInsertedAtTop.length - 1];
  26279. if (options.insertAt === "top") {
  26280. if (!lastStyleElementInsertedAtTop) {
  26281. target.insertBefore(style, target.firstChild);
  26282. } else if (lastStyleElementInsertedAtTop.nextSibling) {
  26283. target.insertBefore(style, lastStyleElementInsertedAtTop.nextSibling);
  26284. } else {
  26285. target.appendChild(style);
  26286. }
  26287. stylesInsertedAtTop.push(style);
  26288. } else if (options.insertAt === "bottom") {
  26289. target.appendChild(style);
  26290. } else if (typeof options.insertAt === "object" && options.insertAt.before) {
  26291. var nextSibling = getElement(options.insertInto + " " + options.insertAt.before);
  26292. target.insertBefore(style, nextSibling);
  26293. } else {
  26294. throw new Error("[Style Loader]\n\n Invalid value for parameter 'insertAt' ('options.insertAt') found.\n Must be 'top', 'bottom', or Object.\n (https://github.com/webpack-contrib/style-loader#insertat)\n");
  26295. }
  26296. }
  26297. function removeStyleElement (style) {
  26298. if (style.parentNode === null) return false;
  26299. style.parentNode.removeChild(style);
  26300. var idx = stylesInsertedAtTop.indexOf(style);
  26301. if(idx >= 0) {
  26302. stylesInsertedAtTop.splice(idx, 1);
  26303. }
  26304. }
  26305. function createStyleElement (options) {
  26306. var style = document.createElement("style");
  26307. if(options.attrs.type === undefined) {
  26308. options.attrs.type = "text/css";
  26309. }
  26310. addAttrs(style, options.attrs);
  26311. insertStyleElement(options, style);
  26312. return style;
  26313. }
  26314. function createLinkElement (options) {
  26315. var link = document.createElement("link");
  26316. if(options.attrs.type === undefined) {
  26317. options.attrs.type = "text/css";
  26318. }
  26319. options.attrs.rel = "stylesheet";
  26320. addAttrs(link, options.attrs);
  26321. insertStyleElement(options, link);
  26322. return link;
  26323. }
  26324. function addAttrs (el, attrs) {
  26325. Object.keys(attrs).forEach(function (key) {
  26326. el.setAttribute(key, attrs[key]);
  26327. });
  26328. }
  26329. function addStyle (obj, options) {
  26330. var style, update, remove, result;
  26331. // If a transform function was defined, run it on the css
  26332. if (options.transform && obj.css) {
  26333. result = options.transform(obj.css);
  26334. if (result) {
  26335. // If transform returns a value, use that instead of the original css.
  26336. // This allows running runtime transformations on the css.
  26337. obj.css = result;
  26338. } else {
  26339. // If the transform function returns a falsy value, don't add this css.
  26340. // This allows conditional loading of css
  26341. return function() {
  26342. // noop
  26343. };
  26344. }
  26345. }
  26346. if (options.singleton) {
  26347. var styleIndex = singletonCounter++;
  26348. style = singleton || (singleton = createStyleElement(options));
  26349. update = applyToSingletonTag.bind(null, style, styleIndex, false);
  26350. remove = applyToSingletonTag.bind(null, style, styleIndex, true);
  26351. } else if (
  26352. obj.sourceMap &&
  26353. typeof URL === "function" &&
  26354. typeof URL.createObjectURL === "function" &&
  26355. typeof URL.revokeObjectURL === "function" &&
  26356. typeof Blob === "function" &&
  26357. typeof btoa === "function"
  26358. ) {
  26359. style = createLinkElement(options);
  26360. update = updateLink.bind(null, style, options);
  26361. remove = function () {
  26362. removeStyleElement(style);
  26363. if(style.href) URL.revokeObjectURL(style.href);
  26364. };
  26365. } else {
  26366. style = createStyleElement(options);
  26367. update = applyToTag.bind(null, style);
  26368. remove = function () {
  26369. removeStyleElement(style);
  26370. };
  26371. }
  26372. update(obj);
  26373. return function updateStyle (newObj) {
  26374. if (newObj) {
  26375. if (
  26376. newObj.css === obj.css &&
  26377. newObj.media === obj.media &&
  26378. newObj.sourceMap === obj.sourceMap
  26379. ) {
  26380. return;
  26381. }
  26382. update(obj = newObj);
  26383. } else {
  26384. remove();
  26385. }
  26386. };
  26387. }
  26388. var replaceText = (function () {
  26389. var textStore = [];
  26390. return function (index, replacement) {
  26391. textStore[index] = replacement;
  26392. return textStore.filter(Boolean).join('\n');
  26393. };
  26394. })();
  26395. function applyToSingletonTag (style, index, remove, obj) {
  26396. var css = remove ? "" : obj.css;
  26397. if (style.styleSheet) {
  26398. style.styleSheet.cssText = replaceText(index, css);
  26399. } else {
  26400. var cssNode = document.createTextNode(css);
  26401. var childNodes = style.childNodes;
  26402. if (childNodes[index]) style.removeChild(childNodes[index]);
  26403. if (childNodes.length) {
  26404. style.insertBefore(cssNode, childNodes[index]);
  26405. } else {
  26406. style.appendChild(cssNode);
  26407. }
  26408. }
  26409. }
  26410. function applyToTag (style, obj) {
  26411. var css = obj.css;
  26412. var media = obj.media;
  26413. if(media) {
  26414. style.setAttribute("media", media);
  26415. }
  26416. if(style.styleSheet) {
  26417. style.styleSheet.cssText = css;
  26418. } else {
  26419. while(style.firstChild) {
  26420. style.removeChild(style.firstChild);
  26421. }
  26422. style.appendChild(document.createTextNode(css));
  26423. }
  26424. }
  26425. function updateLink (link, options, obj) {
  26426. var css = obj.css;
  26427. var sourceMap = obj.sourceMap;
  26428. /*
  26429. If convertToAbsoluteUrls isn't defined, but sourcemaps are enabled
  26430. and there is no publicPath defined then lets turn convertToAbsoluteUrls
  26431. on by default. Otherwise default to the convertToAbsoluteUrls option
  26432. directly
  26433. */
  26434. var autoFixUrls = options.convertToAbsoluteUrls === undefined && sourceMap;
  26435. if (options.convertToAbsoluteUrls || autoFixUrls) {
  26436. css = fixUrls(css);
  26437. }
  26438. if (sourceMap) {
  26439. // http://stackoverflow.com/a/26603875
  26440. css += "\n/*# sourceMappingURL=data:application/json;base64," + btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap)))) + " */";
  26441. }
  26442. var blob = new Blob([css], { type: "text/css" });
  26443. var oldSrc = link.href;
  26444. link.href = URL.createObjectURL(blob);
  26445. if(oldSrc) URL.revokeObjectURL(oldSrc);
  26446. }
  26447. /***/ }),
  26448. /* 13 */
  26449. /***/ (function(module, exports) {
  26450. module.exports = "data:font/ttf;base64,AAEAAAALAIAAAwAwT1MvMg8SBsIAAAC8AAAAYGNtYXBWNv1DAAABHAAAANRnYXNwAAAAEAAAAfAAAAAIZ2x5ZtZLKCQAAAH4AAAPTGhlYWQT25ZrAAARRAAAADZoaGVhB8ID3gAAEXwAAAAkaG10eGoAC+sAABGgAAAAdGxvY2EqcC3wAAASFAAAADxtYXhwACcAewAAElAAAAAgbmFtZZlKCfsAABJwAAABhnBvc3QAAwAAAAAT+AAAACAAAwPsAZAABQAAApkCzAAAAI8CmQLMAAAB6wAzAQkAAAAAAAAAAAAAAAAAAAABEAAAAAAAAAAAAAAAAAAAAABAAADprAPA/8AAQAPAAEAAAAABAAAAAAAAAAAAAAAgAAAAAAADAAAAAwAAABwAAQADAAAAHAADAAEAAAAcAAQAuAAAACoAIAAEAAoAAQAg4DTgN+BC4V3iQ+gN6Mno/ukD6QjpD+kT6RjpHOkm6YDprP/9//8AAAAAACDgNOA34ELhXeJD6A3oyej+6QHpB+kO6RHpFukc6SbpgOms//3//wAB/+Mf0B/OH8Qeqh3FF/wXQRcNFwsXCBcDFwIXABb9FvQWmxZwAAMAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAH//wAPAAEAAAAAAAAAAAACAAA3OQEAAAAAAQAAAAAAAAAAAAIAADc5AQAAAAABAAAAAAAAAAAAAgAANzkBAAAAAAIBAACBAwAC1QADAAcAAAEzESMhETMRAlaqqv6qqgLV/awCVP2sAAABAVYAgQMqAtUAAgAACQIBVgHU/iwC1f7W/tYAAQCqACsDVgOBAC4AAAEyFx4BFxYVFAcOAQcGIyInLgEnJjUzFBceARcWMzI3PgE3NjU0Jy4BJyYjFSc3AgBGPz5dGxsbG10+PkdGPz5dGxtWFBRFLy81NS8vRRQUFBRFLy811tYC1RsbXD4+Rkc+Pl0bGxsbXT4+RzYuL0UUFBQURS8uNjUvLkYUFKzW1gAAAwBWAAEDqgNVABsANwA7AAAlMjc+ATc2NTQnLgEnJiMiBw4BBwYVFBceARcWEzIXHgEXFhUUBw4BBwYjIicuAScmNTQ3PgE3NgMhFSECAEY/Pl0bGxsbXT4+R0Y/Pl0bGxsbXT4+R1hOTnMiISEic05NWVhOTnMiISEic05NfQGs/lRVGxtdPj5HRj4/XRsbGxtdPz5GRz4+XRsbAwAiIXRNTlhZTU50ISEhIXROTVlYTk10ISL+gFQAAAABAKoAAQOAA1UAHwAAATMRIREUBisBIiY1ESE1IxUUBiMhIiY9ATQ2MyEyFhUDAID+qhgSVhIYAaoqGBL+ABIaGhICABIYAwH+qv6AEhgYEgHWqioSGhoSqhIYGBIAAAABAIAAAwOAA1UAMwAAJTIWFRQGIyImNTwBNyUOASMiJjU0NjMyFhclLgE1NDYzMhYVFAYjIiYnBR4BFRQGBwU+AQMAM0lJMzNJAv7SEiwaNExLNRktEgEsAQNLNTRMSzUZLRL+1AEDAgIBMBAs/UkzM0tLMwcPBrAREUs1NEwSEK4HDwg0TEw0NUsTEbAIDwcIDwewDxEAAAMAVgArA6oDVQACAAYAGgAALQI3FTM1FyERFAYjISImNREhNTQ2OwEyFhUBgAFA/sAqrFQBADAk/VQkMAEAMCSsJDCr1qrWVlZW/dYkMjIkAipWJDAwJAAEAIAAgQOAAtUAAwAHAAsADwAAEyEVIRU1IRUBNSEVJTUhFYADAP0AAwD9AAMA/QADAALVVKxWVv6sVFSqVlYABABVACIDqwN3AAQAIQA9AEIAACUzESMREyIHDgEHBhUUFx4BFxYzMjc+ATc2NTQnLgEnJiMRIicuAScmNTQ3PgE3NjMyFx4BFxYVFAcOAQcGAzM1IxUB1VZWK1hOTnQhIiIhdE5OWFhOTnQhIiIhdE5OWEc+Pl0aGxsaXT4+R0c+Pl0aGxsaXT4+clZW9wEA/wACgCEic05OWFlNTnQhIiIhdE5NWVhOTnMiIf0AGxtdPj5HRj8+XBsbGxtcPj9GRz4+XRsbAdZVVQAABABVACIDqwN3AAQAIQA9AFIAACUzNSMVEyIHDgEHBhUUFx4BFxYzMjc+ATc2NTQnLgEnJiMRIicuAScmNTQ3PgE3NjMyFx4BFxYVFAcOAQcGAyIGFTM0NjMyFhUUBhUzNDY1NCYjAdVWVitYTk50ISIiIXROTlhYTk50ISIiIXROTlhHPj5dGhsbGl0+PkdHPj5dGhsbGl0+PkdHZFYyIyMygFaAZEfNVVUCqiEic05OWFlNTnQhIiIhdE5NWVhOTnMiIf0AGxtdPj5HRj8+XBsbGxtcPj9GRz4+XRsbAlZkRyMyMiNALWhIPVBHZAAAAgBVAM0DqwLNAAUACwAAASc3JwkBJTcnNwkBAZHExDz/AAEAARrExDwBAP8AAQnExDz/AP8APMTEPP8A/wAAAAMAVQAiA6sDdwAcACsAOgAAASIHDgEHBhUUFx4BFxYzMjc+ATc2NTQnLgEnJiMBNDc+ATc2MzIWFwEuATUBIiYnAR4BFRQHDgEHBiMCAFhOTXQiIiIidE1OWFhOTXQiIiIidE1OWP6rGxtcPj9GOmot/iIjJQFVOmotAd4jJRsbXD4/RgN3ISJ0Tk1YWE5OdCEiIiF0Tk5YWE1OdCIh/lZGPj5dGxslI/4iLWo6/qomIwHeLWs5Rz4+XRsbAAAAAAMAgADNA4ACzQADAAcACwAANyE1ITUhNSE1FSE1gAMA/QADAP0AAwDNVYBV1lZWAAEAZAAlA1wDXABEAAABERQHBgcGBwYjIicmJyYnJjU0NzY3Njc2MzIXEQURFAcGBwYHBiMiJyYnJicmNTQ3Njc2NzYzMhcRNDc2NyU2MzIXFhUDXBERGhkaGRYXGRoZGhEREREaGRoZFzMr/oURERoZGhkXFhkaGRoRERERGhkaGRY0KwoJDwGbBggUDg4DLP3WGBQTCgsFBQUFCwoTFBgZExQKCwUFEwEKdv6iGRMTCwsFBQUFCwsTExkZExMLCgYFEwHeDw0MBX8CDg4UAAAEAHUAQgOJA1YALwA8AGIAeAAAAS4BBw4BJy4BJy4BBwYiJyYGBw4BJyYGBxQVHAEVFBUeATM2MzoBMzIzMjY3PAE1BSImNTQ2MzIWFRQGJyUqASM8ATU6ATMUFhUUFxwBFQYHFAYHDgEnLgE3PgE3OgEzPAE1BT4BNzoBMxQWBw4BJy4BNz4BNzoBMwKBARkZChUJCxcEFEMvBw8HHikMDCgdFyILCxgWNDM0ZzQzNBsaAf77L0FBMDBAQDEBtx8/IDRoNgEBAQENCxVFICIlBgc3JAcNCf7OAQICEyQTAwUFSiMmOAIBOiYHEAkCzhcaAQEBAwIJCC0fCAEBBhgbGxYGBBMVKCgpUCgoKQ8VARcaSpRK7T8uMEA/LzBAARchPyAKEgkzMjNmMjMzFCwRIBAOD0IjJjQDN2053QwUCi5dLSUsBgVEJig+BAAAAAAEAAAAAAQAA0AAGwAzAE8AUwAAARQXHgEXFjMyNz4BNzY1NCcuAScmIyIHDgEHBgEjLgEjISIGByMiBhURFBYzITI2NRE0JgEiJy4BJyY1NDc+ATc2MzIXHgEXFhUUBw4BBwYBIzUzATAQETgmJisrJiY4ERAQETgmJisrJiY4ERACkOAMJDD/ADAkDOAaJiYaA4AaJib+Jjs0M00XFhYXTTM0Ozs0M00XFhYXTTM0AYWAgAFgKyYmOBEQEBE4JiYrKyYmOBEQEBE4JiYBNTBQUDAmGv3AGiYmGgJAGib9hBYXTTM0Ozs0M00XFhYXTTM0Ozs0M00XFgG8QAABAJEAogOAAt4ABgAAAScHFwEnAQGAszzvAgA8/jwBGrM87wIAPP48AAAAAAEA4gCAAx4CyQAmAAABNzY0JyYiDwEnJiIHBhQfAQcGFBceATMyNj8BFx4BMzI2NzY0LwECPOINDQwkDOLiDCQMDQ3i4g0NBhAICBAG4uIGEAgIEAYNDeIBq+IMIw0MDOLiDAwNIwzi4g0jDAcGBgfh4QcGBgcMIw3iAAACAIAAYwNqA00AIgAvAAABIyc+ATU0Jy4BJyYjIgcOAQcGFRQXHgEXFjMyNjcXFRc3JyEiJjU0NjMyFhUUBiMClSEMHyQWFkszMjo5MzJLFhYWFksyMzk0XCUL1j/V/wBPcXFPUHBwUAF3DCRdMzoyM0sWFhYWSzMyOjkyM0sWFiQfDCLUP9VxT1BwcFBPcQACAGQAIgOcA3cATQBZAAABPgE1NCYnNz4BLwEuAQ8BLgEvAS4BKwEiBg8BDgEHJyYGDwEGFh8BDgEVFBYXBw4BHwEeAT8BHgEfAR4BOwEyNj8BPgE3FxY2PwE2JicFIiY1NDYzMhYVFAYDPQECAgFaBgMEVQQPB2oRJBQQAQwIqggMARAUJBFqBw8EVQQDBloBAgIBWgYDBFUEDwdqESQUEAEMCKoIDAEQFCQRagcPBFUEAwb+aT5XVz4+V1cBowoVCwsUC0YFDweUBwUDKgwVCHIHCgoHcggVDCoDBQeUBw8FRgsVCgsVCkYFEAeTBwUCKw0VCHEICgoIcQgVDSsDBgeTBxAFJlg+PldXPj5YAAEA1QCiAysC9wALAAABIREjESE1IREzESEDK/8AVv8AAQBWAQABov8AAQBVAQD/AAAAAAAJAAAAQAQAA0AAAwAHAAsADwATABcAGwAfACIAABMRIREBIzUzNSM1MzUjNTMBIREhEyM1MzUjNTM1IzUzBRElAAQA/MCAgICAgIACQP4AAgDAgICAgICA/cABAANA/QADAP1AgICAgID9gAKA/YCAgICAgID+gMAAAAAABgBA/8ADwAPAABkAIQA5AEcAVQBjAAABLgEnLgEnLgEjISIGFREUFjMhMjY1ETQmJyceARcjNR4BExQGIyEiJjURNDYzMDM6ATMyMRUUFjsBAyEiJjU0NjMhMhYVFAYnISImNTQ2MyEyFhUUBichIiY1NDYzITIWFRQGA5YRLRkaMxcnKQv+ECEvLyEC4CEvDhyFFyUNmhEphgkH/SAHCQkHTU66TU4TDeCg/kANExMNAcANExMN/kANExMNAcANExMN/kANExMNAcANExMC2xczGhktERwOLyH8oCEvLyECcAspJzYXKRGaDSX86AcJCQcDYAcJ4A0T/gATDQ0TEw0NE4ATDQ0TEw0NE4ATDQ0TEw0NEwAAAAcAAP/ABAADRgALABcAIwAvADsARwBTAAAlNDYzMhYVFAYjIiYBNDYzMhYVFAYjIiYlNDYzMhYVFAYjIiYBNDYzMhYVFAYjIiYBNDYzMhYVFAYjIiYlNDYzMhYVFAYjIiYBNDYzMhYVFAYjIiYBoDgoKDg4KCg4/mA4KCg4OCgoOANAOCgoODgoKDj9OjgoKDg4KCg4Akw4KCg4OCgoOP20OCgoODgoKDgCTDgoKDg4KCg4ICg4OCgoODgByCg4OCgoODgoKDg4KCg4OAFOKDg4KCg4OP3cKDg4KCg4OCgoODgoKDg4AnQoODgoKDg4AAUAfAAAA4QDVQAiAC0AOABGAFQAAAEjNTQmKwEiBh0BIyIGFRQWOwERFBYzITI2NREzMjY1NCYjJTQ2OwEyFh0BIzUBFAYjISImNREhEQEiBh0BFBYzMjY9ATQmMyIGHQEUFjMyNj0BNCYDXZtEMJwwRJsQFxcQJ0QwAYQwRCcQFxcQ/i8WEJwQFugBXRcQ/nwQFwHS/skQFhYQEBcXjBAXFxAQFhYCuicwREQwJxcQEBb+BzBERDAB+RYQEBcnEBcXECcn/ZMQFhYQAfn+BwGEFxDoEBcXEOgQFxcQ6BAXFxDoEBcAAAABAAAAAQAANAmLwV8PPPUACwQAAAAAANheKPcAAAAA2F4o9wAA/8AEAAPAAAAACAACAAAAAAAAAAEAAAPA/8AAAAQAAAAAAAQAAAEAAAAAAAAAAAAAAAAAAAAdBAAAAAAAAAAAAAAAAgAAAAQAAQAEAAFWBAAAqgQAAFYEAACqBAAAgAQAAFYEAACABAAAVQQAAFUEAABVBAAAVQQAAIAEAABkBAAAdQQAAAAEAACRBAAA4gQAAIAEAABkBAAA1QQAAAAEAABABAAAAAQAAHwAAAAAAAoAFAAeADIAQACIAOYBFgFiAY4BrgIUAowCrAMMAyQDjAQ0BLIEyAUGBU4F1gXwBi4GugcyB6YAAQAAAB0AeQAJAAAAAAACAAAAAAAAAAAAAAAAAAAAAAAAAA4ArgABAAAAAAABAAcAAAABAAAAAAACAAcAYAABAAAAAAADAAcANgABAAAAAAAEAAcAdQABAAAAAAAFAAsAFQABAAAAAAAGAAcASwABAAAAAAAKABoAigADAAEECQABAA4ABwADAAEECQACAA4AZwADAAEECQADAA4APQADAAEECQAEAA4AfAADAAEECQAFABYAIAADAAEECQAGAA4AUgADAAEECQAKADQApGljb21vb24AaQBjAG8AbQBvAG8AblZlcnNpb24gMS4wAFYAZQByAHMAaQBvAG4AIAAxAC4AMGljb21vb24AaQBjAG8AbQBvAG8Abmljb21vb24AaQBjAG8AbQBvAG8AblJlZ3VsYXIAUgBlAGcAdQBsAGEAcmljb21vb24AaQBjAG8AbQBvAG8AbkZvbnQgZ2VuZXJhdGVkIGJ5IEljb01vb24uAEYAbwBuAHQAIABnAGUAbgBlAHIAYQB0AGUAZAAgAGIAeQAgAEkAYwBvAE0AbwBvAG4ALgAAAAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
  26451. /***/ }),
  26452. /* 14 */
  26453. /***/ (function(module, exports) {
  26454. /*
  26455. MIT License http://www.opensource.org/licenses/mit-license.php
  26456. Author Tobias Koppers @sokra
  26457. */
  26458. // css base code, injected by the css-loader
  26459. module.exports = function(useSourceMap) {
  26460. var list = [];
  26461. // return the list of modules as css string
  26462. list.toString = function toString() {
  26463. return this.map(function (item) {
  26464. var content = cssWithMappingToString(item, useSourceMap);
  26465. if(item[2]) {
  26466. return "@media " + item[2] + "{" + content + "}";
  26467. } else {
  26468. return content;
  26469. }
  26470. }).join("");
  26471. };
  26472. // import a list of modules into the list
  26473. list.i = function(modules, mediaQuery) {
  26474. if(typeof modules === "string")
  26475. modules = [[null, modules, ""]];
  26476. var alreadyImportedModules = {};
  26477. for(var i = 0; i < this.length; i++) {
  26478. var id = this[i][0];
  26479. if(typeof id === "number")
  26480. alreadyImportedModules[id] = true;
  26481. }
  26482. for(i = 0; i < modules.length; i++) {
  26483. var item = modules[i];
  26484. // skip already imported module
  26485. // this implementation is not 100% perfect for weird media query combinations
  26486. // when a module is imported multiple times with different media queries.
  26487. // I hope this will never occur (Hey this way we have smaller bundles)
  26488. if(typeof item[0] !== "number" || !alreadyImportedModules[item[0]]) {
  26489. if(mediaQuery && !item[2]) {
  26490. item[2] = mediaQuery;
  26491. } else if(mediaQuery) {
  26492. item[2] = "(" + item[2] + ") and (" + mediaQuery + ")";
  26493. }
  26494. list.push(item);
  26495. }
  26496. }
  26497. };
  26498. return list;
  26499. };
  26500. function cssWithMappingToString(item, useSourceMap) {
  26501. var content = item[1] || '';
  26502. var cssMapping = item[3];
  26503. if (!cssMapping) {
  26504. return content;
  26505. }
  26506. if (useSourceMap && typeof btoa === 'function') {
  26507. var sourceMapping = toComment(cssMapping);
  26508. var sourceURLs = cssMapping.sources.map(function (source) {
  26509. return '/*# sourceURL=' + cssMapping.sourceRoot + source + ' */'
  26510. });
  26511. return [content].concat(sourceURLs).concat([sourceMapping]).join('\n');
  26512. }
  26513. return [content].join('\n');
  26514. }
  26515. // Adapted from convert-source-map (MIT)
  26516. function toComment(sourceMap) {
  26517. // eslint-disable-next-line no-undef
  26518. var base64 = btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap))));
  26519. var data = 'sourceMappingURL=data:application/json;charset=utf-8;base64,' + base64;
  26520. return '/*# ' + data + ' */';
  26521. }
  26522. /***/ }),
  26523. /* 15 */
  26524. /***/ (function(module, exports) {
  26525. module.exports = function escape(url) {
  26526. if (typeof url !== 'string') {
  26527. return url
  26528. }
  26529. // If url is already wrapped in quotes, remove them
  26530. if (/^['"].*['"]$/.test(url)) {
  26531. url = url.slice(1, -1);
  26532. }
  26533. // Should url be wrapped?
  26534. // See https://drafts.csswg.org/css-values-3/#urls
  26535. if (/["'() \t\n]/.test(url)) {
  26536. return '"' + url.replace(/"/g, '\\"').replace(/\n/g, '\\n') + '"'
  26537. }
  26538. return url
  26539. };
  26540. /***/ }),
  26541. /* 16 */
  26542. /***/ (function(module, exports, __webpack_require__) {
  26543. var escape = __webpack_require__(15);
  26544. exports = module.exports = __webpack_require__(14)(false);
  26545. // imports
  26546. // module
  26547. exports.push([module.i, "@font-face {\n font-family: 'bf-icons';\n src: url(" + escape(__webpack_require__(13)) + ") format(\"truetype\");\n font-weight: normal;\n font-style: normal; }\n\n.braft-finder [class^=\"braft-icon-\"], .braft-finder [class*=\" braft-icon-\"] {\n /* use !important to prevent issues with browser extensions that change fonts */\n font-family: 'bf-icons' !important;\n font-style: normal;\n font-weight: normal;\n font-variant: normal;\n text-transform: none;\n /* Better Font Rendering =========== */\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale; }\n\n.braft-finder .braft-icon-code:before {\n content: \"\\E903\"; }\n\n.braft-finder .braft-icon-pause:before {\n content: \"\\E034\"; }\n\n.braft-finder .braft-icon-play_arrow:before {\n content: \"\\E037\"; }\n\n.braft-finder .braft-icon-bin:before {\n content: \"\\E9AC\"; }\n\n.braft-finder .braft-icon-replay:before {\n content: \"\\E042\"; }\n\n.braft-finder .braft-icon-close:before {\n content: \"\\E913\"; }\n\n.braft-finder .braft-icon-music:before {\n content: \"\\E90E\"; }\n\n.braft-finder .braft-icon-camera:before {\n content: \"\\E911\"; }\n\n.braft-finder .braft-icon-file-text:before {\n content: \"\\E926\"; }\n\n.braft-finder .braft-icon-film:before {\n content: \"\\E91C\"; }\n\n.braft-finder .braft-icon-paste:before {\n content: \"\\E92D\"; }\n\n.braft-finder .braft-icon-spinner:before {\n content: \"\\E980\"; }\n\n.braft-finder .braft-icon-media:before {\n content: \"\\E90F\"; }\n\n.braft-finder .braft-icon-add:before {\n content: \"\\E918\"; }\n\n.braft-finder .braft-icon-done:before {\n content: \"\\E912\"; }\n\n.braft-finder .braft-icon-drop-down:before {\n content: \"\\E906\"; }\n\n.braft-finder .braft-icon-drop-up:before {\n content: \"\\E909\"; }\n\n.braft-finder .braft-icon-help:before {\n content: \"\\E902\"; }\n\n.braft-finder .braft-icon-info:before {\n content: \"\\E901\"; }\n\n.braft-finder .braft-icon-menu:before {\n content: \"\\E908\"; }\n\n.pull-left {\n float: left; }\n\n.pull-right {\n float: right; }\n\n.braft-finder .bf-uploader {\n position: relative;\n height: 370px;\n margin: 0; }\n .braft-finder .bf-uploader.draging .bf-list-wrap,\n .braft-finder .bf-uploader.draging .bf-add-external {\n pointer-events: none; }\n .braft-finder .bf-uploader input::-webkit-input-placeholder {\n color: #ccc; }\n .braft-finder .bf-uploader input::-moz-placeholder {\n color: #ccc; }\n .braft-finder .bf-uploader input::-ms-input-placeholder {\n color: #ccc; }\n\n.braft-finder .bf-list-wrap {\n position: relative;\n height: 370px; }\n\n.braft-finder .bf-list-tools {\n z-index: 1;\n position: absolute;\n top: 0;\n right: 0;\n left: 0;\n height: 20px;\n padding: 0 15px;\n background-color: #fff; }\n .braft-finder .bf-list-tools span {\n height: 26px;\n font-size: 12px;\n line-height: 20px;\n cursor: pointer;\n user-select: none; }\n .braft-finder .bf-list-tools span[disabled] {\n opacity: .3;\n pointer-events: none; }\n .braft-finder .bf-list-tools .bf-select-all,\n .braft-finder .bf-list-tools .bf-deselect-all {\n float: left;\n margin-right: 5px;\n color: #bbb; }\n .braft-finder .bf-list-tools .bf-select-all:hover,\n .braft-finder .bf-list-tools .bf-deselect-all:hover {\n color: #3498db; }\n .braft-finder .bf-list-tools .bf-remove-selected {\n float: right;\n color: #e74c3c; }\n .braft-finder .bf-list-tools .bf-remove-selected:hover {\n color: #c92e1e; }\n\n.braft-finder .bf-list {\n position: absolute;\n z-index: 1;\n top: 30px;\n right: 0;\n left: 0;\n bottom: 0;\n margin: 0;\n padding: 0 10px;\n list-style: none;\n overflow: auto; }\n .braft-finder .bf-list::-webkit-scrollbar {\n width: 5px;\n height: 5px;\n background-color: #fff; }\n .braft-finder .bf-list::-webkit-scrollbar-track {\n background-color: #fff; }\n .braft-finder .bf-list::-webkit-scrollbar-thumb {\n background-color: rgba(0, 0, 0, 0.1); }\n\n.braft-finder .bf-item,\n.braft-finder .bf-add-item {\n position: relative;\n display: block;\n float: left;\n width: 113px;\n height: 113px;\n margin: 5px;\n overflow: hidden;\n border-radius: 3px; }\n\n.braft-finder .bf-item.uploading {\n pointer-events: none; }\n\n.braft-finder .bf-item.error::before {\n display: block;\n content: \"\\E901\"; }\n\n.braft-finder .bf-item.error::after {\n position: absolute;\n z-index: 1;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n background-color: rgba(231, 76, 60, 0.8);\n content: ''; }\n\n.braft-finder .bf-item.error:hover::after {\n background-color: rgba(231, 76, 60, 0.9); }\n\n.braft-finder .bf-item.error .bf-item-uploading {\n display: none; }\n\n.braft-finder .bf-add-item {\n background-color: #ecedef;\n color: #999; }\n .braft-finder .bf-add-item:hover {\n background-color: #e1e2e3; }\n .braft-finder .bf-add-item i {\n display: block;\n width: 113px;\n height: 113px;\n font-size: 48px;\n line-height: 113px;\n text-align: center; }\n .braft-finder .bf-add-item input {\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n opacity: 0;\n cursor: pointer; }\n\n.braft-finder .bf-item::before {\n display: none;\n position: absolute;\n z-index: 2;\n top: 0;\n left: 0;\n width: 113px;\n height: 113px;\n color: #fff;\n font-size: 48px;\n font-family: 'bf-icons';\n line-height: 113px;\n text-align: center; }\n\n.braft-finder .bf-item::after {\n position: absolute;\n z-index: 1;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n background-color: rgba(52, 152, 219, 0);\n content: ''; }\n\n.braft-finder .bf-item:hover::after {\n background-color: rgba(52, 152, 219, 0.3); }\n\n.braft-finder .bf-item:hover .bf-item-remove {\n display: block; }\n\n.braft-finder .bf-item.active::before {\n display: block;\n content: \"\\E912\"; }\n\n.braft-finder .bf-item.active::after {\n background-color: rgba(52, 152, 219, 0.6); }\n\n.braft-finder .bf-item.active:hover::after {\n background-color: rgba(52, 152, 219, 0.8); }\n\n.braft-finder .bf-item.active:hover .bf-item-remove {\n display: none; }\n\n.braft-finder .bf-item-uploading {\n box-sizing: border-box;\n position: absolute;\n z-index: 3;\n top: 52px;\n left: 10px;\n width: 93px;\n height: 10px;\n overflow: hidden;\n background-color: rgba(255, 255, 255, 0.3);\n border-radius: 5px;\n box-shadow: 0 0 0 100px rgba(0, 0, 0, 0.5); }\n\n.braft-finder .bf-item-uploading-bar {\n height: 10px;\n background-color: #3498db;\n border-radius: 0; }\n\n.braft-finder .bf-item-remove {\n display: none;\n position: absolute;\n z-index: 2;\n top: 0;\n right: 0;\n width: 28px;\n height: 28px;\n color: #fff;\n font-size: 18px;\n line-height: 28px;\n text-align: center;\n cursor: pointer; }\n .braft-finder .bf-item-remove:hover {\n color: #e74c3c; }\n\n.braft-finder .bf-item-title {\n display: none;\n box-sizing: border-box;\n position: absolute;\n z-index: 2;\n bottom: 0;\n left: 0;\n width: 100%;\n height: 40px;\n padding: 0 5px;\n overflow: hidden;\n background-image: linear-gradient(rgba(0, 0, 0, 0), black);\n color: #fff;\n font-size: 12px;\n line-height: 55px;\n text-align: center;\n text-overflow: ellipsis;\n white-space: nowrap; }\n\n.braft-finder .bf-image {\n width: 100%;\n height: 100%;\n background-color: #eee;\n user-select: none; }\n .braft-finder .bf-image img {\n display: block;\n width: 100%;\n height: 100%;\n object-fit: cover; }\n\n.braft-finder .bf-video {\n background-color: #8e44ad; }\n\n.braft-finder .bf-audio {\n background-color: #f39c12; }\n\n.braft-finder .bf-embed {\n background-color: #f1c40f; }\n\n.braft-finder .bf-icon {\n display: block;\n width: 113px;\n height: 113px;\n overflow: hidden;\n color: #fff;\n text-align: center;\n text-decoration: none; }\n .braft-finder .bf-icon i, .braft-finder .bf-icon span {\n display: block; }\n .braft-finder .bf-icon i {\n margin-top: 35px;\n font-size: 24px; }\n .braft-finder .bf-icon span {\n width: 103px;\n margin: 10px auto;\n overflow: hidden;\n font-size: 12px;\n text-overflow: ellipsis;\n white-space: nowrap; }\n\n.braft-finder .bf-drag-uploader {\n box-sizing: border-box;\n position: absolute;\n z-index: 2;\n top: 0;\n right: 15px;\n left: 15px;\n height: 100%;\n background-color: #fff;\n border: dashed 1px #bbb;\n text-align: center;\n opacity: 0;\n pointer-events: none; }\n .braft-finder .bf-drag-uploader:hover, .braft-finder .bf-drag-uploader.draging {\n background-color: #f1f2f3; }\n .braft-finder .bf-drag-uploader.active {\n opacity: 1;\n pointer-events: auto; }\n\n.braft-finder .bf-uploader-buttons {\n height: 370px;\n margin: auto;\n text-align: center; }\n\n.braft-finder .bf-drag-tip {\n display: inline-block;\n margin-top: 150px;\n color: #ccc;\n text-align: center;\n font-size: 28px;\n font-weight: normal;\n line-height: 40px; }\n .braft-finder .bf-drag-tip input {\n position: absolute;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n width: 100%;\n height: 100%;\n opacity: 0;\n color: #fff;\n text-indent: -100px;\n cursor: pointer; }\n\n.braft-finder .bf-manager-footer {\n height: 36px;\n margin: 10px 0;\n padding: 0 15px; }\n .braft-finder .bf-manager-footer .button {\n float: right;\n height: 36px;\n margin-left: 5px;\n padding: 0 35px;\n font-size: 12px;\n font-weight: 700;\n border: none;\n border-radius: 3px;\n cursor: pointer; }\n .braft-finder .bf-manager-footer .button-insert {\n color: #fff;\n background-color: #3498db; }\n .braft-finder .bf-manager-footer .button-insert:hover {\n background-color: #2084c7; }\n .braft-finder .bf-manager-footer .button-insert[disabled] {\n opacity: .3;\n pointer-events: none;\n filter: grayscale(0.4); }\n .braft-finder .bf-manager-footer .button-cancel {\n color: #999;\n background-color: #e8e8e9; }\n .braft-finder .bf-manager-footer .button-cancel:hover {\n background-color: #d8d8d9; }\n\n.braft-finder .bf-toggle-external-form {\n color: #666;\n font-size: 12px;\n line-height: 36px; }\n .braft-finder .bf-toggle-external-form span {\n color: #bbb;\n line-height: 16px;\n cursor: pointer;\n user-select: none; }\n .braft-finder .bf-toggle-external-form span:hover {\n color: #3498db; }\n .braft-finder .bf-toggle-external-form span i {\n position: relative;\n top: 2px;\n font-size: 16px; }\n\n.braft-finder .bf-add-external {\n position: absolute;\n z-index: 3;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n background-color: #fff; }\n .braft-finder .bf-add-external input {\n border: solid 1px rgba(0, 0, 0, 0.3);\n border: solid 0.5px rgba(0, 0, 0, 0.3);\n box-shadow: none; }\n .braft-finder .bf-add-external input:focus {\n border-color: #3498db;\n box-shadow: none; }\n\n.braft-finder .bf-external-form {\n width: 500px;\n max-width: 90%;\n margin: 91px auto 0 auto; }\n\n.braft-finder .bf-external-input {\n position: relative;\n width: 100%;\n height: 40px;\n margin-bottom: 10px; }\n .braft-finder .bf-external-input div {\n position: absolute;\n top: 0;\n right: 85px;\n left: 0;\n height: 40px; }\n .braft-finder .bf-external-input input,\n .braft-finder .bf-external-input textarea {\n display: block;\n box-sizing: border-box;\n width: 100%;\n height: 40px;\n padding: 0 10px;\n border: none;\n border-radius: 3px;\n outline: none;\n box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.3);\n color: #999;\n font-size: 18px; }\n .braft-finder .bf-external-input input:focus,\n .braft-finder .bf-external-input textarea:focus {\n box-shadow: inset 0 0 0 1px #3498db; }\n .braft-finder .bf-external-input textarea {\n height: 100px;\n font-size: 14px; }\n .braft-finder .bf-external-input button {\n position: absolute;\n top: 0;\n right: 0;\n width: 80px;\n height: 40px;\n background-color: #3498db;\n border: none;\n border-radius: 3px;\n color: #fff;\n font-size: 14px;\n font-weight: bold;\n cursor: pointer; }\n .braft-finder .bf-external-input button:disabled {\n opacity: .3;\n pointer-events: none;\n filter: grayscale(0.4); }\n .braft-finder .bf-external-input button:hover {\n background-color: #2084c7; }\n\n.braft-finder .bf-switch-external-type {\n overflow: hidden;\n text-align: center; }\n .braft-finder .bf-switch-external-type button {\n width: auto;\n height: 30px;\n margin: 10px 5px;\n padding: 0 10px;\n background-color: #e8e9ea;\n border: none;\n border-radius: 3px;\n color: #999;\n font-size: 12px;\n cursor: pointer; }\n .braft-finder .bf-switch-external-type button:hover {\n background-color: #d8d9da; }\n .braft-finder .bf-switch-external-type button:only-child {\n display: none; }\n .braft-finder .bf-switch-external-type[data-type=\"IMAGE\"] [data-type=\"IMAGE\"],\n .braft-finder .bf-switch-external-type[data-type=\"VIDEO\"] [data-type=\"VIDEO\"],\n .braft-finder .bf-switch-external-type[data-type=\"AUDIO\"] [data-type=\"AUDIO\"],\n .braft-finder .bf-switch-external-type[data-type=\"EMBED\"] [data-type=\"EMBED\"],\n .braft-finder .bf-switch-external-type[data-type=\"FILE\"] [data-type=\"FILE\"] {\n background-color: #3498db;\n color: #fff; }\n\n.braft-finder .bf-external-tip {\n display: block;\n margin-top: 15px;\n color: #ccc;\n font-size: 12px;\n text-align: center; }\n", ""]);
  26548. // exports
  26549. /***/ }),
  26550. /* 17 */
  26551. /***/ (function(module, exports, __webpack_require__) {
  26552. var content = __webpack_require__(16);
  26553. if(typeof content === 'string') content = [[module.i, content, '']];
  26554. var transform;
  26555. var options = {"hmr":true};
  26556. options.transform = transform;
  26557. options.insertInto = undefined;
  26558. var update = __webpack_require__(12)(content, options);
  26559. if(content.locals) module.exports = content.locals;
  26560. /***/ }),
  26561. /* 18 */
  26562. /***/ (function(module, exports, __webpack_require__) {
  26563. Object.defineProperty(exports, "__esModule", {
  26564. value: true
  26565. });
  26566. var _extends = Object.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; };
  26567. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  26568. __webpack_require__(17);
  26569. var _react = __webpack_require__(2);
  26570. var _react2 = _interopRequireDefault(_react);
  26571. var _base = __webpack_require__(1);
  26572. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  26573. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  26574. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  26575. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  26576. var defaultAccepts = {
  26577. image: 'image/png,image/jpeg,image/gif,image/webp,image/apng,image/svg',
  26578. video: 'video/mp4',
  26579. audio: 'audio/mp3'
  26580. };
  26581. var BraftFinderView = function (_React$Component) {
  26582. _inherits(BraftFinderView, _React$Component);
  26583. function BraftFinderView(props) {
  26584. _classCallCheck(this, BraftFinderView);
  26585. var _this = _possibleConstructorReturn(this, (BraftFinderView.__proto__ || Object.getPrototypeOf(BraftFinderView)).call(this, props));
  26586. _this.toggleSelectItem = function (event) {
  26587. var itemId = event.currentTarget.dataset.id;
  26588. var item = _this.controller.getMediaItem(itemId);
  26589. if (!item) {
  26590. return false;
  26591. }
  26592. if (item.selected) {
  26593. if (!_this.props.onBeforeDeselect || _this.props.onBeforeDeselect([item], _this.controller.getItems()) !== false) {
  26594. _this.controller.deselectMediaItem(itemId);
  26595. _this.props.onDeselect && _this.props.onDeselect([item], _this.controller.getItems());
  26596. }
  26597. } else {
  26598. if (!_this.props.onBeforeSelect || _this.props.onBeforeSelect([item], _this.controller.getItems()) !== false) {
  26599. _this.controller.selectMediaItem(itemId);
  26600. _this.props.onSelect && _this.props.onSelect([item], _this.controller.getItems());
  26601. }
  26602. }
  26603. };
  26604. _this.removeItem = function (event) {
  26605. var itemId = event.currentTarget.dataset.id;
  26606. var item = _this.controller.getMediaItem(itemId);
  26607. if (!item) {
  26608. return false;
  26609. }
  26610. if (!_this.props.onBeforeRemove || _this.props.onBeforeRemove([item], _this.controller.getItems()) !== false) {
  26611. _this.controller.removeMediaItem(itemId);
  26612. _this.props.onRemove && _this.props.onRemove([item], _this.controller.getItems());
  26613. }
  26614. event.stopPropagation();
  26615. };
  26616. _this.selectAllItems = function () {
  26617. var allItems = _this.controller.getItems();
  26618. if (!_this.props.onBeforeSelect || _this.props.onBeforeSelect(allItems, allItems) !== false) {
  26619. _this.controller.selectAllItems();
  26620. _this.props.onSelect && _this.props.onSelect(allItems, allItems);
  26621. }
  26622. };
  26623. _this.deselectAllItems = function () {
  26624. var allItems = _this.controller.getItems();
  26625. if (!_this.props.onBeforeDeselect || _this.props.onBeforeDeselect(allItems, allItems) !== false) {
  26626. _this.controller.deselectAllItems();
  26627. _this.props.onDeselect && _this.props.onDeselect(allItems, allItems);
  26628. }
  26629. };
  26630. _this.removeSelectedItems = function () {
  26631. var selectedItems = _this.controller.getSelectedItems();
  26632. if (!_this.props.onBeforeRemove || _this.props.onBeforeRemove(selectedItems, _this.controller.getItems()) !== false) {
  26633. _this.controller.removeSelectedItems();
  26634. _this.props.onRemove && _this.props.onRemove(selectedItems, _this.controller.getItems());
  26635. }
  26636. };
  26637. _this.handleDragLeave = function (event) {
  26638. event.preventDefault();
  26639. _this.dragCounter--;
  26640. _this.dragCounter === 0 && _this.setState({
  26641. draging: false
  26642. });
  26643. };
  26644. _this.handleDragDrop = function (event) {
  26645. event.preventDefault();
  26646. _this.dragCounter = 0;
  26647. _this.setState({ draging: false });
  26648. _this.reslovePickedFiles(event);
  26649. };
  26650. _this.handleDragEnter = function (event) {
  26651. event.preventDefault();
  26652. _this.dragCounter++;
  26653. _this.setState({ draging: true });
  26654. };
  26655. _this.reslovePickedFiles = function (event) {
  26656. event.persist();
  26657. var _ref = event.type === 'drop' ? event.dataTransfer : event.target,
  26658. files = _ref.files;
  26659. if (_this.props.onFileSelect) {
  26660. var result = _this.props.onFileSelect(files);
  26661. if (result === false) {
  26662. return false;
  26663. } else if (result instanceof FileList || result instanceof Array) {
  26664. files = result;
  26665. }
  26666. }
  26667. var accepts = _extends({}, defaultAccepts, _this.props.accepts);
  26668. _this.controller.resolveFiles({
  26669. files: files,
  26670. onItemReady: function onItemReady(_ref2) {
  26671. var id = _ref2.id;
  26672. return _this.controller.selectMediaItem(id);
  26673. },
  26674. onAllReady: function onAllReady() {
  26675. return event.target.value = null;
  26676. }
  26677. }, 0, accepts);
  26678. };
  26679. _this.inputExternal = function (event) {
  26680. _this.setState({
  26681. external: _extends({}, _this.state.external, {
  26682. url: event.target.value
  26683. })
  26684. });
  26685. };
  26686. _this.switchExternalType = function (event) {
  26687. _this.setState({
  26688. external: _extends({}, _this.state.external, { type: event.target.dataset.type })
  26689. });
  26690. };
  26691. _this.confirmAddExternal = function (event) {
  26692. if (event.target.nodeName.toLowerCase() === 'button' || event.keyCode === 13) {
  26693. var _this$state$external = _this.state.external,
  26694. url = _this$state$external.url,
  26695. type = _this$state$external.type;
  26696. url = url.split('|');
  26697. var name = url.length > 1 ? url[0] : _this.props.language.unnamedItem;
  26698. url = url.length > 1 ? url[1] : url[0];
  26699. var thumbnail = type === 'IMAGE' ? url : null;
  26700. _this.controller.addItems([{
  26701. thumbnail: thumbnail, url: url, name: name, type: type,
  26702. id: new Date().getTime() + '_' + (0, _base.UniqueIndex)(),
  26703. uploading: false,
  26704. uploadProgress: 1,
  26705. selected: true
  26706. }]);
  26707. _this.setState({
  26708. showExternalForm: false,
  26709. external: {
  26710. url: '',
  26711. type: 'IMAGE'
  26712. }
  26713. });
  26714. }
  26715. };
  26716. _this.toggleExternalForm = function () {
  26717. _this.setState({
  26718. showExternalForm: !_this.state.showExternalForm
  26719. });
  26720. };
  26721. _this.cancelInsert = function () {
  26722. _this.props.onCancel && _this.props.onCancel();
  26723. };
  26724. _this.confirmInsert = function () {
  26725. var selectedItems = _this.controller.getSelectedItems();
  26726. if (_this.props.onBeforeInsert) {
  26727. var filteredItems = _this.props.onBeforeInsert(selectedItems);
  26728. if (filteredItems && filteredItems instanceof Array) {
  26729. _this.controller.deselectAllItems();
  26730. _this.props.onInsert && _this.props.onInsert(filteredItems);
  26731. } else if (filteredItems !== false) {
  26732. _this.controller.deselectAllItems();
  26733. _this.props.onInsert && _this.props.onInsert(selectedItems);
  26734. }
  26735. } else {
  26736. _this.controller.deselectAllItems();
  26737. _this.props.onInsert && _this.props.onInsert(selectedItems);
  26738. }
  26739. };
  26740. _this.dragCounter = 0;
  26741. _this.controller = _this.props.controller;
  26742. var initialItems = _this.controller.getItems();
  26743. _this.state = {
  26744. draging: false,
  26745. error: false,
  26746. confirmable: initialItems.find(function (_ref3) {
  26747. var selected = _ref3.selected;
  26748. return selected;
  26749. }),
  26750. external: {
  26751. url: '',
  26752. type: 'IMAGE'
  26753. },
  26754. fileAccept: '',
  26755. showExternalForm: false,
  26756. allowExternal: false,
  26757. items: initialItems
  26758. };
  26759. _this.changeListenerId = _this.controller.onChange(function (items) {
  26760. _this.setState({ items: items, confirmable: items.find(function (_ref4) {
  26761. var selected = _ref4.selected;
  26762. return selected;
  26763. }) });
  26764. _this.props.onChange && _this.props.onChange(items);
  26765. });
  26766. return _this;
  26767. }
  26768. _createClass(BraftFinderView, [{
  26769. key: 'mapPropsToState',
  26770. value: function mapPropsToState(props) {
  26771. var accepts = props.accepts,
  26772. externals = props.externals;
  26773. accepts = _extends({}, defaultAccepts, accepts);
  26774. var fileAccept = !accepts ? [defaultAccepts.image, defaultAccepts.video, defaultAccepts.audio].join(',') : [accepts.image, accepts.video, accepts.audio].filter(function (item) {
  26775. return item;
  26776. }).join(',');
  26777. var external = {
  26778. url: '',
  26779. type: externals.image ? 'IMAGE' : externals.audio ? 'AUDIO' : externals.video ? 'VIDEO' : externals.embed ? 'EMBED' : ''
  26780. };
  26781. return {
  26782. fileAccept: fileAccept,
  26783. external: external,
  26784. allowExternal: externals && (externals.image || externals.audio || externals.video || externals.embed)
  26785. };
  26786. }
  26787. }, {
  26788. key: 'componentDidMount',
  26789. value: function componentDidMount() {
  26790. this.setState(this.mapPropsToState(this.props));
  26791. }
  26792. }, {
  26793. key: 'componentWillReceiveProps',
  26794. value: function componentWillReceiveProps(nextProps) {
  26795. this.setState(this.mapPropsToState(nextProps));
  26796. }
  26797. }, {
  26798. key: 'componentWillUnmount',
  26799. value: function componentWillUnmount() {
  26800. this.controller.offChange(this.changeListenerId);
  26801. }
  26802. }, {
  26803. key: 'render',
  26804. value: function render() {
  26805. var _props = this.props,
  26806. language = _props.language,
  26807. externals = _props.externals;
  26808. var _state = this.state,
  26809. items = _state.items,
  26810. draging = _state.draging,
  26811. confirmable = _state.confirmable,
  26812. fileAccept = _state.fileAccept,
  26813. external = _state.external,
  26814. showExternalForm = _state.showExternalForm,
  26815. allowExternal = _state.allowExternal;
  26816. return _react2.default.createElement(
  26817. 'div',
  26818. { className: 'braft-finder' },
  26819. _react2.default.createElement(
  26820. 'div',
  26821. {
  26822. onDragEnter: this.handleDragEnter,
  26823. onDragOver: this.handleDragEnter,
  26824. onDragLeave: this.handleDragLeave,
  26825. onDrop: this.handleDragDrop,
  26826. className: 'bf-uploader'
  26827. },
  26828. _react2.default.createElement(
  26829. 'div',
  26830. { className: "bf-drag-uploader " + (draging || !items.length ? 'active ' : ' ') + (draging ? 'draging' : '') },
  26831. _react2.default.createElement(
  26832. 'span',
  26833. { className: 'bf-drag-tip' },
  26834. _react2.default.createElement('input', { accept: fileAccept, onChange: this.reslovePickedFiles, multiple: true, type: 'file' }),
  26835. draging ? language.dropTip : language.dragTip
  26836. )
  26837. ),
  26838. items.length ? _react2.default.createElement(
  26839. 'div',
  26840. { className: 'bf-list-wrap' },
  26841. _react2.default.createElement(
  26842. 'div',
  26843. { className: 'bf-list-tools' },
  26844. _react2.default.createElement(
  26845. 'span',
  26846. { onClick: this.selectAllItems, className: 'bf-select-all' },
  26847. _react2.default.createElement('i', { className: 'braft-icon-done' }),
  26848. ' ',
  26849. language.selectAll
  26850. ),
  26851. _react2.default.createElement(
  26852. 'span',
  26853. { onClick: this.deselectAllItems, disabled: !confirmable, className: 'bf-deselect-all' },
  26854. _react2.default.createElement('i', { className: 'braft-icon-close' }),
  26855. ' ',
  26856. language.deselect
  26857. ),
  26858. _react2.default.createElement(
  26859. 'span',
  26860. { onClick: this.removeSelectedItems, disabled: !confirmable, className: 'bf-remove-selected' },
  26861. _react2.default.createElement('i', { className: 'braft-icon-bin' }),
  26862. ' ',
  26863. language.removeSelected
  26864. )
  26865. ),
  26866. this.buildItemList()
  26867. ) : null,
  26868. showExternalForm && allowExternal ? _react2.default.createElement(
  26869. 'div',
  26870. { className: 'bf-add-external' },
  26871. _react2.default.createElement(
  26872. 'div',
  26873. { className: 'bf-external-form' },
  26874. _react2.default.createElement(
  26875. 'div',
  26876. { className: 'bf-external-input' },
  26877. _react2.default.createElement(
  26878. 'div',
  26879. null,
  26880. _react2.default.createElement('input', { onKeyDown: this.confirmAddExternal, value: external.url, onChange: this.inputExternal, placeholder: language.externalInputPlaceHolder })
  26881. ),
  26882. _react2.default.createElement(
  26883. 'button',
  26884. { type: 'button', onClick: this.confirmAddExternal, disabled: !external.url.trim().length },
  26885. language.confirm
  26886. )
  26887. ),
  26888. _react2.default.createElement(
  26889. 'div',
  26890. { 'data-type': external.type, className: 'bf-switch-external-type' },
  26891. externals.image ? _react2.default.createElement(
  26892. 'button',
  26893. { type: 'button', onClick: this.switchExternalType, 'data-type': 'IMAGE' },
  26894. language.image
  26895. ) : null,
  26896. externals.audio ? _react2.default.createElement(
  26897. 'button',
  26898. { type: 'button', onClick: this.switchExternalType, 'data-type': 'AUDIO' },
  26899. language.audio
  26900. ) : null,
  26901. externals.video ? _react2.default.createElement(
  26902. 'button',
  26903. { type: 'button', onClick: this.switchExternalType, 'data-type': 'VIDEO' },
  26904. language.video
  26905. ) : null,
  26906. externals.embed ? _react2.default.createElement(
  26907. 'button',
  26908. { type: 'button', onClick: this.switchExternalType, 'data-type': 'EMBED' },
  26909. language.embed
  26910. ) : null
  26911. ),
  26912. _react2.default.createElement(
  26913. 'span',
  26914. { className: 'bf-external-tip' },
  26915. language.externalInputTip
  26916. )
  26917. )
  26918. ) : null
  26919. ),
  26920. _react2.default.createElement(
  26921. 'footer',
  26922. { className: 'bf-manager-footer' },
  26923. _react2.default.createElement(
  26924. 'div',
  26925. { className: 'pull-left' },
  26926. allowExternal ? _react2.default.createElement(
  26927. 'span',
  26928. {
  26929. onClick: this.toggleExternalForm,
  26930. className: 'bf-toggle-external-form'
  26931. },
  26932. showExternalForm ? _react2.default.createElement(
  26933. 'span',
  26934. { className: 'bf-bottom-text' },
  26935. _react2.default.createElement('i', { className: 'braft-icon-add' }),
  26936. ' ',
  26937. language.addLocalFile
  26938. ) : _react2.default.createElement(
  26939. 'span',
  26940. { className: 'bf-bottom-text' },
  26941. _react2.default.createElement('i', { className: 'braft-icon-add' }),
  26942. ' ',
  26943. language.addExternalSource
  26944. )
  26945. ) : null
  26946. ),
  26947. _react2.default.createElement(
  26948. 'div',
  26949. { className: 'pull-right' },
  26950. _react2.default.createElement(
  26951. 'button',
  26952. { onClick: this.confirmInsert, className: 'button button-insert', disabled: !confirmable },
  26953. language.insert
  26954. ),
  26955. _react2.default.createElement(
  26956. 'button',
  26957. { onClick: this.cancelInsert, className: 'button button-cancel' },
  26958. language.cancel
  26959. )
  26960. )
  26961. )
  26962. );
  26963. }
  26964. }, {
  26965. key: 'buildItemList',
  26966. value: function buildItemList() {
  26967. var _this2 = this;
  26968. return _react2.default.createElement(
  26969. 'ul',
  26970. { className: 'bf-list' },
  26971. _react2.default.createElement(
  26972. 'li',
  26973. { className: 'bf-add-item' },
  26974. _react2.default.createElement('i', { className: 'braft-icon-add' }),
  26975. _react2.default.createElement('input', { accept: this.state.fileAccept, onChange: this.reslovePickedFiles, multiple: true, type: 'file' })
  26976. ),
  26977. this.state.items.map(function (item, index) {
  26978. var previewerComponents = null;
  26979. var progressMarker = item.uploading && !_this2.props.hideProgress ? _react2.default.createElement(
  26980. 'div',
  26981. { className: 'bf-item-uploading' },
  26982. _react2.default.createElement('div', { className: 'bf-item-uploading-bar', style: { width: item.uploadProgress / 1 + '%' } })
  26983. ) : '';
  26984. switch (item.type) {
  26985. case 'IMAGE':
  26986. previewerComponents = _react2.default.createElement(
  26987. 'div',
  26988. { className: 'bf-image' },
  26989. progressMarker,
  26990. _react2.default.createElement('img', { src: item.thumbnail || item.url })
  26991. );
  26992. break;
  26993. case 'VIDEO':
  26994. previewerComponents = _react2.default.createElement(
  26995. 'div',
  26996. { className: 'bf-icon bf-video', title: item.url },
  26997. progressMarker,
  26998. _react2.default.createElement('i', { className: 'braft-icon-film' }),
  26999. _react2.default.createElement(
  27000. 'span',
  27001. null,
  27002. item.name || item.url
  27003. )
  27004. );
  27005. break;
  27006. case 'AUDIO':
  27007. previewerComponents = _react2.default.createElement(
  27008. 'div',
  27009. { className: 'bf-icon bf-audio', title: item.url },
  27010. progressMarker,
  27011. _react2.default.createElement('i', { className: 'braft-icon-music' }),
  27012. _react2.default.createElement(
  27013. 'span',
  27014. null,
  27015. item.name || item.url
  27016. )
  27017. );
  27018. break;
  27019. case 'EMBED':
  27020. previewerComponents = _react2.default.createElement(
  27021. 'div',
  27022. { className: 'bf-icon bf-embed', title: item.url },
  27023. progressMarker,
  27024. _react2.default.createElement('i', { className: 'braft-icon-code' }),
  27025. _react2.default.createElement(
  27026. 'span',
  27027. null,
  27028. item.name || _this2.props.language.embed
  27029. )
  27030. );
  27031. break;
  27032. default:
  27033. previewerComponents = _react2.default.createElement(
  27034. 'a',
  27035. { className: 'bf-icon bf-file', title: item.url, href: item.url },
  27036. progressMarker,
  27037. _react2.default.createElement('i', { className: 'braft-icon-file-text' }),
  27038. _react2.default.createElement(
  27039. 'span',
  27040. null,
  27041. item.name || item.url
  27042. )
  27043. );
  27044. break;
  27045. }
  27046. var className = ['bf-item'];
  27047. item.selected && className.push('active');
  27048. item.uploading && className.push('uploading');
  27049. item.error && className.push('error');
  27050. return _react2.default.createElement(
  27051. 'li',
  27052. {
  27053. key: index,
  27054. title: item.name,
  27055. 'data-id': item.id,
  27056. className: className.join(' '),
  27057. onClick: _this2.toggleSelectItem
  27058. },
  27059. previewerComponents,
  27060. _react2.default.createElement('span', { 'data-id': item.id, onClick: _this2.removeItem, className: 'bf-item-remove braft-icon-close' }),
  27061. _react2.default.createElement(
  27062. 'span',
  27063. { className: 'bf-item-title' },
  27064. item.name
  27065. )
  27066. );
  27067. })
  27068. );
  27069. }
  27070. }]);
  27071. return BraftFinderView;
  27072. }(_react2.default.Component);
  27073. BraftFinderView.defaultProps = {
  27074. accepts: defaultAccepts,
  27075. externals: {
  27076. image: true,
  27077. video: true,
  27078. audio: true,
  27079. embed: true
  27080. }
  27081. };
  27082. exports.default = BraftFinderView;
  27083. /***/ }),
  27084. /* 19 */
  27085. /***/ (function(module, exports, __webpack_require__) {
  27086. Object.defineProperty(exports, "__esModule", {
  27087. value: true
  27088. });
  27089. var _extends = Object.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; };
  27090. var _base = __webpack_require__(1);
  27091. var _image = __webpack_require__(0);
  27092. function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
  27093. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  27094. var defaultValidator = function defaultValidator() {
  27095. return true;
  27096. };
  27097. var BraftFinderController = function BraftFinderController() {
  27098. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  27099. _classCallCheck(this, BraftFinderController);
  27100. _initialiseProps.call(this);
  27101. this.items = props.items || [];
  27102. this.uploadFn = props.uploader;
  27103. this.validateFn = props.validator || defaultValidator;
  27104. this.changeListeners = [];
  27105. }
  27106. // resolvePastedFiles ({ clipboardData }, callback) {
  27107. // if (clipboardData && clipboardData.items && clipboardData.items[0].type.indexOf('image') > -1) {
  27108. // this.uploadImage(clipboardData.items[0].getAsFile(), callback)
  27109. // }
  27110. // }
  27111. ;
  27112. var _initialiseProps = function _initialiseProps() {
  27113. var _this = this;
  27114. this.setProps = function () {
  27115. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  27116. _this.items = props.items || _this.items || [];
  27117. _this.uploadFn = props.uploader;
  27118. _this.validateFn = props.validator || defaultValidator;
  27119. };
  27120. this.getMediaItem = function (id) {
  27121. return _this.items.find(function (item) {
  27122. return item.id === id;
  27123. });
  27124. };
  27125. this.getSelectedItems = function () {
  27126. return _this.items.filter(function (item) {
  27127. return item.selected;
  27128. });
  27129. };
  27130. this.getItems = function () {
  27131. return _this.items;
  27132. };
  27133. this.setItems = function (items) {
  27134. _this.items = items.map(function (item) {
  27135. return _extends({}, item, { id: item.id.toString() });
  27136. }) || [];
  27137. _this.applyChange();
  27138. _this.uploadItems();
  27139. };
  27140. this.addMediaItem = function (item) {
  27141. _this.addItems([item]);
  27142. };
  27143. this.addItems = function (items) {
  27144. _this.items = [].concat(_toConsumableArray(_this.items), _toConsumableArray(items.map(function (item) {
  27145. return _extends({}, item, { id: item.id.toString() });
  27146. })));
  27147. _this.applyChange();
  27148. _this.uploadItems();
  27149. };
  27150. this.selectMediaItem = function (id) {
  27151. var item = _this.getMediaItem(id);
  27152. if (item && (item.uploading || item.error)) {
  27153. return false;
  27154. }
  27155. _this.setMediaItemState(id, {
  27156. selected: true
  27157. });
  27158. };
  27159. this.selectAllItems = function () {
  27160. _this.items = _this.items.filter(function (item) {
  27161. return !item.error && !item.uploading;
  27162. }).map(function (item) {
  27163. return _extends({}, item, { selected: true });
  27164. });
  27165. _this.applyChange();
  27166. };
  27167. this.deselectMediaItem = function (id) {
  27168. _this.setMediaItemState(id, {
  27169. selected: false
  27170. });
  27171. };
  27172. this.deselectAllItems = function () {
  27173. _this.items = _this.items.map(function (item) {
  27174. return _extends({}, item, { selected: false });
  27175. });
  27176. _this.applyChange();
  27177. };
  27178. this.removeMediaItem = function (id) {
  27179. _this.items = _this.items.filter(function (item) {
  27180. return item.id !== id;
  27181. });
  27182. _this.applyChange();
  27183. };
  27184. this.removeItems = function () {
  27185. var ids = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  27186. _this.items = _this.items.filter(function (item) {
  27187. return !ids.includes(item.id);
  27188. });
  27189. _this.applyChange();
  27190. };
  27191. this.removeSelectedItems = function () {
  27192. _this.items = _this.items.filter(function (item) {
  27193. return !item.selected;
  27194. });
  27195. _this.applyChange();
  27196. };
  27197. this.removeErrorItems = function () {
  27198. _this.items = _this.items.filter(function (item) {
  27199. return !item.error;
  27200. });
  27201. _this.applyChange();
  27202. };
  27203. this.removeAllItems = function () {
  27204. _this.items = [];
  27205. _this.applyChange();
  27206. };
  27207. this.setMediaItemState = function (id, state) {
  27208. _this.items = _this.items.map(function (item) {
  27209. return item.id === id ? _extends({}, item, state) : item;
  27210. });
  27211. _this.applyChange();
  27212. };
  27213. this.reuploadErrorItems = function () {
  27214. _this.uploadItems(true);
  27215. };
  27216. this.uploadItems = function () {
  27217. var ignoreError = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  27218. _this.items.forEach(function (item, index) {
  27219. if (item.uploading || item.url) {
  27220. return false;
  27221. }
  27222. if (!ignoreError && item.error) {
  27223. return false;
  27224. }
  27225. if (item.type === 'IMAGE') {
  27226. _this.createThumbnail(item);
  27227. _this.uploadFn = _this.uploadFn || _this.createInlineImage;
  27228. } else if (!_this.uploadFn) {
  27229. _this.setMediaItemState(item.id, { error: 1 });
  27230. return false;
  27231. }
  27232. _this.setMediaItemState(item.id, {
  27233. uploading: true,
  27234. uploadProgress: 0,
  27235. error: 0
  27236. });
  27237. _this.uploadFn({
  27238. id: item.id,
  27239. file: item.file,
  27240. success: function success(res) {
  27241. _this.handleUploadSuccess(item.id, res);
  27242. },
  27243. progress: function progress(_progress) {
  27244. _this.setMediaItemState(item.id, {
  27245. uploading: true,
  27246. uploadProgress: _progress
  27247. });
  27248. },
  27249. error: function error(_error) {
  27250. _this.setMediaItemState(item.id, {
  27251. uploading: false,
  27252. error: 2
  27253. });
  27254. }
  27255. });
  27256. });
  27257. };
  27258. this.createThumbnail = function (_ref) {
  27259. var id = _ref.id,
  27260. file = _ref.file;
  27261. (0, _image.compressImage)(URL.createObjectURL(file), 226, 226).then(function (result) {
  27262. _this.setMediaItemState(id, { thumbnail: result.url });
  27263. });
  27264. };
  27265. this.createInlineImage = function (param) {
  27266. (0, _image.compressImage)(URL.createObjectURL(param.file), 1280, 800).then(function (result) {
  27267. param.success({ url: result.url });
  27268. }).catch(function (error) {
  27269. param.error(error);
  27270. });
  27271. };
  27272. this.handleUploadSuccess = function (id, data) {
  27273. _this.setMediaItemState(id, _extends({}, data, {
  27274. file: null,
  27275. uploadProgress: 1,
  27276. uploading: false,
  27277. selected: false
  27278. }));
  27279. var item = _this.getMediaItem(data.id || id);
  27280. item.onReady && item.onReady(item);
  27281. };
  27282. this.applyChange = function () {
  27283. _this.changeListeners.forEach(function (_ref2) {
  27284. var callback = _ref2.callback;
  27285. return callback(_this.items);
  27286. });
  27287. };
  27288. this.uploadImage = function (file, callback) {
  27289. var fileId = new Date().getTime() + '_' + (0, _base.UniqueIndex)();
  27290. _this.addMediaItem({
  27291. type: 'IMAGE',
  27292. id: fileId,
  27293. file: file,
  27294. name: fileId,
  27295. size: file.size,
  27296. uploadProgress: 0,
  27297. uploading: false,
  27298. selected: false,
  27299. error: 0,
  27300. onReady: callback
  27301. });
  27302. };
  27303. this.uploadImageRecursively = function (files, callback) {
  27304. var index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
  27305. if (files[index] && files[index].type.indexOf('image') > -1) {
  27306. _this.uploadImage(files[index], function (image) {
  27307. callback && callback(image);
  27308. index < files.length - 1 && _this.uploadImageRecursively(files, callback, index + 1);
  27309. });
  27310. } else {
  27311. index < files.length - 1 && _this.uploadImageRecursively(files, callback, index + 1);
  27312. }
  27313. };
  27314. this.addResolvedFiles = function (param, index, accepts) {
  27315. var data = {
  27316. id: new Date().getTime() + '_' + (0, _base.UniqueIndex)(),
  27317. file: param.files[index],
  27318. name: param.files[index].name,
  27319. size: param.files[index].size,
  27320. uploadProgress: 0,
  27321. uploading: false,
  27322. selected: false,
  27323. error: 0,
  27324. onReady: function onReady(item) {
  27325. param.onItemReady && param.onItemReady(item);
  27326. }
  27327. };
  27328. if (param.files[index].type.indexOf('image/') === 0 && accepts.image) {
  27329. data.type = 'IMAGE';
  27330. _this.addMediaItem(data);
  27331. } else if (param.files[index].type.indexOf('video/') === 0 && accepts.video) {
  27332. data.type = 'VIDEO';
  27333. _this.addMediaItem(data);
  27334. } else if (param.files[index].type.indexOf('audio/') === 0 && accepts.audio) {
  27335. data.type = 'AUDIO';
  27336. _this.addMediaItem(data);
  27337. }
  27338. setTimeout(function () {
  27339. _this.resolveFiles(param, index + 1, accepts);
  27340. }, 60);
  27341. };
  27342. this.resolveFiles = function (param, index, accepts) {
  27343. if (index < param.files.length) {
  27344. var validateResult = _this.validateFn(param.files[index]);
  27345. if (validateResult instanceof Promise) {
  27346. validateResult.then(function () {
  27347. _this.addResolvedFiles(param, index, accepts);
  27348. });
  27349. } else if (validateResult) {
  27350. _this.addResolvedFiles(param, index, accepts);
  27351. }
  27352. } else {
  27353. param.onAllReady && param.onAllReady();
  27354. }
  27355. };
  27356. this.onChange = function (callback) {
  27357. var listenerId = (0, _base.UniqueIndex)();
  27358. _this.changeListeners.push({
  27359. id: listenerId,
  27360. callback: callback
  27361. });
  27362. return listenerId;
  27363. };
  27364. this.offChange = function (listenerId) {
  27365. _this.changeListeners = _this.changeListeners.filter(function (_ref3) {
  27366. var id = _ref3.id;
  27367. return id !== listenerId;
  27368. });
  27369. };
  27370. };
  27371. exports.default = BraftFinderController;
  27372. /***/ }),
  27373. /* 20 */
  27374. /***/ (function(module, exports, __webpack_require__) {
  27375. Object.defineProperty(exports, "__esModule", {
  27376. value: true
  27377. });
  27378. exports.ImageUtils = undefined;
  27379. var _extends = Object.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; };
  27380. var _react = __webpack_require__(2);
  27381. var _react2 = _interopRequireDefault(_react);
  27382. var _controller = __webpack_require__(19);
  27383. var _controller2 = _interopRequireDefault(_controller);
  27384. var _view = __webpack_require__(18);
  27385. var _view2 = _interopRequireDefault(_view);
  27386. var _languages = __webpack_require__(10);
  27387. var _languages2 = _interopRequireDefault(_languages);
  27388. var _image = __webpack_require__(0);
  27389. var ImageUtils = _interopRequireWildcard(_image);
  27390. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  27391. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  27392. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  27393. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  27394. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  27395. var BraftFinder = function (_FinderController) {
  27396. _inherits(BraftFinder, _FinderController);
  27397. function BraftFinder(props) {
  27398. _classCallCheck(this, BraftFinder);
  27399. var _this = _possibleConstructorReturn(this, (BraftFinder.__proto__ || Object.getPrototypeOf(BraftFinder)).call(this, props));
  27400. _initialiseProps.call(_this);
  27401. _this.superProps = props;
  27402. return _this;
  27403. }
  27404. return BraftFinder;
  27405. }(_controller2.default);
  27406. var _initialiseProps = function _initialiseProps() {
  27407. var _this2 = this;
  27408. this.ReactComponent = function () {
  27409. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  27410. var componentProps = _extends({}, _this2.superProps, props);
  27411. var language = (typeof componentProps.language === 'function' ? componentProps.language(_languages2.default, 'braft-finder') : _languages2.default[componentProps.language]) || _languages2.default['zh'];
  27412. return _react2.default.createElement(_view2.default, _extends({}, componentProps, {
  27413. language: language,
  27414. controller: _this2
  27415. }));
  27416. };
  27417. };
  27418. exports.default = BraftFinder;
  27419. exports.ImageUtils = ImageUtils;
  27420. /***/ })
  27421. /******/ ]);
  27422. });
  27423. });
  27424. _commonjsHelpers.unwrapExports(dist$2);
  27425. var dist$3 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
  27426. (function webpackUniversalModuleDefinition(root, factory) {
  27427. module.exports = factory(React__default, dist$1, Draft, immutable$1, dist, reactDom__default, dist$2, draftjsUtils);
  27428. })(window, function(__WEBPACK_EXTERNAL_MODULE__0__, __WEBPACK_EXTERNAL_MODULE__3__, __WEBPACK_EXTERNAL_MODULE__6__, __WEBPACK_EXTERNAL_MODULE__13__, __WEBPACK_EXTERNAL_MODULE__14__, __WEBPACK_EXTERNAL_MODULE__16__, __WEBPACK_EXTERNAL_MODULE__17__, __WEBPACK_EXTERNAL_MODULE__23__) {
  27429. return /******/ (function(modules) { // webpackBootstrap
  27430. /******/ // The module cache
  27431. /******/ var installedModules = {};
  27432. /******/
  27433. /******/ // The require function
  27434. /******/ function __webpack_require__(moduleId) {
  27435. /******/
  27436. /******/ // Check if module is in cache
  27437. /******/ if(installedModules[moduleId]) {
  27438. /******/ return installedModules[moduleId].exports;
  27439. /******/ }
  27440. /******/ // Create a new module (and put it into the cache)
  27441. /******/ var module = installedModules[moduleId] = {
  27442. /******/ i: moduleId,
  27443. /******/ l: false,
  27444. /******/ exports: {}
  27445. /******/ };
  27446. /******/
  27447. /******/ // Execute the module function
  27448. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  27449. /******/
  27450. /******/ // Flag the module as loaded
  27451. /******/ module.l = true;
  27452. /******/
  27453. /******/ // Return the exports of the module
  27454. /******/ return module.exports;
  27455. /******/ }
  27456. /******/
  27457. /******/
  27458. /******/ // expose the modules object (__webpack_modules__)
  27459. /******/ __webpack_require__.m = modules;
  27460. /******/
  27461. /******/ // expose the module cache
  27462. /******/ __webpack_require__.c = installedModules;
  27463. /******/
  27464. /******/ // define getter function for harmony exports
  27465. /******/ __webpack_require__.d = function(exports, name, getter) {
  27466. /******/ if(!__webpack_require__.o(exports, name)) {
  27467. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  27468. /******/ }
  27469. /******/ };
  27470. /******/
  27471. /******/ // define __esModule on exports
  27472. /******/ __webpack_require__.r = function(exports) {
  27473. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  27474. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  27475. /******/ }
  27476. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  27477. /******/ };
  27478. /******/
  27479. /******/ // create a fake namespace object
  27480. /******/ // mode & 1: value is a module id, require it
  27481. /******/ // mode & 2: merge all properties of value into the ns
  27482. /******/ // mode & 4: return value when already ns object
  27483. /******/ // mode & 8|1: behave like require
  27484. /******/ __webpack_require__.t = function(value, mode) {
  27485. /******/ if(mode & 1) value = __webpack_require__(value);
  27486. /******/ if(mode & 8) return value;
  27487. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  27488. /******/ var ns = Object.create(null);
  27489. /******/ __webpack_require__.r(ns);
  27490. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  27491. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  27492. /******/ return ns;
  27493. /******/ };
  27494. /******/
  27495. /******/ // getDefaultExport function for compatibility with non-harmony modules
  27496. /******/ __webpack_require__.n = function(module) {
  27497. /******/ var getter = module && module.__esModule ?
  27498. /******/ function getDefault() { return module['default']; } :
  27499. /******/ function getModuleExports() { return module; };
  27500. /******/ __webpack_require__.d(getter, 'a', getter);
  27501. /******/ return getter;
  27502. /******/ };
  27503. /******/
  27504. /******/ // Object.prototype.hasOwnProperty.call
  27505. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  27506. /******/
  27507. /******/ // __webpack_public_path__
  27508. /******/ __webpack_require__.p = "/";
  27509. /******/
  27510. /******/
  27511. /******/ // Load entry module and return exports
  27512. /******/ return __webpack_require__(__webpack_require__.s = 39);
  27513. /******/ })
  27514. /************************************************************************/
  27515. /******/ ([
  27516. /* 0 */
  27517. /***/ (function(module, exports) {
  27518. module.exports = __WEBPACK_EXTERNAL_MODULE__0__;
  27519. /***/ }),
  27520. /* 1 */
  27521. /***/ (function(module, exports) {
  27522. function _assertThisInitialized(self) {
  27523. if (self === void 0) {
  27524. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  27525. }
  27526. return self;
  27527. }
  27528. module.exports = _assertThisInitialized;
  27529. /***/ }),
  27530. /* 2 */
  27531. /***/ (function(module, exports) {
  27532. function _defineProperty(obj, key, value) {
  27533. if (key in obj) {
  27534. Object.defineProperty(obj, key, {
  27535. value: value,
  27536. enumerable: true,
  27537. configurable: true,
  27538. writable: true
  27539. });
  27540. } else {
  27541. obj[key] = value;
  27542. }
  27543. return obj;
  27544. }
  27545. module.exports = _defineProperty;
  27546. /***/ }),
  27547. /* 3 */
  27548. /***/ (function(module, exports) {
  27549. module.exports = __WEBPACK_EXTERNAL_MODULE__3__;
  27550. /***/ }),
  27551. /* 4 */
  27552. /***/ (function(module, exports) {
  27553. function _classCallCheck(instance, Constructor) {
  27554. if (!(instance instanceof Constructor)) {
  27555. throw new TypeError("Cannot call a class as a function");
  27556. }
  27557. }
  27558. module.exports = _classCallCheck;
  27559. /***/ }),
  27560. /* 5 */
  27561. /***/ (function(module, exports, __webpack_require__) {
  27562. var defineProperty = __webpack_require__(2);
  27563. function _objectSpread(target) {
  27564. for (var i = 1; i < arguments.length; i++) {
  27565. var source = arguments[i] != null ? arguments[i] : {};
  27566. var ownKeys = Object.keys(source);
  27567. if (typeof Object.getOwnPropertySymbols === 'function') {
  27568. ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
  27569. return Object.getOwnPropertyDescriptor(source, sym).enumerable;
  27570. }));
  27571. }
  27572. ownKeys.forEach(function (key) {
  27573. defineProperty(target, key, source[key]);
  27574. });
  27575. }
  27576. return target;
  27577. }
  27578. module.exports = _objectSpread;
  27579. /***/ }),
  27580. /* 6 */
  27581. /***/ (function(module, exports) {
  27582. module.exports = __WEBPACK_EXTERNAL_MODULE__6__;
  27583. /***/ }),
  27584. /* 7 */
  27585. /***/ (function(module, exports) {
  27586. function _defineProperties(target, props) {
  27587. for (var i = 0; i < props.length; i++) {
  27588. var descriptor = props[i];
  27589. descriptor.enumerable = descriptor.enumerable || false;
  27590. descriptor.configurable = true;
  27591. if ("value" in descriptor) descriptor.writable = true;
  27592. Object.defineProperty(target, descriptor.key, descriptor);
  27593. }
  27594. }
  27595. function _createClass(Constructor, protoProps, staticProps) {
  27596. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  27597. if (staticProps) _defineProperties(Constructor, staticProps);
  27598. return Constructor;
  27599. }
  27600. module.exports = _createClass;
  27601. /***/ }),
  27602. /* 8 */
  27603. /***/ (function(module, exports, __webpack_require__) {
  27604. var _typeof = __webpack_require__(15);
  27605. var assertThisInitialized = __webpack_require__(1);
  27606. function _possibleConstructorReturn(self, call) {
  27607. if (call && (_typeof(call) === "object" || typeof call === "function")) {
  27608. return call;
  27609. }
  27610. return assertThisInitialized(self);
  27611. }
  27612. module.exports = _possibleConstructorReturn;
  27613. /***/ }),
  27614. /* 9 */
  27615. /***/ (function(module, exports) {
  27616. function _getPrototypeOf(o) {
  27617. module.exports = _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
  27618. return o.__proto__ || Object.getPrototypeOf(o);
  27619. };
  27620. return _getPrototypeOf(o);
  27621. }
  27622. module.exports = _getPrototypeOf;
  27623. /***/ }),
  27624. /* 10 */
  27625. /***/ (function(module, exports, __webpack_require__) {
  27626. var setPrototypeOf = __webpack_require__(26);
  27627. function _inherits(subClass, superClass) {
  27628. if (typeof superClass !== "function" && superClass !== null) {
  27629. throw new TypeError("Super expression must either be null or a function");
  27630. }
  27631. subClass.prototype = Object.create(superClass && superClass.prototype, {
  27632. constructor: {
  27633. value: subClass,
  27634. writable: true,
  27635. configurable: true
  27636. }
  27637. });
  27638. if (superClass) setPrototypeOf(subClass, superClass);
  27639. }
  27640. module.exports = _inherits;
  27641. /***/ }),
  27642. /* 11 */
  27643. /***/ (function(module, exports) {
  27644. function _extends() {
  27645. module.exports = _extends = Object.assign || function (target) {
  27646. for (var i = 1; i < arguments.length; i++) {
  27647. var source = arguments[i];
  27648. for (var key in source) {
  27649. if (Object.prototype.hasOwnProperty.call(source, key)) {
  27650. target[key] = source[key];
  27651. }
  27652. }
  27653. }
  27654. return target;
  27655. };
  27656. return _extends.apply(this, arguments);
  27657. }
  27658. module.exports = _extends;
  27659. /***/ }),
  27660. /* 12 */
  27661. /***/ (function(module, exports, __webpack_require__) {
  27662. var arrayWithoutHoles = __webpack_require__(27);
  27663. var iterableToArray = __webpack_require__(28);
  27664. var nonIterableSpread = __webpack_require__(29);
  27665. function _toConsumableArray(arr) {
  27666. return arrayWithoutHoles(arr) || iterableToArray(arr) || nonIterableSpread();
  27667. }
  27668. module.exports = _toConsumableArray;
  27669. /***/ }),
  27670. /* 13 */
  27671. /***/ (function(module, exports) {
  27672. module.exports = __WEBPACK_EXTERNAL_MODULE__13__;
  27673. /***/ }),
  27674. /* 14 */
  27675. /***/ (function(module, exports) {
  27676. module.exports = __WEBPACK_EXTERNAL_MODULE__14__;
  27677. /***/ }),
  27678. /* 15 */
  27679. /***/ (function(module, exports) {
  27680. function _typeof2(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof2 = function _typeof2(obj) { return typeof obj; }; } else { _typeof2 = function _typeof2(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof2(obj); }
  27681. function _typeof(obj) {
  27682. if (typeof Symbol === "function" && _typeof2(Symbol.iterator) === "symbol") {
  27683. module.exports = _typeof = function _typeof(obj) {
  27684. return _typeof2(obj);
  27685. };
  27686. } else {
  27687. module.exports = _typeof = function _typeof(obj) {
  27688. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : _typeof2(obj);
  27689. };
  27690. }
  27691. return _typeof(obj);
  27692. }
  27693. module.exports = _typeof;
  27694. /***/ }),
  27695. /* 16 */
  27696. /***/ (function(module, exports) {
  27697. module.exports = __WEBPACK_EXTERNAL_MODULE__16__;
  27698. /***/ }),
  27699. /* 17 */
  27700. /***/ (function(module, exports) {
  27701. module.exports = __WEBPACK_EXTERNAL_MODULE__17__;
  27702. /***/ }),
  27703. /* 18 */
  27704. /***/ (function(module, exports, __webpack_require__) {
  27705. var Immutable = __webpack_require__(13);
  27706. var KEY_SEPARATOR = '-';
  27707. function MultiDecorator(decorators) {
  27708. this.decorators = Immutable.List(decorators);
  27709. }
  27710. /**
  27711. Return list of decoration IDs per character
  27712. @param {ContentBlock}
  27713. @return {List<String>}
  27714. */
  27715. MultiDecorator.prototype.getDecorations = function(block) {
  27716. var decorations = Array(block.getText().length).fill(null);
  27717. this.decorators.forEach(function(decorator, i) {
  27718. var _decorations = decorator.getDecorations(block);
  27719. _decorations.forEach(function(key, offset) {
  27720. if (!key) {
  27721. return;
  27722. }
  27723. key = i + KEY_SEPARATOR + key;
  27724. decorations[offset] = key;
  27725. });
  27726. });
  27727. return Immutable.List(decorations);
  27728. };
  27729. /**
  27730. Return component to render a decoration
  27731. @param {String}
  27732. @return {Function}
  27733. */
  27734. MultiDecorator.prototype.getComponentForKey = function(key) {
  27735. var decorator = this.getDecoratorForKey(key);
  27736. return decorator.getComponentForKey(
  27737. this.getInnerKey(key)
  27738. );
  27739. };
  27740. /**
  27741. Return props to render a decoration
  27742. @param {String}
  27743. @return {Object}
  27744. */
  27745. MultiDecorator.prototype.getPropsForKey = function(key) {
  27746. var decorator = this.getDecoratorForKey(key);
  27747. return decorator.getPropsForKey(
  27748. this.getInnerKey(key)
  27749. );
  27750. };
  27751. /**
  27752. Return a decorator for a specific key
  27753. @param {String}
  27754. @return {Decorator}
  27755. */
  27756. MultiDecorator.prototype.getDecoratorForKey = function(key) {
  27757. var parts = key.split(KEY_SEPARATOR);
  27758. var index = Number(parts[0]);
  27759. return this.decorators.get(index);
  27760. };
  27761. /**
  27762. Return inner key for a decorator
  27763. @param {String}
  27764. @return {String}
  27765. */
  27766. MultiDecorator.prototype.getInnerKey = function(key) {
  27767. var parts = key.split(KEY_SEPARATOR);
  27768. return parts.slice(1).join(KEY_SEPARATOR);
  27769. };
  27770. module.exports = MultiDecorator;
  27771. /***/ }),
  27772. /* 19 */
  27773. /***/ (function(module, exports, __webpack_require__) {
  27774. /**
  27775. * Copyright (c) 2013-present, Facebook, Inc.
  27776. * All rights reserved.
  27777. *
  27778. * This source code is licensed under the BSD-style license found in the
  27779. * LICENSE file in the root directory of this source tree. An additional grant
  27780. * of patent rights can be found in the PATENTS file in the same directory.
  27781. *
  27782. * @providesModule CharacterMetadata
  27783. * @format
  27784. *
  27785. */
  27786. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  27787. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  27788. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  27789. var _require = __webpack_require__(13),
  27790. Map = _require.Map,
  27791. OrderedSet = _require.OrderedSet,
  27792. Record = _require.Record;
  27793. // Immutable.map is typed such that the value for every key in the map
  27794. // must be the same type
  27795. var EMPTY_SET = OrderedSet();
  27796. var defaultRecord = {
  27797. style: EMPTY_SET,
  27798. entity: null
  27799. };
  27800. var CharacterMetadataRecord = Record(defaultRecord);
  27801. var CharacterMetadata = function (_CharacterMetadataRec) {
  27802. _inherits(CharacterMetadata, _CharacterMetadataRec);
  27803. function CharacterMetadata() {
  27804. _classCallCheck(this, CharacterMetadata);
  27805. return _possibleConstructorReturn(this, _CharacterMetadataRec.apply(this, arguments));
  27806. }
  27807. CharacterMetadata.prototype.getStyle = function getStyle() {
  27808. return this.get('style');
  27809. };
  27810. CharacterMetadata.prototype.getEntity = function getEntity() {
  27811. return this.get('entity');
  27812. };
  27813. CharacterMetadata.prototype.hasStyle = function hasStyle(style) {
  27814. return this.getStyle().includes(style);
  27815. };
  27816. CharacterMetadata.applyStyle = function applyStyle(record, style) {
  27817. var withStyle = record.set('style', record.getStyle().add(style));
  27818. return CharacterMetadata.create(withStyle);
  27819. };
  27820. CharacterMetadata.removeStyle = function removeStyle(record, style) {
  27821. var withoutStyle = record.set('style', record.getStyle().remove(style));
  27822. return CharacterMetadata.create(withoutStyle);
  27823. };
  27824. CharacterMetadata.applyEntity = function applyEntity(record, entityKey) {
  27825. var withEntity = record.getEntity() === entityKey ? record : record.set('entity', entityKey);
  27826. return CharacterMetadata.create(withEntity);
  27827. };
  27828. /**
  27829. * Use this function instead of the `CharacterMetadata` constructor.
  27830. * Since most content generally uses only a very small number of
  27831. * style/entity permutations, we can reuse these objects as often as
  27832. * possible.
  27833. */
  27834. CharacterMetadata.create = function create(config) {
  27835. if (!config) {
  27836. return EMPTY;
  27837. }
  27838. var defaultConfig = {
  27839. style: EMPTY_SET,
  27840. entity: null
  27841. };
  27842. // Fill in unspecified properties, if necessary.
  27843. var configMap = Map(defaultConfig).merge(config);
  27844. var existing = pool.get(configMap);
  27845. if (existing) {
  27846. return existing;
  27847. }
  27848. var newCharacter = new CharacterMetadata(configMap);
  27849. pool = pool.set(configMap, newCharacter);
  27850. return newCharacter;
  27851. };
  27852. return CharacterMetadata;
  27853. }(CharacterMetadataRecord);
  27854. var EMPTY = new CharacterMetadata();
  27855. var pool = Map([[Map(defaultRecord), EMPTY]]);
  27856. CharacterMetadata.EMPTY = EMPTY;
  27857. module.exports = CharacterMetadata;
  27858. /***/ }),
  27859. /* 20 */
  27860. /***/ (function(module, exports, __webpack_require__) {
  27861. /**
  27862. * Copyright (c) 2013-present, Facebook, Inc.
  27863. * All rights reserved.
  27864. *
  27865. * This source code is licensed under the BSD-style license found in the
  27866. * LICENSE file in the root directory of this source tree. An additional grant
  27867. * of patent rights can be found in the PATENTS file in the same directory.
  27868. *
  27869. * @providesModule findRangesImmutable
  27870. * @format
  27871. *
  27872. */
  27873. /**
  27874. * Search through an array to find contiguous stretches of elements that
  27875. * match a specified filter function.
  27876. *
  27877. * When ranges are found, execute a specified `found` function to supply
  27878. * the values to the caller.
  27879. */
  27880. function findRangesImmutable(haystack, areEqualFn, filterFn, foundFn) {
  27881. if (!haystack.size) {
  27882. return;
  27883. }
  27884. var cursor = 0;
  27885. haystack.reduce(function (value, nextValue, nextIndex) {
  27886. if (!areEqualFn(value, nextValue)) {
  27887. if (filterFn(value)) {
  27888. foundFn(cursor, nextIndex);
  27889. }
  27890. cursor = nextIndex;
  27891. }
  27892. return nextValue;
  27893. });
  27894. filterFn(haystack.last()) && foundFn(cursor, haystack.count());
  27895. }
  27896. module.exports = findRangesImmutable;
  27897. /***/ }),
  27898. /* 21 */
  27899. /***/ (function(module, exports, __webpack_require__) {
  27900. var objectWithoutPropertiesLoose = __webpack_require__(25);
  27901. function _objectWithoutProperties(source, excluded) {
  27902. if (source == null) return {};
  27903. var target = objectWithoutPropertiesLoose(source, excluded);
  27904. var key, i;
  27905. if (Object.getOwnPropertySymbols) {
  27906. var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
  27907. for (i = 0; i < sourceSymbolKeys.length; i++) {
  27908. key = sourceSymbolKeys[i];
  27909. if (excluded.indexOf(key) >= 0) continue;
  27910. if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
  27911. target[key] = source[key];
  27912. }
  27913. }
  27914. return target;
  27915. }
  27916. module.exports = _objectWithoutProperties;
  27917. /***/ }),
  27918. /* 22 */
  27919. /***/ (function(module, exports, __webpack_require__) {
  27920. /**
  27921. * Copyright (c) 2013-present, Facebook, Inc.
  27922. * All rights reserved.
  27923. *
  27924. * This source code is licensed under the BSD-style license found in the
  27925. * LICENSE file in the root directory of this source tree. An additional grant
  27926. * of patent rights can be found in the PATENTS file in the same directory.
  27927. *
  27928. * @providesModule getFragmentFromSelection
  27929. * @format
  27930. *
  27931. */
  27932. var getContentStateFragment = __webpack_require__(30);
  27933. function getFragmentFromSelection(editorState) {
  27934. var selectionState = editorState.getSelection();
  27935. if (selectionState.isCollapsed()) {
  27936. return null;
  27937. }
  27938. return getContentStateFragment(editorState.getCurrentContent(), selectionState);
  27939. }
  27940. module.exports = getFragmentFromSelection;
  27941. /***/ }),
  27942. /* 23 */
  27943. /***/ (function(module, exports) {
  27944. module.exports = __WEBPACK_EXTERNAL_MODULE__23__;
  27945. /***/ }),
  27946. /* 24 */
  27947. /***/ (function(module, exports, __webpack_require__) {
  27948. var arrayWithHoles = __webpack_require__(36);
  27949. var iterableToArrayLimit = __webpack_require__(37);
  27950. var nonIterableRest = __webpack_require__(38);
  27951. function _slicedToArray(arr, i) {
  27952. return arrayWithHoles(arr) || iterableToArrayLimit(arr, i) || nonIterableRest();
  27953. }
  27954. module.exports = _slicedToArray;
  27955. /***/ }),
  27956. /* 25 */
  27957. /***/ (function(module, exports) {
  27958. function _objectWithoutPropertiesLoose(source, excluded) {
  27959. if (source == null) return {};
  27960. var target = {};
  27961. var sourceKeys = Object.keys(source);
  27962. var key, i;
  27963. for (i = 0; i < sourceKeys.length; i++) {
  27964. key = sourceKeys[i];
  27965. if (excluded.indexOf(key) >= 0) continue;
  27966. target[key] = source[key];
  27967. }
  27968. return target;
  27969. }
  27970. module.exports = _objectWithoutPropertiesLoose;
  27971. /***/ }),
  27972. /* 26 */
  27973. /***/ (function(module, exports) {
  27974. function _setPrototypeOf(o, p) {
  27975. module.exports = _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  27976. o.__proto__ = p;
  27977. return o;
  27978. };
  27979. return _setPrototypeOf(o, p);
  27980. }
  27981. module.exports = _setPrototypeOf;
  27982. /***/ }),
  27983. /* 27 */
  27984. /***/ (function(module, exports) {
  27985. function _arrayWithoutHoles(arr) {
  27986. if (Array.isArray(arr)) {
  27987. for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {
  27988. arr2[i] = arr[i];
  27989. }
  27990. return arr2;
  27991. }
  27992. }
  27993. module.exports = _arrayWithoutHoles;
  27994. /***/ }),
  27995. /* 28 */
  27996. /***/ (function(module, exports) {
  27997. function _iterableToArray(iter) {
  27998. if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
  27999. }
  28000. module.exports = _iterableToArray;
  28001. /***/ }),
  28002. /* 29 */
  28003. /***/ (function(module, exports) {
  28004. function _nonIterableSpread() {
  28005. throw new TypeError("Invalid attempt to spread non-iterable instance");
  28006. }
  28007. module.exports = _nonIterableSpread;
  28008. /***/ }),
  28009. /* 30 */
  28010. /***/ (function(module, exports, __webpack_require__) {
  28011. /**
  28012. * Copyright (c) 2013-present, Facebook, Inc.
  28013. * All rights reserved.
  28014. *
  28015. * This source code is licensed under the BSD-style license found in the
  28016. * LICENSE file in the root directory of this source tree. An additional grant
  28017. * of patent rights can be found in the PATENTS file in the same directory.
  28018. *
  28019. * @providesModule getContentStateFragment
  28020. * @format
  28021. *
  28022. */
  28023. var randomizeBlockMapKeys = __webpack_require__(31);
  28024. var removeEntitiesAtEdges = __webpack_require__(34);
  28025. var getContentStateFragment = function getContentStateFragment(contentState, selectionState) {
  28026. var startKey = selectionState.getStartKey();
  28027. var startOffset = selectionState.getStartOffset();
  28028. var endKey = selectionState.getEndKey();
  28029. var endOffset = selectionState.getEndOffset();
  28030. // Edge entities should be stripped to ensure that we don't preserve
  28031. // invalid partial entities when the fragment is reused. We do, however,
  28032. // preserve entities that are entirely within the selection range.
  28033. var contentWithoutEdgeEntities = removeEntitiesAtEdges(contentState, selectionState);
  28034. var blockMap = contentWithoutEdgeEntities.getBlockMap();
  28035. var blockKeys = blockMap.keySeq();
  28036. var startIndex = blockKeys.indexOf(startKey);
  28037. var endIndex = blockKeys.indexOf(endKey) + 1;
  28038. return randomizeBlockMapKeys(blockMap.slice(startIndex, endIndex).map(function (block, blockKey) {
  28039. var text = block.getText();
  28040. var chars = block.getCharacterList();
  28041. if (startKey === endKey) {
  28042. return block.merge({
  28043. text: text.slice(startOffset, endOffset),
  28044. characterList: chars.slice(startOffset, endOffset)
  28045. });
  28046. }
  28047. if (blockKey === startKey) {
  28048. return block.merge({
  28049. text: text.slice(startOffset),
  28050. characterList: chars.slice(startOffset)
  28051. });
  28052. }
  28053. if (blockKey === endKey) {
  28054. return block.merge({
  28055. text: text.slice(0, endOffset),
  28056. characterList: chars.slice(0, endOffset)
  28057. });
  28058. }
  28059. return block;
  28060. }));
  28061. };
  28062. module.exports = getContentStateFragment;
  28063. /***/ }),
  28064. /* 31 */
  28065. /***/ (function(module, exports, __webpack_require__) {
  28066. /**
  28067. * Copyright (c) 2013-present, Facebook, Inc.
  28068. * All rights reserved.
  28069. *
  28070. * This source code is licensed under the BSD-style license found in the
  28071. * LICENSE file in the root directory of this source tree. An additional grant
  28072. * of patent rights can be found in the PATENTS file in the same directory.
  28073. *
  28074. * @providesModule randomizeBlockMapKeys
  28075. * @format
  28076. *
  28077. */
  28078. var ContentBlockNode = __webpack_require__(32);
  28079. var Immutable = __webpack_require__(13);
  28080. var generateRandomKey = __webpack_require__(33);
  28081. var OrderedMap = Immutable.OrderedMap;
  28082. var randomizeContentBlockNodeKeys = function randomizeContentBlockNodeKeys(blockMap) {
  28083. var newKeysRef = {};
  28084. // we keep track of root blocks in order to update subsequent sibling links
  28085. var lastRootBlock = void 0;
  28086. return OrderedMap(blockMap.withMutations(function (blockMapState) {
  28087. blockMapState.forEach(function (block, index) {
  28088. var oldKey = block.getKey();
  28089. var nextKey = block.getNextSiblingKey();
  28090. var prevKey = block.getPrevSiblingKey();
  28091. var childrenKeys = block.getChildKeys();
  28092. var parentKey = block.getParentKey();
  28093. // new key that we will use to build linking
  28094. var key = generateRandomKey();
  28095. // we will add it here to re-use it later
  28096. newKeysRef[oldKey] = key;
  28097. if (nextKey) {
  28098. var nextBlock = blockMapState.get(nextKey);
  28099. if (nextBlock) {
  28100. blockMapState.setIn([nextKey, 'prevSibling'], key);
  28101. } else {
  28102. // this can happen when generating random keys for fragments
  28103. blockMapState.setIn([oldKey, 'nextSibling'], null);
  28104. }
  28105. }
  28106. if (prevKey) {
  28107. var prevBlock = blockMapState.get(prevKey);
  28108. if (prevBlock) {
  28109. blockMapState.setIn([prevKey, 'nextSibling'], key);
  28110. } else {
  28111. // this can happen when generating random keys for fragments
  28112. blockMapState.setIn([oldKey, 'prevSibling'], null);
  28113. }
  28114. }
  28115. if (parentKey && blockMapState.get(parentKey)) {
  28116. var parentBlock = blockMapState.get(parentKey);
  28117. var parentChildrenList = parentBlock.getChildKeys();
  28118. blockMapState.setIn([parentKey, 'children'], parentChildrenList.set(parentChildrenList.indexOf(block.getKey()), key));
  28119. } else {
  28120. // blocks will then be treated as root block nodes
  28121. blockMapState.setIn([oldKey, 'parent'], null);
  28122. if (lastRootBlock) {
  28123. blockMapState.setIn([lastRootBlock.getKey(), 'nextSibling'], key);
  28124. blockMapState.setIn([oldKey, 'prevSibling'], newKeysRef[lastRootBlock.getKey()]);
  28125. }
  28126. lastRootBlock = blockMapState.get(oldKey);
  28127. }
  28128. childrenKeys.forEach(function (childKey) {
  28129. var childBlock = blockMapState.get(childKey);
  28130. if (childBlock) {
  28131. blockMapState.setIn([childKey, 'parent'], key);
  28132. } else {
  28133. blockMapState.setIn([oldKey, 'children'], block.getChildKeys().filter(function (child) {
  28134. return child !== childKey;
  28135. }));
  28136. }
  28137. });
  28138. });
  28139. }).toArray().map(function (block) {
  28140. return [newKeysRef[block.getKey()], block.set('key', newKeysRef[block.getKey()])];
  28141. }));
  28142. };
  28143. var randomizeContentBlockKeys = function randomizeContentBlockKeys(blockMap) {
  28144. return OrderedMap(blockMap.toArray().map(function (block) {
  28145. var key = generateRandomKey();
  28146. return [key, block.set('key', key)];
  28147. }));
  28148. };
  28149. var randomizeBlockMapKeys = function randomizeBlockMapKeys(blockMap) {
  28150. var isTreeBasedBlockMap = blockMap.first() instanceof ContentBlockNode;
  28151. if (!isTreeBasedBlockMap) {
  28152. return randomizeContentBlockKeys(blockMap);
  28153. }
  28154. return randomizeContentBlockNodeKeys(blockMap);
  28155. };
  28156. module.exports = randomizeBlockMapKeys;
  28157. /***/ }),
  28158. /* 32 */
  28159. /***/ (function(module, exports, __webpack_require__) {
  28160. /**
  28161. * Copyright (c) 2013-present, Facebook, Inc.
  28162. * All rights reserved.
  28163. *
  28164. * This source code is licensed under the BSD-style license found in the
  28165. * LICENSE file in the root directory of this source tree. An additional grant
  28166. * of patent rights can be found in the PATENTS file in the same directory.
  28167. *
  28168. * @providesModule ContentBlockNode
  28169. * @format
  28170. *
  28171. *
  28172. * This file is a fork of ContentBlock adding support for nesting references by
  28173. * providing links to children, parent, prevSibling, and nextSibling.
  28174. *
  28175. * This is unstable and not part of the public API and should not be used by
  28176. * production systems. This file may be update/removed without notice.
  28177. */
  28178. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  28179. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  28180. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  28181. var CharacterMetadata = __webpack_require__(19);
  28182. var Immutable = __webpack_require__(13);
  28183. var findRangesImmutable = __webpack_require__(20);
  28184. var List = Immutable.List,
  28185. Map = Immutable.Map,
  28186. OrderedSet = Immutable.OrderedSet,
  28187. Record = Immutable.Record,
  28188. Repeat = Immutable.Repeat;
  28189. var EMPTY_SET = OrderedSet();
  28190. var defaultRecord = {
  28191. parent: null,
  28192. characterList: List(),
  28193. data: Map(),
  28194. depth: 0,
  28195. key: '',
  28196. text: '',
  28197. type: 'unstyled',
  28198. children: List(),
  28199. prevSibling: null,
  28200. nextSibling: null
  28201. };
  28202. var haveEqualStyle = function haveEqualStyle(charA, charB) {
  28203. return charA.getStyle() === charB.getStyle();
  28204. };
  28205. var haveEqualEntity = function haveEqualEntity(charA, charB) {
  28206. return charA.getEntity() === charB.getEntity();
  28207. };
  28208. var decorateCharacterList = function decorateCharacterList(config) {
  28209. if (!config) {
  28210. return config;
  28211. }
  28212. var characterList = config.characterList,
  28213. text = config.text;
  28214. if (text && !characterList) {
  28215. config.characterList = List(Repeat(CharacterMetadata.EMPTY, text.length));
  28216. }
  28217. return config;
  28218. };
  28219. var ContentBlockNode = function (_Record) {
  28220. _inherits(ContentBlockNode, _Record);
  28221. function ContentBlockNode() {
  28222. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultRecord;
  28223. _classCallCheck(this, ContentBlockNode);
  28224. return _possibleConstructorReturn(this, _Record.call(this, decorateCharacterList(props)));
  28225. }
  28226. ContentBlockNode.prototype.getKey = function getKey() {
  28227. return this.get('key');
  28228. };
  28229. ContentBlockNode.prototype.getType = function getType() {
  28230. return this.get('type');
  28231. };
  28232. ContentBlockNode.prototype.getText = function getText() {
  28233. return this.get('text');
  28234. };
  28235. ContentBlockNode.prototype.getCharacterList = function getCharacterList() {
  28236. return this.get('characterList');
  28237. };
  28238. ContentBlockNode.prototype.getLength = function getLength() {
  28239. return this.getText().length;
  28240. };
  28241. ContentBlockNode.prototype.getDepth = function getDepth() {
  28242. return this.get('depth');
  28243. };
  28244. ContentBlockNode.prototype.getData = function getData() {
  28245. return this.get('data');
  28246. };
  28247. ContentBlockNode.prototype.getInlineStyleAt = function getInlineStyleAt(offset) {
  28248. var character = this.getCharacterList().get(offset);
  28249. return character ? character.getStyle() : EMPTY_SET;
  28250. };
  28251. ContentBlockNode.prototype.getEntityAt = function getEntityAt(offset) {
  28252. var character = this.getCharacterList().get(offset);
  28253. return character ? character.getEntity() : null;
  28254. };
  28255. ContentBlockNode.prototype.getChildKeys = function getChildKeys() {
  28256. return this.get('children');
  28257. };
  28258. ContentBlockNode.prototype.getParentKey = function getParentKey() {
  28259. return this.get('parent');
  28260. };
  28261. ContentBlockNode.prototype.getPrevSiblingKey = function getPrevSiblingKey() {
  28262. return this.get('prevSibling');
  28263. };
  28264. ContentBlockNode.prototype.getNextSiblingKey = function getNextSiblingKey() {
  28265. return this.get('nextSibling');
  28266. };
  28267. ContentBlockNode.prototype.findStyleRanges = function findStyleRanges(filterFn, callback) {
  28268. findRangesImmutable(this.getCharacterList(), haveEqualStyle, filterFn, callback);
  28269. };
  28270. ContentBlockNode.prototype.findEntityRanges = function findEntityRanges(filterFn, callback) {
  28271. findRangesImmutable(this.getCharacterList(), haveEqualEntity, filterFn, callback);
  28272. };
  28273. return ContentBlockNode;
  28274. }(Record(defaultRecord));
  28275. module.exports = ContentBlockNode;
  28276. /***/ }),
  28277. /* 33 */
  28278. /***/ (function(module, exports, __webpack_require__) {
  28279. /**
  28280. * Copyright (c) 2013-present, Facebook, Inc.
  28281. * All rights reserved.
  28282. *
  28283. * This source code is licensed under the BSD-style license found in the
  28284. * LICENSE file in the root directory of this source tree. An additional grant
  28285. * of patent rights can be found in the PATENTS file in the same directory.
  28286. *
  28287. * @providesModule generateRandomKey
  28288. * @format
  28289. *
  28290. */
  28291. var seenKeys = {};
  28292. var MULTIPLIER = Math.pow(2, 24);
  28293. function generateRandomKey() {
  28294. var key = void 0;
  28295. while (key === undefined || seenKeys.hasOwnProperty(key) || !isNaN(+key)) {
  28296. key = Math.floor(Math.random() * MULTIPLIER).toString(32);
  28297. }
  28298. seenKeys[key] = true;
  28299. return key;
  28300. }
  28301. module.exports = generateRandomKey;
  28302. /***/ }),
  28303. /* 34 */
  28304. /***/ (function(module, exports, __webpack_require__) {
  28305. /**
  28306. * Copyright (c) 2013-present, Facebook, Inc.
  28307. * All rights reserved.
  28308. *
  28309. * This source code is licensed under the BSD-style license found in the
  28310. * LICENSE file in the root directory of this source tree. An additional grant
  28311. * of patent rights can be found in the PATENTS file in the same directory.
  28312. *
  28313. * @providesModule removeEntitiesAtEdges
  28314. * @format
  28315. *
  28316. */
  28317. var CharacterMetadata = __webpack_require__(19);
  28318. var findRangesImmutable = __webpack_require__(20);
  28319. var invariant = __webpack_require__(35);
  28320. function removeEntitiesAtEdges(contentState, selectionState) {
  28321. var blockMap = contentState.getBlockMap();
  28322. var entityMap = contentState.getEntityMap();
  28323. var updatedBlocks = {};
  28324. var startKey = selectionState.getStartKey();
  28325. var startOffset = selectionState.getStartOffset();
  28326. var startBlock = blockMap.get(startKey);
  28327. var updatedStart = removeForBlock(entityMap, startBlock, startOffset);
  28328. if (updatedStart !== startBlock) {
  28329. updatedBlocks[startKey] = updatedStart;
  28330. }
  28331. var endKey = selectionState.getEndKey();
  28332. var endOffset = selectionState.getEndOffset();
  28333. var endBlock = blockMap.get(endKey);
  28334. if (startKey === endKey) {
  28335. endBlock = updatedStart;
  28336. }
  28337. var updatedEnd = removeForBlock(entityMap, endBlock, endOffset);
  28338. if (updatedEnd !== endBlock) {
  28339. updatedBlocks[endKey] = updatedEnd;
  28340. }
  28341. if (!Object.keys(updatedBlocks).length) {
  28342. return contentState.set('selectionAfter', selectionState);
  28343. }
  28344. return contentState.merge({
  28345. blockMap: blockMap.merge(updatedBlocks),
  28346. selectionAfter: selectionState
  28347. });
  28348. }
  28349. function getRemovalRange(characters, key, offset) {
  28350. var removalRange;
  28351. findRangesImmutable(characters, function (a, b) {
  28352. return a.getEntity() === b.getEntity();
  28353. }, function (element) {
  28354. return element.getEntity() === key;
  28355. }, function (start, end) {
  28356. if (start <= offset && end >= offset) {
  28357. removalRange = { start: start, end: end };
  28358. }
  28359. });
  28360. !(typeof removalRange === 'object') ? invariant(false) : void 0;
  28361. return removalRange;
  28362. }
  28363. function removeForBlock(entityMap, block, offset) {
  28364. var chars = block.getCharacterList();
  28365. var charBefore = offset > 0 ? chars.get(offset - 1) : undefined;
  28366. var charAfter = offset < chars.count() ? chars.get(offset) : undefined;
  28367. var entityBeforeCursor = charBefore ? charBefore.getEntity() : undefined;
  28368. var entityAfterCursor = charAfter ? charAfter.getEntity() : undefined;
  28369. if (entityAfterCursor && entityAfterCursor === entityBeforeCursor) {
  28370. var entity = entityMap.__get(entityAfterCursor);
  28371. if (entity.getMutability() !== 'MUTABLE') {
  28372. var _getRemovalRange = getRemovalRange(chars, entityAfterCursor, offset),
  28373. start = _getRemovalRange.start,
  28374. end = _getRemovalRange.end;
  28375. var current;
  28376. while (start < end) {
  28377. current = chars.get(start);
  28378. chars = chars.set(start, CharacterMetadata.applyEntity(current, null));
  28379. start++;
  28380. }
  28381. return block.set('characterList', chars);
  28382. }
  28383. }
  28384. return block;
  28385. }
  28386. module.exports = removeEntitiesAtEdges;
  28387. /***/ }),
  28388. /* 35 */
  28389. /***/ (function(module, exports, __webpack_require__) {
  28390. function invariant(condition, format, a, b, c, d, e, f) {
  28391. if (!condition) {
  28392. var error;
  28393. if (format === undefined) {
  28394. error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
  28395. } else {
  28396. var args = [a, b, c, d, e, f];
  28397. var argIndex = 0;
  28398. error = new Error(format.replace(/%s/g, function () {
  28399. return args[argIndex++];
  28400. }));
  28401. error.name = 'Invariant Violation';
  28402. }
  28403. error.framesToPop = 1; // we don't care about invariant's own frame
  28404. throw error;
  28405. }
  28406. }
  28407. module.exports = invariant;
  28408. /***/ }),
  28409. /* 36 */
  28410. /***/ (function(module, exports) {
  28411. function _arrayWithHoles(arr) {
  28412. if (Array.isArray(arr)) return arr;
  28413. }
  28414. module.exports = _arrayWithHoles;
  28415. /***/ }),
  28416. /* 37 */
  28417. /***/ (function(module, exports) {
  28418. function _iterableToArrayLimit(arr, i) {
  28419. var _arr = [];
  28420. var _n = true;
  28421. var _d = false;
  28422. var _e = undefined;
  28423. try {
  28424. for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
  28425. _arr.push(_s.value);
  28426. if (i && _arr.length === i) break;
  28427. }
  28428. } catch (err) {
  28429. _d = true;
  28430. _e = err;
  28431. } finally {
  28432. try {
  28433. if (!_n && _i["return"] != null) _i["return"]();
  28434. } finally {
  28435. if (_d) throw _e;
  28436. }
  28437. }
  28438. return _arr;
  28439. }
  28440. module.exports = _iterableToArrayLimit;
  28441. /***/ }),
  28442. /* 38 */
  28443. /***/ (function(module, exports) {
  28444. function _nonIterableRest() {
  28445. throw new TypeError("Invalid attempt to destructure non-iterable instance");
  28446. }
  28447. module.exports = _nonIterableRest;
  28448. /***/ }),
  28449. /* 39 */
  28450. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  28451. __webpack_require__.r(__webpack_exports__);
  28452. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/typeof.js
  28453. var helpers_typeof = __webpack_require__(15);
  28454. var typeof_default = /*#__PURE__*/__webpack_require__.n(helpers_typeof);
  28455. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/objectSpread.js
  28456. var objectSpread = __webpack_require__(5);
  28457. var objectSpread_default = /*#__PURE__*/__webpack_require__.n(objectSpread);
  28458. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/objectWithoutProperties.js
  28459. var objectWithoutProperties = __webpack_require__(21);
  28460. var objectWithoutProperties_default = /*#__PURE__*/__webpack_require__.n(objectWithoutProperties);
  28461. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/classCallCheck.js
  28462. var classCallCheck = __webpack_require__(4);
  28463. var classCallCheck_default = /*#__PURE__*/__webpack_require__.n(classCallCheck);
  28464. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/createClass.js
  28465. var createClass = __webpack_require__(7);
  28466. var createClass_default = /*#__PURE__*/__webpack_require__.n(createClass);
  28467. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js
  28468. var possibleConstructorReturn = __webpack_require__(8);
  28469. var possibleConstructorReturn_default = /*#__PURE__*/__webpack_require__.n(possibleConstructorReturn);
  28470. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/getPrototypeOf.js
  28471. var getPrototypeOf = __webpack_require__(9);
  28472. var getPrototypeOf_default = /*#__PURE__*/__webpack_require__.n(getPrototypeOf);
  28473. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/inherits.js
  28474. var inherits = __webpack_require__(10);
  28475. var inherits_default = /*#__PURE__*/__webpack_require__.n(inherits);
  28476. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/assertThisInitialized.js
  28477. var assertThisInitialized = __webpack_require__(1);
  28478. var assertThisInitialized_default = /*#__PURE__*/__webpack_require__.n(assertThisInitialized);
  28479. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/defineProperty.js
  28480. var defineProperty = __webpack_require__(2);
  28481. var defineProperty_default = /*#__PURE__*/__webpack_require__.n(defineProperty);
  28482. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/toConsumableArray.js
  28483. var toConsumableArray = __webpack_require__(12);
  28484. var toConsumableArray_default = /*#__PURE__*/__webpack_require__.n(toConsumableArray);
  28485. // EXTERNAL MODULE: ../node_modules/draft-js/dist/Draft.css
  28486. var Draft = __webpack_require__(40);
  28487. // EXTERNAL MODULE: ./assets/scss/_base.scss
  28488. var _base = __webpack_require__(42);
  28489. // EXTERNAL MODULE: external "react"
  28490. var external_react_ = __webpack_require__(0);
  28491. var external_react_default = /*#__PURE__*/__webpack_require__.n(external_react_);
  28492. // CONCATENATED MODULE: ./languages/en.js
  28493. /* harmony default export */ var en = ({
  28494. base: {
  28495. remove: 'Remove',
  28496. cancel: 'Cancel',
  28497. confirm: 'Confirm',
  28498. inert: 'Insert',
  28499. width: 'Width',
  28500. height: 'Height'
  28501. },
  28502. controls: {
  28503. clear: 'Clear',
  28504. undo: 'Undo',
  28505. redo: 'Redo',
  28506. fontSize: 'Font Size',
  28507. color: 'Color',
  28508. textColor: 'Text',
  28509. tempColors: 'Temp Colors',
  28510. backgroundColor: 'Background',
  28511. bold: 'Bold',
  28512. lineHeight: 'Line Height',
  28513. letterSpacing: 'Letter Spacing',
  28514. textIndent: 'Text Indent',
  28515. increaseIndent: 'Increase Indent',
  28516. decreaseIndent: 'Decrease Indent',
  28517. italic: 'Italic',
  28518. underline: 'Underline',
  28519. strikeThrough: 'Strike Through',
  28520. fontFamily: 'Font Family',
  28521. textAlign: 'Text Alignment',
  28522. alignLeft: 'Left Alignment',
  28523. alignCenter: 'Center Alignment',
  28524. alignRight: 'Right Alignment',
  28525. alignJustify: 'Justify Alignment',
  28526. floatLeft: 'Left Float',
  28527. floatRight: 'Right Float',
  28528. superScript: 'Super Script',
  28529. subScript: 'Sub Script',
  28530. removeStyles: 'Remove Styles',
  28531. headings: 'Headings',
  28532. header: 'Header',
  28533. normal: 'Normal',
  28534. orderedList: 'Ordered List',
  28535. unorderedList: 'Unordered List',
  28536. blockQuote: 'Quote',
  28537. code: 'Code',
  28538. link: 'Link',
  28539. unlink: 'Unlink',
  28540. hr: 'Horizontal Line',
  28541. media: 'Media',
  28542. mediaLibirary: 'Media Library',
  28543. emoji: 'Emoji',
  28544. fullscreen: 'Fullscreen',
  28545. exitFullscreen: 'Exit Fullscreen'
  28546. },
  28547. linkEditor: {
  28548. textInputPlaceHolder: 'Input link text',
  28549. linkInputPlaceHolder: 'Input link URL',
  28550. inputWithEnterPlaceHolder: 'Input link URL and press Enter',
  28551. openInNewWindow: 'Open in new window',
  28552. removeLink: 'Remove Link'
  28553. },
  28554. audioPlayer: {
  28555. title: 'Play Audio'
  28556. },
  28557. videoPlayer: {
  28558. title: 'Play Video',
  28559. embedTitle: 'Embed Media'
  28560. },
  28561. media: {
  28562. image: 'Image',
  28563. video: 'Video',
  28564. audio: 'Audio',
  28565. embed: 'Embed'
  28566. }
  28567. });
  28568. // CONCATENATED MODULE: ./languages/zh.js
  28569. /* harmony default export */ var zh = ({
  28570. base: {
  28571. remove: '删除',
  28572. cancel: '取消',
  28573. confirm: '确定',
  28574. inert: '插入',
  28575. width: '宽度',
  28576. height: '高度'
  28577. },
  28578. controls: {
  28579. clear: '清除内容',
  28580. undo: '撤销',
  28581. redo: '重做',
  28582. fontSize: '字号',
  28583. lineHeight: '行高',
  28584. letterSpacing: '字间距',
  28585. textIndent: '段落缩进',
  28586. increaseIndent: '增加缩进',
  28587. decreaseIndent: '减少缩进',
  28588. border: '边框',
  28589. color: '颜色',
  28590. textColor: '文字颜色',
  28591. backgroundColor: '背景颜色',
  28592. tempColors: '临时颜色',
  28593. bold: '加粗',
  28594. italic: '斜体',
  28595. underline: '下划线',
  28596. strikeThrough: '删除线',
  28597. fontFamily: '字体',
  28598. textAlign: '文本对齐',
  28599. alignLeft: '居左',
  28600. alignCenter: '居中',
  28601. alignRight: '居右',
  28602. alignJustify: '两端',
  28603. floatLeft: '左浮动',
  28604. floatRight: '右浮动',
  28605. superScript: '上标',
  28606. subScript: '下标',
  28607. removeStyles: '清除样式',
  28608. headings: '标题',
  28609. header: '标题',
  28610. normal: '常规',
  28611. orderedList: '有序列表',
  28612. unorderedList: '无序列表',
  28613. blockQuote: '引用',
  28614. code: '代码',
  28615. link: '链接',
  28616. unlink: '清除链接',
  28617. hr: '水平线',
  28618. media: '媒体',
  28619. mediaLibirary: '媒体库',
  28620. emoji: '小表情',
  28621. fullscreen: '全屏',
  28622. exitFullscreen: '退出全屏'
  28623. },
  28624. linkEditor: {
  28625. textInputPlaceHolder: '输入链接文字',
  28626. linkInputPlaceHolder: '输入链接地址',
  28627. inputWithEnterPlaceHolder: '输入链接地址并回车',
  28628. openInNewWindow: '在新窗口打开',
  28629. removeLink: '移除链接'
  28630. },
  28631. audioPlayer: {
  28632. title: '播放音频文件'
  28633. },
  28634. videoPlayer: {
  28635. title: '播放视频文件',
  28636. embedTitle: '嵌入式媒体'
  28637. },
  28638. media: {
  28639. image: '图像',
  28640. video: '视频',
  28641. audio: '音频',
  28642. embed: '嵌入式媒体'
  28643. }
  28644. });
  28645. // CONCATENATED MODULE: ./languages/zh-hant.js
  28646. /* harmony default export */ var zh_hant = ({
  28647. base: {
  28648. remove: '刪除',
  28649. cancel: '取消',
  28650. confirm: '確定',
  28651. inert: '插入',
  28652. width: '宽度',
  28653. height: '高度'
  28654. },
  28655. controls: {
  28656. clear: '清除内容',
  28657. undo: '撤銷',
  28658. redo: '重做',
  28659. fontSize: '字號',
  28660. color: '顏色',
  28661. textColor: '文字顏色',
  28662. backgroundColor: '背景顏色',
  28663. tempColors: '臨時顏色',
  28664. bold: '加粗',
  28665. lineHeight: '行高',
  28666. letterSpacing: '字間距',
  28667. textIndent: '段落縮進',
  28668. increaseIndent: '增加縮進',
  28669. decreaseIndent: '减少縮進',
  28670. border: '邊框',
  28671. italic: '斜體',
  28672. underline: '下劃線',
  28673. strikeThrough: '刪除線',
  28674. fontFamily: '字體',
  28675. textAlign: '文本對齊',
  28676. alignLeft: '居左',
  28677. alignCenter: '居中',
  28678. alignRight: '居右',
  28679. alignJustify: '兩端對齊',
  28680. floatLeft: '左浮動',
  28681. floatRight: '右浮動',
  28682. superScript: '上標',
  28683. subScript: '下標',
  28684. removeStyles: '清除样式',
  28685. headings: '標題',
  28686. header: '標題',
  28687. normal: '常規',
  28688. orderedList: '有序列表',
  28689. unorderedList: '無序列表',
  28690. blockQuote: '引用',
  28691. code: '代碼',
  28692. link: '鏈接',
  28693. unlink: '清除鏈接',
  28694. hr: '水平线',
  28695. media: '媒體',
  28696. mediaLibirary: '媒體库',
  28697. emoji: '小表情',
  28698. fullscreen: '全熒幕',
  28699. exitFullscreen: '退出全熒幕'
  28700. },
  28701. linkEditor: {
  28702. textInputPlaceHolder: '輸入鏈接文字',
  28703. linkInputPlaceHolder: '輸入鏈接地址',
  28704. inputWithEnterPlaceHolder: '輸入鏈接地址並回車',
  28705. openInNewWindow: '在新窗口打開',
  28706. removeLink: '移除鏈接'
  28707. },
  28708. audioPlayer: {
  28709. title: '播放音頻文件'
  28710. },
  28711. videoPlayer: {
  28712. title: '播放視頻文件',
  28713. embedTitle: '嵌入式媒體'
  28714. },
  28715. media: {
  28716. image: '圖像',
  28717. video: '視頻',
  28718. audio: '音頻',
  28719. embed: '嵌入式媒體'
  28720. }
  28721. });
  28722. // CONCATENATED MODULE: ./languages/pl.js
  28723. /* harmony default export */ var pl = ({
  28724. base: {
  28725. remove: 'Usuń',
  28726. cancel: 'Anuluj',
  28727. confirm: 'Potwierdź',
  28728. inert: 'Wstaw',
  28729. width: 'Szerokość',
  28730. height: 'Wysokość'
  28731. },
  28732. controls: {
  28733. clear: 'Wyczyść',
  28734. undo: 'Cofnij',
  28735. redo: 'Przywróć',
  28736. fontSize: 'Wielkość',
  28737. color: 'Kolor',
  28738. textColor: 'Kolor tekstu',
  28739. tempColors: 'Kolory',
  28740. backgroundColor: 'Tło',
  28741. bold: 'Pogrubienie',
  28742. lineHeight: 'Wysokość linii',
  28743. letterSpacing: 'Odstęp znaków',
  28744. textIndent: 'Wcięcie tekstu',
  28745. increaseIndent: 'Zwiększ wcięcie',
  28746. decreaseIndent: 'Zmniejsz wcięcie',
  28747. italic: 'Italiki',
  28748. underline: 'Podkreślenie',
  28749. strikeThrough: 'Przekreślenie',
  28750. fontFamily: 'Czcionka',
  28751. textAlign: 'Wyrównanie tekstu',
  28752. alignLeft: 'Do lewej',
  28753. alignCenter: 'Wycentruj',
  28754. alignRight: 'Do prawej',
  28755. alignJustify: 'Wyjustuj',
  28756. floatLeft: 'Do lewej',
  28757. floatRight: 'Do prawej',
  28758. superScript: 'Superskrypt',
  28759. subScript: 'Subskrypt',
  28760. removeStyles: 'Usuń stylowanie',
  28761. headings: 'Nagłówki',
  28762. header: 'Nagłówek',
  28763. normal: 'Normalny',
  28764. orderedList: 'Lista uporządkowana',
  28765. unorderedList: 'Lista nieuporządkowana',
  28766. blockQuote: 'Cytat',
  28767. code: 'Kod',
  28768. link: 'Link',
  28769. unlink: 'Usuń link',
  28770. hr: 'Linia pozioma',
  28771. media: 'Media',
  28772. mediaLibirary: 'Biblioteka mediów',
  28773. emoji: 'Emoji'
  28774. },
  28775. linkEditor: {
  28776. textInputPlaceHolder: 'Wpisz tekst linku',
  28777. linkInputPlaceHolder: 'Wpisz Adres URL',
  28778. inputWithEnterPlaceHolder: 'Wpisz adres URL i naciśnij Enter',
  28779. openInNewWindow: 'Otwórz w nowym oknie',
  28780. removeLink: 'Usuń link'
  28781. },
  28782. audioPlayer: {
  28783. title: 'Odtwórz audio'
  28784. },
  28785. videoPlayer: {
  28786. title: 'Odtwórz wideo',
  28787. embedTitle: 'Tytuł'
  28788. },
  28789. media: {
  28790. image: 'Obraz',
  28791. video: 'Wideo',
  28792. audio: 'Audio',
  28793. embed: 'Obiekt osadzony'
  28794. }
  28795. });
  28796. // CONCATENATED MODULE: ./languages/kr.js
  28797. /* harmony default export */ var kr = ({
  28798. base: {
  28799. remove: '삭제',
  28800. cancel: '취소',
  28801. confirm: '결정',
  28802. inert: '삽입',
  28803. width: '너비',
  28804. height: '높이'
  28805. },
  28806. controls: {
  28807. clear: '콘텐츠지우기',
  28808. undo: '취소',
  28809. redo: '다시하기',
  28810. fontSize: '글자크기',
  28811. lineHeight: '행높이',
  28812. letterSpacing: '단어간격',
  28813. textIndent: '단락들여쓰기',
  28814. increaseIndent: '들여쓰기늘리기',
  28815. decreaseIndent: '들여쓰기줄이기',
  28816. border: '국경',
  28817. color: '색상',
  28818. textColor: '텍스트색상',
  28819. backgroundColor: '배경색상',
  28820. tempColors: '임시색',
  28821. bold: '굵게',
  28822. italic: '기울임꼴',
  28823. underline: '밑줄',
  28824. strikeThrough: '취소선',
  28825. fontFamily: '글꼴',
  28826. textAlign: '텍스트정렬',
  28827. alignLeft: '왼쪽',
  28828. alignCenter: '중심',
  28829. alignRight: '오른쪽',
  28830. alignJustify: '양쪽끝',
  28831. floatLeft: '떠다니기',
  28832. floatRight: '오른쪽부동',
  28833. superScript: '위첨자',
  28834. subScript: '첨자',
  28835. removeStyles: '스타일지우기',
  28836. headings: '제목',
  28837. header: '제목',
  28838. normal: '재래식',
  28839. orderedList: '순서가지정된목록',
  28840. unorderedList: '정렬되지않은목록',
  28841. blockQuote: '참고문헌',
  28842. code: '코드',
  28843. link: '링크',
  28844. unlink: '링크삭제',
  28845. hr: '수평선',
  28846. media: '미디어',
  28847. mediaLibirary: '미디어라이브러리',
  28848. emoji: '작은표현',
  28849. fullscreen: '전체화면',
  28850. exitFullscreen: '전체화면종료'
  28851. },
  28852. linkEditor: {
  28853. textInputPlaceHolder: '링크텍스트입력',
  28854. linkInputPlaceHolder: '링크주소입력',
  28855. inputWithEnterPlaceHolder: '링크주소입력.',
  28856. openInNewWindow: '새창열기',
  28857. removeLink: '링크삭제'
  28858. },
  28859. audioPlayer: {
  28860. title: '오디오파일재생'
  28861. },
  28862. videoPlayer: {
  28863. title: '비디오파일재생',
  28864. embedTitle: '임베디드미디어'
  28865. },
  28866. media: {
  28867. image: '이미지',
  28868. video: '비디오',
  28869. audio: '오디오',
  28870. embed: '임베디드미디어'
  28871. }
  28872. });
  28873. // CONCATENATED MODULE: ./languages/tr.js
  28874. /* harmony default export */ var tr = ({
  28875. base: {
  28876. remove: 'Kaldır',
  28877. cancel: 'İptal',
  28878. confirm: 'Onayla',
  28879. inert: 'Ekle',
  28880. width: 'Genişlik',
  28881. height: 'Yükseklik'
  28882. },
  28883. controls: {
  28884. clear: 'Temizle',
  28885. undo: 'Geri al',
  28886. redo: 'İleri al',
  28887. fontSize: 'Yazı boyutu',
  28888. color: 'Renk',
  28889. textColor: 'Yazı rengi',
  28890. tempColors: 'Geçici renkler',
  28891. backgroundColor: 'Arkaplan',
  28892. bold: 'Kalın',
  28893. lineHeight: 'Satır yüksekliği',
  28894. letterSpacing: 'Harf aralığı',
  28895. textIndent: 'Çentik aralığı',
  28896. increaseIndent: 'Çentiği genişlet',
  28897. decreaseIndent: 'Çentiği daralt',
  28898. italic: 'Eğik',
  28899. underline: 'Altı çizili',
  28900. strikeThrough: 'Üstü çizili',
  28901. fontFamily: 'Yazı tipi',
  28902. textAlign: 'Metin Hizalama',
  28903. alignLeft: 'Sola hizala',
  28904. alignCenter: 'Ortaya hizala',
  28905. alignRight: 'Sağa hizala',
  28906. alignJustify: 'Her iki tarafa hizala',
  28907. floatLeft: 'Sola yatır',
  28908. floatRight: 'Sağa yatır',
  28909. superScript: 'Ana kod',
  28910. subScript: 'Alt kod',
  28911. removeStyles: 'Stilleri kaldır',
  28912. headings: 'Başlıklar',
  28913. header: 'Başlık',
  28914. normal: 'Normal',
  28915. orderedList: 'Sıralı liste',
  28916. unorderedList: 'Sırasız liste',
  28917. blockQuote: 'Alıntı',
  28918. code: 'Kod',
  28919. link: 'Bağlantı',
  28920. unlink: 'Bağlantıyı kaldır',
  28921. hr: 'Yatay çizgi',
  28922. media: 'Medya',
  28923. mediaLibirary: 'Kütüphane',
  28924. emoji: 'İfade',
  28925. fullscreen: 'Tam ekran',
  28926. exitFullscreen: 'Tam ekrandan çık'
  28927. },
  28928. linkEditor: {
  28929. textInputPlaceHolder: 'Bağlantı metnini girin',
  28930. linkInputPlaceHolder: 'Bağlantı URL\' si girin',
  28931. inputWithEnterPlaceHolder: 'Bağlantı URL\'si girin ve Enter\' a basın',
  28932. openInNewWindow: 'Yeni pencerede aç',
  28933. removeLink: 'Bağlantıyı kaldır'
  28934. },
  28935. audioPlayer: {
  28936. title: 'Ses çal'
  28937. },
  28938. videoPlayer: {
  28939. title: 'Görüntü oynat',
  28940. embedTitle: 'Görüntüyü göm'
  28941. },
  28942. media: {
  28943. image: 'Resim',
  28944. video: 'Görüntü',
  28945. audio: 'Ses',
  28946. embed: 'Gömülü nesne'
  28947. }
  28948. });
  28949. // CONCATENATED MODULE: ./languages/jpn.js
  28950. /* harmony default export */ var jpn = ({
  28951. base: {
  28952. remove: '削除',
  28953. cancel: 'キャンセル',
  28954. confirm: '決定',
  28955. inert: '挿入',
  28956. width: '幅',
  28957. height: '高さ'
  28958. },
  28959. controls: {
  28960. clear: 'クリアコンテンツ',
  28961. undo: 'キャンセル',
  28962. redo: 'キャンセル',
  28963. fontSize: 'フォントサイズ',
  28964. lineHeight: 'フォントサイズ',
  28965. letterSpacing: 'ワード間隔',
  28966. textIndent: '段落のインデント',
  28967. increaseIndent: 'インデントを増やす',
  28968. decreaseIndent: 'インデントを減らす',
  28969. border: '国境',
  28970. color: '色',
  28971. textColor: 'テキストの色',
  28972. backgroundColor: '背景色',
  28973. tempColors: '仮色',
  28974. bold: '太字',
  28975. italic: 'イタリック体',
  28976. underline: '下線',
  28977. strikeThrough: '取り消し線',
  28978. fontFamily: 'フォント',
  28979. textAlign: 'テキストの配置',
  28980. alignLeft: '左',
  28981. alignCenter: '中央揃え',
  28982. alignRight: '右に立つ',
  28983. alignJustify: '両端',
  28984. floatLeft: '左フローティング',
  28985. floatRight: '右フローティング',
  28986. superScript: '上付き',
  28987. subScript: '下付き文字',
  28988. removeStyles: 'クリアスタイル',
  28989. headings: '役職',
  28990. header: '役職',
  28991. normal: '従来の',
  28992. orderedList: '順序付きリスト',
  28993. unorderedList: '番号なしリスト',
  28994. blockQuote: '参照',
  28995. code: 'コード',
  28996. link: 'リンク',
  28997. unlink: 'リンクを解除',
  28998. hr: '横線',
  28999. media: 'メディア',
  29000. mediaLibirary: 'メディアライブラリー',
  29001. emoji: '小さな表現',
  29002. fullscreen: '全画面',
  29003. exitFullscreen: '全画面を退く'
  29004. },
  29005. linkEditor: {
  29006. textInputPlaceHolder: 'リンクテキストを入力',
  29007. linkInputPlaceHolder: 'リンクアドレスを入力',
  29008. inputWithEnterPlaceHolder: 'リンクアドレスを入力して戻ります',
  29009. openInNewWindow: '新しいウィンドウで開く',
  29010. removeLink: '新しいウィンドウで開く'
  29011. },
  29012. audioPlayer: {
  29013. title: 'オーディオファイルを再生する'
  29014. },
  29015. videoPlayer: {
  29016. title: 'ビデオファイルを再生する',
  29017. embedTitle: '埋め込みメディア'
  29018. },
  29019. media: {
  29020. image: '画像',
  29021. video: 'ビデオ',
  29022. audio: '音声',
  29023. embed: '埋め込みメディア'
  29024. }
  29025. });
  29026. // CONCATENATED MODULE: ./languages/ru.js
  29027. /* harmony default export */ var ru = ({
  29028. base: {
  29029. remove: 'Удалить',
  29030. cancel: 'Отмена',
  29031. confirm: 'Подтвердить',
  29032. insert: 'Вставить',
  29033. width: 'Ширина',
  29034. height: 'Высота'
  29035. },
  29036. controls: {
  29037. clear: 'Очистить',
  29038. undo: 'Отменить',
  29039. redo: 'Повторить',
  29040. fontSize: 'Размер шрифта',
  29041. color: 'Цвет',
  29042. textColor: 'Цвет текста',
  29043. tempColors: 'Temp Colors',
  29044. backgroundColor: 'Цвет фона',
  29045. bold: 'Жирный',
  29046. lineHeight: 'Межстрочный интервал',
  29047. letterSpacing: 'Межбуквенный интервал',
  29048. textIndent: 'Отступ',
  29049. increaseIndent: 'Увеличить отступ',
  29050. decreaseIndent: 'Уменьшить отступ',
  29051. italic: 'Курсив',
  29052. underline: 'Подчеркнутый',
  29053. strikeThrough: 'Перечеркнутый',
  29054. fontFamily: 'Шрифт',
  29055. textAlign: 'Расположение текста',
  29056. alignLeft: 'По левому краю',
  29057. alignCenter: 'По центру',
  29058. alignRight: 'По правому краю',
  29059. alignJustify: 'По ширине',
  29060. floatLeft: 'Обтекание слева',
  29061. floatRight: 'Обтекание справа',
  29062. superScript: 'Надстрочный индекс',
  29063. subScript: 'Подстрочный индекс',
  29064. removeStyles: 'Убрать стили',
  29065. headings: 'Заголовки',
  29066. header: 'Заголовок',
  29067. normal: 'Обычный',
  29068. orderedList: 'Упорядоченный список',
  29069. unorderedList: 'Неупорядоченный список',
  29070. blockQuote: 'Цитата',
  29071. code: 'Код',
  29072. link: 'Вставить ссылку',
  29073. unlink: 'Убрать ссылку',
  29074. hr: 'Горизонтальная линия',
  29075. media: 'Медиа',
  29076. mediaLibirary: 'Медиа библиотека',
  29077. emoji: 'Emoji',
  29078. fullscreen: 'Полноэкранный режим',
  29079. exitFullscreen: 'Выйти из полноэкранного режима'
  29080. },
  29081. linkEditor: {
  29082. textInputPlaceHolder: 'Введите текст ссылки',
  29083. linkInputPlaceHolder: 'Вставить ссылку',
  29084. inputWithEnterPlaceHolder: 'Вставить ссылку и нажать Enter',
  29085. openInNewWindow: 'Открыть в новом окне',
  29086. removeLink: 'Убрать ссылку'
  29087. },
  29088. audioPlayer: {
  29089. title: 'Воспроизвести аудиофайл'
  29090. },
  29091. videoPlayer: {
  29092. title: 'Воспроизвести видеофайл',
  29093. embedTitle: 'Embed Media'
  29094. },
  29095. media: {
  29096. image: 'Картинка',
  29097. video: 'Видео',
  29098. audio: 'Аудио',
  29099. embed: 'Встроенное'
  29100. }
  29101. });
  29102. // CONCATENATED MODULE: ./languages/fr.js
  29103. /* harmony default export */ var fr = ({
  29104. base: {
  29105. remove: 'Supprimer',
  29106. cancel: 'Annuler',
  29107. confirm: 'Confirmer',
  29108. inert: 'Insérer',
  29109. width: 'Largeur',
  29110. height: 'Hauteur'
  29111. },
  29112. controls: {
  29113. clear: 'Effacer',
  29114. undo: 'Annuler',
  29115. redo: 'Refaire',
  29116. fontSize: 'Taille de police',
  29117. color: 'Couleur',
  29118. textColor: 'Texte',
  29119. tempColors: 'Couleurs temporaire',
  29120. backgroundColor: 'Couleur d\'arrière plan',
  29121. bold: 'Gras',
  29122. lineHeight: 'Hauteur de ligne',
  29123. letterSpacing: 'Espacement des lettres',
  29124. textIndent: 'Indentation du texte',
  29125. increaseIndent: 'Augmenter l\'indentation',
  29126. decreaseIndent: 'Réduire l\'indentation',
  29127. italic: 'Italique',
  29128. underline: 'Souligner',
  29129. strikeThrough: 'Barrer',
  29130. fontFamily: 'Police d\'écriture',
  29131. textAlign: 'Alignement du texte',
  29132. alignLeft: 'Aligner à gauche',
  29133. alignCenter: 'Aligner au centre',
  29134. alignRight: 'Aligner à droite',
  29135. alignJustify: 'Justifier',
  29136. floatLeft: 'Déplacer à gauche',
  29137. floatRight: 'Déplacer à droite',
  29138. superScript: 'Super-script',
  29139. subScript: 'Sous-script',
  29140. removeStyles: 'Supprimer les styles',
  29141. headings: 'Titres',
  29142. header: 'Entêtes',
  29143. normal: 'Normal',
  29144. orderedList: 'Liste ordonnée',
  29145. unorderedList: 'Liste non-ordonnée',
  29146. blockQuote: 'Citation',
  29147. code: 'Code',
  29148. link: 'Insérer un lien',
  29149. unlink: 'Supprimer le lien',
  29150. hr: 'Ligne horizontale',
  29151. media: 'Média',
  29152. mediaLibirary: 'Bibliothêque',
  29153. emoji: 'Emoji',
  29154. fullscreen: 'Plein écran',
  29155. exitFullscreen: 'Quitter le plein écran'
  29156. },
  29157. linkEditor: {
  29158. textInputPlaceHolder: 'Insérer le texte à afficher',
  29159. linkInputPlaceHolder: 'Insérer le lien URL',
  29160. inputWithEnterPlaceHolder: 'Insérer le lien URL puis appuyer sur Entrée',
  29161. openInNewWindow: 'Ouvrir dans une nouvelle fenêtre',
  29162. removeLink: 'Supprimer le lien'
  29163. },
  29164. audioPlayer: {
  29165. title: 'Lancer le son audio'
  29166. },
  29167. videoPlayer: {
  29168. title: 'Lancer la video',
  29169. embedTitle: 'Intégrer média'
  29170. },
  29171. media: {
  29172. image: 'Image',
  29173. video: 'Vidéo',
  29174. audio: 'Audio',
  29175. embed: 'Intégré'
  29176. }
  29177. });
  29178. // CONCATENATED MODULE: ./languages/pt-br.js
  29179. /* harmony default export */ var pt_br = ({
  29180. base: {
  29181. remove: 'Remover',
  29182. cancel: 'Cancelar',
  29183. confirm: 'Confirmar',
  29184. inert: 'Inserir',
  29185. width: 'Largura',
  29186. height: 'Altura'
  29187. },
  29188. controls: {
  29189. clear: 'Limpar',
  29190. undo: 'Desfazer',
  29191. redo: 'Refazer',
  29192. fontSize: 'Tamanho da Fonte',
  29193. color: 'Cor',
  29194. textColor: 'Texto',
  29195. tempColors: 'Temp Colors',
  29196. backgroundColor: 'Cor de Fundo',
  29197. bold: 'Negrito',
  29198. lineHeight: 'Altura da LinhaLine Height',
  29199. letterSpacing: 'Espaçamento entre Letras',
  29200. textIndent: 'Identação de Texto',
  29201. increaseIndent: 'Aumentar Identação',
  29202. decreaseIndent: 'Diminuir Identção',
  29203. italic: 'Itálico',
  29204. underline: 'Sublinhado',
  29205. strikeThrough: 'Riscado',
  29206. fontFamily: 'Família da Fonte',
  29207. textAlign: 'Alinhamento de Texto',
  29208. alignLeft: 'Alinhamento à Esquerda',
  29209. alignCenter: 'Alinhamento Centralizado',
  29210. alignRight: 'Alinhamento à Direita',
  29211. alignJustify: 'Alinhamento Justificado',
  29212. floatLeft: 'Flutuação à Esquerda',
  29213. floatRight: 'Flutuação à Direita',
  29214. superScript: 'Sobrescrito',
  29215. subScript: 'Subscrito',
  29216. removeStyles: 'Remover Estilos',
  29217. headings: 'Cabeçalhos',
  29218. header: 'Cabeçalho',
  29219. normal: 'Normal',
  29220. orderedList: 'Lista Ordenada',
  29221. unorderedList: 'Lista Não Ordenada',
  29222. blockQuote: 'Citação',
  29223. code: 'Código',
  29224. link: 'Link',
  29225. unlink: 'Remover Link',
  29226. hr: 'Linha Horizontal',
  29227. media: 'Mídia',
  29228. mediaLibirary: 'Biblioteca de Mídia',
  29229. emoji: 'Emoji',
  29230. fullscreen: 'Tela Cheia',
  29231. exitFullscreen: 'Sair de Tela Cheia'
  29232. },
  29233. linkEditor: {
  29234. textInputPlaceHolder: 'Insira o texto do link',
  29235. linkInputPlaceHolder: 'Insira a URL do link',
  29236. inputWithEnterPlaceHolder: 'Insira a URL do link e aperte Enter',
  29237. openInNewWindow: 'Abrir em nova janela',
  29238. removeLink: 'Remover Link'
  29239. },
  29240. audioPlayer: {
  29241. title: 'Tocar Áudio'
  29242. },
  29243. videoPlayer: {
  29244. title: 'Tocar Vídeo',
  29245. embedTitle: 'Mídia Embutida'
  29246. },
  29247. media: {
  29248. image: 'Imagem',
  29249. video: 'Vídeo',
  29250. audio: 'Áudio',
  29251. embed: 'Embutido'
  29252. }
  29253. });
  29254. // CONCATENATED MODULE: ./languages/index.js
  29255. /* harmony default export */ var languages = ({
  29256. 'en': en,
  29257. 'zh': zh,
  29258. 'zh-hant': zh_hant,
  29259. 'pl': pl,
  29260. 'kr': kr,
  29261. 'tr': tr,
  29262. 'jpn': jpn,
  29263. 'ru': ru,
  29264. 'fr': fr,
  29265. 'pt-br': pt_br
  29266. });
  29267. // EXTERNAL MODULE: external "braft-finder"
  29268. var external_braft_finder_ = __webpack_require__(17);
  29269. var external_braft_finder_default = /*#__PURE__*/__webpack_require__.n(external_braft_finder_);
  29270. // EXTERNAL MODULE: external "braft-utils"
  29271. var external_braft_utils_ = __webpack_require__(3);
  29272. // EXTERNAL MODULE: external "draft-js"
  29273. var external_draft_js_ = __webpack_require__(6);
  29274. // EXTERNAL MODULE: external "immutable"
  29275. var external_immutable_ = __webpack_require__(13);
  29276. var external_immutable_default = /*#__PURE__*/__webpack_require__.n(external_immutable_);
  29277. // CONCATENATED MODULE: ./configs/keybindings.js
  29278. // TODO
  29279. // 允许自定义的快捷键设置
  29280. /* harmony default export */ var keybindings = (function (customKeyBindingFn) {
  29281. return function (event) {
  29282. if (event.keyCode === 83 && (external_draft_js_["KeyBindingUtil"].hasCommandModifier(event) || external_draft_js_["KeyBindingUtil"].isCtrlKeyCommand(event))) {
  29283. return 'braft-save';
  29284. }
  29285. if (customKeyBindingFn) {
  29286. return customKeyBindingFn(event) || Object(external_draft_js_["getDefaultKeyBinding"])(event);
  29287. }
  29288. return Object(external_draft_js_["getDefaultKeyBinding"])(event);
  29289. };
  29290. });
  29291. // CONCATENATED MODULE: ./configs/props.js
  29292. /* harmony default export */ var configs_props = ({
  29293. language: 'zh',
  29294. controls: ['undo', 'redo', 'separator', 'font-size', 'line-height', 'letter-spacing', 'separator', 'text-color', 'bold', 'italic', 'underline', 'strike-through', 'separator', 'superscript', 'subscript', 'remove-styles', 'emoji', 'separator', 'text-indent', 'text-align', 'separator', 'headings', 'list-ul', 'list-ol', 'blockquote', 'code', 'separator', 'media', 'link', 'table', 'split', 'hr', 'separator', 'clear', 'separator', 'fullscreen'],
  29295. excludeControls: [],
  29296. extendControls: [],
  29297. extendAtomics: [],
  29298. componentBelowControlBar: null,
  29299. media: {
  29300. pasteImage: true,
  29301. imagePasteLimit: 5,
  29302. image: true,
  29303. video: true,
  29304. audio: true,
  29305. uploadFn: null,
  29306. validateFn: null,
  29307. onBeforeDeselect: null,
  29308. onDeselect: null,
  29309. onBeforeSelect: null,
  29310. onSelect: null,
  29311. onBeforeRemove: null,
  29312. onRemove: null,
  29313. onCancel: null,
  29314. onFileSelect: null,
  29315. onBeforeInsert: null,
  29316. onInsert: null,
  29317. onChange: null,
  29318. accepts: {
  29319. image: 'image/png,image/jpeg,image/gif,image/webp,image/apng,image/svg',
  29320. video: 'video/mp4',
  29321. audio: 'audio/mp3'
  29322. },
  29323. externals: {
  29324. audio: true,
  29325. video: true,
  29326. image: true,
  29327. embed: true
  29328. }
  29329. },
  29330. imageControls: ['float-left', 'float-right', 'align-left', 'align-center', 'align-right', 'link', 'size', 'remove'],
  29331. imageResizable: true,
  29332. colors: ['#000000', '#333333', '#666666', '#999999', '#cccccc', '#ffffff', '#61a951', '#16a085', '#07a9fe', '#003ba5', '#8e44ad', '#f32784', '#c0392b', '#d35400', '#f39c12', '#fdda00'],
  29333. colorPicker: null,
  29334. colorPickerTheme: 'dark',
  29335. colorPickerAutoHide: true,
  29336. codeTabIndents: 2,
  29337. headings: ['header-one', 'header-two', 'header-three', 'header-four', 'header-five', 'header-six', 'unstyled'],
  29338. textAligns: ['left', 'center', 'right', 'justify'],
  29339. textBackgroundColor: true,
  29340. allowInsertLinkText: false,
  29341. defaultLinkTarget: '',
  29342. letterSpacings: [0, 1, 2, 3, 4, 5, 6],
  29343. lineHeights: [1, 1.2, 1.5, 1.75, 2, 2.5, 3, 4],
  29344. fontSizes: [12, 14, 16, 18, 20, 24, 28, 30, 32, 36, 40, 48, 56, 64, 72, 96, 120, 144],
  29345. fontFamilies: [{
  29346. name: 'Araial',
  29347. family: 'Arial, Helvetica, sans-serif'
  29348. }, {
  29349. name: 'Georgia',
  29350. family: 'Georgia, serif'
  29351. }, {
  29352. name: 'Impact',
  29353. family: 'Impact, serif'
  29354. }, {
  29355. name: 'Monospace',
  29356. family: '"Courier New", Courier, monospace'
  29357. }, {
  29358. name: 'Tahoma',
  29359. family: 'tahoma, arial, "Hiragino Sans GB", 宋体, sans-serif'
  29360. }],
  29361. converts: {
  29362. unitExportFn: function unitExportFn(value, type) {
  29363. return type === 'line-height' ? value : "".concat(value, "px");
  29364. }
  29365. },
  29366. emojis: ['🤣', '🙌', '💚', '💛', '👏', '😉', '💯', '💕', '💞', '💘', '💙', '💝', '🖤', '💜', '❤️', '😍', '😻', '💓', '💗', '😋', '😇', '😂', '😹', '😘', '💖', '😁', '😀', '🤞', '😲', '😄', '😊', '👍', '😌', '😃', '😅', '✌️', '🤗', '💋', '😗', '😽', '😚', '🤠', '😙', '😺', '👄', '😸', '😏', '😼', '👌', '😎', '😆', '😛', '🙏', '🤝', '🙂', '🤑', '😝', '😐', '😑', '🤤', '😤', '🙃', '🤡', '😶', '😪', '😴', '😵', '😓', '👊', '😦', '😷', '🤐', '😜', '🤓', '👻', '😥', '🙄', '🤔', '🤒', '🙁', '😔', '😯', '☹️', '☠️', '😰', '😩', '😖', '😕', '😒', '😣', '😢', '😮', '😿', '🤧', '😫', '🤥', '😞', '😬', '👎', '💀', '😳', '😨', '🤕', '🤢', '😱', '😭', '😠', '😈', '😧', '💔', '😟', '🙀', '💩', '👿', '😡', '😾', '🖕'],
  29367. stripPastedStyles: false,
  29368. triggerChangeOnMount: true,
  29369. className: '',
  29370. style: {},
  29371. controlBarClassName: '',
  29372. controlBarStyle: {},
  29373. contentClassName: '',
  29374. contentStyle: {},
  29375. draftProps: {},
  29376. hooks: {},
  29377. onChange: null,
  29378. onFocus: null,
  29379. onBlur: null,
  29380. onTab: null,
  29381. onDelete: null,
  29382. onSave: null,
  29383. fixPlaceholder: false
  29384. });
  29385. // EXTERNAL MODULE: ../node_modules/draft-js/lib/getFragmentFromSelection.js
  29386. var getFragmentFromSelection = __webpack_require__(22);
  29387. var getFragmentFromSelection_default = /*#__PURE__*/__webpack_require__.n(getFragmentFromSelection);
  29388. // EXTERNAL MODULE: external "draftjs-utils"
  29389. var external_draftjs_utils_ = __webpack_require__(23);
  29390. // CONCATENATED MODULE: ./configs/handlers.js
  29391. var handlers_keyCommandHandlers = function keyCommandHandlers(command, editorState, editor) {
  29392. if (editor.editorProps.handleKeyCommand && editor.editorProps.handleKeyCommand(command, editorState, editor) === 'handled') {
  29393. return 'handled';
  29394. }
  29395. if (command === 'braft-save') {
  29396. editor.editorProps.onSave && editor.editorProps.onSave(editorState);
  29397. return 'handled';
  29398. }
  29399. var _editor$editorProps = editor.editorProps,
  29400. controls = _editor$editorProps.controls,
  29401. excludeControls = _editor$editorProps.excludeControls;
  29402. var allowIndent = (controls.indexOf('text-indent') !== 0 || controls.find(function (item) {
  29403. return item.key === 'text-indent';
  29404. })) && excludeControls.indexOf('text-indent') === -1;
  29405. var cursorStart = editorState.getSelection().getStartOffset();
  29406. var cursorEnd = editorState.getSelection().getEndOffset();
  29407. var cursorIsAtFirst = cursorStart === 0 && cursorEnd === 0;
  29408. if (command === 'backspace') {
  29409. if (editor.editorProps.onDelete && editor.editorProps.onDelete(editorState) === false) {
  29410. return 'handled';
  29411. }
  29412. var blockType = external_braft_utils_["ContentUtils"].getSelectionBlockType(editorState);
  29413. if (allowIndent && cursorIsAtFirst && blockType !== 'code-block') {
  29414. editor.setValue(external_braft_utils_["ContentUtils"].decreaseSelectionIndent(editorState));
  29415. }
  29416. }
  29417. if (command === 'tab') {
  29418. var _blockType = external_braft_utils_["ContentUtils"].getSelectionBlockType(editorState);
  29419. if (_blockType === 'code-block') {
  29420. editor.setValue(external_braft_utils_["ContentUtils"].insertText(editorState, ' '.repeat(editor.editorProps.codeTabIndents)));
  29421. return 'handled';
  29422. } else if (_blockType === 'ordered-list-item' || _blockType === 'unordered-list-item') {
  29423. var newEditorState = external_draft_js_["RichUtils"].onTab(event, editorState, 4);
  29424. if (newEditorState !== editorState) {
  29425. editor.setValue(newEditorState);
  29426. }
  29427. return 'handled';
  29428. } else if (_blockType !== 'atomic' && allowIndent && cursorIsAtFirst) {
  29429. editor.setValue(external_braft_utils_["ContentUtils"].increaseSelectionIndent(editorState));
  29430. return 'handled';
  29431. }
  29432. }
  29433. var nextEditorState = external_braft_utils_["ContentUtils"].handleKeyCommand(editorState, command);
  29434. if (nextEditorState) {
  29435. editor.setValue(nextEditorState);
  29436. return 'handled';
  29437. }
  29438. return 'not-handled';
  29439. };
  29440. var handlers_returnHandlers = function returnHandlers(event, editorState, editor) {
  29441. if (editor.editorProps.handleReturn && editor.editorProps.handleReturn(event, editorState, editor) === 'handled') {
  29442. return 'handled';
  29443. }
  29444. var currentBlock = external_braft_utils_["ContentUtils"].getSelectionBlock(editorState);
  29445. var currentBlockType = currentBlock.getType();
  29446. if (currentBlockType === 'unordered-list-item' || currentBlockType === 'ordered-list-item') {
  29447. if (currentBlock.getLength() === 0) {
  29448. editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionBlockType(editorState, 'unstyled'));
  29449. return 'handled';
  29450. }
  29451. return 'not-handled';
  29452. } else if (currentBlockType === 'code-block') {
  29453. if (event.which === 13 && (event.getModifierState('Shift') || event.getModifierState('Alt') || event.getModifierState('Control'))) {
  29454. editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionBlockType(editorState, 'unstyled'));
  29455. return 'handled';
  29456. }
  29457. return 'not-handled';
  29458. } else if (currentBlockType === 'blockquote') {
  29459. if (event.which === 13) {
  29460. if (event.getModifierState('Shift') || event.getModifierState('Alt') || event.getModifierState('Control')) {
  29461. event.which = 0;
  29462. } else {
  29463. editor.setValue(external_draft_js_["RichUtils"].insertSoftNewline(editorState));
  29464. return 'handled';
  29465. }
  29466. }
  29467. }
  29468. var nextEditorState = Object(external_draftjs_utils_["handleNewLine"])(editorState, event);
  29469. if (nextEditorState) {
  29470. editor.setValue(nextEditorState);
  29471. return 'handled';
  29472. }
  29473. return 'not-handled';
  29474. };
  29475. var beforeInputHandlers = function beforeInputHandlers(chars, editorState, editor) {
  29476. if (editor.editorProps.handleBeforeInput && editor.editorProps.handleBeforeInput(chars, editorState, editor) === 'handled') {
  29477. return 'handled';
  29478. }
  29479. return 'not-handled';
  29480. };
  29481. var handlers_compositionStartHandler = function compositionStartHandler(_, editor) {
  29482. var editorState = editor.state.editorState;
  29483. var selectedBlocks = external_braft_utils_["ContentUtils"].getSelectedBlocks(editorState);
  29484. if (selectedBlocks && selectedBlocks.length > 1) {
  29485. var nextEditorState = external_draft_js_["EditorState"].push(editorState, external_draft_js_["Modifier"].removeRange(editorState.getCurrentContent(), editorState.getSelection(), 'backward'), 'remove-range');
  29486. editor.setValue(nextEditorState);
  29487. }
  29488. };
  29489. var handlers_dropHandlers = function dropHandlers(selectionState, dataTransfer, editor) {
  29490. if (editor.editorProps.readOnly || editor.editorProps.disabled) {
  29491. return 'handled';
  29492. }
  29493. if (window && window.__BRAFT_DRAGING__IMAGE__) {
  29494. var nextEditorState = external_draft_js_["EditorState"].forceSelection(editor.state.editorState, selectionState);
  29495. nextEditorState = external_braft_utils_["ContentUtils"].insertMedias(nextEditorState, [window.__BRAFT_DRAGING__IMAGE__.mediaData]);
  29496. nextEditorState = external_braft_utils_["ContentUtils"].removeBlock(nextEditorState, window.__BRAFT_DRAGING__IMAGE__.block, nextEditorState.getSelection());
  29497. window.__BRAFT_DRAGING__IMAGE__ = null;
  29498. editor.lockOrUnlockEditor(true);
  29499. editor.setValue(nextEditorState);
  29500. return 'handled';
  29501. } else if (!dataTransfer || !dataTransfer.getText()) {
  29502. return 'handled';
  29503. }
  29504. return 'not-handled';
  29505. };
  29506. var handlers_handleFiles = function handleFiles(files, editor) {
  29507. var _editor$constructor$d = objectSpread_default()({}, editor.constructor.defaultProps.media, editor.editorProps.media),
  29508. pasteImage = _editor$constructor$d.pasteImage,
  29509. validateFn = _editor$constructor$d.validateFn,
  29510. imagePasteLimit = _editor$constructor$d.imagePasteLimit;
  29511. pasteImage && files.slice(0, imagePasteLimit).forEach(function (file) {
  29512. if (file && file.type.indexOf('image') > -1 && editor.braftFinder) {
  29513. var validateResult = validateFn ? validateFn(file) : true;
  29514. if (validateResult instanceof Promise) {
  29515. validateResult.then(function () {
  29516. editor.braftFinder.uploadImage(file, function (image) {
  29517. editor.isLiving && editor.setValue(external_braft_utils_["ContentUtils"].insertMedias(editor.state.editorState, [image]));
  29518. });
  29519. });
  29520. } else if (validateResult) {
  29521. editor.braftFinder.uploadImage(file, function (image) {
  29522. editor.isLiving && editor.setValue(external_braft_utils_["ContentUtils"].insertMedias(editor.state.editorState, [image]));
  29523. });
  29524. }
  29525. }
  29526. });
  29527. if (files[0] && files[0].type.indexOf('image') > -1 && pasteImage) {
  29528. return 'handled';
  29529. }
  29530. return 'not-handled';
  29531. };
  29532. var droppedFilesHandlers = function droppedFilesHandlers(selectionState, files, editor) {
  29533. if (editor.editorProps.handleDroppedFiles && editor.editorProps.handleDroppedFiles(selectionState, files, editor) === 'handled') {
  29534. return 'handled';
  29535. }
  29536. return handlers_handleFiles(files, editor);
  29537. };
  29538. var pastedFilesHandlers = function pastedFilesHandlers(files, editor) {
  29539. if (editor.editorProps.handlePastedFiles && editor.editorProps.handlePastedFiles(files, editor) === 'handled') {
  29540. return 'handled';
  29541. }
  29542. return handlers_handleFiles(files, editor);
  29543. };
  29544. var handlers_copyHandlers = function copyHandlers(event, editor) {
  29545. var blockMap = getFragmentFromSelection_default()(editor.state.editorState);
  29546. if (blockMap && blockMap.toArray) {
  29547. try {
  29548. var tempContentState = external_draft_js_["ContentState"].createFromBlockArray(blockMap.toArray());
  29549. var tempEditorState = external_draft_js_["EditorState"].createWithContent(tempContentState);
  29550. var clipboardData = event.clipboardData || window.clipboardData || event.originalEvent.clipboardData;
  29551. tempEditorState.setConvertOptions(editor.state.editorState.convertOptions);
  29552. clipboardData.setData('text/html', tempEditorState.toHTML());
  29553. clipboardData.setData('text/plain', tempEditorState.toText());
  29554. event.preventDefault();
  29555. } catch (error) {
  29556. console.warn(error);
  29557. }
  29558. }
  29559. };
  29560. var handlers_pastedTextHandlers = function pastedTextHandlers(text, html, editorState, editor) {
  29561. if (editor.editorProps.handlePastedText && editor.editorProps.handlePastedText(text, html, editorState, editor) === 'handled') {
  29562. return 'handled';
  29563. }
  29564. if (!html || editor.editorProps.stripPastedStyles) {
  29565. return false;
  29566. }
  29567. var tempColors = external_braft_utils_["ColorUtils"].detectColorsFromHTMLString(html);
  29568. editor.setState({
  29569. tempColors: toConsumableArray_default()(editor.state.tempColors).concat(toConsumableArray_default()(tempColors)).filter(function (item) {
  29570. return editor.editorProps.colors.indexOf(item) === -1;
  29571. }).filter(function (item, index, array) {
  29572. return array.indexOf(item) === index;
  29573. })
  29574. }, function () {
  29575. editor.setValue(external_braft_utils_["ContentUtils"].insertHTML(editorState, html, 'paste'));
  29576. });
  29577. return 'handled';
  29578. };
  29579. // CONCATENATED MODULE: ./helpers/extension.js
  29580. // TODO
  29581. // - block-style和atomic类型的扩展支持
  29582. var extension_extensionControls = [];
  29583. var extension_extensionDecorators = [];
  29584. var extension_propInterceptors = [];
  29585. var extension_extensionBlockRenderMaps = [];
  29586. var extension_extensionBlockRendererFns = [];
  29587. var extensionInlineStyleMaps = [];
  29588. var extension_extensionInlineStyleFns = [];
  29589. var extensionEntities = [];
  29590. var inlineStyleImporters = [];
  29591. var inlineStyleExporters = [];
  29592. var blockImporters = [];
  29593. var blockExporters = [];
  29594. var filterByEditorId = function filterByEditorId(items, editorId) {
  29595. if (!editorId) {
  29596. return items.filter(function (item) {
  29597. return !item.includeEditors;
  29598. }).map(function (item) {
  29599. return item.data;
  29600. });
  29601. }
  29602. return items.map(function (item) {
  29603. if (!item.includeEditors && !item.excludeEditors) {
  29604. return item.data;
  29605. }
  29606. if (item.includeEditors) {
  29607. return item.includeEditors.indexOf(editorId) !== -1 ? item.data : false;
  29608. }
  29609. if (item.excludeEditors) {
  29610. return item.excludeEditors.indexOf(editorId) !== -1 ? false : item.data;
  29611. }
  29612. return false;
  29613. }).filter(function (item) {
  29614. return item;
  29615. });
  29616. };
  29617. var getPropInterceptors = function getPropInterceptors(editorId) {
  29618. return filterByEditorId(extension_propInterceptors, editorId);
  29619. };
  29620. var getExtensionControls = function getExtensionControls(editorId) {
  29621. return filterByEditorId(extension_extensionControls, editorId);
  29622. };
  29623. var getExtensionDecorators = function getExtensionDecorators(editorId) {
  29624. return filterByEditorId(extension_extensionDecorators, editorId);
  29625. };
  29626. var getExtensionBlockRenderMaps = function getExtensionBlockRenderMaps(editorId) {
  29627. return filterByEditorId(extension_extensionBlockRenderMaps, editorId);
  29628. };
  29629. var getExtensionBlockRendererFns = function getExtensionBlockRendererFns(editorId) {
  29630. return filterByEditorId(extension_extensionBlockRendererFns, editorId);
  29631. };
  29632. var getExtensionInlineStyleMap = function getExtensionInlineStyleMap(editorId) {
  29633. var inlineStyleMap = {};
  29634. filterByEditorId(extensionInlineStyleMaps, editorId).forEach(function (item) {
  29635. inlineStyleMap[item.inlineStyleName] = item.styleMap;
  29636. });
  29637. return inlineStyleMap;
  29638. };
  29639. var getExtensionInlineStyleFns = function getExtensionInlineStyleFns(editorId) {
  29640. return filterByEditorId(extension_extensionInlineStyleFns, editorId);
  29641. };
  29642. var compositeStyleImportFn = function compositeStyleImportFn(styleImportFn, editorId) {
  29643. return function (nodeName, node, style) {
  29644. filterByEditorId(inlineStyleImporters, editorId).forEach(function (styleImporter) {
  29645. if (styleImporter.importer && styleImporter.importer(nodeName, node)) {
  29646. style = style.add(styleImporter.inlineStyleName);
  29647. }
  29648. });
  29649. return styleImportFn ? styleImportFn(nodeName, node, style) : style;
  29650. };
  29651. };
  29652. var compositeStyleExportFn = function compositeStyleExportFn(styleExportFn, editorId) {
  29653. return function (style) {
  29654. style = style.toUpperCase();
  29655. var result = styleExportFn ? styleExportFn(style) : undefined;
  29656. if (result) {
  29657. return result;
  29658. }
  29659. filterByEditorId(inlineStyleExporters, editorId).find(function (item) {
  29660. if (item.inlineStyleName === style) {
  29661. result = item.exporter;
  29662. return true;
  29663. }
  29664. });
  29665. return result;
  29666. };
  29667. };
  29668. var compositeEntityImportFn = function compositeEntityImportFn(entityImportFn, editorId) {
  29669. return function (nodeName, node, createEntity, source) {
  29670. var result = entityImportFn ? entityImportFn(nodeName, node, createEntity, source) : null;
  29671. if (result) {
  29672. return result;
  29673. }
  29674. filterByEditorId(extensionEntities, editorId).find(function (entityItem) {
  29675. var matched = entityItem.importer ? entityItem.importer(nodeName, node, source) : null;
  29676. matched && (result = createEntity(entityItem.entityType, matched.mutability || 'MUTABLE', matched.data || {}));
  29677. return !!matched;
  29678. });
  29679. return result;
  29680. };
  29681. };
  29682. var compositeEntityExportFn = function compositeEntityExportFn(entityExportFn, editorId) {
  29683. return function (entity, originalText) {
  29684. var result = entityExportFn ? entityExportFn(entity, originalText) : undefined;
  29685. if (result) {
  29686. return result;
  29687. }
  29688. var entityType = entity.type.toUpperCase();
  29689. filterByEditorId(extensionEntities, editorId).find(function (entityItem) {
  29690. if (entityItem.entityType === entityType) {
  29691. result = entityItem.exporter ? entityItem.exporter(entity, originalText) : undefined;
  29692. return true;
  29693. }
  29694. });
  29695. return result;
  29696. };
  29697. };
  29698. var compositeBlockImportFn = function compositeBlockImportFn(blockImportFn, editorId) {
  29699. return function (nodeName, node, source) {
  29700. var result = blockImportFn ? blockImportFn(nodeName, node, source) : null;
  29701. if (result) {
  29702. return result;
  29703. }
  29704. filterByEditorId(blockImporters, editorId).find(function (blockImporter) {
  29705. var matched = blockImporter.importer ? blockImporter.importer(nodeName, node, source) : undefined;
  29706. matched && (result = matched);
  29707. return !!matched;
  29708. });
  29709. return result;
  29710. };
  29711. };
  29712. var compositeBlockExportFn = function compositeBlockExportFn(blockExportFn, editorId) {
  29713. return function (contentState, block) {
  29714. var result = blockExportFn ? blockExportFn(contentState, block) : null;
  29715. if (result) {
  29716. return result;
  29717. }
  29718. filterByEditorId(blockExporters, editorId).find(function (blockExporter) {
  29719. var matched = blockExporter.exporter ? blockExporter.exporter(contentState, block) : undefined;
  29720. matched && (result = matched);
  29721. return !!matched;
  29722. });
  29723. return result;
  29724. };
  29725. };
  29726. var extension_useExtension = function useExtension(extension) {
  29727. if (extension instanceof Array) {
  29728. extension.forEach(useExtension);
  29729. return false;
  29730. }
  29731. if (!extension || !extension.type || typeof extension.type !== 'string') {
  29732. return false;
  29733. }
  29734. var includeEditors = extension.includeEditors,
  29735. excludeEditors = extension.excludeEditors;
  29736. if (extension.type === 'control') {
  29737. extension_extensionControls.push({
  29738. includeEditors: includeEditors,
  29739. excludeEditors: excludeEditors,
  29740. data: extension.control
  29741. });
  29742. } else if (extension.type === 'inline-style') {
  29743. var inlineStyleName = extension.name.toUpperCase();
  29744. if (extension.control) {
  29745. extension_extensionControls.push({
  29746. includeEditors: includeEditors,
  29747. excludeEditors: excludeEditors,
  29748. data: objectSpread_default()({
  29749. key: inlineStyleName,
  29750. type: 'inline-style',
  29751. command: inlineStyleName
  29752. }, extension.control)
  29753. });
  29754. }
  29755. if (extension.style) {
  29756. extensionInlineStyleMaps.push({
  29757. includeEditors: includeEditors,
  29758. excludeEditors: excludeEditors,
  29759. data: {
  29760. inlineStyleName: inlineStyleName,
  29761. styleMap: extension.style
  29762. }
  29763. });
  29764. }
  29765. if (extension.styleFn) {
  29766. extension_extensionInlineStyleFns.push({
  29767. includeEditors: includeEditors,
  29768. excludeEditors: excludeEditors,
  29769. data: {
  29770. inlineStyleName: inlineStyleName,
  29771. styleFn: extension.styleFn
  29772. }
  29773. });
  29774. }
  29775. if (extension.importer) {
  29776. inlineStyleImporters.push({
  29777. includeEditors: includeEditors,
  29778. excludeEditors: excludeEditors,
  29779. data: {
  29780. inlineStyleName: inlineStyleName,
  29781. importer: extension.importer
  29782. }
  29783. });
  29784. }
  29785. inlineStyleExporters.push({
  29786. includeEditors: includeEditors,
  29787. excludeEditors: excludeEditors,
  29788. data: {
  29789. inlineStyleName: inlineStyleName,
  29790. exporter: extension.exporter ? extension.exporter(extension) : external_react_default.a.createElement("span", {
  29791. style: extension.style
  29792. })
  29793. }
  29794. });
  29795. } else if (extension.type === 'block-style') ; else if (extension.type === 'entity') {
  29796. var entityType = extension.name.toUpperCase();
  29797. if (extension.control) {
  29798. extension_extensionControls.push({
  29799. includeEditors: includeEditors,
  29800. excludeEditors: excludeEditors,
  29801. data: typeof extension.control === 'function' ? extension.control : objectSpread_default()({
  29802. key: entityType,
  29803. type: 'entity',
  29804. command: entityType,
  29805. data: {
  29806. mutability: extension.mutability || 'MUTABLE',
  29807. data: extension.data || {}
  29808. }
  29809. }, extension.control)
  29810. });
  29811. }
  29812. extensionEntities.push({
  29813. includeEditors: includeEditors,
  29814. excludeEditors: excludeEditors,
  29815. data: {
  29816. entityType: entityType,
  29817. importer: extension.importer,
  29818. exporter: extension.exporter
  29819. }
  29820. });
  29821. extension_extensionDecorators.push({
  29822. includeEditors: includeEditors,
  29823. excludeEditors: excludeEditors,
  29824. data: {
  29825. type: 'entity',
  29826. decorator: {
  29827. key: entityType,
  29828. component: extension.component
  29829. }
  29830. }
  29831. });
  29832. } else if (extension.type === 'block') {
  29833. var blockType = extension.name;
  29834. if (extension.renderMap) {
  29835. extension_extensionBlockRenderMaps.push({
  29836. includeEditors: includeEditors,
  29837. excludeEditors: excludeEditors,
  29838. data: {
  29839. blockType: blockType,
  29840. renderMap: extension.renderMap
  29841. }
  29842. });
  29843. }
  29844. if (extension.rendererFn) {
  29845. extension_extensionBlockRendererFns.push({
  29846. includeEditors: includeEditors,
  29847. excludeEditors: excludeEditors,
  29848. data: {
  29849. blockType: blockType,
  29850. rendererFn: extension.rendererFn
  29851. }
  29852. });
  29853. }
  29854. if (extension.importer) {
  29855. blockImporters.push({
  29856. includeEditors: includeEditors,
  29857. excludeEditors: excludeEditors,
  29858. data: {
  29859. blockType: blockType,
  29860. importer: extension.importer
  29861. }
  29862. });
  29863. }
  29864. if (extension.exporter) {
  29865. blockExporters.push({
  29866. includeEditors: includeEditors,
  29867. excludeEditors: excludeEditors,
  29868. data: {
  29869. blockType: blockType,
  29870. exporter: extension.exporter
  29871. }
  29872. });
  29873. }
  29874. } else if (extension.type === 'atomic') ; else if (extension.type === 'decorator') {
  29875. var decorator = extension.decorator;
  29876. if (decorator && decorator.strategy && decorator.component) {
  29877. extension_extensionDecorators.push({
  29878. includeEditors: includeEditors,
  29879. excludeEditors: excludeEditors,
  29880. data: {
  29881. type: 'strategy',
  29882. decorator: decorator
  29883. }
  29884. });
  29885. } else if (decorator && decorator.getDecorations) {
  29886. extension_extensionDecorators.push({
  29887. includeEditors: includeEditors,
  29888. excludeEditors: excludeEditors,
  29889. data: {
  29890. type: 'class',
  29891. decorator: decorator
  29892. }
  29893. });
  29894. }
  29895. } else if (extension.type === 'prop-interception') {
  29896. extension_propInterceptors.push({
  29897. includeEditors: includeEditors,
  29898. excludeEditors: excludeEditors,
  29899. data: extension.interceptor
  29900. });
  29901. }
  29902. };
  29903. var createExtensibleEditor = function createExtensibleEditor(BraftEditor) {
  29904. BraftEditor.use = extension_useExtension;
  29905. return BraftEditor;
  29906. };
  29907. // CONCATENATED MODULE: ./renderers/block/blockRenderMap.js
  29908. /* harmony default export */ var block_blockRenderMap = (function (props, blockRenderMap) {
  29909. var customBlockRenderMap = Object(external_immutable_["Map"])({
  29910. 'atomic': {
  29911. element: ''
  29912. },
  29913. 'code-block': {
  29914. element: 'code',
  29915. wrapper: external_react_default.a.createElement("pre", {
  29916. className: "braft-code-block"
  29917. })
  29918. }
  29919. });
  29920. try {
  29921. var extensionBlockRenderMaps = getExtensionBlockRenderMaps(props.editorId);
  29922. customBlockRenderMap = extensionBlockRenderMaps.reduce(function (customBlockRenderMap, item) {
  29923. return customBlockRenderMap.merge(typeof item.renderMap === 'function' ? item.renderMap(props) : item.renderMap);
  29924. }, customBlockRenderMap);
  29925. if (blockRenderMap) {
  29926. if (typeof blockRenderMap === 'function') {
  29927. customBlockRenderMap = customBlockRenderMap.merge(blockRenderMap(props));
  29928. } else {
  29929. customBlockRenderMap = customBlockRenderMap.merge(blockRenderMap);
  29930. }
  29931. }
  29932. customBlockRenderMap = external_draft_js_["DefaultDraftBlockRenderMap"].merge(customBlockRenderMap);
  29933. } catch (error) {
  29934. console.warn(error);
  29935. }
  29936. return customBlockRenderMap;
  29937. });
  29938. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/extends.js
  29939. var helpers_extends = __webpack_require__(11);
  29940. var extends_default = /*#__PURE__*/__webpack_require__.n(helpers_extends);
  29941. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/slicedToArray.js
  29942. var slicedToArray = __webpack_require__(24);
  29943. var slicedToArray_default = /*#__PURE__*/__webpack_require__.n(slicedToArray);
  29944. // EXTERNAL MODULE: ./renderers/atomics/Image/style.scss
  29945. var Image_style = __webpack_require__(45);
  29946. // EXTERNAL MODULE: ./components/common/Switch/style.scss
  29947. var Switch_style = __webpack_require__(46);
  29948. // CONCATENATED MODULE: ./components/common/Switch/index.jsx
  29949. /* harmony default export */ var Switch = (function (props) {
  29950. var active = props.active,
  29951. _onClick = props.onClick,
  29952. className = props.className;
  29953. return external_react_default.a.createElement("div", {
  29954. onClick: function onClick() {
  29955. return _onClick();
  29956. },
  29957. className: 'bf-switch ' + className + (active ? ' active' : '')
  29958. });
  29959. });
  29960. // CONCATENATED MODULE: ./configs/controls.js
  29961. /* harmony default export */ var configs_controls = (function (lang, editor) {
  29962. return [{
  29963. key: 'undo',
  29964. title: lang.controls.undo,
  29965. text: external_react_default.a.createElement("i", {
  29966. className: "bfi-undo"
  29967. }),
  29968. type: 'editor-method',
  29969. command: 'undo'
  29970. }, {
  29971. key: 'redo',
  29972. title: lang.controls.redo,
  29973. text: external_react_default.a.createElement("i", {
  29974. className: "bfi-redo"
  29975. }),
  29976. type: 'editor-method',
  29977. command: 'redo'
  29978. }, {
  29979. key: 'remove-styles',
  29980. title: lang.controls.removeStyles,
  29981. text: external_react_default.a.createElement("i", {
  29982. className: "bfi-format_clear"
  29983. }),
  29984. type: 'editor-method',
  29985. command: 'removeSelectionInlineStyles'
  29986. }, {
  29987. key: 'hr',
  29988. title: lang.controls.hr,
  29989. text: external_react_default.a.createElement("i", {
  29990. className: "bfi-hr"
  29991. }),
  29992. type: 'editor-method',
  29993. command: 'insertHorizontalLine'
  29994. }, {
  29995. key: 'bold',
  29996. title: lang.controls.bold,
  29997. text: external_react_default.a.createElement("i", {
  29998. className: "bfi-bold"
  29999. }),
  30000. type: 'inline-style',
  30001. command: 'bold'
  30002. }, {
  30003. key: 'italic',
  30004. title: lang.controls.italic,
  30005. text: external_react_default.a.createElement("i", {
  30006. className: "bfi-italic"
  30007. }),
  30008. type: 'inline-style',
  30009. command: 'italic'
  30010. }, {
  30011. key: 'underline',
  30012. title: lang.controls.underline,
  30013. text: external_react_default.a.createElement("i", {
  30014. className: "bfi-underlined"
  30015. }),
  30016. type: 'inline-style',
  30017. command: 'underline'
  30018. }, {
  30019. key: 'strike-through',
  30020. title: lang.controls.strikeThrough,
  30021. text: external_react_default.a.createElement("i", {
  30022. className: "bfi-strikethrough"
  30023. }),
  30024. type: 'inline-style',
  30025. command: 'strikethrough'
  30026. }, {
  30027. key: 'superscript',
  30028. title: lang.controls.superScript,
  30029. text: external_react_default.a.createElement("i", {
  30030. className: "bfi-superscript"
  30031. }),
  30032. type: 'inline-style',
  30033. command: 'superscript'
  30034. }, {
  30035. key: 'subscript',
  30036. title: lang.controls.subScript,
  30037. text: external_react_default.a.createElement("i", {
  30038. className: "bfi-subscript"
  30039. }),
  30040. type: 'inline-style',
  30041. command: 'subscript'
  30042. }, {
  30043. key: 'headings',
  30044. title: lang.controls.headings,
  30045. type: 'headings'
  30046. }, {
  30047. key: 'blockquote',
  30048. title: lang.controls.blockQuote,
  30049. text: external_react_default.a.createElement("i", {
  30050. className: "bfi-quote"
  30051. }),
  30052. type: 'block-type',
  30053. command: 'blockquote'
  30054. }, {
  30055. key: 'code',
  30056. title: lang.controls.code,
  30057. text: external_react_default.a.createElement("i", {
  30058. className: "bfi-code"
  30059. }),
  30060. type: 'block-type',
  30061. command: 'code-block'
  30062. }, {
  30063. key: 'list-ul',
  30064. title: lang.controls.unorderedList,
  30065. text: external_react_default.a.createElement("i", {
  30066. className: "bfi-list"
  30067. }),
  30068. type: 'block-type',
  30069. command: 'unordered-list-item'
  30070. }, {
  30071. key: 'list-ol',
  30072. title: lang.controls.orderedList,
  30073. text: external_react_default.a.createElement("i", {
  30074. className: "bfi-list-numbered"
  30075. }),
  30076. type: 'block-type',
  30077. command: 'ordered-list-item'
  30078. }, {
  30079. key: 'link',
  30080. title: lang.controls.link,
  30081. type: 'link'
  30082. }, {
  30083. key: 'text-color',
  30084. title: lang.controls.color,
  30085. type: 'text-color'
  30086. }, {
  30087. key: 'line-height',
  30088. title: lang.controls.lineHeight,
  30089. type: 'line-height'
  30090. }, {
  30091. key: 'letter-spacing',
  30092. title: lang.controls.letterSpacing,
  30093. type: 'letter-spacing'
  30094. }, {
  30095. key: 'text-indent',
  30096. title: lang.controls.textIndent,
  30097. type: 'text-indent'
  30098. }, {
  30099. key: 'font-size',
  30100. title: lang.controls.fontSize,
  30101. type: 'font-size'
  30102. }, {
  30103. key: 'font-family',
  30104. title: lang.controls.fontFamily,
  30105. type: 'font-family'
  30106. }, {
  30107. key: 'text-align',
  30108. title: lang.controls.textAlign,
  30109. type: 'text-align'
  30110. }, {
  30111. key: 'media',
  30112. title: lang.controls.media,
  30113. text: external_react_default.a.createElement("i", {
  30114. className: "bfi-media"
  30115. }),
  30116. type: 'media'
  30117. }, {
  30118. key: 'emoji',
  30119. title: lang.controls.emoji,
  30120. text: external_react_default.a.createElement("i", {
  30121. className: "bfi-emoji"
  30122. }),
  30123. type: 'emoji'
  30124. }, {
  30125. key: 'clear',
  30126. title: lang.controls.clear,
  30127. text: external_react_default.a.createElement("i", {
  30128. className: "bfi-clear_all"
  30129. }),
  30130. type: 'editor-method',
  30131. command: 'clearEditorContent'
  30132. }, {
  30133. key: 'fullscreen',
  30134. title: editor.state.isFullscreen ? lang.controls.exitFullscreen : lang.controls.fullscreen,
  30135. text: external_react_default.a.createElement("i", {
  30136. className: editor.state.isFullscreen ? 'bfi-fullscreen-exit' : 'bfi-fullscreen'
  30137. }),
  30138. type: 'editor-method',
  30139. command: 'toggleFullscreen'
  30140. }, {
  30141. key: 'modal',
  30142. type: 'modal'
  30143. }, {
  30144. key: 'button',
  30145. type: 'button'
  30146. }, {
  30147. key: 'dropdown',
  30148. type: 'dropdown'
  30149. }, {
  30150. key: 'component',
  30151. type: 'component'
  30152. }];
  30153. });
  30154. var imageControlItems = {
  30155. 'float-left': {
  30156. text: external_react_default.a.createElement("span", {
  30157. "data-float": "left"
  30158. }, "\uE91E"),
  30159. command: 'setImageFloat|left'
  30160. },
  30161. 'float-right': {
  30162. text: external_react_default.a.createElement("span", {
  30163. "data-float": "right"
  30164. }, "\uE914"),
  30165. command: 'setImageFloat|right'
  30166. },
  30167. 'align-left': {
  30168. text: external_react_default.a.createElement("span", {
  30169. "data-align": "left"
  30170. }, "\uE027"),
  30171. command: 'setImageAlignment|left'
  30172. },
  30173. 'align-center': {
  30174. text: external_react_default.a.createElement("span", {
  30175. "data-align": "center"
  30176. }, "\uE028"),
  30177. command: 'setImageAlignment|center'
  30178. },
  30179. 'align-right': {
  30180. text: external_react_default.a.createElement("span", {
  30181. "data-align": "right"
  30182. }, "\uE029"),
  30183. command: 'setImageAlignment|right'
  30184. },
  30185. 'size': {
  30186. text: external_react_default.a.createElement("span", null, "\uE3C2"),
  30187. command: 'toggleSizeEditor'
  30188. },
  30189. 'link': {
  30190. text: external_react_default.a.createElement("span", null, "\uE91A"),
  30191. command: 'toggleLinkEditor'
  30192. },
  30193. 'remove': {
  30194. text: external_react_default.a.createElement("span", null, "\uE9AC"),
  30195. command: 'removeImage'
  30196. }
  30197. };
  30198. // CONCATENATED MODULE: ./renderers/atomics/Image/index.jsx
  30199. var Image_Image =
  30200. /*#__PURE__*/
  30201. function (_React$Component) {
  30202. inherits_default()(Image, _React$Component);
  30203. function Image() {
  30204. var _getPrototypeOf2;
  30205. var _this;
  30206. classCallCheck_default()(this, Image);
  30207. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  30208. args[_key] = arguments[_key];
  30209. }
  30210. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(Image)).call.apply(_getPrototypeOf2, [this].concat(args)));
  30211. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "state", {
  30212. toolbarVisible: false,
  30213. toolbarOffset: 0,
  30214. linkEditorVisible: false,
  30215. sizeEditorVisible: false,
  30216. tempLink: null,
  30217. tempWidth: null,
  30218. tempHeight: null
  30219. });
  30220. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "initialLeft", void 0);
  30221. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "initialTop", void 0);
  30222. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "initialWidth", void 0);
  30223. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "initialHeight", void 0);
  30224. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "reSizeType", void 0);
  30225. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "changeSize", function (e) {
  30226. var type = _this.reSizeType;
  30227. if (!_this.initialLeft) {
  30228. _this.initialLeft = e.screenX;
  30229. _this.initialTop = e.screenY;
  30230. }
  30231. if (type === 'rightbottom') {
  30232. _this.initialHeight += e.screenY - _this.initialTop;
  30233. _this.initialWidth += e.screenX - _this.initialLeft;
  30234. }
  30235. if (type === 'leftbottom') {
  30236. _this.initialHeight += e.screenY - _this.initialTop;
  30237. _this.initialWidth += -e.screenX + _this.initialLeft;
  30238. }
  30239. _this.initialLeft = e.screenX;
  30240. _this.initialTop = e.screenY;
  30241. });
  30242. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "moveImage", function (e) {
  30243. _this.changeSize(e);
  30244. _this.setState({
  30245. tempWidth: Math.abs(_this.initialWidth),
  30246. tempHeight: Math.abs(_this.initialHeight)
  30247. });
  30248. });
  30249. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "upImage", function () {
  30250. _this.confirmImageSize();
  30251. document.removeEventListener('mousemove', _this.moveImage);
  30252. document.removeEventListener('mouseup', _this.upImage);
  30253. });
  30254. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "repareChangeSize", function (type) {
  30255. return function (e) {
  30256. _this.reSizeType = type;
  30257. var imageRect = _this.imageElement.getBoundingClientRect();
  30258. _this.initialLeft = _this.initialTop = 0;
  30259. _this.initialWidth = imageRect.width;
  30260. _this.initialHeight = imageRect.height;
  30261. e.preventDefault();
  30262. document.addEventListener('mousemove', _this.moveImage);
  30263. document.addEventListener('mouseup', _this.upImage);
  30264. };
  30265. });
  30266. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "preventDragEvent", function (event) {
  30267. event.stopPropagation();
  30268. event.preventDefault();
  30269. });
  30270. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleDragStart", function () {
  30271. if (_this.props.editor.editorProps.readOnly || _this.props.editor.editorProps.disabled) {
  30272. return false;
  30273. }
  30274. window.__BRAFT_DRAGING__IMAGE__ = {
  30275. block: _this.props.block,
  30276. mediaData: objectSpread_default()({
  30277. type: 'IMAGE'
  30278. }, _this.props.mediaData)
  30279. };
  30280. _this.setState({
  30281. toolbarVisible: false
  30282. }, function () {
  30283. _this.unlockEditor();
  30284. });
  30285. return true;
  30286. });
  30287. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleDragEnd", function () {
  30288. window.__BRAFT_DRAGING__IMAGE__ = null;
  30289. return false;
  30290. });
  30291. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "executeCommand", function (command) {
  30292. if (typeof command === 'string') {
  30293. var _command$split = command.split('|'),
  30294. _command$split2 = slicedToArray_default()(_command$split, 2),
  30295. method = _command$split2[0],
  30296. param = _command$split2[1];
  30297. _this[method] && _this[method](param);
  30298. } else if (typeof command === 'function') {
  30299. command(_this.props.block, _this.props.mediaData, _this.props.editor.getValue());
  30300. }
  30301. });
  30302. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "removeImage", function () {
  30303. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].removeBlock(_this.props.editor.getValue(), _this.props.block));
  30304. _this.unlockEditor();
  30305. });
  30306. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "toggleLinkEditor", function () {
  30307. _this.setState({
  30308. linkEditorVisible: !_this.state.linkEditorVisible,
  30309. sizeEditorVisible: false
  30310. });
  30311. });
  30312. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "toggleSizeEditor", function () {
  30313. _this.setState({
  30314. linkEditorVisible: false,
  30315. sizeEditorVisible: !_this.state.sizeEditorVisible
  30316. });
  30317. });
  30318. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleLinkInputKeyDown", function (e) {
  30319. if (e.keyCode === 13) {
  30320. _this.confirmImageLink();
  30321. } else {
  30322. return;
  30323. }
  30324. });
  30325. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "setImageLink", function (e) {
  30326. _this.setState({
  30327. tempLink: e.currentTarget.value
  30328. });
  30329. return;
  30330. });
  30331. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "confirmImageLink", function () {
  30332. var link = _this.state.tempLink;
  30333. var hookReturns = _this.props.hooks('set-image-link', link)(link);
  30334. if (hookReturns === false) {
  30335. return false;
  30336. }
  30337. if (typeof hookReturns === 'string') {
  30338. link = hookReturns;
  30339. }
  30340. if (link !== null) {
  30341. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].setMediaData(_this.props.editor.getValue(), _this.props.entityKey, {
  30342. link: link
  30343. }));
  30344. window.setImmediate(_this.props.editor.forceRender);
  30345. }
  30346. });
  30347. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleSizeInputKeyDown", function (e) {
  30348. if (e.keyCode === 13) {
  30349. _this.confirmImageSize();
  30350. } else {
  30351. return;
  30352. }
  30353. });
  30354. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "setImageWidth", function (_ref) {
  30355. var currentTarget = _ref.currentTarget;
  30356. var value = currentTarget.value;
  30357. value && !isNaN(value) && (value = value + 'px');
  30358. _this.setState({
  30359. tempWidth: value
  30360. });
  30361. return;
  30362. });
  30363. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "setImageHeight", function (_ref2) {
  30364. var currentTarget = _ref2.currentTarget;
  30365. var value = currentTarget.value;
  30366. value && !isNaN(value) && (value = value + 'px');
  30367. _this.setState({
  30368. tempHeight: value
  30369. });
  30370. return;
  30371. });
  30372. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "confirmImageSize", function () {
  30373. var _this$state = _this.state,
  30374. width = _this$state.tempWidth,
  30375. height = _this$state.tempHeight;
  30376. var newImageSize = {};
  30377. width !== null && (newImageSize.width = width);
  30378. height !== null && (newImageSize.height = height);
  30379. var hookReturns = _this.props.hooks('set-image-size', newImageSize)(newImageSize);
  30380. if (hookReturns === false) {
  30381. return false;
  30382. }
  30383. if (hookReturns && (hookReturns.width || hookReturns.height)) {
  30384. newImageSize = hookReturns;
  30385. }
  30386. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].setMediaData(_this.props.editor.getValue(), _this.props.entityKey, newImageSize));
  30387. window.setImmediate(_this.props.editor.forceRender);
  30388. });
  30389. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "setImageFloat", function (float) {
  30390. var hookReturns = _this.props.hooks('set-image-float', float)(float);
  30391. if (hookReturns === false) {
  30392. return false;
  30393. }
  30394. if (typeof hookReturns === 'string') {
  30395. float = hookReturns;
  30396. }
  30397. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].setMediaPosition(_this.props.editor.getValue(), _this.props.block, {
  30398. float: float
  30399. }));
  30400. _this.unlockEditor();
  30401. });
  30402. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "setImageAlignment", function (alignment) {
  30403. var hookReturns = _this.props.hooks('set-image-alignment', alignment)(alignment);
  30404. if (hookReturns === false) {
  30405. return false;
  30406. }
  30407. if (typeof hookReturns === 'string') {
  30408. alignment = hookReturns;
  30409. }
  30410. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].setMediaPosition(_this.props.editor.getValue(), _this.props.block, {
  30411. alignment: alignment
  30412. }));
  30413. _this.unlockEditor();
  30414. });
  30415. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "showToolbar", function (event) {
  30416. if (_this.props.editor.editorProps.readOnly || _this.props.editor.editorProps.disabled) {
  30417. return false;
  30418. }
  30419. event.preventDefault();
  30420. if (!_this.state.toolbarVisible) {
  30421. _this.setState({
  30422. toolbarVisible: true
  30423. }, function () {
  30424. _this.lockEditor();
  30425. _this.setState({
  30426. toolbarOffset: _this.calcToolbarOffset()
  30427. });
  30428. });
  30429. }
  30430. });
  30431. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "hideToolbar", function (event) {
  30432. event.preventDefault();
  30433. _this.setState({
  30434. toolbarVisible: false
  30435. }, function () {
  30436. _this.unlockEditor(); // this.props.editor.requestFocus()
  30437. });
  30438. });
  30439. return _this;
  30440. }
  30441. createClass_default()(Image, [{
  30442. key: "render",
  30443. value: function render() {
  30444. var _this2 = this;
  30445. var _this$props = this.props,
  30446. mediaData = _this$props.mediaData,
  30447. language = _this$props.language,
  30448. imageControls = _this$props.imageControls,
  30449. imageResizable = _this$props.imageResizable;
  30450. var _this$state2 = this.state,
  30451. toolbarVisible = _this$state2.toolbarVisible,
  30452. toolbarOffset = _this$state2.toolbarOffset,
  30453. linkEditorVisible = _this$state2.linkEditorVisible,
  30454. sizeEditorVisible = _this$state2.sizeEditorVisible,
  30455. tempWidth = _this$state2.tempWidth,
  30456. tempHeight = _this$state2.tempHeight;
  30457. var blockData = this.props.block.getData();
  30458. var float = blockData.get('float');
  30459. var alignment = blockData.get('alignment');
  30460. var url = mediaData.url,
  30461. link = mediaData.link,
  30462. link_target = mediaData.link_target,
  30463. width = mediaData.width,
  30464. height = mediaData.height,
  30465. meta = mediaData.meta;
  30466. var imageStyles = {};
  30467. var clearFix = false;
  30468. if (float) {
  30469. alignment = null;
  30470. } else if (alignment === 'left') {
  30471. imageStyles.float = 'left';
  30472. clearFix = true;
  30473. } else if (alignment === 'right') {
  30474. imageStyles.float = 'right';
  30475. clearFix = true;
  30476. } else if (alignment === 'center') {
  30477. imageStyles.textAlign = 'center';
  30478. } else {
  30479. imageStyles.float = 'left';
  30480. clearFix = true;
  30481. }
  30482. var renderedControlItems = imageControls.map(function (item, index) {
  30483. if (typeof item === 'string' && imageControlItems[item]) {
  30484. return external_react_default.a.createElement("a", {
  30485. className: item === 'link' && link ? 'active' : '',
  30486. key: index,
  30487. onClick: function onClick() {
  30488. return _this2.executeCommand(imageControlItems[item].command);
  30489. }
  30490. }, imageControlItems[item].text);
  30491. } else if (item && (item.render || item.text)) {
  30492. return item.render ? item.render(mediaData, _this2.props.block) : external_react_default.a.createElement("a", {
  30493. key: index,
  30494. onClick: function onClick() {
  30495. return item.onClick && _this2.executeCommand(item.onClick);
  30496. }
  30497. }, item.text);
  30498. } else {
  30499. return null;
  30500. }
  30501. });
  30502. return external_react_default.a.createElement("div", {
  30503. className: "bf-media"
  30504. }, external_react_default.a.createElement("div", {
  30505. style: imageStyles,
  30506. draggable: true,
  30507. onMouseEnter: this.showToolbar,
  30508. onMouseMove: this.showToolbar,
  30509. onMouseLeave: this.hideToolbar,
  30510. onDragStart: this.handleDragStart,
  30511. onDragEnd: this.handleDragEnd,
  30512. ref: function ref(instance) {
  30513. return _this2.mediaEmbederInstance = instance;
  30514. },
  30515. className: "bf-image"
  30516. }, toolbarVisible ? external_react_default.a.createElement("div", {
  30517. style: {
  30518. marginLeft: toolbarOffset
  30519. },
  30520. ref: function ref(instance) {
  30521. return _this2.toolbarElement = instance;
  30522. },
  30523. "data-float": float,
  30524. "data-align": alignment,
  30525. className: "bf-media-toolbar"
  30526. }, linkEditorVisible ? external_react_default.a.createElement("div", {
  30527. className: "bf-image-link-editor"
  30528. }, external_react_default.a.createElement("div", {
  30529. className: "editor-input-group"
  30530. }, external_react_default.a.createElement("input", {
  30531. type: "text",
  30532. placeholder: language.linkEditor.inputWithEnterPlaceHolder,
  30533. onKeyDown: this.handleLinkInputKeyDown,
  30534. onChange: this.setImageLink,
  30535. defaultValue: link
  30536. }), external_react_default.a.createElement("button", {
  30537. type: "button",
  30538. onClick: this.confirmImageLink
  30539. }, language.base.confirm)), external_react_default.a.createElement("div", {
  30540. className: "switch-group"
  30541. }, external_react_default.a.createElement(Switch, {
  30542. active: link_target === '_blank',
  30543. onClick: function onClick() {
  30544. return _this2.setImageLinkTarget(link_target);
  30545. }
  30546. }), external_react_default.a.createElement("label", null, language.linkEditor.openInNewWindow))) : null, sizeEditorVisible ? external_react_default.a.createElement("div", {
  30547. className: "bf-image-size-editor"
  30548. }, external_react_default.a.createElement("div", {
  30549. className: "editor-input-group"
  30550. }, external_react_default.a.createElement("input", {
  30551. type: "text",
  30552. placeholder: language.base.width,
  30553. onKeyDown: this.handleSizeInputKeyDown,
  30554. onChange: this.setImageWidth,
  30555. defaultValue: width
  30556. }), external_react_default.a.createElement("input", {
  30557. type: "text",
  30558. placeholder: language.base.height,
  30559. onKeyDown: this.handleSizeInputKeyDown,
  30560. onChange: this.setImageHeight,
  30561. defaultValue: height
  30562. }), external_react_default.a.createElement("button", {
  30563. type: "button",
  30564. onClick: this.confirmImageSize
  30565. }, language.base.confirm))) : null, renderedControlItems, external_react_default.a.createElement("i", {
  30566. style: {
  30567. marginLeft: toolbarOffset * -1
  30568. },
  30569. className: "bf-media-toolbar-arrow"
  30570. })) : null, external_react_default.a.createElement("div", {
  30571. style: {
  30572. position: 'relative',
  30573. width: "".concat(width, "px"),
  30574. height: "".concat(height, "px"),
  30575. display: 'inline-block'
  30576. }
  30577. }, external_react_default.a.createElement("img", extends_default()({
  30578. ref: function ref(instance) {
  30579. return _this2.imageElement = instance;
  30580. },
  30581. src: url,
  30582. width: width,
  30583. height: height
  30584. }, meta)), toolbarVisible && imageResizable ? external_react_default.a.createElement("div", {
  30585. className: "bf-csize-icon right-bottom",
  30586. onMouseDown: this.repareChangeSize('rightbottom')
  30587. }) : null, toolbarVisible && imageResizable ? external_react_default.a.createElement("div", {
  30588. className: "bf-csize-icon left-bottom",
  30589. onMouseDown: this.repareChangeSize('leftbottom')
  30590. }) : null, external_react_default.a.createElement("div", {
  30591. className: "bf-pre-csize ".concat(this.reSizeType),
  30592. style: {
  30593. width: "".concat(tempWidth, "px"),
  30594. height: "".concat(tempHeight, "px")
  30595. }
  30596. }))), clearFix && external_react_default.a.createElement("div", {
  30597. className: "clearfix",
  30598. style: {
  30599. clear: 'both',
  30600. height: 0,
  30601. lineHeight: 0,
  30602. float: 'none'
  30603. }
  30604. }));
  30605. }
  30606. }, {
  30607. key: "lockEditor",
  30608. value: function lockEditor() {
  30609. this.props.editor.lockOrUnlockEditor(true);
  30610. }
  30611. }, {
  30612. key: "unlockEditor",
  30613. value: function unlockEditor() {
  30614. this.props.editor.lockOrUnlockEditor(false);
  30615. }
  30616. }, {
  30617. key: "calcToolbarOffset",
  30618. value: function calcToolbarOffset() {
  30619. var _this$props2 = this.props,
  30620. getContainerNode = _this$props2.getContainerNode,
  30621. containerNode = _this$props2.containerNode;
  30622. var container = getContainerNode ? getContainerNode() : containerNode;
  30623. if (!container) {
  30624. return 0;
  30625. }
  30626. var viewRect = container.querySelector('.bf-content').getBoundingClientRect();
  30627. var toolbarRect = this.toolbarElement.getBoundingClientRect();
  30628. var imageRect = this.imageElement.getBoundingClientRect();
  30629. var right = viewRect.right - (imageRect.right - imageRect.width / 2 + toolbarRect.width / 2);
  30630. var left = imageRect.left + imageRect.width / 2 - toolbarRect.width / 2 - viewRect.left;
  30631. if (right < 10) {
  30632. return right - 10;
  30633. } else if (left < 10) {
  30634. return left * -1 + 10;
  30635. } else {
  30636. return 0;
  30637. }
  30638. }
  30639. }, {
  30640. key: "setImageLinkTarget",
  30641. value: function setImageLinkTarget(link_target) {
  30642. var hookReturns = this.props.hooks('set-image-link-target', link_target)(link_target);
  30643. if (hookReturns === false) {
  30644. return false;
  30645. }
  30646. if (typeof hookReturns === 'string') {
  30647. link_target = hookReturns;
  30648. }
  30649. link_target = link_target === '_blank' ? '' : '_blank';
  30650. this.props.editor.setValue(external_braft_utils_["ContentUtils"].setMediaData(this.props.editor.getValue(), this.props.entityKey, {
  30651. link_target: link_target
  30652. }));
  30653. window.setImmediate(this.props.editor.forceRender);
  30654. }
  30655. }]);
  30656. return Image;
  30657. }(external_react_default.a.Component);
  30658. // EXTERNAL MODULE: ./renderers/atomics/Video/style.scss
  30659. var Video_style = __webpack_require__(47);
  30660. // EXTERNAL MODULE: ./components/common/Modal/style.scss
  30661. var Modal_style = __webpack_require__(48);
  30662. // EXTERNAL MODULE: external "react-dom"
  30663. var external_react_dom_ = __webpack_require__(16);
  30664. var external_react_dom_default = /*#__PURE__*/__webpack_require__.n(external_react_dom_);
  30665. // CONCATENATED MODULE: ./components/common/Modal/index.jsx
  30666. var Modal_Modal =
  30667. /*#__PURE__*/
  30668. function (_React$Component) {
  30669. inherits_default()(Modal, _React$Component);
  30670. function Modal(props) {
  30671. var _this;
  30672. classCallCheck_default()(this, Modal);
  30673. _this = possibleConstructorReturn_default()(this, getPrototypeOf_default()(Modal).call(this, props));
  30674. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleTransitionEnd", function () {
  30675. if (!_this.rootElement || !_this.rootElement.classList) {
  30676. return false;
  30677. }
  30678. if (!_this.rootElement.classList.contains('active')) {
  30679. external_react_dom_default.a.unmountComponentAtNode(_this.rootElement) && _this.rootElement.parentNode.removeChild(_this.rootElement);
  30680. }
  30681. });
  30682. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleMouseDown", function (event) {
  30683. var tagName = event.target.tagName.toLowerCase();
  30684. if (tagName === 'input' || tagName === 'textarea') {
  30685. return false;
  30686. }
  30687. event.preventDefault();
  30688. });
  30689. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleCancel", function () {
  30690. _this.props.closeOnCancel && _this.close();
  30691. _this.props.onCancel && _this.props.onCancel();
  30692. });
  30693. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleConfirm", function () {
  30694. _this.props.closeOnConfirm && _this.close();
  30695. _this.props.onConfirm && _this.props.onConfirm();
  30696. });
  30697. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleMaskClick", function () {
  30698. _this.props.closeOnBlur && _this.close();
  30699. _this.props.onBlue && _this.props.onBlue();
  30700. });
  30701. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "close", function () {
  30702. _this.unrenderComponent();
  30703. _this.props.onClose && _this.props.onClose();
  30704. });
  30705. _this.active = false;
  30706. _this.componentId = 'BRAFT-MODAL-' + external_braft_utils_["BaseUtils"].UniqueIndex();
  30707. return _this;
  30708. }
  30709. createClass_default()(Modal, [{
  30710. key: "componentDidMount",
  30711. value: function componentDidMount() {
  30712. if (this.props.visible) {
  30713. this.active = true;
  30714. this.renderComponent(this.props);
  30715. }
  30716. }
  30717. }, {
  30718. key: "componentWillReceiveProps",
  30719. value: function componentWillReceiveProps(next) {
  30720. if (this.props.visible && !next.visible) {
  30721. this.unrenderComponent();
  30722. } else if (this.props.visible || next.visible) {
  30723. this.active = true;
  30724. this.renderComponent(next);
  30725. }
  30726. }
  30727. }, {
  30728. key: "render",
  30729. value: function render() {
  30730. return null;
  30731. }
  30732. }, {
  30733. key: "unrenderComponent",
  30734. value: function unrenderComponent() {
  30735. this.active = false;
  30736. this.activeId && window.clearImmediate(this.activeId);
  30737. if (this.rootElement && this.rootElement.classList) {
  30738. this.rootElement.classList.remove('active');
  30739. }
  30740. }
  30741. }, {
  30742. key: "renderComponent",
  30743. value: function renderComponent(props) {
  30744. var _this2 = this;
  30745. if (!this.active) {
  30746. return false;
  30747. }
  30748. var title = props.title,
  30749. className = props.className,
  30750. width = props.width,
  30751. height = props.height,
  30752. children = props.children,
  30753. component = props.component,
  30754. confirmable = props.confirmable,
  30755. showFooter = props.showFooter,
  30756. showCancel = props.showCancel,
  30757. showConfirm = props.showConfirm,
  30758. showClose = props.showClose,
  30759. cancelText = props.cancelText,
  30760. confirmText = props.confirmText,
  30761. bottomText = props.bottomText,
  30762. language = props.language;
  30763. typeof showCancel === 'undefined' && (showCancel = true);
  30764. typeof showClose === 'undefined' && (showClose = true);
  30765. typeof showConfirm === 'undefined' && (showConfirm = true);
  30766. typeof showFooter === 'undefined' && (showFooter = true);
  30767. var childComponent = external_react_default.a.createElement("div", {
  30768. onMouseDown: this.handleMouseDown,
  30769. className: 'bf-modal ' + (className || '')
  30770. }, external_react_default.a.createElement("div", {
  30771. className: "bf-modal-mask",
  30772. onClick: this.handleMaskClick
  30773. }), external_react_default.a.createElement("div", {
  30774. onTransitionEnd: this.handleTransitionEnd,
  30775. style: {
  30776. width: width,
  30777. height: height
  30778. },
  30779. className: "bf-modal-content"
  30780. }, external_react_default.a.createElement("div", {
  30781. className: "bf-modal-header"
  30782. }, external_react_default.a.createElement("h3", {
  30783. className: "bf-modal-caption"
  30784. }, title), showClose && external_react_default.a.createElement("button", {
  30785. type: "button",
  30786. onClick: this.close,
  30787. className: "bf-modal-close-button"
  30788. }, external_react_default.a.createElement("i", {
  30789. className: "bfi-close"
  30790. }))), external_react_default.a.createElement("div", {
  30791. className: "bf-modal-body"
  30792. }, children || component), showFooter ? external_react_default.a.createElement("div", {
  30793. className: "bf-modal-footer"
  30794. }, external_react_default.a.createElement("div", {
  30795. className: "bf-modal-addon-text"
  30796. }, bottomText), external_react_default.a.createElement("div", {
  30797. className: "bf-modal-buttons"
  30798. }, showCancel && external_react_default.a.createElement("button", {
  30799. type: "button",
  30800. onClick: this.handleCancel,
  30801. className: "bf-modal-cancel"
  30802. }, cancelText || language.base.cancel), showConfirm && external_react_default.a.createElement("button", {
  30803. type: "button",
  30804. onClick: this.handleConfirm,
  30805. className: 'bf-modal-confirm ' + (!confirmable ? 'disabled' : '')
  30806. }, confirmText || language.base.confirm))) : null));
  30807. this.rootElement = document.querySelector('#' + this.componentId);
  30808. if (!this.rootElement) {
  30809. this.rootElement = document.createElement('div');
  30810. this.rootElement.id = this.componentId;
  30811. this.rootElement.className = 'bf-modal-root';
  30812. document.body.appendChild(this.rootElement);
  30813. }
  30814. external_react_dom_default.a.render(childComponent, this.rootElement);
  30815. this.activeId = window.setImmediate(function () {
  30816. _this2.rootElement.classList.add('active');
  30817. });
  30818. }
  30819. }]);
  30820. return Modal;
  30821. }(external_react_default.a.Component);
  30822. defineProperty_default()(Modal_Modal, "defaultProps", {
  30823. showFooter: true,
  30824. closeOnBlur: true
  30825. });
  30826. var Modal_showModal = function showModal(props) {
  30827. var hostNode = document.createElement('div');
  30828. hostNode.style.display = 'none';
  30829. document.body.appendChild(hostNode);
  30830. props = objectSpread_default()({
  30831. visible: true,
  30832. closeOnConfirm: true,
  30833. closeOnCancel: true
  30834. }, props);
  30835. var close = function close() {
  30836. external_react_dom_default.a.unmountComponentAtNode(hostNode) && hostNode.parentNode.removeChild(hostNode);
  30837. };
  30838. var onConfirm = function onConfirm() {
  30839. props.onConfirm && props.onConfirm();
  30840. };
  30841. var onCancel = function onCancel() {
  30842. props.onCancel && props.onCancel();
  30843. };
  30844. var onClose = function onClose() {
  30845. close();
  30846. props.onClose && props.onClose();
  30847. };
  30848. var modalInstance = external_react_dom_default.a.render(external_react_default.a.createElement(Modal_Modal, extends_default()({}, props, {
  30849. onConfirm: onConfirm,
  30850. onCancel: onCancel,
  30851. onClose: onClose
  30852. })), hostNode);
  30853. modalInstance.destroy = close;
  30854. modalInstance.update = modalInstance.renderComponent;
  30855. return modalInstance;
  30856. };
  30857. // EXTERNAL MODULE: ./components/business/PlayerModal/style.scss
  30858. var PlayerModal_style = __webpack_require__(49);
  30859. // CONCATENATED MODULE: ./components/business/PlayerModal/index.jsx
  30860. var PlayerModal_playViaModal = function playViaModal(title, component, language) {
  30861. return Modal_showModal({
  30862. title: title,
  30863. component: component,
  30864. language: language,
  30865. showFooter: false
  30866. });
  30867. };
  30868. var typeIconsMap = {
  30869. 'video': 'bfi-film',
  30870. 'audio': 'bfi-music',
  30871. 'embed': 'bfi-code'
  30872. };
  30873. /* harmony default export */ var PlayerModal = (function (_ref) {
  30874. var title = _ref.title,
  30875. type = _ref.type,
  30876. language = _ref.language,
  30877. name = _ref.name,
  30878. url = _ref.url,
  30879. poster = _ref.poster,
  30880. children = _ref.children,
  30881. onRemove = _ref.onRemove;
  30882. return external_react_default.a.createElement("div", {
  30883. className: "bf-player-holder ".concat(type)
  30884. }, external_react_default.a.createElement("div", {
  30885. className: "icon-badge"
  30886. }, external_react_default.a.createElement("i", {
  30887. className: typeIconsMap[type]
  30888. }), external_react_default.a.createElement("span", {
  30889. className: "text"
  30890. }, language.media[type])), external_react_default.a.createElement("button", {
  30891. onMouseDown: onRemove,
  30892. className: "button-remove"
  30893. }, external_react_default.a.createElement("i", {
  30894. className: "bfi-close"
  30895. })), external_react_default.a.createElement("button", {
  30896. onMouseDown: function onMouseDown() {
  30897. return PlayerModal_playViaModal(name ? "".concat(title, ":").concat(name) : title, children, language);
  30898. },
  30899. className: "button-play"
  30900. }, external_react_default.a.createElement("i", {
  30901. className: "bfi-play_arrow"
  30902. })), name ? external_react_default.a.createElement("h5", {
  30903. className: "bf-name"
  30904. }, name) : null, external_react_default.a.createElement("h6", {
  30905. className: "bf-url"
  30906. }, url), poster ? external_react_default.a.createElement("div", {
  30907. className: "bf-poster",
  30908. style: {
  30909. backgroundImage: "url(".concat(poster, ")")
  30910. }
  30911. }) : null);
  30912. });
  30913. // CONCATENATED MODULE: ./renderers/atomics/Video/index.jsx
  30914. var Video_Video =
  30915. /*#__PURE__*/
  30916. function (_React$Component) {
  30917. inherits_default()(Video, _React$Component);
  30918. function Video() {
  30919. var _getPrototypeOf2;
  30920. var _this;
  30921. classCallCheck_default()(this, Video);
  30922. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  30923. args[_key] = arguments[_key];
  30924. }
  30925. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(Video)).call.apply(_getPrototypeOf2, [this].concat(args)));
  30926. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "removeVideo", function () {
  30927. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].removeBlock(_this.props.editorState, _this.props.block));
  30928. });
  30929. return _this;
  30930. }
  30931. createClass_default()(Video, [{
  30932. key: "render",
  30933. value: function render() {
  30934. var _this$props = this.props,
  30935. mediaData = _this$props.mediaData,
  30936. language = _this$props.language;
  30937. var url = mediaData.url,
  30938. name = mediaData.name,
  30939. meta = mediaData.meta;
  30940. return external_react_default.a.createElement("div", {
  30941. className: "bf-video-wrap"
  30942. }, external_react_default.a.createElement(PlayerModal, {
  30943. type: "video",
  30944. onRemove: this.removeVideo,
  30945. poster: meta ? meta.poster || '' : '',
  30946. language: language,
  30947. url: url,
  30948. name: name,
  30949. title: language.videoPlayer.title
  30950. }, external_react_default.a.createElement("div", {
  30951. className: "bf-video-player"
  30952. }, external_react_default.a.createElement("video", {
  30953. controls: true,
  30954. poster: meta ? meta.poster || '' : ''
  30955. }, external_react_default.a.createElement("source", {
  30956. src: url
  30957. })))));
  30958. }
  30959. }]);
  30960. return Video;
  30961. }(external_react_default.a.Component);
  30962. // EXTERNAL MODULE: ./renderers/atomics/Audio/style.scss
  30963. var Audio_style = __webpack_require__(50);
  30964. // CONCATENATED MODULE: ./renderers/atomics/Audio/index.jsx
  30965. var Audio_Audio =
  30966. /*#__PURE__*/
  30967. function (_React$Component) {
  30968. inherits_default()(Audio, _React$Component);
  30969. function Audio() {
  30970. var _getPrototypeOf2;
  30971. var _this;
  30972. classCallCheck_default()(this, Audio);
  30973. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  30974. args[_key] = arguments[_key];
  30975. }
  30976. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(Audio)).call.apply(_getPrototypeOf2, [this].concat(args)));
  30977. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "removeAudio", function () {
  30978. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].removeBlock(_this.props.editorState, _this.props.block));
  30979. });
  30980. return _this;
  30981. }
  30982. createClass_default()(Audio, [{
  30983. key: "render",
  30984. value: function render() {
  30985. var _this$props = this.props,
  30986. mediaData = _this$props.mediaData,
  30987. language = _this$props.language;
  30988. var url = mediaData.url,
  30989. name = mediaData.name,
  30990. meta = mediaData.meta;
  30991. return external_react_default.a.createElement("div", {
  30992. className: "bf-audio-wrap"
  30993. }, external_react_default.a.createElement(PlayerModal, {
  30994. type: "audio",
  30995. onRemove: this.removeAudio,
  30996. poster: meta ? meta.poster || '' : '',
  30997. language: language,
  30998. url: url,
  30999. name: name,
  31000. title: language.audioPlayer.title
  31001. }, external_react_default.a.createElement("div", {
  31002. className: "bf-audio-player"
  31003. }, external_react_default.a.createElement("audio", {
  31004. controls: true,
  31005. src: url
  31006. }))));
  31007. }
  31008. }]);
  31009. return Audio;
  31010. }(external_react_default.a.Component);
  31011. // EXTERNAL MODULE: ./renderers/atomics/Embed/style.scss
  31012. var Embed_style = __webpack_require__(51);
  31013. // CONCATENATED MODULE: ./renderers/atomics/Embed/index.jsx
  31014. var Embed_Embed =
  31015. /*#__PURE__*/
  31016. function (_React$Component) {
  31017. inherits_default()(Embed, _React$Component);
  31018. function Embed() {
  31019. var _getPrototypeOf2;
  31020. var _this;
  31021. classCallCheck_default()(this, Embed);
  31022. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  31023. args[_key] = arguments[_key];
  31024. }
  31025. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(Embed)).call.apply(_getPrototypeOf2, [this].concat(args)));
  31026. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "removeEmbed", function () {
  31027. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].removeBlock(_this.props.editorState, _this.props.block));
  31028. });
  31029. return _this;
  31030. }
  31031. createClass_default()(Embed, [{
  31032. key: "render",
  31033. value: function render() {
  31034. var _this$props = this.props,
  31035. mediaData = _this$props.mediaData,
  31036. language = _this$props.language;
  31037. var name = mediaData.name,
  31038. url = mediaData.url,
  31039. meta = mediaData.meta;
  31040. return external_react_default.a.createElement("div", {
  31041. className: "bf-embed-wrap"
  31042. }, external_react_default.a.createElement(PlayerModal, {
  31043. type: "embed",
  31044. onRemove: this.removeEmbed,
  31045. poster: meta ? meta.poster || '' : '',
  31046. language: language,
  31047. url: url,
  31048. name: name,
  31049. title: language.videoPlayer.embedTitle
  31050. }, external_react_default.a.createElement("div", {
  31051. className: "bf-embed-player",
  31052. dangerouslySetInnerHTML: {
  31053. __html: url
  31054. }
  31055. })));
  31056. }
  31057. }]);
  31058. return Embed;
  31059. }(external_react_default.a.Component);
  31060. // EXTERNAL MODULE: ./renderers/atomics/HorizontalLine/style.scss
  31061. var HorizontalLine_style = __webpack_require__(52);
  31062. // CONCATENATED MODULE: ./renderers/atomics/HorizontalLine/index.jsx
  31063. var HorizontalLine_HorizontalLine =
  31064. /*#__PURE__*/
  31065. function (_React$Component) {
  31066. inherits_default()(HorizontalLine, _React$Component);
  31067. function HorizontalLine() {
  31068. var _getPrototypeOf2;
  31069. var _this;
  31070. classCallCheck_default()(this, HorizontalLine);
  31071. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  31072. args[_key] = arguments[_key];
  31073. }
  31074. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(HorizontalLine)).call.apply(_getPrototypeOf2, [this].concat(args)));
  31075. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "removeHorizontalLine", function () {
  31076. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].removeBlock(_this.props.editorState, _this.props.block));
  31077. });
  31078. return _this;
  31079. }
  31080. createClass_default()(HorizontalLine, [{
  31081. key: "render",
  31082. value: function render() {
  31083. return external_react_default.a.createElement("div", {
  31084. className: "bf-hr"
  31085. }, external_react_default.a.createElement("div", {
  31086. className: "bf-media-toolbar"
  31087. }, external_react_default.a.createElement("a", {
  31088. onClick: this.removeHorizontalLine
  31089. }, "\uE9AC")));
  31090. }
  31091. }]);
  31092. return HorizontalLine;
  31093. }(external_react_default.a.Component);
  31094. // CONCATENATED MODULE: ./renderers/block/blockRendererFn.js
  31095. var blockRendererFn_BlockRenderFnContext = function BlockRenderFnContext() {
  31096. var _this = this;
  31097. classCallCheck_default()(this, BlockRenderFnContext);
  31098. defineProperty_default()(this, "superProps", void 0);
  31099. defineProperty_default()(this, "customBlockRendererFn", void 0);
  31100. defineProperty_default()(this, "getRenderFn", function (superProps, customBlockRendererFn) {
  31101. _this.superProps = superProps;
  31102. _this.customBlockRendererFn = customBlockRendererFn;
  31103. return _this.blockRendererFn;
  31104. });
  31105. defineProperty_default()(this, "renderAtomicBlock", function (props) {
  31106. var superProps = _this.superProps;
  31107. var entityKey = props.block.getEntityAt(0);
  31108. if (!entityKey) {
  31109. return null;
  31110. }
  31111. var entity = props.contentState.getEntity(entityKey);
  31112. var mediaData = entity.getData();
  31113. var mediaType = entity.getType();
  31114. var mediaProps = objectSpread_default()({}, superProps, {
  31115. block: props.block,
  31116. mediaData: mediaData,
  31117. entityKey: entityKey
  31118. });
  31119. if (mediaType === 'IMAGE') {
  31120. return external_react_default.a.createElement(Image_Image, mediaProps);
  31121. } else if (mediaType === 'AUDIO') {
  31122. return external_react_default.a.createElement(Audio_Audio, mediaProps);
  31123. } else if (mediaType === 'VIDEO') {
  31124. return external_react_default.a.createElement(Video_Video, mediaProps);
  31125. } else if (mediaType === 'EMBED') {
  31126. return external_react_default.a.createElement(Embed_Embed, mediaProps);
  31127. } else if (mediaType === 'HR') {
  31128. return external_react_default.a.createElement(HorizontalLine_HorizontalLine, mediaProps);
  31129. }
  31130. if (superProps.extendAtomics) {
  31131. var atomics = superProps.extendAtomics;
  31132. for (var i = 0; i < atomics.length; i++) {
  31133. if (mediaType === atomics[i].type) {
  31134. var Component = atomics[i].component;
  31135. return external_react_default.a.createElement(Component, mediaProps);
  31136. }
  31137. }
  31138. }
  31139. return null;
  31140. });
  31141. defineProperty_default()(this, "blockRendererFn", function (block) {
  31142. var customBlockRendererFn = _this.customBlockRendererFn,
  31143. superProps = _this.superProps;
  31144. var blockType = block.getType();
  31145. var blockRenderer = null;
  31146. if (customBlockRendererFn) {
  31147. blockRenderer = customBlockRendererFn(block, superProps) || null;
  31148. }
  31149. if (blockRenderer) {
  31150. return blockRenderer;
  31151. }
  31152. var extensionBlockRendererFns = getExtensionBlockRendererFns(superProps.editorId);
  31153. extensionBlockRendererFns.find(function (item) {
  31154. if (item.blockType === blockType || item.blockType instanceof RegExp && item.blockType.test(blockType)) {
  31155. blockRenderer = item.rendererFn ? item.rendererFn(superProps) : null;
  31156. return true;
  31157. }
  31158. });
  31159. if (blockRenderer) {
  31160. return blockRenderer;
  31161. }
  31162. if (blockType === 'atomic') {
  31163. blockRenderer = {
  31164. component: _this.renderAtomicBlock,
  31165. editable: false
  31166. };
  31167. }
  31168. return blockRenderer;
  31169. });
  31170. };
  31171. var blockRenderFnContext = new blockRendererFn_BlockRenderFnContext();
  31172. /* harmony default export */ var block_blockRendererFn = (blockRenderFnContext.getRenderFn);
  31173. // CONCATENATED MODULE: ./renderers/block/blockStyleFn.js
  31174. /* harmony default export */ var block_blockStyleFn = (function (customBlockStyleFn) {
  31175. return function (block) {
  31176. var blockAlignment = block.getData() && block.getData().get('textAlign');
  31177. var blockIndent = block.getData() && block.getData().get('textIndent');
  31178. var blockFloat = block.getData() && block.getData().get('float');
  31179. var result = '';
  31180. if (blockAlignment) {
  31181. result = "bfa-".concat(blockAlignment);
  31182. }
  31183. if (blockIndent && blockIndent !== 0) {
  31184. result += " bftd-".concat(blockIndent);
  31185. }
  31186. if (blockFloat) {
  31187. result += " bff-".concat(blockFloat);
  31188. }
  31189. if (customBlockStyleFn) {
  31190. result += customBlockStyleFn(block) || '';
  31191. }
  31192. return result;
  31193. };
  31194. });
  31195. // CONCATENATED MODULE: ./renderers/inline/inlineStyleMap.js
  31196. /* harmony default export */ var inlineStyleMap = (function (props) {
  31197. var customStyleMap = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  31198. var extensionInlineStyleMap = getExtensionInlineStyleMap(props.editorId);
  31199. return objectSpread_default()({
  31200. 'SUPERSCRIPT': {
  31201. position: 'relative',
  31202. top: '-8px',
  31203. fontSize: '11px'
  31204. },
  31205. 'SUBSCRIPT': {
  31206. position: 'relative',
  31207. bottom: '-8px',
  31208. fontSize: '11px'
  31209. }
  31210. }, extensionInlineStyleMap, customStyleMap);
  31211. });
  31212. // CONCATENATED MODULE: ./renderers/inline/inlineStyleFn.js
  31213. var getStyleValue = function getStyleValue(style) {
  31214. return style.split('-')[1];
  31215. };
  31216. /* harmony default export */ var inlineStyleFn = (function (props, options) {
  31217. return function (styles, block) {
  31218. var output = {};
  31219. var fontFamilies = options.fontFamilies,
  31220. unitExportFn = options.unitExportFn,
  31221. customStyleFn = options.customStyleFn;
  31222. var extensionInlineStyleFns = getExtensionInlineStyleFns(props.editorId);
  31223. extensionInlineStyleFns.forEach(function (item) {
  31224. output = item.styleFn ? item.styleFn(styles, block, output) : output;
  31225. });
  31226. output = customStyleFn ? customStyleFn(styles, block, output) : {};
  31227. styles.forEach(function (style) {
  31228. if (style.indexOf('COLOR-') === 0) {
  31229. output.color = '#' + getStyleValue(style);
  31230. } else if (style.indexOf('BGCOLOR-') === 0) {
  31231. output.backgroundColor = '#' + getStyleValue(style);
  31232. } else if (style.indexOf('FONTSIZE-') === 0) {
  31233. output.fontSize = unitExportFn(getStyleValue(style), 'font-size', 'editor');
  31234. } else if (style.indexOf('LINEHEIGHT-') === 0) {
  31235. output.lineHeight = unitExportFn(getStyleValue(style), 'line-height', 'editor');
  31236. } else if (style.indexOf('LETTERSPACING-') === 0) {
  31237. output.letterSpacing = unitExportFn(getStyleValue(style), 'letter-spacing', 'editor');
  31238. } else if (style.indexOf('TEXTINDENT-') === 0) {
  31239. output.textIndent = unitExportFn(getStyleValue(style), 'text-indent', 'editor');
  31240. } else if (style.indexOf('FONTFAMILY-') === 0) {
  31241. output.fontFamily = (fontFamilies.find(function (item) {
  31242. return item.name.toUpperCase() === getStyleValue(style);
  31243. }) || {}).family || '';
  31244. }
  31245. });
  31246. return output;
  31247. };
  31248. });
  31249. // EXTERNAL MODULE: ../node_modules/draft-js-multidecorators/index.js
  31250. var draft_js_multidecorators = __webpack_require__(18);
  31251. var draft_js_multidecorators_default = /*#__PURE__*/__webpack_require__.n(draft_js_multidecorators);
  31252. // CONCATENATED MODULE: ./renderers/decorators/Link/index.jsx
  31253. /* harmony default export */ var Link = (function (props) {
  31254. var children = props.children,
  31255. entityKey = props.entityKey,
  31256. contentState = props.contentState;
  31257. var _contentState$getEnti = contentState.getEntity(entityKey).getData(),
  31258. href = _contentState$getEnti.href,
  31259. target = _contentState$getEnti.target;
  31260. return external_react_default.a.createElement("span", {
  31261. className: "bf-link-wrap"
  31262. }, external_react_default.a.createElement("a", {
  31263. onClick: function onClick(event) {
  31264. return viewLink(event, href);
  31265. },
  31266. className: "bf-link",
  31267. href: href,
  31268. target: target
  31269. }, children));
  31270. });
  31271. var viewLink = function viewLink(event, link) {
  31272. // 当按下Ctrl/command键时,点击打开链接文字中的url
  31273. if (event.getModifierState('Control') || event.getModifierState('Meta')) {
  31274. var tempLink = document.createElement('a');
  31275. tempLink.href = link;
  31276. tempLink.target = event.currentTarget.target;
  31277. tempLink.click();
  31278. }
  31279. };
  31280. // CONCATENATED MODULE: ./renderers/decorators/index.js
  31281. var KEY_SEPARATOR = '-';
  31282. draft_js_multidecorators_default.a.prototype.getDecorations = function (block, contentState) {
  31283. var decorations = Array(block.getText().length).fill(null);
  31284. this.decorators.forEach(function (decorator, i) {
  31285. decorator.getDecorations(block, contentState).forEach(function (key, offset) {
  31286. if (!key) {
  31287. return;
  31288. }
  31289. key = i + KEY_SEPARATOR + key;
  31290. decorations[offset] = key;
  31291. });
  31292. });
  31293. return external_immutable_default.a.List(decorations);
  31294. };
  31295. var builtinDecorators = [{
  31296. type: 'entity',
  31297. decorator: {
  31298. key: 'LINK',
  31299. component: Link
  31300. }
  31301. }];
  31302. var createStrategy = function createStrategy(type) {
  31303. return function (block, callback, contentState) {
  31304. block.findEntityRanges(function (character) {
  31305. var entityKey = character.getEntity();
  31306. return entityKey !== null && contentState.getEntity(entityKey).getType() === type;
  31307. }, callback);
  31308. };
  31309. };
  31310. /* harmony default export */ var decorators = (function (editorId) {
  31311. var extensionDecorators = getExtensionDecorators(editorId);
  31312. var entityDecorators = builtinDecorators.concat(toConsumableArray_default()(extensionDecorators.filter(function (item) {
  31313. return item.type === 'entity';
  31314. })));
  31315. var strategyDecorators = extensionDecorators.filter(function (item) {
  31316. return item.type === 'strategy';
  31317. });
  31318. var classDecorators = extensionDecorators.filter(function (item) {
  31319. return item.type === 'class';
  31320. });
  31321. return new draft_js_multidecorators_default.a(toConsumableArray_default()(classDecorators.map(function (item) {
  31322. return item.decorator;
  31323. })).concat([// combine decorators created with strategy
  31324. new external_draft_js_["CompositeDecorator"](strategyDecorators.map(function (item) {
  31325. return item.decorator;
  31326. })), // combine decorators for entities
  31327. new external_draft_js_["CompositeDecorator"](entityDecorators.map(function (item) {
  31328. return {
  31329. strategy: createStrategy(item.decorator.key),
  31330. component: item.decorator.component
  31331. };
  31332. }))]));
  31333. });
  31334. // CONCATENATED MODULE: ./renderers/index.js
  31335. var getBlockRenderMap = block_blockRenderMap;
  31336. var getBlockRendererFn = block_blockRendererFn;
  31337. var getBlockStyleFn = block_blockStyleFn;
  31338. var getCustomStyleMap = inlineStyleMap;
  31339. var getCustomStyleFn = inlineStyleFn;
  31340. var getDecorators = decorators;
  31341. // EXTERNAL MODULE: ./components/business/ControlBar/style.scss
  31342. var ControlBar_style = __webpack_require__(53);
  31343. // EXTERNAL MODULE: ./components/business/LinkEditor/style.scss
  31344. var LinkEditor_style = __webpack_require__(54);
  31345. // EXTERNAL MODULE: ./components/common/DropDown/style.scss
  31346. var DropDown_style = __webpack_require__(55);
  31347. // CONCATENATED MODULE: ./helpers/responsive.js
  31348. var resizeEventHandlers = [];
  31349. var responsiveHelperInited = false;
  31350. var debouce = false;
  31351. /* harmony default export */ var responsive = ({
  31352. resolve: function resolve(eventHandler) {
  31353. var id = external_braft_utils_["BaseUtils"].UniqueIndex();
  31354. resizeEventHandlers.push({
  31355. id: id,
  31356. eventHandler: eventHandler
  31357. });
  31358. return id;
  31359. },
  31360. unresolve: function unresolve(id) {
  31361. resizeEventHandlers = resizeEventHandlers.filter(function (item) {
  31362. return item.id !== id;
  31363. });
  31364. }
  31365. });
  31366. if (!responsiveHelperInited && (typeof window === "undefined" ? "undefined" : typeof_default()(window)) === 'object') {
  31367. window.addEventListener('resize', function (event) {
  31368. clearTimeout(debouce);
  31369. debouce = setTimeout(function () {
  31370. resizeEventHandlers.map(function (item) {
  31371. typeof item.eventHandler === 'function' && item.eventHandler(event);
  31372. });
  31373. debouce = false;
  31374. }, 100);
  31375. });
  31376. responsiveHelperInited = true;
  31377. }
  31378. // CONCATENATED MODULE: ./components/common/DropDown/index.jsx
  31379. var DropDown_DropDown =
  31380. /*#__PURE__*/
  31381. function (_React$Component) {
  31382. inherits_default()(DropDown, _React$Component);
  31383. function DropDown() {
  31384. var _getPrototypeOf2;
  31385. var _this;
  31386. classCallCheck_default()(this, DropDown);
  31387. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  31388. args[_key] = arguments[_key];
  31389. }
  31390. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(DropDown)).call.apply(_getPrototypeOf2, [this].concat(args)));
  31391. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "responsiveResolveId", null);
  31392. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "dropDownHandlerElement", null);
  31393. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "dropDownContentElement", null);
  31394. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "state", {
  31395. active: false,
  31396. offset: 0
  31397. });
  31398. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "fixDropDownPosition", function () {
  31399. var viewRect = _this.props.getContainerNode().getBoundingClientRect();
  31400. var handlerRect = _this.dropDownHandlerElement.getBoundingClientRect();
  31401. var contentRect = _this.dropDownContentElement.getBoundingClientRect();
  31402. var offset = 0;
  31403. var right = handlerRect.right - handlerRect.width / 2 + contentRect.width / 2;
  31404. var left = handlerRect.left + handlerRect.width / 2 - contentRect.width / 2;
  31405. right = viewRect.right - right;
  31406. left = left - viewRect.left;
  31407. if (right < 10) {
  31408. offset = right - 10;
  31409. } else if (left < 10) {
  31410. offset = left * -1 + 10;
  31411. }
  31412. if (offset !== _this.state.offset) {
  31413. _this.setState({
  31414. offset: offset
  31415. });
  31416. }
  31417. });
  31418. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "registerClickEvent", function (event) {
  31419. var autoHide = _this.props.autoHide;
  31420. var active = _this.state.active;
  31421. if (_this.dropDownContentElement.contains(event.target) || _this.dropDownHandlerElement.contains(event.target)) {
  31422. return false;
  31423. }
  31424. autoHide && active && _this.hide();
  31425. });
  31426. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "toggle", function () {
  31427. _this.setState({
  31428. active: !_this.state.active
  31429. });
  31430. });
  31431. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "show", function () {
  31432. _this.setState({
  31433. active: true
  31434. });
  31435. });
  31436. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "hide", function () {
  31437. _this.setState({
  31438. active: false
  31439. });
  31440. });
  31441. return _this;
  31442. }
  31443. createClass_default()(DropDown, [{
  31444. key: "componentDidMount",
  31445. value: function componentDidMount() {
  31446. if (document) {
  31447. document.body.addEventListener('click', this.registerClickEvent);
  31448. this.responsiveResolveId = responsive.resolve(this.fixDropDownPosition);
  31449. }
  31450. }
  31451. }, {
  31452. key: "componentWillReceiveProps",
  31453. value: function componentWillReceiveProps(next) {
  31454. if (!this.props.disabled && next.disabled) {
  31455. this.hide();
  31456. }
  31457. }
  31458. }, {
  31459. key: "componentDidUpdate",
  31460. value: function componentDidUpdate(prevState) {
  31461. if (!prevState.active && this.state.active) {
  31462. this.fixDropDownPosition();
  31463. }
  31464. }
  31465. }, {
  31466. key: "componentWillUnmount",
  31467. value: function componentWillUnmount() {
  31468. if (document) {
  31469. document.body.removeEventListener('click', this.registerClickEvent);
  31470. responsive.unresolve(this.responsiveResolveId);
  31471. }
  31472. }
  31473. }, {
  31474. key: "render",
  31475. value: function render() {
  31476. var _this2 = this;
  31477. var _this$state = this.state,
  31478. active = _this$state.active,
  31479. offset = _this$state.offset;
  31480. var _this$props = this.props,
  31481. caption = _this$props.caption,
  31482. htmlCaption = _this$props.htmlCaption,
  31483. title = _this$props.title,
  31484. disabled = _this$props.disabled,
  31485. showArrow = _this$props.showArrow,
  31486. arrowActive = _this$props.arrowActive,
  31487. className = _this$props.className,
  31488. children = _this$props.children,
  31489. theme = _this$props.theme;
  31490. disabled && (active = false);
  31491. theme === 'light' && (className = ' light-theme ' + className);
  31492. return external_react_default.a.createElement("div", {
  31493. className: 'bf-dropdown ' + (active ? 'active ' : '') + (disabled ? 'disabled ' : '') + className
  31494. }, htmlCaption ? external_react_default.a.createElement("button", {
  31495. type: "button",
  31496. className: "dropdown-handler",
  31497. "data-title": title,
  31498. onClick: this.toggle,
  31499. dangerouslySetInnerHTML: htmlCaption ? {
  31500. __html: htmlCaption
  31501. } : null,
  31502. ref: function ref(instance) {
  31503. return _this2.dropDownHandlerElement = instance;
  31504. }
  31505. }) : external_react_default.a.createElement("button", {
  31506. type: "button",
  31507. className: "dropdown-handler",
  31508. "data-title": title,
  31509. onClick: this.toggle,
  31510. ref: function ref(instance) {
  31511. return _this2.dropDownHandlerElement = instance;
  31512. }
  31513. }, external_react_default.a.createElement("span", null, caption), showArrow !== false ? external_react_default.a.createElement("i", {
  31514. className: "bfi-drop-down"
  31515. }) : null), external_react_default.a.createElement("div", {
  31516. className: "dropdown-content",
  31517. style: {
  31518. marginLeft: offset
  31519. },
  31520. ref: function ref(instance) {
  31521. return _this2.dropDownContentElement = instance;
  31522. }
  31523. }, external_react_default.a.createElement("i", {
  31524. style: {
  31525. marginLeft: offset * -1
  31526. },
  31527. className: 'dropdown-arrow' + (arrowActive ? ' active' : '')
  31528. }), external_react_default.a.createElement("div", {
  31529. className: "dropdown-content-inner"
  31530. }, children)));
  31531. }
  31532. }]);
  31533. return DropDown;
  31534. }(external_react_default.a.Component);
  31535. // CONCATENATED MODULE: ./components/business/ControlGroup/index.jsx
  31536. /* harmony default export */ var ControlGroup = (function (props) {
  31537. if (external_react_default.a.Fragment) {
  31538. return external_react_default.a.createElement(external_react_default.a.Fragment, null, props.children);
  31539. } else {
  31540. return external_react_default.a.createElement("div", {
  31541. className: "control-item-group"
  31542. }, props.children);
  31543. }
  31544. });
  31545. // CONCATENATED MODULE: ./components/business/LinkEditor/index.jsx
  31546. var LinkEditor_LinkEditor =
  31547. /*#__PURE__*/
  31548. function (_React$Component) {
  31549. inherits_default()(LinkEditor, _React$Component);
  31550. function LinkEditor(props) {
  31551. var _this;
  31552. classCallCheck_default()(this, LinkEditor);
  31553. _this = possibleConstructorReturn_default()(this, getPrototypeOf_default()(LinkEditor).call(this, props));
  31554. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "dropDownInstance", null);
  31555. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handeKeyDown", function (e) {
  31556. if (e.keyCode === 13) {
  31557. _this.handleConfirm();
  31558. e.preventDefault();
  31559. return false;
  31560. }
  31561. });
  31562. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleTnputText", function (e) {
  31563. _this.setState({
  31564. text: e.currentTarget.value
  31565. });
  31566. });
  31567. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleInputLink", function (e) {
  31568. _this.setState({
  31569. href: e.currentTarget.value
  31570. });
  31571. });
  31572. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "setTarget", function () {
  31573. _this.setState({
  31574. target: _this.state.target === '_blank' ? '' : '_blank'
  31575. });
  31576. });
  31577. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleCancel", function () {
  31578. _this.dropDownInstance.hide();
  31579. });
  31580. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleUnlink", function () {
  31581. _this.dropDownInstance.hide();
  31582. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionLink(_this.props.editorState, false));
  31583. });
  31584. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleConfirm", function () {
  31585. var _this$state = _this.state,
  31586. text = _this$state.text,
  31587. href = _this$state.href,
  31588. target = _this$state.target,
  31589. textSelected = _this$state.textSelected;
  31590. var hookReturns = _this.props.hooks('toggle-link', {
  31591. href: href,
  31592. target: target
  31593. })({
  31594. href: href,
  31595. target: target
  31596. });
  31597. _this.dropDownInstance.hide();
  31598. _this.props.editor.requestFocus();
  31599. if (hookReturns === false) {
  31600. return false;
  31601. }
  31602. if (hookReturns) {
  31603. typeof hookReturns.href === 'string' && (href = hookReturns.href);
  31604. typeof hookReturns.target === 'string' && (target = hookReturns.target);
  31605. }
  31606. if (textSelected) {
  31607. if (href) {
  31608. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionLink(_this.props.editorState, href, target));
  31609. } else {
  31610. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionLink(_this.props.editorState, false));
  31611. }
  31612. } else {
  31613. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].insertText(_this.props.editorState, text || href, null, {
  31614. type: 'LINK',
  31615. data: {
  31616. href: href,
  31617. target: target
  31618. }
  31619. }));
  31620. }
  31621. });
  31622. _this.state = {
  31623. text: '',
  31624. href: '',
  31625. target: props.defaultLinkTarget || '',
  31626. textSelected: false
  31627. };
  31628. return _this;
  31629. }
  31630. createClass_default()(LinkEditor, [{
  31631. key: "componentWillReceiveProps",
  31632. value: function componentWillReceiveProps(nextProps) {
  31633. var _ContentUtils$getSele = external_braft_utils_["ContentUtils"].getSelectionEntityData(nextProps.editorState, 'LINK'),
  31634. href = _ContentUtils$getSele.href,
  31635. target = _ContentUtils$getSele.target;
  31636. var textSelected = !external_braft_utils_["ContentUtils"].isSelectionCollapsed(this.props.editorState) && external_braft_utils_["ContentUtils"].getSelectionBlockType(this.props.editorState) !== 'atomic';
  31637. var selectedText = '';
  31638. if (textSelected) {
  31639. selectedText = external_braft_utils_["ContentUtils"].getSelectionText(this.props.editorState);
  31640. }
  31641. this.setState({
  31642. textSelected: textSelected,
  31643. text: selectedText,
  31644. href: href || '',
  31645. target: typeof target === 'undefined' ? nextProps.defaultLinkTarget || '' : target || ''
  31646. });
  31647. }
  31648. }, {
  31649. key: "render",
  31650. value: function render() {
  31651. var _this2 = this;
  31652. var allowInsertLinkText = this.props.allowInsertLinkText;
  31653. var _this$state2 = this.state,
  31654. text = _this$state2.text,
  31655. href = _this$state2.href,
  31656. target = _this$state2.target,
  31657. textSelected = _this$state2.textSelected;
  31658. var caption = external_react_default.a.createElement("i", {
  31659. className: "bfi-link"
  31660. });
  31661. return external_react_default.a.createElement(ControlGroup, null, external_react_default.a.createElement(DropDown_DropDown, {
  31662. key: 0,
  31663. caption: caption,
  31664. title: this.props.language.controls.link,
  31665. autoHide: true,
  31666. getContainerNode: this.props.getContainerNode,
  31667. showArrow: false,
  31668. ref: function ref(instance) {
  31669. return _this2.dropDownInstance = instance;
  31670. },
  31671. className: 'control-item dropdown link-editor-dropdown'
  31672. }, external_react_default.a.createElement("div", {
  31673. className: "bf-link-editor"
  31674. }, allowInsertLinkText ? external_react_default.a.createElement("div", {
  31675. className: "input-group"
  31676. }, external_react_default.a.createElement("input", {
  31677. type: "text",
  31678. value: text,
  31679. spellCheck: false,
  31680. disabled: textSelected,
  31681. placeholder: this.props.language.linkEditor.textInputPlaceHolder,
  31682. onKeyDown: this.handeKeyDown,
  31683. onChange: this.handleTnputText
  31684. })) : null, external_react_default.a.createElement("div", {
  31685. className: "input-group"
  31686. }, external_react_default.a.createElement("input", {
  31687. type: "text",
  31688. value: href,
  31689. spellCheck: false,
  31690. placeholder: this.props.language.linkEditor.linkInputPlaceHolder,
  31691. onKeyDown: this.handeKeyDown,
  31692. onChange: this.handleInputLink
  31693. })), external_react_default.a.createElement("div", {
  31694. className: "switch-group"
  31695. }, external_react_default.a.createElement(Switch, {
  31696. active: target === '_blank',
  31697. onClick: this.setTarget
  31698. }), external_react_default.a.createElement("label", null, this.props.language.linkEditor.openInNewWindow)), external_react_default.a.createElement("div", {
  31699. className: "buttons"
  31700. }, external_react_default.a.createElement("a", {
  31701. onClick: this.handleUnlink,
  31702. className: "primary button-remove-link pull-left"
  31703. }, external_react_default.a.createElement("i", {
  31704. className: "bfi-close"
  31705. }), external_react_default.a.createElement("span", null, this.props.language.linkEditor.removeLink)), external_react_default.a.createElement("button", {
  31706. type: "button",
  31707. onClick: this.handleConfirm,
  31708. className: "primary pull-right"
  31709. }, this.props.language.base.confirm), external_react_default.a.createElement("button", {
  31710. type: "button",
  31711. onClick: this.handleCancel,
  31712. className: "default pull-right"
  31713. }, this.props.language.base.cancel)))), external_react_default.a.createElement("button", {
  31714. key: 1,
  31715. type: "button",
  31716. "data-title": this.props.language.controls.unlink,
  31717. className: "control-item button",
  31718. onClick: this.handleUnlink,
  31719. disabled: !textSelected || !href
  31720. }, external_react_default.a.createElement("i", {
  31721. className: "bfi-link-off"
  31722. })));
  31723. }
  31724. }]);
  31725. return LinkEditor;
  31726. }(external_react_default.a.Component);
  31727. // EXTERNAL MODULE: ./components/business/Headings/style.scss
  31728. var Headings_style = __webpack_require__(56);
  31729. // CONCATENATED MODULE: ./configs/maps.js
  31730. var maps_getHeadings = function getHeadings(lang) {
  31731. return [{
  31732. key: 'header-one',
  31733. title: lang.controls.header + ' 1',
  31734. text: external_react_default.a.createElement("h1", null, lang.controls.header, " 1"),
  31735. type: 'block-type',
  31736. command: 'header-one'
  31737. }, {
  31738. key: 'header-two',
  31739. title: lang.controls.header + ' 2',
  31740. text: external_react_default.a.createElement("h2", null, lang.controls.header, " 2"),
  31741. type: 'block-type',
  31742. command: 'header-two'
  31743. }, {
  31744. key: 'header-three',
  31745. title: lang.controls.header + ' 3',
  31746. text: external_react_default.a.createElement("h3", null, lang.controls.header, " 3"),
  31747. type: 'block-type',
  31748. command: 'header-three'
  31749. }, {
  31750. key: 'header-four',
  31751. title: lang.controls.header + ' 4',
  31752. text: external_react_default.a.createElement("h4", null, lang.controls.header, " 4"),
  31753. type: 'block-type',
  31754. command: 'header-four'
  31755. }, {
  31756. key: 'header-five',
  31757. title: lang.controls.header + ' 5',
  31758. text: external_react_default.a.createElement("h5", null, lang.controls.header, " 5"),
  31759. type: 'block-type',
  31760. command: 'header-five'
  31761. }, {
  31762. key: 'header-six',
  31763. title: lang.controls.header + ' 6',
  31764. text: external_react_default.a.createElement("h6", null, lang.controls.header, " 6"),
  31765. type: 'block-type',
  31766. command: 'header-six'
  31767. }, {
  31768. key: 'unstyled',
  31769. title: lang.controls.normal,
  31770. text: lang.controls.normal,
  31771. type: 'block-type',
  31772. command: 'unstyled'
  31773. }];
  31774. };
  31775. // CONCATENATED MODULE: ./components/business/Headings/index.jsx
  31776. /* harmony default export */ var Headings = (function (props) {
  31777. var dropDownInstance = null;
  31778. var headings = maps_getHeadings(props.language).filter(function (item) {
  31779. return props.headings.indexOf(item.key) !== -1;
  31780. });
  31781. var currentHeadingIndex = headings.findIndex(function (item) {
  31782. return item.command === props.current;
  31783. });
  31784. var caption = headings[currentHeadingIndex] ? headings[currentHeadingIndex].title : props.language.controls.normal;
  31785. return external_react_default.a.createElement(DropDown_DropDown, {
  31786. caption: caption,
  31787. autoHide: true,
  31788. getContainerNode: props.getContainerNode,
  31789. title: props.language.controls.headings,
  31790. arrowActive: currentHeadingIndex === 0,
  31791. ref: function ref(instance) {
  31792. return dropDownInstance = instance;
  31793. },
  31794. className: 'control-item dropdown headings-dropdown'
  31795. }, external_react_default.a.createElement("ul", {
  31796. className: "menu"
  31797. }, headings.map(function (item, index) {
  31798. var isActive = props.current === item.command;
  31799. return external_react_default.a.createElement("li", {
  31800. key: index,
  31801. className: 'menu-item' + (isActive ? ' active' : ''),
  31802. onClick: function onClick() {
  31803. props.onChange(item.command, item.type), dropDownInstance.hide();
  31804. }
  31805. }, item.text);
  31806. })));
  31807. });
  31808. // EXTERNAL MODULE: ./components/business/TextColor/style.scss
  31809. var TextColor_style = __webpack_require__(57);
  31810. // EXTERNAL MODULE: ./components/common/ColorPicker/style.scss
  31811. var ColorPicker_style = __webpack_require__(58);
  31812. // CONCATENATED MODULE: ./components/common/ColorPicker/index.jsx
  31813. /* harmony default export */ var common_ColorPicker = (function (props) {
  31814. return external_react_default.a.createElement("div", {
  31815. className: "bf-colors-wrap"
  31816. }, external_react_default.a.createElement("ul", {
  31817. className: "bf-colors"
  31818. }, props.presetColors.map(function (item, index) {
  31819. var className = props.color && item.toLowerCase() === props.color.toLowerCase() ? 'color-item active' : 'color-item';
  31820. return external_react_default.a.createElement("li", {
  31821. key: index,
  31822. title: item,
  31823. className: className,
  31824. style: {
  31825. color: item
  31826. },
  31827. "data-color": item.replace('#', ''),
  31828. onClick: function onClick(e) {
  31829. props.onChange(e.currentTarget.dataset.color, true);
  31830. }
  31831. });
  31832. })));
  31833. });
  31834. // CONCATENATED MODULE: ./components/business/TextColor/index.jsx
  31835. var TextColor_TextColor =
  31836. /*#__PURE__*/
  31837. function (_React$Component) {
  31838. inherits_default()(TextColor, _React$Component);
  31839. function TextColor() {
  31840. var _getPrototypeOf2;
  31841. var _this;
  31842. classCallCheck_default()(this, TextColor);
  31843. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  31844. args[_key] = arguments[_key];
  31845. }
  31846. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(TextColor)).call.apply(_getPrototypeOf2, [this].concat(args)));
  31847. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "state", {
  31848. colorType: 'color'
  31849. });
  31850. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "switchColorType", function (_ref) {
  31851. var currentTarget = _ref.currentTarget;
  31852. _this.setState({
  31853. colorType: currentTarget.dataset.type
  31854. });
  31855. });
  31856. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "toggleColor", function (color, closePicker) {
  31857. if (color) {
  31858. var hookReturns = _this.props.hooks("toggle-text-".concat(_this.state.colorType), color)(color);
  31859. if (hookReturns === false) {
  31860. return false;
  31861. }
  31862. if (typeof hookReturns === 'string') {
  31863. color = hookReturns;
  31864. }
  31865. if (_this.state.colorType === 'color') {
  31866. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionColor(_this.props.editorState, color));
  31867. } else {
  31868. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionBackgroundColor(_this.props.editorState, color));
  31869. }
  31870. }
  31871. if (closePicker) {
  31872. _this.dropDownInstance.hide();
  31873. _this.props.editor.requestFocus();
  31874. }
  31875. });
  31876. return _this;
  31877. }
  31878. createClass_default()(TextColor, [{
  31879. key: "render",
  31880. value: function render() {
  31881. var _this2 = this;
  31882. var captionStyle = {};
  31883. var currentColor = null;
  31884. var colorType = this.state.colorType;
  31885. var selectionStyles = this.props.editorState.getCurrentInlineStyle().toJS();
  31886. selectionStyles.forEach(function (style) {
  31887. if (style.indexOf('COLOR-') === 0) {
  31888. captionStyle.color = '#' + style.split('-')[1];
  31889. colorType === 'color' && (currentColor = captionStyle.color);
  31890. }
  31891. if (style.indexOf('BGCOLOR-') === 0) {
  31892. captionStyle.backgroundColor = '#' + style.split('-')[1];
  31893. colorType === 'background-color' && (currentColor = captionStyle.backgroundColor);
  31894. }
  31895. });
  31896. var caption = external_react_default.a.createElement("i", {
  31897. style: captionStyle,
  31898. className: "bfi-text-color"
  31899. }, external_react_default.a.createElement("span", {
  31900. className: "path1"
  31901. }), external_react_default.a.createElement("span", {
  31902. className: "path2"
  31903. }));
  31904. var ColorPicker = this.props.colorPicker || common_ColorPicker;
  31905. return external_react_default.a.createElement(DropDown_DropDown, {
  31906. caption: caption,
  31907. title: this.props.language.controls.color,
  31908. showArrow: false,
  31909. autoHide: this.props.autoHide,
  31910. theme: this.props.theme,
  31911. getContainerNode: this.props.getContainerNode,
  31912. ref: function ref(instance) {
  31913. return _this2.dropDownInstance = instance;
  31914. },
  31915. className: 'control-item dropdown text-color-dropdown'
  31916. }, external_react_default.a.createElement("div", {
  31917. className: "bf-text-color-picker-wrap"
  31918. }, external_react_default.a.createElement("div", {
  31919. className: "bf-color-switch-buttons",
  31920. style: this.props.enableBackgroundColor ? {} : {
  31921. display: 'none'
  31922. }
  31923. }, external_react_default.a.createElement("button", {
  31924. type: "button",
  31925. "data-type": "color",
  31926. className: colorType === 'color' ? 'active' : '',
  31927. onClick: this.switchColorType
  31928. }, this.props.language.controls.textColor), external_react_default.a.createElement("button", {
  31929. type: "button",
  31930. "data-type": "background-color",
  31931. className: colorType === 'background-color' ? 'active' : '',
  31932. onClick: this.switchColorType
  31933. }, this.props.language.controls.backgroundColor)), external_react_default.a.createElement(ColorPicker, {
  31934. width: 200,
  31935. color: currentColor,
  31936. disableAlpha: true,
  31937. presetColors: this.props.colors,
  31938. onChange: this.toggleColor
  31939. })));
  31940. }
  31941. }]);
  31942. return TextColor;
  31943. }(external_react_default.a.Component);
  31944. // EXTERNAL MODULE: ./components/business/FontSize/style.scss
  31945. var FontSize_style = __webpack_require__(59);
  31946. // CONCATENATED MODULE: ./components/business/FontSize/index.jsx
  31947. var FontSize_toggleFontSize = function toggleFontSize(event, props) {
  31948. var fontSize = event.currentTarget.dataset.size;
  31949. var hookReturns = props.hooks('toggle-font-size', fontSize)(fontSize);
  31950. if (hookReturns === false) {
  31951. return false;
  31952. }
  31953. if (!isNaN(fontSize)) {
  31954. fontSize = hookReturns;
  31955. }
  31956. props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionFontSize(props.editorState, fontSize));
  31957. props.editor.requestFocus();
  31958. };
  31959. /* harmony default export */ var FontSize = (function (props) {
  31960. var caption = null;
  31961. var currentFontSize = null;
  31962. var dropDownInstance = null;
  31963. props.fontSizes.find(function (item) {
  31964. if (external_braft_utils_["ContentUtils"].selectionHasInlineStyle(props.editorState, 'FONTSIZE-' + item)) {
  31965. caption = item;
  31966. currentFontSize = item;
  31967. return true;
  31968. }
  31969. return false;
  31970. });
  31971. return external_react_default.a.createElement(DropDown_DropDown, {
  31972. autoHide: true,
  31973. caption: caption || props.defaultCaption,
  31974. getContainerNode: props.getContainerNode,
  31975. title: props.language.controls.fontSize,
  31976. ref: function ref(instance) {
  31977. return dropDownInstance = instance;
  31978. },
  31979. className: 'control-item dropdown bf-font-size-dropdown'
  31980. }, external_react_default.a.createElement("ul", {
  31981. className: "bf-font-sizes"
  31982. }, props.fontSizes.map(function (item, index) {
  31983. return external_react_default.a.createElement("li", {
  31984. key: index,
  31985. className: item === currentFontSize ? 'active' : null,
  31986. "data-size": item,
  31987. onClick: function onClick(event) {
  31988. FontSize_toggleFontSize(event, props), dropDownInstance.hide();
  31989. }
  31990. }, item);
  31991. })));
  31992. });
  31993. // EXTERNAL MODULE: ./components/business/LineHeight/style.scss
  31994. var LineHeight_style = __webpack_require__(60);
  31995. // CONCATENATED MODULE: ./components/business/LineHeight/index.jsx
  31996. var LineHeight_toggleLineHeight = function toggleLineHeight(event, props) {
  31997. var lineHeight = event.currentTarget.dataset.size;
  31998. var hookReturns = props.hooks('toggle-line-height', lineHeight)(lineHeight);
  31999. if (hookReturns === false) {
  32000. return false;
  32001. }
  32002. if (!isNaN(hookReturns)) {
  32003. lineHeight = hookReturns;
  32004. }
  32005. props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionLineHeight(props.editorState, lineHeight));
  32006. props.editor.requestFocus();
  32007. };
  32008. /* harmony default export */ var LineHeight = (function (props) {
  32009. var caption = null;
  32010. var currentLineHeight = null;
  32011. var dropDownInstance = null;
  32012. props.lineHeights.find(function (item) {
  32013. if (external_braft_utils_["ContentUtils"].selectionHasInlineStyle(props.editorState, 'LINEHEIGHT-' + item)) {
  32014. caption = item;
  32015. currentLineHeight = item;
  32016. return true;
  32017. }
  32018. return false;
  32019. });
  32020. return external_react_default.a.createElement(DropDown_DropDown, {
  32021. autoHide: true,
  32022. caption: caption || props.defaultCaption,
  32023. getContainerNode: props.getContainerNode,
  32024. title: props.language.controls.lineHeight,
  32025. ref: function ref(instance) {
  32026. return dropDownInstance = instance;
  32027. },
  32028. className: 'control-item dropdown bf-line-height-dropdown'
  32029. }, external_react_default.a.createElement("ul", {
  32030. className: "bf-line-heights"
  32031. }, props.lineHeights.map(function (item, index) {
  32032. return external_react_default.a.createElement("li", {
  32033. key: index,
  32034. className: item === currentLineHeight ? 'active' : null,
  32035. "data-size": item,
  32036. onClick: function onClick(event) {
  32037. LineHeight_toggleLineHeight(event, props), dropDownInstance.hide();
  32038. }
  32039. }, item);
  32040. })));
  32041. });
  32042. // EXTERNAL MODULE: ./components/business/FontFamily/style.scss
  32043. var FontFamily_style = __webpack_require__(61);
  32044. // CONCATENATED MODULE: ./components/business/FontFamily/index.jsx
  32045. var FontFamily_toggleFontFamily = function toggleFontFamily(event, props) {
  32046. var fontFamilyName = event.currentTarget.dataset.name;
  32047. var hookReturns = props.hooks('toggle-font-family', fontFamilyName)(fontFamilyName, props.fontFamilies);
  32048. if (hookReturns === false) {
  32049. return false;
  32050. }
  32051. if (typeof hookReturns === 'string') {
  32052. fontFamilyName = hookReturns;
  32053. }
  32054. props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionFontFamily(props.editorState, fontFamilyName));
  32055. props.editor.requestFocus();
  32056. };
  32057. /* harmony default export */ var FontFamily = (function (props) {
  32058. var caption = null;
  32059. var currentIndex = null;
  32060. var dropDownInstance = null;
  32061. props.fontFamilies.find(function (item, index) {
  32062. if (external_braft_utils_["ContentUtils"].selectionHasInlineStyle(props.editorState, 'FONTFAMILY-' + item.name)) {
  32063. caption = item.name;
  32064. currentIndex = index;
  32065. return true;
  32066. }
  32067. return false;
  32068. });
  32069. return external_react_default.a.createElement(DropDown_DropDown, {
  32070. caption: caption || props.defaultCaption,
  32071. getContainerNode: props.getContainerNode,
  32072. title: props.language.controls.fontFamily,
  32073. autoHide: true,
  32074. arrowActive: currentIndex === 0,
  32075. ref: function ref(instance) {
  32076. return dropDownInstance = instance;
  32077. },
  32078. className: 'control-item dropdown font-family-dropdown'
  32079. }, external_react_default.a.createElement("ul", {
  32080. className: "menu"
  32081. }, props.fontFamilies.map(function (item, index) {
  32082. return external_react_default.a.createElement("li", {
  32083. key: index,
  32084. className: 'menu-item ' + (index === currentIndex ? 'active' : ''),
  32085. "data-name": item.name,
  32086. onClick: function onClick(event) {
  32087. FontFamily_toggleFontFamily(event, props), dropDownInstance.hide();
  32088. }
  32089. }, external_react_default.a.createElement("span", {
  32090. style: {
  32091. fontFamily: item.family
  32092. }
  32093. }, item.name));
  32094. })));
  32095. });
  32096. // CONCATENATED MODULE: ./components/business/TextAlign/index.jsx
  32097. var TextAlign_TextAlign =
  32098. /*#__PURE__*/
  32099. function (_React$Component) {
  32100. inherits_default()(TextAlign, _React$Component);
  32101. function TextAlign() {
  32102. var _getPrototypeOf2;
  32103. var _this;
  32104. classCallCheck_default()(this, TextAlign);
  32105. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  32106. args[_key] = arguments[_key];
  32107. }
  32108. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(TextAlign)).call.apply(_getPrototypeOf2, [this].concat(args)));
  32109. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "state", {
  32110. currentAlignment: undefined
  32111. });
  32112. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "setAlignment", function (event) {
  32113. var alignment = event.currentTarget.dataset.alignment;
  32114. var hookReturns = _this.props.hooks('toggle-text-alignment', alignment)(alignment);
  32115. if (_this.props.textAligns.indexOf(hookReturns) > -1) {
  32116. alignment = hookReturns;
  32117. }
  32118. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionAlignment(_this.props.editorState, alignment));
  32119. _this.props.editor.requestFocus();
  32120. });
  32121. return _this;
  32122. }
  32123. createClass_default()(TextAlign, [{
  32124. key: "componentWillReceiveProps",
  32125. value: function componentWillReceiveProps(next) {
  32126. this.setState({
  32127. currentAlignment: external_braft_utils_["ContentUtils"].getSelectionBlockData(next.editorState, 'textAlign')
  32128. });
  32129. }
  32130. }, {
  32131. key: "render",
  32132. value: function render() {
  32133. var _this2 = this;
  32134. var textAlignmentTitles = [this.props.language.controls.alignLeft, this.props.language.controls.alignCenter, this.props.language.controls.alignRight, this.props.language.controls.alignJustify];
  32135. return external_react_default.a.createElement(ControlGroup, null, this.props.textAligns.map(function (item, index) {
  32136. return external_react_default.a.createElement("button", {
  32137. type: "button",
  32138. key: index,
  32139. "data-title": textAlignmentTitles[index],
  32140. "data-alignment": item,
  32141. className: 'control-item button ' + (item === _this2.state.currentAlignment ? 'active' : null),
  32142. onClick: _this2.setAlignment
  32143. }, external_react_default.a.createElement("i", {
  32144. className: 'bfi-align-' + item
  32145. }));
  32146. }));
  32147. }
  32148. }]);
  32149. return TextAlign;
  32150. }(external_react_default.a.Component);
  32151. // EXTERNAL MODULE: ./components/business/EmojiPicker/style.scss
  32152. var EmojiPicker_style = __webpack_require__(62);
  32153. // CONCATENATED MODULE: ./components/business/EmojiPicker/index.jsx
  32154. var EmojiPicker_insertEmoji = function insertEmoji(event, props) {
  32155. var emoji = event.currentTarget.dataset.emoji;
  32156. var hookReturns = props.hooks('insert-emoji', emoji)(emoji);
  32157. if (hookReturns === false) {
  32158. return false;
  32159. }
  32160. if (typeof hookReturns === 'string') {
  32161. emoji = hookReturns;
  32162. }
  32163. props.editor.setValue(external_braft_utils_["ContentUtils"].insertText(props.editorState, emoji));
  32164. props.editor.requestFocus();
  32165. };
  32166. /* harmony default export */ var EmojiPicker = (function (props) {
  32167. return external_react_default.a.createElement(DropDown_DropDown, {
  32168. caption: props.defaultCaption,
  32169. autoHide: true,
  32170. showArrow: false,
  32171. getContainerNode: props.getContainerNode,
  32172. title: props.language.controls.emoji,
  32173. className: 'control-item dropdown bf-emoji-dropdown'
  32174. }, external_react_default.a.createElement("div", {
  32175. className: "bf-emojis-wrap"
  32176. }, external_react_default.a.createElement("ul", {
  32177. className: "bf-emojis"
  32178. }, props.emojis.map(function (item, index) {
  32179. return external_react_default.a.createElement("li", {
  32180. key: index,
  32181. "data-emoji": item,
  32182. onClick: function onClick(event) {
  32183. return EmojiPicker_insertEmoji(event, props);
  32184. }
  32185. }, item);
  32186. }))));
  32187. });
  32188. // EXTERNAL MODULE: ./components/business/LetterSpacing/style.scss
  32189. var LetterSpacing_style = __webpack_require__(63);
  32190. // CONCATENATED MODULE: ./components/business/LetterSpacing/index.jsx
  32191. var LetterSpacing_toggleLetterSpacing = function toggleLetterSpacing(event, props) {
  32192. var letterSpacing = event.currentTarget.dataset.size;
  32193. var hookReturns = props.hooks('toggle-letter-spacing', letterSpacing)(letterSpacing);
  32194. if (hookReturns === false) {
  32195. return false;
  32196. }
  32197. if (!isNaN(hookReturns)) {
  32198. letterSpacing = hookReturns;
  32199. }
  32200. props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionLetterSpacing(props.editorState, letterSpacing));
  32201. props.editor.requestFocus();
  32202. };
  32203. /* harmony default export */ var LetterSpacing = (function (props) {
  32204. var caption = null;
  32205. var currentLetterSpacing = null;
  32206. var dropDownInstance = null;
  32207. props.letterSpacings.find(function (item) {
  32208. if (external_braft_utils_["ContentUtils"].selectionHasInlineStyle(props.editorState, 'LETTERSPACING-' + item)) {
  32209. caption = item;
  32210. currentLetterSpacing = item;
  32211. return true;
  32212. }
  32213. return false;
  32214. });
  32215. return external_react_default.a.createElement(DropDown_DropDown, {
  32216. autoHide: true,
  32217. caption: caption || props.defaultCaption,
  32218. getContainerNode: props.getContainerNode,
  32219. title: props.language.controls.letterSpacing,
  32220. ref: function ref(instance) {
  32221. return dropDownInstance = instance;
  32222. },
  32223. className: 'control-item dropdown bf-letter-spacing-dropdown'
  32224. }, external_react_default.a.createElement("ul", {
  32225. className: "bf-letter-spacings"
  32226. }, props.letterSpacings.map(function (item, index) {
  32227. return external_react_default.a.createElement("li", {
  32228. key: index,
  32229. className: item === currentLetterSpacing ? 'active' : null,
  32230. "data-size": item,
  32231. onClick: function onClick(event) {
  32232. LetterSpacing_toggleLetterSpacing(event, props), dropDownInstance.hide();
  32233. }
  32234. }, item);
  32235. })));
  32236. });
  32237. // CONCATENATED MODULE: ./components/business/TextIndent/index.jsx
  32238. var TextIndent_TextAlign =
  32239. /*#__PURE__*/
  32240. function (_React$Component) {
  32241. inherits_default()(TextAlign, _React$Component);
  32242. function TextAlign() {
  32243. var _getPrototypeOf2;
  32244. var _this;
  32245. classCallCheck_default()(this, TextAlign);
  32246. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  32247. args[_key] = arguments[_key];
  32248. }
  32249. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(TextAlign)).call.apply(_getPrototypeOf2, [this].concat(args)));
  32250. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "state", {
  32251. currentIndent: 0
  32252. });
  32253. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "increaseIndent", function () {
  32254. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].increaseSelectionIndent(_this.props.editorState));
  32255. _this.props.editor.requestFocus();
  32256. });
  32257. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "decreaseIndent", function () {
  32258. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].decreaseSelectionIndent(_this.props.editorState));
  32259. _this.props.editor.requestFocus();
  32260. });
  32261. return _this;
  32262. }
  32263. createClass_default()(TextAlign, [{
  32264. key: "componentWillReceiveProps",
  32265. value: function componentWillReceiveProps(nextProps) {
  32266. this.setState({
  32267. currentIndent: external_braft_utils_["ContentUtils"].getSelectionBlockData(nextProps.editorState, 'textIndent') || 0
  32268. });
  32269. }
  32270. }, {
  32271. key: "render",
  32272. value: function render() {
  32273. var currentIndent = this.state.currentIndent;
  32274. var language = this.props.language;
  32275. return external_react_default.a.createElement(ControlGroup, null, external_react_default.a.createElement("button", {
  32276. key: 0,
  32277. type: "button",
  32278. "data-title": language.controls.increaseIndent,
  32279. disabled: currentIndent >= 6,
  32280. className: "control-item button button-indent-increase".concat(currentIndent > 0 && currentIndent < 6 ? ' active' : ''),
  32281. onClick: this.increaseIndent
  32282. }, external_react_default.a.createElement("i", {
  32283. className: 'bfi-indent-increase'
  32284. })), external_react_default.a.createElement("button", {
  32285. key: 1,
  32286. type: "button",
  32287. "data-title": language.controls.decreaseIndent,
  32288. disabled: currentIndent <= 0,
  32289. className: "control-item button button-indent-decrease",
  32290. onClick: this.decreaseIndent
  32291. }, external_react_default.a.createElement("i", {
  32292. className: 'bfi-indent-decrease'
  32293. })));
  32294. }
  32295. }]);
  32296. return TextAlign;
  32297. }(external_react_default.a.Component);
  32298. // CONCATENATED MODULE: ./components/business/ControlBar/index.jsx
  32299. var commandHookMap = {
  32300. 'inline-style': 'toggle-inline-style',
  32301. 'block-type': 'change-block-type',
  32302. 'editor-method': 'exec-editor-command'
  32303. };
  32304. var exclusiveInlineStyles = {
  32305. 'superscript': 'subscript',
  32306. 'subscript': 'superscript'
  32307. };
  32308. var mergeControls = function mergeControls(commonProps, builtControls, extensionControls, extendControls) {
  32309. extensionControls = extensionControls.map(function (item) {
  32310. return typeof item === 'function' ? item(commonProps) : item;
  32311. });
  32312. extendControls = extendControls.map(function (item) {
  32313. return typeof item === 'function' ? item(commonProps) : item;
  32314. });
  32315. if (extensionControls.length === 0 && extendControls.length === 0) {
  32316. return builtControls;
  32317. }
  32318. return builtControls.map(function (item) {
  32319. return extendControls.find(function (subItem) {
  32320. return subItem.replace === (item.key || item);
  32321. }) || extensionControls.find(function (subItem) {
  32322. return subItem.replace === (item.key || item);
  32323. }) || item;
  32324. }).concat(extensionControls.length ? 'separator' : '').concat(extensionControls.filter(function (item) {
  32325. return !item.replace;
  32326. })).concat(extendControls.filter(function (item) {
  32327. return typeof item === 'string' || !item.replace;
  32328. }));
  32329. };
  32330. var ControlBar_ControlBar =
  32331. /*#__PURE__*/
  32332. function (_React$Component) {
  32333. inherits_default()(ControlBar, _React$Component);
  32334. function ControlBar() {
  32335. var _getPrototypeOf2;
  32336. var _this;
  32337. classCallCheck_default()(this, ControlBar);
  32338. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  32339. args[_key] = arguments[_key];
  32340. }
  32341. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(ControlBar)).call.apply(_getPrototypeOf2, [this].concat(args)));
  32342. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "allControls", []);
  32343. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "mediaLibiraryModal", null);
  32344. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "extendedModals", {});
  32345. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "openBraftFinder", function () {
  32346. if (!_this.props.braftFinder || !_this.props.braftFinder.ReactComponent) {
  32347. return false;
  32348. }
  32349. if (_this.props.hooks('open-braft-finder')() === false) {
  32350. return false;
  32351. }
  32352. var mediaProps = _this.props.media;
  32353. var MediaLibrary = _this.props.braftFinder.ReactComponent;
  32354. _this.mediaLibiraryModal = Modal_showModal({
  32355. title: _this.props.language.controls.mediaLibirary,
  32356. language: _this.props.language,
  32357. width: 640,
  32358. showFooter: false,
  32359. component: external_react_default.a.createElement(MediaLibrary, {
  32360. accepts: mediaProps.accepts,
  32361. onCancel: _this.closeBraftFinder,
  32362. onInsert: _this.insertMedias,
  32363. onChange: mediaProps.onChange,
  32364. externals: mediaProps.externals,
  32365. onBeforeSelect: _this.bindBraftFinderHook('select-medias'),
  32366. onBeforeDeselect: _this.bindBraftFinderHook('deselect-medias'),
  32367. onBeforeRemove: _this.bindBraftFinderHook('remove-medias'),
  32368. onBeforeInsert: _this.bindBraftFinderHook('insert-medias'),
  32369. onFileSelect: _this.bindBraftFinderHook('select-files')
  32370. })
  32371. });
  32372. });
  32373. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "bindBraftFinderHook", function (hookName) {
  32374. return function () {
  32375. return _this.props.hooks(hookName, arguments.length <= 0 ? undefined : arguments[0]).apply(void 0, arguments);
  32376. };
  32377. });
  32378. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "insertMedias", function (medias) {
  32379. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].insertMedias(_this.props.editorState, medias));
  32380. _this.props.editor.requestFocus();
  32381. _this.props.media.onInsert && _this.props.media.onInsert(medias);
  32382. _this.closeBraftFinder();
  32383. });
  32384. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "closeBraftFinder", function () {
  32385. _this.props.media.onCancel && _this.props.media.onCancel();
  32386. _this.mediaLibiraryModal && _this.mediaLibiraryModal.close();
  32387. });
  32388. return _this;
  32389. }
  32390. createClass_default()(ControlBar, [{
  32391. key: "componentDidUpdate",
  32392. value: function componentDidUpdate() {
  32393. var _this2 = this;
  32394. var language = this.props.language;
  32395. this.allControls.forEach(function (item) {
  32396. if (item.type === 'modal') {
  32397. if (item.modal && item.modal.id && _this2.extendedModals[item.modal.id]) {
  32398. _this2.extendedModals[item.modal.id].update(objectSpread_default()({}, item.modal, {
  32399. language: language
  32400. }));
  32401. }
  32402. }
  32403. });
  32404. }
  32405. }, {
  32406. key: "getControlItemClassName",
  32407. value: function getControlItemClassName(data) {
  32408. var className = 'control-item button';
  32409. var type = data.type,
  32410. command = data.command;
  32411. if (type === 'inline-style' && external_braft_utils_["ContentUtils"].selectionHasInlineStyle(this.props.editorState, command)) {
  32412. className += ' active';
  32413. } else if (type === 'block-type' && external_braft_utils_["ContentUtils"].getSelectionBlockType(this.props.editorState) === command) {
  32414. className += ' active';
  32415. } else if (type === 'entity' && external_braft_utils_["ContentUtils"].getSelectionEntityType(this.props.editorState) === command) {
  32416. className += ' active';
  32417. }
  32418. return className;
  32419. }
  32420. }, {
  32421. key: "applyControl",
  32422. value: function applyControl(command, type) {
  32423. var data = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  32424. var hookReturns = this.props.hooks(commandHookMap[type] || type, command)(command);
  32425. var editorState = this.props.editorState;
  32426. if (hookReturns === false) {
  32427. return false;
  32428. }
  32429. if (typeof hookReturns === 'string') {
  32430. command = hookReturns;
  32431. }
  32432. if (type === 'inline-style') {
  32433. var exclusiveInlineStyle = exclusiveInlineStyles[command];
  32434. if (exclusiveInlineStyle && external_braft_utils_["ContentUtils"].selectionHasInlineStyle(editorState, exclusiveInlineStyle)) {
  32435. editorState = external_braft_utils_["ContentUtils"].toggleSelectionInlineStyle(editorState, exclusiveInlineStyle);
  32436. }
  32437. this.props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionInlineStyle(editorState, command));
  32438. } else if (type === 'block-type') {
  32439. this.props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionBlockType(editorState, command));
  32440. } else if (type === 'entity') {
  32441. this.props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionEntity(editorState, {
  32442. type: command,
  32443. mutability: data.mutability || 'MUTABLE',
  32444. data: data.data || {}
  32445. }));
  32446. } else if (type === 'editor-method') {
  32447. this.props.editor[command] && this.props.editor[command]();
  32448. }
  32449. }
  32450. }, {
  32451. key: "render",
  32452. value: function render() {
  32453. var _this3 = this;
  32454. var _this$props = this.props,
  32455. editor = _this$props.editor,
  32456. editorId = _this$props.editorId,
  32457. editorState = _this$props.editorState,
  32458. className = _this$props.className,
  32459. style = _this$props.style,
  32460. controls = _this$props.controls,
  32461. media = _this$props.media,
  32462. extendControls = _this$props.extendControls,
  32463. language = _this$props.language,
  32464. hooks = _this$props.hooks,
  32465. colors = _this$props.colors,
  32466. colorPicker = _this$props.colorPicker,
  32467. colorPickerTheme = _this$props.colorPickerTheme,
  32468. colorPickerAutoHide = _this$props.colorPickerAutoHide,
  32469. headings = _this$props.headings,
  32470. fontSizes = _this$props.fontSizes,
  32471. fontFamilies = _this$props.fontFamilies,
  32472. emojis = _this$props.emojis,
  32473. getContainerNode = _this$props.getContainerNode,
  32474. lineHeights = _this$props.lineHeights,
  32475. letterSpacings = _this$props.letterSpacings,
  32476. textAligns = _this$props.textAligns,
  32477. textBackgroundColor = _this$props.textBackgroundColor,
  32478. allowInsertLinkText = _this$props.allowInsertLinkText,
  32479. defaultLinkTarget = _this$props.defaultLinkTarget;
  32480. var currentBlockType = external_braft_utils_["ContentUtils"].getSelectionBlockType(editorState);
  32481. var commonProps = {
  32482. editor: editor,
  32483. editorId: editorId,
  32484. editorState: editorState,
  32485. language: language,
  32486. getContainerNode: getContainerNode,
  32487. hooks: hooks
  32488. };
  32489. var renderedControls = [];
  32490. var editorControls = configs_controls(language, editor);
  32491. var extensionControls = getExtensionControls(editorId);
  32492. var allControls = mergeControls(commonProps, controls, extensionControls, extendControls);
  32493. this.allControls = allControls;
  32494. return external_react_default.a.createElement("div", {
  32495. className: "bf-controlbar ".concat(className || ''),
  32496. style: style,
  32497. onMouseDown: this.preventDefault
  32498. }, allControls.map(function (item, index) {
  32499. var itemKey = typeof item === 'string' ? item : item.key;
  32500. if (typeof itemKey !== 'string') {
  32501. return null;
  32502. }
  32503. if (renderedControls.indexOf(itemKey) > -1) {
  32504. return null;
  32505. }
  32506. if (itemKey.toLowerCase() === 'separator') {
  32507. return external_react_default.a.createElement("span", {
  32508. key: index,
  32509. className: "separator-line"
  32510. });
  32511. }
  32512. var controlItem = editorControls.find(function (subItem) {
  32513. return subItem.key.toLowerCase() === itemKey.toLowerCase();
  32514. });
  32515. if (typeof item !== 'string') {
  32516. controlItem = objectSpread_default()({}, controlItem, item);
  32517. }
  32518. if (!controlItem) {
  32519. return null;
  32520. }
  32521. renderedControls.push(itemKey);
  32522. if (controlItem.type === 'headings') {
  32523. return external_react_default.a.createElement(Headings, extends_default()({
  32524. key: index,
  32525. headings: headings,
  32526. current: currentBlockType,
  32527. onChange: function onChange(command) {
  32528. return _this3.applyControl(command, 'block-type');
  32529. }
  32530. }, commonProps));
  32531. } else if (controlItem.type === 'text-color') {
  32532. return external_react_default.a.createElement(TextColor_TextColor, extends_default()({
  32533. key: index,
  32534. colors: colors,
  32535. colorPicker: colorPicker,
  32536. theme: colorPickerTheme,
  32537. autoHide: colorPickerAutoHide,
  32538. enableBackgroundColor: textBackgroundColor
  32539. }, commonProps));
  32540. } else if (controlItem.type === 'font-size') {
  32541. return external_react_default.a.createElement(FontSize, extends_default()({
  32542. key: index,
  32543. fontSizes: fontSizes,
  32544. defaultCaption: controlItem.title
  32545. }, commonProps));
  32546. } else if (controlItem.type === 'line-height') {
  32547. return external_react_default.a.createElement(LineHeight, extends_default()({
  32548. key: index,
  32549. lineHeights: lineHeights,
  32550. defaultCaption: controlItem.title
  32551. }, commonProps));
  32552. } else if (controlItem.type === 'letter-spacing') {
  32553. return external_react_default.a.createElement(LetterSpacing, extends_default()({
  32554. key: index,
  32555. letterSpacings: letterSpacings,
  32556. defaultCaption: controlItem.title
  32557. }, commonProps));
  32558. } else if (controlItem.type === 'text-indent') {
  32559. return external_react_default.a.createElement(TextIndent_TextAlign, extends_default()({
  32560. key: index,
  32561. defaultCaption: controlItem.title
  32562. }, commonProps));
  32563. } else if (controlItem.type === 'font-family') {
  32564. return external_react_default.a.createElement(FontFamily, extends_default()({
  32565. key: index,
  32566. fontFamilies: fontFamilies,
  32567. defaultCaption: controlItem.title
  32568. }, commonProps));
  32569. } else if (controlItem.type === 'emoji') {
  32570. return external_react_default.a.createElement(EmojiPicker, extends_default()({
  32571. key: index,
  32572. emojis: emojis,
  32573. defaultCaption: controlItem.text
  32574. }, commonProps));
  32575. } else if (controlItem.type === 'link') {
  32576. return external_react_default.a.createElement(LinkEditor_LinkEditor, extends_default()({
  32577. key: index,
  32578. defaultLinkTarget: defaultLinkTarget,
  32579. allowInsertLinkText: allowInsertLinkText
  32580. }, commonProps));
  32581. } else if (controlItem.type === 'text-align') {
  32582. return external_react_default.a.createElement(TextAlign_TextAlign, extends_default()({
  32583. key: index,
  32584. textAligns: textAligns
  32585. }, commonProps));
  32586. } else if (controlItem.type === 'media') {
  32587. if (!media.image && !media.video && !media.audio) {
  32588. return null;
  32589. }
  32590. return external_react_default.a.createElement("button", {
  32591. type: "button",
  32592. key: index,
  32593. "data-title": controlItem.title,
  32594. disabled: controlItem.disabled,
  32595. className: "control-item media button",
  32596. onClick: _this3.openBraftFinder
  32597. }, controlItem.text);
  32598. } else if (controlItem.type === 'dropdown') {
  32599. return external_react_default.a.createElement(DropDown_DropDown, extends_default()({
  32600. key: index,
  32601. className: "control-item extend-control-item dropdown ".concat(controlItem.className || ''),
  32602. caption: controlItem.text,
  32603. htmlCaption: controlItem.html,
  32604. showArrow: controlItem.showArrow,
  32605. title: controlItem.title,
  32606. arrowActive: controlItem.arrowActive,
  32607. theme: controlItem.theme,
  32608. autoHide: controlItem.autoHide,
  32609. disabled: controlItem.disabled,
  32610. ref: controlItem.ref
  32611. }, commonProps), controlItem.component);
  32612. } else if (controlItem.type === 'modal') {
  32613. return external_react_default.a.createElement("button", {
  32614. type: "button",
  32615. key: index,
  32616. "data-title": controlItem.title,
  32617. disabled: controlItem.disabled,
  32618. className: "control-item extend-control-item button ".concat(controlItem.className || ''),
  32619. dangerouslySetInnerHTML: controlItem.html ? {
  32620. __html: controlItem.html
  32621. } : null,
  32622. onClick: function onClick(event) {
  32623. if (controlItem.modal && controlItem.modal.id) {
  32624. if (_this3.extendedModals[controlItem.modal.id]) {
  32625. _this3.extendedModals[controlItem.modal.id].active = true;
  32626. _this3.extendedModals[controlItem.modal.id].update(objectSpread_default()({}, controlItem.modal, {
  32627. language: language
  32628. }));
  32629. } else {
  32630. _this3.extendedModals[controlItem.modal.id] = Modal_showModal(objectSpread_default()({}, controlItem.modal, {
  32631. language: language
  32632. }));
  32633. controlItem.modal.onCreate && controlItem.modal.onCreate(_this3.extendedModals[controlItem.modal.id]);
  32634. }
  32635. }
  32636. controlItem.onClick && controlItem.onClick(event);
  32637. }
  32638. }, !controlItem.html ? controlItem.text : null);
  32639. } else if (controlItem.type === 'component') {
  32640. return external_react_default.a.createElement("div", {
  32641. key: index,
  32642. className: "component-wrapper ".concat(controlItem.className || '')
  32643. }, controlItem.component);
  32644. } else if (controlItem.type === 'button') {
  32645. return external_react_default.a.createElement("button", {
  32646. type: "button",
  32647. key: index,
  32648. "data-title": controlItem.title,
  32649. disabled: controlItem.disabled,
  32650. className: "control-item button ".concat(controlItem.className || ''),
  32651. dangerouslySetInnerHTML: controlItem.html ? {
  32652. __html: controlItem.html
  32653. } : null,
  32654. onClick: function onClick(event) {
  32655. return controlItem.onClick && controlItem.onClick(event);
  32656. }
  32657. }, !controlItem.html ? controlItem.text : null);
  32658. } else if (controlItem) {
  32659. var disabled = false;
  32660. if (controlItem.command === 'undo') {
  32661. disabled = editorState.getUndoStack().size === 0;
  32662. } else if (controlItem.command === 'redo') {
  32663. disabled = editorState.getRedoStack().size === 0;
  32664. }
  32665. return external_react_default.a.createElement("button", {
  32666. type: "button",
  32667. key: index,
  32668. disabled: disabled,
  32669. "data-title": controlItem.title,
  32670. className: _this3.getControlItemClassName({
  32671. type: controlItem.type,
  32672. command: controlItem.command
  32673. }),
  32674. onClick: function onClick() {
  32675. return _this3.applyControl(controlItem.command, controlItem.type, controlItem.data);
  32676. }
  32677. }, controlItem.text);
  32678. }
  32679. }));
  32680. }
  32681. }, {
  32682. key: "preventDefault",
  32683. value: function preventDefault(event) {
  32684. var tagName = event.target.tagName.toLowerCase();
  32685. if (tagName === 'input' || tagName === 'label') ; else {
  32686. event.preventDefault();
  32687. }
  32688. }
  32689. }]);
  32690. return ControlBar;
  32691. }(external_react_default.a.Component);
  32692. // CONCATENATED MODULE: ./editor/index.jsx
  32693. var buildHooks = function buildHooks(hooks) {
  32694. return function (hookName) {
  32695. var defaultReturns = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  32696. return hooks[hookName] || function () {
  32697. return defaultReturns;
  32698. };
  32699. };
  32700. };
  32701. var filterColors = function filterColors(colors, colors2) {
  32702. return colors.filter(function (item) {
  32703. return !colors2.find(function (color) {
  32704. return color.toLowerCase() === item.toLowerCase();
  32705. });
  32706. }).filter(function (item, index, array) {
  32707. return array.indexOf(item) === index;
  32708. });
  32709. };
  32710. var editor_isControlEnabled = function isControlEnabled(props, controlName) {
  32711. return toConsumableArray_default()(props.controls).concat(toConsumableArray_default()(props.extendControls)).find(function (item) {
  32712. return item === controlName || item.key === controlName;
  32713. }) && props.excludeControls.indexOf(controlName) === -1;
  32714. };
  32715. var editor_getConvertOptions = function getConvertOptions(props) {
  32716. var editorId = props.editorId || props.id;
  32717. var convertOptions = objectSpread_default()({}, configs_props.converts, props.converts, {
  32718. fontFamilies: props.fontFamilies
  32719. });
  32720. convertOptions.styleImportFn = compositeStyleImportFn(convertOptions.styleImportFn, editorId);
  32721. convertOptions.styleExportFn = compositeStyleExportFn(convertOptions.styleExportFn, editorId);
  32722. convertOptions.entityImportFn = compositeEntityImportFn(convertOptions.entityImportFn, editorId);
  32723. convertOptions.entityExportFn = compositeEntityExportFn(convertOptions.entityExportFn, editorId);
  32724. convertOptions.blockImportFn = compositeBlockImportFn(convertOptions.blockImportFn, editorId);
  32725. convertOptions.blockExportFn = compositeBlockExportFn(convertOptions.blockExportFn, editorId);
  32726. return convertOptions;
  32727. };
  32728. var editor_BraftEditor =
  32729. /*#__PURE__*/
  32730. function (_React$Component) {
  32731. inherits_default()(BraftEditor, _React$Component);
  32732. function BraftEditor(props) {
  32733. var _this;
  32734. classCallCheck_default()(this, BraftEditor);
  32735. _this = possibleConstructorReturn_default()(this, getPrototypeOf_default()(BraftEditor).call(this, props));
  32736. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "onChange", function (editorState, callback) {
  32737. if (!(editorState instanceof external_draft_js_["EditorState"])) {
  32738. editorState = external_draft_js_["EditorState"].set(editorState, {
  32739. decorator: _this.editorDecorators
  32740. });
  32741. }
  32742. if (!editorState.convertOptions) {
  32743. editorState.setConvertOptions(editor_getConvertOptions(_this.editorProps));
  32744. }
  32745. _this.setState({
  32746. editorState: editorState
  32747. }, function () {
  32748. _this.props.onChange && _this.props.onChange(editorState);
  32749. callback && callback(editorState);
  32750. });
  32751. });
  32752. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "getDraftInstance", function () {
  32753. return _this.draftInstance;
  32754. });
  32755. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "getFinderInstance", function () {
  32756. return _this.braftFinder;
  32757. });
  32758. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "getValue", function () {
  32759. return _this.state.editorState;
  32760. });
  32761. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "setValue", function (editorState, callback) {
  32762. return _this.onChange(editorState, callback);
  32763. });
  32764. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "forceRender", function () {
  32765. var selectionState = _this.state.editorState.getSelection();
  32766. _this.setValue(external_draft_js_["EditorState"].set(_this.state.editorState, {
  32767. decorator: _this.editorDecorators
  32768. }), function () {
  32769. _this.setValue(external_draft_js_["EditorState"].forceSelection(_this.state.editorState, selectionState));
  32770. });
  32771. });
  32772. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "onTab", function (event) {
  32773. if (handlers_keyCommandHandlers('tab', _this.state.editorState, assertThisInitialized_default()(assertThisInitialized_default()(_this))) === 'handled') {
  32774. event.preventDefault();
  32775. }
  32776. _this.editorProps.onTab && _this.editorProps.onTab(event);
  32777. });
  32778. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "onFocus", function () {
  32779. _this.isFocused = true;
  32780. _this.editorProps.onFocus && _this.editorProps.onFocus(_this.state.editorState);
  32781. });
  32782. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "onBlur", function () {
  32783. _this.isFocused = false;
  32784. _this.editorProps.onBlur && _this.editorProps.onBlur(_this.state.editorState);
  32785. });
  32786. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "requestFocus", function () {
  32787. setTimeout(function () {
  32788. return _this.draftInstance.focus();
  32789. }, 0);
  32790. });
  32791. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleKeyCommand", function (command, editorState) {
  32792. return handlers_keyCommandHandlers(command, editorState, assertThisInitialized_default()(assertThisInitialized_default()(_this)));
  32793. });
  32794. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleReturn", function (event, editorState) {
  32795. return handlers_returnHandlers(event, editorState, assertThisInitialized_default()(assertThisInitialized_default()(_this)));
  32796. });
  32797. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleBeforeInput", function (chars, editorState) {
  32798. return beforeInputHandlers(chars, editorState, assertThisInitialized_default()(assertThisInitialized_default()(_this)));
  32799. });
  32800. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleDrop", function (selectionState, dataTransfer) {
  32801. return handlers_dropHandlers(selectionState, dataTransfer, assertThisInitialized_default()(assertThisInitialized_default()(_this)));
  32802. });
  32803. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleDroppedFiles", function (selectionState, files) {
  32804. return droppedFilesHandlers(selectionState, files, assertThisInitialized_default()(assertThisInitialized_default()(_this)));
  32805. });
  32806. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handlePastedFiles", function (files) {
  32807. return pastedFilesHandlers(files, assertThisInitialized_default()(assertThisInitialized_default()(_this)));
  32808. });
  32809. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleCopyContent", function (event) {
  32810. return handlers_copyHandlers(event, assertThisInitialized_default()(assertThisInitialized_default()(_this)));
  32811. });
  32812. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handlePastedText", function (text, html, editorState) {
  32813. return handlers_pastedTextHandlers(text, html, editorState, assertThisInitialized_default()(assertThisInitialized_default()(_this)));
  32814. });
  32815. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleCompositionStart", function (event) {
  32816. return handlers_compositionStartHandler(event, assertThisInitialized_default()(assertThisInitialized_default()(_this)));
  32817. });
  32818. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "undo", function () {
  32819. _this.setValue(external_braft_utils_["ContentUtils"].undo(_this.state.editorState));
  32820. });
  32821. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "redo", function () {
  32822. _this.setValue(external_braft_utils_["ContentUtils"].redo(_this.state.editorState));
  32823. });
  32824. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "removeSelectionInlineStyles", function () {
  32825. _this.setValue(external_braft_utils_["ContentUtils"].removeSelectionInlineStyles(_this.state.editorState));
  32826. });
  32827. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "insertHorizontalLine", function () {
  32828. _this.setValue(external_braft_utils_["ContentUtils"].insertHorizontalLine(_this.state.editorState));
  32829. });
  32830. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "clearEditorContent", function () {
  32831. _this.setValue(external_braft_utils_["ContentUtils"].clear(_this.state.editorState), function (editorState) {
  32832. _this.setValue(external_braft_utils_["ContentUtils"].toggleSelectionIndent(editorState, 0));
  32833. });
  32834. });
  32835. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "toggleFullscreen", function (fullscreen) {
  32836. _this.setState({
  32837. isFullscreen: typeof fullscreen !== 'undefined' ? fullscreen : !_this.state.isFullscreen
  32838. }, function () {
  32839. _this.editorProps.onFullscreen && _this.editorProps.onFullscreen(_this.state.isFullscreen);
  32840. });
  32841. });
  32842. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "setEditorContainerNode", function (containerNode) {
  32843. _this.containerNode = containerNode;
  32844. });
  32845. _this.editorProps = _this.getEditorProps(props);
  32846. _this.editorDecorators = getDecorators(_this.editorProps.editorId || _this.editorProps.id);
  32847. _this.isFocused = false;
  32848. _this.isLiving = false;
  32849. _this.braftFinder = null;
  32850. _this.valueInitialized = !!(_this.props.defaultValue || _this.props.value);
  32851. var defaultEditorState = (_this.props.defaultValue || _this.props.value) instanceof external_draft_js_["EditorState"] ? _this.props.defaultValue || _this.props.value : external_draft_js_["EditorState"].createEmpty(_this.editorDecorators);
  32852. defaultEditorState.setConvertOptions(editor_getConvertOptions(_this.editorProps));
  32853. var tempColors = [];
  32854. if (external_braft_utils_["ContentUtils"].isEditorState(defaultEditorState)) {
  32855. var colors = external_braft_utils_["ColorUtils"].detectColorsFromDraftState(defaultEditorState.toRAW(true));
  32856. defaultEditorState.setConvertOptions(editor_getConvertOptions(_this.editorProps));
  32857. tempColors = filterColors(colors, _this.editorProps.colors);
  32858. }
  32859. _this.state = {
  32860. tempColors: tempColors,
  32861. editorState: defaultEditorState,
  32862. isFullscreen: false,
  32863. draftProps: {}
  32864. };
  32865. _this.containerNode = null;
  32866. return _this;
  32867. }
  32868. createClass_default()(BraftEditor, [{
  32869. key: "getEditorProps",
  32870. value: function getEditorProps(props) {
  32871. var _this2 = this;
  32872. props = props || this.props;
  32873. var _props = props,
  32874. value = _props.value,
  32875. defaultValue = _props.defaultValue,
  32876. onChange = _props.onChange,
  32877. restProps = objectWithoutProperties_default()(_props, ["value", "defaultValue", "onChange"]); // eslint-disable-line no-unused-vars
  32878. var propInterceptors = getPropInterceptors(restProps.editorId || restProps.id);
  32879. if (propInterceptors.length === 0) {
  32880. return restProps;
  32881. }
  32882. var porpsMap = Object(external_immutable_["Map"])(restProps);
  32883. propInterceptors.forEach(function (interceptor) {
  32884. porpsMap = porpsMap.merge(Object(external_immutable_["Map"])(interceptor(porpsMap.toJS(), _this2) || {}));
  32885. });
  32886. return porpsMap.toJS();
  32887. }
  32888. }, {
  32889. key: "componentWillMount",
  32890. value: function componentWillMount() {
  32891. if (editor_isControlEnabled(this.editorProps, 'media')) {
  32892. var _this$editorProps = this.editorProps,
  32893. language = _this$editorProps.language,
  32894. media = _this$editorProps.media;
  32895. var _defaultProps$media$m = objectSpread_default()({}, configs_props.media, media),
  32896. uploadFn = _defaultProps$media$m.uploadFn,
  32897. validateFn = _defaultProps$media$m.validateFn,
  32898. items = _defaultProps$media$m.items;
  32899. this.braftFinder = new external_braft_finder_default.a({
  32900. items: items,
  32901. language: language,
  32902. uploader: uploadFn,
  32903. validator: validateFn
  32904. });
  32905. this.forceUpdate();
  32906. }
  32907. }
  32908. }, {
  32909. key: "componentDidMount",
  32910. value: function componentDidMount() {
  32911. this.isLiving = true;
  32912. }
  32913. }, {
  32914. key: "componentDidUpdate",
  32915. value: function componentDidUpdate(_, prevState) {
  32916. if (prevState.editorState !== this.state.editorState) {
  32917. this.state.editorState.setConvertOptions(editor_getConvertOptions(this.editorProps));
  32918. }
  32919. }
  32920. }, {
  32921. key: "componentWillReceiveProps",
  32922. value: function componentWillReceiveProps(props) {
  32923. var _this3 = this;
  32924. this.editorProps = this.getEditorProps(props);
  32925. var editorState = props.value;
  32926. var _this$editorProps2 = this.editorProps,
  32927. media = _this$editorProps2.media,
  32928. language = _this$editorProps2.language;
  32929. var currentProps = this.getEditorProps();
  32930. if (!editor_isControlEnabled(currentProps, 'media') && editor_isControlEnabled(this.editorProps, 'media') && !this.braftFinder) {
  32931. var _defaultProps$media$m2 = objectSpread_default()({}, configs_props.media, media),
  32932. uploadFn = _defaultProps$media$m2.uploadFn,
  32933. validateFn = _defaultProps$media$m2.validateFn,
  32934. items = _defaultProps$media$m2.items;
  32935. this.braftFinder = new external_braft_finder_default.a({
  32936. items: items,
  32937. language: language,
  32938. uploader: uploadFn,
  32939. validator: validateFn
  32940. });
  32941. this.forceUpdate();
  32942. }
  32943. if (media && media.items && this.braftFinder) {
  32944. this.braftFinder.setItems(media.items);
  32945. }
  32946. var nextEditorState;
  32947. if (!this.valueInitialized && typeof this.props.defaultValue === 'undefined' && external_braft_utils_["ContentUtils"].isEditorState(props.defaultValue)) {
  32948. nextEditorState = props.defaultValue;
  32949. } else if (external_braft_utils_["ContentUtils"].isEditorState(editorState)) {
  32950. nextEditorState = editorState;
  32951. }
  32952. if (nextEditorState) {
  32953. if (nextEditorState && nextEditorState !== this.state.editorState) {
  32954. var tempColors = external_braft_utils_["ColorUtils"].detectColorsFromDraftState(nextEditorState.toRAW(true));
  32955. nextEditorState.setConvertOptions(editor_getConvertOptions(this.editorProps));
  32956. this.setState({
  32957. tempColors: filterColors(toConsumableArray_default()(this.state.tempColors).concat(toConsumableArray_default()(tempColors)), currentProps.colors),
  32958. editorState: nextEditorState
  32959. }, function () {
  32960. _this3.props.onChange && _this3.props.onChange(nextEditorState);
  32961. });
  32962. } else {
  32963. this.setState({
  32964. editorState: nextEditorState
  32965. });
  32966. }
  32967. }
  32968. }
  32969. }, {
  32970. key: "componentWillUnmount",
  32971. value: function componentWillUnmount() {
  32972. this.isLiving = false;
  32973. this.controlBarInstance && this.controlBarInstance.closeBraftFinder();
  32974. }
  32975. }, {
  32976. key: "lockOrUnlockEditor",
  32977. value: function lockOrUnlockEditor(editorLocked) {
  32978. this.setState({
  32979. editorLocked: editorLocked
  32980. });
  32981. }
  32982. }, {
  32983. key: "render",
  32984. value: function render() {
  32985. var _this4 = this;
  32986. var _this$editorProps3 = this.editorProps,
  32987. id = _this$editorProps3.id,
  32988. editorId = _this$editorProps3.editorId,
  32989. controls = _this$editorProps3.controls,
  32990. excludeControls = _this$editorProps3.excludeControls,
  32991. extendControls = _this$editorProps3.extendControls,
  32992. readOnly = _this$editorProps3.readOnly,
  32993. disabled = _this$editorProps3.disabled,
  32994. media = _this$editorProps3.media,
  32995. language = _this$editorProps3.language,
  32996. colors = _this$editorProps3.colors,
  32997. colorPicker = _this$editorProps3.colorPicker,
  32998. colorPickerTheme = _this$editorProps3.colorPickerTheme,
  32999. colorPickerAutoHide = _this$editorProps3.colorPickerAutoHide,
  33000. hooks = _this$editorProps3.hooks,
  33001. fontSizes = _this$editorProps3.fontSizes,
  33002. fontFamilies = _this$editorProps3.fontFamilies,
  33003. emojis = _this$editorProps3.emojis,
  33004. placeholder = _this$editorProps3.placeholder,
  33005. fixPlaceholder = _this$editorProps3.fixPlaceholder,
  33006. headings = _this$editorProps3.headings,
  33007. imageControls = _this$editorProps3.imageControls,
  33008. imageResizable = _this$editorProps3.imageResizable,
  33009. lineHeights = _this$editorProps3.lineHeights,
  33010. letterSpacings = _this$editorProps3.letterSpacings,
  33011. textAligns = _this$editorProps3.textAligns,
  33012. textBackgroundColor = _this$editorProps3.textBackgroundColor,
  33013. allowInsertLinkText = _this$editorProps3.allowInsertLinkText,
  33014. defaultLinkTarget = _this$editorProps3.defaultLinkTarget,
  33015. extendAtomics = _this$editorProps3.extendAtomics,
  33016. className = _this$editorProps3.className,
  33017. style = _this$editorProps3.style,
  33018. controlBarClassName = _this$editorProps3.controlBarClassName,
  33019. controlBarStyle = _this$editorProps3.controlBarStyle,
  33020. contentClassName = _this$editorProps3.contentClassName,
  33021. contentStyle = _this$editorProps3.contentStyle,
  33022. stripPastedStyles = _this$editorProps3.stripPastedStyles,
  33023. componentBelowControlBar = _this$editorProps3.componentBelowControlBar;
  33024. var _this$state = this.state,
  33025. isFullscreen = _this$state.isFullscreen,
  33026. editorState = _this$state.editorState;
  33027. editorId = editorId || id;
  33028. hooks = buildHooks(hooks);
  33029. controls = controls.filter(function (item) {
  33030. return excludeControls.indexOf(item) === -1;
  33031. });
  33032. language = (typeof language === 'function' ? language(languages, 'braft-editor') : languages[language]) || languages[configs_props.language];
  33033. var externalMedias = media && media.externals ? objectSpread_default()({}, configs_props.media.externals, media.externals) : configs_props.media.externals;
  33034. var accepts = media && media.accepts ? objectSpread_default()({}, configs_props.media.accepts, media.accepts) : configs_props.media.accepts;
  33035. media = objectSpread_default()({}, configs_props.media, media, {
  33036. externalMedias: externalMedias,
  33037. accepts: accepts
  33038. });
  33039. if (!media.uploadFn) {
  33040. media.video = false;
  33041. media.audio = false;
  33042. }
  33043. var controlBarProps = {
  33044. editor: this,
  33045. editorState: editorState,
  33046. braftFinder: this.braftFinder,
  33047. ref: function ref(instance) {
  33048. return _this4.controlBarInstance = instance;
  33049. },
  33050. getContainerNode: function getContainerNode() {
  33051. return _this4.containerNode;
  33052. },
  33053. className: controlBarClassName,
  33054. style: controlBarStyle,
  33055. colors: toConsumableArray_default()(colors).concat(toConsumableArray_default()(this.state.tempColors)),
  33056. colorPicker: colorPicker,
  33057. colorPickerTheme: colorPickerTheme,
  33058. colorPickerAutoHide: colorPickerAutoHide,
  33059. hooks: hooks,
  33060. editorId: editorId,
  33061. media: media,
  33062. controls: controls,
  33063. language: language,
  33064. extendControls: extendControls,
  33065. headings: headings,
  33066. fontSizes: fontSizes,
  33067. fontFamilies: fontFamilies,
  33068. emojis: emojis,
  33069. lineHeights: lineHeights,
  33070. letterSpacings: letterSpacings,
  33071. textAligns: textAligns,
  33072. textBackgroundColor: textBackgroundColor,
  33073. allowInsertLinkText: allowInsertLinkText,
  33074. defaultLinkTarget: defaultLinkTarget
  33075. };
  33076. var unitExportFn = editorState.convertOptions.unitExportFn;
  33077. var commonProps = {
  33078. editor: this,
  33079. editorId: editorId,
  33080. hooks: hooks,
  33081. editorState: editorState,
  33082. containerNode: this.containerNode,
  33083. imageControls: imageControls,
  33084. imageResizable: imageResizable,
  33085. language: language,
  33086. extendAtomics: extendAtomics
  33087. };
  33088. var blockRendererFn = getBlockRendererFn(commonProps, this.editorProps.blockRendererFn);
  33089. var blockRenderMap = getBlockRenderMap(commonProps, this.editorProps.blockRenderMap);
  33090. var blockStyleFn = getBlockStyleFn(this.editorProps.blockStyleFn);
  33091. var customStyleMap = getCustomStyleMap(commonProps, this.editorProps.customStyleMap);
  33092. var customStyleFn = getCustomStyleFn(commonProps, {
  33093. fontFamilies: fontFamilies,
  33094. unitExportFn: unitExportFn,
  33095. customStyleFn: this.editorProps.customStyleFn
  33096. });
  33097. var keyBindingFn = keybindings(this.editorProps.keyBindingFn);
  33098. var mixedProps = {};
  33099. if (this.state.editorLocked || this.editorProps.disabled || this.editorProps.readOnly || this.editorProps.draftProps.readOnly) {
  33100. mixedProps.readOnly = true;
  33101. }
  33102. if (placeholder && fixPlaceholder && editorState.isEmpty() && editorState.getCurrentContent().getFirstBlock().getType() !== 'unstyled') {
  33103. placeholder = '';
  33104. }
  33105. var draftProps = objectSpread_default()({
  33106. ref: function ref(instance) {
  33107. _this4.draftInstance = instance;
  33108. },
  33109. editorState: editorState,
  33110. handleKeyCommand: this.handleKeyCommand,
  33111. handleReturn: this.handleReturn,
  33112. handleBeforeInput: this.handleBeforeInput,
  33113. handleDrop: this.handleDrop,
  33114. handleDroppedFiles: this.handleDroppedFiles,
  33115. handlePastedText: this.handlePastedText,
  33116. handlePastedFiles: this.handlePastedFiles,
  33117. onChange: this.onChange,
  33118. onTab: this.onTab,
  33119. onFocus: this.onFocus,
  33120. onBlur: this.onBlur,
  33121. blockRenderMap: blockRenderMap,
  33122. blockRendererFn: blockRendererFn,
  33123. blockStyleFn: blockStyleFn,
  33124. customStyleMap: customStyleMap,
  33125. customStyleFn: customStyleFn,
  33126. keyBindingFn: keyBindingFn,
  33127. placeholder: placeholder,
  33128. stripPastedStyles: stripPastedStyles
  33129. }, this.editorProps.draftProps, mixedProps);
  33130. return external_react_default.a.createElement("div", {
  33131. style: style,
  33132. ref: this.setEditorContainerNode,
  33133. className: "bf-container ".concat(className).concat(disabled ? ' disabled' : '').concat(readOnly ? ' read-only' : '').concat(isFullscreen ? ' fullscreen' : '')
  33134. }, external_react_default.a.createElement(ControlBar_ControlBar, controlBarProps), componentBelowControlBar, external_react_default.a.createElement("div", {
  33135. onCompositionStart: this.handleCompositionStart,
  33136. className: "bf-content ".concat(contentClassName),
  33137. onCopy: this.handleCopyContent,
  33138. style: contentStyle
  33139. }, external_react_default.a.createElement(external_draft_js_["Editor"], draftProps)));
  33140. }
  33141. }]);
  33142. return BraftEditor;
  33143. }(external_react_default.a.Component);
  33144. defineProperty_default()(editor_BraftEditor, "defaultProps", configs_props);
  33145. // EXTERNAL MODULE: external "braft-convert"
  33146. var external_braft_convert_ = __webpack_require__(14);
  33147. // CONCATENATED MODULE: ./index.jsx
  33148. /* concated harmony reexport EditorState */__webpack_require__.d(__webpack_exports__, "EditorState", function() { return external_draft_js_["EditorState"]; });
  33149. /* concated harmony reexport getDecorators */__webpack_require__.d(__webpack_exports__, "getDecorators", function() { return getDecorators; });
  33150. external_draft_js_["EditorState"].prototype.setConvertOptions = function () {
  33151. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  33152. this.convertOptions = options;
  33153. };
  33154. external_draft_js_["EditorState"].prototype.toHTML = function () {
  33155. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  33156. var convertOptions = this.convertOptions || {};
  33157. return Object(external_braft_convert_["convertEditorStateToHTML"])(this, objectSpread_default()({}, convertOptions, options));
  33158. };
  33159. external_draft_js_["EditorState"].prototype.toRAW = function (noStringify) {
  33160. return noStringify ? Object(external_braft_convert_["convertEditorStateToRaw"])(this) : JSON.stringify(Object(external_braft_convert_["convertEditorStateToRaw"])(this));
  33161. };
  33162. external_draft_js_["EditorState"].prototype.toText = function () {
  33163. return this.getCurrentContent().getPlainText();
  33164. };
  33165. external_draft_js_["EditorState"].prototype.isEmpty = function () {
  33166. return !this.getCurrentContent().hasText();
  33167. };
  33168. editor_BraftEditor.createEditorState = external_draft_js_["EditorState"].createFrom = function (content) {
  33169. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  33170. options.unitExportFn = options.unitExportFn || editor_BraftEditor.defaultProps.converts.unitExportFn;
  33171. options.styleImportFn = compositeStyleImportFn(options.styleImportFn, options.editorId);
  33172. options.entityImportFn = compositeEntityImportFn(options.entityImportFn, options.editorId);
  33173. options.blockImportFn = compositeBlockImportFn(options.blockImportFn, options.editorId);
  33174. var editorState = null;
  33175. if (content instanceof external_draft_js_["EditorState"]) {
  33176. editorState = content;
  33177. } else if (typeof_default()(content) === 'object' && content && content.blocks && content.entityMap) {
  33178. editorState = Object(external_braft_convert_["convertRawToEditorState"])(content, getDecorators(options.editorId));
  33179. } else if (typeof content === 'string') {
  33180. try {
  33181. if (/^(-)?\d+$/.test(content)) {
  33182. editorState = Object(external_braft_convert_["convertHTMLToEditorState"])(content, getDecorators(options.editorId), options, 'create');
  33183. } else {
  33184. editorState = external_draft_js_["EditorState"].createFrom(JSON.parse(content), options);
  33185. }
  33186. } catch (error) {
  33187. editorState = Object(external_braft_convert_["convertHTMLToEditorState"])(content, getDecorators(options.editorId), options, 'create');
  33188. }
  33189. } else if (typeof content === 'number') {
  33190. editorState = Object(external_braft_convert_["convertHTMLToEditorState"])(content.toLocaleString().replace(/,/g, ''), getDecorators(options.editorId), options, 'create');
  33191. } else {
  33192. editorState = external_draft_js_["EditorState"].createEmpty(getDecorators(options.editorId));
  33193. }
  33194. options.styleExportFn = compositeStyleExportFn(options.styleExportFn, options.editorId);
  33195. options.entityExportFn = compositeEntityExportFn(options.entityExportFn, options.editorId);
  33196. options.blockExportFn = compositeBlockExportFn(options.blockExportFn, options.editorId);
  33197. editorState.setConvertOptions(options);
  33198. return editorState;
  33199. };
  33200. /* harmony default export */ var index_0 = __webpack_exports__["default"] = (createExtensibleEditor(editor_BraftEditor));
  33201. // 2.1版本开发计划
  33202. // [ ]优化选中多行文字是插入链接报错的问题
  33203. // [ ]新增编辑器内图片删除hook
  33204. // 2.2版本开发计划
  33205. // [ ]表格功能
  33206. // [ ]美化UI,包括图标和界面风格
  33207. // 2.3版本开发计划
  33208. // [ ]初级md快捷输入支持
  33209. // [ ]图片裁切等简单的编辑功能
  33210. // [ ]允许自定义快捷键
  33211. /***/ }),
  33212. /* 40 */
  33213. /***/ (function(module, exports) {
  33214. // removed by extract-text-webpack-plugin
  33215. /***/ }),
  33216. /* 41 */,
  33217. /* 42 */
  33218. /***/ (function(module, exports) {
  33219. // removed by extract-text-webpack-plugin
  33220. /***/ }),
  33221. /* 43 */,
  33222. /* 44 */,
  33223. /* 45 */
  33224. /***/ (function(module, exports) {
  33225. // removed by extract-text-webpack-plugin
  33226. /***/ }),
  33227. /* 46 */
  33228. /***/ (function(module, exports) {
  33229. // removed by extract-text-webpack-plugin
  33230. /***/ }),
  33231. /* 47 */
  33232. /***/ (function(module, exports) {
  33233. // removed by extract-text-webpack-plugin
  33234. /***/ }),
  33235. /* 48 */
  33236. /***/ (function(module, exports) {
  33237. // removed by extract-text-webpack-plugin
  33238. /***/ }),
  33239. /* 49 */
  33240. /***/ (function(module, exports) {
  33241. // removed by extract-text-webpack-plugin
  33242. /***/ }),
  33243. /* 50 */
  33244. /***/ (function(module, exports) {
  33245. // removed by extract-text-webpack-plugin
  33246. /***/ }),
  33247. /* 51 */
  33248. /***/ (function(module, exports) {
  33249. // removed by extract-text-webpack-plugin
  33250. /***/ }),
  33251. /* 52 */
  33252. /***/ (function(module, exports) {
  33253. // removed by extract-text-webpack-plugin
  33254. /***/ }),
  33255. /* 53 */
  33256. /***/ (function(module, exports) {
  33257. // removed by extract-text-webpack-plugin
  33258. /***/ }),
  33259. /* 54 */
  33260. /***/ (function(module, exports) {
  33261. // removed by extract-text-webpack-plugin
  33262. /***/ }),
  33263. /* 55 */
  33264. /***/ (function(module, exports) {
  33265. // removed by extract-text-webpack-plugin
  33266. /***/ }),
  33267. /* 56 */
  33268. /***/ (function(module, exports) {
  33269. // removed by extract-text-webpack-plugin
  33270. /***/ }),
  33271. /* 57 */
  33272. /***/ (function(module, exports) {
  33273. // removed by extract-text-webpack-plugin
  33274. /***/ }),
  33275. /* 58 */
  33276. /***/ (function(module, exports) {
  33277. // removed by extract-text-webpack-plugin
  33278. /***/ }),
  33279. /* 59 */
  33280. /***/ (function(module, exports) {
  33281. // removed by extract-text-webpack-plugin
  33282. /***/ }),
  33283. /* 60 */
  33284. /***/ (function(module, exports) {
  33285. // removed by extract-text-webpack-plugin
  33286. /***/ }),
  33287. /* 61 */
  33288. /***/ (function(module, exports) {
  33289. // removed by extract-text-webpack-plugin
  33290. /***/ }),
  33291. /* 62 */
  33292. /***/ (function(module, exports) {
  33293. // removed by extract-text-webpack-plugin
  33294. /***/ }),
  33295. /* 63 */
  33296. /***/ (function(module, exports) {
  33297. // removed by extract-text-webpack-plugin
  33298. /***/ })
  33299. /******/ ]);
  33300. });
  33301. });
  33302. var BraftEditor = _commonjsHelpers.unwrapExports(dist$3);
  33303. var css = ".index_bf-controlbar__ej8fA{margin:0;padding:0 5px;box-shadow:inset 0 -1px 0 0 rgba(0,0,0,.2)}.index_bf-controlbar__ej8fA:after{display:block;content:\"\";clear:both}.index_bf-controlbar__ej8fA button{padding:0;outline:none}.index_bf-controlbar__ej8fA button[disabled]{pointer-events:none;opacity:.3}.index_bf-controlbar__ej8fA [data-title]{position:relative}.index_bf-controlbar__ej8fA [data-title]:after,.index_bf-controlbar__ej8fA [data-title]:before{position:absolute;z-index:10;top:100%;left:50%;pointer-events:none;opacity:0;transform:translateX(-50%) translateY(-5px);transition:opacity .3s,transform .3s}.index_bf-controlbar__ej8fA [data-title]:before{margin-top:3px;border:5px solid transparent;border-bottom-color:#21242a;content:\"\"}.index_bf-controlbar__ej8fA [data-title]:after{margin-top:12px;padding:5px;background-color:#21242a;border-radius:2px;box-shadow:0 5px 15px rgba(0,0,0,.2);color:#fff;font-size:12px;line-height:16px;white-space:nowrap;content:attr(data-title)}.index_bf-controlbar__ej8fA [data-title]:hover:after,.index_bf-controlbar__ej8fA [data-title]:hover:before{opacity:1;transform:translateX(-50%) translateY(0)}.index_bf-controlbar__ej8fA input{outline:none}.index_bf-controlbar__ej8fA .index_separator-line__3SV92{display:block;float:left;height:26px;width:1px;margin:10px;box-shadow:inset -1px 0 0 0 rgba(0,0,0,.1)}.index_bf-controlbar__ej8fA .index_separator-line__3SV92+.index_control-item__2E9Ul,.index_bf-controlbar__ej8fA .index_separator-line__3SV92+.index_control-item-group__2GENZ{margin-left:0}.index_bf-controlbar__ej8fA .index_separator-line__3SV92+.index_separator-line__3SV92,.index_bf-controlbar__ej8fA .index_separator-line__3SV92.index_first-child__2fRfM,.index_bf-controlbar__ej8fA .index_separator-line__3SV92.index_last-child__1d0yb{display:none}.index_bf-controlbar__ej8fA .index_control-item-group__2GENZ{float:left;height:36px;margin:5px 0 5px 3px}.index_bf-controlbar__ej8fA .index_control-item-group__2GENZ:first-child{margin-left:0}.index_bf-controlbar__ej8fA .index_control-item-group__2GENZ>.index_control-item__2E9Ul{margin-top:0;margin-bottom:0}.index_bf-controlbar__ej8fA .index_dropdown-handler__1xChS{border-radius:2px}.index_bf-controlbar__ej8fA .index_control-item__2E9Ul{display:block;float:left;height:36px;margin:5px 0 5px 3px;border-radius:2px;cursor:pointer}.index_bf-controlbar__ej8fA .index_control-item__2E9Ul.index_component-wrapper__OLlmp{cursor:default}.index_bf-controlbar__ej8fA .index_control-item__2E9Ul:first-child{margin-left:0}.index_bf-controlbar__ej8fA .index_control-item__2E9Ul.index_button__2IaUw{box-sizing:border-box;min-width:36px;padding:0 8px;background-color:transparent;border:none;color:#6a6f7b;font-size:14px}.index_bf-controlbar__ej8fA .index_control-item__2E9Ul.index_button__2IaUw:hover{background-color:rgba(0,0,0,.05)}.index_bf-controlbar__ej8fA .index_control-item__2E9Ul.index_button__2IaUw.index_active__3_mlp{color:#3498db}.index_bf-controlbar__ej8fA .index_control-item__2E9Ul.index_button__2IaUw i:before{display:block;height:36px;font-size:18px;line-height:36px}.index_bf-controlbar__ej8fA .index_control-item__2E9Ul.index_button__2IaUw .index_bfi-redo__1Q-LG:before,.index_bf-controlbar__ej8fA .index_control-item__2E9Ul.index_button__2IaUw .index_bfi-undo___pDce:before{font-size:14px}.index_bf-controlbar__ej8fA .index_dropdown__1rkgF .index_control-item__2E9Ul{width:100%;float:none;margin:0}.index_DraftEditor-editorContainer__1FR0o,.index_DraftEditor-root__mlfOI,.index_public-DraftEditor-content__T2mZu{height:inherit;text-align:initial}.index_public-DraftEditor-content__T2mZu[contenteditable=true]{-webkit-user-modify:read-write-plaintext-only}.index_DraftEditor-root__mlfOI{position:relative}.index_DraftEditor-editorContainer__1FR0o{background-color:hsla(0,0%,100%,0);border-left:.1px solid transparent;position:relative;z-index:1}.index_public-DraftEditor-block__IOQ0s{position:relative}.index_DraftEditor-alignLeft__gR9_E .index_public-DraftStyleDefault-block__3m05I{text-align:left}.index_DraftEditor-alignLeft__gR9_E .index_public-DraftEditorPlaceholder-root__1T6lJ{left:0;text-align:left}.index_DraftEditor-alignCenter__3Fyko .index_public-DraftStyleDefault-block__3m05I{text-align:center}.index_DraftEditor-alignCenter__3Fyko .index_public-DraftEditorPlaceholder-root__1T6lJ{margin:0 auto;text-align:center;width:100%}.index_DraftEditor-alignRight__3ghf4 .index_public-DraftStyleDefault-block__3m05I{text-align:right}.index_DraftEditor-alignRight__3ghf4 .index_public-DraftEditorPlaceholder-root__1T6lJ{right:0;text-align:right}.index_public-DraftEditorPlaceholder-root__1T6lJ{color:#9197a3;position:absolute;z-index:1}.index_public-DraftEditorPlaceholder-hasFocus__kQoHC{color:#bdc1c9}.index_DraftEditorPlaceholder-hidden__22I_U{display:none}.index_public-DraftStyleDefault-block__3m05I{position:relative;white-space:pre-wrap}.index_public-DraftStyleDefault-ltr__3qMdW{direction:ltr;text-align:left}.index_public-DraftStyleDefault-rtl__2k3sG{direction:rtl;text-align:right}.index_public-DraftStyleDefault-listLTR__Mmamr{direction:ltr}.index_public-DraftStyleDefault-listRTL__2WhLE{direction:rtl}.index_public-DraftStyleDefault-ol__32plX,.index_public-DraftStyleDefault-ul__1_opE{margin:16px 0;padding:0}.index_public-DraftStyleDefault-depth0__2YvNJ.index_public-DraftStyleDefault-listLTR__Mmamr{margin-left:1.5em}.index_public-DraftStyleDefault-depth0__2YvNJ.index_public-DraftStyleDefault-listRTL__2WhLE{margin-right:1.5em}.index_public-DraftStyleDefault-depth1__3dbfg.index_public-DraftStyleDefault-listLTR__Mmamr{margin-left:3em}.index_public-DraftStyleDefault-depth1__3dbfg.index_public-DraftStyleDefault-listRTL__2WhLE{margin-right:3em}.index_public-DraftStyleDefault-depth2__2mADP.index_public-DraftStyleDefault-listLTR__Mmamr{margin-left:4.5em}.index_public-DraftStyleDefault-depth2__2mADP.index_public-DraftStyleDefault-listRTL__2WhLE{margin-right:4.5em}.index_public-DraftStyleDefault-depth3__1V80Q.index_public-DraftStyleDefault-listLTR__Mmamr{margin-left:6em}.index_public-DraftStyleDefault-depth3__1V80Q.index_public-DraftStyleDefault-listRTL__2WhLE{margin-right:6em}.index_public-DraftStyleDefault-depth4__9Zzf6.index_public-DraftStyleDefault-listLTR__Mmamr{margin-left:7.5em}.index_public-DraftStyleDefault-depth4__9Zzf6.index_public-DraftStyleDefault-listRTL__2WhLE{margin-right:7.5em}.index_public-DraftStyleDefault-unorderedListItem__fNkjl{list-style-type:square;position:relative}.index_public-DraftStyleDefault-unorderedListItem__fNkjl.index_public-DraftStyleDefault-depth0__2YvNJ{list-style-type:disc}.index_public-DraftStyleDefault-unorderedListItem__fNkjl.index_public-DraftStyleDefault-depth1__3dbfg{list-style-type:circle}.index_public-DraftStyleDefault-orderedListItem__3J0MZ{list-style-type:none;position:relative}.index_public-DraftStyleDefault-orderedListItem__3J0MZ.index_public-DraftStyleDefault-listLTR__Mmamr:before{left:-36px;position:absolute;text-align:right;width:30px}.index_public-DraftStyleDefault-orderedListItem__3J0MZ.index_public-DraftStyleDefault-listRTL__2WhLE:before{position:absolute;right:-36px;text-align:left;width:30px}.index_public-DraftStyleDefault-orderedListItem__3J0MZ:before{content:counter(a) \". \";counter-increment:a}.index_public-DraftStyleDefault-orderedListItem__3J0MZ.index_public-DraftStyleDefault-depth1__3dbfg:before{content:counter(b) \". \";counter-increment:b}.index_public-DraftStyleDefault-orderedListItem__3J0MZ.index_public-DraftStyleDefault-depth2__2mADP:before{content:counter(c) \". \";counter-increment:c}.index_public-DraftStyleDefault-orderedListItem__3J0MZ.index_public-DraftStyleDefault-depth3__1V80Q:before{content:counter(d) \". \";counter-increment:d}.index_public-DraftStyleDefault-orderedListItem__3J0MZ.index_public-DraftStyleDefault-depth4__9Zzf6:before{content:counter(e) \". \";counter-increment:e}.index_public-DraftStyleDefault-depth0__2YvNJ.index_public-DraftStyleDefault-reset__1awm7{counter-reset:a}.index_public-DraftStyleDefault-depth1__3dbfg.index_public-DraftStyleDefault-reset__1awm7{counter-reset:b}.index_public-DraftStyleDefault-depth2__2mADP.index_public-DraftStyleDefault-reset__1awm7{counter-reset:c}.index_public-DraftStyleDefault-depth3__1V80Q.index_public-DraftStyleDefault-reset__1awm7{counter-reset:d}.index_public-DraftStyleDefault-depth4__9Zzf6.index_public-DraftStyleDefault-reset__1awm7{counter-reset:e}.index_bf-switch__1LPr-{position:relative;width:32px;height:16px;background-color:hsla(0,0%,100%,.15);border-radius:8px;transition:background .3s}.index_bf-switch__1LPr-.index_active__3_mlp{background-color:#3498db}.index_bf-switch__1LPr-.index_active__3_mlp:before{left:16px}.index_bf-switch__1LPr-:before{position:absolute;left:0;display:block;width:16px;height:16px;border-radius:8px;background-color:#eee;content:\"\";transform:scale(1.2);transition:.3s}@font-face{font-family:braft-icons;src:url(data:application/font-woff;base64,d09GRgABAAAAACxUAAsAAAAALAgAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABPUy8yAAABCAAAAGAAAABgDxIH02NtYXAAAAFoAAAA9AAAAPQXCcwWZ2FzcAAAAlwAAAAIAAAACAAAABBnbHlmAAACZAAAJggAACYI9aImY2hlYWQAAChsAAAANgAAADYTSfwFaGhlYQAAKKQAAAAkAAAAJAfCBAxobXR4AAAoyAAAASwAAAEsIgAgXGxvY2EAACn0AAAAmAAAAJhQxVqgbWF4cAAAKowAAAAgAAAAIABVAH1uYW1lAAAqrAAAAYYAAAGGmUoJ+3Bvc3QAACw0AAAAIAAAACAAAwAAAAMD+QGQAAUAAAKZAswAAACPApkCzAAAAesAMwEJAAAAAAAAAAAAAAAAAAAAARAAAAAAAAAAAAAAAAAAAAAAQAAA6rADwP/AAEADwABAAAAAAQAAAAAAAAAAAAAAIAAAAAAAAwAAAAMAAAAcAAEAAwAAABwAAwABAAAAHAAEANgAAAAyACAABAASAAEAIOAp4DTgN+BC4LjiKOI547jjwuQp6SbpMelG6WjpgOms6mjqbOpu6nXqsP/9//8AAAAAACDgJuA04DfgQuC44ijiOeO448LkKekA6SzpRuln6YDprOpo6mvqbupz6rD//f//AAH/4x/eH9Qf0h/IH1Md5B3UHFYcTRvnFxEXDBb4FtgWwRaWFdsV2RXYFdQVmgADAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAH//wAPAAEAAAAAAAAAAAACAAA3OQEAAAAAAQAAAAAAAAAAAAIAADc5AQAAAAABAAAAAAAAAAAAAgAANzkBAAAAAAQAVQCAA6sC1QARACMANQBHAAATITIXFhUUBwYjISInJjU0NzYTITIXFhUUBwYjISInJjU0NzY3ITIXFhUUBwYjISInJjU0NzY3ITIXFhUUBwYjISInJjU0NzaAAwASDA0NDBL9ABIMDQ0MEgMAEgwNDQwS/QASDA0NDBIDABIMDQ0MEv0AEgwNDQwSAwASDA0NDBL9ABIMDQ0MAtUMDRESDQwMDRIRDQz+AAwNERINDAwNEhENDKsNDBIRDQwMDRESDA2rDQwSEgwNDQwSEgwNAAAABABVAIADqwLVABEAIwA1AEcAABMhMhcWFRQHBiMhIicmNTQ3NhMhMhcWFRQHBiMhIicmNTQ3NjchMhcWFRQHBiMhIicmNTQ3NjchMhcWFRQHBiMhIicmNTQ3NoADABIMDQ0MEv0AEgwNDQwSAlUSDA0MDRL9qxIMDQ0MEgMAEgwNDQwS/QASDA0NDBICVRIMDQwNEv2rEgwNDQwC1QwNERINDAwNEhENDP4ADA0REg0MDA0SEQ0Mqw0MEhENDAwNERIMDasNDBISDA0NDBISDA0AAAAEAFUAgAOrAtUAEQAkADYASQAAEyEyFxYVFAcGIyEiJyY1NDc2EyEyFxYVFAcGIyEiJyY1NDc2MychMhcWFRQHBiMhIicmNTQ3NjchMhcWFRQHBiMhIicmNTQ3NjOAAwASDA0NDBL9ABIMDQ0MZwJWEQ0MDA0R/aoRDQwMDRFVAwASDA0NDBL9ABIMDQ0MZwJWEQ0MDA0R/aoRDQwMDREC1QwNERINDAwNEhENDP4ADA0REg0MDA0SEQ0Mqw0MEhENDAwNERIMDasNDBISDA0NDBISDA0AAAAEAFUAgAOrAtUAEQAkADYASQAAEyEyFxYVFAcGIyEiJyY1NDc2EyEyFxYVFAcGIyEiJyY1NDc2MychMhcWFRQHBiMhIicmNTQ3NjchMhcWFRQHBiMhIicmNTQ3NjOAAwASDA0NDBL9ABIMDQ0MvQJVEgwNDQwS/asSDA0MDRKrAwASDA0NDBL9ABIMDQ0MvQJVEgwNDQwS/asSDA0MDRIC1QwNERINDAwNEhENDP4ADA0REg0MDA0SEQ0Mqw0MEhENDAwNERIMDasNDBISDA0NDBISDA0AAAACAQAAgQMAAtUAAwAHAAABMxEjIREzEQJWqqr+qqoC1f2sAlT9rAAAAQFWAIEDKgLVAAIAAAkCAVYB1P4sAtX+1v7WAAEAqgArA1YDgQAuAAABMhceARcWFRQHDgEHBiMiJy4BJyY1MxQXHgEXFjMyNz4BNzY1NCcuAScmIxUnNwIARj8+XRsbGxtdPj5HRj8+XRsbVhQURS8vNTUvL0UUFBQURS8vNdbWAtUbG1w+PkZHPj5dGxsbG10+Pkc2Li9FFBQUFEUvLjY1Ly5GFBSs1tYAAAMAMwCqA80CqwAEAAkADQAAEyEVITUDNSEVITc1IRX/As79MswCzv0yaALKAqtnZ/3/Z2fOZWUABQCAACsDgAMrAAMABwALAA8AEwAAAREhEQERIREDESERAREhEQMhESEDKv8AAQD/AFT/AAEA/wBWAwD9AAHVAQD/AP6sAQD/AAFUAQD/AP6sAQD/AAKq/QAAAAACAFYAKwNWAtUACAARAAABIRUjByc3IycnFwEHJwcjNwEBAAJW+ERaHmZ4dAwCaDbyQoBo/tgC1YCgWEh4CAr9ljbynPYBKAACAIAAKwN0Ax8AAwAWAAAlAScBAR4BDwEXBycBIzUBJzcXNzYyFwEoAVhS/qgCngwBDYZSPDz+gsoBfDw8UoYMJAyBAVhS/qgB6AwjDYZSPDz+hMoBfjw8UoYMDAAAAAAEAIAAKwOAAysACAARABoAIwAAATIWHQEjNSM1EzUzFRQGKwE1JRUzFSMiJj0BETQ2OwEVIxUjAyoiNFaqqlYzI6r+VqqqIjQzI6qqVgMrNCKqqlb9VqqqIzNWqqpWMyOqAaoiNFaqAAYAgAArA4ADKwAHAAsAEwAbAB8AIwAAAREzFTMVIxUXITUhJTMRIzUjNTMBIxEzFSEVIQEhFSERIRUhAoBWqqqq/lYBqv2qVlaqqgEAVFQBVv6q/lYBqv5WAQD/AAIrAQBWVFaqVFb/AFZU/lYBAFZUAlRU/lRUAAIAgABNA4ADTQATAB0AACUhESE1ISIGFREUFjMhMjY1ESMRAxUzARcBFTMRIQMr/aoBK/7VIzIyIwJWIzJV1pr+XDwBpFX+1aICVVYyJP2rIzIyIwEr/tUCq1b+XTwBo5kBKwAEAFUAIgOrA3cABAAhAD0AQgAAJTMRIxETIgcOAQcGFRQXHgEXFjMyNz4BNzY1NCcuAScmIxEiJy4BJyY1NDc+ATc2MzIXHgEXFhUUBw4BBwYDMzUjFQHVVlYrWE5OdCEiIiF0Tk5YWE5OdCEiIiF0Tk5YRz4+XRobGxpdPj5HRz4+XRobGxpdPj5yVlb3AQD/AAKAISJzTk5YWU1OdCEiIiF0Tk1ZWE5OcyIh/QAbG10+PkdGPz5cGxsbG1w+P0ZHPj5dGxsB1lVVAAAEAFUAIgOrA3cABAAhAD0AUgAAJTM1IxUTIgcOAQcGFRQXHgEXFjMyNz4BNzY1NCcuAScmIxEiJy4BJyY1NDc+ATc2MzIXHgEXFhUUBw4BBwYDIgYVMzQ2MzIWFRQGFTM0NjU0JiMB1VZWK1hOTnQhIiIhdE5OWFhOTnQhIiIhdE5OWEc+Pl0aGxsaXT4+R0c+Pl0aGxsaXT4+R0dkVjIjIzKAVoBkR81VVQKqISJzTk5YWU1OdCEiIiF0Tk1ZWE5OcyIh/QAbG10+PkdGPz5cGxsbG1w+P0ZHPj5dGxsCVmRHIzIyI0AtaEg9UEdkAAACAFUAzQOrAs0ABQALAAABJzcnCQElNyc3CQEBkcTEPP8AAQABGsTEPAEA/wABCcTEPP8A/wA8xMQ8/wD/AAAAAwErAM0C9QMiAA8AGQAiAAABPgE1NCYjIREhMjY1NCYnJzMyFhUUBisBNRMjNTMyFhUUBgKaHydjSP72ASxDWzIp74AaJiYagJWVlRslJQIAFkEgSWL9q19DME4TtyUbGiaA/oCAJRsaJgAAAQCAACYDgAN3ADQAAAEiBgclPgE1NCYnJR4BMzI2NTQmIyIGFRQWFwUuASMiBhUUFjMyNjcFDgEVFBYzMjY1NCYjAwAYKxH+0AICAgIBLREtGTVLSzU1SwIC/tMRLRk1S0s1GS0RATACAkk0NElJNAEfEg+xBw8IBw8IrxATSzU2Sko2Bw8HsBATSzU1SxIQsQcOBzNJSTM0SQAAAQErAU0C1QIiAAIAAAEXNwEr1dUCItXVAAAAAAMAVQAiA6sDdwAcACsAOgAAASIHDgEHBhUUFx4BFxYzMjc+ATc2NTQnLgEnJiMBNDc+ATc2MzIWFwEuATUBIiYnAR4BFRQHDgEHBiMCAFhOTXQiIiIidE1OWFhOTXQiIiIidE1OWP6rGxtcPj9GOmot/iIjJQFVOmotAd4jJRsbXD4/RgN3ISJ0Tk1YWE5OdCEiIiF0Tk5YWE1OdCIh/lZGPj5dGxslI/4iLWo6/qomIwHeLWs5Rz4+XRsbAAAAAAMAgADNA4ACzQADAAcACwAANyE1ITUhNSE1FSE1gAMA/QADAP0AAwDNVYBV1lZWAAEBKwF3AtUCTQACAAABNxcBK9XVAXfW1gAAAAADAasAdwJVAyIADAAYACQAAAEyNjU0JiMiBhUUFjMVIgYVFBYzMjY1NCYDIgYVFBYzMjY1NCYCACMyMiMjMjIjIzIyIyMyMiMjMjIjIzIyAnczIyMyMiMjM1UyIyMzMyMjMv8AMiMjMzMjIzIAAAAAAwCrAXcDVQIiAAwAGAAkAAABIgYVFBYzMjY1NCYjISIGFRQWMzI2NTQmISIGFRQWMzI2NTQmAQAjMjIjIzIyIwIAIzIyIyMyMv7dIzIyIyMyMgIiMiMjMzMjIzIyIyMzMyMjMjIjIzMzIyMyAAAAAAIAAP/ABAADgAApAC0AAAERIzU0JiMhIgYdARQWMyEyNj0BMxEhFSMiBhURFBY7ATI2NRE0JisBNQEhNSEEAMAmGv1AGiYmGgLAGiaA/cAgDRMTDYANExMNIAFA/UACwAGAAYBAGiYmGsAaJiYaQP8AgBMN/sANExMNAUANE0ABgEAAAAQA1QCiAysC9wAGAA0AEwAaAAATMxUzNSMVEyMVMzUjFQEzNTM1IxM1IxUzNSPVgFbWgIDWVgEAVoDWVlbWgAEigNVVAVVV1YD+K4BVAQCA1VUAAAEAZAAlA1wDXABEAAABERQHBgcGBwYjIicmJyYnJjU0NzY3Njc2MzIXEQURFAcGBwYHBiMiJyYnJicmNTQ3Njc2NzYzMhcRNDc2NyU2MzIXFhUDXBERGhkaGRYXGRoZGhEREREaGRoZFzMr/oURERoZGhkXFhkaGRoRERERGhkaGRY0KwoJDwGbBggUDg4DLP3WGBQTCgsFBQUFCwoTFBgZExQKCwUFEwEKdv6iGRMTCwsFBQUFCwsTExkZExMLCgYFEwHeDw0MBX8CDg4UAAAEAHUAQgOJA1YALwA8AGIAeAAAAS4BBw4BJy4BJy4BBwYiJyYGBw4BJyYGBxQVHAEVFBUeATM2MzoBMzIzMjY3PAE1BSImNTQ2MzIWFRQGJyUqASM8ATU6ATMUFhUUFxwBFQYHFAYHDgEnLgE3PgE3OgEzPAE1BT4BNzoBMxQWBw4BJy4BNz4BNzoBMwKBARkZChUJCxcEFEMvBw8HHikMDCgdFyILCxgWNDM0ZzQzNBsaAf77L0FBMDBAQDEBtx8/IDRoNgEBAQENCxVFICIlBgc3JAcNCf7OAQICEyQTAwUFSiMmOAIBOiYHEAkCzhcaAQEBAwIJCC0fCAEBBhgbGxYGBBMVKCgpUCgoKQ8VARcaSpRK7T8uMEA/LzBAARchPyAKEgkzMjNmMjMzFCwRIBAOD0IjJjQDN2053QwUCi5dLSUsBgVEJig+BAAAAAAEANUAogMrAvcABQALABEAFwAAASMVMzUjAzM1MzUjASMVMzUjAxUzFTM1AStW1oBWVoDWAgCA1laAgFYBd9VVASuAVf4AVdUBgFWA1QAAAAQAAAAABAADQAAbADMATwBTAAABFBceARcWMzI3PgE3NjU0Jy4BJyYjIgcOAQcGASMuASMhIgYHIyIGFREUFjMhMjY1ETQmASInLgEnJjU0Nz4BNzYzMhceARcWFRQHDgEHBgEjNTMBMBAROCYmKysmJjgREBAROCYmKysmJjgREAKQ4AwkMP8AMCQM4BomJhoDgBomJv4mOzQzTRcWFhdNMzQ7OzQzTRcWFhdNMzQBhYCAAWArJiY4ERAQETgmJisrJiY4ERAQETgmJgE1MFBQMCYa/cAaJiYaAkAaJv2EFhdNMzQ7OzQzTRcWFhdNMzQ7OzQzTRcWAbxAAAEAkQCiA4AC3gAGAAABJwcXAScBAYCzPO8CADz+PAEaszzvAgA8/jwAAAAAAQDiAIADHgLJACYAAAE3NjQnJiIPAScmIgcGFB8BBwYUFx4BMzI2PwEXHgEzMjY3NjQvAQI84g0NDCQM4uIMJAwNDeLiDQ0GEAgIEAbi4gYQCAgQBg0N4gGr4gwjDQwM4uIMDA0jDOLiDSMMBwYGB+HhBwYGBwwjDeIAAAUAVQCVA6sC6wAZACoARABeAHgAAAEhIgYHDgEVFBYXHgEzITI2Nz4BNTQmJy4BJTQmIyEiBh0BFBYzITI2PQEDISIGBw4BFRQWFx4BMyEyNjc+ATU0JicuAQMhIgYHDgEVFBYXHgEzITI2Nz4BNTQmJy4BBSEiBgcOARUUFhceATMhMjY3PgE1NCYnLgEB1f6rCQ8GBgcHBgYPCQFVCQ8GBwYGBwYPAc0ZEv8AEhkZEgEAEhkr/QAJDwYGBwcGBg8JAwAJDwYGBwcGBg8J/QAJDwYGBwcGBg8JAwAJDwYGBwcGBg/+TP6rCQ8GBgcHBgYPCQFVCQ8GBwYGBwYPAZUGBgYQCAkPBgcGBgcGDwkIEAYGBoERGRkRrBEZGRGs/tUHBgYPCQkPBgYHBwYGDwkJDwYGBwIABwYGDwkJDwYGBwcGBg8JCQ8GBgerBgcGDwkIEAYGBgYGBhAICQ8GBwYAAAAABABVAE0DqwNNAA4AEgAeACIAAAEhIgYVETMVITUzETQmIwMhNSE3IiY1NDYzMhYVFAYDIRUhAyv9qjVLqwIAq0s1gP6qAVaAEhkZEhEZGTz+AAIAAndKNv8AqqoBADZK/ivVVhkREhkZEhEZAYCrAAIAgABjA2oDTQAiAC8AAAEjJz4BNTQnLgEnJiMiBw4BBwYVFBceARcWMzI2NxcVFzcnISImNTQ2MzIWFRQGIwKVIQwfJBYWSzMyOjkzMksWFhYWSzIzOTRcJQvWP9X/AE9xcU9QcHBQAXcMJF0zOjIzSxYWFhZLMzI6OTIzSxYWJB8MItQ/1XFPUHBwUE9xAAIAZAAiA5wDdwBNAFkAAAE+ATU0Jic3PgEvAS4BDwEuAS8BLgErASIGDwEOAQcnJgYPAQYWHwEOARUUFhcHDgEfAR4BPwEeAR8BHgE7ATI2PwE+ATcXFjY/ATYmJwUiJjU0NjMyFhUUBgM9AQICAVoGAwRVBA8HahEkFBABDAiqCAwBEBQkEWoHDwRVBAMGWgECAgFaBgMEVQQPB2oRJBQQAQwIqggMARAUJBFqBw8EVQQDBv5pPldXPj5XVwGjChULCxQLRgUPB5QHBQMqDBUIcgcKCgdyCBUMKgMFB5QHDwVGCxUKCxUKRgUQB5MHBQIrDRUIcQgKCghxCBUNKwMGB5MHEAUmWD4+V1c+PlgAAQDVAKIDKwL3AAsAAAEhESMRITUhETMRIQMr/wBW/wABAFYBAAGi/wABAFUBAP8AAAAAAAQAVf/vA6sC7wAeADMAOAA9AAATNwEHJyM1JyM1Jw4BFRQWOwEVIyInLgEnJjU0NjcnBTIXHgEXFhUUBgcnPgE1NCYrATUzITMVIycFFSMnM1U3Ask2q0mMSmogJWdIgIA1Li9FFRQyKlwCVjUuL0UVFEc5PC88Z0iAgP6qgDZRAV0zVYgCuTb9NzerSYxKaxhIKklmURQURS8vNTpnIlwfFRRFLy41R3YhPRRWN0hnUVFR1lVVAAADAFUAmgOrApoAGgA1ADkAAAEjFTMyFhUUBisBFTMyNz4BNzY1NCcuAScmIwE0NjsBNSMiBw4BBwYVFBceARcWOwE1IyImNRchNSECq4CASGdnSICANS4vRRUUFBVFLy41/ftnSICANS4vRRUUFBVFLy41gIBIZ68BVv6qAppRZ0hJZlEUFEUvLzU1Li9FFRT/AEhnURUURS8uNTUvL0UUFFFmSStVAAAFAFUAIgOrA3cAHAA4AEQAUABYAAABIgcOAQcGFRQXHgEXFjMyNz4BNzY1NCcuAScmIxEiJy4BJyY1NDc+ATc2MzIXHgEXFhUUBw4BBwYTMjY1NCYjIgYVFBYhMjY1NCYjIgYVFBYTMjY3IR4BMwIAWU1OdCEiIiF0Tk1ZWE5OdCEiIiF0Tk5YRz4+XRsaGhtdPj5HRz4+XRsaGhtdPj5OGyUlGxomJv7wGiYmGhslJbBLdRr+TBp1SwN3ISJzTk5YWU1OdCEiIiF0Tk1ZWE5OcyIh/QAbG10+PkdHPj5dGhsbGl0+PkdHPj5dGxsBgCYaGyUlGxomJhobJSUbGib+61RBQVQAAAAJAAAAQAQAA0AAAwAHAAsADwATABcAGwAfACIAABMRIREBIzUzNSM1MzUjNTMBIREhEyM1MzUjNTM1IzUzBRElAAQA/MCAgICAgIACQP4AAgDAgICAgICA/cABAANA/QADAP1AgICAgID9gAKA/YCAgICAgID+gMAAAAAAAgDVAE0DKwNNABkAHgAAJTI3PgE3NjURIxEUBiMiJjURIxEUFx4BFxYHFSE1IQIANS8uRhQUa1c+PldrFBRGLi/2Alb9qvcVFEUvLzQBVv6qPVhYPQFW/qo0Ly9FFBVVVVUAAAUAVQCVA6sC6wAaACsARQBfAHoAAAEhMhYXHgEVFAYHDgEjISImJy4BNTQ2Nz4BMyU0NjMhMhYdARQGIyEiJj0BEyEyFhceARUUBgcOASMhIiYnLgE1NDY3PgETITIWFx4BFRQGBw4BIyEiJicuATU0Njc+AQUhMhYXHgEVFAYHDgEjISImJy4BNTQ2Nz4BMwIrAVUJDwYGBwcGBg8J/qsJDwYHBgYHBg8J/ioZEgEAEhkZEv8AEhkrAwAJDwYGBwcGBg8J/QAJDwYGBwcGBg8JAwAJDwYGBwcGBg8J/QAJDwYGBwcGBg8BtAFVCQ8GBgcHBgYPCf6rCQ8GBwYGBwYPCQGVBgYGEAgJDwYHBgYHBg8JCBAGBgaBERkZEawRGRkRrP7VBwYGDwkJDwYGBwcGBg8JCQ8GBgcCAAcGBg8JCQ8GBgcHBgYPCQkPBgYHqwYHBg8JCBAGBgYGBgYQCAkPBgcGAAAAAAMAgACiA4ADIgAEAA0AEQAAJTM1IxUDFTMVMzUzNSEDITUhAauqqtbWqtb9qlUDAP0AooCAAoCAgICA/lVWAAACAIAAogOrAyIACAARAAABFTMRMxEzNSEBMxEzETM1IRUBgNWA1v3V/wCAgID+gAMigP4AAgCA/qv+1QErgIAAAgDVAPcDKwKiAAYADQAAJTM3ESERMwUzNxEhETMBAIBV/wCAAQCAVv8AgPerAQD/AKurAQD/AAAGAFUAdwOAAyIACwASAB0AIgAnACwAADczFSMVMxUjFTM1IxMzNSMVMxUHMwcVMzUjNzUjFRMVITUhESE1IRURITUhFVVWKytWgIArK1YrK01NgExMgNYCVf2rAlX9qwJV/av3FSsVK6sBVasrgIBZJytaJisBAFVV/atVVQEAVVUAAAAGAGsAjQOAAw0ACwAXACMAKAAtADIAABMiBhUUFjMyNjU0JgMiBhUUFjMyNjU0JgMiBhUUFjMyNjU0JhchNSEVESE1IRURFSE1IasbJSUbGiYmGhslJRsaJiYaGyUlGxomJmYCVf2rAlX9qwJV/asCDSYaGyUlGxomAQAmGhslJRsaJv4AJhoaJiYaGiZrVVUBAFVVAVVVVQAAAAABAQAAzQMAAyIACwAAARUzAyMVITUjEzM1AatekncBVV6SdwMigP6rgIABVYAAAAABAAABawQAAesAAwAAEyEVIQAEAPwAAeuAAAAABgBA/8ADwAPAABkAIQA5AEcAVQBjAAABLgEnLgEnLgEjISIGFREUFjMhMjY1ETQmJyceARcjNR4BExQGIyEiJjURNDYzMDM6ATMyMRUUFjsBAyEiJjU0NjMhMhYVFAYnISImNTQ2MyEyFhUUBichIiY1NDYzITIWFRQGA5YRLRkaMxcnKQv+ECEvLyEC4CEvDhyFFyUNmhEphgkH/SAHCQkHTU66TU4TDeCg/kANExMNAcANExMN/kANExMNAcANExMN/kANExMNAcANExMC2xczGhktERwOLyH8oCEvLyECcAspJzYXKRGaDSX86AcJCQcDYAcJ4A0T/gATDQ0TEw0NE4ATDQ0TEw0NE4ATDQ0TEw0NEwAAAAUAAP/ABAADwAAIAAsAEwAWABwAAAERIQcRIREhESUVIwMRMzUhFQcRExUjASERMzUhAoD+QMABgAKA/MBlG8ABQMDAZQHl/gDAAUACwAEAwP3A/wADAKVl/gABwMDAwP8AAWVl/gABwMAAAAUAQP/ABAADwAANABgANAA3AD0AAAEjNTQmKwEiBh0BIxUhJyM1OAExMzgBMRUFNTQmKwEVMxUjBxEhETM1IyIGFREUFjMhFSERBRUjASERMzUhAsCAJhqAGiaAAgDAgIABQBMNQCDAwP8AIEANExMNASACgP5AZQHl/gDAAUADQEAaJiYaQICAQEDAoA0TQIDA/wACQEATDf2ADRPAAsBbZf5AAYDAAAYAgABNA4ADTQADAAcACwAPABMAFwAANyE1IRkBNycBITUhARUhNQEhNSERITUhgAMA/QCrqwFVAav+Vf6rAwD+VQGr/lUBq/5VTVUB1f6rq6r+gFYCAFZW/wBV/wBVAAYAgABNA4ADTQADAAcACwAPABMAFwAAJSE1ISUXEQcRITUhERUhNQEhNSERITUhAdUBq/5V/qurqwMA/QADAP5VAav+VQGr/lX3VoCrAVWq/oBVAqtWVv8AVf8AVQAAAAEAAP/NBAAAdwADAAA3IRUhAAQA/AB3qgAAAAACAOsA9wMVA00ACAAMAAABAzM3IRczAyMDGwEjAdXqYC8BCzBg6lY7ZmbMA039qoCAAlb+gAEO/vIAAAACAAD/wAQAA8AADgASAAABBxcDIxcBFTMBFzUlFzcFJzcXAiBgYODgsP7wJwFpsAEAYGD9wEDgQAPAYGD/ALD+lycBELDg4GBgQEDgQAAAAAEAQP/AA4oDwAARAAAFNjc2JicmBxUJARU2Fx4BBwYC+isTEzhVVqj+gAGAyXFyRignQE1bW5ozMgT+AYABgPgFTk7siokAAAEAdv/AA8ADwAASAAABNQkBNSYHDgEXFhcmJyY2NzYXAkABgP6AqFZVOBMTK2knKEZycckCyPj+gP6A/gQyM5pbW01yiYrsTk4FAAAHAAD/wAQAA0YACwAXACMALwA7AEcAUwAAJTQ2MzIWFRQGIyImATQ2MzIWFRQGIyImJTQ2MzIWFRQGIyImATQ2MzIWFRQGIyImATQ2MzIWFRQGIyImJTQ2MzIWFRQGIyImATQ2MzIWFRQGIyImAaA4KCg4OCgoOP5gOCgoODgoKDgDQDgoKDg4KCg4/To4KCg4OCgoOAJMOCgoODgoKDj9tDgoKDg4KCg4Akw4KCg4OCgoOCAoODgoKDg4AcgoODgoKDg4KCg4OCgoODgBTig4OCgoODj93Cg4OCgoODgoKDg4KCg4OAJ0KDg4KCg4OAAFAHwAAAOEA1UAIgAtADgARgBUAAABIzU0JisBIgYdASMiBhUUFjsBERQWMyEyNjURMzI2NTQmIyU0NjsBMhYdASM1ARQGIyEiJjURIREBIgYdARQWMzI2PQE0JjMiBh0BFBYzMjY9ATQmA12bRDCcMESbEBcXECdEMAGEMEQnEBcXEP4vFhCcEBboAV0XEP58EBcB0v7JEBYWEBAXF4wQFxcQEBYWAronMEREMCcXEBAW/gcwREQwAfkWEBAXJxAXFxAnJ/2TEBYWEAH5/gcBhBcQ6BAXFxDoEBcXEOgQFxcQ6BAXAAAABwAA/8AEAAPAAAMABwALAA8AEwAbACMAABMzFSM3MxUjJTMVIzczFSMlMxUjAxMhEzMTIRMBAyEDIwMhAwCAgMDAwAEAgIDAwMABAICAEBD9ABAgEAKAEP1AEAMAECAQ/YAQAcBAQEBAQEBAQEACQP5AAcD+gAGA/AABgP6AAUD+wAAABABQAIAEAAPAAAgADQAQAEAAAD8BIRczAyMDMxMzFyM3ARsBAyMiJjU0NjsBMjY1NCYrASIGFRQWFx4BOwEyFhUUBisBIgYVFBY7ATI2NTQmJy4BwjoBCDpywODAcppIOrw6AWSgoKBADRMTDYANExMNgCg4DQwNJRVADRMTDYANExMNgCg4DQwNJYDAwAKA/YACAMDA/gABAP8AAsATDQ0TEw0NEzgoEiENDxETDQ0TEw0NEzgoEiENDxEAAAAABABQ/8AEAAMAAAgADQAQAEAAAD8BIRczAyMDMxMzFyM3JQsBEyMiJjU0NjsBMjY1NCYrASIGFRQWFx4BOwEyFhUUBisBIgYVFBY7ATI2NTQmJy4BwjoBCDpywODAcppIOrw6AqSgoKBADRMTDYANExMNgCg4DQwNJRVADRMTDYANExMNgCg4DQwNJYDAwAKA/YACAMDAgP8AAQD9gBMNDRMTDQ0TOCgSIQ0PERMNDRMTDQ0TOCgSIQ0PEQAHAAD/wAQAA8AABwAPABMAFwAbAB8AIgAAAREhESMRIREFESERMxEhESUzFSMnMxUjJTMVIzczFSMlFwcBAAMAQP2AAsD9AEACgP5AgIDAgIABgICAwICA/IDAwAJAAYD+gAFA/sDA/kABwP6AAYCAQEBAQEBAQODAwAAAAQCA/8ADgAPAABcAAAEhFSMRIxEjESMRIicuAScmNTQ3PgE3NgGAAgCAgICANS8uRhQUFBRGLi8DwID8gAOA/IACABQURi4vNTUvLkYUFAACAAD/wAQAA8AAFwAaAAABIgcOAQcGFRQXHgEXFjMRMxEzETMRMzUJAgIANS8uRhQUFBRGLi81gICAgPwAAQD/AAPAFBRGLi81NS8uRhQU/gADgPyAA4CA/UABAAEAAAACAAD/wAQAA8AAFwAaAAABIgcOAQcGFRQXHgEXFjMRMxEzETMRMzUFCQEBADUvLkYUFBQURi4vNYCAgIABAP8AAQADwBQURi4vNTUvLkYUFP4AA4D8gAOAgMD/AP8AAAABAAD/zgQAA7MAYwAAASIHDgEHBhUUFx4BFxYXFjY1PAEnBiYxLgExJjYxHgExFjY3PgE3JicuAScmNTQ2Ny4BNzAWFz4BMzIWFz4BMRYGBx4BFRQHDgEHBgceARUUBhUUFjc2Nz4BNzY1NCcuAScmIwIAal1eiygoGhpdQUBMExABakISJyMnJigiXRYEEgsrKipCFBUcGQQMFUNKHkEhIUEeSkMVDAQZHBUUQyopKw4VARATTEFAXRoaKCiLXl1qA7MoKItdXmpUTU2ALy8ZBBIKCTYgF1QsHxgHAzI7BwoYIgoFDA04Ly9JKkUbCUk1AzEICQkIMQM1SQkbRSpKLy44DA0FCzAjNEwNChIEGS8wf01NVGpeXYsoKAAAAAABAAAAAQAAt9HlfV8PPPUACwQAAAAAANgVW8QAAAAA2BVbxAAA/8AEAAPAAAAACAACAAAAAAAAAAEAAAPA/8AAAAQAAAAAAAQAAAEAAAAAAAAAAAAAAAAAAABLBAAAAAAAAAAAAAAAAgAAAAQAAFUEAABVBAAAVQQAAFUEAAEABAABVgQAAKoEAAAzBAAAgAQAAFYEAACABAAAgAQAAIAEAACABAAAVQQAAFUEAABVBAABKwQAAIAEAAErBAAAVQQAAIAEAAErBAABqwQAAKsEAAAABAAA1QQAAGQEAAB1BAAA1QQAAAAEAACRBAAA4gQAAFUEAABVBAAAgAQAAGQEAADVBAAAVQQAAFUEAABVBAAAAAQAANUEAABVBAAAgAQAAIAEAADVBAAAVQQAAGsEAAEABAAAAAQAAEAEAAAABAAAQAQAAIAEAACABAAAAAQAAOsEAAAABAAAQAQAAHYEAAAABAAAfAQAAAAEAABQBAAAUAQAAAAEAACABAAAAAQAAAAEAAAAAAAAAAAKABQAHgCIAPIBXgHKAd4B7AI0AlACfgKiAtIDBgNCA3QD2gRSBHIEqAT2BQQFZAV8BYoFwgX6BjwGZgbOB3YHnggcCDIIcAkiCVoJogoqCkQKoAr0C3gLtgvoDJwMvAzcDPgNOg2IDaANrg46DnAOxA70DyQPMg9QD3gPnA/CEDoQrhDwEVARrhHsEhQSRBJ0EwQAAQAAAEsAewAJAAAAAAACAAAAAAAAAAAAAAAAAAAAAAAAAA4ArgABAAAAAAABAAcAAAABAAAAAAACAAcAYAABAAAAAAADAAcANgABAAAAAAAEAAcAdQABAAAAAAAFAAsAFQABAAAAAAAGAAcASwABAAAAAAAKABoAigADAAEECQABAA4ABwADAAEECQACAA4AZwADAAEECQADAA4APQADAAEECQAEAA4AfAADAAEECQAFABYAIAADAAEECQAGAA4AUgADAAEECQAKADQApGljb21vb24AaQBjAG8AbQBvAG8AblZlcnNpb24gMS4wAFYAZQByAHMAaQBvAG4AIAAxAC4AMGljb21vb24AaQBjAG8AbQBvAG8Abmljb21vb24AaQBjAG8AbQBvAG8AblJlZ3VsYXIAUgBlAGcAdQBsAGEAcmljb21vb24AaQBjAG8AbQBvAG8AbkZvbnQgZ2VuZXJhdGVkIGJ5IEljb01vb24uAEYAbwBuAHQAIABnAGUAbgBlAHIAYQB0AGUAZAAgAGIAeQAgAEkAYwBvAE0AbwBvAG4ALgAAAAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=);font-weight:400;font-style:normal}.index_bf-container__1HxhF [class*=\" bfi-\"],.index_bf-container__1HxhF [class^=bfi-],.index_bf-modal-root__1P_VQ [class*=\" bfi-\"],.index_bf-modal-root__1P_VQ [class^=bfi-]{font-family:braft-icons!important;speak:none;font-style:normal;font-weight:400;font-variant:normal;text-transform:none;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.index_bf-container__1HxhF .index_bfi-table__2fSIV:before,.index_bf-modal-root__1P_VQ .index_bfi-table__2fSIV:before{content:\"\\E228\"}.index_bf-container__1HxhF .index_bfi-clear_all__2OHjw:before,.index_bf-modal-root__1P_VQ .index_bfi-clear_all__2OHjw:before{content:\"\\E0B8\"}.index_bf-container__1HxhF .index_bfi-format_clear__2Z6-D:before,.index_bf-modal-root__1P_VQ .index_bfi-format_clear__2Z6-D:before{content:\"\\E239\"}.index_bf-container__1HxhF .index_bfi-hr__1-frF:before,.index_bf-modal-root__1P_VQ .index_bfi-hr__1-frF:before{content:\"\\E925\"}.index_bf-container__1HxhF .index_bfi-colorize__itEld:before,.index_bf-modal-root__1P_VQ .index_bfi-colorize__itEld:before{content:\"\\E3B8\"}.index_bf-container__1HxhF .index_bfi-crop_free__1UXYS:before,.index_bf-modal-root__1P_VQ .index_bfi-crop_free__1UXYS:before{content:\"\\E3C2\"}.index_bf-container__1HxhF .index_bfi-pause__1OwwZ:before,.index_bf-modal-root__1P_VQ .index_bfi-pause__1OwwZ:before{content:\"\\E034\"}.index_bf-container__1HxhF .index_bfi-play_arrow__1hL7J:before,.index_bf-modal-root__1P_VQ .index_bfi-play_arrow__1hL7J:before{content:\"\\E037\"}.index_bf-container__1HxhF .index_bfi-bin__h1RKN:before,.index_bf-modal-root__1P_VQ .index_bfi-bin__h1RKN:before{content:\"\\E9AC\"}.index_bf-container__1HxhF .index_bfi-replay__11NQk:before,.index_bf-modal-root__1P_VQ .index_bfi-replay__11NQk:before{content:\"\\E042\"}.index_bf-container__1HxhF .index_bfi-tune__axH8Q:before,.index_bf-modal-root__1P_VQ .index_bfi-tune__axH8Q:before{content:\"\\E429\"}.index_bf-container__1HxhF .index_bfi-close__3PhYm:before,.index_bf-modal-root__1P_VQ .index_bfi-close__3PhYm:before{content:\"\\E913\"}.index_bf-container__1HxhF .index_bfi-align-center__3WjMb:before,.index_bf-modal-root__1P_VQ .index_bfi-align-center__3WjMb:before{content:\"\\E028\"}.index_bf-container__1HxhF .index_bfi-align-justify__1QkRU:before,.index_bf-modal-root__1P_VQ .index_bfi-align-justify__1QkRU:before{content:\"\\E026\"}.index_bf-container__1HxhF .index_bfi-align-left__1oX7J:before,.index_bf-modal-root__1P_VQ .index_bfi-align-left__1oX7J:before{content:\"\\E027\"}.index_bf-container__1HxhF .index_bfi-align-right__1eM5M:before,.index_bf-modal-root__1P_VQ .index_bfi-align-right__1eM5M:before{content:\"\\E029\"}.index_bf-container__1HxhF .index_bfi-image-right__2H-ST:before,.index_bf-modal-root__1P_VQ .index_bfi-image-right__2H-ST:before{content:\"\\E914\"}.index_bf-container__1HxhF .index_bfi-image-left__zW8ok:before,.index_bf-modal-root__1P_VQ .index_bfi-image-left__zW8ok:before{content:\"\\E91E\"}.index_bf-container__1HxhF .index_bfi-music__1XtpY:before,.index_bf-modal-root__1P_VQ .index_bfi-music__1XtpY:before{content:\"\\E90E\"}.index_bf-container__1HxhF .index_bfi-camera__2X5Zb:before,.index_bf-modal-root__1P_VQ .index_bfi-camera__2X5Zb:before{content:\"\\E911\"}.index_bf-container__1HxhF .index_bfi-copy__16C-6:before,.index_bf-modal-root__1P_VQ .index_bfi-copy__16C-6:before{content:\"\\E92C\"}.index_bf-container__1HxhF .index_bfi-file-text__12Obf:before,.index_bf-modal-root__1P_VQ .index_bfi-file-text__12Obf:before{content:\"\\E926\"}.index_bf-container__1HxhF .index_bfi-film__2C48n:before,.index_bf-modal-root__1P_VQ .index_bfi-film__2C48n:before{content:\"\\E91C\"}.index_bf-container__1HxhF .index_bfi-github__3XePr:before,.index_bf-modal-root__1P_VQ .index_bfi-github__3XePr:before{content:\"\\EAB0\"}.index_bf-container__1HxhF .index_bfi-ltr__rDkrQ:before,.index_bf-modal-root__1P_VQ .index_bfi-ltr__rDkrQ:before{content:\"\\EA74\"}.index_bf-container__1HxhF .index_bfi-page-break__DhcNp:before,.index_bf-modal-root__1P_VQ .index_bfi-page-break__DhcNp:before{content:\"\\EA68\"}.index_bf-container__1HxhF .index_bfi-pagebreak__m3gAm:before,.index_bf-modal-root__1P_VQ .index_bfi-pagebreak__m3gAm:before{content:\"\\EA6E\"}.index_bf-container__1HxhF .index_bfi-paint-format__pjAiv:before,.index_bf-modal-root__1P_VQ .index_bfi-paint-format__pjAiv:before{content:\"\\E90C\"}.index_bf-container__1HxhF .index_bfi-paste__G7Hrh:before,.index_bf-modal-root__1P_VQ .index_bfi-paste__G7Hrh:before{content:\"\\E92D\"}.index_bf-container__1HxhF .index_bfi-pilcrow__4zJYM:before,.index_bf-modal-root__1P_VQ .index_bfi-pilcrow__4zJYM:before{content:\"\\EA73\"}.index_bf-container__1HxhF .index_bfi-pushpin__3PUoC:before,.index_bf-modal-root__1P_VQ .index_bfi-pushpin__3PUoC:before{content:\"\\E946\"}.index_bf-container__1HxhF .index_bfi-redo__1Q-LG:before,.index_bf-modal-root__1P_VQ .index_bfi-redo__1Q-LG:before{content:\"\\E968\"}.index_bf-container__1HxhF .index_bfi-rtl__sPVOR:before,.index_bf-modal-root__1P_VQ .index_bfi-rtl__sPVOR:before{content:\"\\EA75\"}.index_bf-container__1HxhF .index_bfi-spinner__Dek6M:before,.index_bf-modal-root__1P_VQ .index_bfi-spinner__Dek6M:before{content:\"\\E980\"}.index_bf-container__1HxhF .index_bfi-subscript__kYu6m:before,.index_bf-modal-root__1P_VQ .index_bfi-subscript__kYu6m:before{content:\"\\EA6C\"}.index_bf-container__1HxhF .index_bfi-superscript__3qvwy:before,.index_bf-modal-root__1P_VQ .index_bfi-superscript__3qvwy:before{content:\"\\EA6B\"}.index_bf-container__1HxhF .index_bfi-undo___pDce:before,.index_bf-modal-root__1P_VQ .index_bfi-undo___pDce:before{content:\"\\E967\"}.index_bf-container__1HxhF .index_bfi-media__3Ijxb:before,.index_bf-modal-root__1P_VQ .index_bfi-media__3Ijxb:before{content:\"\\E90F\"}.index_bf-container__1HxhF .index_bfi-add__LigZq:before,.index_bf-modal-root__1P_VQ .index_bfi-add__LigZq:before{content:\"\\E918\"}.index_bf-container__1HxhF .index_bfi-bold__dn9AC:before,.index_bf-modal-root__1P_VQ .index_bfi-bold__dn9AC:before{content:\"\\E904\"}.index_bf-container__1HxhF .index_bfi-code__3tDKj:before,.index_bf-modal-root__1P_VQ .index_bfi-code__3tDKj:before{content:\"\\E903\"}.index_bf-container__1HxhF .index_bfi-done__J_3zM:before,.index_bf-modal-root__1P_VQ .index_bfi-done__J_3zM:before{content:\"\\E912\"}.index_bf-container__1HxhF .index_bfi-drop-down__2-Azn:before,.index_bf-modal-root__1P_VQ .index_bfi-drop-down__2-Azn:before{content:\"\\E906\"}.index_bf-container__1HxhF .index_bfi-drop-up__f9cHI:before,.index_bf-modal-root__1P_VQ .index_bfi-drop-up__f9cHI:before{content:\"\\E909\"}.index_bf-container__1HxhF .index_bfi-emoji__37yM6:before,.index_bf-modal-root__1P_VQ .index_bfi-emoji__37yM6:before{content:\"\\E91B\"}.index_bf-container__1HxhF .index_bfi-font-size__1cbPf:before,.index_bf-modal-root__1P_VQ .index_bfi-font-size__1cbPf:before{content:\"\\E920\"}.index_bf-container__1HxhF .index_bfi-fullscreen__2txWy:before,.index_bf-modal-root__1P_VQ .index_bfi-fullscreen__2txWy:before{content:\"\\E910\"}.index_bf-container__1HxhF .index_bfi-fullscreen-exit__33svQ:before,.index_bf-modal-root__1P_VQ .index_bfi-fullscreen-exit__33svQ:before{content:\"\\E90D\"}.index_bf-container__1HxhF .index_bfi-help__xa9vi:before,.index_bf-modal-root__1P_VQ .index_bfi-help__xa9vi:before{content:\"\\E902\"}.index_bf-container__1HxhF .index_bfi-indent-decrease__1CtRw:before,.index_bf-modal-root__1P_VQ .index_bfi-indent-decrease__1CtRw:before{content:\"\\E92F\"}.index_bf-container__1HxhF .index_bfi-indent-increase__2kSOy:before,.index_bf-modal-root__1P_VQ .index_bfi-indent-increase__2kSOy:before{content:\"\\E92E\"}.index_bf-container__1HxhF .index_bfi-info__3gDtD:before,.index_bf-modal-root__1P_VQ .index_bfi-info__3gDtD:before{content:\"\\E901\"}.index_bf-container__1HxhF .index_bfi-italic__1ENXj:before,.index_bf-modal-root__1P_VQ .index_bfi-italic__1ENXj:before{content:\"\\E924\"}.index_bf-container__1HxhF .index_bfi-link__3-0Rp:before,.index_bf-modal-root__1P_VQ .index_bfi-link__3-0Rp:before{content:\"\\E91A\"}.index_bf-container__1HxhF .index_bfi-link-off__2xzYa:before,.index_bf-modal-root__1P_VQ .index_bfi-link-off__2xzYa:before{content:\"\\E919\"}.index_bf-container__1HxhF .index_bfi-list__3GI0k:before,.index_bf-modal-root__1P_VQ .index_bfi-list__3GI0k:before{content:\"\\E923\"}.index_bf-container__1HxhF .index_bfi-list-numbered__U2An6:before,.index_bf-modal-root__1P_VQ .index_bfi-list-numbered__U2An6:before{content:\"\\E922\"}.index_bf-container__1HxhF .index_bfi-menu__YEtEG:before,.index_bf-modal-root__1P_VQ .index_bfi-menu__YEtEG:before{content:\"\\E908\"}.index_bf-container__1HxhF .index_bfi-more-horiz__38Kqk:before,.index_bf-modal-root__1P_VQ .index_bfi-more-horiz__38Kqk:before{content:\"\\E90B\"}.index_bf-container__1HxhF .index_bfi-more-vert__1Xpoy:before,.index_bf-modal-root__1P_VQ .index_bfi-more-vert__1Xpoy:before{content:\"\\E90A\"}.index_bf-container__1HxhF .index_bfi-not-disturb__2wwfA:before,.index_bf-modal-root__1P_VQ .index_bfi-not-disturb__2wwfA:before{content:\"\\E907\"}.index_bf-container__1HxhF .index_bfi-print__1Vdsh:before,.index_bf-modal-root__1P_VQ .index_bfi-print__1Vdsh:before{content:\"\\E915\"}.index_bf-container__1HxhF .index_bfi-quote__1xD3O:before,.index_bf-modal-root__1P_VQ .index_bfi-quote__1xD3O:before{content:\"\\E921\"}.index_bf-container__1HxhF .index_bfi-search__2G21G:before,.index_bf-modal-root__1P_VQ .index_bfi-search__2G21G:before{content:\"\\E916\"}.index_bf-container__1HxhF .index_bfi-settingsx__5qqai:before,.index_bf-modal-root__1P_VQ .index_bfi-settingsx__5qqai:before{content:\"\\E917\"}.index_bf-container__1HxhF .index_bfi-share__LmF7D:before,.index_bf-modal-root__1P_VQ .index_bfi-share__LmF7D:before{content:\"\\E905\"}.index_bf-container__1HxhF .index_bfi-share-square__sA_aV:before,.index_bf-modal-root__1P_VQ .index_bfi-share-square__sA_aV:before{content:\"\\E900\"}.index_bf-container__1HxhF .index_bfi-strikethrough__3Oij6:before,.index_bf-modal-root__1P_VQ .index_bfi-strikethrough__3Oij6:before{content:\"\\E91F\"}.index_bf-container__1HxhF .index_bfi-text-color__1p69s .index_path1__1i_Zc:before,.index_bf-modal-root__1P_VQ .index_bfi-text-color__1p69s .index_path1__1i_Zc:before{font-family:braft-icons!important;content:\"\\E930\";opacity:.36}.index_bf-container__1HxhF .index_bfi-text-color__1p69s .index_path2__DFG_e:before,.index_bf-modal-root__1P_VQ .index_bfi-text-color__1p69s .index_path2__DFG_e:before{font-family:braft-icons!important;content:\"\\E931\";margin-left:-1em}.index_bf-container__1HxhF .index_bfi-underlined__oAOe6:before,.index_bf-modal-root__1P_VQ .index_bfi-underlined__oAOe6:before{content:\"\\E91D\"}.index_bf-content__5lf-j{height:500px;padding-bottom:10px;overflow:auto;font-size:16px}.index_bf-content__5lf-j img{-webkit-user-select:none;user-select:none}.index_bf-content__5lf-j *{line-height:normal}.index_bf-container__1HxhF{position:relative;height:100%;padding:0}.index_bf-container__1HxhF.index_disabled__KFBp_{pointer-events:none;opacity:.7;filter:grayscale(70%)}.index_bf-container__1HxhF.index_read-only__3HgNB .index_bf-controlbar__ej8fA{pointer-events:none}.index_bf-container__1HxhF.index_read-only__3HgNB .index_bf-image__1MXDI img:hover{outline:none}.index_bf-container__1HxhF.index_read-only__3HgNB .index_bf-hr__39L4E{pointer-events:none}.index_bf-container__1HxhF.index_fullscreen__2MrQv{position:fixed;display:flex;flex-direction:column;z-index:99999;top:0;right:0;bottom:0;left:0;background-color:#fff;height:100%!important}.index_bf-container__1HxhF.index_fullscreen__2MrQv .index_bf-content__5lf-j{flex-grow:1;height:auto}.index_bf-container__1HxhF .index_input-group__1Y0_d{display:block}.index_bf-container__1HxhF .index_input-group__1Y0_d input{box-sizing:border-box;width:100%;height:36px;padding:0 15px;font-size:14px}.index_bf-container__1HxhF .index_pull-left__33hHK{float:left}.index_bf-container__1HxhF .index_pull-right__22QW0{float:right}.index_bf-container__1HxhF button{line-height:normal}.index_bf-container__1HxhF button.index_default__11aE1,.index_bf-container__1HxhF button.index_ghost__q2A8s,.index_bf-container__1HxhF button.index_primary__1ex4f{height:32px;padding:0 20px;color:#fff;font-size:12px}.index_bf-container__1HxhF button.index_default__11aE1{background-color:hsla(0,0%,100%,.15);border:none}.index_bf-container__1HxhF button.index_default__11aE1:hover{background-color:hsla(0,0%,100%,.1)}.index_bf-container__1HxhF button.index_ghost__q2A8s{background-color:transparent;border:none;box-shadow:inset 0 0 0 .5px hsla(0,0%,100%,.5)}.index_bf-container__1HxhF button.index_ghost__q2A8s:hover{box-shadow:inset 0 0 0 .5px hsla(0,0%,100%,.7)}.index_bf-container__1HxhF button.index_primary__1ex4f{background-color:#3498db;border:none;color:#fff}.index_bf-container__1HxhF button.index_primary__1ex4f:hover{background-color:#2084c7}.index_bf-container__1HxhF .index_public-DraftEditorPlaceholder-root__1T6lJ{top:15px;left:15px;font-size:16px;pointer-events:none}.index_bf-container__1HxhF .index_DraftEditor-editorContainer__1FR0o{box-sizing:border-box;border:none}.index_bf-container__1HxhF .index_DraftEditor-root__mlfOI,.index_bf-container__1HxhF .index_public-DraftEditor-content__T2mZu{height:100%}.index_bf-container__1HxhF .index_public-DraftEditor-content__T2mZu{box-sizing:border-box;padding:15px;word-wrap:break-word;word-break:break-all}.index_bf-container__1HxhF .index_public-DraftEditor-content__T2mZu>div{padding-bottom:20px}.index_bf-container__1HxhF .index_public-DraftEditor-content__T2mZu .index_braft-link__1ZeMr{color:#4078c0}.index_bf-container__1HxhF .index_public-DraftEditor-content__T2mZu blockquote{margin:0 0 10px;padding:15px 20px;background-color:#f1f2f3;border-left:5px solid #ccc;color:#666;font-style:italic}.index_bf-container__1HxhF .index_public-DraftEditor-content__T2mZu pre{max-width:100%;max-height:100%;margin:10px 0;padding:15px;overflow:auto;background-color:#f1f2f3;border-radius:3px;color:#666;font-family:monospace;font-size:14px;font-weight:400;line-height:16px;word-wrap:break-word;white-space:pre-wrap}.index_bf-container__1HxhF .index_public-DraftEditor-content__T2mZu pre pre{margin:0;padding:0}.index_bf-container__1HxhF .index_bfa-left__3CWAj,.index_bf-container__1HxhF .index_bfa-left__3CWAj .index_public-DraftStyleDefault-ltr__3qMdW{text-align:left}.index_bf-container__1HxhF .index_bfa-right__Sy5sn,.index_bf-container__1HxhF .index_bfa-right__Sy5sn .index_public-DraftStyleDefault-ltr__3qMdW{text-align:right}.index_bf-container__1HxhF .index_bfa-center__3iBxk,.index_bf-container__1HxhF .index_bfa-center__3iBxk .index_public-DraftStyleDefault-ltr__3qMdW{text-align:center}.index_bf-container__1HxhF .index_bfa-justify__C4cm4,.index_bf-container__1HxhF .index_bfa-justify__C4cm4 .index_public-DraftStyleDefault-ltr__3qMdW{text-align:justify}.index_bf-container__1HxhF .index_bfa-center__3iBxk>div,.index_bf-container__1HxhF .index_bfa-justify__C4cm4>div,.index_bf-container__1HxhF .index_bfa-left__3CWAj>div,.index_bf-container__1HxhF .index_bfa-right__Sy5sn>div{display:inline-block}.index_bf-container__1HxhF .index_bff-left__pCNho:hover,.index_bf-container__1HxhF .index_bff-right__vpxtc:hover{z-index:2}.index_bf-container__1HxhF .index_bff-left__pCNho{position:relative;z-index:1;float:left;margin:0 10px 0 0}.index_bf-container__1HxhF .index_bff-right__vpxtc{position:relative;z-index:1;float:right;margin:0 0 0 10px}.index_bf-container__1HxhF .index_bftd-1__382qR{text-indent:2em;display:initial}.index_bf-container__1HxhF .index_bftd-2__11te-{text-indent:4em;display:initial}.index_bf-container__1HxhF .index_bftd-3__2BZeG{text-indent:6em;display:initial}.index_bf-container__1HxhF .index_bftd-4__4c1Sw{text-indent:8em;display:initial}.index_bf-container__1HxhF .index_bftd-5__34mlP{text-indent:10em;display:initial}.index_bf-container__1HxhF .index_bftd-6__1bsox{text-indent:12em;display:initial}.index_bf-container__1HxhF .index_bf-image__1MXDI,.index_bf-container__1HxhF .index_bf-media__33Dic{position:relative}.index_bf-container__1HxhF .index_bf-image__1MXDI img{display:block;max-width:100%;font-size:0;resize:both;outline-offset:1px}.index_bf-container__1HxhF .index_bf-image__1MXDI img:hover{outline:1px solid #3498db}.index_bf-container__1HxhF .index_bf-media-toolbar__28qi5{position:absolute;z-index:3;bottom:15px;left:50%;width:auto;background-color:#21242a;border-radius:2px;font-weight:400;text-align:center;white-space:nowrap;transform:translateX(-50%);box-shadow:0 5px 15px rgba(0,0,0,.2);-webkit-user-select:none;user-select:none}.index_bf-container__1HxhF .index_bf-media-toolbar__28qi5 .index_bf-media-toolbar-arrow__M3uMb,.index_bf-container__1HxhF .index_bf-media-toolbar__28qi5:before{position:absolute;bottom:-10px;left:50%;display:block;border:5px solid transparent;border-top-color:#21242a;content:\"\";transform:translateX(-5px)}.index_bf-container__1HxhF .index_bf-media-toolbar__28qi5 a{display:inline-block;min-width:40px;height:40px;color:hsla(0,0%,100%,.5);font-family:braft-icons!important;font-size:18px;font-weight:400;line-height:40px;text-align:center;text-decoration:none;text-transform:uppercase;cursor:pointer}.index_bf-container__1HxhF .index_bf-media-toolbar__28qi5 a:hover{color:#fff}.index_bf-container__1HxhF .index_bf-media-toolbar__28qi5 a:first-child{border-radius:2px 0 0 2px}.index_bf-container__1HxhF .index_bf-media-toolbar__28qi5 a:last-child{border-radius:0 2px 2px 0}.index_bf-container__1HxhF .index_bf-media-toolbar__28qi5 a.index_active__3_mlp{color:#3498db}.index_bf-video-player__3Eqxs video{display:block;width:640px;max-width:80vw;height:auto;margin:0 10px 10px;object-fit:contain}.index_bf-audio-player__67sKu audio{width:480px;max-width:80vw;margin:0 10px 10px}.index_bf-player-holder__1k4R5{position:relative;height:240px;overflow:hidden;background-color:#21242a;border-radius:3px}.index_bf-player-holder__1k4R5 .index_icon-badge__35ukN{position:absolute;z-index:2;top:0;left:0;height:30px;padding:0 15px;border-radius:0 0 3px 0;color:#fff;background-color:hsla(0,0%,100%,.1)}.index_bf-player-holder__1k4R5 .index_icon-badge__35ukN i,.index_bf-player-holder__1k4R5 .index_icon-badge__35ukN span{display:block;float:left;line-height:30px}.index_bf-player-holder__1k4R5 .index_icon-badge__35ukN span{margin-left:5px;font-size:12px}.index_bf-player-holder__1k4R5 .index_button-remove__cTw4D{position:absolute;z-index:2;top:5px;right:5px;width:40px;height:40px;background-color:transparent;border:none;border-radius:50%;outline:none;color:#fff;font-size:24px;text-align:center;cursor:pointer}.index_bf-player-holder__1k4R5 .index_button-remove__cTw4D:hover{color:#e74c3c}.index_bf-player-holder__1k4R5 .index_button-play__1GpMM{position:relative;z-index:2;display:block;width:80px;height:80px;margin:40px auto 20px;background-color:rgba(0,0,0,.7);border:none;border-radius:50%;outline:none;color:#fff;font-size:48px;line-height:80px;text-align:center;backdrop-filter:blur(10px);-webkit-backdrop-filter:blur(10px);cursor:pointer}.index_bf-player-holder__1k4R5 .index_button-play__1GpMM:hover{background-color:#3498db}.index_bf-player-holder__1k4R5 .index_bf-name__3FBAI{position:relative;z-index:2;margin:0;color:#fff;font-size:14px;font-weight:500;text-align:center}.index_bf-player-holder__1k4R5 .index_bf-url__1di3g{position:relative;z-index:2;width:70%;margin:10px auto;color:hsla(0,0%,100%,.5);font-size:12px;font-weight:400;text-align:center}.index_bf-player-holder__1k4R5 .index_bf-poster__drCvq{position:absolute;top:0;left:0;width:100%;height:100%;background-repeat:no-repeat;background-position:50% 50%;background-size:cover;opacity:.3}.index_bf-modal__23mEu{position:fixed;z-index:99999;top:0;left:0;width:100%;height:100%}.index_bf-modal__23mEu button{outline:none}.index_bf-modal-mask__3MKbg{position:absolute;z-index:1;top:0;left:0;width:100%;height:100%;background-color:rgba(0,0,0,.1);opacity:0;transition:opacity .2s}.index_bf-modal-content__1RScF{position:absolute;z-index:2;top:45%;left:50%;max-width:95%;background-color:#fff;border-radius:2px;box-shadow:0 15px 30px rgba(0,0,0,.1);opacity:0;transform:translate(-50%,-40%);transition:transform .2s,opacity .2s}.index_bf-modal-header__3jeX-{height:50px}.index_bf-modal-caption__2z9hD{float:left;margin:0;padding:0 15px;color:#999;font-size:14px;font-weight:400;line-height:50px}.index_bf-modal-close-button__13UMv{float:right;width:50px;height:50px;background-color:transparent;border:none;color:#ccc;font-size:18px;cursor:pointer}.index_bf-modal-close-button__13UMv:hover{color:#e74c3c}.index_bf-modal-body__3MjbZ{overflow:auto}.index_bf-modal-footer__3Pc0k{min-height:15px;padding:0 15px;overflow:hidden}.index_bf-modal-addon-text__3dQDG{float:left;color:#999;font-size:12px;line-height:60px}.index_bf-modal-buttons__2IuAO{float:right}.index_bf-modal-cancel__30ePe,.index_bf-modal-confirm__3woeJ{height:36px;margin:12px 0 12px 15px;padding:0 30px;border:none;border-radius:2px;font-size:12px;font-weight:700;cursor:pointer}.index_bf-modal-cancel__30ePe{background-color:#e8e9ea;color:#999}.index_bf-modal-cancel__30ePe:hover{background-color:#d8d9da}.index_bf-modal-confirm__3woeJ{background-color:#3498db;color:#fff}.index_bf-modal-confirm__3woeJ:hover{background-color:#2084c7}.index_bf-modal-confirm__3woeJ.index_disabled__KFBp_{opacity:.3;pointer-events:none;filter:grayscale(.4)}.index_bf-modal-root__1P_VQ.index_active__3_mlp .index_bf-modal-mask__3MKbg{opacity:1}.index_bf-modal-root__1P_VQ.index_active__3_mlp .index_bf-modal-content__1RScF{opacity:1;transform:translate(-50%,-50%)}.index_bf-content__5lf-j .index_bf-hr__39L4E{position:relative;box-sizing:content-box;height:15px;padding-top:15px;text-align:center}.index_bf-content__5lf-j .index_bf-hr__39L4E:before{display:block;height:1px;background-color:rgba(0,0,0,.1);content:\"\"}.index_bf-content__5lf-j .index_bf-hr__39L4E:hover:before{background-color:rgba(0,0,0,.3)}.index_bf-content__5lf-j .index_bf-hr__39L4E:hover .index_bf-media-toolbar__28qi5{display:block}.index_bf-content__5lf-j .index_bf-hr__39L4E .index_bf-media-toolbar__28qi5{display:none}.index_bf-image-link-editor__L5XLU,.index_bf-image-size-editor__3DAVi{padding-bottom:1px;overflow:hidden;border-radius:2px 2px 0 0;box-shadow:inset 0 -1px 0 0 hsla(0,0%,100%,.1)}.index_bf-image-link-editor__L5XLU .index_editor-input-group__1hcX3,.index_bf-image-size-editor__3DAVi .index_editor-input-group__1hcX3{width:300px;margin:8px 10px;overflow:hidden}.index_bf-image-link-editor__L5XLU input,.index_bf-image-size-editor__3DAVi input{display:block;float:left;box-sizing:content-box;height:32px;margin:0 5px 0 0;padding:0 10px;background-color:hsla(0,0%,100%,.1);border:none;border-radius:2px;outline:none;box-shadow:inset 0 0 0 1px hsla(0,0%,100%,.1);color:#fff;font-weight:700}.index_bf-image-link-editor__L5XLU input:hover,.index_bf-image-size-editor__3DAVi input:hover{box-shadow:inset 0 0 0 1px rgba(52,152,219,.5)}.index_bf-image-link-editor__L5XLU input:focus,.index_bf-image-size-editor__3DAVi input:focus{box-shadow:inset 0 0 0 1px #3498db}.index_bf-image-link-editor__L5XLU button,.index_bf-image-size-editor__3DAVi button{float:left;width:90px;height:32px;margin:0;padding:0 20px;background-color:#3498db;border:none;color:#fff;font-size:12px;border-radius:2px;cursor:pointer}.index_bf-image-link-editor__L5XLU button:hover,.index_bf-image-size-editor__3DAVi button:hover{background-color:#2084c7}.index_bf-image-size-editor__3DAVi input{width:80px}.index_bf-image-link-editor__L5XLU input{width:185px}.index_bf-image-link-editor__L5XLU .index_switch-group__3nsEF{height:16px;margin:10px}.index_bf-image-link-editor__L5XLU .index_switch-group__3nsEF .index_bf-switch__1LPr-{float:left}.index_bf-image-link-editor__L5XLU .index_switch-group__3nsEF label{float:left;margin-left:15px;color:#999;font-size:12px;line-height:16px}.index_bf-content__5lf-j .index_bf-image__1MXDI{position:relative}.index_bf-content__5lf-j .index_bf-image__1MXDI .index_bf-csize-icon__13EM-{position:absolute;z-index:2;width:10px;height:10px;background-color:rgba(52,152,219,.3)}.index_bf-content__5lf-j .index_bf-image__1MXDI .index_bf-csize-icon__13EM-.index_right-bottom__2jlUD{right:0;bottom:0;cursor:se-resize}.index_bf-content__5lf-j .index_bf-image__1MXDI .index_bf-csize-icon__13EM-.index_left-bottom__1H0sb{left:0;bottom:0;cursor:sw-resize}.index_bf-content__5lf-j .index_bf-image__1MXDI .index_bf-pre-csize__2lLOX{position:absolute;z-index:1;background:transparent}.index_bf-content__5lf-j .index_bf-image__1MXDI .index_bf-pre-csize__2lLOX.index_rightbottom__S1Zly{left:0;top:0;border:1px dashed #00bfff}.index_bf-content__5lf-j .index_bf-image__1MXDI .index_bf-pre-csize__2lLOX.index_leftbottom__wbQiO{right:0;top:0;border:1px dashed #00bfff}.index_bf-content__5lf-j .index_bf-image__1MXDI .index_bf-media-toolbar__28qi5:before{visibility:hidden}.index_bf-content__5lf-j .index_bf-image__1MXDI .index_bf-media-toolbar__28qi5[data-align=center] [data-align=center],.index_bf-content__5lf-j .index_bf-image__1MXDI .index_bf-media-toolbar__28qi5[data-align=left] [data-align=left],.index_bf-content__5lf-j .index_bf-image__1MXDI .index_bf-media-toolbar__28qi5[data-align=right] [data-align=right],.index_bf-content__5lf-j .index_bf-image__1MXDI .index_bf-media-toolbar__28qi5[data-float=left] [data-float=left],.index_bf-content__5lf-j .index_bf-image__1MXDI .index_bf-media-toolbar__28qi5[data-float=right] [data-float=right]{color:#3498db}.index_headings-dropdown__1KzQP{min-width:110px}.index_headings-dropdown__1KzQP .index_menu__10kCt{width:200px;overflow:hidden}.index_headings-dropdown__1KzQP .index_menu__10kCt .index_menu-item__2_Ov-{padding:15px 20px;text-align:left;line-height:normal}.index_headings-dropdown__1KzQP .index_menu__10kCt .index_menu-item__2_Ov- h1,.index_headings-dropdown__1KzQP .index_menu__10kCt .index_menu-item__2_Ov- h2,.index_headings-dropdown__1KzQP .index_menu__10kCt .index_menu-item__2_Ov- h3,.index_headings-dropdown__1KzQP .index_menu__10kCt .index_menu-item__2_Ov- h4,.index_headings-dropdown__1KzQP .index_menu__10kCt .index_menu-item__2_Ov- h5,.index_headings-dropdown__1KzQP .index_menu__10kCt .index_menu-item__2_Ov- h6{margin:0;padding:0;color:inherit}.index_headings-dropdown__1KzQP .index_menu__10kCt .index_menu-item__2_Ov- h1{font-size:28px}.index_headings-dropdown__1KzQP .index_menu__10kCt .index_menu-item__2_Ov- h2{font-size:24px}.index_headings-dropdown__1KzQP .index_menu__10kCt .index_menu-item__2_Ov- h3{font-size:20px}.index_headings-dropdown__1KzQP .index_menu__10kCt .index_menu-item__2_Ov- h4{font-size:16px}.index_headings-dropdown__1KzQP .index_menu__10kCt .index_menu-item__2_Ov- h5{font-size:14px}.index_headings-dropdown__1KzQP .index_menu__10kCt .index_menu-item__2_Ov- h6{font-size:12px}.index_bf-link-editor__w7aBK{width:360px;padding-top:25px}.index_bf-link-editor__w7aBK .index_input-group__1Y0_d{margin:0 15px 8px}.index_bf-link-editor__w7aBK .index_input-group__1Y0_d input{background-color:hsla(0,0%,100%,.07);border:none;border-radius:2px;box-shadow:inset 0 0 0 1px hsla(0,0%,100%,.1);color:#fff;font-weight:700}.index_bf-link-editor__w7aBK .index_input-group__1Y0_d input:hover{box-shadow:inset 0 0 0 1px rgba(52,152,219,.5)}.index_bf-link-editor__w7aBK .index_input-group__1Y0_d input:focus{box-shadow:inset 0 0 0 1px #3498db}.index_bf-link-editor__w7aBK .index_input-group__1Y0_d input:disabled{color:hsla(0,0%,100%,.7);box-shadow:none}.index_bf-link-editor__w7aBK .index_switch-group__3nsEF{height:16px;margin:15px}.index_bf-link-editor__w7aBK .index_switch-group__3nsEF .index_bf-switch__1LPr-{float:left}.index_bf-link-editor__w7aBK .index_switch-group__3nsEF label{float:left;margin-left:15px;color:#999;font-size:12px;line-height:16px}.index_bf-link-editor__w7aBK .index_buttons__3QT_I{box-sizing:content-box;height:32px;margin-top:20px;padding:15px;overflow:hidden;box-shadow:inset 0 1px 0 0 hsla(0,0%,100%,.1)}.index_bf-link-editor__w7aBK .index_buttons__3QT_I .index_button-remove-link__2004W{color:#999;font-size:12px;line-height:32px;cursor:pointer}.index_bf-link-editor__w7aBK .index_buttons__3QT_I .index_button-remove-link__2004W:hover{color:#e74c3c}.index_bf-link-editor__w7aBK .index_buttons__3QT_I .index_button-remove-link__2004W i{margin-right:5px;font-size:16px}.index_bf-link-editor__w7aBK .index_buttons__3QT_I .index_button-remove-link__2004W i,.index_bf-link-editor__w7aBK .index_buttons__3QT_I .index_button-remove-link__2004W span{display:block;float:left;line-height:32px}.index_bf-link-editor__w7aBK .index_buttons__3QT_I button{margin-left:10px;border-radius:2px;font-weight:700;cursor:pointer}.index_bf-dropdown__zgKp1{position:relative;width:auto;height:36px;margin:0}.index_bf-dropdown__zgKp1.index_disabled__KFBp_{pointer-events:none;opacity:.3}.index_bf-dropdown__zgKp1.index_light-theme__iYoel .index_dropdown-content__2HerW{border:1px solid #ccc}.index_bf-dropdown__zgKp1.index_light-theme__iYoel .index_dropdown-content__2HerW .index_dropdown-arrow__3KWgU{background-color:#fff;border:1px solid #ccc}.index_bf-dropdown__zgKp1.index_light-theme__iYoel .index_dropdown-content__2HerW .index_dropdown-content-inner__5r4YN{background-color:#fff}.index_bf-dropdown__zgKp1 .index_dropdown-content__2HerW{box-sizing:content-box;position:absolute;z-index:10;top:100%;left:50%;visibility:hidden;float:left;width:auto;min-width:100%;margin-top:9px;border-radius:2px;box-shadow:0 5px 15px rgba(0,0,0,.2);opacity:0;cursor:default;transform:translate(-50%,20px);transition:.2s}.index_bf-dropdown__zgKp1 .index_dropdown-content__2HerW ::-webkit-scrollbar-track{background-color:transparent}.index_bf-dropdown__zgKp1 .index_dropdown-content__2HerW ::-webkit-scrollbar{width:4px;background-color:transparent;border-radius:2px}.index_bf-dropdown__zgKp1 .index_dropdown-content__2HerW ::-webkit-scrollbar-thumb{background-color:hsla(0,0%,100%,.3);border-radius:2px}.index_bf-dropdown__zgKp1 .index_dropdown-content__2HerW .index_dropdown-arrow__3KWgU{position:absolute;z-index:1;top:-3px;left:50%;width:10px;height:10px;background-color:#21242a;transform:translateX(-50%) rotate(45deg);transition:margin .2s}.index_bf-dropdown__zgKp1 .index_dropdown-content__2HerW .index_dropdown-arrow__3KWgU.index_active__3_mlp{background-color:#3498db}.index_bf-dropdown__zgKp1 .index_dropdown-content__2HerW .index_menu__10kCt{list-style:none;margin:0;padding:0;overflow:hidden;border-radius:2px}.index_bf-dropdown__zgKp1 .index_dropdown-content__2HerW .index_menu-item__2_Ov-{display:block;list-style:none;margin:0;font-size:16px;cursor:pointer}.index_bf-dropdown__zgKp1 .index_dropdown-content__2HerW .index_menu-item__2_Ov-:hover{background-color:rgba(0,0,0,.1)}.index_bf-dropdown__zgKp1 .index_dropdown-content__2HerW .index_menu-item__2_Ov-.index_active__3_mlp{background-color:#3498db;color:#fff}.index_bf-dropdown__zgKp1 .index_dropdown-content__2HerW .index_menu-item__2_Ov-:not(.index_active__3_mlp){color:hsla(0,0%,100%,.6);box-shadow:inset 0 -1px 0 0 hsla(0,0%,100%,.1)}.index_bf-dropdown__zgKp1 .index_dropdown-content-inner__5r4YN{position:relative;z-index:2;overflow:auto;background-color:#21242a;border-radius:2px}.index_bf-dropdown__zgKp1 .index_dropdown-handler__1xChS{position:relative;display:block;width:100%;height:36px;background-color:transparent;border:none;color:#6a6f7b;cursor:pointer}.index_bf-dropdown__zgKp1 .index_dropdown-handler__1xChS:hover{background-color:rgba(0,0,0,.05)}.index_bf-dropdown__zgKp1 .index_dropdown-handler__1xChS *{display:inline;padding:0;font-size:inherit;font-weight:400}.index_bf-dropdown__zgKp1 .index_dropdown-handler__1xChS>span{float:left;padding:0 10px;font-size:14px;line-height:36px;pointer-events:none}.index_bf-dropdown__zgKp1 .index_dropdown-handler__1xChS>span i{display:block;height:36px;font-size:16px;line-height:36px;text-align:center}.index_bf-dropdown__zgKp1 .index_dropdown-handler__1xChS .index_bfi-drop-down__2-Azn{float:right;width:30px;height:36px;font-size:16px;line-height:36px;text-align:center;pointer-events:none}.index_bf-dropdown__zgKp1.index_active__3_mlp .index_dropdown-handler__1xChS{background-color:rgba(0,0,0,.05)}.index_bf-dropdown__zgKp1.index_active__3_mlp .index_dropdown-content__2HerW{visibility:visible;opacity:1;transform:translate(-50%)}.index_text-color-dropdown__pnJCI.index_light-theme__iYoel .index_bf-color-switch-buttons__R4l-y button{border-bottom:1px solid #ccc;color:#616569}.index_text-color-dropdown__pnJCI.index_light-theme__iYoel .index_bf-color-switch-buttons__R4l-y button.index_active__3_mlp{border-bottom-color:#3498db;color:#3498db}.index_text-color-dropdown__pnJCI button.index_dropdown-handler__1xChS span{width:36px;padding:0;overflow:hidden;border-radius:2px}.index_text-color-dropdown__pnJCI .index_bf-text-color-picker-wrap__2xWAh{overflow:hidden}.index_text-color-dropdown__pnJCI .index_bf-color-switch-buttons__R4l-y{height:36px}.index_text-color-dropdown__pnJCI .index_bf-color-switch-buttons__R4l-y button{float:left;width:50%;height:36px;background-color:transparent;border:none;border-bottom:1px solid hsla(0,0%,100%,.1);color:hsla(0,0%,100%,.5);font-size:12px;font-weight:400;text-transform:uppercase;cursor:pointer}.index_text-color-dropdown__pnJCI .index_bf-color-switch-buttons__R4l-y button.index_active__3_mlp{border-bottom-color:#3498db;color:#3498db}.index_bf-colors__2Jog3{box-sizing:content-box;list-style:none;width:240px;margin:0;padding:15px;overflow:hidden}.index_bf-colors__2Jog3 li{box-sizing:content-box;display:block;float:left;width:24px;height:24px;margin:5px;padding:0;background-color:currentColor;border:3px solid transparent;border-radius:50%;cursor:pointer;transition:transform .2s}.index_bf-colors__2Jog3 li:hover{transform:scale(1.3)}.index_bf-colors__2Jog3 li.index_active__3_mlp{box-shadow:0 0 0 2px #3498db}.index_bf-font-size-dropdown__38pES{min-width:95px}.index_bf-font-sizes__2rRGp{box-sizing:content-box;width:210px;list-style:none;margin:0;padding:5px;overflow:hidden}.index_bf-font-sizes__2rRGp li{display:block;float:left;width:60px;height:30px;background-color:hsla(0,0%,100%,.1);border-radius:2px;margin:5px;color:#fff;font-size:12px;line-height:30px;text-align:center;text-transform:uppercase;cursor:pointer}.index_bf-font-sizes__2rRGp li:hover{background-color:hsla(0,0%,100%,.2)}.index_bf-font-sizes__2rRGp li.index_active__3_mlp{background-color:#3498db}.index_font-family-dropdown__rYXD5{min-width:120px}.index_font-family-dropdown__rYXD5 .index_dropdown-content__2HerW{width:180px}.index_font-family-dropdown__rYXD5 .index_menu-item__2_Ov-{padding:12px 15px}.index_bf-line-height-dropdown__ee0Ld{min-width:95px}.index_bf-line-heights__2Oa0w{box-sizing:content-box;width:210px;list-style:none;margin:0;padding:5px;overflow:hidden}.index_bf-line-heights__2Oa0w li{display:block;float:left;width:60px;height:30px;background-color:hsla(0,0%,100%,.1);border-radius:2px;margin:5px;color:#fff;font-size:12px;line-height:30px;text-align:center;text-transform:uppercase;cursor:pointer}.index_bf-line-heights__2Oa0w li:hover{background-color:hsla(0,0%,100%,.2)}.index_bf-line-heights__2Oa0w li.index_active__3_mlp{background-color:#3498db}.index_bf-letter-spacing-dropdown__1t21I{min-width:95px}.index_bf-letter-spacings__MYcL5{box-sizing:content-box;width:210px;list-style:none;margin:0;padding:5px;overflow:hidden}.index_bf-letter-spacings__MYcL5 li{display:block;float:left;width:60px;height:30px;background-color:hsla(0,0%,100%,.1);border-radius:2px;margin:5px;color:#fff;font-size:12px;line-height:30px;text-align:center;text-transform:uppercase;cursor:pointer}.index_bf-letter-spacings__MYcL5 li:hover{background-color:hsla(0,0%,100%,.2)}.index_bf-letter-spacings__MYcL5 li.index_active__3_mlp{background-color:#3498db}.index_bf-emojis-wrap__3FqEM{position:relative;width:210px;height:220px;overflow:hidden}.index_bf-emojis-wrap__3FqEM:after,.index_bf-emojis-wrap__3FqEM:before{position:absolute;z-index:1;right:0;left:0;height:30px;border-radius:2px;content:\"\";pointer-events:none}.index_bf-emojis-wrap__3FqEM:before{top:0;background-image:linear-gradient(0deg,rgba(33,36,42,0),#21242a)}.index_bf-emojis-wrap__3FqEM:after{bottom:0;background-image:linear-gradient(rgba(33,36,42,0),#21242a)}.index_bf-emojis__3p4Ps{box-sizing:content-box;width:200px;height:195px;list-style:none;margin:0;padding:15px 15px 20px;overflow:auto}.index_bf-emojis__3p4Ps li{display:block;float:left;width:30px;height:30px;margin:0;padding:0;color:#fff;border-radius:2px;font-family:Apple Color Emoji,Segoe UI,Segoe UI Emoji,Segoe UI Symbol;font-size:18px;line-height:32px;text-align:center;cursor:pointer;-webkit-user-select:none;user-select:none;transition:transform .2s}.index_bf-emojis__3p4Ps li:hover{transform:scale(1.5)}";
  33304. styleInject_es.styleInject(css);
  33305. var css$1 = ".emoticon_braft-emoticon-picker__26_HU{box-sizing:border-box;width:210px;height:210px;overflow:hidden}.emoticon_braft-emoticon-picker__26_HU:after,.emoticon_braft-emoticon-picker__26_HU:before{position:absolute;z-index:1;right:0;left:0;height:30px;border-radius:2px;content:\"\";pointer-events:none}.emoticon_braft-emoticon-picker__26_HU:before{top:0;background-image:linear-gradient(0deg,rgba(33,36,42,0),#21242a)}.emoticon_braft-emoticon-picker__26_HU:after{bottom:0;background-image:linear-gradient(rgba(33,36,42,0),#21242a)}.emoticon_braft-emoticon-picker__26_HU .emoticon_braft-emoticons-list__P1AeK{box-sizing:content-box;width:200px;height:190px;margin:0;padding:15px 15px 20px;overflow:auto}.emoticon_braft-emoticon-picker__26_HU .emoticon_braft-emoticons-list__P1AeK img{display:block;box-sizing:content-box;float:left;width:20px;height:20px;margin:3px;padding:5px;border-radius:3px}.emoticon_braft-emoticon-picker__26_HU .emoticon_braft-emoticons-list__P1AeK img:hover{background-color:#3498db}.emoticon_braft-emoticon-in-editor__10cwl{position:relative;padding:0 2px;letter-spacing:12px}.emoticon_braft-emoticon-in-editor__10cwl img{position:absolute;top:0;left:2px;width:16px;height:16px}";
  33306. styleInject_es.styleInject(css$1);
  33307. var immutable$3 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
  33308. /**
  33309. * Copyright (c) 2014-present, Facebook, Inc.
  33310. *
  33311. * This source code is licensed under the MIT license found in the
  33312. * LICENSE file in the root directory of this source tree.
  33313. */
  33314. (function (global, factory) {
  33315. factory(exports) ;
  33316. }(_commonjsHelpers.commonjsGlobal, (function (exports) {
  33317. // Used for setting prototype methods that IE8 chokes on.
  33318. var DELETE = 'delete';
  33319. // Constants describing the size of trie nodes.
  33320. var SHIFT = 5; // Resulted in best performance after ______?
  33321. var SIZE = 1 << SHIFT;
  33322. var MASK = SIZE - 1;
  33323. // A consistent shared value representing "not set" which equals nothing other
  33324. // than itself, and nothing that could be provided externally.
  33325. var NOT_SET = {};
  33326. // Boolean references, Rough equivalent of `bool &`.
  33327. function MakeRef() {
  33328. return { value: false };
  33329. }
  33330. function SetRef(ref) {
  33331. if (ref) {
  33332. ref.value = true;
  33333. }
  33334. }
  33335. // A function which returns a value representing an "owner" for transient writes
  33336. // to tries. The return value will only ever equal itself, and will not equal
  33337. // the return of any subsequent call of this function.
  33338. function OwnerID() {}
  33339. function ensureSize(iter) {
  33340. if (iter.size === undefined) {
  33341. iter.size = iter.__iterate(returnTrue);
  33342. }
  33343. return iter.size;
  33344. }
  33345. function wrapIndex(iter, index) {
  33346. // This implements "is array index" which the ECMAString spec defines as:
  33347. //
  33348. // A String property name P is an array index if and only if
  33349. // ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal
  33350. // to 2^32−1.
  33351. //
  33352. // http://www.ecma-international.org/ecma-262/6.0/#sec-array-exotic-objects
  33353. if (typeof index !== 'number') {
  33354. var uint32Index = index >>> 0; // N >>> 0 is shorthand for ToUint32
  33355. if ('' + uint32Index !== index || uint32Index === 4294967295) {
  33356. return NaN;
  33357. }
  33358. index = uint32Index;
  33359. }
  33360. return index < 0 ? ensureSize(iter) + index : index;
  33361. }
  33362. function returnTrue() {
  33363. return true;
  33364. }
  33365. function wholeSlice(begin, end, size) {
  33366. return (
  33367. ((begin === 0 && !isNeg(begin)) ||
  33368. (size !== undefined && begin <= -size)) &&
  33369. (end === undefined || (size !== undefined && end >= size))
  33370. );
  33371. }
  33372. function resolveBegin(begin, size) {
  33373. return resolveIndex(begin, size, 0);
  33374. }
  33375. function resolveEnd(end, size) {
  33376. return resolveIndex(end, size, size);
  33377. }
  33378. function resolveIndex(index, size, defaultIndex) {
  33379. // Sanitize indices using this shorthand for ToInt32(argument)
  33380. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  33381. return index === undefined
  33382. ? defaultIndex
  33383. : isNeg(index)
  33384. ? size === Infinity
  33385. ? size
  33386. : Math.max(0, size + index) | 0
  33387. : size === undefined || size === index
  33388. ? index
  33389. : Math.min(size, index) | 0;
  33390. }
  33391. function isNeg(value) {
  33392. // Account for -0 which is negative, but not less than 0.
  33393. return value < 0 || (value === 0 && 1 / value === -Infinity);
  33394. }
  33395. // Note: value is unchanged to not break immutable-devtools.
  33396. var IS_COLLECTION_SYMBOL = '@@__IMMUTABLE_ITERABLE__@@';
  33397. function isCollection(maybeCollection) {
  33398. return Boolean(maybeCollection && maybeCollection[IS_COLLECTION_SYMBOL]);
  33399. }
  33400. var IS_KEYED_SYMBOL = '@@__IMMUTABLE_KEYED__@@';
  33401. function isKeyed(maybeKeyed) {
  33402. return Boolean(maybeKeyed && maybeKeyed[IS_KEYED_SYMBOL]);
  33403. }
  33404. var IS_INDEXED_SYMBOL = '@@__IMMUTABLE_INDEXED__@@';
  33405. function isIndexed(maybeIndexed) {
  33406. return Boolean(maybeIndexed && maybeIndexed[IS_INDEXED_SYMBOL]);
  33407. }
  33408. function isAssociative(maybeAssociative) {
  33409. return isKeyed(maybeAssociative) || isIndexed(maybeAssociative);
  33410. }
  33411. var Collection = function Collection(value) {
  33412. return isCollection(value) ? value : Seq(value);
  33413. };
  33414. var KeyedCollection = /*@__PURE__*/(function (Collection) {
  33415. function KeyedCollection(value) {
  33416. return isKeyed(value) ? value : KeyedSeq(value);
  33417. }
  33418. if ( Collection ) KeyedCollection.__proto__ = Collection;
  33419. KeyedCollection.prototype = Object.create( Collection && Collection.prototype );
  33420. KeyedCollection.prototype.constructor = KeyedCollection;
  33421. return KeyedCollection;
  33422. }(Collection));
  33423. var IndexedCollection = /*@__PURE__*/(function (Collection) {
  33424. function IndexedCollection(value) {
  33425. return isIndexed(value) ? value : IndexedSeq(value);
  33426. }
  33427. if ( Collection ) IndexedCollection.__proto__ = Collection;
  33428. IndexedCollection.prototype = Object.create( Collection && Collection.prototype );
  33429. IndexedCollection.prototype.constructor = IndexedCollection;
  33430. return IndexedCollection;
  33431. }(Collection));
  33432. var SetCollection = /*@__PURE__*/(function (Collection) {
  33433. function SetCollection(value) {
  33434. return isCollection(value) && !isAssociative(value) ? value : SetSeq(value);
  33435. }
  33436. if ( Collection ) SetCollection.__proto__ = Collection;
  33437. SetCollection.prototype = Object.create( Collection && Collection.prototype );
  33438. SetCollection.prototype.constructor = SetCollection;
  33439. return SetCollection;
  33440. }(Collection));
  33441. Collection.Keyed = KeyedCollection;
  33442. Collection.Indexed = IndexedCollection;
  33443. Collection.Set = SetCollection;
  33444. var IS_SEQ_SYMBOL = '@@__IMMUTABLE_SEQ__@@';
  33445. function isSeq(maybeSeq) {
  33446. return Boolean(maybeSeq && maybeSeq[IS_SEQ_SYMBOL]);
  33447. }
  33448. var IS_RECORD_SYMBOL = '@@__IMMUTABLE_RECORD__@@';
  33449. function isRecord(maybeRecord) {
  33450. return Boolean(maybeRecord && maybeRecord[IS_RECORD_SYMBOL]);
  33451. }
  33452. function isImmutable(maybeImmutable) {
  33453. return isCollection(maybeImmutable) || isRecord(maybeImmutable);
  33454. }
  33455. var IS_ORDERED_SYMBOL = '@@__IMMUTABLE_ORDERED__@@';
  33456. function isOrdered(maybeOrdered) {
  33457. return Boolean(maybeOrdered && maybeOrdered[IS_ORDERED_SYMBOL]);
  33458. }
  33459. var ITERATE_KEYS = 0;
  33460. var ITERATE_VALUES = 1;
  33461. var ITERATE_ENTRIES = 2;
  33462. var REAL_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
  33463. var FAUX_ITERATOR_SYMBOL = '@@iterator';
  33464. var ITERATOR_SYMBOL = REAL_ITERATOR_SYMBOL || FAUX_ITERATOR_SYMBOL;
  33465. var Iterator = function Iterator(next) {
  33466. this.next = next;
  33467. };
  33468. Iterator.prototype.toString = function toString () {
  33469. return '[Iterator]';
  33470. };
  33471. Iterator.KEYS = ITERATE_KEYS;
  33472. Iterator.VALUES = ITERATE_VALUES;
  33473. Iterator.ENTRIES = ITERATE_ENTRIES;
  33474. Iterator.prototype.inspect = Iterator.prototype.toSource = function() {
  33475. return this.toString();
  33476. };
  33477. Iterator.prototype[ITERATOR_SYMBOL] = function() {
  33478. return this;
  33479. };
  33480. function iteratorValue(type, k, v, iteratorResult) {
  33481. var value = type === 0 ? k : type === 1 ? v : [k, v];
  33482. iteratorResult
  33483. ? (iteratorResult.value = value)
  33484. : (iteratorResult = {
  33485. value: value,
  33486. done: false,
  33487. });
  33488. return iteratorResult;
  33489. }
  33490. function iteratorDone() {
  33491. return { value: undefined, done: true };
  33492. }
  33493. function hasIterator(maybeIterable) {
  33494. return !!getIteratorFn(maybeIterable);
  33495. }
  33496. function isIterator(maybeIterator) {
  33497. return maybeIterator && typeof maybeIterator.next === 'function';
  33498. }
  33499. function getIterator(iterable) {
  33500. var iteratorFn = getIteratorFn(iterable);
  33501. return iteratorFn && iteratorFn.call(iterable);
  33502. }
  33503. function getIteratorFn(iterable) {
  33504. var iteratorFn =
  33505. iterable &&
  33506. ((REAL_ITERATOR_SYMBOL && iterable[REAL_ITERATOR_SYMBOL]) ||
  33507. iterable[FAUX_ITERATOR_SYMBOL]);
  33508. if (typeof iteratorFn === 'function') {
  33509. return iteratorFn;
  33510. }
  33511. }
  33512. var hasOwnProperty = Object.prototype.hasOwnProperty;
  33513. function isArrayLike(value) {
  33514. if (Array.isArray(value) || typeof value === 'string') {
  33515. return true;
  33516. }
  33517. return (
  33518. value &&
  33519. typeof value === 'object' &&
  33520. Number.isInteger(value.length) &&
  33521. value.length >= 0 &&
  33522. (value.length === 0
  33523. ? // Only {length: 0} is considered Array-like.
  33524. Object.keys(value).length === 1
  33525. : // An object is only Array-like if it has a property where the last value
  33526. // in the array-like may be found (which could be undefined).
  33527. value.hasOwnProperty(value.length - 1))
  33528. );
  33529. }
  33530. var Seq = /*@__PURE__*/(function (Collection$$1) {
  33531. function Seq(value) {
  33532. return value === null || value === undefined
  33533. ? emptySequence()
  33534. : isImmutable(value)
  33535. ? value.toSeq()
  33536. : seqFromValue(value);
  33537. }
  33538. if ( Collection$$1 ) Seq.__proto__ = Collection$$1;
  33539. Seq.prototype = Object.create( Collection$$1 && Collection$$1.prototype );
  33540. Seq.prototype.constructor = Seq;
  33541. Seq.prototype.toSeq = function toSeq () {
  33542. return this;
  33543. };
  33544. Seq.prototype.toString = function toString () {
  33545. return this.__toString('Seq {', '}');
  33546. };
  33547. Seq.prototype.cacheResult = function cacheResult () {
  33548. if (!this._cache && this.__iterateUncached) {
  33549. this._cache = this.entrySeq().toArray();
  33550. this.size = this._cache.length;
  33551. }
  33552. return this;
  33553. };
  33554. // abstract __iterateUncached(fn, reverse)
  33555. Seq.prototype.__iterate = function __iterate (fn, reverse) {
  33556. var cache = this._cache;
  33557. if (cache) {
  33558. var size = cache.length;
  33559. var i = 0;
  33560. while (i !== size) {
  33561. var entry = cache[reverse ? size - ++i : i++];
  33562. if (fn(entry[1], entry[0], this) === false) {
  33563. break;
  33564. }
  33565. }
  33566. return i;
  33567. }
  33568. return this.__iterateUncached(fn, reverse);
  33569. };
  33570. // abstract __iteratorUncached(type, reverse)
  33571. Seq.prototype.__iterator = function __iterator (type, reverse) {
  33572. var cache = this._cache;
  33573. if (cache) {
  33574. var size = cache.length;
  33575. var i = 0;
  33576. return new Iterator(function () {
  33577. if (i === size) {
  33578. return iteratorDone();
  33579. }
  33580. var entry = cache[reverse ? size - ++i : i++];
  33581. return iteratorValue(type, entry[0], entry[1]);
  33582. });
  33583. }
  33584. return this.__iteratorUncached(type, reverse);
  33585. };
  33586. return Seq;
  33587. }(Collection));
  33588. var KeyedSeq = /*@__PURE__*/(function (Seq) {
  33589. function KeyedSeq(value) {
  33590. return value === null || value === undefined
  33591. ? emptySequence().toKeyedSeq()
  33592. : isCollection(value)
  33593. ? isKeyed(value)
  33594. ? value.toSeq()
  33595. : value.fromEntrySeq()
  33596. : isRecord(value)
  33597. ? value.toSeq()
  33598. : keyedSeqFromValue(value);
  33599. }
  33600. if ( Seq ) KeyedSeq.__proto__ = Seq;
  33601. KeyedSeq.prototype = Object.create( Seq && Seq.prototype );
  33602. KeyedSeq.prototype.constructor = KeyedSeq;
  33603. KeyedSeq.prototype.toKeyedSeq = function toKeyedSeq () {
  33604. return this;
  33605. };
  33606. return KeyedSeq;
  33607. }(Seq));
  33608. var IndexedSeq = /*@__PURE__*/(function (Seq) {
  33609. function IndexedSeq(value) {
  33610. return value === null || value === undefined
  33611. ? emptySequence()
  33612. : isCollection(value)
  33613. ? isKeyed(value)
  33614. ? value.entrySeq()
  33615. : value.toIndexedSeq()
  33616. : isRecord(value)
  33617. ? value.toSeq().entrySeq()
  33618. : indexedSeqFromValue(value);
  33619. }
  33620. if ( Seq ) IndexedSeq.__proto__ = Seq;
  33621. IndexedSeq.prototype = Object.create( Seq && Seq.prototype );
  33622. IndexedSeq.prototype.constructor = IndexedSeq;
  33623. IndexedSeq.of = function of (/*...values*/) {
  33624. return IndexedSeq(arguments);
  33625. };
  33626. IndexedSeq.prototype.toIndexedSeq = function toIndexedSeq () {
  33627. return this;
  33628. };
  33629. IndexedSeq.prototype.toString = function toString () {
  33630. return this.__toString('Seq [', ']');
  33631. };
  33632. return IndexedSeq;
  33633. }(Seq));
  33634. var SetSeq = /*@__PURE__*/(function (Seq) {
  33635. function SetSeq(value) {
  33636. return (isCollection(value) && !isAssociative(value)
  33637. ? value
  33638. : IndexedSeq(value)
  33639. ).toSetSeq();
  33640. }
  33641. if ( Seq ) SetSeq.__proto__ = Seq;
  33642. SetSeq.prototype = Object.create( Seq && Seq.prototype );
  33643. SetSeq.prototype.constructor = SetSeq;
  33644. SetSeq.of = function of (/*...values*/) {
  33645. return SetSeq(arguments);
  33646. };
  33647. SetSeq.prototype.toSetSeq = function toSetSeq () {
  33648. return this;
  33649. };
  33650. return SetSeq;
  33651. }(Seq));
  33652. Seq.isSeq = isSeq;
  33653. Seq.Keyed = KeyedSeq;
  33654. Seq.Set = SetSeq;
  33655. Seq.Indexed = IndexedSeq;
  33656. Seq.prototype[IS_SEQ_SYMBOL] = true;
  33657. // #pragma Root Sequences
  33658. var ArraySeq = /*@__PURE__*/(function (IndexedSeq) {
  33659. function ArraySeq(array) {
  33660. this._array = array;
  33661. this.size = array.length;
  33662. }
  33663. if ( IndexedSeq ) ArraySeq.__proto__ = IndexedSeq;
  33664. ArraySeq.prototype = Object.create( IndexedSeq && IndexedSeq.prototype );
  33665. ArraySeq.prototype.constructor = ArraySeq;
  33666. ArraySeq.prototype.get = function get (index, notSetValue) {
  33667. return this.has(index) ? this._array[wrapIndex(this, index)] : notSetValue;
  33668. };
  33669. ArraySeq.prototype.__iterate = function __iterate (fn, reverse) {
  33670. var array = this._array;
  33671. var size = array.length;
  33672. var i = 0;
  33673. while (i !== size) {
  33674. var ii = reverse ? size - ++i : i++;
  33675. if (fn(array[ii], ii, this) === false) {
  33676. break;
  33677. }
  33678. }
  33679. return i;
  33680. };
  33681. ArraySeq.prototype.__iterator = function __iterator (type, reverse) {
  33682. var array = this._array;
  33683. var size = array.length;
  33684. var i = 0;
  33685. return new Iterator(function () {
  33686. if (i === size) {
  33687. return iteratorDone();
  33688. }
  33689. var ii = reverse ? size - ++i : i++;
  33690. return iteratorValue(type, ii, array[ii]);
  33691. });
  33692. };
  33693. return ArraySeq;
  33694. }(IndexedSeq));
  33695. var ObjectSeq = /*@__PURE__*/(function (KeyedSeq) {
  33696. function ObjectSeq(object) {
  33697. var keys = Object.keys(object);
  33698. this._object = object;
  33699. this._keys = keys;
  33700. this.size = keys.length;
  33701. }
  33702. if ( KeyedSeq ) ObjectSeq.__proto__ = KeyedSeq;
  33703. ObjectSeq.prototype = Object.create( KeyedSeq && KeyedSeq.prototype );
  33704. ObjectSeq.prototype.constructor = ObjectSeq;
  33705. ObjectSeq.prototype.get = function get (key, notSetValue) {
  33706. if (notSetValue !== undefined && !this.has(key)) {
  33707. return notSetValue;
  33708. }
  33709. return this._object[key];
  33710. };
  33711. ObjectSeq.prototype.has = function has (key) {
  33712. return hasOwnProperty.call(this._object, key);
  33713. };
  33714. ObjectSeq.prototype.__iterate = function __iterate (fn, reverse) {
  33715. var object = this._object;
  33716. var keys = this._keys;
  33717. var size = keys.length;
  33718. var i = 0;
  33719. while (i !== size) {
  33720. var key = keys[reverse ? size - ++i : i++];
  33721. if (fn(object[key], key, this) === false) {
  33722. break;
  33723. }
  33724. }
  33725. return i;
  33726. };
  33727. ObjectSeq.prototype.__iterator = function __iterator (type, reverse) {
  33728. var object = this._object;
  33729. var keys = this._keys;
  33730. var size = keys.length;
  33731. var i = 0;
  33732. return new Iterator(function () {
  33733. if (i === size) {
  33734. return iteratorDone();
  33735. }
  33736. var key = keys[reverse ? size - ++i : i++];
  33737. return iteratorValue(type, key, object[key]);
  33738. });
  33739. };
  33740. return ObjectSeq;
  33741. }(KeyedSeq));
  33742. ObjectSeq.prototype[IS_ORDERED_SYMBOL] = true;
  33743. var CollectionSeq = /*@__PURE__*/(function (IndexedSeq) {
  33744. function CollectionSeq(collection) {
  33745. this._collection = collection;
  33746. this.size = collection.length || collection.size;
  33747. }
  33748. if ( IndexedSeq ) CollectionSeq.__proto__ = IndexedSeq;
  33749. CollectionSeq.prototype = Object.create( IndexedSeq && IndexedSeq.prototype );
  33750. CollectionSeq.prototype.constructor = CollectionSeq;
  33751. CollectionSeq.prototype.__iterateUncached = function __iterateUncached (fn, reverse) {
  33752. if (reverse) {
  33753. return this.cacheResult().__iterate(fn, reverse);
  33754. }
  33755. var collection = this._collection;
  33756. var iterator = getIterator(collection);
  33757. var iterations = 0;
  33758. if (isIterator(iterator)) {
  33759. var step;
  33760. while (!(step = iterator.next()).done) {
  33761. if (fn(step.value, iterations++, this) === false) {
  33762. break;
  33763. }
  33764. }
  33765. }
  33766. return iterations;
  33767. };
  33768. CollectionSeq.prototype.__iteratorUncached = function __iteratorUncached (type, reverse) {
  33769. if (reverse) {
  33770. return this.cacheResult().__iterator(type, reverse);
  33771. }
  33772. var collection = this._collection;
  33773. var iterator = getIterator(collection);
  33774. if (!isIterator(iterator)) {
  33775. return new Iterator(iteratorDone);
  33776. }
  33777. var iterations = 0;
  33778. return new Iterator(function () {
  33779. var step = iterator.next();
  33780. return step.done ? step : iteratorValue(type, iterations++, step.value);
  33781. });
  33782. };
  33783. return CollectionSeq;
  33784. }(IndexedSeq));
  33785. // # pragma Helper functions
  33786. var EMPTY_SEQ;
  33787. function emptySequence() {
  33788. return EMPTY_SEQ || (EMPTY_SEQ = new ArraySeq([]));
  33789. }
  33790. function keyedSeqFromValue(value) {
  33791. var seq = Array.isArray(value)
  33792. ? new ArraySeq(value)
  33793. : hasIterator(value)
  33794. ? new CollectionSeq(value)
  33795. : undefined;
  33796. if (seq) {
  33797. return seq.fromEntrySeq();
  33798. }
  33799. if (typeof value === 'object') {
  33800. return new ObjectSeq(value);
  33801. }
  33802. throw new TypeError(
  33803. 'Expected Array or collection object of [k, v] entries, or keyed object: ' +
  33804. value
  33805. );
  33806. }
  33807. function indexedSeqFromValue(value) {
  33808. var seq = maybeIndexedSeqFromValue(value);
  33809. if (seq) {
  33810. return seq;
  33811. }
  33812. throw new TypeError(
  33813. 'Expected Array or collection object of values: ' + value
  33814. );
  33815. }
  33816. function seqFromValue(value) {
  33817. var seq = maybeIndexedSeqFromValue(value);
  33818. if (seq) {
  33819. return seq;
  33820. }
  33821. if (typeof value === 'object') {
  33822. return new ObjectSeq(value);
  33823. }
  33824. throw new TypeError(
  33825. 'Expected Array or collection object of values, or keyed object: ' + value
  33826. );
  33827. }
  33828. function maybeIndexedSeqFromValue(value) {
  33829. return isArrayLike(value)
  33830. ? new ArraySeq(value)
  33831. : hasIterator(value)
  33832. ? new CollectionSeq(value)
  33833. : undefined;
  33834. }
  33835. var IS_MAP_SYMBOL = '@@__IMMUTABLE_MAP__@@';
  33836. function isMap(maybeMap) {
  33837. return Boolean(maybeMap && maybeMap[IS_MAP_SYMBOL]);
  33838. }
  33839. function isOrderedMap(maybeOrderedMap) {
  33840. return isMap(maybeOrderedMap) && isOrdered(maybeOrderedMap);
  33841. }
  33842. function isValueObject(maybeValue) {
  33843. return Boolean(
  33844. maybeValue &&
  33845. typeof maybeValue.equals === 'function' &&
  33846. typeof maybeValue.hashCode === 'function'
  33847. );
  33848. }
  33849. /**
  33850. * An extension of the "same-value" algorithm as [described for use by ES6 Map
  33851. * and Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map#Key_equality)
  33852. *
  33853. * NaN is considered the same as NaN, however -0 and 0 are considered the same
  33854. * value, which is different from the algorithm described by
  33855. * [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is).
  33856. *
  33857. * This is extended further to allow Objects to describe the values they
  33858. * represent, by way of `valueOf` or `equals` (and `hashCode`).
  33859. *
  33860. * Note: because of this extension, the key equality of Immutable.Map and the
  33861. * value equality of Immutable.Set will differ from ES6 Map and Set.
  33862. *
  33863. * ### Defining custom values
  33864. *
  33865. * The easiest way to describe the value an object represents is by implementing
  33866. * `valueOf`. For example, `Date` represents a value by returning a unix
  33867. * timestamp for `valueOf`:
  33868. *
  33869. * var date1 = new Date(1234567890000); // Fri Feb 13 2009 ...
  33870. * var date2 = new Date(1234567890000);
  33871. * date1.valueOf(); // 1234567890000
  33872. * assert( date1 !== date2 );
  33873. * assert( Immutable.is( date1, date2 ) );
  33874. *
  33875. * Note: overriding `valueOf` may have other implications if you use this object
  33876. * where JavaScript expects a primitive, such as implicit string coercion.
  33877. *
  33878. * For more complex types, especially collections, implementing `valueOf` may
  33879. * not be performant. An alternative is to implement `equals` and `hashCode`.
  33880. *
  33881. * `equals` takes another object, presumably of similar type, and returns true
  33882. * if it is equal. Equality is symmetrical, so the same result should be
  33883. * returned if this and the argument are flipped.
  33884. *
  33885. * assert( a.equals(b) === b.equals(a) );
  33886. *
  33887. * `hashCode` returns a 32bit integer number representing the object which will
  33888. * be used to determine how to store the value object in a Map or Set. You must
  33889. * provide both or neither methods, one must not exist without the other.
  33890. *
  33891. * Also, an important relationship between these methods must be upheld: if two
  33892. * values are equal, they *must* return the same hashCode. If the values are not
  33893. * equal, they might have the same hashCode; this is called a hash collision,
  33894. * and while undesirable for performance reasons, it is acceptable.
  33895. *
  33896. * if (a.equals(b)) {
  33897. * assert( a.hashCode() === b.hashCode() );
  33898. * }
  33899. *
  33900. * All Immutable collections are Value Objects: they implement `equals()`
  33901. * and `hashCode()`.
  33902. */
  33903. function is(valueA, valueB) {
  33904. if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
  33905. return true;
  33906. }
  33907. if (!valueA || !valueB) {
  33908. return false;
  33909. }
  33910. if (
  33911. typeof valueA.valueOf === 'function' &&
  33912. typeof valueB.valueOf === 'function'
  33913. ) {
  33914. valueA = valueA.valueOf();
  33915. valueB = valueB.valueOf();
  33916. if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
  33917. return true;
  33918. }
  33919. if (!valueA || !valueB) {
  33920. return false;
  33921. }
  33922. }
  33923. return !!(
  33924. isValueObject(valueA) &&
  33925. isValueObject(valueB) &&
  33926. valueA.equals(valueB)
  33927. );
  33928. }
  33929. var imul =
  33930. typeof Math.imul === 'function' && Math.imul(0xffffffff, 2) === -2
  33931. ? Math.imul
  33932. : function imul(a, b) {
  33933. a |= 0; // int
  33934. b |= 0; // int
  33935. var c = a & 0xffff;
  33936. var d = b & 0xffff;
  33937. // Shift by 0 fixes the sign on the high part.
  33938. return (c * d + ((((a >>> 16) * d + c * (b >>> 16)) << 16) >>> 0)) | 0; // int
  33939. };
  33940. // v8 has an optimization for storing 31-bit signed numbers.
  33941. // Values which have either 00 or 11 as the high order bits qualify.
  33942. // This function drops the highest order bit in a signed number, maintaining
  33943. // the sign bit.
  33944. function smi(i32) {
  33945. return ((i32 >>> 1) & 0x40000000) | (i32 & 0xbfffffff);
  33946. }
  33947. var defaultValueOf = Object.prototype.valueOf;
  33948. function hash(o) {
  33949. switch (typeof o) {
  33950. case 'boolean':
  33951. // The hash values for built-in constants are a 1 value for each 5-byte
  33952. // shift region expect for the first, which encodes the value. This
  33953. // reduces the odds of a hash collision for these common values.
  33954. return o ? 0x42108421 : 0x42108420;
  33955. case 'number':
  33956. return hashNumber(o);
  33957. case 'string':
  33958. return o.length > STRING_HASH_CACHE_MIN_STRLEN
  33959. ? cachedHashString(o)
  33960. : hashString(o);
  33961. case 'object':
  33962. case 'function':
  33963. if (o === null) {
  33964. return 0x42108422;
  33965. }
  33966. if (typeof o.hashCode === 'function') {
  33967. // Drop any high bits from accidentally long hash codes.
  33968. return smi(o.hashCode(o));
  33969. }
  33970. if (o.valueOf !== defaultValueOf && typeof o.valueOf === 'function') {
  33971. o = o.valueOf(o);
  33972. }
  33973. return hashJSObj(o);
  33974. case 'undefined':
  33975. return 0x42108423;
  33976. default:
  33977. if (typeof o.toString === 'function') {
  33978. return hashString(o.toString());
  33979. }
  33980. throw new Error('Value type ' + typeof o + ' cannot be hashed.');
  33981. }
  33982. }
  33983. // Compress arbitrarily large numbers into smi hashes.
  33984. function hashNumber(n) {
  33985. if (n !== n || n === Infinity) {
  33986. return 0;
  33987. }
  33988. var hash = n | 0;
  33989. if (hash !== n) {
  33990. hash ^= n * 0xffffffff;
  33991. }
  33992. while (n > 0xffffffff) {
  33993. n /= 0xffffffff;
  33994. hash ^= n;
  33995. }
  33996. return smi(hash);
  33997. }
  33998. function cachedHashString(string) {
  33999. var hashed = stringHashCache[string];
  34000. if (hashed === undefined) {
  34001. hashed = hashString(string);
  34002. if (STRING_HASH_CACHE_SIZE === STRING_HASH_CACHE_MAX_SIZE) {
  34003. STRING_HASH_CACHE_SIZE = 0;
  34004. stringHashCache = {};
  34005. }
  34006. STRING_HASH_CACHE_SIZE++;
  34007. stringHashCache[string] = hashed;
  34008. }
  34009. return hashed;
  34010. }
  34011. // http://jsperf.com/hashing-strings
  34012. function hashString(string) {
  34013. // This is the hash from JVM
  34014. // The hash code for a string is computed as
  34015. // s[0] * 31 ^ (n - 1) + s[1] * 31 ^ (n - 2) + ... + s[n - 1],
  34016. // where s[i] is the ith character of the string and n is the length of
  34017. // the string. We "mod" the result to make it between 0 (inclusive) and 2^31
  34018. // (exclusive) by dropping high bits.
  34019. var hashed = 0;
  34020. for (var ii = 0; ii < string.length; ii++) {
  34021. hashed = (31 * hashed + string.charCodeAt(ii)) | 0;
  34022. }
  34023. return smi(hashed);
  34024. }
  34025. function hashJSObj(obj) {
  34026. var hashed;
  34027. if (usingWeakMap) {
  34028. hashed = weakMap.get(obj);
  34029. if (hashed !== undefined) {
  34030. return hashed;
  34031. }
  34032. }
  34033. hashed = obj[UID_HASH_KEY];
  34034. if (hashed !== undefined) {
  34035. return hashed;
  34036. }
  34037. if (!canDefineProperty) {
  34038. hashed = obj.propertyIsEnumerable && obj.propertyIsEnumerable[UID_HASH_KEY];
  34039. if (hashed !== undefined) {
  34040. return hashed;
  34041. }
  34042. hashed = getIENodeHash(obj);
  34043. if (hashed !== undefined) {
  34044. return hashed;
  34045. }
  34046. }
  34047. hashed = ++objHashUID;
  34048. if (objHashUID & 0x40000000) {
  34049. objHashUID = 0;
  34050. }
  34051. if (usingWeakMap) {
  34052. weakMap.set(obj, hashed);
  34053. } else if (isExtensible !== undefined && isExtensible(obj) === false) {
  34054. throw new Error('Non-extensible objects are not allowed as keys.');
  34055. } else if (canDefineProperty) {
  34056. Object.defineProperty(obj, UID_HASH_KEY, {
  34057. enumerable: false,
  34058. configurable: false,
  34059. writable: false,
  34060. value: hashed,
  34061. });
  34062. } else if (
  34063. obj.propertyIsEnumerable !== undefined &&
  34064. obj.propertyIsEnumerable === obj.constructor.prototype.propertyIsEnumerable
  34065. ) {
  34066. // Since we can't define a non-enumerable property on the object
  34067. // we'll hijack one of the less-used non-enumerable properties to
  34068. // save our hash on it. Since this is a function it will not show up in
  34069. // `JSON.stringify` which is what we want.
  34070. obj.propertyIsEnumerable = function() {
  34071. return this.constructor.prototype.propertyIsEnumerable.apply(
  34072. this,
  34073. arguments
  34074. );
  34075. };
  34076. obj.propertyIsEnumerable[UID_HASH_KEY] = hashed;
  34077. } else if (obj.nodeType !== undefined) {
  34078. // At this point we couldn't get the IE `uniqueID` to use as a hash
  34079. // and we couldn't use a non-enumerable property to exploit the
  34080. // dontEnum bug so we simply add the `UID_HASH_KEY` on the node
  34081. // itself.
  34082. obj[UID_HASH_KEY] = hashed;
  34083. } else {
  34084. throw new Error('Unable to set a non-enumerable property on object.');
  34085. }
  34086. return hashed;
  34087. }
  34088. // Get references to ES5 object methods.
  34089. var isExtensible = Object.isExtensible;
  34090. // True if Object.defineProperty works as expected. IE8 fails this test.
  34091. var canDefineProperty = (function() {
  34092. try {
  34093. Object.defineProperty({}, '@', {});
  34094. return true;
  34095. } catch (e) {
  34096. return false;
  34097. }
  34098. })();
  34099. // IE has a `uniqueID` property on DOM nodes. We can construct the hash from it
  34100. // and avoid memory leaks from the IE cloneNode bug.
  34101. function getIENodeHash(node) {
  34102. if (node && node.nodeType > 0) {
  34103. switch (node.nodeType) {
  34104. case 1: // Element
  34105. return node.uniqueID;
  34106. case 9: // Document
  34107. return node.documentElement && node.documentElement.uniqueID;
  34108. }
  34109. }
  34110. }
  34111. // If possible, use a WeakMap.
  34112. var usingWeakMap = typeof WeakMap === 'function';
  34113. var weakMap;
  34114. if (usingWeakMap) {
  34115. weakMap = new WeakMap();
  34116. }
  34117. var objHashUID = 0;
  34118. var UID_HASH_KEY = '__immutablehash__';
  34119. if (typeof Symbol === 'function') {
  34120. UID_HASH_KEY = Symbol(UID_HASH_KEY);
  34121. }
  34122. var STRING_HASH_CACHE_MIN_STRLEN = 16;
  34123. var STRING_HASH_CACHE_MAX_SIZE = 255;
  34124. var STRING_HASH_CACHE_SIZE = 0;
  34125. var stringHashCache = {};
  34126. var ToKeyedSequence = /*@__PURE__*/(function (KeyedSeq$$1) {
  34127. function ToKeyedSequence(indexed, useKeys) {
  34128. this._iter = indexed;
  34129. this._useKeys = useKeys;
  34130. this.size = indexed.size;
  34131. }
  34132. if ( KeyedSeq$$1 ) ToKeyedSequence.__proto__ = KeyedSeq$$1;
  34133. ToKeyedSequence.prototype = Object.create( KeyedSeq$$1 && KeyedSeq$$1.prototype );
  34134. ToKeyedSequence.prototype.constructor = ToKeyedSequence;
  34135. ToKeyedSequence.prototype.get = function get (key, notSetValue) {
  34136. return this._iter.get(key, notSetValue);
  34137. };
  34138. ToKeyedSequence.prototype.has = function has (key) {
  34139. return this._iter.has(key);
  34140. };
  34141. ToKeyedSequence.prototype.valueSeq = function valueSeq () {
  34142. return this._iter.valueSeq();
  34143. };
  34144. ToKeyedSequence.prototype.reverse = function reverse () {
  34145. var this$1 = this;
  34146. var reversedSequence = reverseFactory(this, true);
  34147. if (!this._useKeys) {
  34148. reversedSequence.valueSeq = function () { return this$1._iter.toSeq().reverse(); };
  34149. }
  34150. return reversedSequence;
  34151. };
  34152. ToKeyedSequence.prototype.map = function map (mapper, context) {
  34153. var this$1 = this;
  34154. var mappedSequence = mapFactory(this, mapper, context);
  34155. if (!this._useKeys) {
  34156. mappedSequence.valueSeq = function () { return this$1._iter.toSeq().map(mapper, context); };
  34157. }
  34158. return mappedSequence;
  34159. };
  34160. ToKeyedSequence.prototype.__iterate = function __iterate (fn, reverse) {
  34161. var this$1 = this;
  34162. return this._iter.__iterate(function (v, k) { return fn(v, k, this$1); }, reverse);
  34163. };
  34164. ToKeyedSequence.prototype.__iterator = function __iterator (type, reverse) {
  34165. return this._iter.__iterator(type, reverse);
  34166. };
  34167. return ToKeyedSequence;
  34168. }(KeyedSeq));
  34169. ToKeyedSequence.prototype[IS_ORDERED_SYMBOL] = true;
  34170. var ToIndexedSequence = /*@__PURE__*/(function (IndexedSeq$$1) {
  34171. function ToIndexedSequence(iter) {
  34172. this._iter = iter;
  34173. this.size = iter.size;
  34174. }
  34175. if ( IndexedSeq$$1 ) ToIndexedSequence.__proto__ = IndexedSeq$$1;
  34176. ToIndexedSequence.prototype = Object.create( IndexedSeq$$1 && IndexedSeq$$1.prototype );
  34177. ToIndexedSequence.prototype.constructor = ToIndexedSequence;
  34178. ToIndexedSequence.prototype.includes = function includes (value) {
  34179. return this._iter.includes(value);
  34180. };
  34181. ToIndexedSequence.prototype.__iterate = function __iterate (fn, reverse) {
  34182. var this$1 = this;
  34183. var i = 0;
  34184. reverse && ensureSize(this);
  34185. return this._iter.__iterate(
  34186. function (v) { return fn(v, reverse ? this$1.size - ++i : i++, this$1); },
  34187. reverse
  34188. );
  34189. };
  34190. ToIndexedSequence.prototype.__iterator = function __iterator (type, reverse) {
  34191. var this$1 = this;
  34192. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  34193. var i = 0;
  34194. reverse && ensureSize(this);
  34195. return new Iterator(function () {
  34196. var step = iterator.next();
  34197. return step.done
  34198. ? step
  34199. : iteratorValue(
  34200. type,
  34201. reverse ? this$1.size - ++i : i++,
  34202. step.value,
  34203. step
  34204. );
  34205. });
  34206. };
  34207. return ToIndexedSequence;
  34208. }(IndexedSeq));
  34209. var ToSetSequence = /*@__PURE__*/(function (SetSeq$$1) {
  34210. function ToSetSequence(iter) {
  34211. this._iter = iter;
  34212. this.size = iter.size;
  34213. }
  34214. if ( SetSeq$$1 ) ToSetSequence.__proto__ = SetSeq$$1;
  34215. ToSetSequence.prototype = Object.create( SetSeq$$1 && SetSeq$$1.prototype );
  34216. ToSetSequence.prototype.constructor = ToSetSequence;
  34217. ToSetSequence.prototype.has = function has (key) {
  34218. return this._iter.includes(key);
  34219. };
  34220. ToSetSequence.prototype.__iterate = function __iterate (fn, reverse) {
  34221. var this$1 = this;
  34222. return this._iter.__iterate(function (v) { return fn(v, v, this$1); }, reverse);
  34223. };
  34224. ToSetSequence.prototype.__iterator = function __iterator (type, reverse) {
  34225. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  34226. return new Iterator(function () {
  34227. var step = iterator.next();
  34228. return step.done
  34229. ? step
  34230. : iteratorValue(type, step.value, step.value, step);
  34231. });
  34232. };
  34233. return ToSetSequence;
  34234. }(SetSeq));
  34235. var FromEntriesSequence = /*@__PURE__*/(function (KeyedSeq$$1) {
  34236. function FromEntriesSequence(entries) {
  34237. this._iter = entries;
  34238. this.size = entries.size;
  34239. }
  34240. if ( KeyedSeq$$1 ) FromEntriesSequence.__proto__ = KeyedSeq$$1;
  34241. FromEntriesSequence.prototype = Object.create( KeyedSeq$$1 && KeyedSeq$$1.prototype );
  34242. FromEntriesSequence.prototype.constructor = FromEntriesSequence;
  34243. FromEntriesSequence.prototype.entrySeq = function entrySeq () {
  34244. return this._iter.toSeq();
  34245. };
  34246. FromEntriesSequence.prototype.__iterate = function __iterate (fn, reverse) {
  34247. var this$1 = this;
  34248. return this._iter.__iterate(function (entry) {
  34249. // Check if entry exists first so array access doesn't throw for holes
  34250. // in the parent iteration.
  34251. if (entry) {
  34252. validateEntry(entry);
  34253. var indexedCollection = isCollection(entry);
  34254. return fn(
  34255. indexedCollection ? entry.get(1) : entry[1],
  34256. indexedCollection ? entry.get(0) : entry[0],
  34257. this$1
  34258. );
  34259. }
  34260. }, reverse);
  34261. };
  34262. FromEntriesSequence.prototype.__iterator = function __iterator (type, reverse) {
  34263. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  34264. return new Iterator(function () {
  34265. while (true) {
  34266. var step = iterator.next();
  34267. if (step.done) {
  34268. return step;
  34269. }
  34270. var entry = step.value;
  34271. // Check if entry exists first so array access doesn't throw for holes
  34272. // in the parent iteration.
  34273. if (entry) {
  34274. validateEntry(entry);
  34275. var indexedCollection = isCollection(entry);
  34276. return iteratorValue(
  34277. type,
  34278. indexedCollection ? entry.get(0) : entry[0],
  34279. indexedCollection ? entry.get(1) : entry[1],
  34280. step
  34281. );
  34282. }
  34283. }
  34284. });
  34285. };
  34286. return FromEntriesSequence;
  34287. }(KeyedSeq));
  34288. ToIndexedSequence.prototype.cacheResult = ToKeyedSequence.prototype.cacheResult = ToSetSequence.prototype.cacheResult = FromEntriesSequence.prototype.cacheResult = cacheResultThrough;
  34289. function flipFactory(collection) {
  34290. var flipSequence = makeSequence(collection);
  34291. flipSequence._iter = collection;
  34292. flipSequence.size = collection.size;
  34293. flipSequence.flip = function () { return collection; };
  34294. flipSequence.reverse = function() {
  34295. var reversedSequence = collection.reverse.apply(this); // super.reverse()
  34296. reversedSequence.flip = function () { return collection.reverse(); };
  34297. return reversedSequence;
  34298. };
  34299. flipSequence.has = function (key) { return collection.includes(key); };
  34300. flipSequence.includes = function (key) { return collection.has(key); };
  34301. flipSequence.cacheResult = cacheResultThrough;
  34302. flipSequence.__iterateUncached = function(fn, reverse) {
  34303. var this$1 = this;
  34304. return collection.__iterate(function (v, k) { return fn(k, v, this$1) !== false; }, reverse);
  34305. };
  34306. flipSequence.__iteratorUncached = function(type, reverse) {
  34307. if (type === ITERATE_ENTRIES) {
  34308. var iterator = collection.__iterator(type, reverse);
  34309. return new Iterator(function () {
  34310. var step = iterator.next();
  34311. if (!step.done) {
  34312. var k = step.value[0];
  34313. step.value[0] = step.value[1];
  34314. step.value[1] = k;
  34315. }
  34316. return step;
  34317. });
  34318. }
  34319. return collection.__iterator(
  34320. type === ITERATE_VALUES ? ITERATE_KEYS : ITERATE_VALUES,
  34321. reverse
  34322. );
  34323. };
  34324. return flipSequence;
  34325. }
  34326. function mapFactory(collection, mapper, context) {
  34327. var mappedSequence = makeSequence(collection);
  34328. mappedSequence.size = collection.size;
  34329. mappedSequence.has = function (key) { return collection.has(key); };
  34330. mappedSequence.get = function (key, notSetValue) {
  34331. var v = collection.get(key, NOT_SET);
  34332. return v === NOT_SET
  34333. ? notSetValue
  34334. : mapper.call(context, v, key, collection);
  34335. };
  34336. mappedSequence.__iterateUncached = function(fn, reverse) {
  34337. var this$1 = this;
  34338. return collection.__iterate(
  34339. function (v, k, c) { return fn(mapper.call(context, v, k, c), k, this$1) !== false; },
  34340. reverse
  34341. );
  34342. };
  34343. mappedSequence.__iteratorUncached = function(type, reverse) {
  34344. var iterator = collection.__iterator(ITERATE_ENTRIES, reverse);
  34345. return new Iterator(function () {
  34346. var step = iterator.next();
  34347. if (step.done) {
  34348. return step;
  34349. }
  34350. var entry = step.value;
  34351. var key = entry[0];
  34352. return iteratorValue(
  34353. type,
  34354. key,
  34355. mapper.call(context, entry[1], key, collection),
  34356. step
  34357. );
  34358. });
  34359. };
  34360. return mappedSequence;
  34361. }
  34362. function reverseFactory(collection, useKeys) {
  34363. var this$1 = this;
  34364. var reversedSequence = makeSequence(collection);
  34365. reversedSequence._iter = collection;
  34366. reversedSequence.size = collection.size;
  34367. reversedSequence.reverse = function () { return collection; };
  34368. if (collection.flip) {
  34369. reversedSequence.flip = function() {
  34370. var flipSequence = flipFactory(collection);
  34371. flipSequence.reverse = function () { return collection.flip(); };
  34372. return flipSequence;
  34373. };
  34374. }
  34375. reversedSequence.get = function (key, notSetValue) { return collection.get(useKeys ? key : -1 - key, notSetValue); };
  34376. reversedSequence.has = function (key) { return collection.has(useKeys ? key : -1 - key); };
  34377. reversedSequence.includes = function (value) { return collection.includes(value); };
  34378. reversedSequence.cacheResult = cacheResultThrough;
  34379. reversedSequence.__iterate = function(fn, reverse) {
  34380. var this$1 = this;
  34381. var i = 0;
  34382. reverse && ensureSize(collection);
  34383. return collection.__iterate(
  34384. function (v, k) { return fn(v, useKeys ? k : reverse ? this$1.size - ++i : i++, this$1); },
  34385. !reverse
  34386. );
  34387. };
  34388. reversedSequence.__iterator = function (type, reverse) {
  34389. var i = 0;
  34390. reverse && ensureSize(collection);
  34391. var iterator = collection.__iterator(ITERATE_ENTRIES, !reverse);
  34392. return new Iterator(function () {
  34393. var step = iterator.next();
  34394. if (step.done) {
  34395. return step;
  34396. }
  34397. var entry = step.value;
  34398. return iteratorValue(
  34399. type,
  34400. useKeys ? entry[0] : reverse ? this$1.size - ++i : i++,
  34401. entry[1],
  34402. step
  34403. );
  34404. });
  34405. };
  34406. return reversedSequence;
  34407. }
  34408. function filterFactory(collection, predicate, context, useKeys) {
  34409. var filterSequence = makeSequence(collection);
  34410. if (useKeys) {
  34411. filterSequence.has = function (key) {
  34412. var v = collection.get(key, NOT_SET);
  34413. return v !== NOT_SET && !!predicate.call(context, v, key, collection);
  34414. };
  34415. filterSequence.get = function (key, notSetValue) {
  34416. var v = collection.get(key, NOT_SET);
  34417. return v !== NOT_SET && predicate.call(context, v, key, collection)
  34418. ? v
  34419. : notSetValue;
  34420. };
  34421. }
  34422. filterSequence.__iterateUncached = function(fn, reverse) {
  34423. var this$1 = this;
  34424. var iterations = 0;
  34425. collection.__iterate(function (v, k, c) {
  34426. if (predicate.call(context, v, k, c)) {
  34427. iterations++;
  34428. return fn(v, useKeys ? k : iterations - 1, this$1);
  34429. }
  34430. }, reverse);
  34431. return iterations;
  34432. };
  34433. filterSequence.__iteratorUncached = function(type, reverse) {
  34434. var iterator = collection.__iterator(ITERATE_ENTRIES, reverse);
  34435. var iterations = 0;
  34436. return new Iterator(function () {
  34437. while (true) {
  34438. var step = iterator.next();
  34439. if (step.done) {
  34440. return step;
  34441. }
  34442. var entry = step.value;
  34443. var key = entry[0];
  34444. var value = entry[1];
  34445. if (predicate.call(context, value, key, collection)) {
  34446. return iteratorValue(type, useKeys ? key : iterations++, value, step);
  34447. }
  34448. }
  34449. });
  34450. };
  34451. return filterSequence;
  34452. }
  34453. function countByFactory(collection, grouper, context) {
  34454. var groups = Map().asMutable();
  34455. collection.__iterate(function (v, k) {
  34456. groups.update(grouper.call(context, v, k, collection), 0, function (a) { return a + 1; });
  34457. });
  34458. return groups.asImmutable();
  34459. }
  34460. function groupByFactory(collection, grouper, context) {
  34461. var isKeyedIter = isKeyed(collection);
  34462. var groups = (isOrdered(collection) ? OrderedMap() : Map()).asMutable();
  34463. collection.__iterate(function (v, k) {
  34464. groups.update(
  34465. grouper.call(context, v, k, collection),
  34466. function (a) { return ((a = a || []), a.push(isKeyedIter ? [k, v] : v), a); }
  34467. );
  34468. });
  34469. var coerce = collectionClass(collection);
  34470. return groups.map(function (arr) { return reify(collection, coerce(arr)); }).asImmutable();
  34471. }
  34472. function sliceFactory(collection, begin, end, useKeys) {
  34473. var originalSize = collection.size;
  34474. if (wholeSlice(begin, end, originalSize)) {
  34475. return collection;
  34476. }
  34477. var resolvedBegin = resolveBegin(begin, originalSize);
  34478. var resolvedEnd = resolveEnd(end, originalSize);
  34479. // begin or end will be NaN if they were provided as negative numbers and
  34480. // this collection's size is unknown. In that case, cache first so there is
  34481. // a known size and these do not resolve to NaN.
  34482. if (resolvedBegin !== resolvedBegin || resolvedEnd !== resolvedEnd) {
  34483. return sliceFactory(collection.toSeq().cacheResult(), begin, end, useKeys);
  34484. }
  34485. // Note: resolvedEnd is undefined when the original sequence's length is
  34486. // unknown and this slice did not supply an end and should contain all
  34487. // elements after resolvedBegin.
  34488. // In that case, resolvedSize will be NaN and sliceSize will remain undefined.
  34489. var resolvedSize = resolvedEnd - resolvedBegin;
  34490. var sliceSize;
  34491. if (resolvedSize === resolvedSize) {
  34492. sliceSize = resolvedSize < 0 ? 0 : resolvedSize;
  34493. }
  34494. var sliceSeq = makeSequence(collection);
  34495. // If collection.size is undefined, the size of the realized sliceSeq is
  34496. // unknown at this point unless the number of items to slice is 0
  34497. sliceSeq.size =
  34498. sliceSize === 0 ? sliceSize : (collection.size && sliceSize) || undefined;
  34499. if (!useKeys && isSeq(collection) && sliceSize >= 0) {
  34500. sliceSeq.get = function(index, notSetValue) {
  34501. index = wrapIndex(this, index);
  34502. return index >= 0 && index < sliceSize
  34503. ? collection.get(index + resolvedBegin, notSetValue)
  34504. : notSetValue;
  34505. };
  34506. }
  34507. sliceSeq.__iterateUncached = function(fn, reverse) {
  34508. var this$1 = this;
  34509. if (sliceSize === 0) {
  34510. return 0;
  34511. }
  34512. if (reverse) {
  34513. return this.cacheResult().__iterate(fn, reverse);
  34514. }
  34515. var skipped = 0;
  34516. var isSkipping = true;
  34517. var iterations = 0;
  34518. collection.__iterate(function (v, k) {
  34519. if (!(isSkipping && (isSkipping = skipped++ < resolvedBegin))) {
  34520. iterations++;
  34521. return (
  34522. fn(v, useKeys ? k : iterations - 1, this$1) !== false &&
  34523. iterations !== sliceSize
  34524. );
  34525. }
  34526. });
  34527. return iterations;
  34528. };
  34529. sliceSeq.__iteratorUncached = function(type, reverse) {
  34530. if (sliceSize !== 0 && reverse) {
  34531. return this.cacheResult().__iterator(type, reverse);
  34532. }
  34533. // Don't bother instantiating parent iterator if taking 0.
  34534. if (sliceSize === 0) {
  34535. return new Iterator(iteratorDone);
  34536. }
  34537. var iterator = collection.__iterator(type, reverse);
  34538. var skipped = 0;
  34539. var iterations = 0;
  34540. return new Iterator(function () {
  34541. while (skipped++ < resolvedBegin) {
  34542. iterator.next();
  34543. }
  34544. if (++iterations > sliceSize) {
  34545. return iteratorDone();
  34546. }
  34547. var step = iterator.next();
  34548. if (useKeys || type === ITERATE_VALUES || step.done) {
  34549. return step;
  34550. }
  34551. if (type === ITERATE_KEYS) {
  34552. return iteratorValue(type, iterations - 1, undefined, step);
  34553. }
  34554. return iteratorValue(type, iterations - 1, step.value[1], step);
  34555. });
  34556. };
  34557. return sliceSeq;
  34558. }
  34559. function takeWhileFactory(collection, predicate, context) {
  34560. var takeSequence = makeSequence(collection);
  34561. takeSequence.__iterateUncached = function(fn, reverse) {
  34562. var this$1 = this;
  34563. if (reverse) {
  34564. return this.cacheResult().__iterate(fn, reverse);
  34565. }
  34566. var iterations = 0;
  34567. collection.__iterate(
  34568. function (v, k, c) { return predicate.call(context, v, k, c) && ++iterations && fn(v, k, this$1); }
  34569. );
  34570. return iterations;
  34571. };
  34572. takeSequence.__iteratorUncached = function(type, reverse) {
  34573. var this$1 = this;
  34574. if (reverse) {
  34575. return this.cacheResult().__iterator(type, reverse);
  34576. }
  34577. var iterator = collection.__iterator(ITERATE_ENTRIES, reverse);
  34578. var iterating = true;
  34579. return new Iterator(function () {
  34580. if (!iterating) {
  34581. return iteratorDone();
  34582. }
  34583. var step = iterator.next();
  34584. if (step.done) {
  34585. return step;
  34586. }
  34587. var entry = step.value;
  34588. var k = entry[0];
  34589. var v = entry[1];
  34590. if (!predicate.call(context, v, k, this$1)) {
  34591. iterating = false;
  34592. return iteratorDone();
  34593. }
  34594. return type === ITERATE_ENTRIES ? step : iteratorValue(type, k, v, step);
  34595. });
  34596. };
  34597. return takeSequence;
  34598. }
  34599. function skipWhileFactory(collection, predicate, context, useKeys) {
  34600. var skipSequence = makeSequence(collection);
  34601. skipSequence.__iterateUncached = function(fn, reverse) {
  34602. var this$1 = this;
  34603. if (reverse) {
  34604. return this.cacheResult().__iterate(fn, reverse);
  34605. }
  34606. var isSkipping = true;
  34607. var iterations = 0;
  34608. collection.__iterate(function (v, k, c) {
  34609. if (!(isSkipping && (isSkipping = predicate.call(context, v, k, c)))) {
  34610. iterations++;
  34611. return fn(v, useKeys ? k : iterations - 1, this$1);
  34612. }
  34613. });
  34614. return iterations;
  34615. };
  34616. skipSequence.__iteratorUncached = function(type, reverse) {
  34617. var this$1 = this;
  34618. if (reverse) {
  34619. return this.cacheResult().__iterator(type, reverse);
  34620. }
  34621. var iterator = collection.__iterator(ITERATE_ENTRIES, reverse);
  34622. var skipping = true;
  34623. var iterations = 0;
  34624. return new Iterator(function () {
  34625. var step;
  34626. var k;
  34627. var v;
  34628. do {
  34629. step = iterator.next();
  34630. if (step.done) {
  34631. if (useKeys || type === ITERATE_VALUES) {
  34632. return step;
  34633. }
  34634. if (type === ITERATE_KEYS) {
  34635. return iteratorValue(type, iterations++, undefined, step);
  34636. }
  34637. return iteratorValue(type, iterations++, step.value[1], step);
  34638. }
  34639. var entry = step.value;
  34640. k = entry[0];
  34641. v = entry[1];
  34642. skipping && (skipping = predicate.call(context, v, k, this$1));
  34643. } while (skipping);
  34644. return type === ITERATE_ENTRIES ? step : iteratorValue(type, k, v, step);
  34645. });
  34646. };
  34647. return skipSequence;
  34648. }
  34649. function concatFactory(collection, values) {
  34650. var isKeyedCollection = isKeyed(collection);
  34651. var iters = [collection]
  34652. .concat(values)
  34653. .map(function (v) {
  34654. if (!isCollection(v)) {
  34655. v = isKeyedCollection
  34656. ? keyedSeqFromValue(v)
  34657. : indexedSeqFromValue(Array.isArray(v) ? v : [v]);
  34658. } else if (isKeyedCollection) {
  34659. v = KeyedCollection(v);
  34660. }
  34661. return v;
  34662. })
  34663. .filter(function (v) { return v.size !== 0; });
  34664. if (iters.length === 0) {
  34665. return collection;
  34666. }
  34667. if (iters.length === 1) {
  34668. var singleton = iters[0];
  34669. if (
  34670. singleton === collection ||
  34671. (isKeyedCollection && isKeyed(singleton)) ||
  34672. (isIndexed(collection) && isIndexed(singleton))
  34673. ) {
  34674. return singleton;
  34675. }
  34676. }
  34677. var concatSeq = new ArraySeq(iters);
  34678. if (isKeyedCollection) {
  34679. concatSeq = concatSeq.toKeyedSeq();
  34680. } else if (!isIndexed(collection)) {
  34681. concatSeq = concatSeq.toSetSeq();
  34682. }
  34683. concatSeq = concatSeq.flatten(true);
  34684. concatSeq.size = iters.reduce(function (sum, seq) {
  34685. if (sum !== undefined) {
  34686. var size = seq.size;
  34687. if (size !== undefined) {
  34688. return sum + size;
  34689. }
  34690. }
  34691. }, 0);
  34692. return concatSeq;
  34693. }
  34694. function flattenFactory(collection, depth, useKeys) {
  34695. var flatSequence = makeSequence(collection);
  34696. flatSequence.__iterateUncached = function(fn, reverse) {
  34697. if (reverse) {
  34698. return this.cacheResult().__iterate(fn, reverse);
  34699. }
  34700. var iterations = 0;
  34701. var stopped = false;
  34702. function flatDeep(iter, currentDepth) {
  34703. iter.__iterate(function (v, k) {
  34704. if ((!depth || currentDepth < depth) && isCollection(v)) {
  34705. flatDeep(v, currentDepth + 1);
  34706. } else {
  34707. iterations++;
  34708. if (fn(v, useKeys ? k : iterations - 1, flatSequence) === false) {
  34709. stopped = true;
  34710. }
  34711. }
  34712. return !stopped;
  34713. }, reverse);
  34714. }
  34715. flatDeep(collection, 0);
  34716. return iterations;
  34717. };
  34718. flatSequence.__iteratorUncached = function(type, reverse) {
  34719. if (reverse) {
  34720. return this.cacheResult().__iterator(type, reverse);
  34721. }
  34722. var iterator = collection.__iterator(type, reverse);
  34723. var stack = [];
  34724. var iterations = 0;
  34725. return new Iterator(function () {
  34726. while (iterator) {
  34727. var step = iterator.next();
  34728. if (step.done !== false) {
  34729. iterator = stack.pop();
  34730. continue;
  34731. }
  34732. var v = step.value;
  34733. if (type === ITERATE_ENTRIES) {
  34734. v = v[1];
  34735. }
  34736. if ((!depth || stack.length < depth) && isCollection(v)) {
  34737. stack.push(iterator);
  34738. iterator = v.__iterator(type, reverse);
  34739. } else {
  34740. return useKeys ? step : iteratorValue(type, iterations++, v, step);
  34741. }
  34742. }
  34743. return iteratorDone();
  34744. });
  34745. };
  34746. return flatSequence;
  34747. }
  34748. function flatMapFactory(collection, mapper, context) {
  34749. var coerce = collectionClass(collection);
  34750. return collection
  34751. .toSeq()
  34752. .map(function (v, k) { return coerce(mapper.call(context, v, k, collection)); })
  34753. .flatten(true);
  34754. }
  34755. function interposeFactory(collection, separator) {
  34756. var interposedSequence = makeSequence(collection);
  34757. interposedSequence.size = collection.size && collection.size * 2 - 1;
  34758. interposedSequence.__iterateUncached = function(fn, reverse) {
  34759. var this$1 = this;
  34760. var iterations = 0;
  34761. collection.__iterate(
  34762. function (v) { return (!iterations || fn(separator, iterations++, this$1) !== false) &&
  34763. fn(v, iterations++, this$1) !== false; },
  34764. reverse
  34765. );
  34766. return iterations;
  34767. };
  34768. interposedSequence.__iteratorUncached = function(type, reverse) {
  34769. var iterator = collection.__iterator(ITERATE_VALUES, reverse);
  34770. var iterations = 0;
  34771. var step;
  34772. return new Iterator(function () {
  34773. if (!step || iterations % 2) {
  34774. step = iterator.next();
  34775. if (step.done) {
  34776. return step;
  34777. }
  34778. }
  34779. return iterations % 2
  34780. ? iteratorValue(type, iterations++, separator)
  34781. : iteratorValue(type, iterations++, step.value, step);
  34782. });
  34783. };
  34784. return interposedSequence;
  34785. }
  34786. function sortFactory(collection, comparator, mapper) {
  34787. if (!comparator) {
  34788. comparator = defaultComparator;
  34789. }
  34790. var isKeyedCollection = isKeyed(collection);
  34791. var index = 0;
  34792. var entries = collection
  34793. .toSeq()
  34794. .map(function (v, k) { return [k, v, index++, mapper ? mapper(v, k, collection) : v]; })
  34795. .valueSeq()
  34796. .toArray();
  34797. entries.sort(function (a, b) { return comparator(a[3], b[3]) || a[2] - b[2]; }).forEach(
  34798. isKeyedCollection
  34799. ? function (v, i) {
  34800. entries[i].length = 2;
  34801. }
  34802. : function (v, i) {
  34803. entries[i] = v[1];
  34804. }
  34805. );
  34806. return isKeyedCollection
  34807. ? KeyedSeq(entries)
  34808. : isIndexed(collection)
  34809. ? IndexedSeq(entries)
  34810. : SetSeq(entries);
  34811. }
  34812. function maxFactory(collection, comparator, mapper) {
  34813. if (!comparator) {
  34814. comparator = defaultComparator;
  34815. }
  34816. if (mapper) {
  34817. var entry = collection
  34818. .toSeq()
  34819. .map(function (v, k) { return [v, mapper(v, k, collection)]; })
  34820. .reduce(function (a, b) { return (maxCompare(comparator, a[1], b[1]) ? b : a); });
  34821. return entry && entry[0];
  34822. }
  34823. return collection.reduce(function (a, b) { return (maxCompare(comparator, a, b) ? b : a); });
  34824. }
  34825. function maxCompare(comparator, a, b) {
  34826. var comp = comparator(b, a);
  34827. // b is considered the new max if the comparator declares them equal, but
  34828. // they are not equal and b is in fact a nullish value.
  34829. return (
  34830. (comp === 0 && b !== a && (b === undefined || b === null || b !== b)) ||
  34831. comp > 0
  34832. );
  34833. }
  34834. function zipWithFactory(keyIter, zipper, iters, zipAll) {
  34835. var zipSequence = makeSequence(keyIter);
  34836. var sizes = new ArraySeq(iters).map(function (i) { return i.size; });
  34837. zipSequence.size = zipAll ? sizes.max() : sizes.min();
  34838. // Note: this a generic base implementation of __iterate in terms of
  34839. // __iterator which may be more generically useful in the future.
  34840. zipSequence.__iterate = function(fn, reverse) {
  34841. /* generic:
  34842. var iterator = this.__iterator(ITERATE_ENTRIES, reverse);
  34843. var step;
  34844. var iterations = 0;
  34845. while (!(step = iterator.next()).done) {
  34846. iterations++;
  34847. if (fn(step.value[1], step.value[0], this) === false) {
  34848. break;
  34849. }
  34850. }
  34851. return iterations;
  34852. */
  34853. // indexed:
  34854. var iterator = this.__iterator(ITERATE_VALUES, reverse);
  34855. var step;
  34856. var iterations = 0;
  34857. while (!(step = iterator.next()).done) {
  34858. if (fn(step.value, iterations++, this) === false) {
  34859. break;
  34860. }
  34861. }
  34862. return iterations;
  34863. };
  34864. zipSequence.__iteratorUncached = function(type, reverse) {
  34865. var iterators = iters.map(
  34866. function (i) { return ((i = Collection(i)), getIterator(reverse ? i.reverse() : i)); }
  34867. );
  34868. var iterations = 0;
  34869. var isDone = false;
  34870. return new Iterator(function () {
  34871. var steps;
  34872. if (!isDone) {
  34873. steps = iterators.map(function (i) { return i.next(); });
  34874. isDone = zipAll ? steps.every(function (s) { return s.done; }) : steps.some(function (s) { return s.done; });
  34875. }
  34876. if (isDone) {
  34877. return iteratorDone();
  34878. }
  34879. return iteratorValue(
  34880. type,
  34881. iterations++,
  34882. zipper.apply(null, steps.map(function (s) { return s.value; }))
  34883. );
  34884. });
  34885. };
  34886. return zipSequence;
  34887. }
  34888. // #pragma Helper Functions
  34889. function reify(iter, seq) {
  34890. return iter === seq ? iter : isSeq(iter) ? seq : iter.constructor(seq);
  34891. }
  34892. function validateEntry(entry) {
  34893. if (entry !== Object(entry)) {
  34894. throw new TypeError('Expected [K, V] tuple: ' + entry);
  34895. }
  34896. }
  34897. function collectionClass(collection) {
  34898. return isKeyed(collection)
  34899. ? KeyedCollection
  34900. : isIndexed(collection)
  34901. ? IndexedCollection
  34902. : SetCollection;
  34903. }
  34904. function makeSequence(collection) {
  34905. return Object.create(
  34906. (isKeyed(collection)
  34907. ? KeyedSeq
  34908. : isIndexed(collection)
  34909. ? IndexedSeq
  34910. : SetSeq
  34911. ).prototype
  34912. );
  34913. }
  34914. function cacheResultThrough() {
  34915. if (this._iter.cacheResult) {
  34916. this._iter.cacheResult();
  34917. this.size = this._iter.size;
  34918. return this;
  34919. }
  34920. return Seq.prototype.cacheResult.call(this);
  34921. }
  34922. function defaultComparator(a, b) {
  34923. if (a === undefined && b === undefined) {
  34924. return 0;
  34925. }
  34926. if (a === undefined) {
  34927. return 1;
  34928. }
  34929. if (b === undefined) {
  34930. return -1;
  34931. }
  34932. return a > b ? 1 : a < b ? -1 : 0;
  34933. }
  34934. // http://jsperf.com/copy-array-inline
  34935. function arrCopy(arr, offset) {
  34936. offset = offset || 0;
  34937. var len = Math.max(0, arr.length - offset);
  34938. var newArr = new Array(len);
  34939. for (var ii = 0; ii < len; ii++) {
  34940. newArr[ii] = arr[ii + offset];
  34941. }
  34942. return newArr;
  34943. }
  34944. function invariant(condition, error) {
  34945. if (!condition) { throw new Error(error); }
  34946. }
  34947. function assertNotInfinite(size) {
  34948. invariant(
  34949. size !== Infinity,
  34950. 'Cannot perform this action with an infinite size.'
  34951. );
  34952. }
  34953. function coerceKeyPath(keyPath) {
  34954. if (isArrayLike(keyPath) && typeof keyPath !== 'string') {
  34955. return keyPath;
  34956. }
  34957. if (isOrdered(keyPath)) {
  34958. return keyPath.toArray();
  34959. }
  34960. throw new TypeError(
  34961. 'Invalid keyPath: expected Ordered Collection or Array: ' + keyPath
  34962. );
  34963. }
  34964. function isPlainObj(value) {
  34965. return (
  34966. value &&
  34967. (typeof value.constructor !== 'function' ||
  34968. value.constructor.name === 'Object')
  34969. );
  34970. }
  34971. /**
  34972. * Returns true if the value is a potentially-persistent data structure, either
  34973. * provided by Immutable.js or a plain Array or Object.
  34974. */
  34975. function isDataStructure(value) {
  34976. return (
  34977. typeof value === 'object' &&
  34978. (isImmutable(value) || Array.isArray(value) || isPlainObj(value))
  34979. );
  34980. }
  34981. /**
  34982. * Converts a value to a string, adding quotes if a string was provided.
  34983. */
  34984. function quoteString(value) {
  34985. try {
  34986. return typeof value === 'string' ? JSON.stringify(value) : String(value);
  34987. } catch (_ignoreError) {
  34988. return JSON.stringify(value);
  34989. }
  34990. }
  34991. function has(collection, key) {
  34992. return isImmutable(collection)
  34993. ? collection.has(key)
  34994. : isDataStructure(collection) && hasOwnProperty.call(collection, key);
  34995. }
  34996. function get(collection, key, notSetValue) {
  34997. return isImmutable(collection)
  34998. ? collection.get(key, notSetValue)
  34999. : !has(collection, key)
  35000. ? notSetValue
  35001. : typeof collection.get === 'function'
  35002. ? collection.get(key)
  35003. : collection[key];
  35004. }
  35005. function shallowCopy(from) {
  35006. if (Array.isArray(from)) {
  35007. return arrCopy(from);
  35008. }
  35009. var to = {};
  35010. for (var key in from) {
  35011. if (hasOwnProperty.call(from, key)) {
  35012. to[key] = from[key];
  35013. }
  35014. }
  35015. return to;
  35016. }
  35017. function remove(collection, key) {
  35018. if (!isDataStructure(collection)) {
  35019. throw new TypeError(
  35020. 'Cannot update non-data-structure value: ' + collection
  35021. );
  35022. }
  35023. if (isImmutable(collection)) {
  35024. if (!collection.remove) {
  35025. throw new TypeError(
  35026. 'Cannot update immutable value without .remove() method: ' + collection
  35027. );
  35028. }
  35029. return collection.remove(key);
  35030. }
  35031. if (!hasOwnProperty.call(collection, key)) {
  35032. return collection;
  35033. }
  35034. var collectionCopy = shallowCopy(collection);
  35035. if (Array.isArray(collectionCopy)) {
  35036. collectionCopy.splice(key, 1);
  35037. } else {
  35038. delete collectionCopy[key];
  35039. }
  35040. return collectionCopy;
  35041. }
  35042. function set(collection, key, value) {
  35043. if (!isDataStructure(collection)) {
  35044. throw new TypeError(
  35045. 'Cannot update non-data-structure value: ' + collection
  35046. );
  35047. }
  35048. if (isImmutable(collection)) {
  35049. if (!collection.set) {
  35050. throw new TypeError(
  35051. 'Cannot update immutable value without .set() method: ' + collection
  35052. );
  35053. }
  35054. return collection.set(key, value);
  35055. }
  35056. if (hasOwnProperty.call(collection, key) && value === collection[key]) {
  35057. return collection;
  35058. }
  35059. var collectionCopy = shallowCopy(collection);
  35060. collectionCopy[key] = value;
  35061. return collectionCopy;
  35062. }
  35063. function updateIn(collection, keyPath, notSetValue, updater) {
  35064. if (!updater) {
  35065. updater = notSetValue;
  35066. notSetValue = undefined;
  35067. }
  35068. var updatedValue = updateInDeeply(
  35069. isImmutable(collection),
  35070. collection,
  35071. coerceKeyPath(keyPath),
  35072. 0,
  35073. notSetValue,
  35074. updater
  35075. );
  35076. return updatedValue === NOT_SET ? notSetValue : updatedValue;
  35077. }
  35078. function updateInDeeply(
  35079. inImmutable,
  35080. existing,
  35081. keyPath,
  35082. i,
  35083. notSetValue,
  35084. updater
  35085. ) {
  35086. var wasNotSet = existing === NOT_SET;
  35087. if (i === keyPath.length) {
  35088. var existingValue = wasNotSet ? notSetValue : existing;
  35089. var newValue = updater(existingValue);
  35090. return newValue === existingValue ? existing : newValue;
  35091. }
  35092. if (!wasNotSet && !isDataStructure(existing)) {
  35093. throw new TypeError(
  35094. 'Cannot update within non-data-structure value in path [' +
  35095. keyPath.slice(0, i).map(quoteString) +
  35096. ']: ' +
  35097. existing
  35098. );
  35099. }
  35100. var key = keyPath[i];
  35101. var nextExisting = wasNotSet ? NOT_SET : get(existing, key, NOT_SET);
  35102. var nextUpdated = updateInDeeply(
  35103. nextExisting === NOT_SET ? inImmutable : isImmutable(nextExisting),
  35104. nextExisting,
  35105. keyPath,
  35106. i + 1,
  35107. notSetValue,
  35108. updater
  35109. );
  35110. return nextUpdated === nextExisting
  35111. ? existing
  35112. : nextUpdated === NOT_SET
  35113. ? remove(existing, key)
  35114. : set(
  35115. wasNotSet ? (inImmutable ? emptyMap() : {}) : existing,
  35116. key,
  35117. nextUpdated
  35118. );
  35119. }
  35120. function setIn(collection, keyPath, value) {
  35121. return updateIn(collection, keyPath, NOT_SET, function () { return value; });
  35122. }
  35123. function setIn$1(keyPath, v) {
  35124. return setIn(this, keyPath, v);
  35125. }
  35126. function removeIn(collection, keyPath) {
  35127. return updateIn(collection, keyPath, function () { return NOT_SET; });
  35128. }
  35129. function deleteIn(keyPath) {
  35130. return removeIn(this, keyPath);
  35131. }
  35132. function update(collection, key, notSetValue, updater) {
  35133. return updateIn(collection, [key], notSetValue, updater);
  35134. }
  35135. function update$1(key, notSetValue, updater) {
  35136. return arguments.length === 1
  35137. ? key(this)
  35138. : update(this, key, notSetValue, updater);
  35139. }
  35140. function updateIn$1(keyPath, notSetValue, updater) {
  35141. return updateIn(this, keyPath, notSetValue, updater);
  35142. }
  35143. function merge() {
  35144. var iters = [], len = arguments.length;
  35145. while ( len-- ) iters[ len ] = arguments[ len ];
  35146. return mergeIntoKeyedWith(this, iters);
  35147. }
  35148. function mergeWith(merger) {
  35149. var iters = [], len = arguments.length - 1;
  35150. while ( len-- > 0 ) iters[ len ] = arguments[ len + 1 ];
  35151. if (typeof merger !== 'function') {
  35152. throw new TypeError('Invalid merger function: ' + merger);
  35153. }
  35154. return mergeIntoKeyedWith(this, iters, merger);
  35155. }
  35156. function mergeIntoKeyedWith(collection, collections, merger) {
  35157. var iters = [];
  35158. for (var ii = 0; ii < collections.length; ii++) {
  35159. var collection$1 = KeyedCollection(collections[ii]);
  35160. if (collection$1.size !== 0) {
  35161. iters.push(collection$1);
  35162. }
  35163. }
  35164. if (iters.length === 0) {
  35165. return collection;
  35166. }
  35167. if (
  35168. collection.toSeq().size === 0 &&
  35169. !collection.__ownerID &&
  35170. iters.length === 1
  35171. ) {
  35172. return collection.constructor(iters[0]);
  35173. }
  35174. return collection.withMutations(function (collection) {
  35175. var mergeIntoCollection = merger
  35176. ? function (value, key) {
  35177. update(
  35178. collection,
  35179. key,
  35180. NOT_SET,
  35181. function (oldVal) { return (oldVal === NOT_SET ? value : merger(oldVal, value, key)); }
  35182. );
  35183. }
  35184. : function (value, key) {
  35185. collection.set(key, value);
  35186. };
  35187. for (var ii = 0; ii < iters.length; ii++) {
  35188. iters[ii].forEach(mergeIntoCollection);
  35189. }
  35190. });
  35191. }
  35192. function merge$1(collection) {
  35193. var sources = [], len = arguments.length - 1;
  35194. while ( len-- > 0 ) sources[ len ] = arguments[ len + 1 ];
  35195. return mergeWithSources(collection, sources);
  35196. }
  35197. function mergeWith$1(merger, collection) {
  35198. var sources = [], len = arguments.length - 2;
  35199. while ( len-- > 0 ) sources[ len ] = arguments[ len + 2 ];
  35200. return mergeWithSources(collection, sources, merger);
  35201. }
  35202. function mergeDeep(collection) {
  35203. var sources = [], len = arguments.length - 1;
  35204. while ( len-- > 0 ) sources[ len ] = arguments[ len + 1 ];
  35205. return mergeDeepWithSources(collection, sources);
  35206. }
  35207. function mergeDeepWith(merger, collection) {
  35208. var sources = [], len = arguments.length - 2;
  35209. while ( len-- > 0 ) sources[ len ] = arguments[ len + 2 ];
  35210. return mergeDeepWithSources(collection, sources, merger);
  35211. }
  35212. function mergeDeepWithSources(collection, sources, merger) {
  35213. return mergeWithSources(collection, sources, deepMergerWith(merger));
  35214. }
  35215. function mergeWithSources(collection, sources, merger) {
  35216. if (!isDataStructure(collection)) {
  35217. throw new TypeError(
  35218. 'Cannot merge into non-data-structure value: ' + collection
  35219. );
  35220. }
  35221. if (isImmutable(collection)) {
  35222. return typeof merger === 'function' && collection.mergeWith
  35223. ? collection.mergeWith.apply(collection, [ merger ].concat( sources ))
  35224. : collection.merge
  35225. ? collection.merge.apply(collection, sources)
  35226. : collection.concat.apply(collection, sources);
  35227. }
  35228. var isArray = Array.isArray(collection);
  35229. var merged = collection;
  35230. var Collection$$1 = isArray ? IndexedCollection : KeyedCollection;
  35231. var mergeItem = isArray
  35232. ? function (value) {
  35233. // Copy on write
  35234. if (merged === collection) {
  35235. merged = shallowCopy(merged);
  35236. }
  35237. merged.push(value);
  35238. }
  35239. : function (value, key) {
  35240. var hasVal = hasOwnProperty.call(merged, key);
  35241. var nextVal =
  35242. hasVal && merger ? merger(merged[key], value, key) : value;
  35243. if (!hasVal || nextVal !== merged[key]) {
  35244. // Copy on write
  35245. if (merged === collection) {
  35246. merged = shallowCopy(merged);
  35247. }
  35248. merged[key] = nextVal;
  35249. }
  35250. };
  35251. for (var i = 0; i < sources.length; i++) {
  35252. Collection$$1(sources[i]).forEach(mergeItem);
  35253. }
  35254. return merged;
  35255. }
  35256. function deepMergerWith(merger) {
  35257. function deepMerger(oldValue, newValue, key) {
  35258. return isDataStructure(oldValue) && isDataStructure(newValue)
  35259. ? mergeWithSources(oldValue, [newValue], deepMerger)
  35260. : merger
  35261. ? merger(oldValue, newValue, key)
  35262. : newValue;
  35263. }
  35264. return deepMerger;
  35265. }
  35266. function mergeDeep$1() {
  35267. var iters = [], len = arguments.length;
  35268. while ( len-- ) iters[ len ] = arguments[ len ];
  35269. return mergeDeepWithSources(this, iters);
  35270. }
  35271. function mergeDeepWith$1(merger) {
  35272. var iters = [], len = arguments.length - 1;
  35273. while ( len-- > 0 ) iters[ len ] = arguments[ len + 1 ];
  35274. return mergeDeepWithSources(this, iters, merger);
  35275. }
  35276. function mergeIn(keyPath) {
  35277. var iters = [], len = arguments.length - 1;
  35278. while ( len-- > 0 ) iters[ len ] = arguments[ len + 1 ];
  35279. return updateIn(this, keyPath, emptyMap(), function (m) { return mergeWithSources(m, iters); });
  35280. }
  35281. function mergeDeepIn(keyPath) {
  35282. var iters = [], len = arguments.length - 1;
  35283. while ( len-- > 0 ) iters[ len ] = arguments[ len + 1 ];
  35284. return updateIn(this, keyPath, emptyMap(), function (m) { return mergeDeepWithSources(m, iters); }
  35285. );
  35286. }
  35287. function withMutations(fn) {
  35288. var mutable = this.asMutable();
  35289. fn(mutable);
  35290. return mutable.wasAltered() ? mutable.__ensureOwner(this.__ownerID) : this;
  35291. }
  35292. function asMutable() {
  35293. return this.__ownerID ? this : this.__ensureOwner(new OwnerID());
  35294. }
  35295. function asImmutable() {
  35296. return this.__ensureOwner();
  35297. }
  35298. function wasAltered() {
  35299. return this.__altered;
  35300. }
  35301. var Map = /*@__PURE__*/(function (KeyedCollection$$1) {
  35302. function Map(value) {
  35303. return value === null || value === undefined
  35304. ? emptyMap()
  35305. : isMap(value) && !isOrdered(value)
  35306. ? value
  35307. : emptyMap().withMutations(function (map) {
  35308. var iter = KeyedCollection$$1(value);
  35309. assertNotInfinite(iter.size);
  35310. iter.forEach(function (v, k) { return map.set(k, v); });
  35311. });
  35312. }
  35313. if ( KeyedCollection$$1 ) Map.__proto__ = KeyedCollection$$1;
  35314. Map.prototype = Object.create( KeyedCollection$$1 && KeyedCollection$$1.prototype );
  35315. Map.prototype.constructor = Map;
  35316. Map.of = function of () {
  35317. var keyValues = [], len = arguments.length;
  35318. while ( len-- ) keyValues[ len ] = arguments[ len ];
  35319. return emptyMap().withMutations(function (map) {
  35320. for (var i = 0; i < keyValues.length; i += 2) {
  35321. if (i + 1 >= keyValues.length) {
  35322. throw new Error('Missing value for key: ' + keyValues[i]);
  35323. }
  35324. map.set(keyValues[i], keyValues[i + 1]);
  35325. }
  35326. });
  35327. };
  35328. Map.prototype.toString = function toString () {
  35329. return this.__toString('Map {', '}');
  35330. };
  35331. // @pragma Access
  35332. Map.prototype.get = function get (k, notSetValue) {
  35333. return this._root
  35334. ? this._root.get(0, undefined, k, notSetValue)
  35335. : notSetValue;
  35336. };
  35337. // @pragma Modification
  35338. Map.prototype.set = function set (k, v) {
  35339. return updateMap(this, k, v);
  35340. };
  35341. Map.prototype.remove = function remove (k) {
  35342. return updateMap(this, k, NOT_SET);
  35343. };
  35344. Map.prototype.deleteAll = function deleteAll (keys) {
  35345. var collection = Collection(keys);
  35346. if (collection.size === 0) {
  35347. return this;
  35348. }
  35349. return this.withMutations(function (map) {
  35350. collection.forEach(function (key) { return map.remove(key); });
  35351. });
  35352. };
  35353. Map.prototype.clear = function clear () {
  35354. if (this.size === 0) {
  35355. return this;
  35356. }
  35357. if (this.__ownerID) {
  35358. this.size = 0;
  35359. this._root = null;
  35360. this.__hash = undefined;
  35361. this.__altered = true;
  35362. return this;
  35363. }
  35364. return emptyMap();
  35365. };
  35366. // @pragma Composition
  35367. Map.prototype.sort = function sort (comparator) {
  35368. // Late binding
  35369. return OrderedMap(sortFactory(this, comparator));
  35370. };
  35371. Map.prototype.sortBy = function sortBy (mapper, comparator) {
  35372. // Late binding
  35373. return OrderedMap(sortFactory(this, comparator, mapper));
  35374. };
  35375. Map.prototype.map = function map (mapper, context) {
  35376. return this.withMutations(function (map) {
  35377. map.forEach(function (value, key) {
  35378. map.set(key, mapper.call(context, value, key, map));
  35379. });
  35380. });
  35381. };
  35382. // @pragma Mutability
  35383. Map.prototype.__iterator = function __iterator (type, reverse) {
  35384. return new MapIterator(this, type, reverse);
  35385. };
  35386. Map.prototype.__iterate = function __iterate (fn, reverse) {
  35387. var this$1 = this;
  35388. var iterations = 0;
  35389. this._root &&
  35390. this._root.iterate(function (entry) {
  35391. iterations++;
  35392. return fn(entry[1], entry[0], this$1);
  35393. }, reverse);
  35394. return iterations;
  35395. };
  35396. Map.prototype.__ensureOwner = function __ensureOwner (ownerID) {
  35397. if (ownerID === this.__ownerID) {
  35398. return this;
  35399. }
  35400. if (!ownerID) {
  35401. if (this.size === 0) {
  35402. return emptyMap();
  35403. }
  35404. this.__ownerID = ownerID;
  35405. this.__altered = false;
  35406. return this;
  35407. }
  35408. return makeMap(this.size, this._root, ownerID, this.__hash);
  35409. };
  35410. return Map;
  35411. }(KeyedCollection));
  35412. Map.isMap = isMap;
  35413. var MapPrototype = Map.prototype;
  35414. MapPrototype[IS_MAP_SYMBOL] = true;
  35415. MapPrototype[DELETE] = MapPrototype.remove;
  35416. MapPrototype.removeAll = MapPrototype.deleteAll;
  35417. MapPrototype.setIn = setIn$1;
  35418. MapPrototype.removeIn = MapPrototype.deleteIn = deleteIn;
  35419. MapPrototype.update = update$1;
  35420. MapPrototype.updateIn = updateIn$1;
  35421. MapPrototype.merge = MapPrototype.concat = merge;
  35422. MapPrototype.mergeWith = mergeWith;
  35423. MapPrototype.mergeDeep = mergeDeep$1;
  35424. MapPrototype.mergeDeepWith = mergeDeepWith$1;
  35425. MapPrototype.mergeIn = mergeIn;
  35426. MapPrototype.mergeDeepIn = mergeDeepIn;
  35427. MapPrototype.withMutations = withMutations;
  35428. MapPrototype.wasAltered = wasAltered;
  35429. MapPrototype.asImmutable = asImmutable;
  35430. MapPrototype['@@transducer/init'] = MapPrototype.asMutable = asMutable;
  35431. MapPrototype['@@transducer/step'] = function(result, arr) {
  35432. return result.set(arr[0], arr[1]);
  35433. };
  35434. MapPrototype['@@transducer/result'] = function(obj) {
  35435. return obj.asImmutable();
  35436. };
  35437. // #pragma Trie Nodes
  35438. var ArrayMapNode = function ArrayMapNode(ownerID, entries) {
  35439. this.ownerID = ownerID;
  35440. this.entries = entries;
  35441. };
  35442. ArrayMapNode.prototype.get = function get (shift, keyHash, key, notSetValue) {
  35443. var entries = this.entries;
  35444. for (var ii = 0, len = entries.length; ii < len; ii++) {
  35445. if (is(key, entries[ii][0])) {
  35446. return entries[ii][1];
  35447. }
  35448. }
  35449. return notSetValue;
  35450. };
  35451. ArrayMapNode.prototype.update = function update (ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  35452. var removed = value === NOT_SET;
  35453. var entries = this.entries;
  35454. var idx = 0;
  35455. var len = entries.length;
  35456. for (; idx < len; idx++) {
  35457. if (is(key, entries[idx][0])) {
  35458. break;
  35459. }
  35460. }
  35461. var exists = idx < len;
  35462. if (exists ? entries[idx][1] === value : removed) {
  35463. return this;
  35464. }
  35465. SetRef(didAlter);
  35466. (removed || !exists) && SetRef(didChangeSize);
  35467. if (removed && entries.length === 1) {
  35468. return; // undefined
  35469. }
  35470. if (!exists && !removed && entries.length >= MAX_ARRAY_MAP_SIZE) {
  35471. return createNodes(ownerID, entries, key, value);
  35472. }
  35473. var isEditable = ownerID && ownerID === this.ownerID;
  35474. var newEntries = isEditable ? entries : arrCopy(entries);
  35475. if (exists) {
  35476. if (removed) {
  35477. idx === len - 1
  35478. ? newEntries.pop()
  35479. : (newEntries[idx] = newEntries.pop());
  35480. } else {
  35481. newEntries[idx] = [key, value];
  35482. }
  35483. } else {
  35484. newEntries.push([key, value]);
  35485. }
  35486. if (isEditable) {
  35487. this.entries = newEntries;
  35488. return this;
  35489. }
  35490. return new ArrayMapNode(ownerID, newEntries);
  35491. };
  35492. var BitmapIndexedNode = function BitmapIndexedNode(ownerID, bitmap, nodes) {
  35493. this.ownerID = ownerID;
  35494. this.bitmap = bitmap;
  35495. this.nodes = nodes;
  35496. };
  35497. BitmapIndexedNode.prototype.get = function get (shift, keyHash, key, notSetValue) {
  35498. if (keyHash === undefined) {
  35499. keyHash = hash(key);
  35500. }
  35501. var bit = 1 << ((shift === 0 ? keyHash : keyHash >>> shift) & MASK);
  35502. var bitmap = this.bitmap;
  35503. return (bitmap & bit) === 0
  35504. ? notSetValue
  35505. : this.nodes[popCount(bitmap & (bit - 1))].get(
  35506. shift + SHIFT,
  35507. keyHash,
  35508. key,
  35509. notSetValue
  35510. );
  35511. };
  35512. BitmapIndexedNode.prototype.update = function update (ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  35513. if (keyHash === undefined) {
  35514. keyHash = hash(key);
  35515. }
  35516. var keyHashFrag = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  35517. var bit = 1 << keyHashFrag;
  35518. var bitmap = this.bitmap;
  35519. var exists = (bitmap & bit) !== 0;
  35520. if (!exists && value === NOT_SET) {
  35521. return this;
  35522. }
  35523. var idx = popCount(bitmap & (bit - 1));
  35524. var nodes = this.nodes;
  35525. var node = exists ? nodes[idx] : undefined;
  35526. var newNode = updateNode(
  35527. node,
  35528. ownerID,
  35529. shift + SHIFT,
  35530. keyHash,
  35531. key,
  35532. value,
  35533. didChangeSize,
  35534. didAlter
  35535. );
  35536. if (newNode === node) {
  35537. return this;
  35538. }
  35539. if (!exists && newNode && nodes.length >= MAX_BITMAP_INDEXED_SIZE) {
  35540. return expandNodes(ownerID, nodes, bitmap, keyHashFrag, newNode);
  35541. }
  35542. if (
  35543. exists &&
  35544. !newNode &&
  35545. nodes.length === 2 &&
  35546. isLeafNode(nodes[idx ^ 1])
  35547. ) {
  35548. return nodes[idx ^ 1];
  35549. }
  35550. if (exists && newNode && nodes.length === 1 && isLeafNode(newNode)) {
  35551. return newNode;
  35552. }
  35553. var isEditable = ownerID && ownerID === this.ownerID;
  35554. var newBitmap = exists ? (newNode ? bitmap : bitmap ^ bit) : bitmap | bit;
  35555. var newNodes = exists
  35556. ? newNode
  35557. ? setAt(nodes, idx, newNode, isEditable)
  35558. : spliceOut(nodes, idx, isEditable)
  35559. : spliceIn(nodes, idx, newNode, isEditable);
  35560. if (isEditable) {
  35561. this.bitmap = newBitmap;
  35562. this.nodes = newNodes;
  35563. return this;
  35564. }
  35565. return new BitmapIndexedNode(ownerID, newBitmap, newNodes);
  35566. };
  35567. var HashArrayMapNode = function HashArrayMapNode(ownerID, count, nodes) {
  35568. this.ownerID = ownerID;
  35569. this.count = count;
  35570. this.nodes = nodes;
  35571. };
  35572. HashArrayMapNode.prototype.get = function get (shift, keyHash, key, notSetValue) {
  35573. if (keyHash === undefined) {
  35574. keyHash = hash(key);
  35575. }
  35576. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  35577. var node = this.nodes[idx];
  35578. return node
  35579. ? node.get(shift + SHIFT, keyHash, key, notSetValue)
  35580. : notSetValue;
  35581. };
  35582. HashArrayMapNode.prototype.update = function update (ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  35583. if (keyHash === undefined) {
  35584. keyHash = hash(key);
  35585. }
  35586. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  35587. var removed = value === NOT_SET;
  35588. var nodes = this.nodes;
  35589. var node = nodes[idx];
  35590. if (removed && !node) {
  35591. return this;
  35592. }
  35593. var newNode = updateNode(
  35594. node,
  35595. ownerID,
  35596. shift + SHIFT,
  35597. keyHash,
  35598. key,
  35599. value,
  35600. didChangeSize,
  35601. didAlter
  35602. );
  35603. if (newNode === node) {
  35604. return this;
  35605. }
  35606. var newCount = this.count;
  35607. if (!node) {
  35608. newCount++;
  35609. } else if (!newNode) {
  35610. newCount--;
  35611. if (newCount < MIN_HASH_ARRAY_MAP_SIZE) {
  35612. return packNodes(ownerID, nodes, newCount, idx);
  35613. }
  35614. }
  35615. var isEditable = ownerID && ownerID === this.ownerID;
  35616. var newNodes = setAt(nodes, idx, newNode, isEditable);
  35617. if (isEditable) {
  35618. this.count = newCount;
  35619. this.nodes = newNodes;
  35620. return this;
  35621. }
  35622. return new HashArrayMapNode(ownerID, newCount, newNodes);
  35623. };
  35624. var HashCollisionNode = function HashCollisionNode(ownerID, keyHash, entries) {
  35625. this.ownerID = ownerID;
  35626. this.keyHash = keyHash;
  35627. this.entries = entries;
  35628. };
  35629. HashCollisionNode.prototype.get = function get (shift, keyHash, key, notSetValue) {
  35630. var entries = this.entries;
  35631. for (var ii = 0, len = entries.length; ii < len; ii++) {
  35632. if (is(key, entries[ii][0])) {
  35633. return entries[ii][1];
  35634. }
  35635. }
  35636. return notSetValue;
  35637. };
  35638. HashCollisionNode.prototype.update = function update (ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  35639. if (keyHash === undefined) {
  35640. keyHash = hash(key);
  35641. }
  35642. var removed = value === NOT_SET;
  35643. if (keyHash !== this.keyHash) {
  35644. if (removed) {
  35645. return this;
  35646. }
  35647. SetRef(didAlter);
  35648. SetRef(didChangeSize);
  35649. return mergeIntoNode(this, ownerID, shift, keyHash, [key, value]);
  35650. }
  35651. var entries = this.entries;
  35652. var idx = 0;
  35653. var len = entries.length;
  35654. for (; idx < len; idx++) {
  35655. if (is(key, entries[idx][0])) {
  35656. break;
  35657. }
  35658. }
  35659. var exists = idx < len;
  35660. if (exists ? entries[idx][1] === value : removed) {
  35661. return this;
  35662. }
  35663. SetRef(didAlter);
  35664. (removed || !exists) && SetRef(didChangeSize);
  35665. if (removed && len === 2) {
  35666. return new ValueNode(ownerID, this.keyHash, entries[idx ^ 1]);
  35667. }
  35668. var isEditable = ownerID && ownerID === this.ownerID;
  35669. var newEntries = isEditable ? entries : arrCopy(entries);
  35670. if (exists) {
  35671. if (removed) {
  35672. idx === len - 1
  35673. ? newEntries.pop()
  35674. : (newEntries[idx] = newEntries.pop());
  35675. } else {
  35676. newEntries[idx] = [key, value];
  35677. }
  35678. } else {
  35679. newEntries.push([key, value]);
  35680. }
  35681. if (isEditable) {
  35682. this.entries = newEntries;
  35683. return this;
  35684. }
  35685. return new HashCollisionNode(ownerID, this.keyHash, newEntries);
  35686. };
  35687. var ValueNode = function ValueNode(ownerID, keyHash, entry) {
  35688. this.ownerID = ownerID;
  35689. this.keyHash = keyHash;
  35690. this.entry = entry;
  35691. };
  35692. ValueNode.prototype.get = function get (shift, keyHash, key, notSetValue) {
  35693. return is(key, this.entry[0]) ? this.entry[1] : notSetValue;
  35694. };
  35695. ValueNode.prototype.update = function update (ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  35696. var removed = value === NOT_SET;
  35697. var keyMatch = is(key, this.entry[0]);
  35698. if (keyMatch ? value === this.entry[1] : removed) {
  35699. return this;
  35700. }
  35701. SetRef(didAlter);
  35702. if (removed) {
  35703. SetRef(didChangeSize);
  35704. return; // undefined
  35705. }
  35706. if (keyMatch) {
  35707. if (ownerID && ownerID === this.ownerID) {
  35708. this.entry[1] = value;
  35709. return this;
  35710. }
  35711. return new ValueNode(ownerID, this.keyHash, [key, value]);
  35712. }
  35713. SetRef(didChangeSize);
  35714. return mergeIntoNode(this, ownerID, shift, hash(key), [key, value]);
  35715. };
  35716. // #pragma Iterators
  35717. ArrayMapNode.prototype.iterate = HashCollisionNode.prototype.iterate = function(
  35718. fn,
  35719. reverse
  35720. ) {
  35721. var entries = this.entries;
  35722. for (var ii = 0, maxIndex = entries.length - 1; ii <= maxIndex; ii++) {
  35723. if (fn(entries[reverse ? maxIndex - ii : ii]) === false) {
  35724. return false;
  35725. }
  35726. }
  35727. };
  35728. BitmapIndexedNode.prototype.iterate = HashArrayMapNode.prototype.iterate = function(
  35729. fn,
  35730. reverse
  35731. ) {
  35732. var nodes = this.nodes;
  35733. for (var ii = 0, maxIndex = nodes.length - 1; ii <= maxIndex; ii++) {
  35734. var node = nodes[reverse ? maxIndex - ii : ii];
  35735. if (node && node.iterate(fn, reverse) === false) {
  35736. return false;
  35737. }
  35738. }
  35739. };
  35740. // eslint-disable-next-line no-unused-vars
  35741. ValueNode.prototype.iterate = function(fn, reverse) {
  35742. return fn(this.entry);
  35743. };
  35744. var MapIterator = /*@__PURE__*/(function (Iterator$$1) {
  35745. function MapIterator(map, type, reverse) {
  35746. this._type = type;
  35747. this._reverse = reverse;
  35748. this._stack = map._root && mapIteratorFrame(map._root);
  35749. }
  35750. if ( Iterator$$1 ) MapIterator.__proto__ = Iterator$$1;
  35751. MapIterator.prototype = Object.create( Iterator$$1 && Iterator$$1.prototype );
  35752. MapIterator.prototype.constructor = MapIterator;
  35753. MapIterator.prototype.next = function next () {
  35754. var type = this._type;
  35755. var stack = this._stack;
  35756. while (stack) {
  35757. var node = stack.node;
  35758. var index = stack.index++;
  35759. var maxIndex = (void 0);
  35760. if (node.entry) {
  35761. if (index === 0) {
  35762. return mapIteratorValue(type, node.entry);
  35763. }
  35764. } else if (node.entries) {
  35765. maxIndex = node.entries.length - 1;
  35766. if (index <= maxIndex) {
  35767. return mapIteratorValue(
  35768. type,
  35769. node.entries[this._reverse ? maxIndex - index : index]
  35770. );
  35771. }
  35772. } else {
  35773. maxIndex = node.nodes.length - 1;
  35774. if (index <= maxIndex) {
  35775. var subNode = node.nodes[this._reverse ? maxIndex - index : index];
  35776. if (subNode) {
  35777. if (subNode.entry) {
  35778. return mapIteratorValue(type, subNode.entry);
  35779. }
  35780. stack = this._stack = mapIteratorFrame(subNode, stack);
  35781. }
  35782. continue;
  35783. }
  35784. }
  35785. stack = this._stack = this._stack.__prev;
  35786. }
  35787. return iteratorDone();
  35788. };
  35789. return MapIterator;
  35790. }(Iterator));
  35791. function mapIteratorValue(type, entry) {
  35792. return iteratorValue(type, entry[0], entry[1]);
  35793. }
  35794. function mapIteratorFrame(node, prev) {
  35795. return {
  35796. node: node,
  35797. index: 0,
  35798. __prev: prev,
  35799. };
  35800. }
  35801. function makeMap(size, root, ownerID, hash$$1) {
  35802. var map = Object.create(MapPrototype);
  35803. map.size = size;
  35804. map._root = root;
  35805. map.__ownerID = ownerID;
  35806. map.__hash = hash$$1;
  35807. map.__altered = false;
  35808. return map;
  35809. }
  35810. var EMPTY_MAP;
  35811. function emptyMap() {
  35812. return EMPTY_MAP || (EMPTY_MAP = makeMap(0));
  35813. }
  35814. function updateMap(map, k, v) {
  35815. var newRoot;
  35816. var newSize;
  35817. if (!map._root) {
  35818. if (v === NOT_SET) {
  35819. return map;
  35820. }
  35821. newSize = 1;
  35822. newRoot = new ArrayMapNode(map.__ownerID, [[k, v]]);
  35823. } else {
  35824. var didChangeSize = MakeRef();
  35825. var didAlter = MakeRef();
  35826. newRoot = updateNode(
  35827. map._root,
  35828. map.__ownerID,
  35829. 0,
  35830. undefined,
  35831. k,
  35832. v,
  35833. didChangeSize,
  35834. didAlter
  35835. );
  35836. if (!didAlter.value) {
  35837. return map;
  35838. }
  35839. newSize = map.size + (didChangeSize.value ? (v === NOT_SET ? -1 : 1) : 0);
  35840. }
  35841. if (map.__ownerID) {
  35842. map.size = newSize;
  35843. map._root = newRoot;
  35844. map.__hash = undefined;
  35845. map.__altered = true;
  35846. return map;
  35847. }
  35848. return newRoot ? makeMap(newSize, newRoot) : emptyMap();
  35849. }
  35850. function updateNode(
  35851. node,
  35852. ownerID,
  35853. shift,
  35854. keyHash,
  35855. key,
  35856. value,
  35857. didChangeSize,
  35858. didAlter
  35859. ) {
  35860. if (!node) {
  35861. if (value === NOT_SET) {
  35862. return node;
  35863. }
  35864. SetRef(didAlter);
  35865. SetRef(didChangeSize);
  35866. return new ValueNode(ownerID, keyHash, [key, value]);
  35867. }
  35868. return node.update(
  35869. ownerID,
  35870. shift,
  35871. keyHash,
  35872. key,
  35873. value,
  35874. didChangeSize,
  35875. didAlter
  35876. );
  35877. }
  35878. function isLeafNode(node) {
  35879. return (
  35880. node.constructor === ValueNode || node.constructor === HashCollisionNode
  35881. );
  35882. }
  35883. function mergeIntoNode(node, ownerID, shift, keyHash, entry) {
  35884. if (node.keyHash === keyHash) {
  35885. return new HashCollisionNode(ownerID, keyHash, [node.entry, entry]);
  35886. }
  35887. var idx1 = (shift === 0 ? node.keyHash : node.keyHash >>> shift) & MASK;
  35888. var idx2 = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  35889. var newNode;
  35890. var nodes =
  35891. idx1 === idx2
  35892. ? [mergeIntoNode(node, ownerID, shift + SHIFT, keyHash, entry)]
  35893. : ((newNode = new ValueNode(ownerID, keyHash, entry)),
  35894. idx1 < idx2 ? [node, newNode] : [newNode, node]);
  35895. return new BitmapIndexedNode(ownerID, (1 << idx1) | (1 << idx2), nodes);
  35896. }
  35897. function createNodes(ownerID, entries, key, value) {
  35898. if (!ownerID) {
  35899. ownerID = new OwnerID();
  35900. }
  35901. var node = new ValueNode(ownerID, hash(key), [key, value]);
  35902. for (var ii = 0; ii < entries.length; ii++) {
  35903. var entry = entries[ii];
  35904. node = node.update(ownerID, 0, undefined, entry[0], entry[1]);
  35905. }
  35906. return node;
  35907. }
  35908. function packNodes(ownerID, nodes, count, excluding) {
  35909. var bitmap = 0;
  35910. var packedII = 0;
  35911. var packedNodes = new Array(count);
  35912. for (var ii = 0, bit = 1, len = nodes.length; ii < len; ii++, bit <<= 1) {
  35913. var node = nodes[ii];
  35914. if (node !== undefined && ii !== excluding) {
  35915. bitmap |= bit;
  35916. packedNodes[packedII++] = node;
  35917. }
  35918. }
  35919. return new BitmapIndexedNode(ownerID, bitmap, packedNodes);
  35920. }
  35921. function expandNodes(ownerID, nodes, bitmap, including, node) {
  35922. var count = 0;
  35923. var expandedNodes = new Array(SIZE);
  35924. for (var ii = 0; bitmap !== 0; ii++, bitmap >>>= 1) {
  35925. expandedNodes[ii] = bitmap & 1 ? nodes[count++] : undefined;
  35926. }
  35927. expandedNodes[including] = node;
  35928. return new HashArrayMapNode(ownerID, count + 1, expandedNodes);
  35929. }
  35930. function popCount(x) {
  35931. x -= (x >> 1) & 0x55555555;
  35932. x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
  35933. x = (x + (x >> 4)) & 0x0f0f0f0f;
  35934. x += x >> 8;
  35935. x += x >> 16;
  35936. return x & 0x7f;
  35937. }
  35938. function setAt(array, idx, val, canEdit) {
  35939. var newArray = canEdit ? array : arrCopy(array);
  35940. newArray[idx] = val;
  35941. return newArray;
  35942. }
  35943. function spliceIn(array, idx, val, canEdit) {
  35944. var newLen = array.length + 1;
  35945. if (canEdit && idx + 1 === newLen) {
  35946. array[idx] = val;
  35947. return array;
  35948. }
  35949. var newArray = new Array(newLen);
  35950. var after = 0;
  35951. for (var ii = 0; ii < newLen; ii++) {
  35952. if (ii === idx) {
  35953. newArray[ii] = val;
  35954. after = -1;
  35955. } else {
  35956. newArray[ii] = array[ii + after];
  35957. }
  35958. }
  35959. return newArray;
  35960. }
  35961. function spliceOut(array, idx, canEdit) {
  35962. var newLen = array.length - 1;
  35963. if (canEdit && idx === newLen) {
  35964. array.pop();
  35965. return array;
  35966. }
  35967. var newArray = new Array(newLen);
  35968. var after = 0;
  35969. for (var ii = 0; ii < newLen; ii++) {
  35970. if (ii === idx) {
  35971. after = 1;
  35972. }
  35973. newArray[ii] = array[ii + after];
  35974. }
  35975. return newArray;
  35976. }
  35977. var MAX_ARRAY_MAP_SIZE = SIZE / 4;
  35978. var MAX_BITMAP_INDEXED_SIZE = SIZE / 2;
  35979. var MIN_HASH_ARRAY_MAP_SIZE = SIZE / 4;
  35980. var IS_LIST_SYMBOL = '@@__IMMUTABLE_LIST__@@';
  35981. function isList(maybeList) {
  35982. return Boolean(maybeList && maybeList[IS_LIST_SYMBOL]);
  35983. }
  35984. var List = /*@__PURE__*/(function (IndexedCollection$$1) {
  35985. function List(value) {
  35986. var empty = emptyList();
  35987. if (value === null || value === undefined) {
  35988. return empty;
  35989. }
  35990. if (isList(value)) {
  35991. return value;
  35992. }
  35993. var iter = IndexedCollection$$1(value);
  35994. var size = iter.size;
  35995. if (size === 0) {
  35996. return empty;
  35997. }
  35998. assertNotInfinite(size);
  35999. if (size > 0 && size < SIZE) {
  36000. return makeList(0, size, SHIFT, null, new VNode(iter.toArray()));
  36001. }
  36002. return empty.withMutations(function (list) {
  36003. list.setSize(size);
  36004. iter.forEach(function (v, i) { return list.set(i, v); });
  36005. });
  36006. }
  36007. if ( IndexedCollection$$1 ) List.__proto__ = IndexedCollection$$1;
  36008. List.prototype = Object.create( IndexedCollection$$1 && IndexedCollection$$1.prototype );
  36009. List.prototype.constructor = List;
  36010. List.of = function of (/*...values*/) {
  36011. return this(arguments);
  36012. };
  36013. List.prototype.toString = function toString () {
  36014. return this.__toString('List [', ']');
  36015. };
  36016. // @pragma Access
  36017. List.prototype.get = function get (index, notSetValue) {
  36018. index = wrapIndex(this, index);
  36019. if (index >= 0 && index < this.size) {
  36020. index += this._origin;
  36021. var node = listNodeFor(this, index);
  36022. return node && node.array[index & MASK];
  36023. }
  36024. return notSetValue;
  36025. };
  36026. // @pragma Modification
  36027. List.prototype.set = function set (index, value) {
  36028. return updateList(this, index, value);
  36029. };
  36030. List.prototype.remove = function remove (index) {
  36031. return !this.has(index)
  36032. ? this
  36033. : index === 0
  36034. ? this.shift()
  36035. : index === this.size - 1
  36036. ? this.pop()
  36037. : this.splice(index, 1);
  36038. };
  36039. List.prototype.insert = function insert (index, value) {
  36040. return this.splice(index, 0, value);
  36041. };
  36042. List.prototype.clear = function clear () {
  36043. if (this.size === 0) {
  36044. return this;
  36045. }
  36046. if (this.__ownerID) {
  36047. this.size = this._origin = this._capacity = 0;
  36048. this._level = SHIFT;
  36049. this._root = this._tail = null;
  36050. this.__hash = undefined;
  36051. this.__altered = true;
  36052. return this;
  36053. }
  36054. return emptyList();
  36055. };
  36056. List.prototype.push = function push (/*...values*/) {
  36057. var values = arguments;
  36058. var oldSize = this.size;
  36059. return this.withMutations(function (list) {
  36060. setListBounds(list, 0, oldSize + values.length);
  36061. for (var ii = 0; ii < values.length; ii++) {
  36062. list.set(oldSize + ii, values[ii]);
  36063. }
  36064. });
  36065. };
  36066. List.prototype.pop = function pop () {
  36067. return setListBounds(this, 0, -1);
  36068. };
  36069. List.prototype.unshift = function unshift (/*...values*/) {
  36070. var values = arguments;
  36071. return this.withMutations(function (list) {
  36072. setListBounds(list, -values.length);
  36073. for (var ii = 0; ii < values.length; ii++) {
  36074. list.set(ii, values[ii]);
  36075. }
  36076. });
  36077. };
  36078. List.prototype.shift = function shift () {
  36079. return setListBounds(this, 1);
  36080. };
  36081. // @pragma Composition
  36082. List.prototype.concat = function concat (/*...collections*/) {
  36083. var arguments$1 = arguments;
  36084. var seqs = [];
  36085. for (var i = 0; i < arguments.length; i++) {
  36086. var argument = arguments$1[i];
  36087. var seq = IndexedCollection$$1(
  36088. typeof argument !== 'string' && hasIterator(argument)
  36089. ? argument
  36090. : [argument]
  36091. );
  36092. if (seq.size !== 0) {
  36093. seqs.push(seq);
  36094. }
  36095. }
  36096. if (seqs.length === 0) {
  36097. return this;
  36098. }
  36099. if (this.size === 0 && !this.__ownerID && seqs.length === 1) {
  36100. return this.constructor(seqs[0]);
  36101. }
  36102. return this.withMutations(function (list) {
  36103. seqs.forEach(function (seq) { return seq.forEach(function (value) { return list.push(value); }); });
  36104. });
  36105. };
  36106. List.prototype.setSize = function setSize (size) {
  36107. return setListBounds(this, 0, size);
  36108. };
  36109. List.prototype.map = function map (mapper, context) {
  36110. var this$1 = this;
  36111. return this.withMutations(function (list) {
  36112. for (var i = 0; i < this$1.size; i++) {
  36113. list.set(i, mapper.call(context, list.get(i), i, list));
  36114. }
  36115. });
  36116. };
  36117. // @pragma Iteration
  36118. List.prototype.slice = function slice (begin, end) {
  36119. var size = this.size;
  36120. if (wholeSlice(begin, end, size)) {
  36121. return this;
  36122. }
  36123. return setListBounds(
  36124. this,
  36125. resolveBegin(begin, size),
  36126. resolveEnd(end, size)
  36127. );
  36128. };
  36129. List.prototype.__iterator = function __iterator (type, reverse) {
  36130. var index = reverse ? this.size : 0;
  36131. var values = iterateList(this, reverse);
  36132. return new Iterator(function () {
  36133. var value = values();
  36134. return value === DONE
  36135. ? iteratorDone()
  36136. : iteratorValue(type, reverse ? --index : index++, value);
  36137. });
  36138. };
  36139. List.prototype.__iterate = function __iterate (fn, reverse) {
  36140. var index = reverse ? this.size : 0;
  36141. var values = iterateList(this, reverse);
  36142. var value;
  36143. while ((value = values()) !== DONE) {
  36144. if (fn(value, reverse ? --index : index++, this) === false) {
  36145. break;
  36146. }
  36147. }
  36148. return index;
  36149. };
  36150. List.prototype.__ensureOwner = function __ensureOwner (ownerID) {
  36151. if (ownerID === this.__ownerID) {
  36152. return this;
  36153. }
  36154. if (!ownerID) {
  36155. if (this.size === 0) {
  36156. return emptyList();
  36157. }
  36158. this.__ownerID = ownerID;
  36159. this.__altered = false;
  36160. return this;
  36161. }
  36162. return makeList(
  36163. this._origin,
  36164. this._capacity,
  36165. this._level,
  36166. this._root,
  36167. this._tail,
  36168. ownerID,
  36169. this.__hash
  36170. );
  36171. };
  36172. return List;
  36173. }(IndexedCollection));
  36174. List.isList = isList;
  36175. var ListPrototype = List.prototype;
  36176. ListPrototype[IS_LIST_SYMBOL] = true;
  36177. ListPrototype[DELETE] = ListPrototype.remove;
  36178. ListPrototype.merge = ListPrototype.concat;
  36179. ListPrototype.setIn = setIn$1;
  36180. ListPrototype.deleteIn = ListPrototype.removeIn = deleteIn;
  36181. ListPrototype.update = update$1;
  36182. ListPrototype.updateIn = updateIn$1;
  36183. ListPrototype.mergeIn = mergeIn;
  36184. ListPrototype.mergeDeepIn = mergeDeepIn;
  36185. ListPrototype.withMutations = withMutations;
  36186. ListPrototype.wasAltered = wasAltered;
  36187. ListPrototype.asImmutable = asImmutable;
  36188. ListPrototype['@@transducer/init'] = ListPrototype.asMutable = asMutable;
  36189. ListPrototype['@@transducer/step'] = function(result, arr) {
  36190. return result.push(arr);
  36191. };
  36192. ListPrototype['@@transducer/result'] = function(obj) {
  36193. return obj.asImmutable();
  36194. };
  36195. var VNode = function VNode(array, ownerID) {
  36196. this.array = array;
  36197. this.ownerID = ownerID;
  36198. };
  36199. // TODO: seems like these methods are very similar
  36200. VNode.prototype.removeBefore = function removeBefore (ownerID, level, index) {
  36201. if (index === level ? 1 << level : this.array.length === 0) {
  36202. return this;
  36203. }
  36204. var originIndex = (index >>> level) & MASK;
  36205. if (originIndex >= this.array.length) {
  36206. return new VNode([], ownerID);
  36207. }
  36208. var removingFirst = originIndex === 0;
  36209. var newChild;
  36210. if (level > 0) {
  36211. var oldChild = this.array[originIndex];
  36212. newChild =
  36213. oldChild && oldChild.removeBefore(ownerID, level - SHIFT, index);
  36214. if (newChild === oldChild && removingFirst) {
  36215. return this;
  36216. }
  36217. }
  36218. if (removingFirst && !newChild) {
  36219. return this;
  36220. }
  36221. var editable = editableVNode(this, ownerID);
  36222. if (!removingFirst) {
  36223. for (var ii = 0; ii < originIndex; ii++) {
  36224. editable.array[ii] = undefined;
  36225. }
  36226. }
  36227. if (newChild) {
  36228. editable.array[originIndex] = newChild;
  36229. }
  36230. return editable;
  36231. };
  36232. VNode.prototype.removeAfter = function removeAfter (ownerID, level, index) {
  36233. if (index === (level ? 1 << level : 0) || this.array.length === 0) {
  36234. return this;
  36235. }
  36236. var sizeIndex = ((index - 1) >>> level) & MASK;
  36237. if (sizeIndex >= this.array.length) {
  36238. return this;
  36239. }
  36240. var newChild;
  36241. if (level > 0) {
  36242. var oldChild = this.array[sizeIndex];
  36243. newChild =
  36244. oldChild && oldChild.removeAfter(ownerID, level - SHIFT, index);
  36245. if (newChild === oldChild && sizeIndex === this.array.length - 1) {
  36246. return this;
  36247. }
  36248. }
  36249. var editable = editableVNode(this, ownerID);
  36250. editable.array.splice(sizeIndex + 1);
  36251. if (newChild) {
  36252. editable.array[sizeIndex] = newChild;
  36253. }
  36254. return editable;
  36255. };
  36256. var DONE = {};
  36257. function iterateList(list, reverse) {
  36258. var left = list._origin;
  36259. var right = list._capacity;
  36260. var tailPos = getTailOffset(right);
  36261. var tail = list._tail;
  36262. return iterateNodeOrLeaf(list._root, list._level, 0);
  36263. function iterateNodeOrLeaf(node, level, offset) {
  36264. return level === 0
  36265. ? iterateLeaf(node, offset)
  36266. : iterateNode(node, level, offset);
  36267. }
  36268. function iterateLeaf(node, offset) {
  36269. var array = offset === tailPos ? tail && tail.array : node && node.array;
  36270. var from = offset > left ? 0 : left - offset;
  36271. var to = right - offset;
  36272. if (to > SIZE) {
  36273. to = SIZE;
  36274. }
  36275. return function () {
  36276. if (from === to) {
  36277. return DONE;
  36278. }
  36279. var idx = reverse ? --to : from++;
  36280. return array && array[idx];
  36281. };
  36282. }
  36283. function iterateNode(node, level, offset) {
  36284. var values;
  36285. var array = node && node.array;
  36286. var from = offset > left ? 0 : (left - offset) >> level;
  36287. var to = ((right - offset) >> level) + 1;
  36288. if (to > SIZE) {
  36289. to = SIZE;
  36290. }
  36291. return function () {
  36292. while (true) {
  36293. if (values) {
  36294. var value = values();
  36295. if (value !== DONE) {
  36296. return value;
  36297. }
  36298. values = null;
  36299. }
  36300. if (from === to) {
  36301. return DONE;
  36302. }
  36303. var idx = reverse ? --to : from++;
  36304. values = iterateNodeOrLeaf(
  36305. array && array[idx],
  36306. level - SHIFT,
  36307. offset + (idx << level)
  36308. );
  36309. }
  36310. };
  36311. }
  36312. }
  36313. function makeList(origin, capacity, level, root, tail, ownerID, hash) {
  36314. var list = Object.create(ListPrototype);
  36315. list.size = capacity - origin;
  36316. list._origin = origin;
  36317. list._capacity = capacity;
  36318. list._level = level;
  36319. list._root = root;
  36320. list._tail = tail;
  36321. list.__ownerID = ownerID;
  36322. list.__hash = hash;
  36323. list.__altered = false;
  36324. return list;
  36325. }
  36326. var EMPTY_LIST;
  36327. function emptyList() {
  36328. return EMPTY_LIST || (EMPTY_LIST = makeList(0, 0, SHIFT));
  36329. }
  36330. function updateList(list, index, value) {
  36331. index = wrapIndex(list, index);
  36332. if (index !== index) {
  36333. return list;
  36334. }
  36335. if (index >= list.size || index < 0) {
  36336. return list.withMutations(function (list) {
  36337. index < 0
  36338. ? setListBounds(list, index).set(0, value)
  36339. : setListBounds(list, 0, index + 1).set(index, value);
  36340. });
  36341. }
  36342. index += list._origin;
  36343. var newTail = list._tail;
  36344. var newRoot = list._root;
  36345. var didAlter = MakeRef();
  36346. if (index >= getTailOffset(list._capacity)) {
  36347. newTail = updateVNode(newTail, list.__ownerID, 0, index, value, didAlter);
  36348. } else {
  36349. newRoot = updateVNode(
  36350. newRoot,
  36351. list.__ownerID,
  36352. list._level,
  36353. index,
  36354. value,
  36355. didAlter
  36356. );
  36357. }
  36358. if (!didAlter.value) {
  36359. return list;
  36360. }
  36361. if (list.__ownerID) {
  36362. list._root = newRoot;
  36363. list._tail = newTail;
  36364. list.__hash = undefined;
  36365. list.__altered = true;
  36366. return list;
  36367. }
  36368. return makeList(list._origin, list._capacity, list._level, newRoot, newTail);
  36369. }
  36370. function updateVNode(node, ownerID, level, index, value, didAlter) {
  36371. var idx = (index >>> level) & MASK;
  36372. var nodeHas = node && idx < node.array.length;
  36373. if (!nodeHas && value === undefined) {
  36374. return node;
  36375. }
  36376. var newNode;
  36377. if (level > 0) {
  36378. var lowerNode = node && node.array[idx];
  36379. var newLowerNode = updateVNode(
  36380. lowerNode,
  36381. ownerID,
  36382. level - SHIFT,
  36383. index,
  36384. value,
  36385. didAlter
  36386. );
  36387. if (newLowerNode === lowerNode) {
  36388. return node;
  36389. }
  36390. newNode = editableVNode(node, ownerID);
  36391. newNode.array[idx] = newLowerNode;
  36392. return newNode;
  36393. }
  36394. if (nodeHas && node.array[idx] === value) {
  36395. return node;
  36396. }
  36397. if (didAlter) {
  36398. SetRef(didAlter);
  36399. }
  36400. newNode = editableVNode(node, ownerID);
  36401. if (value === undefined && idx === newNode.array.length - 1) {
  36402. newNode.array.pop();
  36403. } else {
  36404. newNode.array[idx] = value;
  36405. }
  36406. return newNode;
  36407. }
  36408. function editableVNode(node, ownerID) {
  36409. if (ownerID && node && ownerID === node.ownerID) {
  36410. return node;
  36411. }
  36412. return new VNode(node ? node.array.slice() : [], ownerID);
  36413. }
  36414. function listNodeFor(list, rawIndex) {
  36415. if (rawIndex >= getTailOffset(list._capacity)) {
  36416. return list._tail;
  36417. }
  36418. if (rawIndex < 1 << (list._level + SHIFT)) {
  36419. var node = list._root;
  36420. var level = list._level;
  36421. while (node && level > 0) {
  36422. node = node.array[(rawIndex >>> level) & MASK];
  36423. level -= SHIFT;
  36424. }
  36425. return node;
  36426. }
  36427. }
  36428. function setListBounds(list, begin, end) {
  36429. // Sanitize begin & end using this shorthand for ToInt32(argument)
  36430. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  36431. if (begin !== undefined) {
  36432. begin |= 0;
  36433. }
  36434. if (end !== undefined) {
  36435. end |= 0;
  36436. }
  36437. var owner = list.__ownerID || new OwnerID();
  36438. var oldOrigin = list._origin;
  36439. var oldCapacity = list._capacity;
  36440. var newOrigin = oldOrigin + begin;
  36441. var newCapacity =
  36442. end === undefined
  36443. ? oldCapacity
  36444. : end < 0
  36445. ? oldCapacity + end
  36446. : oldOrigin + end;
  36447. if (newOrigin === oldOrigin && newCapacity === oldCapacity) {
  36448. return list;
  36449. }
  36450. // If it's going to end after it starts, it's empty.
  36451. if (newOrigin >= newCapacity) {
  36452. return list.clear();
  36453. }
  36454. var newLevel = list._level;
  36455. var newRoot = list._root;
  36456. // New origin might need creating a higher root.
  36457. var offsetShift = 0;
  36458. while (newOrigin + offsetShift < 0) {
  36459. newRoot = new VNode(
  36460. newRoot && newRoot.array.length ? [undefined, newRoot] : [],
  36461. owner
  36462. );
  36463. newLevel += SHIFT;
  36464. offsetShift += 1 << newLevel;
  36465. }
  36466. if (offsetShift) {
  36467. newOrigin += offsetShift;
  36468. oldOrigin += offsetShift;
  36469. newCapacity += offsetShift;
  36470. oldCapacity += offsetShift;
  36471. }
  36472. var oldTailOffset = getTailOffset(oldCapacity);
  36473. var newTailOffset = getTailOffset(newCapacity);
  36474. // New size might need creating a higher root.
  36475. while (newTailOffset >= 1 << (newLevel + SHIFT)) {
  36476. newRoot = new VNode(
  36477. newRoot && newRoot.array.length ? [newRoot] : [],
  36478. owner
  36479. );
  36480. newLevel += SHIFT;
  36481. }
  36482. // Locate or create the new tail.
  36483. var oldTail = list._tail;
  36484. var newTail =
  36485. newTailOffset < oldTailOffset
  36486. ? listNodeFor(list, newCapacity - 1)
  36487. : newTailOffset > oldTailOffset
  36488. ? new VNode([], owner)
  36489. : oldTail;
  36490. // Merge Tail into tree.
  36491. if (
  36492. oldTail &&
  36493. newTailOffset > oldTailOffset &&
  36494. newOrigin < oldCapacity &&
  36495. oldTail.array.length
  36496. ) {
  36497. newRoot = editableVNode(newRoot, owner);
  36498. var node = newRoot;
  36499. for (var level = newLevel; level > SHIFT; level -= SHIFT) {
  36500. var idx = (oldTailOffset >>> level) & MASK;
  36501. node = node.array[idx] = editableVNode(node.array[idx], owner);
  36502. }
  36503. node.array[(oldTailOffset >>> SHIFT) & MASK] = oldTail;
  36504. }
  36505. // If the size has been reduced, there's a chance the tail needs to be trimmed.
  36506. if (newCapacity < oldCapacity) {
  36507. newTail = newTail && newTail.removeAfter(owner, 0, newCapacity);
  36508. }
  36509. // If the new origin is within the tail, then we do not need a root.
  36510. if (newOrigin >= newTailOffset) {
  36511. newOrigin -= newTailOffset;
  36512. newCapacity -= newTailOffset;
  36513. newLevel = SHIFT;
  36514. newRoot = null;
  36515. newTail = newTail && newTail.removeBefore(owner, 0, newOrigin);
  36516. // Otherwise, if the root has been trimmed, garbage collect.
  36517. } else if (newOrigin > oldOrigin || newTailOffset < oldTailOffset) {
  36518. offsetShift = 0;
  36519. // Identify the new top root node of the subtree of the old root.
  36520. while (newRoot) {
  36521. var beginIndex = (newOrigin >>> newLevel) & MASK;
  36522. if ((beginIndex !== newTailOffset >>> newLevel) & MASK) {
  36523. break;
  36524. }
  36525. if (beginIndex) {
  36526. offsetShift += (1 << newLevel) * beginIndex;
  36527. }
  36528. newLevel -= SHIFT;
  36529. newRoot = newRoot.array[beginIndex];
  36530. }
  36531. // Trim the new sides of the new root.
  36532. if (newRoot && newOrigin > oldOrigin) {
  36533. newRoot = newRoot.removeBefore(owner, newLevel, newOrigin - offsetShift);
  36534. }
  36535. if (newRoot && newTailOffset < oldTailOffset) {
  36536. newRoot = newRoot.removeAfter(
  36537. owner,
  36538. newLevel,
  36539. newTailOffset - offsetShift
  36540. );
  36541. }
  36542. if (offsetShift) {
  36543. newOrigin -= offsetShift;
  36544. newCapacity -= offsetShift;
  36545. }
  36546. }
  36547. if (list.__ownerID) {
  36548. list.size = newCapacity - newOrigin;
  36549. list._origin = newOrigin;
  36550. list._capacity = newCapacity;
  36551. list._level = newLevel;
  36552. list._root = newRoot;
  36553. list._tail = newTail;
  36554. list.__hash = undefined;
  36555. list.__altered = true;
  36556. return list;
  36557. }
  36558. return makeList(newOrigin, newCapacity, newLevel, newRoot, newTail);
  36559. }
  36560. function getTailOffset(size) {
  36561. return size < SIZE ? 0 : ((size - 1) >>> SHIFT) << SHIFT;
  36562. }
  36563. var OrderedMap = /*@__PURE__*/(function (Map$$1) {
  36564. function OrderedMap(value) {
  36565. return value === null || value === undefined
  36566. ? emptyOrderedMap()
  36567. : isOrderedMap(value)
  36568. ? value
  36569. : emptyOrderedMap().withMutations(function (map) {
  36570. var iter = KeyedCollection(value);
  36571. assertNotInfinite(iter.size);
  36572. iter.forEach(function (v, k) { return map.set(k, v); });
  36573. });
  36574. }
  36575. if ( Map$$1 ) OrderedMap.__proto__ = Map$$1;
  36576. OrderedMap.prototype = Object.create( Map$$1 && Map$$1.prototype );
  36577. OrderedMap.prototype.constructor = OrderedMap;
  36578. OrderedMap.of = function of (/*...values*/) {
  36579. return this(arguments);
  36580. };
  36581. OrderedMap.prototype.toString = function toString () {
  36582. return this.__toString('OrderedMap {', '}');
  36583. };
  36584. // @pragma Access
  36585. OrderedMap.prototype.get = function get (k, notSetValue) {
  36586. var index = this._map.get(k);
  36587. return index !== undefined ? this._list.get(index)[1] : notSetValue;
  36588. };
  36589. // @pragma Modification
  36590. OrderedMap.prototype.clear = function clear () {
  36591. if (this.size === 0) {
  36592. return this;
  36593. }
  36594. if (this.__ownerID) {
  36595. this.size = 0;
  36596. this._map.clear();
  36597. this._list.clear();
  36598. return this;
  36599. }
  36600. return emptyOrderedMap();
  36601. };
  36602. OrderedMap.prototype.set = function set (k, v) {
  36603. return updateOrderedMap(this, k, v);
  36604. };
  36605. OrderedMap.prototype.remove = function remove (k) {
  36606. return updateOrderedMap(this, k, NOT_SET);
  36607. };
  36608. OrderedMap.prototype.wasAltered = function wasAltered () {
  36609. return this._map.wasAltered() || this._list.wasAltered();
  36610. };
  36611. OrderedMap.prototype.__iterate = function __iterate (fn, reverse) {
  36612. var this$1 = this;
  36613. return this._list.__iterate(
  36614. function (entry) { return entry && fn(entry[1], entry[0], this$1); },
  36615. reverse
  36616. );
  36617. };
  36618. OrderedMap.prototype.__iterator = function __iterator (type, reverse) {
  36619. return this._list.fromEntrySeq().__iterator(type, reverse);
  36620. };
  36621. OrderedMap.prototype.__ensureOwner = function __ensureOwner (ownerID) {
  36622. if (ownerID === this.__ownerID) {
  36623. return this;
  36624. }
  36625. var newMap = this._map.__ensureOwner(ownerID);
  36626. var newList = this._list.__ensureOwner(ownerID);
  36627. if (!ownerID) {
  36628. if (this.size === 0) {
  36629. return emptyOrderedMap();
  36630. }
  36631. this.__ownerID = ownerID;
  36632. this._map = newMap;
  36633. this._list = newList;
  36634. return this;
  36635. }
  36636. return makeOrderedMap(newMap, newList, ownerID, this.__hash);
  36637. };
  36638. return OrderedMap;
  36639. }(Map));
  36640. OrderedMap.isOrderedMap = isOrderedMap;
  36641. OrderedMap.prototype[IS_ORDERED_SYMBOL] = true;
  36642. OrderedMap.prototype[DELETE] = OrderedMap.prototype.remove;
  36643. function makeOrderedMap(map, list, ownerID, hash) {
  36644. var omap = Object.create(OrderedMap.prototype);
  36645. omap.size = map ? map.size : 0;
  36646. omap._map = map;
  36647. omap._list = list;
  36648. omap.__ownerID = ownerID;
  36649. omap.__hash = hash;
  36650. return omap;
  36651. }
  36652. var EMPTY_ORDERED_MAP;
  36653. function emptyOrderedMap() {
  36654. return (
  36655. EMPTY_ORDERED_MAP ||
  36656. (EMPTY_ORDERED_MAP = makeOrderedMap(emptyMap(), emptyList()))
  36657. );
  36658. }
  36659. function updateOrderedMap(omap, k, v) {
  36660. var map = omap._map;
  36661. var list = omap._list;
  36662. var i = map.get(k);
  36663. var has = i !== undefined;
  36664. var newMap;
  36665. var newList;
  36666. if (v === NOT_SET) {
  36667. // removed
  36668. if (!has) {
  36669. return omap;
  36670. }
  36671. if (list.size >= SIZE && list.size >= map.size * 2) {
  36672. newList = list.filter(function (entry, idx) { return entry !== undefined && i !== idx; });
  36673. newMap = newList
  36674. .toKeyedSeq()
  36675. .map(function (entry) { return entry[0]; })
  36676. .flip()
  36677. .toMap();
  36678. if (omap.__ownerID) {
  36679. newMap.__ownerID = newList.__ownerID = omap.__ownerID;
  36680. }
  36681. } else {
  36682. newMap = map.remove(k);
  36683. newList = i === list.size - 1 ? list.pop() : list.set(i, undefined);
  36684. }
  36685. } else if (has) {
  36686. if (v === list.get(i)[1]) {
  36687. return omap;
  36688. }
  36689. newMap = map;
  36690. newList = list.set(i, [k, v]);
  36691. } else {
  36692. newMap = map.set(k, list.size);
  36693. newList = list.set(list.size, [k, v]);
  36694. }
  36695. if (omap.__ownerID) {
  36696. omap.size = newMap.size;
  36697. omap._map = newMap;
  36698. omap._list = newList;
  36699. omap.__hash = undefined;
  36700. return omap;
  36701. }
  36702. return makeOrderedMap(newMap, newList);
  36703. }
  36704. var IS_STACK_SYMBOL = '@@__IMMUTABLE_STACK__@@';
  36705. function isStack(maybeStack) {
  36706. return Boolean(maybeStack && maybeStack[IS_STACK_SYMBOL]);
  36707. }
  36708. var Stack = /*@__PURE__*/(function (IndexedCollection$$1) {
  36709. function Stack(value) {
  36710. return value === null || value === undefined
  36711. ? emptyStack()
  36712. : isStack(value)
  36713. ? value
  36714. : emptyStack().pushAll(value);
  36715. }
  36716. if ( IndexedCollection$$1 ) Stack.__proto__ = IndexedCollection$$1;
  36717. Stack.prototype = Object.create( IndexedCollection$$1 && IndexedCollection$$1.prototype );
  36718. Stack.prototype.constructor = Stack;
  36719. Stack.of = function of (/*...values*/) {
  36720. return this(arguments);
  36721. };
  36722. Stack.prototype.toString = function toString () {
  36723. return this.__toString('Stack [', ']');
  36724. };
  36725. // @pragma Access
  36726. Stack.prototype.get = function get (index, notSetValue) {
  36727. var head = this._head;
  36728. index = wrapIndex(this, index);
  36729. while (head && index--) {
  36730. head = head.next;
  36731. }
  36732. return head ? head.value : notSetValue;
  36733. };
  36734. Stack.prototype.peek = function peek () {
  36735. return this._head && this._head.value;
  36736. };
  36737. // @pragma Modification
  36738. Stack.prototype.push = function push (/*...values*/) {
  36739. var arguments$1 = arguments;
  36740. if (arguments.length === 0) {
  36741. return this;
  36742. }
  36743. var newSize = this.size + arguments.length;
  36744. var head = this._head;
  36745. for (var ii = arguments.length - 1; ii >= 0; ii--) {
  36746. head = {
  36747. value: arguments$1[ii],
  36748. next: head,
  36749. };
  36750. }
  36751. if (this.__ownerID) {
  36752. this.size = newSize;
  36753. this._head = head;
  36754. this.__hash = undefined;
  36755. this.__altered = true;
  36756. return this;
  36757. }
  36758. return makeStack(newSize, head);
  36759. };
  36760. Stack.prototype.pushAll = function pushAll (iter) {
  36761. iter = IndexedCollection$$1(iter);
  36762. if (iter.size === 0) {
  36763. return this;
  36764. }
  36765. if (this.size === 0 && isStack(iter)) {
  36766. return iter;
  36767. }
  36768. assertNotInfinite(iter.size);
  36769. var newSize = this.size;
  36770. var head = this._head;
  36771. iter.__iterate(function (value) {
  36772. newSize++;
  36773. head = {
  36774. value: value,
  36775. next: head,
  36776. };
  36777. }, /* reverse */ true);
  36778. if (this.__ownerID) {
  36779. this.size = newSize;
  36780. this._head = head;
  36781. this.__hash = undefined;
  36782. this.__altered = true;
  36783. return this;
  36784. }
  36785. return makeStack(newSize, head);
  36786. };
  36787. Stack.prototype.pop = function pop () {
  36788. return this.slice(1);
  36789. };
  36790. Stack.prototype.clear = function clear () {
  36791. if (this.size === 0) {
  36792. return this;
  36793. }
  36794. if (this.__ownerID) {
  36795. this.size = 0;
  36796. this._head = undefined;
  36797. this.__hash = undefined;
  36798. this.__altered = true;
  36799. return this;
  36800. }
  36801. return emptyStack();
  36802. };
  36803. Stack.prototype.slice = function slice (begin, end) {
  36804. if (wholeSlice(begin, end, this.size)) {
  36805. return this;
  36806. }
  36807. var resolvedBegin = resolveBegin(begin, this.size);
  36808. var resolvedEnd = resolveEnd(end, this.size);
  36809. if (resolvedEnd !== this.size) {
  36810. // super.slice(begin, end);
  36811. return IndexedCollection$$1.prototype.slice.call(this, begin, end);
  36812. }
  36813. var newSize = this.size - resolvedBegin;
  36814. var head = this._head;
  36815. while (resolvedBegin--) {
  36816. head = head.next;
  36817. }
  36818. if (this.__ownerID) {
  36819. this.size = newSize;
  36820. this._head = head;
  36821. this.__hash = undefined;
  36822. this.__altered = true;
  36823. return this;
  36824. }
  36825. return makeStack(newSize, head);
  36826. };
  36827. // @pragma Mutability
  36828. Stack.prototype.__ensureOwner = function __ensureOwner (ownerID) {
  36829. if (ownerID === this.__ownerID) {
  36830. return this;
  36831. }
  36832. if (!ownerID) {
  36833. if (this.size === 0) {
  36834. return emptyStack();
  36835. }
  36836. this.__ownerID = ownerID;
  36837. this.__altered = false;
  36838. return this;
  36839. }
  36840. return makeStack(this.size, this._head, ownerID, this.__hash);
  36841. };
  36842. // @pragma Iteration
  36843. Stack.prototype.__iterate = function __iterate (fn, reverse) {
  36844. var this$1 = this;
  36845. if (reverse) {
  36846. return new ArraySeq(this.toArray()).__iterate(
  36847. function (v, k) { return fn(v, k, this$1); },
  36848. reverse
  36849. );
  36850. }
  36851. var iterations = 0;
  36852. var node = this._head;
  36853. while (node) {
  36854. if (fn(node.value, iterations++, this) === false) {
  36855. break;
  36856. }
  36857. node = node.next;
  36858. }
  36859. return iterations;
  36860. };
  36861. Stack.prototype.__iterator = function __iterator (type, reverse) {
  36862. if (reverse) {
  36863. return new ArraySeq(this.toArray()).__iterator(type, reverse);
  36864. }
  36865. var iterations = 0;
  36866. var node = this._head;
  36867. return new Iterator(function () {
  36868. if (node) {
  36869. var value = node.value;
  36870. node = node.next;
  36871. return iteratorValue(type, iterations++, value);
  36872. }
  36873. return iteratorDone();
  36874. });
  36875. };
  36876. return Stack;
  36877. }(IndexedCollection));
  36878. Stack.isStack = isStack;
  36879. var StackPrototype = Stack.prototype;
  36880. StackPrototype[IS_STACK_SYMBOL] = true;
  36881. StackPrototype.shift = StackPrototype.pop;
  36882. StackPrototype.unshift = StackPrototype.push;
  36883. StackPrototype.unshiftAll = StackPrototype.pushAll;
  36884. StackPrototype.withMutations = withMutations;
  36885. StackPrototype.wasAltered = wasAltered;
  36886. StackPrototype.asImmutable = asImmutable;
  36887. StackPrototype['@@transducer/init'] = StackPrototype.asMutable = asMutable;
  36888. StackPrototype['@@transducer/step'] = function(result, arr) {
  36889. return result.unshift(arr);
  36890. };
  36891. StackPrototype['@@transducer/result'] = function(obj) {
  36892. return obj.asImmutable();
  36893. };
  36894. function makeStack(size, head, ownerID, hash) {
  36895. var map = Object.create(StackPrototype);
  36896. map.size = size;
  36897. map._head = head;
  36898. map.__ownerID = ownerID;
  36899. map.__hash = hash;
  36900. map.__altered = false;
  36901. return map;
  36902. }
  36903. var EMPTY_STACK;
  36904. function emptyStack() {
  36905. return EMPTY_STACK || (EMPTY_STACK = makeStack(0));
  36906. }
  36907. var IS_SET_SYMBOL = '@@__IMMUTABLE_SET__@@';
  36908. function isSet(maybeSet) {
  36909. return Boolean(maybeSet && maybeSet[IS_SET_SYMBOL]);
  36910. }
  36911. function isOrderedSet(maybeOrderedSet) {
  36912. return isSet(maybeOrderedSet) && isOrdered(maybeOrderedSet);
  36913. }
  36914. function deepEqual(a, b) {
  36915. if (a === b) {
  36916. return true;
  36917. }
  36918. if (
  36919. !isCollection(b) ||
  36920. (a.size !== undefined && b.size !== undefined && a.size !== b.size) ||
  36921. (a.__hash !== undefined &&
  36922. b.__hash !== undefined &&
  36923. a.__hash !== b.__hash) ||
  36924. isKeyed(a) !== isKeyed(b) ||
  36925. isIndexed(a) !== isIndexed(b) ||
  36926. isOrdered(a) !== isOrdered(b)
  36927. ) {
  36928. return false;
  36929. }
  36930. if (a.size === 0 && b.size === 0) {
  36931. return true;
  36932. }
  36933. var notAssociative = !isAssociative(a);
  36934. if (isOrdered(a)) {
  36935. var entries = a.entries();
  36936. return (
  36937. b.every(function (v, k) {
  36938. var entry = entries.next().value;
  36939. return entry && is(entry[1], v) && (notAssociative || is(entry[0], k));
  36940. }) && entries.next().done
  36941. );
  36942. }
  36943. var flipped = false;
  36944. if (a.size === undefined) {
  36945. if (b.size === undefined) {
  36946. if (typeof a.cacheResult === 'function') {
  36947. a.cacheResult();
  36948. }
  36949. } else {
  36950. flipped = true;
  36951. var _ = a;
  36952. a = b;
  36953. b = _;
  36954. }
  36955. }
  36956. var allEqual = true;
  36957. var bSize = b.__iterate(function (v, k) {
  36958. if (
  36959. notAssociative
  36960. ? !a.has(v)
  36961. : flipped
  36962. ? !is(v, a.get(k, NOT_SET))
  36963. : !is(a.get(k, NOT_SET), v)
  36964. ) {
  36965. allEqual = false;
  36966. return false;
  36967. }
  36968. });
  36969. return allEqual && a.size === bSize;
  36970. }
  36971. /**
  36972. * Contributes additional methods to a constructor
  36973. */
  36974. function mixin(ctor, methods) {
  36975. var keyCopier = function (key) {
  36976. ctor.prototype[key] = methods[key];
  36977. };
  36978. Object.keys(methods).forEach(keyCopier);
  36979. Object.getOwnPropertySymbols &&
  36980. Object.getOwnPropertySymbols(methods).forEach(keyCopier);
  36981. return ctor;
  36982. }
  36983. function toJS(value) {
  36984. if (!value || typeof value !== 'object') {
  36985. return value;
  36986. }
  36987. if (!isCollection(value)) {
  36988. if (!isDataStructure(value)) {
  36989. return value;
  36990. }
  36991. value = Seq(value);
  36992. }
  36993. if (isKeyed(value)) {
  36994. var result$1 = {};
  36995. value.__iterate(function (v, k) {
  36996. result$1[k] = toJS(v);
  36997. });
  36998. return result$1;
  36999. }
  37000. var result = [];
  37001. value.__iterate(function (v) {
  37002. result.push(toJS(v));
  37003. });
  37004. return result;
  37005. }
  37006. var Set = /*@__PURE__*/(function (SetCollection$$1) {
  37007. function Set(value) {
  37008. return value === null || value === undefined
  37009. ? emptySet()
  37010. : isSet(value) && !isOrdered(value)
  37011. ? value
  37012. : emptySet().withMutations(function (set) {
  37013. var iter = SetCollection$$1(value);
  37014. assertNotInfinite(iter.size);
  37015. iter.forEach(function (v) { return set.add(v); });
  37016. });
  37017. }
  37018. if ( SetCollection$$1 ) Set.__proto__ = SetCollection$$1;
  37019. Set.prototype = Object.create( SetCollection$$1 && SetCollection$$1.prototype );
  37020. Set.prototype.constructor = Set;
  37021. Set.of = function of (/*...values*/) {
  37022. return this(arguments);
  37023. };
  37024. Set.fromKeys = function fromKeys (value) {
  37025. return this(KeyedCollection(value).keySeq());
  37026. };
  37027. Set.intersect = function intersect (sets) {
  37028. sets = Collection(sets).toArray();
  37029. return sets.length
  37030. ? SetPrototype.intersect.apply(Set(sets.pop()), sets)
  37031. : emptySet();
  37032. };
  37033. Set.union = function union (sets) {
  37034. sets = Collection(sets).toArray();
  37035. return sets.length
  37036. ? SetPrototype.union.apply(Set(sets.pop()), sets)
  37037. : emptySet();
  37038. };
  37039. Set.prototype.toString = function toString () {
  37040. return this.__toString('Set {', '}');
  37041. };
  37042. // @pragma Access
  37043. Set.prototype.has = function has (value) {
  37044. return this._map.has(value);
  37045. };
  37046. // @pragma Modification
  37047. Set.prototype.add = function add (value) {
  37048. return updateSet(this, this._map.set(value, value));
  37049. };
  37050. Set.prototype.remove = function remove (value) {
  37051. return updateSet(this, this._map.remove(value));
  37052. };
  37053. Set.prototype.clear = function clear () {
  37054. return updateSet(this, this._map.clear());
  37055. };
  37056. // @pragma Composition
  37057. Set.prototype.map = function map (mapper, context) {
  37058. var this$1 = this;
  37059. var removes = [];
  37060. var adds = [];
  37061. this.forEach(function (value) {
  37062. var mapped = mapper.call(context, value, value, this$1);
  37063. if (mapped !== value) {
  37064. removes.push(value);
  37065. adds.push(mapped);
  37066. }
  37067. });
  37068. return this.withMutations(function (set) {
  37069. removes.forEach(function (value) { return set.remove(value); });
  37070. adds.forEach(function (value) { return set.add(value); });
  37071. });
  37072. };
  37073. Set.prototype.union = function union () {
  37074. var iters = [], len = arguments.length;
  37075. while ( len-- ) iters[ len ] = arguments[ len ];
  37076. iters = iters.filter(function (x) { return x.size !== 0; });
  37077. if (iters.length === 0) {
  37078. return this;
  37079. }
  37080. if (this.size === 0 && !this.__ownerID && iters.length === 1) {
  37081. return this.constructor(iters[0]);
  37082. }
  37083. return this.withMutations(function (set) {
  37084. for (var ii = 0; ii < iters.length; ii++) {
  37085. SetCollection$$1(iters[ii]).forEach(function (value) { return set.add(value); });
  37086. }
  37087. });
  37088. };
  37089. Set.prototype.intersect = function intersect () {
  37090. var iters = [], len = arguments.length;
  37091. while ( len-- ) iters[ len ] = arguments[ len ];
  37092. if (iters.length === 0) {
  37093. return this;
  37094. }
  37095. iters = iters.map(function (iter) { return SetCollection$$1(iter); });
  37096. var toRemove = [];
  37097. this.forEach(function (value) {
  37098. if (!iters.every(function (iter) { return iter.includes(value); })) {
  37099. toRemove.push(value);
  37100. }
  37101. });
  37102. return this.withMutations(function (set) {
  37103. toRemove.forEach(function (value) {
  37104. set.remove(value);
  37105. });
  37106. });
  37107. };
  37108. Set.prototype.subtract = function subtract () {
  37109. var iters = [], len = arguments.length;
  37110. while ( len-- ) iters[ len ] = arguments[ len ];
  37111. if (iters.length === 0) {
  37112. return this;
  37113. }
  37114. iters = iters.map(function (iter) { return SetCollection$$1(iter); });
  37115. var toRemove = [];
  37116. this.forEach(function (value) {
  37117. if (iters.some(function (iter) { return iter.includes(value); })) {
  37118. toRemove.push(value);
  37119. }
  37120. });
  37121. return this.withMutations(function (set) {
  37122. toRemove.forEach(function (value) {
  37123. set.remove(value);
  37124. });
  37125. });
  37126. };
  37127. Set.prototype.sort = function sort (comparator) {
  37128. // Late binding
  37129. return OrderedSet(sortFactory(this, comparator));
  37130. };
  37131. Set.prototype.sortBy = function sortBy (mapper, comparator) {
  37132. // Late binding
  37133. return OrderedSet(sortFactory(this, comparator, mapper));
  37134. };
  37135. Set.prototype.wasAltered = function wasAltered () {
  37136. return this._map.wasAltered();
  37137. };
  37138. Set.prototype.__iterate = function __iterate (fn, reverse) {
  37139. var this$1 = this;
  37140. return this._map.__iterate(function (k) { return fn(k, k, this$1); }, reverse);
  37141. };
  37142. Set.prototype.__iterator = function __iterator (type, reverse) {
  37143. return this._map.__iterator(type, reverse);
  37144. };
  37145. Set.prototype.__ensureOwner = function __ensureOwner (ownerID) {
  37146. if (ownerID === this.__ownerID) {
  37147. return this;
  37148. }
  37149. var newMap = this._map.__ensureOwner(ownerID);
  37150. if (!ownerID) {
  37151. if (this.size === 0) {
  37152. return this.__empty();
  37153. }
  37154. this.__ownerID = ownerID;
  37155. this._map = newMap;
  37156. return this;
  37157. }
  37158. return this.__make(newMap, ownerID);
  37159. };
  37160. return Set;
  37161. }(SetCollection));
  37162. Set.isSet = isSet;
  37163. var SetPrototype = Set.prototype;
  37164. SetPrototype[IS_SET_SYMBOL] = true;
  37165. SetPrototype[DELETE] = SetPrototype.remove;
  37166. SetPrototype.merge = SetPrototype.concat = SetPrototype.union;
  37167. SetPrototype.withMutations = withMutations;
  37168. SetPrototype.asImmutable = asImmutable;
  37169. SetPrototype['@@transducer/init'] = SetPrototype.asMutable = asMutable;
  37170. SetPrototype['@@transducer/step'] = function(result, arr) {
  37171. return result.add(arr);
  37172. };
  37173. SetPrototype['@@transducer/result'] = function(obj) {
  37174. return obj.asImmutable();
  37175. };
  37176. SetPrototype.__empty = emptySet;
  37177. SetPrototype.__make = makeSet;
  37178. function updateSet(set, newMap) {
  37179. if (set.__ownerID) {
  37180. set.size = newMap.size;
  37181. set._map = newMap;
  37182. return set;
  37183. }
  37184. return newMap === set._map
  37185. ? set
  37186. : newMap.size === 0
  37187. ? set.__empty()
  37188. : set.__make(newMap);
  37189. }
  37190. function makeSet(map, ownerID) {
  37191. var set = Object.create(SetPrototype);
  37192. set.size = map ? map.size : 0;
  37193. set._map = map;
  37194. set.__ownerID = ownerID;
  37195. return set;
  37196. }
  37197. var EMPTY_SET;
  37198. function emptySet() {
  37199. return EMPTY_SET || (EMPTY_SET = makeSet(emptyMap()));
  37200. }
  37201. /**
  37202. * Returns a lazy seq of nums from start (inclusive) to end
  37203. * (exclusive), by step, where start defaults to 0, step to 1, and end to
  37204. * infinity. When start is equal to end, returns empty list.
  37205. */
  37206. var Range = /*@__PURE__*/(function (IndexedSeq$$1) {
  37207. function Range(start, end, step) {
  37208. if (!(this instanceof Range)) {
  37209. return new Range(start, end, step);
  37210. }
  37211. invariant(step !== 0, 'Cannot step a Range by 0');
  37212. start = start || 0;
  37213. if (end === undefined) {
  37214. end = Infinity;
  37215. }
  37216. step = step === undefined ? 1 : Math.abs(step);
  37217. if (end < start) {
  37218. step = -step;
  37219. }
  37220. this._start = start;
  37221. this._end = end;
  37222. this._step = step;
  37223. this.size = Math.max(0, Math.ceil((end - start) / step - 1) + 1);
  37224. if (this.size === 0) {
  37225. if (EMPTY_RANGE) {
  37226. return EMPTY_RANGE;
  37227. }
  37228. EMPTY_RANGE = this;
  37229. }
  37230. }
  37231. if ( IndexedSeq$$1 ) Range.__proto__ = IndexedSeq$$1;
  37232. Range.prototype = Object.create( IndexedSeq$$1 && IndexedSeq$$1.prototype );
  37233. Range.prototype.constructor = Range;
  37234. Range.prototype.toString = function toString () {
  37235. if (this.size === 0) {
  37236. return 'Range []';
  37237. }
  37238. return (
  37239. 'Range [ ' +
  37240. this._start +
  37241. '...' +
  37242. this._end +
  37243. (this._step !== 1 ? ' by ' + this._step : '') +
  37244. ' ]'
  37245. );
  37246. };
  37247. Range.prototype.get = function get (index, notSetValue) {
  37248. return this.has(index)
  37249. ? this._start + wrapIndex(this, index) * this._step
  37250. : notSetValue;
  37251. };
  37252. Range.prototype.includes = function includes (searchValue) {
  37253. var possibleIndex = (searchValue - this._start) / this._step;
  37254. return (
  37255. possibleIndex >= 0 &&
  37256. possibleIndex < this.size &&
  37257. possibleIndex === Math.floor(possibleIndex)
  37258. );
  37259. };
  37260. Range.prototype.slice = function slice (begin, end) {
  37261. if (wholeSlice(begin, end, this.size)) {
  37262. return this;
  37263. }
  37264. begin = resolveBegin(begin, this.size);
  37265. end = resolveEnd(end, this.size);
  37266. if (end <= begin) {
  37267. return new Range(0, 0);
  37268. }
  37269. return new Range(
  37270. this.get(begin, this._end),
  37271. this.get(end, this._end),
  37272. this._step
  37273. );
  37274. };
  37275. Range.prototype.indexOf = function indexOf (searchValue) {
  37276. var offsetValue = searchValue - this._start;
  37277. if (offsetValue % this._step === 0) {
  37278. var index = offsetValue / this._step;
  37279. if (index >= 0 && index < this.size) {
  37280. return index;
  37281. }
  37282. }
  37283. return -1;
  37284. };
  37285. Range.prototype.lastIndexOf = function lastIndexOf (searchValue) {
  37286. return this.indexOf(searchValue);
  37287. };
  37288. Range.prototype.__iterate = function __iterate (fn, reverse) {
  37289. var size = this.size;
  37290. var step = this._step;
  37291. var value = reverse ? this._start + (size - 1) * step : this._start;
  37292. var i = 0;
  37293. while (i !== size) {
  37294. if (fn(value, reverse ? size - ++i : i++, this) === false) {
  37295. break;
  37296. }
  37297. value += reverse ? -step : step;
  37298. }
  37299. return i;
  37300. };
  37301. Range.prototype.__iterator = function __iterator (type, reverse) {
  37302. var size = this.size;
  37303. var step = this._step;
  37304. var value = reverse ? this._start + (size - 1) * step : this._start;
  37305. var i = 0;
  37306. return new Iterator(function () {
  37307. if (i === size) {
  37308. return iteratorDone();
  37309. }
  37310. var v = value;
  37311. value += reverse ? -step : step;
  37312. return iteratorValue(type, reverse ? size - ++i : i++, v);
  37313. });
  37314. };
  37315. Range.prototype.equals = function equals (other) {
  37316. return other instanceof Range
  37317. ? this._start === other._start &&
  37318. this._end === other._end &&
  37319. this._step === other._step
  37320. : deepEqual(this, other);
  37321. };
  37322. return Range;
  37323. }(IndexedSeq));
  37324. var EMPTY_RANGE;
  37325. function getIn(collection, searchKeyPath, notSetValue) {
  37326. var keyPath = coerceKeyPath(searchKeyPath);
  37327. var i = 0;
  37328. while (i !== keyPath.length) {
  37329. collection = get(collection, keyPath[i++], NOT_SET);
  37330. if (collection === NOT_SET) {
  37331. return notSetValue;
  37332. }
  37333. }
  37334. return collection;
  37335. }
  37336. function getIn$1(searchKeyPath, notSetValue) {
  37337. return getIn(this, searchKeyPath, notSetValue);
  37338. }
  37339. function hasIn(collection, keyPath) {
  37340. return getIn(collection, keyPath, NOT_SET) !== NOT_SET;
  37341. }
  37342. function hasIn$1(searchKeyPath) {
  37343. return hasIn(this, searchKeyPath);
  37344. }
  37345. function toObject() {
  37346. assertNotInfinite(this.size);
  37347. var object = {};
  37348. this.__iterate(function (v, k) {
  37349. object[k] = v;
  37350. });
  37351. return object;
  37352. }
  37353. // Note: all of these methods are deprecated.
  37354. Collection.isIterable = isCollection;
  37355. Collection.isKeyed = isKeyed;
  37356. Collection.isIndexed = isIndexed;
  37357. Collection.isAssociative = isAssociative;
  37358. Collection.isOrdered = isOrdered;
  37359. Collection.Iterator = Iterator;
  37360. mixin(Collection, {
  37361. // ### Conversion to other types
  37362. toArray: function toArray() {
  37363. assertNotInfinite(this.size);
  37364. var array = new Array(this.size || 0);
  37365. var useTuples = isKeyed(this);
  37366. var i = 0;
  37367. this.__iterate(function (v, k) {
  37368. // Keyed collections produce an array of tuples.
  37369. array[i++] = useTuples ? [k, v] : v;
  37370. });
  37371. return array;
  37372. },
  37373. toIndexedSeq: function toIndexedSeq() {
  37374. return new ToIndexedSequence(this);
  37375. },
  37376. toJS: function toJS$1() {
  37377. return toJS(this);
  37378. },
  37379. toKeyedSeq: function toKeyedSeq() {
  37380. return new ToKeyedSequence(this, true);
  37381. },
  37382. toMap: function toMap() {
  37383. // Use Late Binding here to solve the circular dependency.
  37384. return Map(this.toKeyedSeq());
  37385. },
  37386. toObject: toObject,
  37387. toOrderedMap: function toOrderedMap() {
  37388. // Use Late Binding here to solve the circular dependency.
  37389. return OrderedMap(this.toKeyedSeq());
  37390. },
  37391. toOrderedSet: function toOrderedSet() {
  37392. // Use Late Binding here to solve the circular dependency.
  37393. return OrderedSet(isKeyed(this) ? this.valueSeq() : this);
  37394. },
  37395. toSet: function toSet() {
  37396. // Use Late Binding here to solve the circular dependency.
  37397. return Set(isKeyed(this) ? this.valueSeq() : this);
  37398. },
  37399. toSetSeq: function toSetSeq() {
  37400. return new ToSetSequence(this);
  37401. },
  37402. toSeq: function toSeq() {
  37403. return isIndexed(this)
  37404. ? this.toIndexedSeq()
  37405. : isKeyed(this)
  37406. ? this.toKeyedSeq()
  37407. : this.toSetSeq();
  37408. },
  37409. toStack: function toStack() {
  37410. // Use Late Binding here to solve the circular dependency.
  37411. return Stack(isKeyed(this) ? this.valueSeq() : this);
  37412. },
  37413. toList: function toList() {
  37414. // Use Late Binding here to solve the circular dependency.
  37415. return List(isKeyed(this) ? this.valueSeq() : this);
  37416. },
  37417. // ### Common JavaScript methods and properties
  37418. toString: function toString() {
  37419. return '[Collection]';
  37420. },
  37421. __toString: function __toString(head, tail) {
  37422. if (this.size === 0) {
  37423. return head + tail;
  37424. }
  37425. return (
  37426. head +
  37427. ' ' +
  37428. this.toSeq()
  37429. .map(this.__toStringMapper)
  37430. .join(', ') +
  37431. ' ' +
  37432. tail
  37433. );
  37434. },
  37435. // ### ES6 Collection methods (ES6 Array and Map)
  37436. concat: function concat() {
  37437. var values = [], len = arguments.length;
  37438. while ( len-- ) values[ len ] = arguments[ len ];
  37439. return reify(this, concatFactory(this, values));
  37440. },
  37441. includes: function includes(searchValue) {
  37442. return this.some(function (value) { return is(value, searchValue); });
  37443. },
  37444. entries: function entries() {
  37445. return this.__iterator(ITERATE_ENTRIES);
  37446. },
  37447. every: function every(predicate, context) {
  37448. assertNotInfinite(this.size);
  37449. var returnValue = true;
  37450. this.__iterate(function (v, k, c) {
  37451. if (!predicate.call(context, v, k, c)) {
  37452. returnValue = false;
  37453. return false;
  37454. }
  37455. });
  37456. return returnValue;
  37457. },
  37458. filter: function filter(predicate, context) {
  37459. return reify(this, filterFactory(this, predicate, context, true));
  37460. },
  37461. find: function find(predicate, context, notSetValue) {
  37462. var entry = this.findEntry(predicate, context);
  37463. return entry ? entry[1] : notSetValue;
  37464. },
  37465. forEach: function forEach(sideEffect, context) {
  37466. assertNotInfinite(this.size);
  37467. return this.__iterate(context ? sideEffect.bind(context) : sideEffect);
  37468. },
  37469. join: function join(separator) {
  37470. assertNotInfinite(this.size);
  37471. separator = separator !== undefined ? '' + separator : ',';
  37472. var joined = '';
  37473. var isFirst = true;
  37474. this.__iterate(function (v) {
  37475. isFirst ? (isFirst = false) : (joined += separator);
  37476. joined += v !== null && v !== undefined ? v.toString() : '';
  37477. });
  37478. return joined;
  37479. },
  37480. keys: function keys() {
  37481. return this.__iterator(ITERATE_KEYS);
  37482. },
  37483. map: function map(mapper, context) {
  37484. return reify(this, mapFactory(this, mapper, context));
  37485. },
  37486. reduce: function reduce$1(reducer, initialReduction, context) {
  37487. return reduce(
  37488. this,
  37489. reducer,
  37490. initialReduction,
  37491. context,
  37492. arguments.length < 2,
  37493. false
  37494. );
  37495. },
  37496. reduceRight: function reduceRight(reducer, initialReduction, context) {
  37497. return reduce(
  37498. this,
  37499. reducer,
  37500. initialReduction,
  37501. context,
  37502. arguments.length < 2,
  37503. true
  37504. );
  37505. },
  37506. reverse: function reverse() {
  37507. return reify(this, reverseFactory(this, true));
  37508. },
  37509. slice: function slice(begin, end) {
  37510. return reify(this, sliceFactory(this, begin, end, true));
  37511. },
  37512. some: function some(predicate, context) {
  37513. return !this.every(not(predicate), context);
  37514. },
  37515. sort: function sort(comparator) {
  37516. return reify(this, sortFactory(this, comparator));
  37517. },
  37518. values: function values() {
  37519. return this.__iterator(ITERATE_VALUES);
  37520. },
  37521. // ### More sequential methods
  37522. butLast: function butLast() {
  37523. return this.slice(0, -1);
  37524. },
  37525. isEmpty: function isEmpty() {
  37526. return this.size !== undefined ? this.size === 0 : !this.some(function () { return true; });
  37527. },
  37528. count: function count(predicate, context) {
  37529. return ensureSize(
  37530. predicate ? this.toSeq().filter(predicate, context) : this
  37531. );
  37532. },
  37533. countBy: function countBy(grouper, context) {
  37534. return countByFactory(this, grouper, context);
  37535. },
  37536. equals: function equals(other) {
  37537. return deepEqual(this, other);
  37538. },
  37539. entrySeq: function entrySeq() {
  37540. var collection = this;
  37541. if (collection._cache) {
  37542. // We cache as an entries array, so we can just return the cache!
  37543. return new ArraySeq(collection._cache);
  37544. }
  37545. var entriesSequence = collection
  37546. .toSeq()
  37547. .map(entryMapper)
  37548. .toIndexedSeq();
  37549. entriesSequence.fromEntrySeq = function () { return collection.toSeq(); };
  37550. return entriesSequence;
  37551. },
  37552. filterNot: function filterNot(predicate, context) {
  37553. return this.filter(not(predicate), context);
  37554. },
  37555. findEntry: function findEntry(predicate, context, notSetValue) {
  37556. var found = notSetValue;
  37557. this.__iterate(function (v, k, c) {
  37558. if (predicate.call(context, v, k, c)) {
  37559. found = [k, v];
  37560. return false;
  37561. }
  37562. });
  37563. return found;
  37564. },
  37565. findKey: function findKey(predicate, context) {
  37566. var entry = this.findEntry(predicate, context);
  37567. return entry && entry[0];
  37568. },
  37569. findLast: function findLast(predicate, context, notSetValue) {
  37570. return this.toKeyedSeq()
  37571. .reverse()
  37572. .find(predicate, context, notSetValue);
  37573. },
  37574. findLastEntry: function findLastEntry(predicate, context, notSetValue) {
  37575. return this.toKeyedSeq()
  37576. .reverse()
  37577. .findEntry(predicate, context, notSetValue);
  37578. },
  37579. findLastKey: function findLastKey(predicate, context) {
  37580. return this.toKeyedSeq()
  37581. .reverse()
  37582. .findKey(predicate, context);
  37583. },
  37584. first: function first(notSetValue) {
  37585. return this.find(returnTrue, null, notSetValue);
  37586. },
  37587. flatMap: function flatMap(mapper, context) {
  37588. return reify(this, flatMapFactory(this, mapper, context));
  37589. },
  37590. flatten: function flatten(depth) {
  37591. return reify(this, flattenFactory(this, depth, true));
  37592. },
  37593. fromEntrySeq: function fromEntrySeq() {
  37594. return new FromEntriesSequence(this);
  37595. },
  37596. get: function get(searchKey, notSetValue) {
  37597. return this.find(function (_, key) { return is(key, searchKey); }, undefined, notSetValue);
  37598. },
  37599. getIn: getIn$1,
  37600. groupBy: function groupBy(grouper, context) {
  37601. return groupByFactory(this, grouper, context);
  37602. },
  37603. has: function has(searchKey) {
  37604. return this.get(searchKey, NOT_SET) !== NOT_SET;
  37605. },
  37606. hasIn: hasIn$1,
  37607. isSubset: function isSubset(iter) {
  37608. iter = typeof iter.includes === 'function' ? iter : Collection(iter);
  37609. return this.every(function (value) { return iter.includes(value); });
  37610. },
  37611. isSuperset: function isSuperset(iter) {
  37612. iter = typeof iter.isSubset === 'function' ? iter : Collection(iter);
  37613. return iter.isSubset(this);
  37614. },
  37615. keyOf: function keyOf(searchValue) {
  37616. return this.findKey(function (value) { return is(value, searchValue); });
  37617. },
  37618. keySeq: function keySeq() {
  37619. return this.toSeq()
  37620. .map(keyMapper)
  37621. .toIndexedSeq();
  37622. },
  37623. last: function last(notSetValue) {
  37624. return this.toSeq()
  37625. .reverse()
  37626. .first(notSetValue);
  37627. },
  37628. lastKeyOf: function lastKeyOf(searchValue) {
  37629. return this.toKeyedSeq()
  37630. .reverse()
  37631. .keyOf(searchValue);
  37632. },
  37633. max: function max(comparator) {
  37634. return maxFactory(this, comparator);
  37635. },
  37636. maxBy: function maxBy(mapper, comparator) {
  37637. return maxFactory(this, comparator, mapper);
  37638. },
  37639. min: function min(comparator) {
  37640. return maxFactory(
  37641. this,
  37642. comparator ? neg(comparator) : defaultNegComparator
  37643. );
  37644. },
  37645. minBy: function minBy(mapper, comparator) {
  37646. return maxFactory(
  37647. this,
  37648. comparator ? neg(comparator) : defaultNegComparator,
  37649. mapper
  37650. );
  37651. },
  37652. rest: function rest() {
  37653. return this.slice(1);
  37654. },
  37655. skip: function skip(amount) {
  37656. return amount === 0 ? this : this.slice(Math.max(0, amount));
  37657. },
  37658. skipLast: function skipLast(amount) {
  37659. return amount === 0 ? this : this.slice(0, -Math.max(0, amount));
  37660. },
  37661. skipWhile: function skipWhile(predicate, context) {
  37662. return reify(this, skipWhileFactory(this, predicate, context, true));
  37663. },
  37664. skipUntil: function skipUntil(predicate, context) {
  37665. return this.skipWhile(not(predicate), context);
  37666. },
  37667. sortBy: function sortBy(mapper, comparator) {
  37668. return reify(this, sortFactory(this, comparator, mapper));
  37669. },
  37670. take: function take(amount) {
  37671. return this.slice(0, Math.max(0, amount));
  37672. },
  37673. takeLast: function takeLast(amount) {
  37674. return this.slice(-Math.max(0, amount));
  37675. },
  37676. takeWhile: function takeWhile(predicate, context) {
  37677. return reify(this, takeWhileFactory(this, predicate, context));
  37678. },
  37679. takeUntil: function takeUntil(predicate, context) {
  37680. return this.takeWhile(not(predicate), context);
  37681. },
  37682. update: function update(fn) {
  37683. return fn(this);
  37684. },
  37685. valueSeq: function valueSeq() {
  37686. return this.toIndexedSeq();
  37687. },
  37688. // ### Hashable Object
  37689. hashCode: function hashCode() {
  37690. return this.__hash || (this.__hash = hashCollection(this));
  37691. },
  37692. // ### Internal
  37693. // abstract __iterate(fn, reverse)
  37694. // abstract __iterator(type, reverse)
  37695. });
  37696. var CollectionPrototype = Collection.prototype;
  37697. CollectionPrototype[IS_COLLECTION_SYMBOL] = true;
  37698. CollectionPrototype[ITERATOR_SYMBOL] = CollectionPrototype.values;
  37699. CollectionPrototype.toJSON = CollectionPrototype.toArray;
  37700. CollectionPrototype.__toStringMapper = quoteString;
  37701. CollectionPrototype.inspect = CollectionPrototype.toSource = function() {
  37702. return this.toString();
  37703. };
  37704. CollectionPrototype.chain = CollectionPrototype.flatMap;
  37705. CollectionPrototype.contains = CollectionPrototype.includes;
  37706. mixin(KeyedCollection, {
  37707. // ### More sequential methods
  37708. flip: function flip() {
  37709. return reify(this, flipFactory(this));
  37710. },
  37711. mapEntries: function mapEntries(mapper, context) {
  37712. var this$1 = this;
  37713. var iterations = 0;
  37714. return reify(
  37715. this,
  37716. this.toSeq()
  37717. .map(function (v, k) { return mapper.call(context, [k, v], iterations++, this$1); })
  37718. .fromEntrySeq()
  37719. );
  37720. },
  37721. mapKeys: function mapKeys(mapper, context) {
  37722. var this$1 = this;
  37723. return reify(
  37724. this,
  37725. this.toSeq()
  37726. .flip()
  37727. .map(function (k, v) { return mapper.call(context, k, v, this$1); })
  37728. .flip()
  37729. );
  37730. },
  37731. });
  37732. var KeyedCollectionPrototype = KeyedCollection.prototype;
  37733. KeyedCollectionPrototype[IS_KEYED_SYMBOL] = true;
  37734. KeyedCollectionPrototype[ITERATOR_SYMBOL] = CollectionPrototype.entries;
  37735. KeyedCollectionPrototype.toJSON = toObject;
  37736. KeyedCollectionPrototype.__toStringMapper = function (v, k) { return quoteString(k) + ': ' + quoteString(v); };
  37737. mixin(IndexedCollection, {
  37738. // ### Conversion to other types
  37739. toKeyedSeq: function toKeyedSeq() {
  37740. return new ToKeyedSequence(this, false);
  37741. },
  37742. // ### ES6 Collection methods (ES6 Array and Map)
  37743. filter: function filter(predicate, context) {
  37744. return reify(this, filterFactory(this, predicate, context, false));
  37745. },
  37746. findIndex: function findIndex(predicate, context) {
  37747. var entry = this.findEntry(predicate, context);
  37748. return entry ? entry[0] : -1;
  37749. },
  37750. indexOf: function indexOf(searchValue) {
  37751. var key = this.keyOf(searchValue);
  37752. return key === undefined ? -1 : key;
  37753. },
  37754. lastIndexOf: function lastIndexOf(searchValue) {
  37755. var key = this.lastKeyOf(searchValue);
  37756. return key === undefined ? -1 : key;
  37757. },
  37758. reverse: function reverse() {
  37759. return reify(this, reverseFactory(this, false));
  37760. },
  37761. slice: function slice(begin, end) {
  37762. return reify(this, sliceFactory(this, begin, end, false));
  37763. },
  37764. splice: function splice(index, removeNum /*, ...values*/) {
  37765. var numArgs = arguments.length;
  37766. removeNum = Math.max(removeNum || 0, 0);
  37767. if (numArgs === 0 || (numArgs === 2 && !removeNum)) {
  37768. return this;
  37769. }
  37770. // If index is negative, it should resolve relative to the size of the
  37771. // collection. However size may be expensive to compute if not cached, so
  37772. // only call count() if the number is in fact negative.
  37773. index = resolveBegin(index, index < 0 ? this.count() : this.size);
  37774. var spliced = this.slice(0, index);
  37775. return reify(
  37776. this,
  37777. numArgs === 1
  37778. ? spliced
  37779. : spliced.concat(arrCopy(arguments, 2), this.slice(index + removeNum))
  37780. );
  37781. },
  37782. // ### More collection methods
  37783. findLastIndex: function findLastIndex(predicate, context) {
  37784. var entry = this.findLastEntry(predicate, context);
  37785. return entry ? entry[0] : -1;
  37786. },
  37787. first: function first(notSetValue) {
  37788. return this.get(0, notSetValue);
  37789. },
  37790. flatten: function flatten(depth) {
  37791. return reify(this, flattenFactory(this, depth, false));
  37792. },
  37793. get: function get(index, notSetValue) {
  37794. index = wrapIndex(this, index);
  37795. return index < 0 ||
  37796. (this.size === Infinity || (this.size !== undefined && index > this.size))
  37797. ? notSetValue
  37798. : this.find(function (_, key) { return key === index; }, undefined, notSetValue);
  37799. },
  37800. has: function has(index) {
  37801. index = wrapIndex(this, index);
  37802. return (
  37803. index >= 0 &&
  37804. (this.size !== undefined
  37805. ? this.size === Infinity || index < this.size
  37806. : this.indexOf(index) !== -1)
  37807. );
  37808. },
  37809. interpose: function interpose(separator) {
  37810. return reify(this, interposeFactory(this, separator));
  37811. },
  37812. interleave: function interleave(/*...collections*/) {
  37813. var collections = [this].concat(arrCopy(arguments));
  37814. var zipped = zipWithFactory(this.toSeq(), IndexedSeq.of, collections);
  37815. var interleaved = zipped.flatten(true);
  37816. if (zipped.size) {
  37817. interleaved.size = zipped.size * collections.length;
  37818. }
  37819. return reify(this, interleaved);
  37820. },
  37821. keySeq: function keySeq() {
  37822. return Range(0, this.size);
  37823. },
  37824. last: function last(notSetValue) {
  37825. return this.get(-1, notSetValue);
  37826. },
  37827. skipWhile: function skipWhile(predicate, context) {
  37828. return reify(this, skipWhileFactory(this, predicate, context, false));
  37829. },
  37830. zip: function zip(/*, ...collections */) {
  37831. var collections = [this].concat(arrCopy(arguments));
  37832. return reify(this, zipWithFactory(this, defaultZipper, collections));
  37833. },
  37834. zipAll: function zipAll(/*, ...collections */) {
  37835. var collections = [this].concat(arrCopy(arguments));
  37836. return reify(this, zipWithFactory(this, defaultZipper, collections, true));
  37837. },
  37838. zipWith: function zipWith(zipper /*, ...collections */) {
  37839. var collections = arrCopy(arguments);
  37840. collections[0] = this;
  37841. return reify(this, zipWithFactory(this, zipper, collections));
  37842. },
  37843. });
  37844. var IndexedCollectionPrototype = IndexedCollection.prototype;
  37845. IndexedCollectionPrototype[IS_INDEXED_SYMBOL] = true;
  37846. IndexedCollectionPrototype[IS_ORDERED_SYMBOL] = true;
  37847. mixin(SetCollection, {
  37848. // ### ES6 Collection methods (ES6 Array and Map)
  37849. get: function get(value, notSetValue) {
  37850. return this.has(value) ? value : notSetValue;
  37851. },
  37852. includes: function includes(value) {
  37853. return this.has(value);
  37854. },
  37855. // ### More sequential methods
  37856. keySeq: function keySeq() {
  37857. return this.valueSeq();
  37858. },
  37859. });
  37860. SetCollection.prototype.has = CollectionPrototype.includes;
  37861. SetCollection.prototype.contains = SetCollection.prototype.includes;
  37862. // Mixin subclasses
  37863. mixin(KeyedSeq, KeyedCollection.prototype);
  37864. mixin(IndexedSeq, IndexedCollection.prototype);
  37865. mixin(SetSeq, SetCollection.prototype);
  37866. // #pragma Helper functions
  37867. function reduce(collection, reducer, reduction, context, useFirst, reverse) {
  37868. assertNotInfinite(collection.size);
  37869. collection.__iterate(function (v, k, c) {
  37870. if (useFirst) {
  37871. useFirst = false;
  37872. reduction = v;
  37873. } else {
  37874. reduction = reducer.call(context, reduction, v, k, c);
  37875. }
  37876. }, reverse);
  37877. return reduction;
  37878. }
  37879. function keyMapper(v, k) {
  37880. return k;
  37881. }
  37882. function entryMapper(v, k) {
  37883. return [k, v];
  37884. }
  37885. function not(predicate) {
  37886. return function() {
  37887. return !predicate.apply(this, arguments);
  37888. };
  37889. }
  37890. function neg(predicate) {
  37891. return function() {
  37892. return -predicate.apply(this, arguments);
  37893. };
  37894. }
  37895. function defaultZipper() {
  37896. return arrCopy(arguments);
  37897. }
  37898. function defaultNegComparator(a, b) {
  37899. return a < b ? 1 : a > b ? -1 : 0;
  37900. }
  37901. function hashCollection(collection) {
  37902. if (collection.size === Infinity) {
  37903. return 0;
  37904. }
  37905. var ordered = isOrdered(collection);
  37906. var keyed = isKeyed(collection);
  37907. var h = ordered ? 1 : 0;
  37908. var size = collection.__iterate(
  37909. keyed
  37910. ? ordered
  37911. ? function (v, k) {
  37912. h = (31 * h + hashMerge(hash(v), hash(k))) | 0;
  37913. }
  37914. : function (v, k) {
  37915. h = (h + hashMerge(hash(v), hash(k))) | 0;
  37916. }
  37917. : ordered
  37918. ? function (v) {
  37919. h = (31 * h + hash(v)) | 0;
  37920. }
  37921. : function (v) {
  37922. h = (h + hash(v)) | 0;
  37923. }
  37924. );
  37925. return murmurHashOfSize(size, h);
  37926. }
  37927. function murmurHashOfSize(size, h) {
  37928. h = imul(h, 0xcc9e2d51);
  37929. h = imul((h << 15) | (h >>> -15), 0x1b873593);
  37930. h = imul((h << 13) | (h >>> -13), 5);
  37931. h = ((h + 0xe6546b64) | 0) ^ size;
  37932. h = imul(h ^ (h >>> 16), 0x85ebca6b);
  37933. h = imul(h ^ (h >>> 13), 0xc2b2ae35);
  37934. h = smi(h ^ (h >>> 16));
  37935. return h;
  37936. }
  37937. function hashMerge(a, b) {
  37938. return (a ^ (b + 0x9e3779b9 + (a << 6) + (a >> 2))) | 0; // int
  37939. }
  37940. var OrderedSet = /*@__PURE__*/(function (Set$$1) {
  37941. function OrderedSet(value) {
  37942. return value === null || value === undefined
  37943. ? emptyOrderedSet()
  37944. : isOrderedSet(value)
  37945. ? value
  37946. : emptyOrderedSet().withMutations(function (set) {
  37947. var iter = SetCollection(value);
  37948. assertNotInfinite(iter.size);
  37949. iter.forEach(function (v) { return set.add(v); });
  37950. });
  37951. }
  37952. if ( Set$$1 ) OrderedSet.__proto__ = Set$$1;
  37953. OrderedSet.prototype = Object.create( Set$$1 && Set$$1.prototype );
  37954. OrderedSet.prototype.constructor = OrderedSet;
  37955. OrderedSet.of = function of (/*...values*/) {
  37956. return this(arguments);
  37957. };
  37958. OrderedSet.fromKeys = function fromKeys (value) {
  37959. return this(KeyedCollection(value).keySeq());
  37960. };
  37961. OrderedSet.prototype.toString = function toString () {
  37962. return this.__toString('OrderedSet {', '}');
  37963. };
  37964. return OrderedSet;
  37965. }(Set));
  37966. OrderedSet.isOrderedSet = isOrderedSet;
  37967. var OrderedSetPrototype = OrderedSet.prototype;
  37968. OrderedSetPrototype[IS_ORDERED_SYMBOL] = true;
  37969. OrderedSetPrototype.zip = IndexedCollectionPrototype.zip;
  37970. OrderedSetPrototype.zipWith = IndexedCollectionPrototype.zipWith;
  37971. OrderedSetPrototype.__empty = emptyOrderedSet;
  37972. OrderedSetPrototype.__make = makeOrderedSet;
  37973. function makeOrderedSet(map, ownerID) {
  37974. var set = Object.create(OrderedSetPrototype);
  37975. set.size = map ? map.size : 0;
  37976. set._map = map;
  37977. set.__ownerID = ownerID;
  37978. return set;
  37979. }
  37980. var EMPTY_ORDERED_SET;
  37981. function emptyOrderedSet() {
  37982. return (
  37983. EMPTY_ORDERED_SET || (EMPTY_ORDERED_SET = makeOrderedSet(emptyOrderedMap()))
  37984. );
  37985. }
  37986. var Record = function Record(defaultValues, name) {
  37987. var hasInitialized;
  37988. var RecordType = function Record(values) {
  37989. var this$1 = this;
  37990. if (values instanceof RecordType) {
  37991. return values;
  37992. }
  37993. if (!(this instanceof RecordType)) {
  37994. return new RecordType(values);
  37995. }
  37996. if (!hasInitialized) {
  37997. hasInitialized = true;
  37998. var keys = Object.keys(defaultValues);
  37999. var indices = (RecordTypePrototype._indices = {});
  38000. // Deprecated: left to attempt not to break any external code which
  38001. // relies on a ._name property existing on record instances.
  38002. // Use Record.getDescriptiveName() instead
  38003. RecordTypePrototype._name = name;
  38004. RecordTypePrototype._keys = keys;
  38005. RecordTypePrototype._defaultValues = defaultValues;
  38006. for (var i = 0; i < keys.length; i++) {
  38007. var propName = keys[i];
  38008. indices[propName] = i;
  38009. if (RecordTypePrototype[propName]) {
  38010. /* eslint-disable no-console */
  38011. typeof console === 'object' &&
  38012. console.warn &&
  38013. console.warn(
  38014. 'Cannot define ' +
  38015. recordName(this) +
  38016. ' with property "' +
  38017. propName +
  38018. '" since that property name is part of the Record API.'
  38019. );
  38020. /* eslint-enable no-console */
  38021. } else {
  38022. setProp(RecordTypePrototype, propName);
  38023. }
  38024. }
  38025. }
  38026. this.__ownerID = undefined;
  38027. this._values = List().withMutations(function (l) {
  38028. l.setSize(this$1._keys.length);
  38029. KeyedCollection(values).forEach(function (v, k) {
  38030. l.set(this$1._indices[k], v === this$1._defaultValues[k] ? undefined : v);
  38031. });
  38032. });
  38033. };
  38034. var RecordTypePrototype = (RecordType.prototype = Object.create(
  38035. RecordPrototype
  38036. ));
  38037. RecordTypePrototype.constructor = RecordType;
  38038. if (name) {
  38039. RecordType.displayName = name;
  38040. }
  38041. return RecordType;
  38042. };
  38043. Record.prototype.toString = function toString () {
  38044. var str = recordName(this) + ' { ';
  38045. var keys = this._keys;
  38046. var k;
  38047. for (var i = 0, l = keys.length; i !== l; i++) {
  38048. k = keys[i];
  38049. str += (i ? ', ' : '') + k + ': ' + quoteString(this.get(k));
  38050. }
  38051. return str + ' }';
  38052. };
  38053. Record.prototype.equals = function equals (other) {
  38054. return (
  38055. this === other ||
  38056. (other &&
  38057. this._keys === other._keys &&
  38058. recordSeq(this).equals(recordSeq(other)))
  38059. );
  38060. };
  38061. Record.prototype.hashCode = function hashCode () {
  38062. return recordSeq(this).hashCode();
  38063. };
  38064. // @pragma Access
  38065. Record.prototype.has = function has (k) {
  38066. return this._indices.hasOwnProperty(k);
  38067. };
  38068. Record.prototype.get = function get (k, notSetValue) {
  38069. if (!this.has(k)) {
  38070. return notSetValue;
  38071. }
  38072. var index = this._indices[k];
  38073. var value = this._values.get(index);
  38074. return value === undefined ? this._defaultValues[k] : value;
  38075. };
  38076. // @pragma Modification
  38077. Record.prototype.set = function set (k, v) {
  38078. if (this.has(k)) {
  38079. var newValues = this._values.set(
  38080. this._indices[k],
  38081. v === this._defaultValues[k] ? undefined : v
  38082. );
  38083. if (newValues !== this._values && !this.__ownerID) {
  38084. return makeRecord(this, newValues);
  38085. }
  38086. }
  38087. return this;
  38088. };
  38089. Record.prototype.remove = function remove (k) {
  38090. return this.set(k);
  38091. };
  38092. Record.prototype.clear = function clear () {
  38093. var newValues = this._values.clear().setSize(this._keys.length);
  38094. return this.__ownerID ? this : makeRecord(this, newValues);
  38095. };
  38096. Record.prototype.wasAltered = function wasAltered () {
  38097. return this._values.wasAltered();
  38098. };
  38099. Record.prototype.toSeq = function toSeq () {
  38100. return recordSeq(this);
  38101. };
  38102. Record.prototype.toJS = function toJS$1 () {
  38103. return toJS(this);
  38104. };
  38105. Record.prototype.entries = function entries () {
  38106. return this.__iterator(ITERATE_ENTRIES);
  38107. };
  38108. Record.prototype.__iterator = function __iterator (type, reverse) {
  38109. return recordSeq(this).__iterator(type, reverse);
  38110. };
  38111. Record.prototype.__iterate = function __iterate (fn, reverse) {
  38112. return recordSeq(this).__iterate(fn, reverse);
  38113. };
  38114. Record.prototype.__ensureOwner = function __ensureOwner (ownerID) {
  38115. if (ownerID === this.__ownerID) {
  38116. return this;
  38117. }
  38118. var newValues = this._values.__ensureOwner(ownerID);
  38119. if (!ownerID) {
  38120. this.__ownerID = ownerID;
  38121. this._values = newValues;
  38122. return this;
  38123. }
  38124. return makeRecord(this, newValues, ownerID);
  38125. };
  38126. Record.isRecord = isRecord;
  38127. Record.getDescriptiveName = recordName;
  38128. var RecordPrototype = Record.prototype;
  38129. RecordPrototype[IS_RECORD_SYMBOL] = true;
  38130. RecordPrototype[DELETE] = RecordPrototype.remove;
  38131. RecordPrototype.deleteIn = RecordPrototype.removeIn = deleteIn;
  38132. RecordPrototype.getIn = getIn$1;
  38133. RecordPrototype.hasIn = CollectionPrototype.hasIn;
  38134. RecordPrototype.merge = merge;
  38135. RecordPrototype.mergeWith = mergeWith;
  38136. RecordPrototype.mergeIn = mergeIn;
  38137. RecordPrototype.mergeDeep = mergeDeep$1;
  38138. RecordPrototype.mergeDeepWith = mergeDeepWith$1;
  38139. RecordPrototype.mergeDeepIn = mergeDeepIn;
  38140. RecordPrototype.setIn = setIn$1;
  38141. RecordPrototype.update = update$1;
  38142. RecordPrototype.updateIn = updateIn$1;
  38143. RecordPrototype.withMutations = withMutations;
  38144. RecordPrototype.asMutable = asMutable;
  38145. RecordPrototype.asImmutable = asImmutable;
  38146. RecordPrototype[ITERATOR_SYMBOL] = RecordPrototype.entries;
  38147. RecordPrototype.toJSON = RecordPrototype.toObject =
  38148. CollectionPrototype.toObject;
  38149. RecordPrototype.inspect = RecordPrototype.toSource = function() {
  38150. return this.toString();
  38151. };
  38152. function makeRecord(likeRecord, values, ownerID) {
  38153. var record = Object.create(Object.getPrototypeOf(likeRecord));
  38154. record._values = values;
  38155. record.__ownerID = ownerID;
  38156. return record;
  38157. }
  38158. function recordName(record) {
  38159. return record.constructor.displayName || record.constructor.name || 'Record';
  38160. }
  38161. function recordSeq(record) {
  38162. return keyedSeqFromValue(record._keys.map(function (k) { return [k, record.get(k)]; }));
  38163. }
  38164. function setProp(prototype, name) {
  38165. try {
  38166. Object.defineProperty(prototype, name, {
  38167. get: function() {
  38168. return this.get(name);
  38169. },
  38170. set: function(value) {
  38171. invariant(this.__ownerID, 'Cannot set on an immutable record.');
  38172. this.set(name, value);
  38173. },
  38174. });
  38175. } catch (error) {
  38176. // Object.defineProperty failed. Probably IE8.
  38177. }
  38178. }
  38179. /**
  38180. * Returns a lazy Seq of `value` repeated `times` times. When `times` is
  38181. * undefined, returns an infinite sequence of `value`.
  38182. */
  38183. var Repeat = /*@__PURE__*/(function (IndexedSeq$$1) {
  38184. function Repeat(value, times) {
  38185. if (!(this instanceof Repeat)) {
  38186. return new Repeat(value, times);
  38187. }
  38188. this._value = value;
  38189. this.size = times === undefined ? Infinity : Math.max(0, times);
  38190. if (this.size === 0) {
  38191. if (EMPTY_REPEAT) {
  38192. return EMPTY_REPEAT;
  38193. }
  38194. EMPTY_REPEAT = this;
  38195. }
  38196. }
  38197. if ( IndexedSeq$$1 ) Repeat.__proto__ = IndexedSeq$$1;
  38198. Repeat.prototype = Object.create( IndexedSeq$$1 && IndexedSeq$$1.prototype );
  38199. Repeat.prototype.constructor = Repeat;
  38200. Repeat.prototype.toString = function toString () {
  38201. if (this.size === 0) {
  38202. return 'Repeat []';
  38203. }
  38204. return 'Repeat [ ' + this._value + ' ' + this.size + ' times ]';
  38205. };
  38206. Repeat.prototype.get = function get (index, notSetValue) {
  38207. return this.has(index) ? this._value : notSetValue;
  38208. };
  38209. Repeat.prototype.includes = function includes (searchValue) {
  38210. return is(this._value, searchValue);
  38211. };
  38212. Repeat.prototype.slice = function slice (begin, end) {
  38213. var size = this.size;
  38214. return wholeSlice(begin, end, size)
  38215. ? this
  38216. : new Repeat(
  38217. this._value,
  38218. resolveEnd(end, size) - resolveBegin(begin, size)
  38219. );
  38220. };
  38221. Repeat.prototype.reverse = function reverse () {
  38222. return this;
  38223. };
  38224. Repeat.prototype.indexOf = function indexOf (searchValue) {
  38225. if (is(this._value, searchValue)) {
  38226. return 0;
  38227. }
  38228. return -1;
  38229. };
  38230. Repeat.prototype.lastIndexOf = function lastIndexOf (searchValue) {
  38231. if (is(this._value, searchValue)) {
  38232. return this.size;
  38233. }
  38234. return -1;
  38235. };
  38236. Repeat.prototype.__iterate = function __iterate (fn, reverse) {
  38237. var size = this.size;
  38238. var i = 0;
  38239. while (i !== size) {
  38240. if (fn(this._value, reverse ? size - ++i : i++, this) === false) {
  38241. break;
  38242. }
  38243. }
  38244. return i;
  38245. };
  38246. Repeat.prototype.__iterator = function __iterator (type, reverse) {
  38247. var this$1 = this;
  38248. var size = this.size;
  38249. var i = 0;
  38250. return new Iterator(
  38251. function () { return i === size
  38252. ? iteratorDone()
  38253. : iteratorValue(type, reverse ? size - ++i : i++, this$1._value); }
  38254. );
  38255. };
  38256. Repeat.prototype.equals = function equals (other) {
  38257. return other instanceof Repeat
  38258. ? is(this._value, other._value)
  38259. : deepEqual(other);
  38260. };
  38261. return Repeat;
  38262. }(IndexedSeq));
  38263. var EMPTY_REPEAT;
  38264. function fromJS(value, converter) {
  38265. return fromJSWith(
  38266. [],
  38267. converter || defaultConverter,
  38268. value,
  38269. '',
  38270. converter && converter.length > 2 ? [] : undefined,
  38271. { '': value }
  38272. );
  38273. }
  38274. function fromJSWith(stack, converter, value, key, keyPath, parentValue) {
  38275. var toSeq = Array.isArray(value)
  38276. ? IndexedSeq
  38277. : isPlainObj(value)
  38278. ? KeyedSeq
  38279. : null;
  38280. if (toSeq) {
  38281. if (~stack.indexOf(value)) {
  38282. throw new TypeError('Cannot convert circular structure to Immutable');
  38283. }
  38284. stack.push(value);
  38285. keyPath && key !== '' && keyPath.push(key);
  38286. var converted = converter.call(
  38287. parentValue,
  38288. key,
  38289. toSeq(value).map(function (v, k) { return fromJSWith(stack, converter, v, k, keyPath, value); }
  38290. ),
  38291. keyPath && keyPath.slice()
  38292. );
  38293. stack.pop();
  38294. keyPath && keyPath.pop();
  38295. return converted;
  38296. }
  38297. return value;
  38298. }
  38299. function defaultConverter(k, v) {
  38300. return isKeyed(v) ? v.toMap() : v.toList();
  38301. }
  38302. var version = "4.0.0-rc.11";
  38303. var Immutable = {
  38304. version: version,
  38305. Collection: Collection,
  38306. // Note: Iterable is deprecated
  38307. Iterable: Collection,
  38308. Seq: Seq,
  38309. Map: Map,
  38310. OrderedMap: OrderedMap,
  38311. List: List,
  38312. Stack: Stack,
  38313. Set: Set,
  38314. OrderedSet: OrderedSet,
  38315. Record: Record,
  38316. Range: Range,
  38317. Repeat: Repeat,
  38318. is: is,
  38319. fromJS: fromJS,
  38320. hash: hash,
  38321. isImmutable: isImmutable,
  38322. isCollection: isCollection,
  38323. isKeyed: isKeyed,
  38324. isIndexed: isIndexed,
  38325. isAssociative: isAssociative,
  38326. isOrdered: isOrdered,
  38327. isValueObject: isValueObject,
  38328. isSeq: isSeq,
  38329. isList: isList,
  38330. isMap: isMap,
  38331. isOrderedMap: isOrderedMap,
  38332. isStack: isStack,
  38333. isSet: isSet,
  38334. isOrderedSet: isOrderedSet,
  38335. isRecord: isRecord,
  38336. get: get,
  38337. getIn: getIn,
  38338. has: has,
  38339. hasIn: hasIn,
  38340. merge: merge$1,
  38341. mergeDeep: mergeDeep,
  38342. mergeWith: mergeWith$1,
  38343. mergeDeepWith: mergeDeepWith,
  38344. remove: remove,
  38345. removeIn: removeIn,
  38346. set: set,
  38347. setIn: setIn,
  38348. update: update,
  38349. updateIn: updateIn,
  38350. };
  38351. // Note: Iterable is deprecated
  38352. var Iterable = Collection;
  38353. exports.default = Immutable;
  38354. exports.version = version;
  38355. exports.Collection = Collection;
  38356. exports.Iterable = Iterable;
  38357. exports.Seq = Seq;
  38358. exports.Map = Map;
  38359. exports.OrderedMap = OrderedMap;
  38360. exports.List = List;
  38361. exports.Stack = Stack;
  38362. exports.Set = Set;
  38363. exports.OrderedSet = OrderedSet;
  38364. exports.Record = Record;
  38365. exports.Range = Range;
  38366. exports.Repeat = Repeat;
  38367. exports.is = is;
  38368. exports.fromJS = fromJS;
  38369. exports.hash = hash;
  38370. exports.isImmutable = isImmutable;
  38371. exports.isCollection = isCollection;
  38372. exports.isKeyed = isKeyed;
  38373. exports.isIndexed = isIndexed;
  38374. exports.isAssociative = isAssociative;
  38375. exports.isOrdered = isOrdered;
  38376. exports.isValueObject = isValueObject;
  38377. exports.get = get;
  38378. exports.getIn = getIn;
  38379. exports.has = has;
  38380. exports.hasIn = hasIn;
  38381. exports.merge = merge$1;
  38382. exports.mergeDeep = mergeDeep;
  38383. exports.mergeWith = mergeWith$1;
  38384. exports.mergeDeepWith = mergeDeepWith;
  38385. exports.remove = remove;
  38386. exports.removeIn = removeIn;
  38387. exports.set = set;
  38388. exports.setIn = setIn;
  38389. exports.update = update;
  38390. exports.updateIn = updateIn;
  38391. Object.defineProperty(exports, '__esModule', { value: true });
  38392. })));
  38393. });
  38394. _commonjsHelpers.unwrapExports(immutable$3);
  38395. var draftjsUtils$1 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
  38396. !function(t,e){module.exports=e(Draft,immutable$3);}(window,function(n,r){return u={},o.m=i=[function(t,e){t.exports=n;},function(t,e){t.exports=r;},function(t,e,n){t.exports=n(3);},function(t,e,n){n.r(e);var C=n(0),i=n(1);function m(t){var e=t.getSelection(),n=t.getCurrentContent(),r=e.getStartKey(),o=e.getEndKey(),i=n.getBlockMap();return i.toSeq().skipUntil(function(t,e){return e===r}).takeUntil(function(t,e){return e===o}).concat([[o,i.get(o)]])}function a(t){return m(t).toList()}function f(t){if(t)return a(t).get(0)}function r(t){if(t){var n=f(t),e=t.getCurrentContent().getBlockMap().toSeq().toList(),r=0;if(e.forEach(function(t,e){t.get("key")===n.get("key")&&(r=e-1);}),-1<r)return e.get(r)}}function o(t){return t?t.getCurrentContent().getBlockMap().toList():new i.List}function u(t){var e=a(t);if(!e.some(function(t){return t.type!==e.get(0).type}))return e.get(0).type}function c(t){var e=C.RichUtils.tryToRemoveBlockStyle(t);return e?C.EditorState.push(t,e,"change-block-type"):t}function l(t){var e="",n=t.getSelection(),r=n.getAnchorOffset(),o=n.getFocusOffset(),i=a(t);if(0<i.size){if(n.getIsBackward()){var u=r;r=o,o=u;}for(var c=0;c<i.size;c+=1){var f=0===c?r:0,l=c===i.size-1?o:i.get(c).getText().length;e+=i.get(c).getText().slice(f,l);}}return e}function s(t){var e=t.getCurrentContent(),n=t.getSelection(),r=C.Modifier.removeRange(e,n,"forward"),o=r.getSelectionAfter(),i=r.getBlockForKey(o.getStartKey());return r=C.Modifier.insertText(r,o,"\n",i.getInlineStyleAt(o.getStartOffset()),null),C.EditorState.push(t,r,"insert-fragment")}function g(t){var e=C.Modifier.splitBlock(t.getCurrentContent(),t.getSelection());return c(C.EditorState.push(t,e,"split-block"))}function d(t){var e=t.getCurrentContent().getBlockMap().toList(),n=t.getSelection().merge({anchorKey:e.first().get("key"),anchorOffset:0,focusKey:e.last().get("key"),focusOffset:e.last().getLength()}),r=C.Modifier.removeRange(t.getCurrentContent(),n,"forward");return C.EditorState.push(t,r,"remove-range")}function S(t,e){var n=C.Modifier.setBlockData(t.getCurrentContent(),t.getSelection(),e);return C.EditorState.push(t,n,"change-block-data")}function p(t){var r=new i.Map({}),e=a(t);if(e&&0<e.size)for(var n=function(t){var n=e.get(t).getData();if(!n||0===n.size)return r=r.clear(),"break";if(0===t)r=n;else if(r.forEach(function(t,e){n.get(e)&&n.get(e)===t||(r=r.delete(e));}),0===r.size)return r=r.clear(),"break"},o=0;o<e.size;o+=1){if("break"===n(o))break}return r}var y=Object(i.Map)({code:{element:"pre"}}),v=C.DefaultDraftBlockRenderMap.merge(y);function b(t){if(t){var e=t.getType();return "unordered-list-item"===e||"ordered-list-item"===e}return !1}function h(t,e,n){var r,o=t.getSelection();r=o.getIsBackward()?o.getFocusKey():o.getAnchorKey();var i=t.getCurrentContent(),u=i.getBlockForKey(r),c=u.getType();if("unordered-list-item"!==c&&"ordered-list-item"!==c)return t;var f=i.getBlockBefore(r);if(!f)return t;if(f.getType()!==c)return t;var l=u.getDepth();if(1===e&&l===n)return t;var a,s,g,d,S,p,y,v=Math.min(f.getDepth()+1,n),b=(s=e,g=v,d=(a=t).getSelection(),S=a.getCurrentContent(),p=S.getBlockMap(),y=m(a).map(function(t){var e=t.getDepth()+s;return e=Math.max(0,Math.min(e,g)),t.set("depth",e)}),p=p.merge(y),S.merge({blockMap:p,selectionBefore:d,selectionAfter:d}));return C.EditorState.push(t,b,"adjust-depth")}function O(t,e){var n;return 13===(n=e).which&&(n.getModifierState("Shift")||n.getModifierState("Alt")||n.getModifierState("Control"))?t.getSelection().isCollapsed()?C.RichUtils.insertSoftNewline(t):s(t):function(t){var e=t.getSelection();if(e.isCollapsed()){var n=t.getCurrentContent(),r=e.getStartKey(),o=n.getBlockForKey(r);if(!b(o)&&"unstyled"!==o.getType()&&o.getLength()===e.getStartOffset())return g(t);if(b(o)&&0===o.getLength()){var i=o.getDepth();if(0===i)return c(t);if(0<i)return h(t,-1,i)}}}(t)}function k(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r);}return n}function E(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function I(t){return (I="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function R(t){var e=t.getSelection();if(e.isCollapsed()){var n={},r=t.getCurrentInlineStyle().toList().toJS();if(r)return ["BOLD","ITALIC","UNDERLINE","STRIKETHROUGH","CODE","SUPERSCRIPT","SUBSCRIPT"].forEach(function(t){n[t]=0<=r.indexOf(t);}),n}var u=e.getStartOffset(),c=e.getEndOffset(),f=a(t);if(0<f.size){var o=function(){for(var n={BOLD:!0,ITALIC:!0,UNDERLINE:!0,STRIKETHROUGH:!0,CODE:!0,SUPERSCRIPT:!0,SUBSCRIPT:!0},r=0;r<f.size;r+=1){var t=0===r?u:0,e=r===f.size-1?c:f.get(r).getText().length;t===e&&0===t?(t=1,e=2):t===e&&--t;for(var o=function(t){var e=f.get(r).getInlineStyleAt(t);["BOLD","ITALIC","UNDERLINE","STRIKETHROUGH","CODE","SUPERSCRIPT","SUBSCRIPT"].forEach(function(t){n[t]=n[t]&&e.get(t)===t;});},i=t;i<e;i+=1)o(i);}return {v:n}}();if("object"===I(o))return o.v}return {}}function B(t){var e,n=t.getSelection(),r=n.getStartOffset(),o=n.getEndOffset();r===o&&0===r?o=1:r===o&&--r;for(var i=f(t),u=r;u<o;u+=1){var c=i.getEntityAt(u);if(!c){e=void 0;break}if(u===r)e=c;else if(e!==c){e=void 0;break}}return e}function T(t,e){var n,r=f(t);return r.findEntityRanges(function(t){return t.get("entity")===e},function(t,e){n={start:t,end:e,text:r.get("text").slice(t,e)};}),n}function P(t,e,n){x[t]["".concat(t.toLowerCase(),"-").concat(n)]=E({},"".concat(e),n);}function j(){return function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?k(Object(n),!0).forEach(function(t){E(e,t,n[t]);}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):k(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t));});}return e}({},x.color,{},x.bgcolor,{},x.fontSize,{},x.fontFamily,{CODE:x.CODE,SUPERSCRIPT:x.SUPERSCRIPT,SUBSCRIPT:x.SUBSCRIPT})}var x={color:{},bgcolor:{},fontSize:{},fontFamily:{},CODE:{fontFamily:"monospace",wordWrap:"break-word",background:"#f1f1f1",borderRadius:3,padding:"1px 3px"},SUPERSCRIPT:{fontSize:11,position:"relative",top:-8,display:"inline-flex"},SUBSCRIPT:{fontSize:11,position:"relative",bottom:-8,display:"inline-flex"}};function M(t,e,n){var r=t.getSelection(),o=Object.keys(x[e]).reduce(function(t,e){return C.Modifier.removeInlineStyle(t,r,e)},t.getCurrentContent()),i=C.EditorState.push(t,o,"changeinline-style"),u=t.getCurrentInlineStyle();if(r.isCollapsed()&&(i=u.reduce(function(t,e){return C.RichUtils.toggleInlineStyle(t,e)},i)),"SUPERSCRIPT"===e||"SUBSCRIPT"==e)u.has(n)||(i=C.RichUtils.toggleInlineStyle(i,n));else{var c="bgcolor"===e?"backgroundColor":e;u.has("".concat(c,"-").concat(n))||(i=C.RichUtils.toggleInlineStyle(i,"".concat(e.toLowerCase(),"-").concat(n)),P(e,c,n));}return i}function L(t){t&&t.getCurrentContent().getBlockMap().map(function(t){return t.get("characterList")}).toList().flatten().forEach(function(t){t&&0===t.indexOf("color-")?P("color","color",t.substr(6)):t&&0===t.indexOf("bgcolor-")?P("bgcolor","backgroundColor",t.substr(8)):t&&0===t.indexOf("fontsize-")?P("fontSize","fontSize",+t.substr(9)):t&&0===t.indexOf("fontfamily-")&&P("fontFamily","fontFamily",t.substr(11));});}function U(t,e,n){var r=t.getInlineStyleAt(n).toList().filter(function(t){return t.startsWith(e.toLowerCase())});if(r&&0<r.size)return r.get(0)}function w(r,l){if(r&&l&&0<l.length){var t=function(){var t=r.getSelection(),i={};if(t.isCollapsed())return l.forEach(function(t){i[t]=function(t,e){var n=t.getCurrentInlineStyle().toList().filter(function(t){return t.startsWith(e.toLowerCase())});if(n&&0<n.size)return n.get(0)}(r,t);}),{v:i};var u=t.getStartOffset(),c=t.getEndOffset(),f=a(r);if(0<f.size){for(var e=function(n){var t=0===n?u:0,e=n===f.size-1?c:f.get(n).getText().length;t===e&&0===t?(t=1,e=2):t===e&&--t;for(var r=function(e){e===t?l.forEach(function(t){i[t]=U(f.get(n),t,e);}):l.forEach(function(t){i[t]&&i[t]!==U(f.get(n),t,e)&&(i[t]=void 0);});},o=t;o<e;o+=1)r(o);},n=0;n<f.size;n+=1)e(n);return {v:i}}}();if("object"===I(t))return t.v}return {}}function D(e){var t=e.getCurrentInlineStyle(),n=e.getCurrentContent();return t.forEach(function(t){n=C.Modifier.removeInlineStyle(n,e.getSelection(),t);}),C.EditorState.push(e,n,"change-inline-style")}n.d(e,"isListBlock",function(){return b}),n.d(e,"changeDepth",function(){return h}),n.d(e,"handleNewLine",function(){return O}),n.d(e,"getEntityRange",function(){return T}),n.d(e,"getCustomStyleMap",function(){return j}),n.d(e,"toggleCustomInlineStyle",function(){return M}),n.d(e,"getSelectionEntity",function(){return B}),n.d(e,"extractInlineStyle",function(){return L}),n.d(e,"removeAllInlineStyles",function(){return D}),n.d(e,"getSelectionInlineStyle",function(){return R}),n.d(e,"getSelectionCustomInlineStyle",function(){return w}),n.d(e,"getSelectedBlocksMap",function(){return m}),n.d(e,"getSelectedBlocksList",function(){return a}),n.d(e,"getSelectedBlock",function(){return f}),n.d(e,"getBlockBeforeSelectedBlock",function(){return r}),n.d(e,"getAllBlocks",function(){return o}),n.d(e,"getSelectedBlocksType",function(){return u}),n.d(e,"removeSelectedBlocksStyle",function(){return c}),n.d(e,"getSelectionText",function(){return l}),n.d(e,"addLineBreakRemovingSelection",function(){return s}),n.d(e,"insertNewUnstyledBlock",function(){return g}),n.d(e,"clearEditorContent",function(){return d}),n.d(e,"setBlockData",function(){return S}),n.d(e,"getSelectedBlocksMetadata",function(){return p}),n.d(e,"blockRenderMap",function(){return v});}],o.c=u,o.d=function(t,e,n){o.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n});},o.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0});},o.t=function(e,t){if(1&t&&(e=o(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(o.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)o.d(n,r,function(t){return e[t]}.bind(null,r));return n},o.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return o.d(e,"a",e),e},o.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},o.p="",o(o.s=2);function o(t){if(u[t])return u[t].exports;var e=u[t]={i:t,l:!1,exports:{}};return i[t].call(e.exports,e,e.exports,o),e.l=!0,e.exports}var i,u;});
  38397. });
  38398. _commonjsHelpers.unwrapExports(draftjsUtils$1);
  38399. var draftjsUtils_1$1 = draftjsUtils$1.draftjsUtils;
  38400. var content$1 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
  38401. Object.defineProperty(exports, "__esModule", {
  38402. value: true
  38403. });
  38404. exports.redo = exports.undo = exports.handleKeyCommand = exports.clear = exports.setMediaPosition = exports.removeMedia = exports.setMediaData = exports.insertMedias = exports.insertHorizontalLine = exports.insertAtomicBlock = exports.insertHTML = exports.insertText = exports.toggleSelectionLetterSpacing = exports.toggleSelectionFontFamily = exports.toggleSelectionLineHeight = exports.toggleSelectionFontSize = exports.toggleSelectionBackgroundColor = exports.toggleSelectionColor = exports.decreaseSelectionIndent = exports.increaseSelectionIndent = exports.toggleSelectionIndent = exports.toggleSelectionAlignment = exports.removeSelectionInlineStyles = exports.toggleSelectionInlineStyle = exports.selectionHasInlineStyle = exports.getSelectionInlineStyle = exports.toggleSelectionLink = exports.toggleSelectionEntity = exports.getSelectionEntityData = exports.getSelectionEntityType = exports.toggleSelectionBlockType = exports.getSelectionText = exports.getSelectionBlockType = exports.getSelectionBlockData = exports.setSelectionBlockData = exports.getSelectedBlocks = exports.updateEachCharacterOfSelection = exports.getSelectionBlock = exports.removeBlock = exports.selectNextBlock = exports.selectBlock = exports.selectionContainsStrictBlock = exports.selectionContainsBlockType = exports.isSelectionCollapsed = exports.createEditorState = exports.createEmptyEditorState = exports.isEditorState = exports.registerStrictBlockType = undefined;
  38405. var _immutable2 = _interopRequireDefault(immutable$3);
  38406. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  38407. var strictBlockTypes = ['atomic'];
  38408. var registerStrictBlockType = exports.registerStrictBlockType = function registerStrictBlockType(blockType) {
  38409. strictBlockTypes.indexOf(blockType) === -1 && strictBlockTypes.push(blockType);
  38410. };
  38411. var isEditorState = exports.isEditorState = function isEditorState(editorState) {
  38412. return editorState instanceof Draft.EditorState;
  38413. };
  38414. var createEmptyEditorState = exports.createEmptyEditorState = function createEmptyEditorState(editorDecorators) {
  38415. return Draft.EditorState.createEmpty(editorDecorators);
  38416. };
  38417. var createEditorState = exports.createEditorState = function createEditorState(contentState, editorDecorators) {
  38418. return Draft.EditorState.createWithContent(contentState, editorDecorators);
  38419. };
  38420. var isSelectionCollapsed = exports.isSelectionCollapsed = function isSelectionCollapsed(editorState) {
  38421. return editorState.getSelection().isCollapsed();
  38422. };
  38423. var selectionContainsBlockType = exports.selectionContainsBlockType = function selectionContainsBlockType(editorState, blockType) {
  38424. return getSelectedBlocks(editorState).find(function (block) {
  38425. return block.getType() === blockType;
  38426. });
  38427. };
  38428. var selectionContainsStrictBlock = exports.selectionContainsStrictBlock = function selectionContainsStrictBlock(editorState) {
  38429. return getSelectedBlocks(editorState).find(function (block) {
  38430. return ~strictBlockTypes.indexOf(block.getType());
  38431. });
  38432. };
  38433. var selectBlock = exports.selectBlock = function selectBlock(editorState, block) {
  38434. var blockKey = block.getKey();
  38435. return Draft.EditorState.forceSelection(editorState, new Draft.SelectionState({
  38436. anchorKey: blockKey,
  38437. anchorOffset: 0,
  38438. focusKey: blockKey,
  38439. focusOffset: block.getLength()
  38440. }));
  38441. };
  38442. var selectNextBlock = exports.selectNextBlock = function selectNextBlock(editorState, block) {
  38443. var nextBlock = editorState.getCurrentContent().getBlockAfter(block.getKey());
  38444. return nextBlock ? selectBlock(editorState, nextBlock) : editorState;
  38445. };
  38446. var removeBlock = exports.removeBlock = function removeBlock(editorState, block) {
  38447. var lastSelection = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  38448. var nextContentState = void 0,
  38449. nextEditorState = void 0;
  38450. var blockKey = block.getKey();
  38451. nextContentState = Draft.Modifier.removeRange(editorState.getCurrentContent(), new Draft.SelectionState({
  38452. anchorKey: blockKey,
  38453. anchorOffset: 0,
  38454. focusKey: blockKey,
  38455. focusOffset: block.getLength()
  38456. }), 'backward');
  38457. nextContentState = Draft.Modifier.setBlockType(nextContentState, nextContentState.getSelectionAfter(), 'unstyled');
  38458. nextEditorState = Draft.EditorState.push(editorState, nextContentState, 'remove-range');
  38459. return Draft.EditorState.forceSelection(nextEditorState, lastSelection || nextContentState.getSelectionAfter());
  38460. };
  38461. var getSelectionBlock = exports.getSelectionBlock = function getSelectionBlock(editorState) {
  38462. return editorState.getCurrentContent().getBlockForKey(editorState.getSelection().getAnchorKey());
  38463. };
  38464. var updateEachCharacterOfSelection = exports.updateEachCharacterOfSelection = function updateEachCharacterOfSelection(editorState, callback) {
  38465. var selectionState = editorState.getSelection();
  38466. var contentState = editorState.getCurrentContent();
  38467. var contentBlocks = contentState.getBlockMap();
  38468. var selectedBlocks = getSelectedBlocks(editorState);
  38469. if (selectedBlocks.length === 0) {
  38470. return editorState;
  38471. }
  38472. var startKey = selectionState.getStartKey();
  38473. var startOffset = selectionState.getStartOffset();
  38474. var endKey = selectionState.getEndKey();
  38475. var endOffset = selectionState.getEndOffset();
  38476. var nextContentBlocks = contentBlocks.map(function (block) {
  38477. if (selectedBlocks.indexOf(block) === -1) {
  38478. return block;
  38479. }
  38480. var blockKey = block.getKey();
  38481. var charactersList = block.getCharacterList();
  38482. var nextCharactersList = null;
  38483. if (blockKey === startKey && blockKey === endKey) {
  38484. nextCharactersList = charactersList.map(function (character, index) {
  38485. if (index >= startOffset && index < endOffset) {
  38486. return callback(character);
  38487. }
  38488. return character;
  38489. });
  38490. } else if (blockKey === startKey) {
  38491. nextCharactersList = charactersList.map(function (character, index) {
  38492. if (index >= startOffset) {
  38493. return callback(character);
  38494. }
  38495. return character;
  38496. });
  38497. } else if (blockKey === endKey) {
  38498. nextCharactersList = charactersList.map(function (character, index) {
  38499. if (index < endOffset) {
  38500. return callback(character);
  38501. }
  38502. return character;
  38503. });
  38504. } else {
  38505. nextCharactersList = charactersList.map(function (character) {
  38506. return callback(character);
  38507. });
  38508. }
  38509. return block.merge({
  38510. 'characterList': nextCharactersList
  38511. });
  38512. });
  38513. return Draft.EditorState.push(editorState, contentState.merge({
  38514. blockMap: nextContentBlocks,
  38515. selectionBefore: selectionState,
  38516. selectionAfter: selectionState
  38517. }), 'update-selection-character-list');
  38518. };
  38519. var getSelectedBlocks = exports.getSelectedBlocks = function getSelectedBlocks(editorState) {
  38520. var selectionState = editorState.getSelection();
  38521. var contentState = editorState.getCurrentContent();
  38522. var startKey = selectionState.getStartKey();
  38523. var endKey = selectionState.getEndKey();
  38524. var isSameBlock = startKey === endKey;
  38525. var startingBlock = contentState.getBlockForKey(startKey);
  38526. var selectedBlocks = [startingBlock];
  38527. if (!isSameBlock) {
  38528. var blockKey = startKey;
  38529. while (blockKey !== endKey) {
  38530. var nextBlock = contentState.getBlockAfter(blockKey);
  38531. selectedBlocks.push(nextBlock);
  38532. blockKey = nextBlock.getKey();
  38533. }
  38534. }
  38535. return selectedBlocks;
  38536. };
  38537. var setSelectionBlockData = exports.setSelectionBlockData = function setSelectionBlockData(editorState, blockData, override) {
  38538. var newBlockData = override ? blockData : Object.assign({}, getSelectionBlockData(editorState).toJS(), blockData);
  38539. Object.keys(newBlockData).forEach(function (key) {
  38540. if (newBlockData.hasOwnProperty(key) && newBlockData[key] === undefined) {
  38541. delete newBlockData[key];
  38542. }
  38543. });
  38544. return (0, draftjsUtils$1.setBlockData)(editorState, newBlockData);
  38545. };
  38546. var getSelectionBlockData = exports.getSelectionBlockData = function getSelectionBlockData(editorState, name) {
  38547. var blockData = getSelectionBlock(editorState).getData();
  38548. return name ? blockData.get(name) : blockData;
  38549. };
  38550. var getSelectionBlockType = exports.getSelectionBlockType = function getSelectionBlockType(editorState) {
  38551. return getSelectionBlock(editorState).getType();
  38552. };
  38553. var getSelectionText = exports.getSelectionText = function getSelectionText(editorState) {
  38554. var selectionState = editorState.getSelection();
  38555. var contentState = editorState.getCurrentContent();
  38556. if (selectionState.isCollapsed() || getSelectionBlockType(editorState) === 'atomic') {
  38557. return '';
  38558. }
  38559. var anchorKey = selectionState.getAnchorKey();
  38560. var currentContentBlock = contentState.getBlockForKey(anchorKey);
  38561. var start = selectionState.getStartOffset();
  38562. var end = selectionState.getEndOffset();
  38563. return currentContentBlock.getText().slice(start, end);
  38564. };
  38565. var toggleSelectionBlockType = exports.toggleSelectionBlockType = function toggleSelectionBlockType(editorState, blockType) {
  38566. if (selectionContainsStrictBlock(editorState)) {
  38567. return editorState;
  38568. }
  38569. return Draft.RichUtils.toggleBlockType(editorState, blockType);
  38570. };
  38571. var getSelectionEntityType = exports.getSelectionEntityType = function getSelectionEntityType(editorState) {
  38572. var entityKey = (0, draftjsUtils$1.getSelectionEntity)(editorState);
  38573. if (entityKey) {
  38574. var entity = editorState.getCurrentContent().getEntity(entityKey);
  38575. return entity ? entity.get('type') : null;
  38576. }
  38577. return null;
  38578. };
  38579. var getSelectionEntityData = exports.getSelectionEntityData = function getSelectionEntityData(editorState, type) {
  38580. var entityKey = (0, draftjsUtils$1.getSelectionEntity)(editorState);
  38581. if (entityKey) {
  38582. var entity = editorState.getCurrentContent().getEntity(entityKey);
  38583. if (entity && entity.get('type') === type) {
  38584. return entity.getData();
  38585. } else {
  38586. return {};
  38587. }
  38588. } else {
  38589. return {};
  38590. }
  38591. };
  38592. var toggleSelectionEntity = exports.toggleSelectionEntity = function toggleSelectionEntity(editorState, entity) {
  38593. var contentState = editorState.getCurrentContent();
  38594. var selectionState = editorState.getSelection();
  38595. if (selectionState.isCollapsed() || getSelectionBlockType(editorState) === 'atomic') {
  38596. return editorState;
  38597. }
  38598. if (!entity || !entity.type || getSelectionEntityType(editorState) === entity.type) {
  38599. return Draft.EditorState.push(editorState, Draft.Modifier.applyEntity(contentState, selectionState, null), 'apply-entity');
  38600. }
  38601. try {
  38602. var nextContentState = contentState.createEntity(entity.type, entity.mutability, entity.data);
  38603. var entityKey = nextContentState.getLastCreatedEntityKey();
  38604. var nextEditorState = Draft.EditorState.set(editorState, {
  38605. currentContent: nextContentState
  38606. });
  38607. return Draft.EditorState.push(nextEditorState, Draft.Modifier.applyEntity(nextContentState, selectionState, entityKey), 'apply-entity');
  38608. } catch (error) {
  38609. console.warn(error);
  38610. return editorState;
  38611. }
  38612. };
  38613. var toggleSelectionLink = exports.toggleSelectionLink = function toggleSelectionLink(editorState, href, target) {
  38614. var contentState = editorState.getCurrentContent();
  38615. var selectionState = editorState.getSelection();
  38616. var entityData = { href: href, target: target };
  38617. if (selectionState.isCollapsed() || getSelectionBlockType(editorState) === 'atomic') {
  38618. return editorState;
  38619. }
  38620. if (href === false) {
  38621. return Draft.RichUtils.toggleLink(editorState, selectionState, null);
  38622. }
  38623. if (href === null) {
  38624. delete entityData.href;
  38625. }
  38626. try {
  38627. var nextContentState = contentState.createEntity('LINK', 'MUTABLE', entityData);
  38628. var entityKey = nextContentState.getLastCreatedEntityKey();
  38629. var nextEditorState = Draft.EditorState.set(editorState, {
  38630. currentContent: nextContentState
  38631. });
  38632. nextEditorState = Draft.RichUtils.toggleLink(nextEditorState, selectionState, entityKey);
  38633. nextEditorState = Draft.EditorState.forceSelection(nextEditorState, selectionState.merge({
  38634. anchorOffset: selectionState.getEndOffset(),
  38635. focusOffset: selectionState.getEndOffset()
  38636. }));
  38637. nextEditorState = Draft.EditorState.push(nextEditorState, Draft.Modifier.insertText(nextEditorState.getCurrentContent(), nextEditorState.getSelection(), ''), 'insert-text');
  38638. return nextEditorState;
  38639. } catch (error) {
  38640. console.warn(error);
  38641. return editorState;
  38642. }
  38643. };
  38644. var getSelectionInlineStyle = exports.getSelectionInlineStyle = function getSelectionInlineStyle(editorState) {
  38645. return editorState.getCurrentInlineStyle();
  38646. };
  38647. var selectionHasInlineStyle = exports.selectionHasInlineStyle = function selectionHasInlineStyle(editorState, style) {
  38648. return getSelectionInlineStyle(editorState).has(style.toUpperCase());
  38649. };
  38650. var toggleSelectionInlineStyle = exports.toggleSelectionInlineStyle = function toggleSelectionInlineStyle(editorState, style) {
  38651. var prefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
  38652. var nextEditorState = editorState;
  38653. style = prefix + style.toUpperCase();
  38654. if (prefix) {
  38655. nextEditorState = updateEachCharacterOfSelection(nextEditorState, function (characterMetadata) {
  38656. return characterMetadata.toJS().style.reduce(function (characterMetadata, characterStyle) {
  38657. if (characterStyle.indexOf(prefix) === 0 && style !== characterStyle) {
  38658. return Draft.CharacterMetadata.removeStyle(characterMetadata, characterStyle);
  38659. } else {
  38660. return characterMetadata;
  38661. }
  38662. }, characterMetadata);
  38663. });
  38664. }
  38665. return Draft.RichUtils.toggleInlineStyle(nextEditorState, style);
  38666. };
  38667. var removeSelectionInlineStyles = exports.removeSelectionInlineStyles = function removeSelectionInlineStyles(editorState) {
  38668. return updateEachCharacterOfSelection(editorState, function (characterMetadata) {
  38669. return characterMetadata.merge({
  38670. style: _immutable2.default.OrderedSet([])
  38671. });
  38672. });
  38673. };
  38674. var toggleSelectionAlignment = exports.toggleSelectionAlignment = function toggleSelectionAlignment(editorState, alignment) {
  38675. return setSelectionBlockData(editorState, {
  38676. textAlign: getSelectionBlockData(editorState, 'textAlign') !== alignment ? alignment : undefined
  38677. });
  38678. };
  38679. var toggleSelectionIndent = exports.toggleSelectionIndent = function toggleSelectionIndent(editorState, textIndent) {
  38680. var maxIndent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 6;
  38681. return textIndent < 0 || textIndent > maxIndent || isNaN(textIndent) ? editorState : setSelectionBlockData(editorState, {
  38682. textIndent: textIndent || undefined
  38683. });
  38684. };
  38685. var increaseSelectionIndent = exports.increaseSelectionIndent = function increaseSelectionIndent(editorState) {
  38686. var maxIndent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 6;
  38687. var currentIndent = getSelectionBlockData(editorState, 'textIndent') || 0;
  38688. return toggleSelectionIndent(editorState, currentIndent + 1, maxIndent);
  38689. };
  38690. var decreaseSelectionIndent = exports.decreaseSelectionIndent = function decreaseSelectionIndent(editorState) {
  38691. var currentIndent = getSelectionBlockData(editorState, 'textIndent') || 0;
  38692. return toggleSelectionIndent(editorState, currentIndent - 1);
  38693. };
  38694. var toggleSelectionColor = exports.toggleSelectionColor = function toggleSelectionColor(editorState, color) {
  38695. return toggleSelectionInlineStyle(editorState, color.replace('#', ''), 'COLOR-');
  38696. };
  38697. var toggleSelectionBackgroundColor = exports.toggleSelectionBackgroundColor = function toggleSelectionBackgroundColor(editorState, color) {
  38698. return toggleSelectionInlineStyle(editorState, color.replace('#', ''), 'BGCOLOR-');
  38699. };
  38700. var toggleSelectionFontSize = exports.toggleSelectionFontSize = function toggleSelectionFontSize(editorState, fontSize) {
  38701. return toggleSelectionInlineStyle(editorState, fontSize, 'FONTSIZE-');
  38702. };
  38703. var toggleSelectionLineHeight = exports.toggleSelectionLineHeight = function toggleSelectionLineHeight(editorState, lineHeight) {
  38704. return toggleSelectionInlineStyle(editorState, lineHeight, 'LINEHEIGHT-');
  38705. };
  38706. var toggleSelectionFontFamily = exports.toggleSelectionFontFamily = function toggleSelectionFontFamily(editorState, fontFamily) {
  38707. return toggleSelectionInlineStyle(editorState, fontFamily, 'FONTFAMILY-');
  38708. };
  38709. var toggleSelectionLetterSpacing = exports.toggleSelectionLetterSpacing = function toggleSelectionLetterSpacing(editorState, letterSpacing) {
  38710. return toggleSelectionInlineStyle(editorState, letterSpacing, 'LETTERSPACING-');
  38711. };
  38712. var insertText = exports.insertText = function insertText(editorState, text, inlineStyle, entity) {
  38713. var selectionState = editorState.getSelection();
  38714. var currentSelectedBlockType = getSelectionBlockType(editorState);
  38715. if (currentSelectedBlockType === 'atomic') {
  38716. return editorState;
  38717. }
  38718. var entityKey = void 0;
  38719. var contentState = editorState.getCurrentContent();
  38720. if (entity && entity.type) {
  38721. contentState = contentState.createEntity(entity.type, entity.mutability || 'MUTABLE', entity.data || entityData);
  38722. entityKey = contentState.getLastCreatedEntityKey();
  38723. }
  38724. if (!selectionState.isCollapsed()) {
  38725. return Draft.EditorState.push(editorState, Draft.Modifier.replaceText(contentState, selectionState, text, inlineStyle, entityKey), 'replace-text');
  38726. } else {
  38727. return Draft.EditorState.push(editorState, Draft.Modifier.insertText(contentState, selectionState, text, inlineStyle, entityKey), 'insert-text');
  38728. }
  38729. };
  38730. var insertHTML = exports.insertHTML = function insertHTML(editorState, htmlString, source) {
  38731. if (!htmlString) {
  38732. return editorState;
  38733. }
  38734. var selectionState = editorState.getSelection();
  38735. var contentState = editorState.getCurrentContent();
  38736. var options = editorState.convertOptions || {};
  38737. try {
  38738. var _convertFromRaw = (0, Draft.convertFromRaw)((0, dist.convertHTMLToRaw)(htmlString, options, source)),
  38739. blockMap = _convertFromRaw.blockMap;
  38740. return Draft.EditorState.push(editorState, Draft.Modifier.replaceWithFragment(contentState, selectionState, blockMap), 'insert-fragment');
  38741. } catch (error) {
  38742. console.warn(error);
  38743. return editorState;
  38744. }
  38745. };
  38746. var insertAtomicBlock = exports.insertAtomicBlock = function insertAtomicBlock(editorState, type) {
  38747. var immutable = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
  38748. var data = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
  38749. if (selectionContainsStrictBlock(editorState)) {
  38750. return insertAtomicBlock(selectNextBlock(editorState, getSelectionBlock(editorState)), type, immutable, data);
  38751. }
  38752. var selectionState = editorState.getSelection();
  38753. var contentState = editorState.getCurrentContent();
  38754. if (!selectionState.isCollapsed() || getSelectionBlockType(editorState) === 'atomic') {
  38755. return editorState;
  38756. }
  38757. var contentStateWithEntity = contentState.createEntity(type, immutable ? 'IMMUTABLE' : 'MUTABLE', data);
  38758. var entityKey = contentStateWithEntity.getLastCreatedEntityKey();
  38759. var newEditorState = Draft.AtomicBlockUtils.insertAtomicBlock(editorState, entityKey, ' ');
  38760. return newEditorState;
  38761. };
  38762. var insertHorizontalLine = exports.insertHorizontalLine = function insertHorizontalLine(editorState) {
  38763. return insertAtomicBlock(editorState, 'HR');
  38764. };
  38765. var insertMedias = exports.insertMedias = function insertMedias(editorState) {
  38766. var medias = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  38767. if (!medias.length) {
  38768. return editorState;
  38769. }
  38770. return medias.reduce(function (editorState, media) {
  38771. var url = media.url,
  38772. link = media.link,
  38773. link_target = media.link_target,
  38774. name = media.name,
  38775. type = media.type,
  38776. width = media.width,
  38777. height = media.height,
  38778. meta = media.meta;
  38779. return insertAtomicBlock(editorState, type, true, { url: url, link: link, link_target: link_target, name: name, type: type, width: width, height: height, meta: meta });
  38780. }, editorState);
  38781. };
  38782. var setMediaData = exports.setMediaData = function setMediaData(editorState, entityKey, data) {
  38783. return Draft.EditorState.push(editorState, editorState.getCurrentContent().mergeEntityData(entityKey, data), 'change-block-data');
  38784. };
  38785. var removeMedia = exports.removeMedia = function removeMedia(editorState, mediaBlock) {
  38786. return removeBlock(editorState, mediaBlock);
  38787. };
  38788. var setMediaPosition = exports.setMediaPosition = function setMediaPosition(editorState, mediaBlock, position) {
  38789. var newPosition = {};
  38790. var float = position.float,
  38791. alignment = position.alignment;
  38792. if (typeof float !== 'undefined') {
  38793. newPosition.float = mediaBlock.getData().get('float') === float ? null : float;
  38794. }
  38795. if (typeof alignment !== 'undefined') {
  38796. newPosition.alignment = mediaBlock.getData().get('alignment') === alignment ? null : alignment;
  38797. }
  38798. return setSelectionBlockData(selectBlock(editorState, mediaBlock), newPosition);
  38799. };
  38800. var clear = exports.clear = function clear(editorState) {
  38801. var contentState = editorState.getCurrentContent();
  38802. var firstBlock = contentState.getFirstBlock();
  38803. var lastBlock = contentState.getLastBlock();
  38804. var allSelected = new Draft.SelectionState({
  38805. anchorKey: firstBlock.getKey(),
  38806. anchorOffset: 0,
  38807. focusKey: lastBlock.getKey(),
  38808. focusOffset: lastBlock.getLength(),
  38809. hasFocus: true
  38810. });
  38811. return Draft.RichUtils.toggleBlockType(Draft.EditorState.push(editorState, Draft.Modifier.removeRange(contentState, allSelected, 'backward'), 'remove-range'), 'unstyled');
  38812. };
  38813. var handleKeyCommand = exports.handleKeyCommand = function handleKeyCommand(editorState, command) {
  38814. return Draft.RichUtils.handleKeyCommand(editorState, command);
  38815. };
  38816. var undo = exports.undo = function undo(editorState) {
  38817. return Draft.EditorState.undo(editorState);
  38818. };
  38819. var redo = exports.redo = function redo(editorState) {
  38820. return Draft.EditorState.redo(editorState);
  38821. };
  38822. });
  38823. _commonjsHelpers.unwrapExports(content$1);
  38824. var content_1$1 = content$1.redo;
  38825. var content_2$1 = content$1.undo;
  38826. var content_3$1 = content$1.handleKeyCommand;
  38827. var content_4$1 = content$1.clear;
  38828. var content_5$1 = content$1.setMediaPosition;
  38829. var content_6$1 = content$1.removeMedia;
  38830. var content_7$1 = content$1.setMediaData;
  38831. var content_8$1 = content$1.insertMedias;
  38832. var content_9$1 = content$1.insertHorizontalLine;
  38833. var content_10$1 = content$1.insertAtomicBlock;
  38834. var content_11$1 = content$1.insertHTML;
  38835. var content_12$1 = content$1.insertText;
  38836. var content_13$1 = content$1.toggleSelectionLetterSpacing;
  38837. var content_14$1 = content$1.toggleSelectionFontFamily;
  38838. var content_15$1 = content$1.toggleSelectionLineHeight;
  38839. var content_16$1 = content$1.toggleSelectionFontSize;
  38840. var content_17$1 = content$1.toggleSelectionBackgroundColor;
  38841. var content_18$1 = content$1.toggleSelectionColor;
  38842. var content_19$1 = content$1.decreaseSelectionIndent;
  38843. var content_20$1 = content$1.increaseSelectionIndent;
  38844. var content_21$1 = content$1.toggleSelectionIndent;
  38845. var content_22$1 = content$1.toggleSelectionAlignment;
  38846. var content_23$1 = content$1.removeSelectionInlineStyles;
  38847. var content_24$1 = content$1.toggleSelectionInlineStyle;
  38848. var content_25$1 = content$1.selectionHasInlineStyle;
  38849. var content_26$1 = content$1.getSelectionInlineStyle;
  38850. var content_27$1 = content$1.toggleSelectionLink;
  38851. var content_28$1 = content$1.toggleSelectionEntity;
  38852. var content_29$1 = content$1.getSelectionEntityData;
  38853. var content_30$1 = content$1.getSelectionEntityType;
  38854. var content_31$1 = content$1.toggleSelectionBlockType;
  38855. var content_32$1 = content$1.getSelectionText;
  38856. var content_33$1 = content$1.getSelectionBlockType;
  38857. var content_34$1 = content$1.getSelectionBlockData;
  38858. var content_35$1 = content$1.setSelectionBlockData;
  38859. var content_36$1 = content$1.getSelectedBlocks;
  38860. var content_37$1 = content$1.updateEachCharacterOfSelection;
  38861. var content_38$1 = content$1.getSelectionBlock;
  38862. var content_39$1 = content$1.removeBlock;
  38863. var content_40$1 = content$1.selectNextBlock;
  38864. var content_41$1 = content$1.selectBlock;
  38865. var content_42$1 = content$1.selectionContainsStrictBlock;
  38866. var content_43$1 = content$1.selectionContainsBlockType;
  38867. var content_44$1 = content$1.isSelectionCollapsed;
  38868. var content_45$1 = content$1.createEditorState;
  38869. var content_46$1 = content$1.createEmptyEditorState;
  38870. var content_47$1 = content$1.isEditorState;
  38871. var content_48$1 = content$1.registerStrictBlockType;
  38872. var base$1 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
  38873. Object.defineProperty(exports, "__esModule", {
  38874. value: true
  38875. });
  38876. var braftUniqueIndex = 0;
  38877. var UniqueIndex = exports.UniqueIndex = function UniqueIndex() {
  38878. return braftUniqueIndex += 1;
  38879. };
  38880. });
  38881. _commonjsHelpers.unwrapExports(base$1);
  38882. var base_1$1 = base$1.UniqueIndex;
  38883. var color$1 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
  38884. Object.defineProperty(exports, "__esModule", {
  38885. value: true
  38886. });
  38887. var _namedColors = {
  38888. "aliceblue": "#f0f8ff",
  38889. "antiquewhite": "#faebd7",
  38890. "aqua": "#00ffff",
  38891. "aquamarine": "#7fffd4",
  38892. "azure": "#f0ffff",
  38893. "beige": "#f5f5dc",
  38894. "bisque": "#ffe4c4",
  38895. "black": "#000000",
  38896. "blanchedalmond": "#ffebcd",
  38897. "blue": "#0000ff",
  38898. "blueviolet": "#8a2be2",
  38899. "brown": "#a52a2a",
  38900. "burlywood": "#deb887",
  38901. "cadetblue": "#5f9ea0",
  38902. "chartreuse": "#7fff00",
  38903. "chocolate": "#d2691e",
  38904. "coral": "#ff7f50",
  38905. "cornflowerblue": "#6495ed",
  38906. "cornsilk": "#fff8dc",
  38907. "crimson": "#dc143c",
  38908. "cyan": "#00ffff",
  38909. "darkblue": "#00008b",
  38910. "darkcyan": "#008b8b",
  38911. "darkgoldenrod": "#b8860b",
  38912. "darkgray": "#a9a9a9",
  38913. "darkgreen": "#006400",
  38914. "darkkhaki": "#bdb76b",
  38915. "darkmagenta": "#8b008b",
  38916. "darkolivegreen": "#556b2f",
  38917. "darkorange": "#ff8c00",
  38918. "darkorchid": "#9932cc",
  38919. "darkred": "#8b0000",
  38920. "darksalmon": "#e9967a",
  38921. "darkseagreen": "#8fbc8f",
  38922. "darkslateblue": "#483d8b",
  38923. "darkslategray": "#2f4f4f",
  38924. "darkturquoise": "#00ced1",
  38925. "darkviolet": "#9400d3",
  38926. "deeppink": "#ff1493",
  38927. "deepskyblue": "#00bfff",
  38928. "dimgray": "#696969",
  38929. "dodgerblue": "#1e90ff",
  38930. "firebrick": "#b22222",
  38931. "floralwhite": "#fffaf0",
  38932. "forestgreen": "#228b22",
  38933. "fuchsia": "#ff00ff",
  38934. "gainsboro": "#dcdcdc",
  38935. "ghostwhite": "#f8f8ff",
  38936. "gold": "#ffd700",
  38937. "goldenrod": "#daa520",
  38938. "gray": "#808080",
  38939. "green": "#008000",
  38940. "greenyellow": "#adff2f",
  38941. "honeydew": "#f0fff0",
  38942. "hotpink": "#ff69b4",
  38943. "indianred ": "#cd5c5c",
  38944. "indigo": "#4b0082",
  38945. "ivory": "#fffff0",
  38946. "khaki": "#f0e68c",
  38947. "lavender": "#e6e6fa",
  38948. "lavenderblush": "#fff0f5",
  38949. "lawngreen": "#7cfc00",
  38950. "lemonchiffon": "#fffacd",
  38951. "lightblue": "#add8e6",
  38952. "lightcoral": "#f08080",
  38953. "lightcyan": "#e0ffff",
  38954. "lightgoldenrodyellow": "#fafad2",
  38955. "lightgrey": "#d3d3d3",
  38956. "lightgreen": "#90ee90",
  38957. "lightpink": "#ffb6c1",
  38958. "lightsalmon": "#ffa07a",
  38959. "lightseagreen": "#20b2aa",
  38960. "lightskyblue": "#87cefa",
  38961. "lightslategray": "#778899",
  38962. "lightsteelblue": "#b0c4de",
  38963. "lightyellow": "#ffffe0",
  38964. "lime": "#00ff00",
  38965. "limegreen": "#32cd32",
  38966. "linen": "#faf0e6",
  38967. "magenta": "#ff00ff",
  38968. "maroon": "#800000",
  38969. "mediumaquamarine": "#66cdaa",
  38970. "mediumblue": "#0000cd",
  38971. "mediumorchid": "#ba55d3",
  38972. "mediumpurple": "#9370d8",
  38973. "mediumseagreen": "#3cb371",
  38974. "mediumslateblue": "#7b68ee",
  38975. "mediumspringgreen": "#00fa9a",
  38976. "mediumturquoise": "#48d1cc",
  38977. "mediumvioletred": "#c71585",
  38978. "midnightblue": "#191970",
  38979. "mintcream": "#f5fffa",
  38980. "mistyrose": "#ffe4e1",
  38981. "moccasin": "#ffe4b5",
  38982. "navajowhite": "#ffdead",
  38983. "navy": "#000080",
  38984. "oldlace": "#fdf5e6",
  38985. "olive": "#808000",
  38986. "olivedrab": "#6b8e23",
  38987. "orange": "#ffa500",
  38988. "orangered": "#ff4500",
  38989. "orchid": "#da70d6",
  38990. "palegoldenrod": "#eee8aa",
  38991. "palegreen": "#98fb98",
  38992. "paleturquoise": "#afeeee",
  38993. "palevioletred": "#d87093",
  38994. "papayawhip": "#ffefd5",
  38995. "peachpuff": "#ffdab9",
  38996. "peru": "#cd853f",
  38997. "pink": "#ffc0cb",
  38998. "plum": "#dda0dd",
  38999. "powderblue": "#b0e0e6",
  39000. "purple": "#800080",
  39001. "rebeccapurple": "#663399",
  39002. "red": "#ff0000",
  39003. "rosybrown": "#bc8f8f",
  39004. "royalblue": "#4169e1",
  39005. "saddlebrown": "#8b4513",
  39006. "salmon": "#fa8072",
  39007. "sandybrown": "#f4a460",
  39008. "seagreen": "#2e8b57",
  39009. "seashell": "#fff5ee",
  39010. "sienna": "#a0522d",
  39011. "silver": "#c0c0c0",
  39012. "skyblue": "#87ceeb",
  39013. "slateblue": "#6a5acd",
  39014. "slategray": "#708090",
  39015. "snow": "#fffafa",
  39016. "springgreen": "#00ff7f",
  39017. "steelblue": "#4682b4",
  39018. "tan": "#d2b48c",
  39019. "teal": "#008080",
  39020. "thistle": "#d8bfd8",
  39021. "tomato": "#ff6347",
  39022. "turquoise": "#40e0d0",
  39023. "violet": "#ee82ee",
  39024. "wheat": "#f5deb3",
  39025. "white": "#ffffff",
  39026. "whitesmoke": "#f5f5f5",
  39027. "yellow": "#ffff00",
  39028. "yellowgreen": "#9acd32"
  39029. };
  39030. var _getHexColor = function _getHexColor(color) {
  39031. color = color.replace('color:', '').replace(';', '').replace(' ', '');
  39032. if (/^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/.test(color)) {
  39033. return color;
  39034. } else if (namedColors[color]) {
  39035. return namedColors[color];
  39036. } else if (color.indexOf('rgb') === 0) {
  39037. var rgbArray = color.split(',');
  39038. var convertedColor = rgbArray.length < 3 ? null : '#' + [rgbArray[0], rgbArray[1], rgbArray[2]].map(function (x) {
  39039. var hex = parseInt(x.replace(/\D/g, ''), 10).toString(16);
  39040. return hex.length === 1 ? '0' + hex : hex;
  39041. }).join('');
  39042. return (/^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/.test(convertedColor) ? convertedColor : null
  39043. );
  39044. } else {
  39045. return null;
  39046. }
  39047. };
  39048. var namedColors = exports.namedColors = _namedColors;
  39049. var getHexColor = exports.getHexColor = _getHexColor;
  39050. var detectColorsFromHTMLString = exports.detectColorsFromHTMLString = function detectColorsFromHTMLString(html) {
  39051. return typeof html !== 'string' ? [] : (html.match(/color:[^;]{3,24};/g) || []).map(getHexColor).filter(function (color) {
  39052. return color;
  39053. });
  39054. };
  39055. var detectColorsFromDraftState = exports.detectColorsFromDraftState = function detectColorsFromDraftState(draftState) {
  39056. var result = [];
  39057. if (!draftState || !draftState.blocks || !draftState.blocks.length) {
  39058. return result;
  39059. }
  39060. draftState.blocks.forEach(function (block) {
  39061. if (block && block.inlineStyleRanges && block.inlineStyleRanges.length) {
  39062. block.inlineStyleRanges.forEach(function (inlineStyle) {
  39063. if (inlineStyle.style && inlineStyle.style.indexOf('COLOR-') >= 0) {
  39064. result.push('#' + inlineStyle.style.split('COLOR-')[1]);
  39065. }
  39066. });
  39067. }
  39068. });
  39069. return result.filter(function (color) {
  39070. return color;
  39071. });
  39072. };
  39073. });
  39074. _commonjsHelpers.unwrapExports(color$1);
  39075. var color_1$1 = color$1.namedColors;
  39076. var color_2$1 = color$1.getHexColor;
  39077. var color_3$1 = color$1.detectColorsFromHTMLString;
  39078. var color_4$1 = color$1.detectColorsFromDraftState;
  39079. var dist$4 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
  39080. Object.defineProperty(exports, "__esModule", {
  39081. value: true
  39082. });
  39083. exports.ColorUtils = exports.BaseUtils = exports.ContentUtils = undefined;
  39084. var _ContentUtils = _interopRequireWildcard(content$1);
  39085. var _BaseUtils = _interopRequireWildcard(base$1);
  39086. var _ColorUtils = _interopRequireWildcard(color$1);
  39087. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  39088. var ContentUtils = exports.ContentUtils = _ContentUtils;
  39089. var BaseUtils = exports.BaseUtils = _BaseUtils;
  39090. var ColorUtils = exports.ColorUtils = _ColorUtils;
  39091. });
  39092. _commonjsHelpers.unwrapExports(dist$4);
  39093. var dist_1$2 = dist$4.ColorUtils;
  39094. var dist_2$2 = dist$4.BaseUtils;
  39095. var dist_3$2 = dist$4.ContentUtils;
  39096. var emoticon = _commonjsHelpers.createCommonjsModule(function (module, exports) {
  39097. (function webpackUniversalModuleDefinition(root, factory) {
  39098. module.exports = factory(React__default, dist$4);
  39099. })(window, function(__WEBPACK_EXTERNAL_MODULE__1__, __WEBPACK_EXTERNAL_MODULE__6__) {
  39100. return /******/ (function(modules) { // webpackBootstrap
  39101. /******/ // The module cache
  39102. /******/ var installedModules = {};
  39103. /******/
  39104. /******/ // The require function
  39105. /******/ function __webpack_require__(moduleId) {
  39106. /******/
  39107. /******/ // Check if module is in cache
  39108. /******/ if(installedModules[moduleId]) {
  39109. /******/ return installedModules[moduleId].exports;
  39110. /******/ }
  39111. /******/ // Create a new module (and put it into the cache)
  39112. /******/ var module = installedModules[moduleId] = {
  39113. /******/ i: moduleId,
  39114. /******/ l: false,
  39115. /******/ exports: {}
  39116. /******/ };
  39117. /******/
  39118. /******/ // Execute the module function
  39119. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  39120. /******/
  39121. /******/ // Flag the module as loaded
  39122. /******/ module.l = true;
  39123. /******/
  39124. /******/ // Return the exports of the module
  39125. /******/ return module.exports;
  39126. /******/ }
  39127. /******/
  39128. /******/
  39129. /******/ // expose the modules object (__webpack_modules__)
  39130. /******/ __webpack_require__.m = modules;
  39131. /******/
  39132. /******/ // expose the module cache
  39133. /******/ __webpack_require__.c = installedModules;
  39134. /******/
  39135. /******/ // define getter function for harmony exports
  39136. /******/ __webpack_require__.d = function(exports, name, getter) {
  39137. /******/ if(!__webpack_require__.o(exports, name)) {
  39138. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  39139. /******/ }
  39140. /******/ };
  39141. /******/
  39142. /******/ // define __esModule on exports
  39143. /******/ __webpack_require__.r = function(exports) {
  39144. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  39145. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  39146. /******/ }
  39147. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  39148. /******/ };
  39149. /******/
  39150. /******/ // create a fake namespace object
  39151. /******/ // mode & 1: value is a module id, require it
  39152. /******/ // mode & 2: merge all properties of value into the ns
  39153. /******/ // mode & 4: return value when already ns object
  39154. /******/ // mode & 8|1: behave like require
  39155. /******/ __webpack_require__.t = function(value, mode) {
  39156. /******/ if(mode & 1) value = __webpack_require__(value);
  39157. /******/ if(mode & 8) return value;
  39158. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  39159. /******/ var ns = Object.create(null);
  39160. /******/ __webpack_require__.r(ns);
  39161. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  39162. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  39163. /******/ return ns;
  39164. /******/ };
  39165. /******/
  39166. /******/ // getDefaultExport function for compatibility with non-harmony modules
  39167. /******/ __webpack_require__.n = function(module) {
  39168. /******/ var getter = module && module.__esModule ?
  39169. /******/ function getDefault() { return module['default']; } :
  39170. /******/ function getModuleExports() { return module; };
  39171. /******/ __webpack_require__.d(getter, 'a', getter);
  39172. /******/ return getter;
  39173. /******/ };
  39174. /******/
  39175. /******/ // Object.prototype.hasOwnProperty.call
  39176. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  39177. /******/
  39178. /******/ // __webpack_public_path__
  39179. /******/ __webpack_require__.p = "/";
  39180. /******/
  39181. /******/
  39182. /******/ // Load entry module and return exports
  39183. /******/ return __webpack_require__(__webpack_require__.s = 33);
  39184. /******/ })
  39185. /************************************************************************/
  39186. /******/ ({
  39187. /***/ 1:
  39188. /***/ (function(module, exports) {
  39189. module.exports = __WEBPACK_EXTERNAL_MODULE__1__;
  39190. /***/ }),
  39191. /***/ 2:
  39192. /***/ (function(module, exports) {
  39193. function _defineProperty(obj, key, value) {
  39194. if (key in obj) {
  39195. Object.defineProperty(obj, key, {
  39196. value: value,
  39197. enumerable: true,
  39198. configurable: true,
  39199. writable: true
  39200. });
  39201. } else {
  39202. obj[key] = value;
  39203. }
  39204. return obj;
  39205. }
  39206. module.exports = _defineProperty;
  39207. /***/ }),
  39208. /***/ 33:
  39209. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  39210. __webpack_require__.r(__webpack_exports__);
  39211. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "defaultEmoticons", function() { return defaultEmoticons; });
  39212. /* harmony import */ var _babel_runtime_helpers_objectSpread__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(5);
  39213. /* harmony import */ var _babel_runtime_helpers_objectSpread__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_objectSpread__WEBPACK_IMPORTED_MODULE_0__);
  39214. /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1);
  39215. /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_1__);
  39216. /* harmony import */ var braft_utils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6);
  39217. /* harmony import */ var _styles_scss__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(48);
  39218. // https://www.iconfinder.com/iconsets/emoji-18
  39219. var defaultEmoticons = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25].map(function (item) {
  39220. return "".concat(item, ".png");
  39221. });
  39222. var insertEmoticon = function insertEmoticon(editor, editorState, src) {
  39223. editor.setValue(braft_utils__WEBPACK_IMPORTED_MODULE_2__["ContentUtils"].insertText(editorState, ' ', null, {
  39224. type: 'EMOTICON',
  39225. mutability: 'IMMUTABLE',
  39226. data: {
  39227. src: src
  39228. }
  39229. }));
  39230. };
  39231. var controlRef = null;
  39232. var bindControlRef = function bindControlRef(ref) {
  39233. return controlRef = ref;
  39234. };
  39235. /* harmony default export */ __webpack_exports__["default"] = (function (options) {
  39236. options = _babel_runtime_helpers_objectSpread__WEBPACK_IMPORTED_MODULE_0___default()({
  39237. emoticons: [],
  39238. closeOnSelect: false,
  39239. closeOnBlur: false
  39240. }, options);
  39241. var _options = options,
  39242. emoticons = _options.emoticons,
  39243. closeOnSelect = _options.closeOnSelect,
  39244. closeOnBlur = _options.closeOnBlur,
  39245. includeEditors = _options.includeEditors,
  39246. excludeEditors = _options.excludeEditors;
  39247. return {
  39248. type: 'entity',
  39249. includeEditors: includeEditors,
  39250. excludeEditors: excludeEditors,
  39251. name: 'EMOTICON',
  39252. control: function control(props) {
  39253. return {
  39254. key: 'EMOTICON',
  39255. replace: 'emoji',
  39256. type: 'dropdown',
  39257. text: react__WEBPACK_IMPORTED_MODULE_1___default.a.createElement("i", {
  39258. className: "bfi-emoji"
  39259. }),
  39260. showArrow: false,
  39261. ref: bindControlRef,
  39262. autoHide: closeOnBlur,
  39263. component: react__WEBPACK_IMPORTED_MODULE_1___default.a.createElement("div", {
  39264. className: "braft-emoticon-picker"
  39265. }, react__WEBPACK_IMPORTED_MODULE_1___default.a.createElement("div", {
  39266. className: "braft-emoticons-list"
  39267. }, emoticons.map(function (item, index) {
  39268. return react__WEBPACK_IMPORTED_MODULE_1___default.a.createElement("img", {
  39269. onClick: function onClick() {
  39270. insertEmoticon(props.editor, props.editorState, item);
  39271. closeOnSelect && controlRef && controlRef.hide();
  39272. },
  39273. key: index,
  39274. src: item
  39275. });
  39276. })))
  39277. };
  39278. },
  39279. mutability: 'IMMUTABLE',
  39280. component: function component(props) {
  39281. var entity = props.contentState.getEntity(props.entityKey);
  39282. var _entity$getData = entity.getData(),
  39283. src = _entity$getData.src;
  39284. return react__WEBPACK_IMPORTED_MODULE_1___default.a.createElement("span", {
  39285. className: "braft-emoticon-in-editor"
  39286. }, react__WEBPACK_IMPORTED_MODULE_1___default.a.createElement("img", {
  39287. src: src
  39288. }), props.children);
  39289. },
  39290. importer: function importer(nodeName, node) {
  39291. if (nodeName.toLowerCase() === 'span' && node.classList && node.classList.contains('braft-emoticon-wrap')) {
  39292. var imgNode = node.querySelector('img');
  39293. var src = imgNode.getAttribute('src'); // 移除img节点以避免生成atomic block
  39294. node.removeChild(imgNode);
  39295. return {
  39296. mutability: 'IMMUTABLE',
  39297. data: {
  39298. src: src
  39299. }
  39300. };
  39301. }
  39302. },
  39303. exporter: function exporter(entityObject, initialText) {
  39304. var src = entityObject.data.src;
  39305. return react__WEBPACK_IMPORTED_MODULE_1___default.a.createElement("span", {
  39306. className: "braft-emoticon-wrap"
  39307. }, react__WEBPACK_IMPORTED_MODULE_1___default.a.createElement("img", {
  39308. src: src
  39309. }), initialText);
  39310. }
  39311. };
  39312. });
  39313. /***/ }),
  39314. /***/ 48:
  39315. /***/ (function(module, exports) {
  39316. // removed by extract-text-webpack-plugin
  39317. /***/ }),
  39318. /***/ 5:
  39319. /***/ (function(module, exports, __webpack_require__) {
  39320. var defineProperty = __webpack_require__(2);
  39321. function _objectSpread(target) {
  39322. for (var i = 1; i < arguments.length; i++) {
  39323. var source = arguments[i] != null ? arguments[i] : {};
  39324. var ownKeys = Object.keys(source);
  39325. if (typeof Object.getOwnPropertySymbols === 'function') {
  39326. ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
  39327. return Object.getOwnPropertyDescriptor(source, sym).enumerable;
  39328. }));
  39329. }
  39330. ownKeys.forEach(function (key) {
  39331. defineProperty(target, key, source[key]);
  39332. });
  39333. }
  39334. return target;
  39335. }
  39336. module.exports = _objectSpread;
  39337. /***/ }),
  39338. /***/ 6:
  39339. /***/ (function(module, exports) {
  39340. module.exports = __WEBPACK_EXTERNAL_MODULE__6__;
  39341. /***/ })
  39342. /******/ });
  39343. });
  39344. });
  39345. var Emoticon = _commonjsHelpers.unwrapExports(emoticon);
  39346. var emoticon_1 = emoticon.defaultEmoticons;
  39347. var maxLength = _commonjsHelpers.createCommonjsModule(function (module, exports) {
  39348. (function webpackUniversalModuleDefinition(root, factory) {
  39349. module.exports = factory();
  39350. })(window, function() {
  39351. return /******/ (function(modules) { // webpackBootstrap
  39352. /******/ // The module cache
  39353. /******/ var installedModules = {};
  39354. /******/
  39355. /******/ // The require function
  39356. /******/ function __webpack_require__(moduleId) {
  39357. /******/
  39358. /******/ // Check if module is in cache
  39359. /******/ if(installedModules[moduleId]) {
  39360. /******/ return installedModules[moduleId].exports;
  39361. /******/ }
  39362. /******/ // Create a new module (and put it into the cache)
  39363. /******/ var module = installedModules[moduleId] = {
  39364. /******/ i: moduleId,
  39365. /******/ l: false,
  39366. /******/ exports: {}
  39367. /******/ };
  39368. /******/
  39369. /******/ // Execute the module function
  39370. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  39371. /******/
  39372. /******/ // Flag the module as loaded
  39373. /******/ module.l = true;
  39374. /******/
  39375. /******/ // Return the exports of the module
  39376. /******/ return module.exports;
  39377. /******/ }
  39378. /******/
  39379. /******/
  39380. /******/ // expose the modules object (__webpack_modules__)
  39381. /******/ __webpack_require__.m = modules;
  39382. /******/
  39383. /******/ // expose the module cache
  39384. /******/ __webpack_require__.c = installedModules;
  39385. /******/
  39386. /******/ // define getter function for harmony exports
  39387. /******/ __webpack_require__.d = function(exports, name, getter) {
  39388. /******/ if(!__webpack_require__.o(exports, name)) {
  39389. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  39390. /******/ }
  39391. /******/ };
  39392. /******/
  39393. /******/ // define __esModule on exports
  39394. /******/ __webpack_require__.r = function(exports) {
  39395. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  39396. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  39397. /******/ }
  39398. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  39399. /******/ };
  39400. /******/
  39401. /******/ // create a fake namespace object
  39402. /******/ // mode & 1: value is a module id, require it
  39403. /******/ // mode & 2: merge all properties of value into the ns
  39404. /******/ // mode & 4: return value when already ns object
  39405. /******/ // mode & 8|1: behave like require
  39406. /******/ __webpack_require__.t = function(value, mode) {
  39407. /******/ if(mode & 1) value = __webpack_require__(value);
  39408. /******/ if(mode & 8) return value;
  39409. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  39410. /******/ var ns = Object.create(null);
  39411. /******/ __webpack_require__.r(ns);
  39412. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  39413. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  39414. /******/ return ns;
  39415. /******/ };
  39416. /******/
  39417. /******/ // getDefaultExport function for compatibility with non-harmony modules
  39418. /******/ __webpack_require__.n = function(module) {
  39419. /******/ var getter = module && module.__esModule ?
  39420. /******/ function getDefault() { return module['default']; } :
  39421. /******/ function getModuleExports() { return module; };
  39422. /******/ __webpack_require__.d(getter, 'a', getter);
  39423. /******/ return getter;
  39424. /******/ };
  39425. /******/
  39426. /******/ // Object.prototype.hasOwnProperty.call
  39427. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  39428. /******/
  39429. /******/ // __webpack_public_path__
  39430. /******/ __webpack_require__.p = "/";
  39431. /******/
  39432. /******/
  39433. /******/ // Load entry module and return exports
  39434. /******/ return __webpack_require__(__webpack_require__.s = 34);
  39435. /******/ })
  39436. /************************************************************************/
  39437. /******/ ({
  39438. /***/ 2:
  39439. /***/ (function(module, exports) {
  39440. function _defineProperty(obj, key, value) {
  39441. if (key in obj) {
  39442. Object.defineProperty(obj, key, {
  39443. value: value,
  39444. enumerable: true,
  39445. configurable: true,
  39446. writable: true
  39447. });
  39448. } else {
  39449. obj[key] = value;
  39450. }
  39451. return obj;
  39452. }
  39453. module.exports = _defineProperty;
  39454. /***/ }),
  39455. /***/ 34:
  39456. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  39457. __webpack_require__.r(__webpack_exports__);
  39458. /* harmony import */ var _babel_runtime_helpers_objectSpread__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(5);
  39459. /* harmony import */ var _babel_runtime_helpers_objectSpread__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_objectSpread__WEBPACK_IMPORTED_MODULE_0__);
  39460. var getSelectedTextLength = function getSelectedTextLength(editorState) {
  39461. var currentSelection = editorState.getSelection();
  39462. var isCollapsed = currentSelection.isCollapsed();
  39463. var length = 0;
  39464. if (!isCollapsed) {
  39465. var currentContent = editorState.getCurrentContent();
  39466. var startKey = currentSelection.getStartKey();
  39467. var endKey = currentSelection.getEndKey();
  39468. var startBlock = currentContent.getBlockForKey(startKey);
  39469. var isStartAndEndBlockAreTheSame = startKey === endKey;
  39470. var startBlockTextLength = startBlock.getLength();
  39471. var startSelectedTextLength = startBlockTextLength - currentSelection.getStartOffset();
  39472. var endSelectedTextLength = currentSelection.getEndOffset();
  39473. var keyAfterEnd = currentContent.getKeyAfter(endKey);
  39474. if (isStartAndEndBlockAreTheSame) {
  39475. length += currentSelection.getEndOffset() - currentSelection.getStartOffset();
  39476. } else {
  39477. var currentKey = startKey;
  39478. while (currentKey && currentKey !== keyAfterEnd) {
  39479. if (currentKey === startKey) {
  39480. length += startSelectedTextLength + 1;
  39481. } else if (currentKey === endKey) {
  39482. length += endSelectedTextLength;
  39483. } else {
  39484. length += currentContent.getBlockForKey(currentKey).getLength() + 1;
  39485. }
  39486. currentKey = currentContent.getKeyAfter(currentKey);
  39487. }
  39488. }
  39489. }
  39490. return length;
  39491. };
  39492. /* harmony default export */ __webpack_exports__["default"] = (function (options) {
  39493. options = _babel_runtime_helpers_objectSpread__WEBPACK_IMPORTED_MODULE_0___default()({
  39494. defaultValue: Infinity
  39495. }, options);
  39496. var _options = options,
  39497. includeEditors = _options.includeEditors,
  39498. excludeEditors = _options.excludeEditors,
  39499. defaultValue = _options.defaultValue;
  39500. return {
  39501. type: 'prop-interception',
  39502. includeEditors: includeEditors,
  39503. excludeEditors: excludeEditors,
  39504. interceptor: function interceptor(editorProps) {
  39505. var maxLength = editorProps.maxLength || defaultValue;
  39506. editorProps.handleBeforeInput = function (_, editorState) {
  39507. if (maxLength === Infinity) {
  39508. return 'not-handled';
  39509. }
  39510. var currentContentLength = editorState.toText().length;
  39511. var selectedTextLength = getSelectedTextLength(editorState);
  39512. if (currentContentLength - selectedTextLength > maxLength - 1) {
  39513. editorProps.onReachMaxLength && editorProps.onReachMaxLength(maxLength);
  39514. return 'handled';
  39515. }
  39516. };
  39517. editorProps.handlePastedText = function (pastedText, _, editorState) {
  39518. if (maxLength === Infinity) {
  39519. return 'not-handled';
  39520. }
  39521. var currentContentLength = editorState.toText().length;
  39522. var selectedTextLength = getSelectedTextLength(editorState);
  39523. if (currentContentLength + pastedText.length - selectedTextLength > maxLength) {
  39524. editorProps.onReachMaxLength && editorProps.onReachMaxLength(maxLength);
  39525. return 'handled';
  39526. }
  39527. };
  39528. return editorProps;
  39529. }
  39530. };
  39531. });
  39532. /***/ }),
  39533. /***/ 5:
  39534. /***/ (function(module, exports, __webpack_require__) {
  39535. var defineProperty = __webpack_require__(2);
  39536. function _objectSpread(target) {
  39537. for (var i = 1; i < arguments.length; i++) {
  39538. var source = arguments[i] != null ? arguments[i] : {};
  39539. var ownKeys = Object.keys(source);
  39540. if (typeof Object.getOwnPropertySymbols === 'function') {
  39541. ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
  39542. return Object.getOwnPropertyDescriptor(source, sym).enumerable;
  39543. }));
  39544. }
  39545. ownKeys.forEach(function (key) {
  39546. defineProperty(target, key, source[key]);
  39547. });
  39548. }
  39549. return target;
  39550. }
  39551. module.exports = _objectSpread;
  39552. /***/ })
  39553. /******/ });
  39554. });
  39555. });
  39556. var MaxLength = _commonjsHelpers.unwrapExports(maxLength);
  39557. var lengthOptions = {
  39558. defaultValue: 100
  39559. };
  39560. BraftEditor.use(MaxLength(lengthOptions));
  39561. var emoticons = emoticon_1.map(function (item) {
  39562. return require("braft-extensions/dist/assets/".concat(item));
  39563. });
  39564. var emotionOptions = {
  39565. emoticons: emoticons,
  39566. closeOnBlur: true,
  39567. closeOnSelect: false
  39568. };
  39569. BraftEditor.use(Emoticon(emotionOptions));
  39570. var BarftEditorPage = function BarftEditorPage(_ref) {
  39571. var value = _ref.value;
  39572. var controls = ["bold", "italic", "underline", "separator", "link", "emoji", "separator", "media"];
  39573. var _useState = React.useState(BraftEditor.createEditorState(value || "<p>Hello <b>World!</b></p>")),
  39574. _useState2 = slicedToArray._slicedToArray(_useState, 2),
  39575. editorState = _useState2[0],
  39576. setEditorState = _useState2[1];
  39577. return React__default.createElement("div", {
  39578. className: "editor-wrapper"
  39579. }, React__default.createElement(BraftEditor, {
  39580. value: editorState,
  39581. onChange: setEditorState,
  39582. controls: controls,
  39583. contentStyle: {
  39584. boxShadow: "inset 0 1px 3px rgba(0,0,0,.1)"
  39585. }
  39586. }));
  39587. };
  39588. exports.BarftEditorPage = BarftEditorPage;
  39589. exports.default = BarftEditorPage;
  39590. //# sourceMappingURL=index.js.map