暂无描述

index.js 1.5MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571
  1. import React, { useState } from 'react';
  2. import ReactDOM from 'react-dom';
  3. import { s as styleInject } from '../style-inject.es-1f59c1d0.js';
  4. import { c as createCommonjsModule, a as commonjsGlobal, u as unwrapExports } from '../_commonjsHelpers-97e6d7b1.js';
  5. import { _ as _slicedToArray } from '../slicedToArray-4cd9e6d3.js';
  6. import server from 'react-dom/server';
  7. /*
  8. object-assign
  9. (c) Sindre Sorhus
  10. @license MIT
  11. */
  12. /* eslint-disable no-unused-vars */
  13. var getOwnPropertySymbols = Object.getOwnPropertySymbols;
  14. var hasOwnProperty = Object.prototype.hasOwnProperty;
  15. var propIsEnumerable = Object.prototype.propertyIsEnumerable;
  16. function toObject(val) {
  17. if (val === null || val === undefined) {
  18. throw new TypeError('Object.assign cannot be called with null or undefined');
  19. }
  20. return Object(val);
  21. }
  22. function shouldUseNative() {
  23. try {
  24. if (!Object.assign) {
  25. return false;
  26. }
  27. // Detect buggy property enumeration order in older V8 versions.
  28. // https://bugs.chromium.org/p/v8/issues/detail?id=4118
  29. var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
  30. test1[5] = 'de';
  31. if (Object.getOwnPropertyNames(test1)[0] === '5') {
  32. return false;
  33. }
  34. // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  35. var test2 = {};
  36. for (var i = 0; i < 10; i++) {
  37. test2['_' + String.fromCharCode(i)] = i;
  38. }
  39. var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
  40. return test2[n];
  41. });
  42. if (order2.join('') !== '0123456789') {
  43. return false;
  44. }
  45. // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  46. var test3 = {};
  47. 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
  48. test3[letter] = letter;
  49. });
  50. if (Object.keys(Object.assign({}, test3)).join('') !==
  51. 'abcdefghijklmnopqrst') {
  52. return false;
  53. }
  54. return true;
  55. } catch (err) {
  56. // We don't expect any of the above to throw, but better to be safe.
  57. return false;
  58. }
  59. }
  60. var objectAssign = shouldUseNative() ? Object.assign : function (target, source) {
  61. var from;
  62. var to = toObject(target);
  63. var symbols;
  64. for (var s = 1; s < arguments.length; s++) {
  65. from = Object(arguments[s]);
  66. for (var key in from) {
  67. if (hasOwnProperty.call(from, key)) {
  68. to[key] = from[key];
  69. }
  70. }
  71. if (getOwnPropertySymbols) {
  72. symbols = getOwnPropertySymbols(from);
  73. for (var i = 0; i < symbols.length; i++) {
  74. if (propIsEnumerable.call(from, symbols[i])) {
  75. to[symbols[i]] = from[symbols[i]];
  76. }
  77. }
  78. }
  79. }
  80. return to;
  81. };
  82. var immutable = createCommonjsModule(function (module, exports) {
  83. /**
  84. * Copyright (c) 2014-2015, Facebook, Inc.
  85. * All rights reserved.
  86. *
  87. * This source code is licensed under the BSD-style license found in the
  88. * LICENSE file in the root directory of this source tree. An additional grant
  89. * of patent rights can be found in the PATENTS file in the same directory.
  90. */
  91. (function (global, factory) {
  92. module.exports = factory() ;
  93. }(commonjsGlobal, function () {var SLICE$0 = Array.prototype.slice;
  94. function createClass(ctor, superClass) {
  95. if (superClass) {
  96. ctor.prototype = Object.create(superClass.prototype);
  97. }
  98. ctor.prototype.constructor = ctor;
  99. }
  100. function Iterable(value) {
  101. return isIterable(value) ? value : Seq(value);
  102. }
  103. createClass(KeyedIterable, Iterable);
  104. function KeyedIterable(value) {
  105. return isKeyed(value) ? value : KeyedSeq(value);
  106. }
  107. createClass(IndexedIterable, Iterable);
  108. function IndexedIterable(value) {
  109. return isIndexed(value) ? value : IndexedSeq(value);
  110. }
  111. createClass(SetIterable, Iterable);
  112. function SetIterable(value) {
  113. return isIterable(value) && !isAssociative(value) ? value : SetSeq(value);
  114. }
  115. function isIterable(maybeIterable) {
  116. return !!(maybeIterable && maybeIterable[IS_ITERABLE_SENTINEL]);
  117. }
  118. function isKeyed(maybeKeyed) {
  119. return !!(maybeKeyed && maybeKeyed[IS_KEYED_SENTINEL]);
  120. }
  121. function isIndexed(maybeIndexed) {
  122. return !!(maybeIndexed && maybeIndexed[IS_INDEXED_SENTINEL]);
  123. }
  124. function isAssociative(maybeAssociative) {
  125. return isKeyed(maybeAssociative) || isIndexed(maybeAssociative);
  126. }
  127. function isOrdered(maybeOrdered) {
  128. return !!(maybeOrdered && maybeOrdered[IS_ORDERED_SENTINEL]);
  129. }
  130. Iterable.isIterable = isIterable;
  131. Iterable.isKeyed = isKeyed;
  132. Iterable.isIndexed = isIndexed;
  133. Iterable.isAssociative = isAssociative;
  134. Iterable.isOrdered = isOrdered;
  135. Iterable.Keyed = KeyedIterable;
  136. Iterable.Indexed = IndexedIterable;
  137. Iterable.Set = SetIterable;
  138. var IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
  139. var IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
  140. var IS_INDEXED_SENTINEL = '@@__IMMUTABLE_INDEXED__@@';
  141. var IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
  142. // Used for setting prototype methods that IE8 chokes on.
  143. var DELETE = 'delete';
  144. // Constants describing the size of trie nodes.
  145. var SHIFT = 5; // Resulted in best performance after ______?
  146. var SIZE = 1 << SHIFT;
  147. var MASK = SIZE - 1;
  148. // A consistent shared value representing "not set" which equals nothing other
  149. // than itself, and nothing that could be provided externally.
  150. var NOT_SET = {};
  151. // Boolean references, Rough equivalent of `bool &`.
  152. var CHANGE_LENGTH = { value: false };
  153. var DID_ALTER = { value: false };
  154. function MakeRef(ref) {
  155. ref.value = false;
  156. return ref;
  157. }
  158. function SetRef(ref) {
  159. ref && (ref.value = true);
  160. }
  161. // A function which returns a value representing an "owner" for transient writes
  162. // to tries. The return value will only ever equal itself, and will not equal
  163. // the return of any subsequent call of this function.
  164. function OwnerID() {}
  165. // http://jsperf.com/copy-array-inline
  166. function arrCopy(arr, offset) {
  167. offset = offset || 0;
  168. var len = Math.max(0, arr.length - offset);
  169. var newArr = new Array(len);
  170. for (var ii = 0; ii < len; ii++) {
  171. newArr[ii] = arr[ii + offset];
  172. }
  173. return newArr;
  174. }
  175. function ensureSize(iter) {
  176. if (iter.size === undefined) {
  177. iter.size = iter.__iterate(returnTrue);
  178. }
  179. return iter.size;
  180. }
  181. function wrapIndex(iter, index) {
  182. // This implements "is array index" which the ECMAString spec defines as:
  183. //
  184. // A String property name P is an array index if and only if
  185. // ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal
  186. // to 2^32−1.
  187. //
  188. // http://www.ecma-international.org/ecma-262/6.0/#sec-array-exotic-objects
  189. if (typeof index !== 'number') {
  190. var uint32Index = index >>> 0; // N >>> 0 is shorthand for ToUint32
  191. if ('' + uint32Index !== index || uint32Index === 4294967295) {
  192. return NaN;
  193. }
  194. index = uint32Index;
  195. }
  196. return index < 0 ? ensureSize(iter) + index : index;
  197. }
  198. function returnTrue() {
  199. return true;
  200. }
  201. function wholeSlice(begin, end, size) {
  202. return (begin === 0 || (size !== undefined && begin <= -size)) &&
  203. (end === undefined || (size !== undefined && end >= size));
  204. }
  205. function resolveBegin(begin, size) {
  206. return resolveIndex(begin, size, 0);
  207. }
  208. function resolveEnd(end, size) {
  209. return resolveIndex(end, size, size);
  210. }
  211. function resolveIndex(index, size, defaultIndex) {
  212. return index === undefined ?
  213. defaultIndex :
  214. index < 0 ?
  215. Math.max(0, size + index) :
  216. size === undefined ?
  217. index :
  218. Math.min(size, index);
  219. }
  220. /* global Symbol */
  221. var ITERATE_KEYS = 0;
  222. var ITERATE_VALUES = 1;
  223. var ITERATE_ENTRIES = 2;
  224. var REAL_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
  225. var FAUX_ITERATOR_SYMBOL = '@@iterator';
  226. var ITERATOR_SYMBOL = REAL_ITERATOR_SYMBOL || FAUX_ITERATOR_SYMBOL;
  227. function Iterator(next) {
  228. this.next = next;
  229. }
  230. Iterator.prototype.toString = function() {
  231. return '[Iterator]';
  232. };
  233. Iterator.KEYS = ITERATE_KEYS;
  234. Iterator.VALUES = ITERATE_VALUES;
  235. Iterator.ENTRIES = ITERATE_ENTRIES;
  236. Iterator.prototype.inspect =
  237. Iterator.prototype.toSource = function () { return this.toString(); };
  238. Iterator.prototype[ITERATOR_SYMBOL] = function () {
  239. return this;
  240. };
  241. function iteratorValue(type, k, v, iteratorResult) {
  242. var value = type === 0 ? k : type === 1 ? v : [k, v];
  243. iteratorResult ? (iteratorResult.value = value) : (iteratorResult = {
  244. value: value, done: false
  245. });
  246. return iteratorResult;
  247. }
  248. function iteratorDone() {
  249. return { value: undefined, done: true };
  250. }
  251. function hasIterator(maybeIterable) {
  252. return !!getIteratorFn(maybeIterable);
  253. }
  254. function isIterator(maybeIterator) {
  255. return maybeIterator && typeof maybeIterator.next === 'function';
  256. }
  257. function getIterator(iterable) {
  258. var iteratorFn = getIteratorFn(iterable);
  259. return iteratorFn && iteratorFn.call(iterable);
  260. }
  261. function getIteratorFn(iterable) {
  262. var iteratorFn = iterable && (
  263. (REAL_ITERATOR_SYMBOL && iterable[REAL_ITERATOR_SYMBOL]) ||
  264. iterable[FAUX_ITERATOR_SYMBOL]
  265. );
  266. if (typeof iteratorFn === 'function') {
  267. return iteratorFn;
  268. }
  269. }
  270. function isArrayLike(value) {
  271. return value && typeof value.length === 'number';
  272. }
  273. createClass(Seq, Iterable);
  274. function Seq(value) {
  275. return value === null || value === undefined ? emptySequence() :
  276. isIterable(value) ? value.toSeq() : seqFromValue(value);
  277. }
  278. Seq.of = function(/*...values*/) {
  279. return Seq(arguments);
  280. };
  281. Seq.prototype.toSeq = function() {
  282. return this;
  283. };
  284. Seq.prototype.toString = function() {
  285. return this.__toString('Seq {', '}');
  286. };
  287. Seq.prototype.cacheResult = function() {
  288. if (!this._cache && this.__iterateUncached) {
  289. this._cache = this.entrySeq().toArray();
  290. this.size = this._cache.length;
  291. }
  292. return this;
  293. };
  294. // abstract __iterateUncached(fn, reverse)
  295. Seq.prototype.__iterate = function(fn, reverse) {
  296. return seqIterate(this, fn, reverse, true);
  297. };
  298. // abstract __iteratorUncached(type, reverse)
  299. Seq.prototype.__iterator = function(type, reverse) {
  300. return seqIterator(this, type, reverse, true);
  301. };
  302. createClass(KeyedSeq, Seq);
  303. function KeyedSeq(value) {
  304. return value === null || value === undefined ?
  305. emptySequence().toKeyedSeq() :
  306. isIterable(value) ?
  307. (isKeyed(value) ? value.toSeq() : value.fromEntrySeq()) :
  308. keyedSeqFromValue(value);
  309. }
  310. KeyedSeq.prototype.toKeyedSeq = function() {
  311. return this;
  312. };
  313. createClass(IndexedSeq, Seq);
  314. function IndexedSeq(value) {
  315. return value === null || value === undefined ? emptySequence() :
  316. !isIterable(value) ? indexedSeqFromValue(value) :
  317. isKeyed(value) ? value.entrySeq() : value.toIndexedSeq();
  318. }
  319. IndexedSeq.of = function(/*...values*/) {
  320. return IndexedSeq(arguments);
  321. };
  322. IndexedSeq.prototype.toIndexedSeq = function() {
  323. return this;
  324. };
  325. IndexedSeq.prototype.toString = function() {
  326. return this.__toString('Seq [', ']');
  327. };
  328. IndexedSeq.prototype.__iterate = function(fn, reverse) {
  329. return seqIterate(this, fn, reverse, false);
  330. };
  331. IndexedSeq.prototype.__iterator = function(type, reverse) {
  332. return seqIterator(this, type, reverse, false);
  333. };
  334. createClass(SetSeq, Seq);
  335. function SetSeq(value) {
  336. return (
  337. value === null || value === undefined ? emptySequence() :
  338. !isIterable(value) ? indexedSeqFromValue(value) :
  339. isKeyed(value) ? value.entrySeq() : value
  340. ).toSetSeq();
  341. }
  342. SetSeq.of = function(/*...values*/) {
  343. return SetSeq(arguments);
  344. };
  345. SetSeq.prototype.toSetSeq = function() {
  346. return this;
  347. };
  348. Seq.isSeq = isSeq;
  349. Seq.Keyed = KeyedSeq;
  350. Seq.Set = SetSeq;
  351. Seq.Indexed = IndexedSeq;
  352. var IS_SEQ_SENTINEL = '@@__IMMUTABLE_SEQ__@@';
  353. Seq.prototype[IS_SEQ_SENTINEL] = true;
  354. createClass(ArraySeq, IndexedSeq);
  355. function ArraySeq(array) {
  356. this._array = array;
  357. this.size = array.length;
  358. }
  359. ArraySeq.prototype.get = function(index, notSetValue) {
  360. return this.has(index) ? this._array[wrapIndex(this, index)] : notSetValue;
  361. };
  362. ArraySeq.prototype.__iterate = function(fn, reverse) {
  363. var array = this._array;
  364. var maxIndex = array.length - 1;
  365. for (var ii = 0; ii <= maxIndex; ii++) {
  366. if (fn(array[reverse ? maxIndex - ii : ii], ii, this) === false) {
  367. return ii + 1;
  368. }
  369. }
  370. return ii;
  371. };
  372. ArraySeq.prototype.__iterator = function(type, reverse) {
  373. var array = this._array;
  374. var maxIndex = array.length - 1;
  375. var ii = 0;
  376. return new Iterator(function()
  377. {return ii > maxIndex ?
  378. iteratorDone() :
  379. iteratorValue(type, ii, array[reverse ? maxIndex - ii++ : ii++])}
  380. );
  381. };
  382. createClass(ObjectSeq, KeyedSeq);
  383. function ObjectSeq(object) {
  384. var keys = Object.keys(object);
  385. this._object = object;
  386. this._keys = keys;
  387. this.size = keys.length;
  388. }
  389. ObjectSeq.prototype.get = function(key, notSetValue) {
  390. if (notSetValue !== undefined && !this.has(key)) {
  391. return notSetValue;
  392. }
  393. return this._object[key];
  394. };
  395. ObjectSeq.prototype.has = function(key) {
  396. return this._object.hasOwnProperty(key);
  397. };
  398. ObjectSeq.prototype.__iterate = function(fn, reverse) {
  399. var object = this._object;
  400. var keys = this._keys;
  401. var maxIndex = keys.length - 1;
  402. for (var ii = 0; ii <= maxIndex; ii++) {
  403. var key = keys[reverse ? maxIndex - ii : ii];
  404. if (fn(object[key], key, this) === false) {
  405. return ii + 1;
  406. }
  407. }
  408. return ii;
  409. };
  410. ObjectSeq.prototype.__iterator = function(type, reverse) {
  411. var object = this._object;
  412. var keys = this._keys;
  413. var maxIndex = keys.length - 1;
  414. var ii = 0;
  415. return new Iterator(function() {
  416. var key = keys[reverse ? maxIndex - ii : ii];
  417. return ii++ > maxIndex ?
  418. iteratorDone() :
  419. iteratorValue(type, key, object[key]);
  420. });
  421. };
  422. ObjectSeq.prototype[IS_ORDERED_SENTINEL] = true;
  423. createClass(IterableSeq, IndexedSeq);
  424. function IterableSeq(iterable) {
  425. this._iterable = iterable;
  426. this.size = iterable.length || iterable.size;
  427. }
  428. IterableSeq.prototype.__iterateUncached = function(fn, reverse) {
  429. if (reverse) {
  430. return this.cacheResult().__iterate(fn, reverse);
  431. }
  432. var iterable = this._iterable;
  433. var iterator = getIterator(iterable);
  434. var iterations = 0;
  435. if (isIterator(iterator)) {
  436. var step;
  437. while (!(step = iterator.next()).done) {
  438. if (fn(step.value, iterations++, this) === false) {
  439. break;
  440. }
  441. }
  442. }
  443. return iterations;
  444. };
  445. IterableSeq.prototype.__iteratorUncached = function(type, reverse) {
  446. if (reverse) {
  447. return this.cacheResult().__iterator(type, reverse);
  448. }
  449. var iterable = this._iterable;
  450. var iterator = getIterator(iterable);
  451. if (!isIterator(iterator)) {
  452. return new Iterator(iteratorDone);
  453. }
  454. var iterations = 0;
  455. return new Iterator(function() {
  456. var step = iterator.next();
  457. return step.done ? step : iteratorValue(type, iterations++, step.value);
  458. });
  459. };
  460. createClass(IteratorSeq, IndexedSeq);
  461. function IteratorSeq(iterator) {
  462. this._iterator = iterator;
  463. this._iteratorCache = [];
  464. }
  465. IteratorSeq.prototype.__iterateUncached = function(fn, reverse) {
  466. if (reverse) {
  467. return this.cacheResult().__iterate(fn, reverse);
  468. }
  469. var iterator = this._iterator;
  470. var cache = this._iteratorCache;
  471. var iterations = 0;
  472. while (iterations < cache.length) {
  473. if (fn(cache[iterations], iterations++, this) === false) {
  474. return iterations;
  475. }
  476. }
  477. var step;
  478. while (!(step = iterator.next()).done) {
  479. var val = step.value;
  480. cache[iterations] = val;
  481. if (fn(val, iterations++, this) === false) {
  482. break;
  483. }
  484. }
  485. return iterations;
  486. };
  487. IteratorSeq.prototype.__iteratorUncached = function(type, reverse) {
  488. if (reverse) {
  489. return this.cacheResult().__iterator(type, reverse);
  490. }
  491. var iterator = this._iterator;
  492. var cache = this._iteratorCache;
  493. var iterations = 0;
  494. return new Iterator(function() {
  495. if (iterations >= cache.length) {
  496. var step = iterator.next();
  497. if (step.done) {
  498. return step;
  499. }
  500. cache[iterations] = step.value;
  501. }
  502. return iteratorValue(type, iterations, cache[iterations++]);
  503. });
  504. };
  505. // # pragma Helper functions
  506. function isSeq(maybeSeq) {
  507. return !!(maybeSeq && maybeSeq[IS_SEQ_SENTINEL]);
  508. }
  509. var EMPTY_SEQ;
  510. function emptySequence() {
  511. return EMPTY_SEQ || (EMPTY_SEQ = new ArraySeq([]));
  512. }
  513. function keyedSeqFromValue(value) {
  514. var seq =
  515. Array.isArray(value) ? new ArraySeq(value).fromEntrySeq() :
  516. isIterator(value) ? new IteratorSeq(value).fromEntrySeq() :
  517. hasIterator(value) ? new IterableSeq(value).fromEntrySeq() :
  518. typeof value === 'object' ? new ObjectSeq(value) :
  519. undefined;
  520. if (!seq) {
  521. throw new TypeError(
  522. 'Expected Array or iterable object of [k, v] entries, '+
  523. 'or keyed object: ' + value
  524. );
  525. }
  526. return seq;
  527. }
  528. function indexedSeqFromValue(value) {
  529. var seq = maybeIndexedSeqFromValue(value);
  530. if (!seq) {
  531. throw new TypeError(
  532. 'Expected Array or iterable object of values: ' + value
  533. );
  534. }
  535. return seq;
  536. }
  537. function seqFromValue(value) {
  538. var seq = maybeIndexedSeqFromValue(value) ||
  539. (typeof value === 'object' && new ObjectSeq(value));
  540. if (!seq) {
  541. throw new TypeError(
  542. 'Expected Array or iterable object of values, or keyed object: ' + value
  543. );
  544. }
  545. return seq;
  546. }
  547. function maybeIndexedSeqFromValue(value) {
  548. return (
  549. isArrayLike(value) ? new ArraySeq(value) :
  550. isIterator(value) ? new IteratorSeq(value) :
  551. hasIterator(value) ? new IterableSeq(value) :
  552. undefined
  553. );
  554. }
  555. function seqIterate(seq, fn, reverse, useKeys) {
  556. var cache = seq._cache;
  557. if (cache) {
  558. var maxIndex = cache.length - 1;
  559. for (var ii = 0; ii <= maxIndex; ii++) {
  560. var entry = cache[reverse ? maxIndex - ii : ii];
  561. if (fn(entry[1], useKeys ? entry[0] : ii, seq) === false) {
  562. return ii + 1;
  563. }
  564. }
  565. return ii;
  566. }
  567. return seq.__iterateUncached(fn, reverse);
  568. }
  569. function seqIterator(seq, type, reverse, useKeys) {
  570. var cache = seq._cache;
  571. if (cache) {
  572. var maxIndex = cache.length - 1;
  573. var ii = 0;
  574. return new Iterator(function() {
  575. var entry = cache[reverse ? maxIndex - ii : ii];
  576. return ii++ > maxIndex ?
  577. iteratorDone() :
  578. iteratorValue(type, useKeys ? entry[0] : ii - 1, entry[1]);
  579. });
  580. }
  581. return seq.__iteratorUncached(type, reverse);
  582. }
  583. function fromJS(json, converter) {
  584. return converter ?
  585. fromJSWith(converter, json, '', {'': json}) :
  586. fromJSDefault(json);
  587. }
  588. function fromJSWith(converter, json, key, parentJSON) {
  589. if (Array.isArray(json)) {
  590. return converter.call(parentJSON, key, IndexedSeq(json).map(function(v, k) {return fromJSWith(converter, v, k, json)}));
  591. }
  592. if (isPlainObj(json)) {
  593. return converter.call(parentJSON, key, KeyedSeq(json).map(function(v, k) {return fromJSWith(converter, v, k, json)}));
  594. }
  595. return json;
  596. }
  597. function fromJSDefault(json) {
  598. if (Array.isArray(json)) {
  599. return IndexedSeq(json).map(fromJSDefault).toList();
  600. }
  601. if (isPlainObj(json)) {
  602. return KeyedSeq(json).map(fromJSDefault).toMap();
  603. }
  604. return json;
  605. }
  606. function isPlainObj(value) {
  607. return value && (value.constructor === Object || value.constructor === undefined);
  608. }
  609. /**
  610. * An extension of the "same-value" algorithm as [described for use by ES6 Map
  611. * and Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map#Key_equality)
  612. *
  613. * NaN is considered the same as NaN, however -0 and 0 are considered the same
  614. * value, which is different from the algorithm described by
  615. * [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is).
  616. *
  617. * This is extended further to allow Objects to describe the values they
  618. * represent, by way of `valueOf` or `equals` (and `hashCode`).
  619. *
  620. * Note: because of this extension, the key equality of Immutable.Map and the
  621. * value equality of Immutable.Set will differ from ES6 Map and Set.
  622. *
  623. * ### Defining custom values
  624. *
  625. * The easiest way to describe the value an object represents is by implementing
  626. * `valueOf`. For example, `Date` represents a value by returning a unix
  627. * timestamp for `valueOf`:
  628. *
  629. * var date1 = new Date(1234567890000); // Fri Feb 13 2009 ...
  630. * var date2 = new Date(1234567890000);
  631. * date1.valueOf(); // 1234567890000
  632. * assert( date1 !== date2 );
  633. * assert( Immutable.is( date1, date2 ) );
  634. *
  635. * Note: overriding `valueOf` may have other implications if you use this object
  636. * where JavaScript expects a primitive, such as implicit string coercion.
  637. *
  638. * For more complex types, especially collections, implementing `valueOf` may
  639. * not be performant. An alternative is to implement `equals` and `hashCode`.
  640. *
  641. * `equals` takes another object, presumably of similar type, and returns true
  642. * if the it is equal. Equality is symmetrical, so the same result should be
  643. * returned if this and the argument are flipped.
  644. *
  645. * assert( a.equals(b) === b.equals(a) );
  646. *
  647. * `hashCode` returns a 32bit integer number representing the object which will
  648. * be used to determine how to store the value object in a Map or Set. You must
  649. * provide both or neither methods, one must not exist without the other.
  650. *
  651. * Also, an important relationship between these methods must be upheld: if two
  652. * values are equal, they *must* return the same hashCode. If the values are not
  653. * equal, they might have the same hashCode; this is called a hash collision,
  654. * and while undesirable for performance reasons, it is acceptable.
  655. *
  656. * if (a.equals(b)) {
  657. * assert( a.hashCode() === b.hashCode() );
  658. * }
  659. *
  660. * All Immutable collections implement `equals` and `hashCode`.
  661. *
  662. */
  663. function is(valueA, valueB) {
  664. if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
  665. return true;
  666. }
  667. if (!valueA || !valueB) {
  668. return false;
  669. }
  670. if (typeof valueA.valueOf === 'function' &&
  671. typeof valueB.valueOf === 'function') {
  672. valueA = valueA.valueOf();
  673. valueB = valueB.valueOf();
  674. if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
  675. return true;
  676. }
  677. if (!valueA || !valueB) {
  678. return false;
  679. }
  680. }
  681. if (typeof valueA.equals === 'function' &&
  682. typeof valueB.equals === 'function' &&
  683. valueA.equals(valueB)) {
  684. return true;
  685. }
  686. return false;
  687. }
  688. function deepEqual(a, b) {
  689. if (a === b) {
  690. return true;
  691. }
  692. if (
  693. !isIterable(b) ||
  694. a.size !== undefined && b.size !== undefined && a.size !== b.size ||
  695. a.__hash !== undefined && b.__hash !== undefined && a.__hash !== b.__hash ||
  696. isKeyed(a) !== isKeyed(b) ||
  697. isIndexed(a) !== isIndexed(b) ||
  698. isOrdered(a) !== isOrdered(b)
  699. ) {
  700. return false;
  701. }
  702. if (a.size === 0 && b.size === 0) {
  703. return true;
  704. }
  705. var notAssociative = !isAssociative(a);
  706. if (isOrdered(a)) {
  707. var entries = a.entries();
  708. return b.every(function(v, k) {
  709. var entry = entries.next().value;
  710. return entry && is(entry[1], v) && (notAssociative || is(entry[0], k));
  711. }) && entries.next().done;
  712. }
  713. var flipped = false;
  714. if (a.size === undefined) {
  715. if (b.size === undefined) {
  716. if (typeof a.cacheResult === 'function') {
  717. a.cacheResult();
  718. }
  719. } else {
  720. flipped = true;
  721. var _ = a;
  722. a = b;
  723. b = _;
  724. }
  725. }
  726. var allEqual = true;
  727. var bSize = b.__iterate(function(v, k) {
  728. if (notAssociative ? !a.has(v) :
  729. flipped ? !is(v, a.get(k, NOT_SET)) : !is(a.get(k, NOT_SET), v)) {
  730. allEqual = false;
  731. return false;
  732. }
  733. });
  734. return allEqual && a.size === bSize;
  735. }
  736. createClass(Repeat, IndexedSeq);
  737. function Repeat(value, times) {
  738. if (!(this instanceof Repeat)) {
  739. return new Repeat(value, times);
  740. }
  741. this._value = value;
  742. this.size = times === undefined ? Infinity : Math.max(0, times);
  743. if (this.size === 0) {
  744. if (EMPTY_REPEAT) {
  745. return EMPTY_REPEAT;
  746. }
  747. EMPTY_REPEAT = this;
  748. }
  749. }
  750. Repeat.prototype.toString = function() {
  751. if (this.size === 0) {
  752. return 'Repeat []';
  753. }
  754. return 'Repeat [ ' + this._value + ' ' + this.size + ' times ]';
  755. };
  756. Repeat.prototype.get = function(index, notSetValue) {
  757. return this.has(index) ? this._value : notSetValue;
  758. };
  759. Repeat.prototype.includes = function(searchValue) {
  760. return is(this._value, searchValue);
  761. };
  762. Repeat.prototype.slice = function(begin, end) {
  763. var size = this.size;
  764. return wholeSlice(begin, end, size) ? this :
  765. new Repeat(this._value, resolveEnd(end, size) - resolveBegin(begin, size));
  766. };
  767. Repeat.prototype.reverse = function() {
  768. return this;
  769. };
  770. Repeat.prototype.indexOf = function(searchValue) {
  771. if (is(this._value, searchValue)) {
  772. return 0;
  773. }
  774. return -1;
  775. };
  776. Repeat.prototype.lastIndexOf = function(searchValue) {
  777. if (is(this._value, searchValue)) {
  778. return this.size;
  779. }
  780. return -1;
  781. };
  782. Repeat.prototype.__iterate = function(fn, reverse) {
  783. for (var ii = 0; ii < this.size; ii++) {
  784. if (fn(this._value, ii, this) === false) {
  785. return ii + 1;
  786. }
  787. }
  788. return ii;
  789. };
  790. Repeat.prototype.__iterator = function(type, reverse) {var this$0 = this;
  791. var ii = 0;
  792. return new Iterator(function()
  793. {return ii < this$0.size ? iteratorValue(type, ii++, this$0._value) : iteratorDone()}
  794. );
  795. };
  796. Repeat.prototype.equals = function(other) {
  797. return other instanceof Repeat ?
  798. is(this._value, other._value) :
  799. deepEqual(other);
  800. };
  801. var EMPTY_REPEAT;
  802. function invariant(condition, error) {
  803. if (!condition) throw new Error(error);
  804. }
  805. createClass(Range, IndexedSeq);
  806. function Range(start, end, step) {
  807. if (!(this instanceof Range)) {
  808. return new Range(start, end, step);
  809. }
  810. invariant(step !== 0, 'Cannot step a Range by 0');
  811. start = start || 0;
  812. if (end === undefined) {
  813. end = Infinity;
  814. }
  815. step = step === undefined ? 1 : Math.abs(step);
  816. if (end < start) {
  817. step = -step;
  818. }
  819. this._start = start;
  820. this._end = end;
  821. this._step = step;
  822. this.size = Math.max(0, Math.ceil((end - start) / step - 1) + 1);
  823. if (this.size === 0) {
  824. if (EMPTY_RANGE) {
  825. return EMPTY_RANGE;
  826. }
  827. EMPTY_RANGE = this;
  828. }
  829. }
  830. Range.prototype.toString = function() {
  831. if (this.size === 0) {
  832. return 'Range []';
  833. }
  834. return 'Range [ ' +
  835. this._start + '...' + this._end +
  836. (this._step > 1 ? ' by ' + this._step : '') +
  837. ' ]';
  838. };
  839. Range.prototype.get = function(index, notSetValue) {
  840. return this.has(index) ?
  841. this._start + wrapIndex(this, index) * this._step :
  842. notSetValue;
  843. };
  844. Range.prototype.includes = function(searchValue) {
  845. var possibleIndex = (searchValue - this._start) / this._step;
  846. return possibleIndex >= 0 &&
  847. possibleIndex < this.size &&
  848. possibleIndex === Math.floor(possibleIndex);
  849. };
  850. Range.prototype.slice = function(begin, end) {
  851. if (wholeSlice(begin, end, this.size)) {
  852. return this;
  853. }
  854. begin = resolveBegin(begin, this.size);
  855. end = resolveEnd(end, this.size);
  856. if (end <= begin) {
  857. return new Range(0, 0);
  858. }
  859. return new Range(this.get(begin, this._end), this.get(end, this._end), this._step);
  860. };
  861. Range.prototype.indexOf = function(searchValue) {
  862. var offsetValue = searchValue - this._start;
  863. if (offsetValue % this._step === 0) {
  864. var index = offsetValue / this._step;
  865. if (index >= 0 && index < this.size) {
  866. return index
  867. }
  868. }
  869. return -1;
  870. };
  871. Range.prototype.lastIndexOf = function(searchValue) {
  872. return this.indexOf(searchValue);
  873. };
  874. Range.prototype.__iterate = function(fn, reverse) {
  875. var maxIndex = this.size - 1;
  876. var step = this._step;
  877. var value = reverse ? this._start + maxIndex * step : this._start;
  878. for (var ii = 0; ii <= maxIndex; ii++) {
  879. if (fn(value, ii, this) === false) {
  880. return ii + 1;
  881. }
  882. value += reverse ? -step : step;
  883. }
  884. return ii;
  885. };
  886. Range.prototype.__iterator = function(type, reverse) {
  887. var maxIndex = this.size - 1;
  888. var step = this._step;
  889. var value = reverse ? this._start + maxIndex * step : this._start;
  890. var ii = 0;
  891. return new Iterator(function() {
  892. var v = value;
  893. value += reverse ? -step : step;
  894. return ii > maxIndex ? iteratorDone() : iteratorValue(type, ii++, v);
  895. });
  896. };
  897. Range.prototype.equals = function(other) {
  898. return other instanceof Range ?
  899. this._start === other._start &&
  900. this._end === other._end &&
  901. this._step === other._step :
  902. deepEqual(this, other);
  903. };
  904. var EMPTY_RANGE;
  905. createClass(Collection, Iterable);
  906. function Collection() {
  907. throw TypeError('Abstract');
  908. }
  909. createClass(KeyedCollection, Collection);function KeyedCollection() {}
  910. createClass(IndexedCollection, Collection);function IndexedCollection() {}
  911. createClass(SetCollection, Collection);function SetCollection() {}
  912. Collection.Keyed = KeyedCollection;
  913. Collection.Indexed = IndexedCollection;
  914. Collection.Set = SetCollection;
  915. var imul =
  916. typeof Math.imul === 'function' && Math.imul(0xffffffff, 2) === -2 ?
  917. Math.imul :
  918. function imul(a, b) {
  919. a = a | 0; // int
  920. b = b | 0; // int
  921. var c = a & 0xffff;
  922. var d = b & 0xffff;
  923. // Shift by 0 fixes the sign on the high part.
  924. return (c * d) + ((((a >>> 16) * d + c * (b >>> 16)) << 16) >>> 0) | 0; // int
  925. };
  926. // v8 has an optimization for storing 31-bit signed numbers.
  927. // Values which have either 00 or 11 as the high order bits qualify.
  928. // This function drops the highest order bit in a signed number, maintaining
  929. // the sign bit.
  930. function smi(i32) {
  931. return ((i32 >>> 1) & 0x40000000) | (i32 & 0xBFFFFFFF);
  932. }
  933. function hash(o) {
  934. if (o === false || o === null || o === undefined) {
  935. return 0;
  936. }
  937. if (typeof o.valueOf === 'function') {
  938. o = o.valueOf();
  939. if (o === false || o === null || o === undefined) {
  940. return 0;
  941. }
  942. }
  943. if (o === true) {
  944. return 1;
  945. }
  946. var type = typeof o;
  947. if (type === 'number') {
  948. var h = o | 0;
  949. if (h !== o) {
  950. h ^= o * 0xFFFFFFFF;
  951. }
  952. while (o > 0xFFFFFFFF) {
  953. o /= 0xFFFFFFFF;
  954. h ^= o;
  955. }
  956. return smi(h);
  957. }
  958. if (type === 'string') {
  959. return o.length > STRING_HASH_CACHE_MIN_STRLEN ? cachedHashString(o) : hashString(o);
  960. }
  961. if (typeof o.hashCode === 'function') {
  962. return o.hashCode();
  963. }
  964. if (type === 'object') {
  965. return hashJSObj(o);
  966. }
  967. if (typeof o.toString === 'function') {
  968. return hashString(o.toString());
  969. }
  970. throw new Error('Value type ' + type + ' cannot be hashed.');
  971. }
  972. function cachedHashString(string) {
  973. var hash = stringHashCache[string];
  974. if (hash === undefined) {
  975. hash = hashString(string);
  976. if (STRING_HASH_CACHE_SIZE === STRING_HASH_CACHE_MAX_SIZE) {
  977. STRING_HASH_CACHE_SIZE = 0;
  978. stringHashCache = {};
  979. }
  980. STRING_HASH_CACHE_SIZE++;
  981. stringHashCache[string] = hash;
  982. }
  983. return hash;
  984. }
  985. // http://jsperf.com/hashing-strings
  986. function hashString(string) {
  987. // This is the hash from JVM
  988. // The hash code for a string is computed as
  989. // s[0] * 31 ^ (n - 1) + s[1] * 31 ^ (n - 2) + ... + s[n - 1],
  990. // where s[i] is the ith character of the string and n is the length of
  991. // the string. We "mod" the result to make it between 0 (inclusive) and 2^31
  992. // (exclusive) by dropping high bits.
  993. var hash = 0;
  994. for (var ii = 0; ii < string.length; ii++) {
  995. hash = 31 * hash + string.charCodeAt(ii) | 0;
  996. }
  997. return smi(hash);
  998. }
  999. function hashJSObj(obj) {
  1000. var hash;
  1001. if (usingWeakMap) {
  1002. hash = weakMap.get(obj);
  1003. if (hash !== undefined) {
  1004. return hash;
  1005. }
  1006. }
  1007. hash = obj[UID_HASH_KEY];
  1008. if (hash !== undefined) {
  1009. return hash;
  1010. }
  1011. if (!canDefineProperty) {
  1012. hash = obj.propertyIsEnumerable && obj.propertyIsEnumerable[UID_HASH_KEY];
  1013. if (hash !== undefined) {
  1014. return hash;
  1015. }
  1016. hash = getIENodeHash(obj);
  1017. if (hash !== undefined) {
  1018. return hash;
  1019. }
  1020. }
  1021. hash = ++objHashUID;
  1022. if (objHashUID & 0x40000000) {
  1023. objHashUID = 0;
  1024. }
  1025. if (usingWeakMap) {
  1026. weakMap.set(obj, hash);
  1027. } else if (isExtensible !== undefined && isExtensible(obj) === false) {
  1028. throw new Error('Non-extensible objects are not allowed as keys.');
  1029. } else if (canDefineProperty) {
  1030. Object.defineProperty(obj, UID_HASH_KEY, {
  1031. 'enumerable': false,
  1032. 'configurable': false,
  1033. 'writable': false,
  1034. 'value': hash
  1035. });
  1036. } else if (obj.propertyIsEnumerable !== undefined &&
  1037. obj.propertyIsEnumerable === obj.constructor.prototype.propertyIsEnumerable) {
  1038. // Since we can't define a non-enumerable property on the object
  1039. // we'll hijack one of the less-used non-enumerable properties to
  1040. // save our hash on it. Since this is a function it will not show up in
  1041. // `JSON.stringify` which is what we want.
  1042. obj.propertyIsEnumerable = function() {
  1043. return this.constructor.prototype.propertyIsEnumerable.apply(this, arguments);
  1044. };
  1045. obj.propertyIsEnumerable[UID_HASH_KEY] = hash;
  1046. } else if (obj.nodeType !== undefined) {
  1047. // At this point we couldn't get the IE `uniqueID` to use as a hash
  1048. // and we couldn't use a non-enumerable property to exploit the
  1049. // dontEnum bug so we simply add the `UID_HASH_KEY` on the node
  1050. // itself.
  1051. obj[UID_HASH_KEY] = hash;
  1052. } else {
  1053. throw new Error('Unable to set a non-enumerable property on object.');
  1054. }
  1055. return hash;
  1056. }
  1057. // Get references to ES5 object methods.
  1058. var isExtensible = Object.isExtensible;
  1059. // True if Object.defineProperty works as expected. IE8 fails this test.
  1060. var canDefineProperty = (function() {
  1061. try {
  1062. Object.defineProperty({}, '@', {});
  1063. return true;
  1064. } catch (e) {
  1065. return false;
  1066. }
  1067. }());
  1068. // IE has a `uniqueID` property on DOM nodes. We can construct the hash from it
  1069. // and avoid memory leaks from the IE cloneNode bug.
  1070. function getIENodeHash(node) {
  1071. if (node && node.nodeType > 0) {
  1072. switch (node.nodeType) {
  1073. case 1: // Element
  1074. return node.uniqueID;
  1075. case 9: // Document
  1076. return node.documentElement && node.documentElement.uniqueID;
  1077. }
  1078. }
  1079. }
  1080. // If possible, use a WeakMap.
  1081. var usingWeakMap = typeof WeakMap === 'function';
  1082. var weakMap;
  1083. if (usingWeakMap) {
  1084. weakMap = new WeakMap();
  1085. }
  1086. var objHashUID = 0;
  1087. var UID_HASH_KEY = '__immutablehash__';
  1088. if (typeof Symbol === 'function') {
  1089. UID_HASH_KEY = Symbol(UID_HASH_KEY);
  1090. }
  1091. var STRING_HASH_CACHE_MIN_STRLEN = 16;
  1092. var STRING_HASH_CACHE_MAX_SIZE = 255;
  1093. var STRING_HASH_CACHE_SIZE = 0;
  1094. var stringHashCache = {};
  1095. function assertNotInfinite(size) {
  1096. invariant(
  1097. size !== Infinity,
  1098. 'Cannot perform this action with an infinite size.'
  1099. );
  1100. }
  1101. createClass(Map, KeyedCollection);
  1102. // @pragma Construction
  1103. function Map(value) {
  1104. return value === null || value === undefined ? emptyMap() :
  1105. isMap(value) && !isOrdered(value) ? value :
  1106. emptyMap().withMutations(function(map ) {
  1107. var iter = KeyedIterable(value);
  1108. assertNotInfinite(iter.size);
  1109. iter.forEach(function(v, k) {return map.set(k, v)});
  1110. });
  1111. }
  1112. Map.prototype.toString = function() {
  1113. return this.__toString('Map {', '}');
  1114. };
  1115. // @pragma Access
  1116. Map.prototype.get = function(k, notSetValue) {
  1117. return this._root ?
  1118. this._root.get(0, undefined, k, notSetValue) :
  1119. notSetValue;
  1120. };
  1121. // @pragma Modification
  1122. Map.prototype.set = function(k, v) {
  1123. return updateMap(this, k, v);
  1124. };
  1125. Map.prototype.setIn = function(keyPath, v) {
  1126. return this.updateIn(keyPath, NOT_SET, function() {return v});
  1127. };
  1128. Map.prototype.remove = function(k) {
  1129. return updateMap(this, k, NOT_SET);
  1130. };
  1131. Map.prototype.deleteIn = function(keyPath) {
  1132. return this.updateIn(keyPath, function() {return NOT_SET});
  1133. };
  1134. Map.prototype.update = function(k, notSetValue, updater) {
  1135. return arguments.length === 1 ?
  1136. k(this) :
  1137. this.updateIn([k], notSetValue, updater);
  1138. };
  1139. Map.prototype.updateIn = function(keyPath, notSetValue, updater) {
  1140. if (!updater) {
  1141. updater = notSetValue;
  1142. notSetValue = undefined;
  1143. }
  1144. var updatedValue = updateInDeepMap(
  1145. this,
  1146. forceIterator(keyPath),
  1147. notSetValue,
  1148. updater
  1149. );
  1150. return updatedValue === NOT_SET ? undefined : updatedValue;
  1151. };
  1152. Map.prototype.clear = function() {
  1153. if (this.size === 0) {
  1154. return this;
  1155. }
  1156. if (this.__ownerID) {
  1157. this.size = 0;
  1158. this._root = null;
  1159. this.__hash = undefined;
  1160. this.__altered = true;
  1161. return this;
  1162. }
  1163. return emptyMap();
  1164. };
  1165. // @pragma Composition
  1166. Map.prototype.merge = function(/*...iters*/) {
  1167. return mergeIntoMapWith(this, undefined, arguments);
  1168. };
  1169. Map.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  1170. return mergeIntoMapWith(this, merger, iters);
  1171. };
  1172. Map.prototype.mergeIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1);
  1173. return this.updateIn(
  1174. keyPath,
  1175. emptyMap(),
  1176. function(m ) {return typeof m.merge === 'function' ?
  1177. m.merge.apply(m, iters) :
  1178. iters[iters.length - 1]}
  1179. );
  1180. };
  1181. Map.prototype.mergeDeep = function(/*...iters*/) {
  1182. return mergeIntoMapWith(this, deepMerger, arguments);
  1183. };
  1184. Map.prototype.mergeDeepWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  1185. return mergeIntoMapWith(this, deepMergerWith(merger), iters);
  1186. };
  1187. Map.prototype.mergeDeepIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1);
  1188. return this.updateIn(
  1189. keyPath,
  1190. emptyMap(),
  1191. function(m ) {return typeof m.mergeDeep === 'function' ?
  1192. m.mergeDeep.apply(m, iters) :
  1193. iters[iters.length - 1]}
  1194. );
  1195. };
  1196. Map.prototype.sort = function(comparator) {
  1197. // Late binding
  1198. return OrderedMap(sortFactory(this, comparator));
  1199. };
  1200. Map.prototype.sortBy = function(mapper, comparator) {
  1201. // Late binding
  1202. return OrderedMap(sortFactory(this, comparator, mapper));
  1203. };
  1204. // @pragma Mutability
  1205. Map.prototype.withMutations = function(fn) {
  1206. var mutable = this.asMutable();
  1207. fn(mutable);
  1208. return mutable.wasAltered() ? mutable.__ensureOwner(this.__ownerID) : this;
  1209. };
  1210. Map.prototype.asMutable = function() {
  1211. return this.__ownerID ? this : this.__ensureOwner(new OwnerID());
  1212. };
  1213. Map.prototype.asImmutable = function() {
  1214. return this.__ensureOwner();
  1215. };
  1216. Map.prototype.wasAltered = function() {
  1217. return this.__altered;
  1218. };
  1219. Map.prototype.__iterator = function(type, reverse) {
  1220. return new MapIterator(this, type, reverse);
  1221. };
  1222. Map.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  1223. var iterations = 0;
  1224. this._root && this._root.iterate(function(entry ) {
  1225. iterations++;
  1226. return fn(entry[1], entry[0], this$0);
  1227. }, reverse);
  1228. return iterations;
  1229. };
  1230. Map.prototype.__ensureOwner = function(ownerID) {
  1231. if (ownerID === this.__ownerID) {
  1232. return this;
  1233. }
  1234. if (!ownerID) {
  1235. this.__ownerID = ownerID;
  1236. this.__altered = false;
  1237. return this;
  1238. }
  1239. return makeMap(this.size, this._root, ownerID, this.__hash);
  1240. };
  1241. function isMap(maybeMap) {
  1242. return !!(maybeMap && maybeMap[IS_MAP_SENTINEL]);
  1243. }
  1244. Map.isMap = isMap;
  1245. var IS_MAP_SENTINEL = '@@__IMMUTABLE_MAP__@@';
  1246. var MapPrototype = Map.prototype;
  1247. MapPrototype[IS_MAP_SENTINEL] = true;
  1248. MapPrototype[DELETE] = MapPrototype.remove;
  1249. MapPrototype.removeIn = MapPrototype.deleteIn;
  1250. // #pragma Trie Nodes
  1251. function ArrayMapNode(ownerID, entries) {
  1252. this.ownerID = ownerID;
  1253. this.entries = entries;
  1254. }
  1255. ArrayMapNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  1256. var entries = this.entries;
  1257. for (var ii = 0, len = entries.length; ii < len; ii++) {
  1258. if (is(key, entries[ii][0])) {
  1259. return entries[ii][1];
  1260. }
  1261. }
  1262. return notSetValue;
  1263. };
  1264. ArrayMapNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  1265. var removed = value === NOT_SET;
  1266. var entries = this.entries;
  1267. var idx = 0;
  1268. for (var len = entries.length; idx < len; idx++) {
  1269. if (is(key, entries[idx][0])) {
  1270. break;
  1271. }
  1272. }
  1273. var exists = idx < len;
  1274. if (exists ? entries[idx][1] === value : removed) {
  1275. return this;
  1276. }
  1277. SetRef(didAlter);
  1278. (removed || !exists) && SetRef(didChangeSize);
  1279. if (removed && entries.length === 1) {
  1280. return; // undefined
  1281. }
  1282. if (!exists && !removed && entries.length >= MAX_ARRAY_MAP_SIZE) {
  1283. return createNodes(ownerID, entries, key, value);
  1284. }
  1285. var isEditable = ownerID && ownerID === this.ownerID;
  1286. var newEntries = isEditable ? entries : arrCopy(entries);
  1287. if (exists) {
  1288. if (removed) {
  1289. idx === len - 1 ? newEntries.pop() : (newEntries[idx] = newEntries.pop());
  1290. } else {
  1291. newEntries[idx] = [key, value];
  1292. }
  1293. } else {
  1294. newEntries.push([key, value]);
  1295. }
  1296. if (isEditable) {
  1297. this.entries = newEntries;
  1298. return this;
  1299. }
  1300. return new ArrayMapNode(ownerID, newEntries);
  1301. };
  1302. function BitmapIndexedNode(ownerID, bitmap, nodes) {
  1303. this.ownerID = ownerID;
  1304. this.bitmap = bitmap;
  1305. this.nodes = nodes;
  1306. }
  1307. BitmapIndexedNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  1308. if (keyHash === undefined) {
  1309. keyHash = hash(key);
  1310. }
  1311. var bit = (1 << ((shift === 0 ? keyHash : keyHash >>> shift) & MASK));
  1312. var bitmap = this.bitmap;
  1313. return (bitmap & bit) === 0 ? notSetValue :
  1314. this.nodes[popCount(bitmap & (bit - 1))].get(shift + SHIFT, keyHash, key, notSetValue);
  1315. };
  1316. BitmapIndexedNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  1317. if (keyHash === undefined) {
  1318. keyHash = hash(key);
  1319. }
  1320. var keyHashFrag = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  1321. var bit = 1 << keyHashFrag;
  1322. var bitmap = this.bitmap;
  1323. var exists = (bitmap & bit) !== 0;
  1324. if (!exists && value === NOT_SET) {
  1325. return this;
  1326. }
  1327. var idx = popCount(bitmap & (bit - 1));
  1328. var nodes = this.nodes;
  1329. var node = exists ? nodes[idx] : undefined;
  1330. var newNode = updateNode(node, ownerID, shift + SHIFT, keyHash, key, value, didChangeSize, didAlter);
  1331. if (newNode === node) {
  1332. return this;
  1333. }
  1334. if (!exists && newNode && nodes.length >= MAX_BITMAP_INDEXED_SIZE) {
  1335. return expandNodes(ownerID, nodes, bitmap, keyHashFrag, newNode);
  1336. }
  1337. if (exists && !newNode && nodes.length === 2 && isLeafNode(nodes[idx ^ 1])) {
  1338. return nodes[idx ^ 1];
  1339. }
  1340. if (exists && newNode && nodes.length === 1 && isLeafNode(newNode)) {
  1341. return newNode;
  1342. }
  1343. var isEditable = ownerID && ownerID === this.ownerID;
  1344. var newBitmap = exists ? newNode ? bitmap : bitmap ^ bit : bitmap | bit;
  1345. var newNodes = exists ? newNode ?
  1346. setIn(nodes, idx, newNode, isEditable) :
  1347. spliceOut(nodes, idx, isEditable) :
  1348. spliceIn(nodes, idx, newNode, isEditable);
  1349. if (isEditable) {
  1350. this.bitmap = newBitmap;
  1351. this.nodes = newNodes;
  1352. return this;
  1353. }
  1354. return new BitmapIndexedNode(ownerID, newBitmap, newNodes);
  1355. };
  1356. function HashArrayMapNode(ownerID, count, nodes) {
  1357. this.ownerID = ownerID;
  1358. this.count = count;
  1359. this.nodes = nodes;
  1360. }
  1361. HashArrayMapNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  1362. if (keyHash === undefined) {
  1363. keyHash = hash(key);
  1364. }
  1365. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  1366. var node = this.nodes[idx];
  1367. return node ? node.get(shift + SHIFT, keyHash, key, notSetValue) : notSetValue;
  1368. };
  1369. HashArrayMapNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  1370. if (keyHash === undefined) {
  1371. keyHash = hash(key);
  1372. }
  1373. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  1374. var removed = value === NOT_SET;
  1375. var nodes = this.nodes;
  1376. var node = nodes[idx];
  1377. if (removed && !node) {
  1378. return this;
  1379. }
  1380. var newNode = updateNode(node, ownerID, shift + SHIFT, keyHash, key, value, didChangeSize, didAlter);
  1381. if (newNode === node) {
  1382. return this;
  1383. }
  1384. var newCount = this.count;
  1385. if (!node) {
  1386. newCount++;
  1387. } else if (!newNode) {
  1388. newCount--;
  1389. if (newCount < MIN_HASH_ARRAY_MAP_SIZE) {
  1390. return packNodes(ownerID, nodes, newCount, idx);
  1391. }
  1392. }
  1393. var isEditable = ownerID && ownerID === this.ownerID;
  1394. var newNodes = setIn(nodes, idx, newNode, isEditable);
  1395. if (isEditable) {
  1396. this.count = newCount;
  1397. this.nodes = newNodes;
  1398. return this;
  1399. }
  1400. return new HashArrayMapNode(ownerID, newCount, newNodes);
  1401. };
  1402. function HashCollisionNode(ownerID, keyHash, entries) {
  1403. this.ownerID = ownerID;
  1404. this.keyHash = keyHash;
  1405. this.entries = entries;
  1406. }
  1407. HashCollisionNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  1408. var entries = this.entries;
  1409. for (var ii = 0, len = entries.length; ii < len; ii++) {
  1410. if (is(key, entries[ii][0])) {
  1411. return entries[ii][1];
  1412. }
  1413. }
  1414. return notSetValue;
  1415. };
  1416. HashCollisionNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  1417. if (keyHash === undefined) {
  1418. keyHash = hash(key);
  1419. }
  1420. var removed = value === NOT_SET;
  1421. if (keyHash !== this.keyHash) {
  1422. if (removed) {
  1423. return this;
  1424. }
  1425. SetRef(didAlter);
  1426. SetRef(didChangeSize);
  1427. return mergeIntoNode(this, ownerID, shift, keyHash, [key, value]);
  1428. }
  1429. var entries = this.entries;
  1430. var idx = 0;
  1431. for (var len = entries.length; idx < len; idx++) {
  1432. if (is(key, entries[idx][0])) {
  1433. break;
  1434. }
  1435. }
  1436. var exists = idx < len;
  1437. if (exists ? entries[idx][1] === value : removed) {
  1438. return this;
  1439. }
  1440. SetRef(didAlter);
  1441. (removed || !exists) && SetRef(didChangeSize);
  1442. if (removed && len === 2) {
  1443. return new ValueNode(ownerID, this.keyHash, entries[idx ^ 1]);
  1444. }
  1445. var isEditable = ownerID && ownerID === this.ownerID;
  1446. var newEntries = isEditable ? entries : arrCopy(entries);
  1447. if (exists) {
  1448. if (removed) {
  1449. idx === len - 1 ? newEntries.pop() : (newEntries[idx] = newEntries.pop());
  1450. } else {
  1451. newEntries[idx] = [key, value];
  1452. }
  1453. } else {
  1454. newEntries.push([key, value]);
  1455. }
  1456. if (isEditable) {
  1457. this.entries = newEntries;
  1458. return this;
  1459. }
  1460. return new HashCollisionNode(ownerID, this.keyHash, newEntries);
  1461. };
  1462. function ValueNode(ownerID, keyHash, entry) {
  1463. this.ownerID = ownerID;
  1464. this.keyHash = keyHash;
  1465. this.entry = entry;
  1466. }
  1467. ValueNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  1468. return is(key, this.entry[0]) ? this.entry[1] : notSetValue;
  1469. };
  1470. ValueNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  1471. var removed = value === NOT_SET;
  1472. var keyMatch = is(key, this.entry[0]);
  1473. if (keyMatch ? value === this.entry[1] : removed) {
  1474. return this;
  1475. }
  1476. SetRef(didAlter);
  1477. if (removed) {
  1478. SetRef(didChangeSize);
  1479. return; // undefined
  1480. }
  1481. if (keyMatch) {
  1482. if (ownerID && ownerID === this.ownerID) {
  1483. this.entry[1] = value;
  1484. return this;
  1485. }
  1486. return new ValueNode(ownerID, this.keyHash, [key, value]);
  1487. }
  1488. SetRef(didChangeSize);
  1489. return mergeIntoNode(this, ownerID, shift, hash(key), [key, value]);
  1490. };
  1491. // #pragma Iterators
  1492. ArrayMapNode.prototype.iterate =
  1493. HashCollisionNode.prototype.iterate = function (fn, reverse) {
  1494. var entries = this.entries;
  1495. for (var ii = 0, maxIndex = entries.length - 1; ii <= maxIndex; ii++) {
  1496. if (fn(entries[reverse ? maxIndex - ii : ii]) === false) {
  1497. return false;
  1498. }
  1499. }
  1500. };
  1501. BitmapIndexedNode.prototype.iterate =
  1502. HashArrayMapNode.prototype.iterate = function (fn, reverse) {
  1503. var nodes = this.nodes;
  1504. for (var ii = 0, maxIndex = nodes.length - 1; ii <= maxIndex; ii++) {
  1505. var node = nodes[reverse ? maxIndex - ii : ii];
  1506. if (node && node.iterate(fn, reverse) === false) {
  1507. return false;
  1508. }
  1509. }
  1510. };
  1511. ValueNode.prototype.iterate = function (fn, reverse) {
  1512. return fn(this.entry);
  1513. };
  1514. createClass(MapIterator, Iterator);
  1515. function MapIterator(map, type, reverse) {
  1516. this._type = type;
  1517. this._reverse = reverse;
  1518. this._stack = map._root && mapIteratorFrame(map._root);
  1519. }
  1520. MapIterator.prototype.next = function() {
  1521. var type = this._type;
  1522. var stack = this._stack;
  1523. while (stack) {
  1524. var node = stack.node;
  1525. var index = stack.index++;
  1526. var maxIndex;
  1527. if (node.entry) {
  1528. if (index === 0) {
  1529. return mapIteratorValue(type, node.entry);
  1530. }
  1531. } else if (node.entries) {
  1532. maxIndex = node.entries.length - 1;
  1533. if (index <= maxIndex) {
  1534. return mapIteratorValue(type, node.entries[this._reverse ? maxIndex - index : index]);
  1535. }
  1536. } else {
  1537. maxIndex = node.nodes.length - 1;
  1538. if (index <= maxIndex) {
  1539. var subNode = node.nodes[this._reverse ? maxIndex - index : index];
  1540. if (subNode) {
  1541. if (subNode.entry) {
  1542. return mapIteratorValue(type, subNode.entry);
  1543. }
  1544. stack = this._stack = mapIteratorFrame(subNode, stack);
  1545. }
  1546. continue;
  1547. }
  1548. }
  1549. stack = this._stack = this._stack.__prev;
  1550. }
  1551. return iteratorDone();
  1552. };
  1553. function mapIteratorValue(type, entry) {
  1554. return iteratorValue(type, entry[0], entry[1]);
  1555. }
  1556. function mapIteratorFrame(node, prev) {
  1557. return {
  1558. node: node,
  1559. index: 0,
  1560. __prev: prev
  1561. };
  1562. }
  1563. function makeMap(size, root, ownerID, hash) {
  1564. var map = Object.create(MapPrototype);
  1565. map.size = size;
  1566. map._root = root;
  1567. map.__ownerID = ownerID;
  1568. map.__hash = hash;
  1569. map.__altered = false;
  1570. return map;
  1571. }
  1572. var EMPTY_MAP;
  1573. function emptyMap() {
  1574. return EMPTY_MAP || (EMPTY_MAP = makeMap(0));
  1575. }
  1576. function updateMap(map, k, v) {
  1577. var newRoot;
  1578. var newSize;
  1579. if (!map._root) {
  1580. if (v === NOT_SET) {
  1581. return map;
  1582. }
  1583. newSize = 1;
  1584. newRoot = new ArrayMapNode(map.__ownerID, [[k, v]]);
  1585. } else {
  1586. var didChangeSize = MakeRef(CHANGE_LENGTH);
  1587. var didAlter = MakeRef(DID_ALTER);
  1588. newRoot = updateNode(map._root, map.__ownerID, 0, undefined, k, v, didChangeSize, didAlter);
  1589. if (!didAlter.value) {
  1590. return map;
  1591. }
  1592. newSize = map.size + (didChangeSize.value ? v === NOT_SET ? -1 : 1 : 0);
  1593. }
  1594. if (map.__ownerID) {
  1595. map.size = newSize;
  1596. map._root = newRoot;
  1597. map.__hash = undefined;
  1598. map.__altered = true;
  1599. return map;
  1600. }
  1601. return newRoot ? makeMap(newSize, newRoot) : emptyMap();
  1602. }
  1603. function updateNode(node, ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  1604. if (!node) {
  1605. if (value === NOT_SET) {
  1606. return node;
  1607. }
  1608. SetRef(didAlter);
  1609. SetRef(didChangeSize);
  1610. return new ValueNode(ownerID, keyHash, [key, value]);
  1611. }
  1612. return node.update(ownerID, shift, keyHash, key, value, didChangeSize, didAlter);
  1613. }
  1614. function isLeafNode(node) {
  1615. return node.constructor === ValueNode || node.constructor === HashCollisionNode;
  1616. }
  1617. function mergeIntoNode(node, ownerID, shift, keyHash, entry) {
  1618. if (node.keyHash === keyHash) {
  1619. return new HashCollisionNode(ownerID, keyHash, [node.entry, entry]);
  1620. }
  1621. var idx1 = (shift === 0 ? node.keyHash : node.keyHash >>> shift) & MASK;
  1622. var idx2 = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  1623. var newNode;
  1624. var nodes = idx1 === idx2 ?
  1625. [mergeIntoNode(node, ownerID, shift + SHIFT, keyHash, entry)] :
  1626. ((newNode = new ValueNode(ownerID, keyHash, entry)), idx1 < idx2 ? [node, newNode] : [newNode, node]);
  1627. return new BitmapIndexedNode(ownerID, (1 << idx1) | (1 << idx2), nodes);
  1628. }
  1629. function createNodes(ownerID, entries, key, value) {
  1630. if (!ownerID) {
  1631. ownerID = new OwnerID();
  1632. }
  1633. var node = new ValueNode(ownerID, hash(key), [key, value]);
  1634. for (var ii = 0; ii < entries.length; ii++) {
  1635. var entry = entries[ii];
  1636. node = node.update(ownerID, 0, undefined, entry[0], entry[1]);
  1637. }
  1638. return node;
  1639. }
  1640. function packNodes(ownerID, nodes, count, excluding) {
  1641. var bitmap = 0;
  1642. var packedII = 0;
  1643. var packedNodes = new Array(count);
  1644. for (var ii = 0, bit = 1, len = nodes.length; ii < len; ii++, bit <<= 1) {
  1645. var node = nodes[ii];
  1646. if (node !== undefined && ii !== excluding) {
  1647. bitmap |= bit;
  1648. packedNodes[packedII++] = node;
  1649. }
  1650. }
  1651. return new BitmapIndexedNode(ownerID, bitmap, packedNodes);
  1652. }
  1653. function expandNodes(ownerID, nodes, bitmap, including, node) {
  1654. var count = 0;
  1655. var expandedNodes = new Array(SIZE);
  1656. for (var ii = 0; bitmap !== 0; ii++, bitmap >>>= 1) {
  1657. expandedNodes[ii] = bitmap & 1 ? nodes[count++] : undefined;
  1658. }
  1659. expandedNodes[including] = node;
  1660. return new HashArrayMapNode(ownerID, count + 1, expandedNodes);
  1661. }
  1662. function mergeIntoMapWith(map, merger, iterables) {
  1663. var iters = [];
  1664. for (var ii = 0; ii < iterables.length; ii++) {
  1665. var value = iterables[ii];
  1666. var iter = KeyedIterable(value);
  1667. if (!isIterable(value)) {
  1668. iter = iter.map(function(v ) {return fromJS(v)});
  1669. }
  1670. iters.push(iter);
  1671. }
  1672. return mergeIntoCollectionWith(map, merger, iters);
  1673. }
  1674. function deepMerger(existing, value, key) {
  1675. return existing && existing.mergeDeep && isIterable(value) ?
  1676. existing.mergeDeep(value) :
  1677. is(existing, value) ? existing : value;
  1678. }
  1679. function deepMergerWith(merger) {
  1680. return function(existing, value, key) {
  1681. if (existing && existing.mergeDeepWith && isIterable(value)) {
  1682. return existing.mergeDeepWith(merger, value);
  1683. }
  1684. var nextValue = merger(existing, value, key);
  1685. return is(existing, nextValue) ? existing : nextValue;
  1686. };
  1687. }
  1688. function mergeIntoCollectionWith(collection, merger, iters) {
  1689. iters = iters.filter(function(x ) {return x.size !== 0});
  1690. if (iters.length === 0) {
  1691. return collection;
  1692. }
  1693. if (collection.size === 0 && !collection.__ownerID && iters.length === 1) {
  1694. return collection.constructor(iters[0]);
  1695. }
  1696. return collection.withMutations(function(collection ) {
  1697. var mergeIntoMap = merger ?
  1698. function(value, key) {
  1699. collection.update(key, NOT_SET, function(existing )
  1700. {return existing === NOT_SET ? value : merger(existing, value, key)}
  1701. );
  1702. } :
  1703. function(value, key) {
  1704. collection.set(key, value);
  1705. };
  1706. for (var ii = 0; ii < iters.length; ii++) {
  1707. iters[ii].forEach(mergeIntoMap);
  1708. }
  1709. });
  1710. }
  1711. function updateInDeepMap(existing, keyPathIter, notSetValue, updater) {
  1712. var isNotSet = existing === NOT_SET;
  1713. var step = keyPathIter.next();
  1714. if (step.done) {
  1715. var existingValue = isNotSet ? notSetValue : existing;
  1716. var newValue = updater(existingValue);
  1717. return newValue === existingValue ? existing : newValue;
  1718. }
  1719. invariant(
  1720. isNotSet || (existing && existing.set),
  1721. 'invalid keyPath'
  1722. );
  1723. var key = step.value;
  1724. var nextExisting = isNotSet ? NOT_SET : existing.get(key, NOT_SET);
  1725. var nextUpdated = updateInDeepMap(
  1726. nextExisting,
  1727. keyPathIter,
  1728. notSetValue,
  1729. updater
  1730. );
  1731. return nextUpdated === nextExisting ? existing :
  1732. nextUpdated === NOT_SET ? existing.remove(key) :
  1733. (isNotSet ? emptyMap() : existing).set(key, nextUpdated);
  1734. }
  1735. function popCount(x) {
  1736. x = x - ((x >> 1) & 0x55555555);
  1737. x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
  1738. x = (x + (x >> 4)) & 0x0f0f0f0f;
  1739. x = x + (x >> 8);
  1740. x = x + (x >> 16);
  1741. return x & 0x7f;
  1742. }
  1743. function setIn(array, idx, val, canEdit) {
  1744. var newArray = canEdit ? array : arrCopy(array);
  1745. newArray[idx] = val;
  1746. return newArray;
  1747. }
  1748. function spliceIn(array, idx, val, canEdit) {
  1749. var newLen = array.length + 1;
  1750. if (canEdit && idx + 1 === newLen) {
  1751. array[idx] = val;
  1752. return array;
  1753. }
  1754. var newArray = new Array(newLen);
  1755. var after = 0;
  1756. for (var ii = 0; ii < newLen; ii++) {
  1757. if (ii === idx) {
  1758. newArray[ii] = val;
  1759. after = -1;
  1760. } else {
  1761. newArray[ii] = array[ii + after];
  1762. }
  1763. }
  1764. return newArray;
  1765. }
  1766. function spliceOut(array, idx, canEdit) {
  1767. var newLen = array.length - 1;
  1768. if (canEdit && idx === newLen) {
  1769. array.pop();
  1770. return array;
  1771. }
  1772. var newArray = new Array(newLen);
  1773. var after = 0;
  1774. for (var ii = 0; ii < newLen; ii++) {
  1775. if (ii === idx) {
  1776. after = 1;
  1777. }
  1778. newArray[ii] = array[ii + after];
  1779. }
  1780. return newArray;
  1781. }
  1782. var MAX_ARRAY_MAP_SIZE = SIZE / 4;
  1783. var MAX_BITMAP_INDEXED_SIZE = SIZE / 2;
  1784. var MIN_HASH_ARRAY_MAP_SIZE = SIZE / 4;
  1785. createClass(List, IndexedCollection);
  1786. // @pragma Construction
  1787. function List(value) {
  1788. var empty = emptyList();
  1789. if (value === null || value === undefined) {
  1790. return empty;
  1791. }
  1792. if (isList(value)) {
  1793. return value;
  1794. }
  1795. var iter = IndexedIterable(value);
  1796. var size = iter.size;
  1797. if (size === 0) {
  1798. return empty;
  1799. }
  1800. assertNotInfinite(size);
  1801. if (size > 0 && size < SIZE) {
  1802. return makeList(0, size, SHIFT, null, new VNode(iter.toArray()));
  1803. }
  1804. return empty.withMutations(function(list ) {
  1805. list.setSize(size);
  1806. iter.forEach(function(v, i) {return list.set(i, v)});
  1807. });
  1808. }
  1809. List.of = function(/*...values*/) {
  1810. return this(arguments);
  1811. };
  1812. List.prototype.toString = function() {
  1813. return this.__toString('List [', ']');
  1814. };
  1815. // @pragma Access
  1816. List.prototype.get = function(index, notSetValue) {
  1817. index = wrapIndex(this, index);
  1818. if (index >= 0 && index < this.size) {
  1819. index += this._origin;
  1820. var node = listNodeFor(this, index);
  1821. return node && node.array[index & MASK];
  1822. }
  1823. return notSetValue;
  1824. };
  1825. // @pragma Modification
  1826. List.prototype.set = function(index, value) {
  1827. return updateList(this, index, value);
  1828. };
  1829. List.prototype.remove = function(index) {
  1830. return !this.has(index) ? this :
  1831. index === 0 ? this.shift() :
  1832. index === this.size - 1 ? this.pop() :
  1833. this.splice(index, 1);
  1834. };
  1835. List.prototype.insert = function(index, value) {
  1836. return this.splice(index, 0, value);
  1837. };
  1838. List.prototype.clear = function() {
  1839. if (this.size === 0) {
  1840. return this;
  1841. }
  1842. if (this.__ownerID) {
  1843. this.size = this._origin = this._capacity = 0;
  1844. this._level = SHIFT;
  1845. this._root = this._tail = null;
  1846. this.__hash = undefined;
  1847. this.__altered = true;
  1848. return this;
  1849. }
  1850. return emptyList();
  1851. };
  1852. List.prototype.push = function(/*...values*/) {
  1853. var values = arguments;
  1854. var oldSize = this.size;
  1855. return this.withMutations(function(list ) {
  1856. setListBounds(list, 0, oldSize + values.length);
  1857. for (var ii = 0; ii < values.length; ii++) {
  1858. list.set(oldSize + ii, values[ii]);
  1859. }
  1860. });
  1861. };
  1862. List.prototype.pop = function() {
  1863. return setListBounds(this, 0, -1);
  1864. };
  1865. List.prototype.unshift = function(/*...values*/) {
  1866. var values = arguments;
  1867. return this.withMutations(function(list ) {
  1868. setListBounds(list, -values.length);
  1869. for (var ii = 0; ii < values.length; ii++) {
  1870. list.set(ii, values[ii]);
  1871. }
  1872. });
  1873. };
  1874. List.prototype.shift = function() {
  1875. return setListBounds(this, 1);
  1876. };
  1877. // @pragma Composition
  1878. List.prototype.merge = function(/*...iters*/) {
  1879. return mergeIntoListWith(this, undefined, arguments);
  1880. };
  1881. List.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  1882. return mergeIntoListWith(this, merger, iters);
  1883. };
  1884. List.prototype.mergeDeep = function(/*...iters*/) {
  1885. return mergeIntoListWith(this, deepMerger, arguments);
  1886. };
  1887. List.prototype.mergeDeepWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  1888. return mergeIntoListWith(this, deepMergerWith(merger), iters);
  1889. };
  1890. List.prototype.setSize = function(size) {
  1891. return setListBounds(this, 0, size);
  1892. };
  1893. // @pragma Iteration
  1894. List.prototype.slice = function(begin, end) {
  1895. var size = this.size;
  1896. if (wholeSlice(begin, end, size)) {
  1897. return this;
  1898. }
  1899. return setListBounds(
  1900. this,
  1901. resolveBegin(begin, size),
  1902. resolveEnd(end, size)
  1903. );
  1904. };
  1905. List.prototype.__iterator = function(type, reverse) {
  1906. var index = 0;
  1907. var values = iterateList(this, reverse);
  1908. return new Iterator(function() {
  1909. var value = values();
  1910. return value === DONE ?
  1911. iteratorDone() :
  1912. iteratorValue(type, index++, value);
  1913. });
  1914. };
  1915. List.prototype.__iterate = function(fn, reverse) {
  1916. var index = 0;
  1917. var values = iterateList(this, reverse);
  1918. var value;
  1919. while ((value = values()) !== DONE) {
  1920. if (fn(value, index++, this) === false) {
  1921. break;
  1922. }
  1923. }
  1924. return index;
  1925. };
  1926. List.prototype.__ensureOwner = function(ownerID) {
  1927. if (ownerID === this.__ownerID) {
  1928. return this;
  1929. }
  1930. if (!ownerID) {
  1931. this.__ownerID = ownerID;
  1932. return this;
  1933. }
  1934. return makeList(this._origin, this._capacity, this._level, this._root, this._tail, ownerID, this.__hash);
  1935. };
  1936. function isList(maybeList) {
  1937. return !!(maybeList && maybeList[IS_LIST_SENTINEL]);
  1938. }
  1939. List.isList = isList;
  1940. var IS_LIST_SENTINEL = '@@__IMMUTABLE_LIST__@@';
  1941. var ListPrototype = List.prototype;
  1942. ListPrototype[IS_LIST_SENTINEL] = true;
  1943. ListPrototype[DELETE] = ListPrototype.remove;
  1944. ListPrototype.setIn = MapPrototype.setIn;
  1945. ListPrototype.deleteIn =
  1946. ListPrototype.removeIn = MapPrototype.removeIn;
  1947. ListPrototype.update = MapPrototype.update;
  1948. ListPrototype.updateIn = MapPrototype.updateIn;
  1949. ListPrototype.mergeIn = MapPrototype.mergeIn;
  1950. ListPrototype.mergeDeepIn = MapPrototype.mergeDeepIn;
  1951. ListPrototype.withMutations = MapPrototype.withMutations;
  1952. ListPrototype.asMutable = MapPrototype.asMutable;
  1953. ListPrototype.asImmutable = MapPrototype.asImmutable;
  1954. ListPrototype.wasAltered = MapPrototype.wasAltered;
  1955. function VNode(array, ownerID) {
  1956. this.array = array;
  1957. this.ownerID = ownerID;
  1958. }
  1959. // TODO: seems like these methods are very similar
  1960. VNode.prototype.removeBefore = function(ownerID, level, index) {
  1961. if (index === level ? 1 << level : this.array.length === 0) {
  1962. return this;
  1963. }
  1964. var originIndex = (index >>> level) & MASK;
  1965. if (originIndex >= this.array.length) {
  1966. return new VNode([], ownerID);
  1967. }
  1968. var removingFirst = originIndex === 0;
  1969. var newChild;
  1970. if (level > 0) {
  1971. var oldChild = this.array[originIndex];
  1972. newChild = oldChild && oldChild.removeBefore(ownerID, level - SHIFT, index);
  1973. if (newChild === oldChild && removingFirst) {
  1974. return this;
  1975. }
  1976. }
  1977. if (removingFirst && !newChild) {
  1978. return this;
  1979. }
  1980. var editable = editableVNode(this, ownerID);
  1981. if (!removingFirst) {
  1982. for (var ii = 0; ii < originIndex; ii++) {
  1983. editable.array[ii] = undefined;
  1984. }
  1985. }
  1986. if (newChild) {
  1987. editable.array[originIndex] = newChild;
  1988. }
  1989. return editable;
  1990. };
  1991. VNode.prototype.removeAfter = function(ownerID, level, index) {
  1992. if (index === (level ? 1 << level : 0) || this.array.length === 0) {
  1993. return this;
  1994. }
  1995. var sizeIndex = ((index - 1) >>> level) & MASK;
  1996. if (sizeIndex >= this.array.length) {
  1997. return this;
  1998. }
  1999. var newChild;
  2000. if (level > 0) {
  2001. var oldChild = this.array[sizeIndex];
  2002. newChild = oldChild && oldChild.removeAfter(ownerID, level - SHIFT, index);
  2003. if (newChild === oldChild && sizeIndex === this.array.length - 1) {
  2004. return this;
  2005. }
  2006. }
  2007. var editable = editableVNode(this, ownerID);
  2008. editable.array.splice(sizeIndex + 1);
  2009. if (newChild) {
  2010. editable.array[sizeIndex] = newChild;
  2011. }
  2012. return editable;
  2013. };
  2014. var DONE = {};
  2015. function iterateList(list, reverse) {
  2016. var left = list._origin;
  2017. var right = list._capacity;
  2018. var tailPos = getTailOffset(right);
  2019. var tail = list._tail;
  2020. return iterateNodeOrLeaf(list._root, list._level, 0);
  2021. function iterateNodeOrLeaf(node, level, offset) {
  2022. return level === 0 ?
  2023. iterateLeaf(node, offset) :
  2024. iterateNode(node, level, offset);
  2025. }
  2026. function iterateLeaf(node, offset) {
  2027. var array = offset === tailPos ? tail && tail.array : node && node.array;
  2028. var from = offset > left ? 0 : left - offset;
  2029. var to = right - offset;
  2030. if (to > SIZE) {
  2031. to = SIZE;
  2032. }
  2033. return function() {
  2034. if (from === to) {
  2035. return DONE;
  2036. }
  2037. var idx = reverse ? --to : from++;
  2038. return array && array[idx];
  2039. };
  2040. }
  2041. function iterateNode(node, level, offset) {
  2042. var values;
  2043. var array = node && node.array;
  2044. var from = offset > left ? 0 : (left - offset) >> level;
  2045. var to = ((right - offset) >> level) + 1;
  2046. if (to > SIZE) {
  2047. to = SIZE;
  2048. }
  2049. return function() {
  2050. do {
  2051. if (values) {
  2052. var value = values();
  2053. if (value !== DONE) {
  2054. return value;
  2055. }
  2056. values = null;
  2057. }
  2058. if (from === to) {
  2059. return DONE;
  2060. }
  2061. var idx = reverse ? --to : from++;
  2062. values = iterateNodeOrLeaf(
  2063. array && array[idx], level - SHIFT, offset + (idx << level)
  2064. );
  2065. } while (true);
  2066. };
  2067. }
  2068. }
  2069. function makeList(origin, capacity, level, root, tail, ownerID, hash) {
  2070. var list = Object.create(ListPrototype);
  2071. list.size = capacity - origin;
  2072. list._origin = origin;
  2073. list._capacity = capacity;
  2074. list._level = level;
  2075. list._root = root;
  2076. list._tail = tail;
  2077. list.__ownerID = ownerID;
  2078. list.__hash = hash;
  2079. list.__altered = false;
  2080. return list;
  2081. }
  2082. var EMPTY_LIST;
  2083. function emptyList() {
  2084. return EMPTY_LIST || (EMPTY_LIST = makeList(0, 0, SHIFT));
  2085. }
  2086. function updateList(list, index, value) {
  2087. index = wrapIndex(list, index);
  2088. if (index !== index) {
  2089. return list;
  2090. }
  2091. if (index >= list.size || index < 0) {
  2092. return list.withMutations(function(list ) {
  2093. index < 0 ?
  2094. setListBounds(list, index).set(0, value) :
  2095. setListBounds(list, 0, index + 1).set(index, value);
  2096. });
  2097. }
  2098. index += list._origin;
  2099. var newTail = list._tail;
  2100. var newRoot = list._root;
  2101. var didAlter = MakeRef(DID_ALTER);
  2102. if (index >= getTailOffset(list._capacity)) {
  2103. newTail = updateVNode(newTail, list.__ownerID, 0, index, value, didAlter);
  2104. } else {
  2105. newRoot = updateVNode(newRoot, list.__ownerID, list._level, index, value, didAlter);
  2106. }
  2107. if (!didAlter.value) {
  2108. return list;
  2109. }
  2110. if (list.__ownerID) {
  2111. list._root = newRoot;
  2112. list._tail = newTail;
  2113. list.__hash = undefined;
  2114. list.__altered = true;
  2115. return list;
  2116. }
  2117. return makeList(list._origin, list._capacity, list._level, newRoot, newTail);
  2118. }
  2119. function updateVNode(node, ownerID, level, index, value, didAlter) {
  2120. var idx = (index >>> level) & MASK;
  2121. var nodeHas = node && idx < node.array.length;
  2122. if (!nodeHas && value === undefined) {
  2123. return node;
  2124. }
  2125. var newNode;
  2126. if (level > 0) {
  2127. var lowerNode = node && node.array[idx];
  2128. var newLowerNode = updateVNode(lowerNode, ownerID, level - SHIFT, index, value, didAlter);
  2129. if (newLowerNode === lowerNode) {
  2130. return node;
  2131. }
  2132. newNode = editableVNode(node, ownerID);
  2133. newNode.array[idx] = newLowerNode;
  2134. return newNode;
  2135. }
  2136. if (nodeHas && node.array[idx] === value) {
  2137. return node;
  2138. }
  2139. SetRef(didAlter);
  2140. newNode = editableVNode(node, ownerID);
  2141. if (value === undefined && idx === newNode.array.length - 1) {
  2142. newNode.array.pop();
  2143. } else {
  2144. newNode.array[idx] = value;
  2145. }
  2146. return newNode;
  2147. }
  2148. function editableVNode(node, ownerID) {
  2149. if (ownerID && node && ownerID === node.ownerID) {
  2150. return node;
  2151. }
  2152. return new VNode(node ? node.array.slice() : [], ownerID);
  2153. }
  2154. function listNodeFor(list, rawIndex) {
  2155. if (rawIndex >= getTailOffset(list._capacity)) {
  2156. return list._tail;
  2157. }
  2158. if (rawIndex < 1 << (list._level + SHIFT)) {
  2159. var node = list._root;
  2160. var level = list._level;
  2161. while (node && level > 0) {
  2162. node = node.array[(rawIndex >>> level) & MASK];
  2163. level -= SHIFT;
  2164. }
  2165. return node;
  2166. }
  2167. }
  2168. function setListBounds(list, begin, end) {
  2169. // Sanitize begin & end using this shorthand for ToInt32(argument)
  2170. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  2171. if (begin !== undefined) {
  2172. begin = begin | 0;
  2173. }
  2174. if (end !== undefined) {
  2175. end = end | 0;
  2176. }
  2177. var owner = list.__ownerID || new OwnerID();
  2178. var oldOrigin = list._origin;
  2179. var oldCapacity = list._capacity;
  2180. var newOrigin = oldOrigin + begin;
  2181. var newCapacity = end === undefined ? oldCapacity : end < 0 ? oldCapacity + end : oldOrigin + end;
  2182. if (newOrigin === oldOrigin && newCapacity === oldCapacity) {
  2183. return list;
  2184. }
  2185. // If it's going to end after it starts, it's empty.
  2186. if (newOrigin >= newCapacity) {
  2187. return list.clear();
  2188. }
  2189. var newLevel = list._level;
  2190. var newRoot = list._root;
  2191. // New origin might need creating a higher root.
  2192. var offsetShift = 0;
  2193. while (newOrigin + offsetShift < 0) {
  2194. newRoot = new VNode(newRoot && newRoot.array.length ? [undefined, newRoot] : [], owner);
  2195. newLevel += SHIFT;
  2196. offsetShift += 1 << newLevel;
  2197. }
  2198. if (offsetShift) {
  2199. newOrigin += offsetShift;
  2200. oldOrigin += offsetShift;
  2201. newCapacity += offsetShift;
  2202. oldCapacity += offsetShift;
  2203. }
  2204. var oldTailOffset = getTailOffset(oldCapacity);
  2205. var newTailOffset = getTailOffset(newCapacity);
  2206. // New size might need creating a higher root.
  2207. while (newTailOffset >= 1 << (newLevel + SHIFT)) {
  2208. newRoot = new VNode(newRoot && newRoot.array.length ? [newRoot] : [], owner);
  2209. newLevel += SHIFT;
  2210. }
  2211. // Locate or create the new tail.
  2212. var oldTail = list._tail;
  2213. var newTail = newTailOffset < oldTailOffset ?
  2214. listNodeFor(list, newCapacity - 1) :
  2215. newTailOffset > oldTailOffset ? new VNode([], owner) : oldTail;
  2216. // Merge Tail into tree.
  2217. if (oldTail && newTailOffset > oldTailOffset && newOrigin < oldCapacity && oldTail.array.length) {
  2218. newRoot = editableVNode(newRoot, owner);
  2219. var node = newRoot;
  2220. for (var level = newLevel; level > SHIFT; level -= SHIFT) {
  2221. var idx = (oldTailOffset >>> level) & MASK;
  2222. node = node.array[idx] = editableVNode(node.array[idx], owner);
  2223. }
  2224. node.array[(oldTailOffset >>> SHIFT) & MASK] = oldTail;
  2225. }
  2226. // If the size has been reduced, there's a chance the tail needs to be trimmed.
  2227. if (newCapacity < oldCapacity) {
  2228. newTail = newTail && newTail.removeAfter(owner, 0, newCapacity);
  2229. }
  2230. // If the new origin is within the tail, then we do not need a root.
  2231. if (newOrigin >= newTailOffset) {
  2232. newOrigin -= newTailOffset;
  2233. newCapacity -= newTailOffset;
  2234. newLevel = SHIFT;
  2235. newRoot = null;
  2236. newTail = newTail && newTail.removeBefore(owner, 0, newOrigin);
  2237. // Otherwise, if the root has been trimmed, garbage collect.
  2238. } else if (newOrigin > oldOrigin || newTailOffset < oldTailOffset) {
  2239. offsetShift = 0;
  2240. // Identify the new top root node of the subtree of the old root.
  2241. while (newRoot) {
  2242. var beginIndex = (newOrigin >>> newLevel) & MASK;
  2243. if (beginIndex !== (newTailOffset >>> newLevel) & MASK) {
  2244. break;
  2245. }
  2246. if (beginIndex) {
  2247. offsetShift += (1 << newLevel) * beginIndex;
  2248. }
  2249. newLevel -= SHIFT;
  2250. newRoot = newRoot.array[beginIndex];
  2251. }
  2252. // Trim the new sides of the new root.
  2253. if (newRoot && newOrigin > oldOrigin) {
  2254. newRoot = newRoot.removeBefore(owner, newLevel, newOrigin - offsetShift);
  2255. }
  2256. if (newRoot && newTailOffset < oldTailOffset) {
  2257. newRoot = newRoot.removeAfter(owner, newLevel, newTailOffset - offsetShift);
  2258. }
  2259. if (offsetShift) {
  2260. newOrigin -= offsetShift;
  2261. newCapacity -= offsetShift;
  2262. }
  2263. }
  2264. if (list.__ownerID) {
  2265. list.size = newCapacity - newOrigin;
  2266. list._origin = newOrigin;
  2267. list._capacity = newCapacity;
  2268. list._level = newLevel;
  2269. list._root = newRoot;
  2270. list._tail = newTail;
  2271. list.__hash = undefined;
  2272. list.__altered = true;
  2273. return list;
  2274. }
  2275. return makeList(newOrigin, newCapacity, newLevel, newRoot, newTail);
  2276. }
  2277. function mergeIntoListWith(list, merger, iterables) {
  2278. var iters = [];
  2279. var maxSize = 0;
  2280. for (var ii = 0; ii < iterables.length; ii++) {
  2281. var value = iterables[ii];
  2282. var iter = IndexedIterable(value);
  2283. if (iter.size > maxSize) {
  2284. maxSize = iter.size;
  2285. }
  2286. if (!isIterable(value)) {
  2287. iter = iter.map(function(v ) {return fromJS(v)});
  2288. }
  2289. iters.push(iter);
  2290. }
  2291. if (maxSize > list.size) {
  2292. list = list.setSize(maxSize);
  2293. }
  2294. return mergeIntoCollectionWith(list, merger, iters);
  2295. }
  2296. function getTailOffset(size) {
  2297. return size < SIZE ? 0 : (((size - 1) >>> SHIFT) << SHIFT);
  2298. }
  2299. createClass(OrderedMap, Map);
  2300. // @pragma Construction
  2301. function OrderedMap(value) {
  2302. return value === null || value === undefined ? emptyOrderedMap() :
  2303. isOrderedMap(value) ? value :
  2304. emptyOrderedMap().withMutations(function(map ) {
  2305. var iter = KeyedIterable(value);
  2306. assertNotInfinite(iter.size);
  2307. iter.forEach(function(v, k) {return map.set(k, v)});
  2308. });
  2309. }
  2310. OrderedMap.of = function(/*...values*/) {
  2311. return this(arguments);
  2312. };
  2313. OrderedMap.prototype.toString = function() {
  2314. return this.__toString('OrderedMap {', '}');
  2315. };
  2316. // @pragma Access
  2317. OrderedMap.prototype.get = function(k, notSetValue) {
  2318. var index = this._map.get(k);
  2319. return index !== undefined ? this._list.get(index)[1] : notSetValue;
  2320. };
  2321. // @pragma Modification
  2322. OrderedMap.prototype.clear = function() {
  2323. if (this.size === 0) {
  2324. return this;
  2325. }
  2326. if (this.__ownerID) {
  2327. this.size = 0;
  2328. this._map.clear();
  2329. this._list.clear();
  2330. return this;
  2331. }
  2332. return emptyOrderedMap();
  2333. };
  2334. OrderedMap.prototype.set = function(k, v) {
  2335. return updateOrderedMap(this, k, v);
  2336. };
  2337. OrderedMap.prototype.remove = function(k) {
  2338. return updateOrderedMap(this, k, NOT_SET);
  2339. };
  2340. OrderedMap.prototype.wasAltered = function() {
  2341. return this._map.wasAltered() || this._list.wasAltered();
  2342. };
  2343. OrderedMap.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  2344. return this._list.__iterate(
  2345. function(entry ) {return entry && fn(entry[1], entry[0], this$0)},
  2346. reverse
  2347. );
  2348. };
  2349. OrderedMap.prototype.__iterator = function(type, reverse) {
  2350. return this._list.fromEntrySeq().__iterator(type, reverse);
  2351. };
  2352. OrderedMap.prototype.__ensureOwner = function(ownerID) {
  2353. if (ownerID === this.__ownerID) {
  2354. return this;
  2355. }
  2356. var newMap = this._map.__ensureOwner(ownerID);
  2357. var newList = this._list.__ensureOwner(ownerID);
  2358. if (!ownerID) {
  2359. this.__ownerID = ownerID;
  2360. this._map = newMap;
  2361. this._list = newList;
  2362. return this;
  2363. }
  2364. return makeOrderedMap(newMap, newList, ownerID, this.__hash);
  2365. };
  2366. function isOrderedMap(maybeOrderedMap) {
  2367. return isMap(maybeOrderedMap) && isOrdered(maybeOrderedMap);
  2368. }
  2369. OrderedMap.isOrderedMap = isOrderedMap;
  2370. OrderedMap.prototype[IS_ORDERED_SENTINEL] = true;
  2371. OrderedMap.prototype[DELETE] = OrderedMap.prototype.remove;
  2372. function makeOrderedMap(map, list, ownerID, hash) {
  2373. var omap = Object.create(OrderedMap.prototype);
  2374. omap.size = map ? map.size : 0;
  2375. omap._map = map;
  2376. omap._list = list;
  2377. omap.__ownerID = ownerID;
  2378. omap.__hash = hash;
  2379. return omap;
  2380. }
  2381. var EMPTY_ORDERED_MAP;
  2382. function emptyOrderedMap() {
  2383. return EMPTY_ORDERED_MAP || (EMPTY_ORDERED_MAP = makeOrderedMap(emptyMap(), emptyList()));
  2384. }
  2385. function updateOrderedMap(omap, k, v) {
  2386. var map = omap._map;
  2387. var list = omap._list;
  2388. var i = map.get(k);
  2389. var has = i !== undefined;
  2390. var newMap;
  2391. var newList;
  2392. if (v === NOT_SET) { // removed
  2393. if (!has) {
  2394. return omap;
  2395. }
  2396. if (list.size >= SIZE && list.size >= map.size * 2) {
  2397. newList = list.filter(function(entry, idx) {return entry !== undefined && i !== idx});
  2398. newMap = newList.toKeyedSeq().map(function(entry ) {return entry[0]}).flip().toMap();
  2399. if (omap.__ownerID) {
  2400. newMap.__ownerID = newList.__ownerID = omap.__ownerID;
  2401. }
  2402. } else {
  2403. newMap = map.remove(k);
  2404. newList = i === list.size - 1 ? list.pop() : list.set(i, undefined);
  2405. }
  2406. } else {
  2407. if (has) {
  2408. if (v === list.get(i)[1]) {
  2409. return omap;
  2410. }
  2411. newMap = map;
  2412. newList = list.set(i, [k, v]);
  2413. } else {
  2414. newMap = map.set(k, list.size);
  2415. newList = list.set(list.size, [k, v]);
  2416. }
  2417. }
  2418. if (omap.__ownerID) {
  2419. omap.size = newMap.size;
  2420. omap._map = newMap;
  2421. omap._list = newList;
  2422. omap.__hash = undefined;
  2423. return omap;
  2424. }
  2425. return makeOrderedMap(newMap, newList);
  2426. }
  2427. createClass(ToKeyedSequence, KeyedSeq);
  2428. function ToKeyedSequence(indexed, useKeys) {
  2429. this._iter = indexed;
  2430. this._useKeys = useKeys;
  2431. this.size = indexed.size;
  2432. }
  2433. ToKeyedSequence.prototype.get = function(key, notSetValue) {
  2434. return this._iter.get(key, notSetValue);
  2435. };
  2436. ToKeyedSequence.prototype.has = function(key) {
  2437. return this._iter.has(key);
  2438. };
  2439. ToKeyedSequence.prototype.valueSeq = function() {
  2440. return this._iter.valueSeq();
  2441. };
  2442. ToKeyedSequence.prototype.reverse = function() {var this$0 = this;
  2443. var reversedSequence = reverseFactory(this, true);
  2444. if (!this._useKeys) {
  2445. reversedSequence.valueSeq = function() {return this$0._iter.toSeq().reverse()};
  2446. }
  2447. return reversedSequence;
  2448. };
  2449. ToKeyedSequence.prototype.map = function(mapper, context) {var this$0 = this;
  2450. var mappedSequence = mapFactory(this, mapper, context);
  2451. if (!this._useKeys) {
  2452. mappedSequence.valueSeq = function() {return this$0._iter.toSeq().map(mapper, context)};
  2453. }
  2454. return mappedSequence;
  2455. };
  2456. ToKeyedSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  2457. var ii;
  2458. return this._iter.__iterate(
  2459. this._useKeys ?
  2460. function(v, k) {return fn(v, k, this$0)} :
  2461. ((ii = reverse ? resolveSize(this) : 0),
  2462. function(v ) {return fn(v, reverse ? --ii : ii++, this$0)}),
  2463. reverse
  2464. );
  2465. };
  2466. ToKeyedSequence.prototype.__iterator = function(type, reverse) {
  2467. if (this._useKeys) {
  2468. return this._iter.__iterator(type, reverse);
  2469. }
  2470. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  2471. var ii = reverse ? resolveSize(this) : 0;
  2472. return new Iterator(function() {
  2473. var step = iterator.next();
  2474. return step.done ? step :
  2475. iteratorValue(type, reverse ? --ii : ii++, step.value, step);
  2476. });
  2477. };
  2478. ToKeyedSequence.prototype[IS_ORDERED_SENTINEL] = true;
  2479. createClass(ToIndexedSequence, IndexedSeq);
  2480. function ToIndexedSequence(iter) {
  2481. this._iter = iter;
  2482. this.size = iter.size;
  2483. }
  2484. ToIndexedSequence.prototype.includes = function(value) {
  2485. return this._iter.includes(value);
  2486. };
  2487. ToIndexedSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  2488. var iterations = 0;
  2489. return this._iter.__iterate(function(v ) {return fn(v, iterations++, this$0)}, reverse);
  2490. };
  2491. ToIndexedSequence.prototype.__iterator = function(type, reverse) {
  2492. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  2493. var iterations = 0;
  2494. return new Iterator(function() {
  2495. var step = iterator.next();
  2496. return step.done ? step :
  2497. iteratorValue(type, iterations++, step.value, step)
  2498. });
  2499. };
  2500. createClass(ToSetSequence, SetSeq);
  2501. function ToSetSequence(iter) {
  2502. this._iter = iter;
  2503. this.size = iter.size;
  2504. }
  2505. ToSetSequence.prototype.has = function(key) {
  2506. return this._iter.includes(key);
  2507. };
  2508. ToSetSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  2509. return this._iter.__iterate(function(v ) {return fn(v, v, this$0)}, reverse);
  2510. };
  2511. ToSetSequence.prototype.__iterator = function(type, reverse) {
  2512. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  2513. return new Iterator(function() {
  2514. var step = iterator.next();
  2515. return step.done ? step :
  2516. iteratorValue(type, step.value, step.value, step);
  2517. });
  2518. };
  2519. createClass(FromEntriesSequence, KeyedSeq);
  2520. function FromEntriesSequence(entries) {
  2521. this._iter = entries;
  2522. this.size = entries.size;
  2523. }
  2524. FromEntriesSequence.prototype.entrySeq = function() {
  2525. return this._iter.toSeq();
  2526. };
  2527. FromEntriesSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  2528. return this._iter.__iterate(function(entry ) {
  2529. // Check if entry exists first so array access doesn't throw for holes
  2530. // in the parent iteration.
  2531. if (entry) {
  2532. validateEntry(entry);
  2533. var indexedIterable = isIterable(entry);
  2534. return fn(
  2535. indexedIterable ? entry.get(1) : entry[1],
  2536. indexedIterable ? entry.get(0) : entry[0],
  2537. this$0
  2538. );
  2539. }
  2540. }, reverse);
  2541. };
  2542. FromEntriesSequence.prototype.__iterator = function(type, reverse) {
  2543. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  2544. return new Iterator(function() {
  2545. while (true) {
  2546. var step = iterator.next();
  2547. if (step.done) {
  2548. return step;
  2549. }
  2550. var entry = step.value;
  2551. // Check if entry exists first so array access doesn't throw for holes
  2552. // in the parent iteration.
  2553. if (entry) {
  2554. validateEntry(entry);
  2555. var indexedIterable = isIterable(entry);
  2556. return iteratorValue(
  2557. type,
  2558. indexedIterable ? entry.get(0) : entry[0],
  2559. indexedIterable ? entry.get(1) : entry[1],
  2560. step
  2561. );
  2562. }
  2563. }
  2564. });
  2565. };
  2566. ToIndexedSequence.prototype.cacheResult =
  2567. ToKeyedSequence.prototype.cacheResult =
  2568. ToSetSequence.prototype.cacheResult =
  2569. FromEntriesSequence.prototype.cacheResult =
  2570. cacheResultThrough;
  2571. function flipFactory(iterable) {
  2572. var flipSequence = makeSequence(iterable);
  2573. flipSequence._iter = iterable;
  2574. flipSequence.size = iterable.size;
  2575. flipSequence.flip = function() {return iterable};
  2576. flipSequence.reverse = function () {
  2577. var reversedSequence = iterable.reverse.apply(this); // super.reverse()
  2578. reversedSequence.flip = function() {return iterable.reverse()};
  2579. return reversedSequence;
  2580. };
  2581. flipSequence.has = function(key ) {return iterable.includes(key)};
  2582. flipSequence.includes = function(key ) {return iterable.has(key)};
  2583. flipSequence.cacheResult = cacheResultThrough;
  2584. flipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  2585. return iterable.__iterate(function(v, k) {return fn(k, v, this$0) !== false}, reverse);
  2586. };
  2587. flipSequence.__iteratorUncached = function(type, reverse) {
  2588. if (type === ITERATE_ENTRIES) {
  2589. var iterator = iterable.__iterator(type, reverse);
  2590. return new Iterator(function() {
  2591. var step = iterator.next();
  2592. if (!step.done) {
  2593. var k = step.value[0];
  2594. step.value[0] = step.value[1];
  2595. step.value[1] = k;
  2596. }
  2597. return step;
  2598. });
  2599. }
  2600. return iterable.__iterator(
  2601. type === ITERATE_VALUES ? ITERATE_KEYS : ITERATE_VALUES,
  2602. reverse
  2603. );
  2604. };
  2605. return flipSequence;
  2606. }
  2607. function mapFactory(iterable, mapper, context) {
  2608. var mappedSequence = makeSequence(iterable);
  2609. mappedSequence.size = iterable.size;
  2610. mappedSequence.has = function(key ) {return iterable.has(key)};
  2611. mappedSequence.get = function(key, notSetValue) {
  2612. var v = iterable.get(key, NOT_SET);
  2613. return v === NOT_SET ?
  2614. notSetValue :
  2615. mapper.call(context, v, key, iterable);
  2616. };
  2617. mappedSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  2618. return iterable.__iterate(
  2619. function(v, k, c) {return fn(mapper.call(context, v, k, c), k, this$0) !== false},
  2620. reverse
  2621. );
  2622. };
  2623. mappedSequence.__iteratorUncached = function (type, reverse) {
  2624. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  2625. return new Iterator(function() {
  2626. var step = iterator.next();
  2627. if (step.done) {
  2628. return step;
  2629. }
  2630. var entry = step.value;
  2631. var key = entry[0];
  2632. return iteratorValue(
  2633. type,
  2634. key,
  2635. mapper.call(context, entry[1], key, iterable),
  2636. step
  2637. );
  2638. });
  2639. };
  2640. return mappedSequence;
  2641. }
  2642. function reverseFactory(iterable, useKeys) {
  2643. var reversedSequence = makeSequence(iterable);
  2644. reversedSequence._iter = iterable;
  2645. reversedSequence.size = iterable.size;
  2646. reversedSequence.reverse = function() {return iterable};
  2647. if (iterable.flip) {
  2648. reversedSequence.flip = function () {
  2649. var flipSequence = flipFactory(iterable);
  2650. flipSequence.reverse = function() {return iterable.flip()};
  2651. return flipSequence;
  2652. };
  2653. }
  2654. reversedSequence.get = function(key, notSetValue)
  2655. {return iterable.get(useKeys ? key : -1 - key, notSetValue)};
  2656. reversedSequence.has = function(key )
  2657. {return iterable.has(useKeys ? key : -1 - key)};
  2658. reversedSequence.includes = function(value ) {return iterable.includes(value)};
  2659. reversedSequence.cacheResult = cacheResultThrough;
  2660. reversedSequence.__iterate = function (fn, reverse) {var this$0 = this;
  2661. return iterable.__iterate(function(v, k) {return fn(v, k, this$0)}, !reverse);
  2662. };
  2663. reversedSequence.__iterator =
  2664. function(type, reverse) {return iterable.__iterator(type, !reverse)};
  2665. return reversedSequence;
  2666. }
  2667. function filterFactory(iterable, predicate, context, useKeys) {
  2668. var filterSequence = makeSequence(iterable);
  2669. if (useKeys) {
  2670. filterSequence.has = function(key ) {
  2671. var v = iterable.get(key, NOT_SET);
  2672. return v !== NOT_SET && !!predicate.call(context, v, key, iterable);
  2673. };
  2674. filterSequence.get = function(key, notSetValue) {
  2675. var v = iterable.get(key, NOT_SET);
  2676. return v !== NOT_SET && predicate.call(context, v, key, iterable) ?
  2677. v : notSetValue;
  2678. };
  2679. }
  2680. filterSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  2681. var iterations = 0;
  2682. iterable.__iterate(function(v, k, c) {
  2683. if (predicate.call(context, v, k, c)) {
  2684. iterations++;
  2685. return fn(v, useKeys ? k : iterations - 1, this$0);
  2686. }
  2687. }, reverse);
  2688. return iterations;
  2689. };
  2690. filterSequence.__iteratorUncached = function (type, reverse) {
  2691. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  2692. var iterations = 0;
  2693. return new Iterator(function() {
  2694. while (true) {
  2695. var step = iterator.next();
  2696. if (step.done) {
  2697. return step;
  2698. }
  2699. var entry = step.value;
  2700. var key = entry[0];
  2701. var value = entry[1];
  2702. if (predicate.call(context, value, key, iterable)) {
  2703. return iteratorValue(type, useKeys ? key : iterations++, value, step);
  2704. }
  2705. }
  2706. });
  2707. };
  2708. return filterSequence;
  2709. }
  2710. function countByFactory(iterable, grouper, context) {
  2711. var groups = Map().asMutable();
  2712. iterable.__iterate(function(v, k) {
  2713. groups.update(
  2714. grouper.call(context, v, k, iterable),
  2715. 0,
  2716. function(a ) {return a + 1}
  2717. );
  2718. });
  2719. return groups.asImmutable();
  2720. }
  2721. function groupByFactory(iterable, grouper, context) {
  2722. var isKeyedIter = isKeyed(iterable);
  2723. var groups = (isOrdered(iterable) ? OrderedMap() : Map()).asMutable();
  2724. iterable.__iterate(function(v, k) {
  2725. groups.update(
  2726. grouper.call(context, v, k, iterable),
  2727. function(a ) {return (a = a || [], a.push(isKeyedIter ? [k, v] : v), a)}
  2728. );
  2729. });
  2730. var coerce = iterableClass(iterable);
  2731. return groups.map(function(arr ) {return reify(iterable, coerce(arr))});
  2732. }
  2733. function sliceFactory(iterable, begin, end, useKeys) {
  2734. var originalSize = iterable.size;
  2735. // Sanitize begin & end using this shorthand for ToInt32(argument)
  2736. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  2737. if (begin !== undefined) {
  2738. begin = begin | 0;
  2739. }
  2740. if (end !== undefined) {
  2741. end = end | 0;
  2742. }
  2743. if (wholeSlice(begin, end, originalSize)) {
  2744. return iterable;
  2745. }
  2746. var resolvedBegin = resolveBegin(begin, originalSize);
  2747. var resolvedEnd = resolveEnd(end, originalSize);
  2748. // begin or end will be NaN if they were provided as negative numbers and
  2749. // this iterable's size is unknown. In that case, cache first so there is
  2750. // a known size and these do not resolve to NaN.
  2751. if (resolvedBegin !== resolvedBegin || resolvedEnd !== resolvedEnd) {
  2752. return sliceFactory(iterable.toSeq().cacheResult(), begin, end, useKeys);
  2753. }
  2754. // Note: resolvedEnd is undefined when the original sequence's length is
  2755. // unknown and this slice did not supply an end and should contain all
  2756. // elements after resolvedBegin.
  2757. // In that case, resolvedSize will be NaN and sliceSize will remain undefined.
  2758. var resolvedSize = resolvedEnd - resolvedBegin;
  2759. var sliceSize;
  2760. if (resolvedSize === resolvedSize) {
  2761. sliceSize = resolvedSize < 0 ? 0 : resolvedSize;
  2762. }
  2763. var sliceSeq = makeSequence(iterable);
  2764. // If iterable.size is undefined, the size of the realized sliceSeq is
  2765. // unknown at this point unless the number of items to slice is 0
  2766. sliceSeq.size = sliceSize === 0 ? sliceSize : iterable.size && sliceSize || undefined;
  2767. if (!useKeys && isSeq(iterable) && sliceSize >= 0) {
  2768. sliceSeq.get = function (index, notSetValue) {
  2769. index = wrapIndex(this, index);
  2770. return index >= 0 && index < sliceSize ?
  2771. iterable.get(index + resolvedBegin, notSetValue) :
  2772. notSetValue;
  2773. };
  2774. }
  2775. sliceSeq.__iterateUncached = function(fn, reverse) {var this$0 = this;
  2776. if (sliceSize === 0) {
  2777. return 0;
  2778. }
  2779. if (reverse) {
  2780. return this.cacheResult().__iterate(fn, reverse);
  2781. }
  2782. var skipped = 0;
  2783. var isSkipping = true;
  2784. var iterations = 0;
  2785. iterable.__iterate(function(v, k) {
  2786. if (!(isSkipping && (isSkipping = skipped++ < resolvedBegin))) {
  2787. iterations++;
  2788. return fn(v, useKeys ? k : iterations - 1, this$0) !== false &&
  2789. iterations !== sliceSize;
  2790. }
  2791. });
  2792. return iterations;
  2793. };
  2794. sliceSeq.__iteratorUncached = function(type, reverse) {
  2795. if (sliceSize !== 0 && reverse) {
  2796. return this.cacheResult().__iterator(type, reverse);
  2797. }
  2798. // Don't bother instantiating parent iterator if taking 0.
  2799. var iterator = sliceSize !== 0 && iterable.__iterator(type, reverse);
  2800. var skipped = 0;
  2801. var iterations = 0;
  2802. return new Iterator(function() {
  2803. while (skipped++ < resolvedBegin) {
  2804. iterator.next();
  2805. }
  2806. if (++iterations > sliceSize) {
  2807. return iteratorDone();
  2808. }
  2809. var step = iterator.next();
  2810. if (useKeys || type === ITERATE_VALUES) {
  2811. return step;
  2812. } else if (type === ITERATE_KEYS) {
  2813. return iteratorValue(type, iterations - 1, undefined, step);
  2814. } else {
  2815. return iteratorValue(type, iterations - 1, step.value[1], step);
  2816. }
  2817. });
  2818. };
  2819. return sliceSeq;
  2820. }
  2821. function takeWhileFactory(iterable, predicate, context) {
  2822. var takeSequence = makeSequence(iterable);
  2823. takeSequence.__iterateUncached = function(fn, reverse) {var this$0 = this;
  2824. if (reverse) {
  2825. return this.cacheResult().__iterate(fn, reverse);
  2826. }
  2827. var iterations = 0;
  2828. iterable.__iterate(function(v, k, c)
  2829. {return predicate.call(context, v, k, c) && ++iterations && fn(v, k, this$0)}
  2830. );
  2831. return iterations;
  2832. };
  2833. takeSequence.__iteratorUncached = function(type, reverse) {var this$0 = this;
  2834. if (reverse) {
  2835. return this.cacheResult().__iterator(type, reverse);
  2836. }
  2837. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  2838. var iterating = true;
  2839. return new Iterator(function() {
  2840. if (!iterating) {
  2841. return iteratorDone();
  2842. }
  2843. var step = iterator.next();
  2844. if (step.done) {
  2845. return step;
  2846. }
  2847. var entry = step.value;
  2848. var k = entry[0];
  2849. var v = entry[1];
  2850. if (!predicate.call(context, v, k, this$0)) {
  2851. iterating = false;
  2852. return iteratorDone();
  2853. }
  2854. return type === ITERATE_ENTRIES ? step :
  2855. iteratorValue(type, k, v, step);
  2856. });
  2857. };
  2858. return takeSequence;
  2859. }
  2860. function skipWhileFactory(iterable, predicate, context, useKeys) {
  2861. var skipSequence = makeSequence(iterable);
  2862. skipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  2863. if (reverse) {
  2864. return this.cacheResult().__iterate(fn, reverse);
  2865. }
  2866. var isSkipping = true;
  2867. var iterations = 0;
  2868. iterable.__iterate(function(v, k, c) {
  2869. if (!(isSkipping && (isSkipping = predicate.call(context, v, k, c)))) {
  2870. iterations++;
  2871. return fn(v, useKeys ? k : iterations - 1, this$0);
  2872. }
  2873. });
  2874. return iterations;
  2875. };
  2876. skipSequence.__iteratorUncached = function(type, reverse) {var this$0 = this;
  2877. if (reverse) {
  2878. return this.cacheResult().__iterator(type, reverse);
  2879. }
  2880. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  2881. var skipping = true;
  2882. var iterations = 0;
  2883. return new Iterator(function() {
  2884. var step, k, v;
  2885. do {
  2886. step = iterator.next();
  2887. if (step.done) {
  2888. if (useKeys || type === ITERATE_VALUES) {
  2889. return step;
  2890. } else if (type === ITERATE_KEYS) {
  2891. return iteratorValue(type, iterations++, undefined, step);
  2892. } else {
  2893. return iteratorValue(type, iterations++, step.value[1], step);
  2894. }
  2895. }
  2896. var entry = step.value;
  2897. k = entry[0];
  2898. v = entry[1];
  2899. skipping && (skipping = predicate.call(context, v, k, this$0));
  2900. } while (skipping);
  2901. return type === ITERATE_ENTRIES ? step :
  2902. iteratorValue(type, k, v, step);
  2903. });
  2904. };
  2905. return skipSequence;
  2906. }
  2907. function concatFactory(iterable, values) {
  2908. var isKeyedIterable = isKeyed(iterable);
  2909. var iters = [iterable].concat(values).map(function(v ) {
  2910. if (!isIterable(v)) {
  2911. v = isKeyedIterable ?
  2912. keyedSeqFromValue(v) :
  2913. indexedSeqFromValue(Array.isArray(v) ? v : [v]);
  2914. } else if (isKeyedIterable) {
  2915. v = KeyedIterable(v);
  2916. }
  2917. return v;
  2918. }).filter(function(v ) {return v.size !== 0});
  2919. if (iters.length === 0) {
  2920. return iterable;
  2921. }
  2922. if (iters.length === 1) {
  2923. var singleton = iters[0];
  2924. if (singleton === iterable ||
  2925. isKeyedIterable && isKeyed(singleton) ||
  2926. isIndexed(iterable) && isIndexed(singleton)) {
  2927. return singleton;
  2928. }
  2929. }
  2930. var concatSeq = new ArraySeq(iters);
  2931. if (isKeyedIterable) {
  2932. concatSeq = concatSeq.toKeyedSeq();
  2933. } else if (!isIndexed(iterable)) {
  2934. concatSeq = concatSeq.toSetSeq();
  2935. }
  2936. concatSeq = concatSeq.flatten(true);
  2937. concatSeq.size = iters.reduce(
  2938. function(sum, seq) {
  2939. if (sum !== undefined) {
  2940. var size = seq.size;
  2941. if (size !== undefined) {
  2942. return sum + size;
  2943. }
  2944. }
  2945. },
  2946. 0
  2947. );
  2948. return concatSeq;
  2949. }
  2950. function flattenFactory(iterable, depth, useKeys) {
  2951. var flatSequence = makeSequence(iterable);
  2952. flatSequence.__iterateUncached = function(fn, reverse) {
  2953. var iterations = 0;
  2954. var stopped = false;
  2955. function flatDeep(iter, currentDepth) {var this$0 = this;
  2956. iter.__iterate(function(v, k) {
  2957. if ((!depth || currentDepth < depth) && isIterable(v)) {
  2958. flatDeep(v, currentDepth + 1);
  2959. } else if (fn(v, useKeys ? k : iterations++, this$0) === false) {
  2960. stopped = true;
  2961. }
  2962. return !stopped;
  2963. }, reverse);
  2964. }
  2965. flatDeep(iterable, 0);
  2966. return iterations;
  2967. };
  2968. flatSequence.__iteratorUncached = function(type, reverse) {
  2969. var iterator = iterable.__iterator(type, reverse);
  2970. var stack = [];
  2971. var iterations = 0;
  2972. return new Iterator(function() {
  2973. while (iterator) {
  2974. var step = iterator.next();
  2975. if (step.done !== false) {
  2976. iterator = stack.pop();
  2977. continue;
  2978. }
  2979. var v = step.value;
  2980. if (type === ITERATE_ENTRIES) {
  2981. v = v[1];
  2982. }
  2983. if ((!depth || stack.length < depth) && isIterable(v)) {
  2984. stack.push(iterator);
  2985. iterator = v.__iterator(type, reverse);
  2986. } else {
  2987. return useKeys ? step : iteratorValue(type, iterations++, v, step);
  2988. }
  2989. }
  2990. return iteratorDone();
  2991. });
  2992. };
  2993. return flatSequence;
  2994. }
  2995. function flatMapFactory(iterable, mapper, context) {
  2996. var coerce = iterableClass(iterable);
  2997. return iterable.toSeq().map(
  2998. function(v, k) {return coerce(mapper.call(context, v, k, iterable))}
  2999. ).flatten(true);
  3000. }
  3001. function interposeFactory(iterable, separator) {
  3002. var interposedSequence = makeSequence(iterable);
  3003. interposedSequence.size = iterable.size && iterable.size * 2 -1;
  3004. interposedSequence.__iterateUncached = function(fn, reverse) {var this$0 = this;
  3005. var iterations = 0;
  3006. iterable.__iterate(function(v, k)
  3007. {return (!iterations || fn(separator, iterations++, this$0) !== false) &&
  3008. fn(v, iterations++, this$0) !== false},
  3009. reverse
  3010. );
  3011. return iterations;
  3012. };
  3013. interposedSequence.__iteratorUncached = function(type, reverse) {
  3014. var iterator = iterable.__iterator(ITERATE_VALUES, reverse);
  3015. var iterations = 0;
  3016. var step;
  3017. return new Iterator(function() {
  3018. if (!step || iterations % 2) {
  3019. step = iterator.next();
  3020. if (step.done) {
  3021. return step;
  3022. }
  3023. }
  3024. return iterations % 2 ?
  3025. iteratorValue(type, iterations++, separator) :
  3026. iteratorValue(type, iterations++, step.value, step);
  3027. });
  3028. };
  3029. return interposedSequence;
  3030. }
  3031. function sortFactory(iterable, comparator, mapper) {
  3032. if (!comparator) {
  3033. comparator = defaultComparator;
  3034. }
  3035. var isKeyedIterable = isKeyed(iterable);
  3036. var index = 0;
  3037. var entries = iterable.toSeq().map(
  3038. function(v, k) {return [k, v, index++, mapper ? mapper(v, k, iterable) : v]}
  3039. ).toArray();
  3040. entries.sort(function(a, b) {return comparator(a[3], b[3]) || a[2] - b[2]}).forEach(
  3041. isKeyedIterable ?
  3042. function(v, i) { entries[i].length = 2; } :
  3043. function(v, i) { entries[i] = v[1]; }
  3044. );
  3045. return isKeyedIterable ? KeyedSeq(entries) :
  3046. isIndexed(iterable) ? IndexedSeq(entries) :
  3047. SetSeq(entries);
  3048. }
  3049. function maxFactory(iterable, comparator, mapper) {
  3050. if (!comparator) {
  3051. comparator = defaultComparator;
  3052. }
  3053. if (mapper) {
  3054. var entry = iterable.toSeq()
  3055. .map(function(v, k) {return [v, mapper(v, k, iterable)]})
  3056. .reduce(function(a, b) {return maxCompare(comparator, a[1], b[1]) ? b : a});
  3057. return entry && entry[0];
  3058. } else {
  3059. return iterable.reduce(function(a, b) {return maxCompare(comparator, a, b) ? b : a});
  3060. }
  3061. }
  3062. function maxCompare(comparator, a, b) {
  3063. var comp = comparator(b, a);
  3064. // b is considered the new max if the comparator declares them equal, but
  3065. // they are not equal and b is in fact a nullish value.
  3066. return (comp === 0 && b !== a && (b === undefined || b === null || b !== b)) || comp > 0;
  3067. }
  3068. function zipWithFactory(keyIter, zipper, iters) {
  3069. var zipSequence = makeSequence(keyIter);
  3070. zipSequence.size = new ArraySeq(iters).map(function(i ) {return i.size}).min();
  3071. // Note: this a generic base implementation of __iterate in terms of
  3072. // __iterator which may be more generically useful in the future.
  3073. zipSequence.__iterate = function(fn, reverse) {
  3074. /* generic:
  3075. var iterator = this.__iterator(ITERATE_ENTRIES, reverse);
  3076. var step;
  3077. var iterations = 0;
  3078. while (!(step = iterator.next()).done) {
  3079. iterations++;
  3080. if (fn(step.value[1], step.value[0], this) === false) {
  3081. break;
  3082. }
  3083. }
  3084. return iterations;
  3085. */
  3086. // indexed:
  3087. var iterator = this.__iterator(ITERATE_VALUES, reverse);
  3088. var step;
  3089. var iterations = 0;
  3090. while (!(step = iterator.next()).done) {
  3091. if (fn(step.value, iterations++, this) === false) {
  3092. break;
  3093. }
  3094. }
  3095. return iterations;
  3096. };
  3097. zipSequence.__iteratorUncached = function(type, reverse) {
  3098. var iterators = iters.map(function(i )
  3099. {return (i = Iterable(i), getIterator(reverse ? i.reverse() : i))}
  3100. );
  3101. var iterations = 0;
  3102. var isDone = false;
  3103. return new Iterator(function() {
  3104. var steps;
  3105. if (!isDone) {
  3106. steps = iterators.map(function(i ) {return i.next()});
  3107. isDone = steps.some(function(s ) {return s.done});
  3108. }
  3109. if (isDone) {
  3110. return iteratorDone();
  3111. }
  3112. return iteratorValue(
  3113. type,
  3114. iterations++,
  3115. zipper.apply(null, steps.map(function(s ) {return s.value}))
  3116. );
  3117. });
  3118. };
  3119. return zipSequence
  3120. }
  3121. // #pragma Helper Functions
  3122. function reify(iter, seq) {
  3123. return isSeq(iter) ? seq : iter.constructor(seq);
  3124. }
  3125. function validateEntry(entry) {
  3126. if (entry !== Object(entry)) {
  3127. throw new TypeError('Expected [K, V] tuple: ' + entry);
  3128. }
  3129. }
  3130. function resolveSize(iter) {
  3131. assertNotInfinite(iter.size);
  3132. return ensureSize(iter);
  3133. }
  3134. function iterableClass(iterable) {
  3135. return isKeyed(iterable) ? KeyedIterable :
  3136. isIndexed(iterable) ? IndexedIterable :
  3137. SetIterable;
  3138. }
  3139. function makeSequence(iterable) {
  3140. return Object.create(
  3141. (
  3142. isKeyed(iterable) ? KeyedSeq :
  3143. isIndexed(iterable) ? IndexedSeq :
  3144. SetSeq
  3145. ).prototype
  3146. );
  3147. }
  3148. function cacheResultThrough() {
  3149. if (this._iter.cacheResult) {
  3150. this._iter.cacheResult();
  3151. this.size = this._iter.size;
  3152. return this;
  3153. } else {
  3154. return Seq.prototype.cacheResult.call(this);
  3155. }
  3156. }
  3157. function defaultComparator(a, b) {
  3158. return a > b ? 1 : a < b ? -1 : 0;
  3159. }
  3160. function forceIterator(keyPath) {
  3161. var iter = getIterator(keyPath);
  3162. if (!iter) {
  3163. // Array might not be iterable in this environment, so we need a fallback
  3164. // to our wrapped type.
  3165. if (!isArrayLike(keyPath)) {
  3166. throw new TypeError('Expected iterable or array-like: ' + keyPath);
  3167. }
  3168. iter = getIterator(Iterable(keyPath));
  3169. }
  3170. return iter;
  3171. }
  3172. createClass(Record, KeyedCollection);
  3173. function Record(defaultValues, name) {
  3174. var hasInitialized;
  3175. var RecordType = function Record(values) {
  3176. if (values instanceof RecordType) {
  3177. return values;
  3178. }
  3179. if (!(this instanceof RecordType)) {
  3180. return new RecordType(values);
  3181. }
  3182. if (!hasInitialized) {
  3183. hasInitialized = true;
  3184. var keys = Object.keys(defaultValues);
  3185. setProps(RecordTypePrototype, keys);
  3186. RecordTypePrototype.size = keys.length;
  3187. RecordTypePrototype._name = name;
  3188. RecordTypePrototype._keys = keys;
  3189. RecordTypePrototype._defaultValues = defaultValues;
  3190. }
  3191. this._map = Map(values);
  3192. };
  3193. var RecordTypePrototype = RecordType.prototype = Object.create(RecordPrototype);
  3194. RecordTypePrototype.constructor = RecordType;
  3195. return RecordType;
  3196. }
  3197. Record.prototype.toString = function() {
  3198. return this.__toString(recordName(this) + ' {', '}');
  3199. };
  3200. // @pragma Access
  3201. Record.prototype.has = function(k) {
  3202. return this._defaultValues.hasOwnProperty(k);
  3203. };
  3204. Record.prototype.get = function(k, notSetValue) {
  3205. if (!this.has(k)) {
  3206. return notSetValue;
  3207. }
  3208. var defaultVal = this._defaultValues[k];
  3209. return this._map ? this._map.get(k, defaultVal) : defaultVal;
  3210. };
  3211. // @pragma Modification
  3212. Record.prototype.clear = function() {
  3213. if (this.__ownerID) {
  3214. this._map && this._map.clear();
  3215. return this;
  3216. }
  3217. var RecordType = this.constructor;
  3218. return RecordType._empty || (RecordType._empty = makeRecord(this, emptyMap()));
  3219. };
  3220. Record.prototype.set = function(k, v) {
  3221. if (!this.has(k)) {
  3222. throw new Error('Cannot set unknown key "' + k + '" on ' + recordName(this));
  3223. }
  3224. var newMap = this._map && this._map.set(k, v);
  3225. if (this.__ownerID || newMap === this._map) {
  3226. return this;
  3227. }
  3228. return makeRecord(this, newMap);
  3229. };
  3230. Record.prototype.remove = function(k) {
  3231. if (!this.has(k)) {
  3232. return this;
  3233. }
  3234. var newMap = this._map && this._map.remove(k);
  3235. if (this.__ownerID || newMap === this._map) {
  3236. return this;
  3237. }
  3238. return makeRecord(this, newMap);
  3239. };
  3240. Record.prototype.wasAltered = function() {
  3241. return this._map.wasAltered();
  3242. };
  3243. Record.prototype.__iterator = function(type, reverse) {var this$0 = this;
  3244. return KeyedIterable(this._defaultValues).map(function(_, k) {return this$0.get(k)}).__iterator(type, reverse);
  3245. };
  3246. Record.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  3247. return KeyedIterable(this._defaultValues).map(function(_, k) {return this$0.get(k)}).__iterate(fn, reverse);
  3248. };
  3249. Record.prototype.__ensureOwner = function(ownerID) {
  3250. if (ownerID === this.__ownerID) {
  3251. return this;
  3252. }
  3253. var newMap = this._map && this._map.__ensureOwner(ownerID);
  3254. if (!ownerID) {
  3255. this.__ownerID = ownerID;
  3256. this._map = newMap;
  3257. return this;
  3258. }
  3259. return makeRecord(this, newMap, ownerID);
  3260. };
  3261. var RecordPrototype = Record.prototype;
  3262. RecordPrototype[DELETE] = RecordPrototype.remove;
  3263. RecordPrototype.deleteIn =
  3264. RecordPrototype.removeIn = MapPrototype.removeIn;
  3265. RecordPrototype.merge = MapPrototype.merge;
  3266. RecordPrototype.mergeWith = MapPrototype.mergeWith;
  3267. RecordPrototype.mergeIn = MapPrototype.mergeIn;
  3268. RecordPrototype.mergeDeep = MapPrototype.mergeDeep;
  3269. RecordPrototype.mergeDeepWith = MapPrototype.mergeDeepWith;
  3270. RecordPrototype.mergeDeepIn = MapPrototype.mergeDeepIn;
  3271. RecordPrototype.setIn = MapPrototype.setIn;
  3272. RecordPrototype.update = MapPrototype.update;
  3273. RecordPrototype.updateIn = MapPrototype.updateIn;
  3274. RecordPrototype.withMutations = MapPrototype.withMutations;
  3275. RecordPrototype.asMutable = MapPrototype.asMutable;
  3276. RecordPrototype.asImmutable = MapPrototype.asImmutable;
  3277. function makeRecord(likeRecord, map, ownerID) {
  3278. var record = Object.create(Object.getPrototypeOf(likeRecord));
  3279. record._map = map;
  3280. record.__ownerID = ownerID;
  3281. return record;
  3282. }
  3283. function recordName(record) {
  3284. return record._name || record.constructor.name || 'Record';
  3285. }
  3286. function setProps(prototype, names) {
  3287. try {
  3288. names.forEach(setProp.bind(undefined, prototype));
  3289. } catch (error) {
  3290. // Object.defineProperty failed. Probably IE8.
  3291. }
  3292. }
  3293. function setProp(prototype, name) {
  3294. Object.defineProperty(prototype, name, {
  3295. get: function() {
  3296. return this.get(name);
  3297. },
  3298. set: function(value) {
  3299. invariant(this.__ownerID, 'Cannot set on an immutable record.');
  3300. this.set(name, value);
  3301. }
  3302. });
  3303. }
  3304. createClass(Set, SetCollection);
  3305. // @pragma Construction
  3306. function Set(value) {
  3307. return value === null || value === undefined ? emptySet() :
  3308. isSet(value) && !isOrdered(value) ? value :
  3309. emptySet().withMutations(function(set ) {
  3310. var iter = SetIterable(value);
  3311. assertNotInfinite(iter.size);
  3312. iter.forEach(function(v ) {return set.add(v)});
  3313. });
  3314. }
  3315. Set.of = function(/*...values*/) {
  3316. return this(arguments);
  3317. };
  3318. Set.fromKeys = function(value) {
  3319. return this(KeyedIterable(value).keySeq());
  3320. };
  3321. Set.prototype.toString = function() {
  3322. return this.__toString('Set {', '}');
  3323. };
  3324. // @pragma Access
  3325. Set.prototype.has = function(value) {
  3326. return this._map.has(value);
  3327. };
  3328. // @pragma Modification
  3329. Set.prototype.add = function(value) {
  3330. return updateSet(this, this._map.set(value, true));
  3331. };
  3332. Set.prototype.remove = function(value) {
  3333. return updateSet(this, this._map.remove(value));
  3334. };
  3335. Set.prototype.clear = function() {
  3336. return updateSet(this, this._map.clear());
  3337. };
  3338. // @pragma Composition
  3339. Set.prototype.union = function() {var iters = SLICE$0.call(arguments, 0);
  3340. iters = iters.filter(function(x ) {return x.size !== 0});
  3341. if (iters.length === 0) {
  3342. return this;
  3343. }
  3344. if (this.size === 0 && !this.__ownerID && iters.length === 1) {
  3345. return this.constructor(iters[0]);
  3346. }
  3347. return this.withMutations(function(set ) {
  3348. for (var ii = 0; ii < iters.length; ii++) {
  3349. SetIterable(iters[ii]).forEach(function(value ) {return set.add(value)});
  3350. }
  3351. });
  3352. };
  3353. Set.prototype.intersect = function() {var iters = SLICE$0.call(arguments, 0);
  3354. if (iters.length === 0) {
  3355. return this;
  3356. }
  3357. iters = iters.map(function(iter ) {return SetIterable(iter)});
  3358. var originalSet = this;
  3359. return this.withMutations(function(set ) {
  3360. originalSet.forEach(function(value ) {
  3361. if (!iters.every(function(iter ) {return iter.includes(value)})) {
  3362. set.remove(value);
  3363. }
  3364. });
  3365. });
  3366. };
  3367. Set.prototype.subtract = function() {var iters = SLICE$0.call(arguments, 0);
  3368. if (iters.length === 0) {
  3369. return this;
  3370. }
  3371. iters = iters.map(function(iter ) {return SetIterable(iter)});
  3372. var originalSet = this;
  3373. return this.withMutations(function(set ) {
  3374. originalSet.forEach(function(value ) {
  3375. if (iters.some(function(iter ) {return iter.includes(value)})) {
  3376. set.remove(value);
  3377. }
  3378. });
  3379. });
  3380. };
  3381. Set.prototype.merge = function() {
  3382. return this.union.apply(this, arguments);
  3383. };
  3384. Set.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  3385. return this.union.apply(this, iters);
  3386. };
  3387. Set.prototype.sort = function(comparator) {
  3388. // Late binding
  3389. return OrderedSet(sortFactory(this, comparator));
  3390. };
  3391. Set.prototype.sortBy = function(mapper, comparator) {
  3392. // Late binding
  3393. return OrderedSet(sortFactory(this, comparator, mapper));
  3394. };
  3395. Set.prototype.wasAltered = function() {
  3396. return this._map.wasAltered();
  3397. };
  3398. Set.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  3399. return this._map.__iterate(function(_, k) {return fn(k, k, this$0)}, reverse);
  3400. };
  3401. Set.prototype.__iterator = function(type, reverse) {
  3402. return this._map.map(function(_, k) {return k}).__iterator(type, reverse);
  3403. };
  3404. Set.prototype.__ensureOwner = function(ownerID) {
  3405. if (ownerID === this.__ownerID) {
  3406. return this;
  3407. }
  3408. var newMap = this._map.__ensureOwner(ownerID);
  3409. if (!ownerID) {
  3410. this.__ownerID = ownerID;
  3411. this._map = newMap;
  3412. return this;
  3413. }
  3414. return this.__make(newMap, ownerID);
  3415. };
  3416. function isSet(maybeSet) {
  3417. return !!(maybeSet && maybeSet[IS_SET_SENTINEL]);
  3418. }
  3419. Set.isSet = isSet;
  3420. var IS_SET_SENTINEL = '@@__IMMUTABLE_SET__@@';
  3421. var SetPrototype = Set.prototype;
  3422. SetPrototype[IS_SET_SENTINEL] = true;
  3423. SetPrototype[DELETE] = SetPrototype.remove;
  3424. SetPrototype.mergeDeep = SetPrototype.merge;
  3425. SetPrototype.mergeDeepWith = SetPrototype.mergeWith;
  3426. SetPrototype.withMutations = MapPrototype.withMutations;
  3427. SetPrototype.asMutable = MapPrototype.asMutable;
  3428. SetPrototype.asImmutable = MapPrototype.asImmutable;
  3429. SetPrototype.__empty = emptySet;
  3430. SetPrototype.__make = makeSet;
  3431. function updateSet(set, newMap) {
  3432. if (set.__ownerID) {
  3433. set.size = newMap.size;
  3434. set._map = newMap;
  3435. return set;
  3436. }
  3437. return newMap === set._map ? set :
  3438. newMap.size === 0 ? set.__empty() :
  3439. set.__make(newMap);
  3440. }
  3441. function makeSet(map, ownerID) {
  3442. var set = Object.create(SetPrototype);
  3443. set.size = map ? map.size : 0;
  3444. set._map = map;
  3445. set.__ownerID = ownerID;
  3446. return set;
  3447. }
  3448. var EMPTY_SET;
  3449. function emptySet() {
  3450. return EMPTY_SET || (EMPTY_SET = makeSet(emptyMap()));
  3451. }
  3452. createClass(OrderedSet, Set);
  3453. // @pragma Construction
  3454. function OrderedSet(value) {
  3455. return value === null || value === undefined ? emptyOrderedSet() :
  3456. isOrderedSet(value) ? value :
  3457. emptyOrderedSet().withMutations(function(set ) {
  3458. var iter = SetIterable(value);
  3459. assertNotInfinite(iter.size);
  3460. iter.forEach(function(v ) {return set.add(v)});
  3461. });
  3462. }
  3463. OrderedSet.of = function(/*...values*/) {
  3464. return this(arguments);
  3465. };
  3466. OrderedSet.fromKeys = function(value) {
  3467. return this(KeyedIterable(value).keySeq());
  3468. };
  3469. OrderedSet.prototype.toString = function() {
  3470. return this.__toString('OrderedSet {', '}');
  3471. };
  3472. function isOrderedSet(maybeOrderedSet) {
  3473. return isSet(maybeOrderedSet) && isOrdered(maybeOrderedSet);
  3474. }
  3475. OrderedSet.isOrderedSet = isOrderedSet;
  3476. var OrderedSetPrototype = OrderedSet.prototype;
  3477. OrderedSetPrototype[IS_ORDERED_SENTINEL] = true;
  3478. OrderedSetPrototype.__empty = emptyOrderedSet;
  3479. OrderedSetPrototype.__make = makeOrderedSet;
  3480. function makeOrderedSet(map, ownerID) {
  3481. var set = Object.create(OrderedSetPrototype);
  3482. set.size = map ? map.size : 0;
  3483. set._map = map;
  3484. set.__ownerID = ownerID;
  3485. return set;
  3486. }
  3487. var EMPTY_ORDERED_SET;
  3488. function emptyOrderedSet() {
  3489. return EMPTY_ORDERED_SET || (EMPTY_ORDERED_SET = makeOrderedSet(emptyOrderedMap()));
  3490. }
  3491. createClass(Stack, IndexedCollection);
  3492. // @pragma Construction
  3493. function Stack(value) {
  3494. return value === null || value === undefined ? emptyStack() :
  3495. isStack(value) ? value :
  3496. emptyStack().unshiftAll(value);
  3497. }
  3498. Stack.of = function(/*...values*/) {
  3499. return this(arguments);
  3500. };
  3501. Stack.prototype.toString = function() {
  3502. return this.__toString('Stack [', ']');
  3503. };
  3504. // @pragma Access
  3505. Stack.prototype.get = function(index, notSetValue) {
  3506. var head = this._head;
  3507. index = wrapIndex(this, index);
  3508. while (head && index--) {
  3509. head = head.next;
  3510. }
  3511. return head ? head.value : notSetValue;
  3512. };
  3513. Stack.prototype.peek = function() {
  3514. return this._head && this._head.value;
  3515. };
  3516. // @pragma Modification
  3517. Stack.prototype.push = function(/*...values*/) {
  3518. if (arguments.length === 0) {
  3519. return this;
  3520. }
  3521. var newSize = this.size + arguments.length;
  3522. var head = this._head;
  3523. for (var ii = arguments.length - 1; ii >= 0; ii--) {
  3524. head = {
  3525. value: arguments[ii],
  3526. next: head
  3527. };
  3528. }
  3529. if (this.__ownerID) {
  3530. this.size = newSize;
  3531. this._head = head;
  3532. this.__hash = undefined;
  3533. this.__altered = true;
  3534. return this;
  3535. }
  3536. return makeStack(newSize, head);
  3537. };
  3538. Stack.prototype.pushAll = function(iter) {
  3539. iter = IndexedIterable(iter);
  3540. if (iter.size === 0) {
  3541. return this;
  3542. }
  3543. assertNotInfinite(iter.size);
  3544. var newSize = this.size;
  3545. var head = this._head;
  3546. iter.reverse().forEach(function(value ) {
  3547. newSize++;
  3548. head = {
  3549. value: value,
  3550. next: head
  3551. };
  3552. });
  3553. if (this.__ownerID) {
  3554. this.size = newSize;
  3555. this._head = head;
  3556. this.__hash = undefined;
  3557. this.__altered = true;
  3558. return this;
  3559. }
  3560. return makeStack(newSize, head);
  3561. };
  3562. Stack.prototype.pop = function() {
  3563. return this.slice(1);
  3564. };
  3565. Stack.prototype.unshift = function(/*...values*/) {
  3566. return this.push.apply(this, arguments);
  3567. };
  3568. Stack.prototype.unshiftAll = function(iter) {
  3569. return this.pushAll(iter);
  3570. };
  3571. Stack.prototype.shift = function() {
  3572. return this.pop.apply(this, arguments);
  3573. };
  3574. Stack.prototype.clear = function() {
  3575. if (this.size === 0) {
  3576. return this;
  3577. }
  3578. if (this.__ownerID) {
  3579. this.size = 0;
  3580. this._head = undefined;
  3581. this.__hash = undefined;
  3582. this.__altered = true;
  3583. return this;
  3584. }
  3585. return emptyStack();
  3586. };
  3587. Stack.prototype.slice = function(begin, end) {
  3588. if (wholeSlice(begin, end, this.size)) {
  3589. return this;
  3590. }
  3591. var resolvedBegin = resolveBegin(begin, this.size);
  3592. var resolvedEnd = resolveEnd(end, this.size);
  3593. if (resolvedEnd !== this.size) {
  3594. // super.slice(begin, end);
  3595. return IndexedCollection.prototype.slice.call(this, begin, end);
  3596. }
  3597. var newSize = this.size - resolvedBegin;
  3598. var head = this._head;
  3599. while (resolvedBegin--) {
  3600. head = head.next;
  3601. }
  3602. if (this.__ownerID) {
  3603. this.size = newSize;
  3604. this._head = head;
  3605. this.__hash = undefined;
  3606. this.__altered = true;
  3607. return this;
  3608. }
  3609. return makeStack(newSize, head);
  3610. };
  3611. // @pragma Mutability
  3612. Stack.prototype.__ensureOwner = function(ownerID) {
  3613. if (ownerID === this.__ownerID) {
  3614. return this;
  3615. }
  3616. if (!ownerID) {
  3617. this.__ownerID = ownerID;
  3618. this.__altered = false;
  3619. return this;
  3620. }
  3621. return makeStack(this.size, this._head, ownerID, this.__hash);
  3622. };
  3623. // @pragma Iteration
  3624. Stack.prototype.__iterate = function(fn, reverse) {
  3625. if (reverse) {
  3626. return this.reverse().__iterate(fn);
  3627. }
  3628. var iterations = 0;
  3629. var node = this._head;
  3630. while (node) {
  3631. if (fn(node.value, iterations++, this) === false) {
  3632. break;
  3633. }
  3634. node = node.next;
  3635. }
  3636. return iterations;
  3637. };
  3638. Stack.prototype.__iterator = function(type, reverse) {
  3639. if (reverse) {
  3640. return this.reverse().__iterator(type);
  3641. }
  3642. var iterations = 0;
  3643. var node = this._head;
  3644. return new Iterator(function() {
  3645. if (node) {
  3646. var value = node.value;
  3647. node = node.next;
  3648. return iteratorValue(type, iterations++, value);
  3649. }
  3650. return iteratorDone();
  3651. });
  3652. };
  3653. function isStack(maybeStack) {
  3654. return !!(maybeStack && maybeStack[IS_STACK_SENTINEL]);
  3655. }
  3656. Stack.isStack = isStack;
  3657. var IS_STACK_SENTINEL = '@@__IMMUTABLE_STACK__@@';
  3658. var StackPrototype = Stack.prototype;
  3659. StackPrototype[IS_STACK_SENTINEL] = true;
  3660. StackPrototype.withMutations = MapPrototype.withMutations;
  3661. StackPrototype.asMutable = MapPrototype.asMutable;
  3662. StackPrototype.asImmutable = MapPrototype.asImmutable;
  3663. StackPrototype.wasAltered = MapPrototype.wasAltered;
  3664. function makeStack(size, head, ownerID, hash) {
  3665. var map = Object.create(StackPrototype);
  3666. map.size = size;
  3667. map._head = head;
  3668. map.__ownerID = ownerID;
  3669. map.__hash = hash;
  3670. map.__altered = false;
  3671. return map;
  3672. }
  3673. var EMPTY_STACK;
  3674. function emptyStack() {
  3675. return EMPTY_STACK || (EMPTY_STACK = makeStack(0));
  3676. }
  3677. /**
  3678. * Contributes additional methods to a constructor
  3679. */
  3680. function mixin(ctor, methods) {
  3681. var keyCopier = function(key ) { ctor.prototype[key] = methods[key]; };
  3682. Object.keys(methods).forEach(keyCopier);
  3683. Object.getOwnPropertySymbols &&
  3684. Object.getOwnPropertySymbols(methods).forEach(keyCopier);
  3685. return ctor;
  3686. }
  3687. Iterable.Iterator = Iterator;
  3688. mixin(Iterable, {
  3689. // ### Conversion to other types
  3690. toArray: function() {
  3691. assertNotInfinite(this.size);
  3692. var array = new Array(this.size || 0);
  3693. this.valueSeq().__iterate(function(v, i) { array[i] = v; });
  3694. return array;
  3695. },
  3696. toIndexedSeq: function() {
  3697. return new ToIndexedSequence(this);
  3698. },
  3699. toJS: function() {
  3700. return this.toSeq().map(
  3701. function(value ) {return value && typeof value.toJS === 'function' ? value.toJS() : value}
  3702. ).__toJS();
  3703. },
  3704. toJSON: function() {
  3705. return this.toSeq().map(
  3706. function(value ) {return value && typeof value.toJSON === 'function' ? value.toJSON() : value}
  3707. ).__toJS();
  3708. },
  3709. toKeyedSeq: function() {
  3710. return new ToKeyedSequence(this, true);
  3711. },
  3712. toMap: function() {
  3713. // Use Late Binding here to solve the circular dependency.
  3714. return Map(this.toKeyedSeq());
  3715. },
  3716. toObject: function() {
  3717. assertNotInfinite(this.size);
  3718. var object = {};
  3719. this.__iterate(function(v, k) { object[k] = v; });
  3720. return object;
  3721. },
  3722. toOrderedMap: function() {
  3723. // Use Late Binding here to solve the circular dependency.
  3724. return OrderedMap(this.toKeyedSeq());
  3725. },
  3726. toOrderedSet: function() {
  3727. // Use Late Binding here to solve the circular dependency.
  3728. return OrderedSet(isKeyed(this) ? this.valueSeq() : this);
  3729. },
  3730. toSet: function() {
  3731. // Use Late Binding here to solve the circular dependency.
  3732. return Set(isKeyed(this) ? this.valueSeq() : this);
  3733. },
  3734. toSetSeq: function() {
  3735. return new ToSetSequence(this);
  3736. },
  3737. toSeq: function() {
  3738. return isIndexed(this) ? this.toIndexedSeq() :
  3739. isKeyed(this) ? this.toKeyedSeq() :
  3740. this.toSetSeq();
  3741. },
  3742. toStack: function() {
  3743. // Use Late Binding here to solve the circular dependency.
  3744. return Stack(isKeyed(this) ? this.valueSeq() : this);
  3745. },
  3746. toList: function() {
  3747. // Use Late Binding here to solve the circular dependency.
  3748. return List(isKeyed(this) ? this.valueSeq() : this);
  3749. },
  3750. // ### Common JavaScript methods and properties
  3751. toString: function() {
  3752. return '[Iterable]';
  3753. },
  3754. __toString: function(head, tail) {
  3755. if (this.size === 0) {
  3756. return head + tail;
  3757. }
  3758. return head + ' ' + this.toSeq().map(this.__toStringMapper).join(', ') + ' ' + tail;
  3759. },
  3760. // ### ES6 Collection methods (ES6 Array and Map)
  3761. concat: function() {var values = SLICE$0.call(arguments, 0);
  3762. return reify(this, concatFactory(this, values));
  3763. },
  3764. includes: function(searchValue) {
  3765. return this.some(function(value ) {return is(value, searchValue)});
  3766. },
  3767. entries: function() {
  3768. return this.__iterator(ITERATE_ENTRIES);
  3769. },
  3770. every: function(predicate, context) {
  3771. assertNotInfinite(this.size);
  3772. var returnValue = true;
  3773. this.__iterate(function(v, k, c) {
  3774. if (!predicate.call(context, v, k, c)) {
  3775. returnValue = false;
  3776. return false;
  3777. }
  3778. });
  3779. return returnValue;
  3780. },
  3781. filter: function(predicate, context) {
  3782. return reify(this, filterFactory(this, predicate, context, true));
  3783. },
  3784. find: function(predicate, context, notSetValue) {
  3785. var entry = this.findEntry(predicate, context);
  3786. return entry ? entry[1] : notSetValue;
  3787. },
  3788. findEntry: function(predicate, context) {
  3789. var found;
  3790. this.__iterate(function(v, k, c) {
  3791. if (predicate.call(context, v, k, c)) {
  3792. found = [k, v];
  3793. return false;
  3794. }
  3795. });
  3796. return found;
  3797. },
  3798. findLastEntry: function(predicate, context) {
  3799. return this.toSeq().reverse().findEntry(predicate, context);
  3800. },
  3801. forEach: function(sideEffect, context) {
  3802. assertNotInfinite(this.size);
  3803. return this.__iterate(context ? sideEffect.bind(context) : sideEffect);
  3804. },
  3805. join: function(separator) {
  3806. assertNotInfinite(this.size);
  3807. separator = separator !== undefined ? '' + separator : ',';
  3808. var joined = '';
  3809. var isFirst = true;
  3810. this.__iterate(function(v ) {
  3811. isFirst ? (isFirst = false) : (joined += separator);
  3812. joined += v !== null && v !== undefined ? v.toString() : '';
  3813. });
  3814. return joined;
  3815. },
  3816. keys: function() {
  3817. return this.__iterator(ITERATE_KEYS);
  3818. },
  3819. map: function(mapper, context) {
  3820. return reify(this, mapFactory(this, mapper, context));
  3821. },
  3822. reduce: function(reducer, initialReduction, context) {
  3823. assertNotInfinite(this.size);
  3824. var reduction;
  3825. var useFirst;
  3826. if (arguments.length < 2) {
  3827. useFirst = true;
  3828. } else {
  3829. reduction = initialReduction;
  3830. }
  3831. this.__iterate(function(v, k, c) {
  3832. if (useFirst) {
  3833. useFirst = false;
  3834. reduction = v;
  3835. } else {
  3836. reduction = reducer.call(context, reduction, v, k, c);
  3837. }
  3838. });
  3839. return reduction;
  3840. },
  3841. reduceRight: function(reducer, initialReduction, context) {
  3842. var reversed = this.toKeyedSeq().reverse();
  3843. return reversed.reduce.apply(reversed, arguments);
  3844. },
  3845. reverse: function() {
  3846. return reify(this, reverseFactory(this, true));
  3847. },
  3848. slice: function(begin, end) {
  3849. return reify(this, sliceFactory(this, begin, end, true));
  3850. },
  3851. some: function(predicate, context) {
  3852. return !this.every(not(predicate), context);
  3853. },
  3854. sort: function(comparator) {
  3855. return reify(this, sortFactory(this, comparator));
  3856. },
  3857. values: function() {
  3858. return this.__iterator(ITERATE_VALUES);
  3859. },
  3860. // ### More sequential methods
  3861. butLast: function() {
  3862. return this.slice(0, -1);
  3863. },
  3864. isEmpty: function() {
  3865. return this.size !== undefined ? this.size === 0 : !this.some(function() {return true});
  3866. },
  3867. count: function(predicate, context) {
  3868. return ensureSize(
  3869. predicate ? this.toSeq().filter(predicate, context) : this
  3870. );
  3871. },
  3872. countBy: function(grouper, context) {
  3873. return countByFactory(this, grouper, context);
  3874. },
  3875. equals: function(other) {
  3876. return deepEqual(this, other);
  3877. },
  3878. entrySeq: function() {
  3879. var iterable = this;
  3880. if (iterable._cache) {
  3881. // We cache as an entries array, so we can just return the cache!
  3882. return new ArraySeq(iterable._cache);
  3883. }
  3884. var entriesSequence = iterable.toSeq().map(entryMapper).toIndexedSeq();
  3885. entriesSequence.fromEntrySeq = function() {return iterable.toSeq()};
  3886. return entriesSequence;
  3887. },
  3888. filterNot: function(predicate, context) {
  3889. return this.filter(not(predicate), context);
  3890. },
  3891. findLast: function(predicate, context, notSetValue) {
  3892. return this.toKeyedSeq().reverse().find(predicate, context, notSetValue);
  3893. },
  3894. first: function() {
  3895. return this.find(returnTrue);
  3896. },
  3897. flatMap: function(mapper, context) {
  3898. return reify(this, flatMapFactory(this, mapper, context));
  3899. },
  3900. flatten: function(depth) {
  3901. return reify(this, flattenFactory(this, depth, true));
  3902. },
  3903. fromEntrySeq: function() {
  3904. return new FromEntriesSequence(this);
  3905. },
  3906. get: function(searchKey, notSetValue) {
  3907. return this.find(function(_, key) {return is(key, searchKey)}, undefined, notSetValue);
  3908. },
  3909. getIn: function(searchKeyPath, notSetValue) {
  3910. var nested = this;
  3911. // Note: in an ES6 environment, we would prefer:
  3912. // for (var key of searchKeyPath) {
  3913. var iter = forceIterator(searchKeyPath);
  3914. var step;
  3915. while (!(step = iter.next()).done) {
  3916. var key = step.value;
  3917. nested = nested && nested.get ? nested.get(key, NOT_SET) : NOT_SET;
  3918. if (nested === NOT_SET) {
  3919. return notSetValue;
  3920. }
  3921. }
  3922. return nested;
  3923. },
  3924. groupBy: function(grouper, context) {
  3925. return groupByFactory(this, grouper, context);
  3926. },
  3927. has: function(searchKey) {
  3928. return this.get(searchKey, NOT_SET) !== NOT_SET;
  3929. },
  3930. hasIn: function(searchKeyPath) {
  3931. return this.getIn(searchKeyPath, NOT_SET) !== NOT_SET;
  3932. },
  3933. isSubset: function(iter) {
  3934. iter = typeof iter.includes === 'function' ? iter : Iterable(iter);
  3935. return this.every(function(value ) {return iter.includes(value)});
  3936. },
  3937. isSuperset: function(iter) {
  3938. iter = typeof iter.isSubset === 'function' ? iter : Iterable(iter);
  3939. return iter.isSubset(this);
  3940. },
  3941. keySeq: function() {
  3942. return this.toSeq().map(keyMapper).toIndexedSeq();
  3943. },
  3944. last: function() {
  3945. return this.toSeq().reverse().first();
  3946. },
  3947. max: function(comparator) {
  3948. return maxFactory(this, comparator);
  3949. },
  3950. maxBy: function(mapper, comparator) {
  3951. return maxFactory(this, comparator, mapper);
  3952. },
  3953. min: function(comparator) {
  3954. return maxFactory(this, comparator ? neg(comparator) : defaultNegComparator);
  3955. },
  3956. minBy: function(mapper, comparator) {
  3957. return maxFactory(this, comparator ? neg(comparator) : defaultNegComparator, mapper);
  3958. },
  3959. rest: function() {
  3960. return this.slice(1);
  3961. },
  3962. skip: function(amount) {
  3963. return this.slice(Math.max(0, amount));
  3964. },
  3965. skipLast: function(amount) {
  3966. return reify(this, this.toSeq().reverse().skip(amount).reverse());
  3967. },
  3968. skipWhile: function(predicate, context) {
  3969. return reify(this, skipWhileFactory(this, predicate, context, true));
  3970. },
  3971. skipUntil: function(predicate, context) {
  3972. return this.skipWhile(not(predicate), context);
  3973. },
  3974. sortBy: function(mapper, comparator) {
  3975. return reify(this, sortFactory(this, comparator, mapper));
  3976. },
  3977. take: function(amount) {
  3978. return this.slice(0, Math.max(0, amount));
  3979. },
  3980. takeLast: function(amount) {
  3981. return reify(this, this.toSeq().reverse().take(amount).reverse());
  3982. },
  3983. takeWhile: function(predicate, context) {
  3984. return reify(this, takeWhileFactory(this, predicate, context));
  3985. },
  3986. takeUntil: function(predicate, context) {
  3987. return this.takeWhile(not(predicate), context);
  3988. },
  3989. valueSeq: function() {
  3990. return this.toIndexedSeq();
  3991. },
  3992. // ### Hashable Object
  3993. hashCode: function() {
  3994. return this.__hash || (this.__hash = hashIterable(this));
  3995. }
  3996. // ### Internal
  3997. // abstract __iterate(fn, reverse)
  3998. // abstract __iterator(type, reverse)
  3999. });
  4000. // var IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
  4001. // var IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
  4002. // var IS_INDEXED_SENTINEL = '@@__IMMUTABLE_INDEXED__@@';
  4003. // var IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
  4004. var IterablePrototype = Iterable.prototype;
  4005. IterablePrototype[IS_ITERABLE_SENTINEL] = true;
  4006. IterablePrototype[ITERATOR_SYMBOL] = IterablePrototype.values;
  4007. IterablePrototype.__toJS = IterablePrototype.toArray;
  4008. IterablePrototype.__toStringMapper = quoteString;
  4009. IterablePrototype.inspect =
  4010. IterablePrototype.toSource = function() { return this.toString(); };
  4011. IterablePrototype.chain = IterablePrototype.flatMap;
  4012. IterablePrototype.contains = IterablePrototype.includes;
  4013. // Temporary warning about using length
  4014. (function () {
  4015. try {
  4016. Object.defineProperty(IterablePrototype, 'length', {
  4017. get: function () {
  4018. if (!Iterable.noLengthWarning) {
  4019. var stack;
  4020. try {
  4021. throw new Error();
  4022. } catch (error) {
  4023. stack = error.stack;
  4024. }
  4025. if (stack.indexOf('_wrapObject') === -1) {
  4026. console && console.warn && console.warn(
  4027. 'iterable.length has been deprecated, '+
  4028. 'use iterable.size or iterable.count(). '+
  4029. 'This warning will become a silent error in a future version. ' +
  4030. stack
  4031. );
  4032. return this.size;
  4033. }
  4034. }
  4035. }
  4036. });
  4037. } catch (e) {}
  4038. })();
  4039. mixin(KeyedIterable, {
  4040. // ### More sequential methods
  4041. flip: function() {
  4042. return reify(this, flipFactory(this));
  4043. },
  4044. findKey: function(predicate, context) {
  4045. var entry = this.findEntry(predicate, context);
  4046. return entry && entry[0];
  4047. },
  4048. findLastKey: function(predicate, context) {
  4049. return this.toSeq().reverse().findKey(predicate, context);
  4050. },
  4051. keyOf: function(searchValue) {
  4052. return this.findKey(function(value ) {return is(value, searchValue)});
  4053. },
  4054. lastKeyOf: function(searchValue) {
  4055. return this.findLastKey(function(value ) {return is(value, searchValue)});
  4056. },
  4057. mapEntries: function(mapper, context) {var this$0 = this;
  4058. var iterations = 0;
  4059. return reify(this,
  4060. this.toSeq().map(
  4061. function(v, k) {return mapper.call(context, [k, v], iterations++, this$0)}
  4062. ).fromEntrySeq()
  4063. );
  4064. },
  4065. mapKeys: function(mapper, context) {var this$0 = this;
  4066. return reify(this,
  4067. this.toSeq().flip().map(
  4068. function(k, v) {return mapper.call(context, k, v, this$0)}
  4069. ).flip()
  4070. );
  4071. }
  4072. });
  4073. var KeyedIterablePrototype = KeyedIterable.prototype;
  4074. KeyedIterablePrototype[IS_KEYED_SENTINEL] = true;
  4075. KeyedIterablePrototype[ITERATOR_SYMBOL] = IterablePrototype.entries;
  4076. KeyedIterablePrototype.__toJS = IterablePrototype.toObject;
  4077. KeyedIterablePrototype.__toStringMapper = function(v, k) {return JSON.stringify(k) + ': ' + quoteString(v)};
  4078. mixin(IndexedIterable, {
  4079. // ### Conversion to other types
  4080. toKeyedSeq: function() {
  4081. return new ToKeyedSequence(this, false);
  4082. },
  4083. // ### ES6 Collection methods (ES6 Array and Map)
  4084. filter: function(predicate, context) {
  4085. return reify(this, filterFactory(this, predicate, context, false));
  4086. },
  4087. findIndex: function(predicate, context) {
  4088. var entry = this.findEntry(predicate, context);
  4089. return entry ? entry[0] : -1;
  4090. },
  4091. indexOf: function(searchValue) {
  4092. var key = this.toKeyedSeq().keyOf(searchValue);
  4093. return key === undefined ? -1 : key;
  4094. },
  4095. lastIndexOf: function(searchValue) {
  4096. var key = this.toKeyedSeq().reverse().keyOf(searchValue);
  4097. return key === undefined ? -1 : key;
  4098. // var index =
  4099. // return this.toSeq().reverse().indexOf(searchValue);
  4100. },
  4101. reverse: function() {
  4102. return reify(this, reverseFactory(this, false));
  4103. },
  4104. slice: function(begin, end) {
  4105. return reify(this, sliceFactory(this, begin, end, false));
  4106. },
  4107. splice: function(index, removeNum /*, ...values*/) {
  4108. var numArgs = arguments.length;
  4109. removeNum = Math.max(removeNum | 0, 0);
  4110. if (numArgs === 0 || (numArgs === 2 && !removeNum)) {
  4111. return this;
  4112. }
  4113. // If index is negative, it should resolve relative to the size of the
  4114. // collection. However size may be expensive to compute if not cached, so
  4115. // only call count() if the number is in fact negative.
  4116. index = resolveBegin(index, index < 0 ? this.count() : this.size);
  4117. var spliced = this.slice(0, index);
  4118. return reify(
  4119. this,
  4120. numArgs === 1 ?
  4121. spliced :
  4122. spliced.concat(arrCopy(arguments, 2), this.slice(index + removeNum))
  4123. );
  4124. },
  4125. // ### More collection methods
  4126. findLastIndex: function(predicate, context) {
  4127. var key = this.toKeyedSeq().findLastKey(predicate, context);
  4128. return key === undefined ? -1 : key;
  4129. },
  4130. first: function() {
  4131. return this.get(0);
  4132. },
  4133. flatten: function(depth) {
  4134. return reify(this, flattenFactory(this, depth, false));
  4135. },
  4136. get: function(index, notSetValue) {
  4137. index = wrapIndex(this, index);
  4138. return (index < 0 || (this.size === Infinity ||
  4139. (this.size !== undefined && index > this.size))) ?
  4140. notSetValue :
  4141. this.find(function(_, key) {return key === index}, undefined, notSetValue);
  4142. },
  4143. has: function(index) {
  4144. index = wrapIndex(this, index);
  4145. return index >= 0 && (this.size !== undefined ?
  4146. this.size === Infinity || index < this.size :
  4147. this.indexOf(index) !== -1
  4148. );
  4149. },
  4150. interpose: function(separator) {
  4151. return reify(this, interposeFactory(this, separator));
  4152. },
  4153. interleave: function(/*...iterables*/) {
  4154. var iterables = [this].concat(arrCopy(arguments));
  4155. var zipped = zipWithFactory(this.toSeq(), IndexedSeq.of, iterables);
  4156. var interleaved = zipped.flatten(true);
  4157. if (zipped.size) {
  4158. interleaved.size = zipped.size * iterables.length;
  4159. }
  4160. return reify(this, interleaved);
  4161. },
  4162. last: function() {
  4163. return this.get(-1);
  4164. },
  4165. skipWhile: function(predicate, context) {
  4166. return reify(this, skipWhileFactory(this, predicate, context, false));
  4167. },
  4168. zip: function(/*, ...iterables */) {
  4169. var iterables = [this].concat(arrCopy(arguments));
  4170. return reify(this, zipWithFactory(this, defaultZipper, iterables));
  4171. },
  4172. zipWith: function(zipper/*, ...iterables */) {
  4173. var iterables = arrCopy(arguments);
  4174. iterables[0] = this;
  4175. return reify(this, zipWithFactory(this, zipper, iterables));
  4176. }
  4177. });
  4178. IndexedIterable.prototype[IS_INDEXED_SENTINEL] = true;
  4179. IndexedIterable.prototype[IS_ORDERED_SENTINEL] = true;
  4180. mixin(SetIterable, {
  4181. // ### ES6 Collection methods (ES6 Array and Map)
  4182. get: function(value, notSetValue) {
  4183. return this.has(value) ? value : notSetValue;
  4184. },
  4185. includes: function(value) {
  4186. return this.has(value);
  4187. },
  4188. // ### More sequential methods
  4189. keySeq: function() {
  4190. return this.valueSeq();
  4191. }
  4192. });
  4193. SetIterable.prototype.has = IterablePrototype.includes;
  4194. // Mixin subclasses
  4195. mixin(KeyedSeq, KeyedIterable.prototype);
  4196. mixin(IndexedSeq, IndexedIterable.prototype);
  4197. mixin(SetSeq, SetIterable.prototype);
  4198. mixin(KeyedCollection, KeyedIterable.prototype);
  4199. mixin(IndexedCollection, IndexedIterable.prototype);
  4200. mixin(SetCollection, SetIterable.prototype);
  4201. // #pragma Helper functions
  4202. function keyMapper(v, k) {
  4203. return k;
  4204. }
  4205. function entryMapper(v, k) {
  4206. return [k, v];
  4207. }
  4208. function not(predicate) {
  4209. return function() {
  4210. return !predicate.apply(this, arguments);
  4211. }
  4212. }
  4213. function neg(predicate) {
  4214. return function() {
  4215. return -predicate.apply(this, arguments);
  4216. }
  4217. }
  4218. function quoteString(value) {
  4219. return typeof value === 'string' ? JSON.stringify(value) : value;
  4220. }
  4221. function defaultZipper() {
  4222. return arrCopy(arguments);
  4223. }
  4224. function defaultNegComparator(a, b) {
  4225. return a < b ? 1 : a > b ? -1 : 0;
  4226. }
  4227. function hashIterable(iterable) {
  4228. if (iterable.size === Infinity) {
  4229. return 0;
  4230. }
  4231. var ordered = isOrdered(iterable);
  4232. var keyed = isKeyed(iterable);
  4233. var h = ordered ? 1 : 0;
  4234. var size = iterable.__iterate(
  4235. keyed ?
  4236. ordered ?
  4237. function(v, k) { h = 31 * h + hashMerge(hash(v), hash(k)) | 0; } :
  4238. function(v, k) { h = h + hashMerge(hash(v), hash(k)) | 0; } :
  4239. ordered ?
  4240. function(v ) { h = 31 * h + hash(v) | 0; } :
  4241. function(v ) { h = h + hash(v) | 0; }
  4242. );
  4243. return murmurHashOfSize(size, h);
  4244. }
  4245. function murmurHashOfSize(size, h) {
  4246. h = imul(h, 0xCC9E2D51);
  4247. h = imul(h << 15 | h >>> -15, 0x1B873593);
  4248. h = imul(h << 13 | h >>> -13, 5);
  4249. h = (h + 0xE6546B64 | 0) ^ size;
  4250. h = imul(h ^ h >>> 16, 0x85EBCA6B);
  4251. h = imul(h ^ h >>> 13, 0xC2B2AE35);
  4252. h = smi(h ^ h >>> 16);
  4253. return h;
  4254. }
  4255. function hashMerge(a, b) {
  4256. return a ^ b + 0x9E3779B9 + (a << 6) + (a >> 2) | 0; // int
  4257. }
  4258. var Immutable = {
  4259. Iterable: Iterable,
  4260. Seq: Seq,
  4261. Collection: Collection,
  4262. Map: Map,
  4263. OrderedMap: OrderedMap,
  4264. List: List,
  4265. Stack: Stack,
  4266. Set: Set,
  4267. OrderedSet: OrderedSet,
  4268. Record: Record,
  4269. Range: Range,
  4270. Repeat: Repeat,
  4271. is: is,
  4272. fromJS: fromJS
  4273. };
  4274. return Immutable;
  4275. }));
  4276. });
  4277. var OrderedMap = immutable.OrderedMap;
  4278. var BlockMapBuilder = {
  4279. createFromArray: function createFromArray(blocks) {
  4280. return OrderedMap(blocks.map(function (block) {
  4281. return [block.getKey(), block];
  4282. }));
  4283. }
  4284. };
  4285. var BlockMapBuilder_1 = BlockMapBuilder;
  4286. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4287. 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; }
  4288. 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; }
  4289. var Map = immutable.Map,
  4290. OrderedSet = immutable.OrderedSet,
  4291. Record = immutable.Record;
  4292. // Immutable.map is typed such that the value for every key in the map
  4293. // must be the same type
  4294. var EMPTY_SET = OrderedSet();
  4295. var defaultRecord = {
  4296. style: EMPTY_SET,
  4297. entity: null
  4298. };
  4299. var CharacterMetadataRecord = Record(defaultRecord);
  4300. var CharacterMetadata = function (_CharacterMetadataRec) {
  4301. _inherits(CharacterMetadata, _CharacterMetadataRec);
  4302. function CharacterMetadata() {
  4303. _classCallCheck(this, CharacterMetadata);
  4304. return _possibleConstructorReturn(this, _CharacterMetadataRec.apply(this, arguments));
  4305. }
  4306. CharacterMetadata.prototype.getStyle = function getStyle() {
  4307. return this.get('style');
  4308. };
  4309. CharacterMetadata.prototype.getEntity = function getEntity() {
  4310. return this.get('entity');
  4311. };
  4312. CharacterMetadata.prototype.hasStyle = function hasStyle(style) {
  4313. return this.getStyle().includes(style);
  4314. };
  4315. CharacterMetadata.applyStyle = function applyStyle(record, style) {
  4316. var withStyle = record.set('style', record.getStyle().add(style));
  4317. return CharacterMetadata.create(withStyle);
  4318. };
  4319. CharacterMetadata.removeStyle = function removeStyle(record, style) {
  4320. var withoutStyle = record.set('style', record.getStyle().remove(style));
  4321. return CharacterMetadata.create(withoutStyle);
  4322. };
  4323. CharacterMetadata.applyEntity = function applyEntity(record, entityKey) {
  4324. var withEntity = record.getEntity() === entityKey ? record : record.set('entity', entityKey);
  4325. return CharacterMetadata.create(withEntity);
  4326. };
  4327. /**
  4328. * Use this function instead of the `CharacterMetadata` constructor.
  4329. * Since most content generally uses only a very small number of
  4330. * style/entity permutations, we can reuse these objects as often as
  4331. * possible.
  4332. */
  4333. CharacterMetadata.create = function create(config) {
  4334. if (!config) {
  4335. return EMPTY;
  4336. }
  4337. var defaultConfig = {
  4338. style: EMPTY_SET,
  4339. entity: null
  4340. };
  4341. // Fill in unspecified properties, if necessary.
  4342. var configMap = Map(defaultConfig).merge(config);
  4343. var existing = pool.get(configMap);
  4344. if (existing) {
  4345. return existing;
  4346. }
  4347. var newCharacter = new CharacterMetadata(configMap);
  4348. pool = pool.set(configMap, newCharacter);
  4349. return newCharacter;
  4350. };
  4351. return CharacterMetadata;
  4352. }(CharacterMetadataRecord);
  4353. var EMPTY = new CharacterMetadata();
  4354. var pool = Map([[Map(defaultRecord), EMPTY]]);
  4355. CharacterMetadata.EMPTY = EMPTY;
  4356. var CharacterMetadata_1 = CharacterMetadata;
  4357. /**
  4358. * Copyright (c) 2013-present, Facebook, Inc.
  4359. * All rights reserved.
  4360. *
  4361. * This source code is licensed under the BSD-style license found in the
  4362. * LICENSE file in the root directory of this source tree. An additional grant
  4363. * of patent rights can be found in the PATENTS file in the same directory.
  4364. *
  4365. * @providesModule findRangesImmutable
  4366. * @format
  4367. *
  4368. */
  4369. /**
  4370. * Search through an array to find contiguous stretches of elements that
  4371. * match a specified filter function.
  4372. *
  4373. * When ranges are found, execute a specified `found` function to supply
  4374. * the values to the caller.
  4375. */
  4376. function findRangesImmutable(haystack, areEqualFn, filterFn, foundFn) {
  4377. if (!haystack.size) {
  4378. return;
  4379. }
  4380. var cursor = 0;
  4381. haystack.reduce(function (value, nextValue, nextIndex) {
  4382. if (!areEqualFn(value, nextValue)) {
  4383. if (filterFn(value)) {
  4384. foundFn(cursor, nextIndex);
  4385. }
  4386. cursor = nextIndex;
  4387. }
  4388. return nextValue;
  4389. });
  4390. filterFn(haystack.last()) && foundFn(cursor, haystack.count());
  4391. }
  4392. var findRangesImmutable_1 = findRangesImmutable;
  4393. function _classCallCheck$1(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4394. 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; }
  4395. 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; }
  4396. var List = immutable.List,
  4397. Map$1 = immutable.Map,
  4398. OrderedSet$1 = immutable.OrderedSet,
  4399. Record$1 = immutable.Record,
  4400. Repeat = immutable.Repeat;
  4401. var EMPTY_SET$1 = OrderedSet$1();
  4402. var defaultRecord$1 = {
  4403. key: '',
  4404. type: 'unstyled',
  4405. text: '',
  4406. characterList: List(),
  4407. depth: 0,
  4408. data: Map$1()
  4409. };
  4410. var ContentBlockRecord = Record$1(defaultRecord$1);
  4411. var decorateCharacterList = function decorateCharacterList(config) {
  4412. if (!config) {
  4413. return config;
  4414. }
  4415. var characterList = config.characterList,
  4416. text = config.text;
  4417. if (text && !characterList) {
  4418. config.characterList = List(Repeat(CharacterMetadata_1.EMPTY, text.length));
  4419. }
  4420. return config;
  4421. };
  4422. var ContentBlock = function (_ContentBlockRecord) {
  4423. _inherits$1(ContentBlock, _ContentBlockRecord);
  4424. function ContentBlock(config) {
  4425. _classCallCheck$1(this, ContentBlock);
  4426. return _possibleConstructorReturn$1(this, _ContentBlockRecord.call(this, decorateCharacterList(config)));
  4427. }
  4428. ContentBlock.prototype.getKey = function getKey() {
  4429. return this.get('key');
  4430. };
  4431. ContentBlock.prototype.getType = function getType() {
  4432. return this.get('type');
  4433. };
  4434. ContentBlock.prototype.getText = function getText() {
  4435. return this.get('text');
  4436. };
  4437. ContentBlock.prototype.getCharacterList = function getCharacterList() {
  4438. return this.get('characterList');
  4439. };
  4440. ContentBlock.prototype.getLength = function getLength() {
  4441. return this.getText().length;
  4442. };
  4443. ContentBlock.prototype.getDepth = function getDepth() {
  4444. return this.get('depth');
  4445. };
  4446. ContentBlock.prototype.getData = function getData() {
  4447. return this.get('data');
  4448. };
  4449. ContentBlock.prototype.getInlineStyleAt = function getInlineStyleAt(offset) {
  4450. var character = this.getCharacterList().get(offset);
  4451. return character ? character.getStyle() : EMPTY_SET$1;
  4452. };
  4453. ContentBlock.prototype.getEntityAt = function getEntityAt(offset) {
  4454. var character = this.getCharacterList().get(offset);
  4455. return character ? character.getEntity() : null;
  4456. };
  4457. /**
  4458. * Execute a callback for every contiguous range of styles within the block.
  4459. */
  4460. ContentBlock.prototype.findStyleRanges = function findStyleRanges(filterFn, callback) {
  4461. findRangesImmutable_1(this.getCharacterList(), haveEqualStyle, filterFn, callback);
  4462. };
  4463. /**
  4464. * Execute a callback for every contiguous range of entities within the block.
  4465. */
  4466. ContentBlock.prototype.findEntityRanges = function findEntityRanges(filterFn, callback) {
  4467. findRangesImmutable_1(this.getCharacterList(), haveEqualEntity, filterFn, callback);
  4468. };
  4469. return ContentBlock;
  4470. }(ContentBlockRecord);
  4471. function haveEqualStyle(charA, charB) {
  4472. return charA.getStyle() === charB.getStyle();
  4473. }
  4474. function haveEqualEntity(charA, charB) {
  4475. return charA.getEntity() === charB.getEntity();
  4476. }
  4477. var ContentBlock_1 = ContentBlock;
  4478. function _classCallCheck$2(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4479. 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; }
  4480. 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; }
  4481. var List$1 = immutable.List,
  4482. Map$2 = immutable.Map,
  4483. OrderedSet$2 = immutable.OrderedSet,
  4484. Record$2 = immutable.Record,
  4485. Repeat$1 = immutable.Repeat;
  4486. var EMPTY_SET$2 = OrderedSet$2();
  4487. var defaultRecord$2 = {
  4488. parent: null,
  4489. characterList: List$1(),
  4490. data: Map$2(),
  4491. depth: 0,
  4492. key: '',
  4493. text: '',
  4494. type: 'unstyled',
  4495. children: List$1(),
  4496. prevSibling: null,
  4497. nextSibling: null
  4498. };
  4499. var haveEqualStyle$1 = function haveEqualStyle(charA, charB) {
  4500. return charA.getStyle() === charB.getStyle();
  4501. };
  4502. var haveEqualEntity$1 = function haveEqualEntity(charA, charB) {
  4503. return charA.getEntity() === charB.getEntity();
  4504. };
  4505. var decorateCharacterList$1 = function decorateCharacterList(config) {
  4506. if (!config) {
  4507. return config;
  4508. }
  4509. var characterList = config.characterList,
  4510. text = config.text;
  4511. if (text && !characterList) {
  4512. config.characterList = List$1(Repeat$1(CharacterMetadata_1.EMPTY, text.length));
  4513. }
  4514. return config;
  4515. };
  4516. var ContentBlockNode = function (_Record) {
  4517. _inherits$2(ContentBlockNode, _Record);
  4518. function ContentBlockNode() {
  4519. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultRecord$2;
  4520. _classCallCheck$2(this, ContentBlockNode);
  4521. return _possibleConstructorReturn$2(this, _Record.call(this, decorateCharacterList$1(props)));
  4522. }
  4523. ContentBlockNode.prototype.getKey = function getKey() {
  4524. return this.get('key');
  4525. };
  4526. ContentBlockNode.prototype.getType = function getType() {
  4527. return this.get('type');
  4528. };
  4529. ContentBlockNode.prototype.getText = function getText() {
  4530. return this.get('text');
  4531. };
  4532. ContentBlockNode.prototype.getCharacterList = function getCharacterList() {
  4533. return this.get('characterList');
  4534. };
  4535. ContentBlockNode.prototype.getLength = function getLength() {
  4536. return this.getText().length;
  4537. };
  4538. ContentBlockNode.prototype.getDepth = function getDepth() {
  4539. return this.get('depth');
  4540. };
  4541. ContentBlockNode.prototype.getData = function getData() {
  4542. return this.get('data');
  4543. };
  4544. ContentBlockNode.prototype.getInlineStyleAt = function getInlineStyleAt(offset) {
  4545. var character = this.getCharacterList().get(offset);
  4546. return character ? character.getStyle() : EMPTY_SET$2;
  4547. };
  4548. ContentBlockNode.prototype.getEntityAt = function getEntityAt(offset) {
  4549. var character = this.getCharacterList().get(offset);
  4550. return character ? character.getEntity() : null;
  4551. };
  4552. ContentBlockNode.prototype.getChildKeys = function getChildKeys() {
  4553. return this.get('children');
  4554. };
  4555. ContentBlockNode.prototype.getParentKey = function getParentKey() {
  4556. return this.get('parent');
  4557. };
  4558. ContentBlockNode.prototype.getPrevSiblingKey = function getPrevSiblingKey() {
  4559. return this.get('prevSibling');
  4560. };
  4561. ContentBlockNode.prototype.getNextSiblingKey = function getNextSiblingKey() {
  4562. return this.get('nextSibling');
  4563. };
  4564. ContentBlockNode.prototype.findStyleRanges = function findStyleRanges(filterFn, callback) {
  4565. findRangesImmutable_1(this.getCharacterList(), haveEqualStyle$1, filterFn, callback);
  4566. };
  4567. ContentBlockNode.prototype.findEntityRanges = function findEntityRanges(filterFn, callback) {
  4568. findRangesImmutable_1(this.getCharacterList(), haveEqualEntity$1, filterFn, callback);
  4569. };
  4570. return ContentBlockNode;
  4571. }(Record$2(defaultRecord$2));
  4572. var ContentBlockNode_1 = ContentBlockNode;
  4573. /**
  4574. * Copyright 2013-present, Facebook, Inc.
  4575. * All rights reserved.
  4576. *
  4577. * This source code is licensed under the BSD-style license found in the
  4578. * LICENSE file in the root directory of this source tree. An additional grant
  4579. * of patent rights can be found in the PATENTS file in the same directory.
  4580. *
  4581. * @providesModule DraftFeatureFlags-core
  4582. * @format
  4583. *
  4584. */
  4585. var DraftFeatureFlags = {
  4586. draft_killswitch_allow_nontextnodes: false,
  4587. draft_segmented_entities_behavior: false,
  4588. draft_handlebeforeinput_composed_text: false,
  4589. draft_tree_data_support: false
  4590. };
  4591. var DraftFeatureFlagsCore = DraftFeatureFlags;
  4592. var DraftFeatureFlags_1 = DraftFeatureFlagsCore;
  4593. var Map$3 = immutable.Map;
  4594. var ContentStateInlineStyle = {
  4595. add: function add(contentState, selectionState, inlineStyle) {
  4596. return modifyInlineStyle(contentState, selectionState, inlineStyle, true);
  4597. },
  4598. remove: function remove(contentState, selectionState, inlineStyle) {
  4599. return modifyInlineStyle(contentState, selectionState, inlineStyle, false);
  4600. }
  4601. };
  4602. function modifyInlineStyle(contentState, selectionState, inlineStyle, addOrRemove) {
  4603. var blockMap = contentState.getBlockMap();
  4604. var startKey = selectionState.getStartKey();
  4605. var startOffset = selectionState.getStartOffset();
  4606. var endKey = selectionState.getEndKey();
  4607. var endOffset = selectionState.getEndOffset();
  4608. var newBlocks = blockMap.skipUntil(function (_, k) {
  4609. return k === startKey;
  4610. }).takeUntil(function (_, k) {
  4611. return k === endKey;
  4612. }).concat(Map$3([[endKey, blockMap.get(endKey)]])).map(function (block, blockKey) {
  4613. var sliceStart;
  4614. var sliceEnd;
  4615. if (startKey === endKey) {
  4616. sliceStart = startOffset;
  4617. sliceEnd = endOffset;
  4618. } else {
  4619. sliceStart = blockKey === startKey ? startOffset : 0;
  4620. sliceEnd = blockKey === endKey ? endOffset : block.getLength();
  4621. }
  4622. var chars = block.getCharacterList();
  4623. var current;
  4624. while (sliceStart < sliceEnd) {
  4625. current = chars.get(sliceStart);
  4626. chars = chars.set(sliceStart, addOrRemove ? CharacterMetadata_1.applyStyle(current, inlineStyle) : CharacterMetadata_1.removeStyle(current, inlineStyle));
  4627. sliceStart++;
  4628. }
  4629. return block.set('characterList', chars);
  4630. });
  4631. return contentState.merge({
  4632. blockMap: blockMap.merge(newBlocks),
  4633. selectionBefore: selectionState,
  4634. selectionAfter: selectionState
  4635. });
  4636. }
  4637. var ContentStateInlineStyle_1 = ContentStateInlineStyle;
  4638. function applyEntityToContentBlock(contentBlock, start, end, entityKey) {
  4639. var characterList = contentBlock.getCharacterList();
  4640. while (start < end) {
  4641. characterList = characterList.set(start, CharacterMetadata_1.applyEntity(characterList.get(start), entityKey));
  4642. start++;
  4643. }
  4644. return contentBlock.set('characterList', characterList);
  4645. }
  4646. var applyEntityToContentBlock_1 = applyEntityToContentBlock;
  4647. function applyEntityToContentState(contentState, selectionState, entityKey) {
  4648. var blockMap = contentState.getBlockMap();
  4649. var startKey = selectionState.getStartKey();
  4650. var startOffset = selectionState.getStartOffset();
  4651. var endKey = selectionState.getEndKey();
  4652. var endOffset = selectionState.getEndOffset();
  4653. var newBlocks = blockMap.skipUntil(function (_, k) {
  4654. return k === startKey;
  4655. }).takeUntil(function (_, k) {
  4656. return k === endKey;
  4657. }).toOrderedMap().merge(immutable.OrderedMap([[endKey, blockMap.get(endKey)]])).map(function (block, blockKey) {
  4658. var sliceStart = blockKey === startKey ? startOffset : 0;
  4659. var sliceEnd = blockKey === endKey ? endOffset : block.getLength();
  4660. return applyEntityToContentBlock_1(block, sliceStart, sliceEnd, entityKey);
  4661. });
  4662. return contentState.merge({
  4663. blockMap: blockMap.merge(newBlocks),
  4664. selectionBefore: selectionState,
  4665. selectionAfter: selectionState
  4666. });
  4667. }
  4668. var applyEntityToContentState_1 = applyEntityToContentState;
  4669. /**
  4670. * Copyright (c) 2013-present, Facebook, Inc.
  4671. * All rights reserved.
  4672. *
  4673. * This source code is licensed under the BSD-style license found in the
  4674. * LICENSE file in the root directory of this source tree. An additional grant
  4675. * of patent rights can be found in the PATENTS file in the same directory.
  4676. *
  4677. * @providesModule DraftEntitySegments
  4678. * @format
  4679. *
  4680. */
  4681. /**
  4682. * Identify the range to delete from a segmented entity.
  4683. *
  4684. * Rules:
  4685. *
  4686. * Example: 'John F. Kennedy'
  4687. *
  4688. * - Deletion from within any non-whitespace (i.e. ['John', 'F.', 'Kennedy'])
  4689. * will return the range of that text.
  4690. *
  4691. * 'John F. Kennedy' -> 'John F.'
  4692. * ^
  4693. *
  4694. * - Forward deletion of whitespace will remove the following section:
  4695. *
  4696. * 'John F. Kennedy' -> 'John Kennedy'
  4697. * ^
  4698. *
  4699. * - Backward deletion of whitespace will remove the previous section:
  4700. *
  4701. * 'John F. Kennedy' -> 'F. Kennedy'
  4702. * ^
  4703. */
  4704. var DraftEntitySegments = {
  4705. getRemovalRange: function getRemovalRange(selectionStart, selectionEnd, text, entityStart, direction) {
  4706. var segments = text.split(' ');
  4707. segments = segments.map(function ( /*string*/segment, /*number*/ii) {
  4708. if (direction === 'forward') {
  4709. if (ii > 0) {
  4710. return ' ' + segment;
  4711. }
  4712. } else if (ii < segments.length - 1) {
  4713. return segment + ' ';
  4714. }
  4715. return segment;
  4716. });
  4717. var segmentStart = entityStart;
  4718. var segmentEnd;
  4719. var segment;
  4720. var removalStart = null;
  4721. var removalEnd = null;
  4722. for (var jj = 0; jj < segments.length; jj++) {
  4723. segment = segments[jj];
  4724. segmentEnd = segmentStart + segment.length;
  4725. // Our selection overlaps this segment.
  4726. if (selectionStart < segmentEnd && segmentStart < selectionEnd) {
  4727. if (removalStart !== null) {
  4728. removalEnd = segmentEnd;
  4729. } else {
  4730. removalStart = segmentStart;
  4731. removalEnd = segmentEnd;
  4732. }
  4733. } else if (removalStart !== null) {
  4734. break;
  4735. }
  4736. segmentStart = segmentEnd;
  4737. }
  4738. var entityEnd = entityStart + text.length;
  4739. var atStart = removalStart === entityStart;
  4740. var atEnd = removalEnd === entityEnd;
  4741. if (!atStart && atEnd || atStart && !atEnd) {
  4742. if (direction === 'forward') {
  4743. if (removalEnd !== entityEnd) {
  4744. removalEnd++;
  4745. }
  4746. } else if (removalStart !== entityStart) {
  4747. removalStart--;
  4748. }
  4749. }
  4750. return {
  4751. start: removalStart,
  4752. end: removalEnd
  4753. };
  4754. }
  4755. };
  4756. var DraftEntitySegments_1 = DraftEntitySegments;
  4757. /**
  4758. * Copyright (c) 2013-present, Facebook, Inc.
  4759. *
  4760. * This source code is licensed under the MIT license found in the
  4761. * LICENSE file in the root directory of this source tree.
  4762. *
  4763. */
  4764. /**
  4765. * Use invariant() to assert state which your program assumes to be true.
  4766. *
  4767. * Provide sprintf-style format (only %s is supported) and arguments
  4768. * to provide information about what broke and what you were
  4769. * expecting.
  4770. *
  4771. * The invariant message will be stripped in production, but the invariant
  4772. * will remain to ensure logic does not differ in production.
  4773. */
  4774. var validateFormat = function validateFormat(format) {};
  4775. if (process.env.NODE_ENV !== 'production') {
  4776. validateFormat = function validateFormat(format) {
  4777. if (format === undefined) {
  4778. throw new Error('invariant requires an error message argument');
  4779. }
  4780. };
  4781. }
  4782. function invariant(condition, format, a, b, c, d, e, f) {
  4783. validateFormat(format);
  4784. if (!condition) {
  4785. var error;
  4786. if (format === undefined) {
  4787. error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
  4788. } else {
  4789. var args = [a, b, c, d, e, f];
  4790. var argIndex = 0;
  4791. error = new Error(format.replace(/%s/g, function () {
  4792. return args[argIndex++];
  4793. }));
  4794. error.name = 'Invariant Violation';
  4795. }
  4796. error.framesToPop = 1; // we don't care about invariant's own frame
  4797. throw error;
  4798. }
  4799. }
  4800. var invariant_1 = invariant;
  4801. /**
  4802. * Obtain the start and end positions of the range that has the
  4803. * specified entity applied to it.
  4804. *
  4805. * Entity keys are applied only to contiguous stretches of text, so this
  4806. * method searches for the first instance of the entity key and returns
  4807. * the subsequent range.
  4808. */
  4809. function getRangesForDraftEntity(block, key) {
  4810. var ranges = [];
  4811. block.findEntityRanges(function (c) {
  4812. return c.getEntity() === key;
  4813. }, function (start, end) {
  4814. ranges.push({ start: start, end: end });
  4815. });
  4816. !!!ranges.length ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Entity key not found in this range.') : invariant_1(false) : void 0;
  4817. return ranges;
  4818. }
  4819. var getRangesForDraftEntity_1 = getRangesForDraftEntity;
  4820. /**
  4821. * Given a SelectionState and a removal direction, determine the entire range
  4822. * that should be removed from a ContentState. This is based on any entities
  4823. * within the target, with their `mutability` values taken into account.
  4824. *
  4825. * For instance, if we are attempting to remove part of an "immutable" entity
  4826. * range, the entire entity must be removed. The returned `SelectionState`
  4827. * will be adjusted accordingly.
  4828. */
  4829. function getCharacterRemovalRange(entityMap, startBlock, endBlock, selectionState, direction) {
  4830. var start = selectionState.getStartOffset();
  4831. var end = selectionState.getEndOffset();
  4832. var startEntityKey = startBlock.getEntityAt(start);
  4833. var endEntityKey = endBlock.getEntityAt(end - 1);
  4834. if (!startEntityKey && !endEntityKey) {
  4835. return selectionState;
  4836. }
  4837. var newSelectionState = selectionState;
  4838. if (startEntityKey && startEntityKey === endEntityKey) {
  4839. newSelectionState = getEntityRemovalRange(entityMap, startBlock, newSelectionState, direction, startEntityKey, true, true);
  4840. } else if (startEntityKey && endEntityKey) {
  4841. var startSelectionState = getEntityRemovalRange(entityMap, startBlock, newSelectionState, direction, startEntityKey, false, true);
  4842. var endSelectionState = getEntityRemovalRange(entityMap, endBlock, newSelectionState, direction, endEntityKey, false, false);
  4843. newSelectionState = newSelectionState.merge({
  4844. anchorOffset: startSelectionState.getAnchorOffset(),
  4845. focusOffset: endSelectionState.getFocusOffset(),
  4846. isBackward: false
  4847. });
  4848. } else if (startEntityKey) {
  4849. var _startSelectionState = getEntityRemovalRange(entityMap, startBlock, newSelectionState, direction, startEntityKey, false, true);
  4850. newSelectionState = newSelectionState.merge({
  4851. anchorOffset: _startSelectionState.getStartOffset(),
  4852. isBackward: false
  4853. });
  4854. } else if (endEntityKey) {
  4855. var _endSelectionState = getEntityRemovalRange(entityMap, endBlock, newSelectionState, direction, endEntityKey, false, false);
  4856. newSelectionState = newSelectionState.merge({
  4857. focusOffset: _endSelectionState.getEndOffset(),
  4858. isBackward: false
  4859. });
  4860. }
  4861. return newSelectionState;
  4862. }
  4863. function getEntityRemovalRange(entityMap, block, selectionState, direction, entityKey, isEntireSelectionWithinEntity, isEntityAtStart) {
  4864. var start = selectionState.getStartOffset();
  4865. var end = selectionState.getEndOffset();
  4866. var entity = entityMap.__get(entityKey);
  4867. var mutability = entity.getMutability();
  4868. var sideToConsider = isEntityAtStart ? start : end;
  4869. // `MUTABLE` entities can just have the specified range of text removed
  4870. // directly. No adjustments are needed.
  4871. if (mutability === 'MUTABLE') {
  4872. return selectionState;
  4873. }
  4874. // Find the entity range that overlaps with our removal range.
  4875. var entityRanges = getRangesForDraftEntity_1(block, entityKey).filter(function (range) {
  4876. return sideToConsider <= range.end && sideToConsider >= range.start;
  4877. });
  4878. !(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;
  4879. var entityRange = entityRanges[0];
  4880. // For `IMMUTABLE` entity types, we will remove the entire entity range.
  4881. if (mutability === 'IMMUTABLE') {
  4882. return selectionState.merge({
  4883. anchorOffset: entityRange.start,
  4884. focusOffset: entityRange.end,
  4885. isBackward: false
  4886. });
  4887. }
  4888. // For `SEGMENTED` entity types, determine the appropriate segment to
  4889. // remove.
  4890. if (!isEntireSelectionWithinEntity) {
  4891. if (isEntityAtStart) {
  4892. end = entityRange.end;
  4893. } else {
  4894. start = entityRange.start;
  4895. }
  4896. }
  4897. var removalRange = DraftEntitySegments_1.getRemovalRange(start, end, block.getText().slice(entityRange.start, entityRange.end), entityRange.start, direction);
  4898. return selectionState.merge({
  4899. anchorOffset: removalRange.start,
  4900. focusOffset: removalRange.end,
  4901. isBackward: false
  4902. });
  4903. }
  4904. var getCharacterRemovalRange_1 = getCharacterRemovalRange;
  4905. /**
  4906. * Copyright (c) 2013-present, Facebook, Inc.
  4907. * All rights reserved.
  4908. *
  4909. * This source code is licensed under the BSD-style license found in the
  4910. * LICENSE file in the root directory of this source tree. An additional grant
  4911. * of patent rights can be found in the PATENTS file in the same directory.
  4912. *
  4913. * @providesModule generateRandomKey
  4914. * @format
  4915. *
  4916. */
  4917. var seenKeys = {};
  4918. var MULTIPLIER = Math.pow(2, 24);
  4919. function generateRandomKey() {
  4920. var key = void 0;
  4921. while (key === undefined || seenKeys.hasOwnProperty(key) || !isNaN(+key)) {
  4922. key = Math.floor(Math.random() * MULTIPLIER).toString(32);
  4923. }
  4924. seenKeys[key] = true;
  4925. return key;
  4926. }
  4927. var generateRandomKey_1 = generateRandomKey;
  4928. var OrderedMap$1 = immutable.OrderedMap;
  4929. var randomizeContentBlockNodeKeys = function randomizeContentBlockNodeKeys(blockMap) {
  4930. var newKeysRef = {};
  4931. // we keep track of root blocks in order to update subsequent sibling links
  4932. var lastRootBlock = void 0;
  4933. return OrderedMap$1(blockMap.withMutations(function (blockMapState) {
  4934. blockMapState.forEach(function (block, index) {
  4935. var oldKey = block.getKey();
  4936. var nextKey = block.getNextSiblingKey();
  4937. var prevKey = block.getPrevSiblingKey();
  4938. var childrenKeys = block.getChildKeys();
  4939. var parentKey = block.getParentKey();
  4940. // new key that we will use to build linking
  4941. var key = generateRandomKey_1();
  4942. // we will add it here to re-use it later
  4943. newKeysRef[oldKey] = key;
  4944. if (nextKey) {
  4945. var nextBlock = blockMapState.get(nextKey);
  4946. if (nextBlock) {
  4947. blockMapState.setIn([nextKey, 'prevSibling'], key);
  4948. } else {
  4949. // this can happen when generating random keys for fragments
  4950. blockMapState.setIn([oldKey, 'nextSibling'], null);
  4951. }
  4952. }
  4953. if (prevKey) {
  4954. var prevBlock = blockMapState.get(prevKey);
  4955. if (prevBlock) {
  4956. blockMapState.setIn([prevKey, 'nextSibling'], key);
  4957. } else {
  4958. // this can happen when generating random keys for fragments
  4959. blockMapState.setIn([oldKey, 'prevSibling'], null);
  4960. }
  4961. }
  4962. if (parentKey && blockMapState.get(parentKey)) {
  4963. var parentBlock = blockMapState.get(parentKey);
  4964. var parentChildrenList = parentBlock.getChildKeys();
  4965. blockMapState.setIn([parentKey, 'children'], parentChildrenList.set(parentChildrenList.indexOf(block.getKey()), key));
  4966. } else {
  4967. // blocks will then be treated as root block nodes
  4968. blockMapState.setIn([oldKey, 'parent'], null);
  4969. if (lastRootBlock) {
  4970. blockMapState.setIn([lastRootBlock.getKey(), 'nextSibling'], key);
  4971. blockMapState.setIn([oldKey, 'prevSibling'], newKeysRef[lastRootBlock.getKey()]);
  4972. }
  4973. lastRootBlock = blockMapState.get(oldKey);
  4974. }
  4975. childrenKeys.forEach(function (childKey) {
  4976. var childBlock = blockMapState.get(childKey);
  4977. if (childBlock) {
  4978. blockMapState.setIn([childKey, 'parent'], key);
  4979. } else {
  4980. blockMapState.setIn([oldKey, 'children'], block.getChildKeys().filter(function (child) {
  4981. return child !== childKey;
  4982. }));
  4983. }
  4984. });
  4985. });
  4986. }).toArray().map(function (block) {
  4987. return [newKeysRef[block.getKey()], block.set('key', newKeysRef[block.getKey()])];
  4988. }));
  4989. };
  4990. var randomizeContentBlockKeys = function randomizeContentBlockKeys(blockMap) {
  4991. return OrderedMap$1(blockMap.toArray().map(function (block) {
  4992. var key = generateRandomKey_1();
  4993. return [key, block.set('key', key)];
  4994. }));
  4995. };
  4996. var randomizeBlockMapKeys = function randomizeBlockMapKeys(blockMap) {
  4997. var isTreeBasedBlockMap = blockMap.first() instanceof ContentBlockNode_1;
  4998. if (!isTreeBasedBlockMap) {
  4999. return randomizeContentBlockKeys(blockMap);
  5000. }
  5001. return randomizeContentBlockNodeKeys(blockMap);
  5002. };
  5003. var randomizeBlockMapKeys_1 = randomizeBlockMapKeys;
  5004. function removeEntitiesAtEdges(contentState, selectionState) {
  5005. var blockMap = contentState.getBlockMap();
  5006. var entityMap = contentState.getEntityMap();
  5007. var updatedBlocks = {};
  5008. var startKey = selectionState.getStartKey();
  5009. var startOffset = selectionState.getStartOffset();
  5010. var startBlock = blockMap.get(startKey);
  5011. var updatedStart = removeForBlock(entityMap, startBlock, startOffset);
  5012. if (updatedStart !== startBlock) {
  5013. updatedBlocks[startKey] = updatedStart;
  5014. }
  5015. var endKey = selectionState.getEndKey();
  5016. var endOffset = selectionState.getEndOffset();
  5017. var endBlock = blockMap.get(endKey);
  5018. if (startKey === endKey) {
  5019. endBlock = updatedStart;
  5020. }
  5021. var updatedEnd = removeForBlock(entityMap, endBlock, endOffset);
  5022. if (updatedEnd !== endBlock) {
  5023. updatedBlocks[endKey] = updatedEnd;
  5024. }
  5025. if (!Object.keys(updatedBlocks).length) {
  5026. return contentState.set('selectionAfter', selectionState);
  5027. }
  5028. return contentState.merge({
  5029. blockMap: blockMap.merge(updatedBlocks),
  5030. selectionAfter: selectionState
  5031. });
  5032. }
  5033. function getRemovalRange(characters, key, offset) {
  5034. var removalRange;
  5035. findRangesImmutable_1(characters, function (a, b) {
  5036. return a.getEntity() === b.getEntity();
  5037. }, function (element) {
  5038. return element.getEntity() === key;
  5039. }, function (start, end) {
  5040. if (start <= offset && end >= offset) {
  5041. removalRange = { start: start, end: end };
  5042. }
  5043. });
  5044. !(typeof removalRange === 'object') ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Removal range must exist within character list.') : invariant_1(false) : void 0;
  5045. return removalRange;
  5046. }
  5047. function removeForBlock(entityMap, block, offset) {
  5048. var chars = block.getCharacterList();
  5049. var charBefore = offset > 0 ? chars.get(offset - 1) : undefined;
  5050. var charAfter = offset < chars.count() ? chars.get(offset) : undefined;
  5051. var entityBeforeCursor = charBefore ? charBefore.getEntity() : undefined;
  5052. var entityAfterCursor = charAfter ? charAfter.getEntity() : undefined;
  5053. if (entityAfterCursor && entityAfterCursor === entityBeforeCursor) {
  5054. var entity = entityMap.__get(entityAfterCursor);
  5055. if (entity.getMutability() !== 'MUTABLE') {
  5056. var _getRemovalRange = getRemovalRange(chars, entityAfterCursor, offset),
  5057. start = _getRemovalRange.start,
  5058. end = _getRemovalRange.end;
  5059. var current;
  5060. while (start < end) {
  5061. current = chars.get(start);
  5062. chars = chars.set(start, CharacterMetadata_1.applyEntity(current, null));
  5063. start++;
  5064. }
  5065. return block.set('characterList', chars);
  5066. }
  5067. }
  5068. return block;
  5069. }
  5070. var removeEntitiesAtEdges_1 = removeEntitiesAtEdges;
  5071. var getContentStateFragment = function getContentStateFragment(contentState, selectionState) {
  5072. var startKey = selectionState.getStartKey();
  5073. var startOffset = selectionState.getStartOffset();
  5074. var endKey = selectionState.getEndKey();
  5075. var endOffset = selectionState.getEndOffset();
  5076. // Edge entities should be stripped to ensure that we don't preserve
  5077. // invalid partial entities when the fragment is reused. We do, however,
  5078. // preserve entities that are entirely within the selection range.
  5079. var contentWithoutEdgeEntities = removeEntitiesAtEdges_1(contentState, selectionState);
  5080. var blockMap = contentWithoutEdgeEntities.getBlockMap();
  5081. var blockKeys = blockMap.keySeq();
  5082. var startIndex = blockKeys.indexOf(startKey);
  5083. var endIndex = blockKeys.indexOf(endKey) + 1;
  5084. return randomizeBlockMapKeys_1(blockMap.slice(startIndex, endIndex).map(function (block, blockKey) {
  5085. var text = block.getText();
  5086. var chars = block.getCharacterList();
  5087. if (startKey === endKey) {
  5088. return block.merge({
  5089. text: text.slice(startOffset, endOffset),
  5090. characterList: chars.slice(startOffset, endOffset)
  5091. });
  5092. }
  5093. if (blockKey === startKey) {
  5094. return block.merge({
  5095. text: text.slice(startOffset),
  5096. characterList: chars.slice(startOffset)
  5097. });
  5098. }
  5099. if (blockKey === endKey) {
  5100. return block.merge({
  5101. text: text.slice(0, endOffset),
  5102. characterList: chars.slice(0, endOffset)
  5103. });
  5104. }
  5105. return block;
  5106. }));
  5107. };
  5108. var getContentStateFragment_1 = getContentStateFragment;
  5109. /**
  5110. * Copyright (c) 2013-present, Facebook, Inc.
  5111. * All rights reserved.
  5112. *
  5113. * This source code is licensed under the BSD-style license found in the
  5114. * LICENSE file in the root directory of this source tree. An additional grant
  5115. * of patent rights can be found in the PATENTS file in the same directory.
  5116. *
  5117. * @providesModule insertIntoList
  5118. * @format
  5119. *
  5120. */
  5121. /**
  5122. * Maintain persistence for target list when appending and prepending.
  5123. */
  5124. function insertIntoList(targetList, toInsert, offset) {
  5125. if (offset === targetList.count()) {
  5126. toInsert.forEach(function (c) {
  5127. targetList = targetList.push(c);
  5128. });
  5129. } else if (offset === 0) {
  5130. toInsert.reverse().forEach(function (c) {
  5131. targetList = targetList.unshift(c);
  5132. });
  5133. } else {
  5134. var head = targetList.slice(0, offset);
  5135. var tail = targetList.slice(offset);
  5136. targetList = head.concat(toInsert, tail).toList();
  5137. }
  5138. return targetList;
  5139. }
  5140. var insertIntoList_1 = insertIntoList;
  5141. var List$2 = immutable.List;
  5142. var updateExistingBlock = function updateExistingBlock(contentState, selectionState, blockMap, fragmentBlock, targetKey, targetOffset) {
  5143. var targetBlock = blockMap.get(targetKey);
  5144. var text = targetBlock.getText();
  5145. var chars = targetBlock.getCharacterList();
  5146. var finalKey = targetKey;
  5147. var finalOffset = targetOffset + fragmentBlock.getText().length;
  5148. var newBlock = targetBlock.merge({
  5149. text: text.slice(0, targetOffset) + fragmentBlock.getText() + text.slice(targetOffset),
  5150. characterList: insertIntoList_1(chars, fragmentBlock.getCharacterList(), targetOffset),
  5151. data: fragmentBlock.getData()
  5152. });
  5153. return contentState.merge({
  5154. blockMap: blockMap.set(targetKey, newBlock),
  5155. selectionBefore: selectionState,
  5156. selectionAfter: selectionState.merge({
  5157. anchorKey: finalKey,
  5158. anchorOffset: finalOffset,
  5159. focusKey: finalKey,
  5160. focusOffset: finalOffset,
  5161. isBackward: false
  5162. })
  5163. });
  5164. };
  5165. /**
  5166. * Appends text/characterList from the fragment first block to
  5167. * target block.
  5168. */
  5169. var updateHead = function updateHead(block, targetOffset, fragment) {
  5170. var text = block.getText();
  5171. var chars = block.getCharacterList();
  5172. // Modify head portion of block.
  5173. var headText = text.slice(0, targetOffset);
  5174. var headCharacters = chars.slice(0, targetOffset);
  5175. var appendToHead = fragment.first();
  5176. return block.merge({
  5177. text: headText + appendToHead.getText(),
  5178. characterList: headCharacters.concat(appendToHead.getCharacterList()),
  5179. type: headText ? block.getType() : appendToHead.getType(),
  5180. data: appendToHead.getData()
  5181. });
  5182. };
  5183. /**
  5184. * Appends offset text/characterList from the target block to the last
  5185. * fragment block.
  5186. */
  5187. var updateTail = function updateTail(block, targetOffset, fragment) {
  5188. // Modify tail portion of block.
  5189. var text = block.getText();
  5190. var chars = block.getCharacterList();
  5191. // Modify head portion of block.
  5192. var blockSize = text.length;
  5193. var tailText = text.slice(targetOffset, blockSize);
  5194. var tailCharacters = chars.slice(targetOffset, blockSize);
  5195. var prependToTail = fragment.last();
  5196. return prependToTail.merge({
  5197. text: prependToTail.getText() + tailText,
  5198. characterList: prependToTail.getCharacterList().concat(tailCharacters),
  5199. data: prependToTail.getData()
  5200. });
  5201. };
  5202. var getRootBlocks = function getRootBlocks(block, blockMap) {
  5203. var headKey = block.getKey();
  5204. var rootBlock = block;
  5205. var rootBlocks = [];
  5206. // sometimes the fragment head block will not be part of the blockMap itself this can happen when
  5207. // the fragment head is used to update the target block, however when this does not happen we need
  5208. // to make sure that we include it on the rootBlocks since the first block of a fragment is always a
  5209. // fragment root block
  5210. if (blockMap.get(headKey)) {
  5211. rootBlocks.push(headKey);
  5212. }
  5213. while (rootBlock && rootBlock.getNextSiblingKey()) {
  5214. var lastSiblingKey = rootBlock.getNextSiblingKey();
  5215. if (!lastSiblingKey) {
  5216. break;
  5217. }
  5218. rootBlocks.push(lastSiblingKey);
  5219. rootBlock = blockMap.get(lastSiblingKey);
  5220. }
  5221. return rootBlocks;
  5222. };
  5223. var updateBlockMapLinks = function updateBlockMapLinks(blockMap, originalBlockMap, targetBlock, fragmentHeadBlock) {
  5224. return blockMap.withMutations(function (blockMapState) {
  5225. var targetKey = targetBlock.getKey();
  5226. var headKey = fragmentHeadBlock.getKey();
  5227. var targetNextKey = targetBlock.getNextSiblingKey();
  5228. var targetParentKey = targetBlock.getParentKey();
  5229. var fragmentRootBlocks = getRootBlocks(fragmentHeadBlock, blockMap);
  5230. var lastRootFragmentBlockKey = fragmentRootBlocks[fragmentRootBlocks.length - 1];
  5231. if (blockMapState.get(headKey)) {
  5232. // update the fragment head when it is part of the blockMap otherwise
  5233. blockMapState.setIn([targetKey, 'nextSibling'], headKey);
  5234. blockMapState.setIn([headKey, 'prevSibling'], targetKey);
  5235. } else {
  5236. // update the target block that had the fragment head contents merged into it
  5237. blockMapState.setIn([targetKey, 'nextSibling'], fragmentHeadBlock.getNextSiblingKey());
  5238. blockMapState.setIn([fragmentHeadBlock.getNextSiblingKey(), 'prevSibling'], targetKey);
  5239. }
  5240. // update the last root block fragment
  5241. blockMapState.setIn([lastRootFragmentBlockKey, 'nextSibling'], targetNextKey);
  5242. // update the original target next block
  5243. if (targetNextKey) {
  5244. blockMapState.setIn([targetNextKey, 'prevSibling'], lastRootFragmentBlockKey);
  5245. }
  5246. // update fragment parent links
  5247. fragmentRootBlocks.forEach(function (blockKey) {
  5248. return blockMapState.setIn([blockKey, 'parent'], targetParentKey);
  5249. });
  5250. // update targetBlock parent child links
  5251. if (targetParentKey) {
  5252. var targetParent = blockMap.get(targetParentKey);
  5253. var originalTargetParentChildKeys = targetParent.getChildKeys();
  5254. var targetBlockIndex = originalTargetParentChildKeys.indexOf(targetKey);
  5255. var insertionIndex = targetBlockIndex + 1;
  5256. var newChildrenKeysArray = originalTargetParentChildKeys.toArray();
  5257. // insert fragment children
  5258. newChildrenKeysArray.splice.apply(newChildrenKeysArray, [insertionIndex, 0].concat(fragmentRootBlocks));
  5259. blockMapState.setIn([targetParentKey, 'children'], List$2(newChildrenKeysArray));
  5260. }
  5261. });
  5262. };
  5263. var insertFragment = function insertFragment(contentState, selectionState, blockMap, fragment, targetKey, targetOffset) {
  5264. var isTreeBasedBlockMap = blockMap.first() instanceof ContentBlockNode_1;
  5265. var newBlockArr = [];
  5266. var fragmentSize = fragment.size;
  5267. var target = blockMap.get(targetKey);
  5268. var head = fragment.first();
  5269. var tail = fragment.last();
  5270. var finalOffset = tail.getLength();
  5271. var finalKey = tail.getKey();
  5272. var shouldNotUpdateFromFragmentBlock = isTreeBasedBlockMap && (!target.getChildKeys().isEmpty() || !head.getChildKeys().isEmpty());
  5273. blockMap.forEach(function (block, blockKey) {
  5274. if (blockKey !== targetKey) {
  5275. newBlockArr.push(block);
  5276. return;
  5277. }
  5278. if (shouldNotUpdateFromFragmentBlock) {
  5279. newBlockArr.push(block);
  5280. } else {
  5281. newBlockArr.push(updateHead(block, targetOffset, fragment));
  5282. }
  5283. // Insert fragment blocks after the head and before the tail.
  5284. fragment
  5285. // when we are updating the target block with the head fragment block we skip the first fragment
  5286. // head since its contents have already been merged with the target block otherwise we include
  5287. // the whole fragment
  5288. .slice(shouldNotUpdateFromFragmentBlock ? 0 : 1, fragmentSize - 1).forEach(function (fragmentBlock) {
  5289. return newBlockArr.push(fragmentBlock);
  5290. });
  5291. // update tail
  5292. newBlockArr.push(updateTail(block, targetOffset, fragment));
  5293. });
  5294. var updatedBlockMap = BlockMapBuilder_1.createFromArray(newBlockArr);
  5295. if (isTreeBasedBlockMap) {
  5296. updatedBlockMap = updateBlockMapLinks(updatedBlockMap, blockMap, target, head);
  5297. }
  5298. return contentState.merge({
  5299. blockMap: updatedBlockMap,
  5300. selectionBefore: selectionState,
  5301. selectionAfter: selectionState.merge({
  5302. anchorKey: finalKey,
  5303. anchorOffset: finalOffset,
  5304. focusKey: finalKey,
  5305. focusOffset: finalOffset,
  5306. isBackward: false
  5307. })
  5308. });
  5309. };
  5310. var insertFragmentIntoContentState = function insertFragmentIntoContentState(contentState, selectionState, fragmentBlockMap) {
  5311. !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;
  5312. var blockMap = contentState.getBlockMap();
  5313. var fragment = randomizeBlockMapKeys_1(fragmentBlockMap);
  5314. var targetKey = selectionState.getStartKey();
  5315. var targetOffset = selectionState.getStartOffset();
  5316. var targetBlock = blockMap.get(targetKey);
  5317. if (targetBlock instanceof ContentBlockNode_1) {
  5318. !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;
  5319. }
  5320. // When we insert a fragment with a single block we simply update the target block
  5321. // with the contents of the inserted fragment block
  5322. if (fragment.size === 1) {
  5323. return updateExistingBlock(contentState, selectionState, blockMap, fragment.first(), targetKey, targetOffset);
  5324. }
  5325. return insertFragment(contentState, selectionState, blockMap, fragment, targetKey, targetOffset);
  5326. };
  5327. var insertFragmentIntoContentState_1 = insertFragmentIntoContentState;
  5328. var Repeat$2 = immutable.Repeat;
  5329. function insertTextIntoContentState(contentState, selectionState, text, characterMetadata) {
  5330. !selectionState.isCollapsed() ? process.env.NODE_ENV !== 'production' ? invariant_1(false, '`insertText` should only be called with a collapsed range.') : invariant_1(false) : void 0;
  5331. var len = text.length;
  5332. if (!len) {
  5333. return contentState;
  5334. }
  5335. var blockMap = contentState.getBlockMap();
  5336. var key = selectionState.getStartKey();
  5337. var offset = selectionState.getStartOffset();
  5338. var block = blockMap.get(key);
  5339. var blockText = block.getText();
  5340. var newBlock = block.merge({
  5341. text: blockText.slice(0, offset) + text + blockText.slice(offset, block.getLength()),
  5342. characterList: insertIntoList_1(block.getCharacterList(), Repeat$2(characterMetadata, len).toList(), offset)
  5343. });
  5344. var newOffset = offset + len;
  5345. return contentState.merge({
  5346. blockMap: blockMap.set(key, newBlock),
  5347. selectionAfter: selectionState.merge({
  5348. anchorOffset: newOffset,
  5349. focusOffset: newOffset
  5350. })
  5351. });
  5352. }
  5353. var insertTextIntoContentState_1 = insertTextIntoContentState;
  5354. var Map$4 = immutable.Map;
  5355. function modifyBlockForContentState(contentState, selectionState, operation) {
  5356. var startKey = selectionState.getStartKey();
  5357. var endKey = selectionState.getEndKey();
  5358. var blockMap = contentState.getBlockMap();
  5359. var newBlocks = blockMap.toSeq().skipUntil(function (_, k) {
  5360. return k === startKey;
  5361. }).takeUntil(function (_, k) {
  5362. return k === endKey;
  5363. }).concat(Map$4([[endKey, blockMap.get(endKey)]])).map(operation);
  5364. return contentState.merge({
  5365. blockMap: blockMap.merge(newBlocks),
  5366. selectionBefore: selectionState,
  5367. selectionAfter: selectionState
  5368. });
  5369. }
  5370. var modifyBlockForContentState_1 = modifyBlockForContentState;
  5371. /**
  5372. * Copyright (c) 2013-present, Facebook, Inc.
  5373. * All rights reserved.
  5374. *
  5375. * This source code is licensed under the BSD-style license found in the
  5376. * LICENSE file in the root directory of this source tree. An additional grant
  5377. * of patent rights can be found in the PATENTS file in the same directory.
  5378. *
  5379. * @providesModule getNextDelimiterBlockKey
  5380. * @format
  5381. *
  5382. *
  5383. * This is unstable and not part of the public API and should not be used by
  5384. * production systems. This file may be update/removed without notice.
  5385. */
  5386. var getNextDelimiterBlockKey = function getNextDelimiterBlockKey(block, blockMap) {
  5387. var isExperimentalTreeBlock = block instanceof ContentBlockNode_1;
  5388. if (!isExperimentalTreeBlock) {
  5389. return null;
  5390. }
  5391. var nextSiblingKey = block.getNextSiblingKey();
  5392. if (nextSiblingKey) {
  5393. return nextSiblingKey;
  5394. }
  5395. var parent = block.getParentKey();
  5396. if (!parent) {
  5397. return null;
  5398. }
  5399. var nextNonDescendantBlock = blockMap.get(parent);
  5400. while (nextNonDescendantBlock && !nextNonDescendantBlock.getNextSiblingKey()) {
  5401. var parentKey = nextNonDescendantBlock.getParentKey();
  5402. nextNonDescendantBlock = parentKey ? blockMap.get(parentKey) : null;
  5403. }
  5404. if (!nextNonDescendantBlock) {
  5405. return null;
  5406. }
  5407. return nextNonDescendantBlock.getNextSiblingKey();
  5408. };
  5409. var getNextDelimiterBlockKey_1 = getNextDelimiterBlockKey;
  5410. var List$3 = immutable.List,
  5411. Map$5 = immutable.Map;
  5412. var transformBlock = function transformBlock(key, blockMap, func) {
  5413. if (!key) {
  5414. return;
  5415. }
  5416. var block = blockMap.get(key);
  5417. if (!block) {
  5418. return;
  5419. }
  5420. blockMap.set(key, func(block));
  5421. };
  5422. /**
  5423. * Ancestors needs to be preserved when there are non selected
  5424. * children to make sure we do not leave any orphans behind
  5425. */
  5426. var getAncestorsKeys = function getAncestorsKeys(blockKey, blockMap) {
  5427. var parents = [];
  5428. if (!blockKey) {
  5429. return parents;
  5430. }
  5431. var blockNode = blockMap.get(blockKey);
  5432. while (blockNode && blockNode.getParentKey()) {
  5433. var parentKey = blockNode.getParentKey();
  5434. if (parentKey) {
  5435. parents.push(parentKey);
  5436. }
  5437. blockNode = parentKey ? blockMap.get(parentKey) : null;
  5438. }
  5439. return parents;
  5440. };
  5441. /**
  5442. * Get all next delimiter keys until we hit a root delimiter and return
  5443. * an array of key references
  5444. */
  5445. var getNextDelimitersBlockKeys = function getNextDelimitersBlockKeys(block, blockMap) {
  5446. var nextDelimiters = [];
  5447. if (!block) {
  5448. return nextDelimiters;
  5449. }
  5450. var nextDelimiter = getNextDelimiterBlockKey_1(block, blockMap);
  5451. while (nextDelimiter && blockMap.get(nextDelimiter)) {
  5452. var _block = blockMap.get(nextDelimiter);
  5453. nextDelimiters.push(nextDelimiter);
  5454. // we do not need to keep checking all root node siblings, just the first occurance
  5455. nextDelimiter = _block.getParentKey() ? getNextDelimiterBlockKey_1(_block, blockMap) : null;
  5456. }
  5457. return nextDelimiters;
  5458. };
  5459. var getNextValidSibling = function getNextValidSibling(block, blockMap, originalBlockMap) {
  5460. if (!block) {
  5461. return null;
  5462. }
  5463. // note that we need to make sure we refer to the original block since this
  5464. // function is called within a withMutations
  5465. var nextValidSiblingKey = originalBlockMap.get(block.getKey()).getNextSiblingKey();
  5466. while (nextValidSiblingKey && !blockMap.get(nextValidSiblingKey)) {
  5467. nextValidSiblingKey = originalBlockMap.get(nextValidSiblingKey).getNextSiblingKey() || null;
  5468. }
  5469. return nextValidSiblingKey;
  5470. };
  5471. var getPrevValidSibling = function getPrevValidSibling(block, blockMap, originalBlockMap) {
  5472. if (!block) {
  5473. return null;
  5474. }
  5475. // note that we need to make sure we refer to the original block since this
  5476. // function is called within a withMutations
  5477. var prevValidSiblingKey = originalBlockMap.get(block.getKey()).getPrevSiblingKey();
  5478. while (prevValidSiblingKey && !blockMap.get(prevValidSiblingKey)) {
  5479. prevValidSiblingKey = originalBlockMap.get(prevValidSiblingKey).getPrevSiblingKey() || null;
  5480. }
  5481. return prevValidSiblingKey;
  5482. };
  5483. var updateBlockMapLinks$1 = function updateBlockMapLinks(blockMap, startBlock, endBlock, originalBlockMap) {
  5484. return blockMap.withMutations(function (blocks) {
  5485. // update start block if its retained
  5486. transformBlock(startBlock.getKey(), blocks, function (block) {
  5487. return block.merge({
  5488. nextSibling: getNextValidSibling(startBlock, blocks, originalBlockMap),
  5489. prevSibling: getPrevValidSibling(startBlock, blocks, originalBlockMap)
  5490. });
  5491. });
  5492. // update endblock if its retained
  5493. transformBlock(endBlock.getKey(), blocks, function (block) {
  5494. return block.merge({
  5495. nextSibling: getNextValidSibling(endBlock, blocks, originalBlockMap),
  5496. prevSibling: getPrevValidSibling(endBlock, blocks, originalBlockMap)
  5497. });
  5498. });
  5499. // update start block parent ancestors
  5500. getAncestorsKeys(startBlock.getKey(), originalBlockMap).forEach(function (parentKey) {
  5501. return transformBlock(parentKey, blocks, function (block) {
  5502. return block.merge({
  5503. children: block.getChildKeys().filter(function (key) {
  5504. return blocks.get(key);
  5505. }),
  5506. nextSibling: getNextValidSibling(block, blocks, originalBlockMap),
  5507. prevSibling: getPrevValidSibling(block, blocks, originalBlockMap)
  5508. });
  5509. });
  5510. });
  5511. // update start block next - can only happen if startBlock == endBlock
  5512. transformBlock(startBlock.getNextSiblingKey(), blocks, function (block) {
  5513. return block.merge({
  5514. prevSibling: startBlock.getPrevSiblingKey()
  5515. });
  5516. });
  5517. // update start block prev
  5518. transformBlock(startBlock.getPrevSiblingKey(), blocks, function (block) {
  5519. return block.merge({
  5520. nextSibling: getNextValidSibling(startBlock, blocks, originalBlockMap)
  5521. });
  5522. });
  5523. // update end block next
  5524. transformBlock(endBlock.getNextSiblingKey(), blocks, function (block) {
  5525. return block.merge({
  5526. prevSibling: getPrevValidSibling(endBlock, blocks, originalBlockMap)
  5527. });
  5528. });
  5529. // update end block prev
  5530. transformBlock(endBlock.getPrevSiblingKey(), blocks, function (block) {
  5531. return block.merge({
  5532. nextSibling: endBlock.getNextSiblingKey()
  5533. });
  5534. });
  5535. // update end block parent ancestors
  5536. getAncestorsKeys(endBlock.getKey(), originalBlockMap).forEach(function (parentKey) {
  5537. transformBlock(parentKey, blocks, function (block) {
  5538. return block.merge({
  5539. children: block.getChildKeys().filter(function (key) {
  5540. return blocks.get(key);
  5541. }),
  5542. nextSibling: getNextValidSibling(block, blocks, originalBlockMap),
  5543. prevSibling: getPrevValidSibling(block, blocks, originalBlockMap)
  5544. });
  5545. });
  5546. });
  5547. // update next delimiters all the way to a root delimiter
  5548. getNextDelimitersBlockKeys(endBlock, originalBlockMap).forEach(function (delimiterKey) {
  5549. return transformBlock(delimiterKey, blocks, function (block) {
  5550. return block.merge({
  5551. nextSibling: getNextValidSibling(block, blocks, originalBlockMap),
  5552. prevSibling: getPrevValidSibling(block, blocks, originalBlockMap)
  5553. });
  5554. });
  5555. });
  5556. });
  5557. };
  5558. var removeRangeFromContentState = function removeRangeFromContentState(contentState, selectionState) {
  5559. if (selectionState.isCollapsed()) {
  5560. return contentState;
  5561. }
  5562. var blockMap = contentState.getBlockMap();
  5563. var startKey = selectionState.getStartKey();
  5564. var startOffset = selectionState.getStartOffset();
  5565. var endKey = selectionState.getEndKey();
  5566. var endOffset = selectionState.getEndOffset();
  5567. var startBlock = blockMap.get(startKey);
  5568. var endBlock = blockMap.get(endKey);
  5569. // we assume that ContentBlockNode and ContentBlocks are not mixed together
  5570. var isExperimentalTreeBlock = startBlock instanceof ContentBlockNode_1;
  5571. // used to retain blocks that should not be deleted to avoid orphan children
  5572. var parentAncestors = [];
  5573. if (isExperimentalTreeBlock) {
  5574. var endBlockchildrenKeys = endBlock.getChildKeys();
  5575. var endBlockAncestors = getAncestorsKeys(endKey, blockMap);
  5576. // endBlock has unselected sibblings so we can not remove its ancestors parents
  5577. if (endBlock.getNextSiblingKey()) {
  5578. parentAncestors = parentAncestors.concat(endBlockAncestors);
  5579. }
  5580. // endBlock has children so can not remove this block or any of its ancestors
  5581. if (!endBlockchildrenKeys.isEmpty()) {
  5582. parentAncestors = parentAncestors.concat(endBlockAncestors.concat([endKey]));
  5583. }
  5584. // we need to retain all ancestors of the next delimiter block
  5585. parentAncestors = parentAncestors.concat(getAncestorsKeys(getNextDelimiterBlockKey_1(endBlock, blockMap), blockMap));
  5586. }
  5587. var characterList = void 0;
  5588. if (startBlock === endBlock) {
  5589. characterList = removeFromList(startBlock.getCharacterList(), startOffset, endOffset);
  5590. } else {
  5591. characterList = startBlock.getCharacterList().slice(0, startOffset).concat(endBlock.getCharacterList().slice(endOffset));
  5592. }
  5593. var modifiedStart = startBlock.merge({
  5594. text: startBlock.getText().slice(0, startOffset) + endBlock.getText().slice(endOffset),
  5595. characterList: characterList
  5596. });
  5597. var newBlocks = blockMap.toSeq().skipUntil(function (_, k) {
  5598. return k === startKey;
  5599. }).takeUntil(function (_, k) {
  5600. return k === endKey;
  5601. }).filter(function (_, k) {
  5602. return parentAncestors.indexOf(k) === -1;
  5603. }).concat(Map$5([[endKey, null]])).map(function (_, k) {
  5604. return k === startKey ? modifiedStart : null;
  5605. });
  5606. var updatedBlockMap = blockMap.merge(newBlocks).filter(function (block) {
  5607. return !!block;
  5608. });
  5609. if (isExperimentalTreeBlock) {
  5610. updatedBlockMap = updateBlockMapLinks$1(updatedBlockMap, startBlock, endBlock, blockMap);
  5611. }
  5612. return contentState.merge({
  5613. blockMap: updatedBlockMap,
  5614. selectionBefore: selectionState,
  5615. selectionAfter: selectionState.merge({
  5616. anchorKey: startKey,
  5617. anchorOffset: startOffset,
  5618. focusKey: startKey,
  5619. focusOffset: startOffset,
  5620. isBackward: false
  5621. })
  5622. });
  5623. };
  5624. /**
  5625. * Maintain persistence for target list when removing characters on the
  5626. * head and tail of the character list.
  5627. */
  5628. var removeFromList = function removeFromList(targetList, startOffset, endOffset) {
  5629. if (startOffset === 0) {
  5630. while (startOffset < endOffset) {
  5631. targetList = targetList.shift();
  5632. startOffset++;
  5633. }
  5634. } else if (endOffset === targetList.count()) {
  5635. while (endOffset > startOffset) {
  5636. targetList = targetList.pop();
  5637. endOffset--;
  5638. }
  5639. } else {
  5640. var head = targetList.slice(0, startOffset);
  5641. var tail = targetList.slice(endOffset);
  5642. targetList = head.concat(tail).toList();
  5643. }
  5644. return targetList;
  5645. };
  5646. var removeRangeFromContentState_1 = removeRangeFromContentState;
  5647. var List$4 = immutable.List,
  5648. Map$6 = immutable.Map;
  5649. var transformBlock$1 = function transformBlock(key, blockMap, func) {
  5650. if (!key) {
  5651. return;
  5652. }
  5653. var block = blockMap.get(key);
  5654. if (!block) {
  5655. return;
  5656. }
  5657. blockMap.set(key, func(block));
  5658. };
  5659. var updateBlockMapLinks$2 = function updateBlockMapLinks(blockMap, originalBlock, belowBlock) {
  5660. return blockMap.withMutations(function (blocks) {
  5661. var originalBlockKey = originalBlock.getKey();
  5662. var belowBlockKey = belowBlock.getKey();
  5663. // update block parent
  5664. transformBlock$1(originalBlock.getParentKey(), blocks, function (block) {
  5665. var parentChildrenList = block.getChildKeys();
  5666. var insertionIndex = parentChildrenList.indexOf(originalBlockKey) + 1;
  5667. var newChildrenArray = parentChildrenList.toArray();
  5668. newChildrenArray.splice(insertionIndex, 0, belowBlockKey);
  5669. return block.merge({
  5670. children: List$4(newChildrenArray)
  5671. });
  5672. });
  5673. // update original next block
  5674. transformBlock$1(originalBlock.getNextSiblingKey(), blocks, function (block) {
  5675. return block.merge({
  5676. prevSibling: belowBlockKey
  5677. });
  5678. });
  5679. // update original block
  5680. transformBlock$1(originalBlockKey, blocks, function (block) {
  5681. return block.merge({
  5682. nextSibling: belowBlockKey
  5683. });
  5684. });
  5685. // update below block
  5686. transformBlock$1(belowBlockKey, blocks, function (block) {
  5687. return block.merge({
  5688. prevSibling: originalBlockKey
  5689. });
  5690. });
  5691. });
  5692. };
  5693. var splitBlockInContentState = function splitBlockInContentState(contentState, selectionState) {
  5694. !selectionState.isCollapsed() ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Selection range must be collapsed.') : invariant_1(false) : void 0;
  5695. var key = selectionState.getAnchorKey();
  5696. var offset = selectionState.getAnchorOffset();
  5697. var blockMap = contentState.getBlockMap();
  5698. var blockToSplit = blockMap.get(key);
  5699. var text = blockToSplit.getText();
  5700. var chars = blockToSplit.getCharacterList();
  5701. var keyBelow = generateRandomKey_1();
  5702. var isExperimentalTreeBlock = blockToSplit instanceof ContentBlockNode_1;
  5703. var blockAbove = blockToSplit.merge({
  5704. text: text.slice(0, offset),
  5705. characterList: chars.slice(0, offset)
  5706. });
  5707. var blockBelow = blockAbove.merge({
  5708. key: keyBelow,
  5709. text: text.slice(offset),
  5710. characterList: chars.slice(offset),
  5711. data: Map$6()
  5712. });
  5713. var blocksBefore = blockMap.toSeq().takeUntil(function (v) {
  5714. return v === blockToSplit;
  5715. });
  5716. var blocksAfter = blockMap.toSeq().skipUntil(function (v) {
  5717. return v === blockToSplit;
  5718. }).rest();
  5719. var newBlocks = blocksBefore.concat([[key, blockAbove], [keyBelow, blockBelow]], blocksAfter).toOrderedMap();
  5720. if (isExperimentalTreeBlock) {
  5721. !blockToSplit.getChildKeys().isEmpty() ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'ContentBlockNode must not have children') : invariant_1(false) : void 0;
  5722. newBlocks = updateBlockMapLinks$2(newBlocks, blockAbove, blockBelow);
  5723. }
  5724. return contentState.merge({
  5725. blockMap: newBlocks,
  5726. selectionBefore: selectionState,
  5727. selectionAfter: selectionState.merge({
  5728. anchorKey: keyBelow,
  5729. anchorOffset: 0,
  5730. focusKey: keyBelow,
  5731. focusOffset: 0,
  5732. isBackward: false
  5733. })
  5734. });
  5735. };
  5736. var splitBlockInContentState_1 = splitBlockInContentState;
  5737. var OrderedSet$3 = immutable.OrderedSet;
  5738. /**
  5739. * `DraftModifier` provides a set of convenience methods that apply
  5740. * modifications to a `ContentState` object based on a target `SelectionState`.
  5741. *
  5742. * Any change to a `ContentState` should be decomposable into a series of
  5743. * transaction functions that apply the required changes and return output
  5744. * `ContentState` objects.
  5745. *
  5746. * These functions encapsulate some of the most common transaction sequences.
  5747. */
  5748. var DraftModifier = {
  5749. replaceText: function replaceText(contentState, rangeToReplace, text, inlineStyle, entityKey) {
  5750. var withoutEntities = removeEntitiesAtEdges_1(contentState, rangeToReplace);
  5751. var withoutText = removeRangeFromContentState_1(withoutEntities, rangeToReplace);
  5752. var character = CharacterMetadata_1.create({
  5753. style: inlineStyle || OrderedSet$3(),
  5754. entity: entityKey || null
  5755. });
  5756. return insertTextIntoContentState_1(withoutText, withoutText.getSelectionAfter(), text, character);
  5757. },
  5758. insertText: function insertText(contentState, targetRange, text, inlineStyle, entityKey) {
  5759. !targetRange.isCollapsed() ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Target range must be collapsed for `insertText`.') : invariant_1(false) : void 0;
  5760. return DraftModifier.replaceText(contentState, targetRange, text, inlineStyle, entityKey);
  5761. },
  5762. moveText: function moveText(contentState, removalRange, targetRange) {
  5763. var movedFragment = getContentStateFragment_1(contentState, removalRange);
  5764. var afterRemoval = DraftModifier.removeRange(contentState, removalRange, 'backward');
  5765. return DraftModifier.replaceWithFragment(afterRemoval, targetRange, movedFragment);
  5766. },
  5767. replaceWithFragment: function replaceWithFragment(contentState, targetRange, fragment) {
  5768. var withoutEntities = removeEntitiesAtEdges_1(contentState, targetRange);
  5769. var withoutText = removeRangeFromContentState_1(withoutEntities, targetRange);
  5770. return insertFragmentIntoContentState_1(withoutText, withoutText.getSelectionAfter(), fragment);
  5771. },
  5772. removeRange: function removeRange(contentState, rangeToRemove, removalDirection) {
  5773. var startKey = void 0,
  5774. endKey = void 0,
  5775. startBlock = void 0,
  5776. endBlock = void 0;
  5777. if (rangeToRemove.getIsBackward()) {
  5778. rangeToRemove = rangeToRemove.merge({
  5779. anchorKey: rangeToRemove.getFocusKey(),
  5780. anchorOffset: rangeToRemove.getFocusOffset(),
  5781. focusKey: rangeToRemove.getAnchorKey(),
  5782. focusOffset: rangeToRemove.getAnchorOffset(),
  5783. isBackward: false
  5784. });
  5785. }
  5786. startKey = rangeToRemove.getAnchorKey();
  5787. endKey = rangeToRemove.getFocusKey();
  5788. startBlock = contentState.getBlockForKey(startKey);
  5789. endBlock = contentState.getBlockForKey(endKey);
  5790. var startOffset = rangeToRemove.getStartOffset();
  5791. var endOffset = rangeToRemove.getEndOffset();
  5792. var startEntityKey = startBlock.getEntityAt(startOffset);
  5793. var endEntityKey = endBlock.getEntityAt(endOffset - 1);
  5794. // Check whether the selection state overlaps with a single entity.
  5795. // If so, try to remove the appropriate substring of the entity text.
  5796. if (startKey === endKey) {
  5797. if (startEntityKey && startEntityKey === endEntityKey) {
  5798. var _adjustedRemovalRange = getCharacterRemovalRange_1(contentState.getEntityMap(), startBlock, endBlock, rangeToRemove, removalDirection);
  5799. return removeRangeFromContentState_1(contentState, _adjustedRemovalRange);
  5800. }
  5801. }
  5802. var adjustedRemovalRange = rangeToRemove;
  5803. var withoutEntities = removeEntitiesAtEdges_1(contentState, adjustedRemovalRange);
  5804. return removeRangeFromContentState_1(withoutEntities, adjustedRemovalRange);
  5805. },
  5806. splitBlock: function splitBlock(contentState, selectionState) {
  5807. var withoutEntities = removeEntitiesAtEdges_1(contentState, selectionState);
  5808. var withoutText = removeRangeFromContentState_1(withoutEntities, selectionState);
  5809. return splitBlockInContentState_1(withoutText, withoutText.getSelectionAfter());
  5810. },
  5811. applyInlineStyle: function applyInlineStyle(contentState, selectionState, inlineStyle) {
  5812. return ContentStateInlineStyle_1.add(contentState, selectionState, inlineStyle);
  5813. },
  5814. removeInlineStyle: function removeInlineStyle(contentState, selectionState, inlineStyle) {
  5815. return ContentStateInlineStyle_1.remove(contentState, selectionState, inlineStyle);
  5816. },
  5817. setBlockType: function setBlockType(contentState, selectionState, blockType) {
  5818. return modifyBlockForContentState_1(contentState, selectionState, function (block) {
  5819. return block.merge({ type: blockType, depth: 0 });
  5820. });
  5821. },
  5822. setBlockData: function setBlockData(contentState, selectionState, blockData) {
  5823. return modifyBlockForContentState_1(contentState, selectionState, function (block) {
  5824. return block.merge({ data: blockData });
  5825. });
  5826. },
  5827. mergeBlockData: function mergeBlockData(contentState, selectionState, blockData) {
  5828. return modifyBlockForContentState_1(contentState, selectionState, function (block) {
  5829. return block.merge({ data: block.getData().merge(blockData) });
  5830. });
  5831. },
  5832. applyEntity: function applyEntity(contentState, selectionState, entityKey) {
  5833. var withoutEntities = removeEntitiesAtEdges_1(contentState, selectionState);
  5834. return applyEntityToContentState_1(withoutEntities, selectionState, entityKey);
  5835. }
  5836. };
  5837. var DraftModifier_1 = DraftModifier;
  5838. /**
  5839. * Copyright (c) 2013-present, Facebook, Inc.
  5840. *
  5841. * This source code is licensed under the MIT license found in the
  5842. * LICENSE file in the root directory of this source tree.
  5843. *
  5844. *
  5845. */
  5846. function makeEmptyFunction(arg) {
  5847. return function () {
  5848. return arg;
  5849. };
  5850. }
  5851. /**
  5852. * This function accepts and discards inputs; it has no side effects. This is
  5853. * primarily useful idiomatically for overridable function endpoints which
  5854. * always need to be callable, since JS lacks a null-call idiom ala Cocoa.
  5855. */
  5856. var emptyFunction = function emptyFunction() {};
  5857. emptyFunction.thatReturns = makeEmptyFunction;
  5858. emptyFunction.thatReturnsFalse = makeEmptyFunction(false);
  5859. emptyFunction.thatReturnsTrue = makeEmptyFunction(true);
  5860. emptyFunction.thatReturnsNull = makeEmptyFunction(null);
  5861. emptyFunction.thatReturnsThis = function () {
  5862. return this;
  5863. };
  5864. emptyFunction.thatReturnsArgument = function (arg) {
  5865. return arg;
  5866. };
  5867. var emptyFunction_1 = emptyFunction;
  5868. var List$5 = immutable.List,
  5869. Repeat$3 = immutable.Repeat,
  5870. Record$3 = immutable.Record;
  5871. var returnTrue = emptyFunction_1.thatReturnsTrue;
  5872. var FINGERPRINT_DELIMITER = '-';
  5873. var defaultLeafRange = {
  5874. start: null,
  5875. end: null
  5876. };
  5877. var LeafRange = Record$3(defaultLeafRange);
  5878. var defaultDecoratorRange = {
  5879. start: null,
  5880. end: null,
  5881. decoratorKey: null,
  5882. leaves: null
  5883. };
  5884. var DecoratorRange = Record$3(defaultDecoratorRange);
  5885. var BlockTree = {
  5886. /**
  5887. * Generate a block tree for a given ContentBlock/decorator pair.
  5888. */
  5889. generate: function generate(contentState, block, decorator) {
  5890. var textLength = block.getLength();
  5891. if (!textLength) {
  5892. return List$5.of(new DecoratorRange({
  5893. start: 0,
  5894. end: 0,
  5895. decoratorKey: null,
  5896. leaves: List$5.of(new LeafRange({ start: 0, end: 0 }))
  5897. }));
  5898. }
  5899. var leafSets = [];
  5900. var decorations = decorator ? decorator.getDecorations(block, contentState) : List$5(Repeat$3(null, textLength));
  5901. var chars = block.getCharacterList();
  5902. findRangesImmutable_1(decorations, areEqual, returnTrue, function (start, end) {
  5903. leafSets.push(new DecoratorRange({
  5904. start: start,
  5905. end: end,
  5906. decoratorKey: decorations.get(start),
  5907. leaves: generateLeaves(chars.slice(start, end).toList(), start)
  5908. }));
  5909. });
  5910. return List$5(leafSets);
  5911. },
  5912. /**
  5913. * Create a string representation of the given tree map. This allows us
  5914. * to rapidly determine whether a tree has undergone a significant
  5915. * structural change.
  5916. */
  5917. getFingerprint: function getFingerprint(tree) {
  5918. return tree.map(function (leafSet) {
  5919. var decoratorKey = leafSet.get('decoratorKey');
  5920. var fingerprintString = decoratorKey !== null ? decoratorKey + '.' + (leafSet.get('end') - leafSet.get('start')) : '';
  5921. return '' + fingerprintString + '.' + leafSet.get('leaves').size;
  5922. }).join(FINGERPRINT_DELIMITER);
  5923. }
  5924. };
  5925. /**
  5926. * Generate LeafRange records for a given character list.
  5927. */
  5928. function generateLeaves(characters, offset) {
  5929. var leaves = [];
  5930. var inlineStyles = characters.map(function (c) {
  5931. return c.getStyle();
  5932. }).toList();
  5933. findRangesImmutable_1(inlineStyles, areEqual, returnTrue, function (start, end) {
  5934. leaves.push(new LeafRange({
  5935. start: start + offset,
  5936. end: end + offset
  5937. }));
  5938. });
  5939. return List$5(leaves);
  5940. }
  5941. function areEqual(a, b) {
  5942. return a === b;
  5943. }
  5944. var BlockTree_1 = BlockTree;
  5945. function _classCallCheck$3(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5946. 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; }
  5947. 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; }
  5948. var Record$4 = immutable.Record;
  5949. var DraftEntityInstanceRecord = Record$4({
  5950. type: 'TOKEN',
  5951. mutability: 'IMMUTABLE',
  5952. data: Object
  5953. });
  5954. /**
  5955. * An instance of a document entity, consisting of a `type` and relevant
  5956. * `data`, metadata about the entity.
  5957. *
  5958. * For instance, a "link" entity might provide a URI, and a "mention"
  5959. * entity might provide the mentioned user's ID. These pieces of data
  5960. * may be used when rendering the entity as part of a ContentBlock DOM
  5961. * representation. For a link, the data would be used as an href for
  5962. * the rendered anchor. For a mention, the ID could be used to retrieve
  5963. * a hovercard.
  5964. */
  5965. var DraftEntityInstance = function (_DraftEntityInstanceR) {
  5966. _inherits$3(DraftEntityInstance, _DraftEntityInstanceR);
  5967. function DraftEntityInstance() {
  5968. _classCallCheck$3(this, DraftEntityInstance);
  5969. return _possibleConstructorReturn$3(this, _DraftEntityInstanceR.apply(this, arguments));
  5970. }
  5971. DraftEntityInstance.prototype.getType = function getType() {
  5972. return this.get('type');
  5973. };
  5974. DraftEntityInstance.prototype.getMutability = function getMutability() {
  5975. return this.get('mutability');
  5976. };
  5977. DraftEntityInstance.prototype.getData = function getData() {
  5978. return this.get('data');
  5979. };
  5980. return DraftEntityInstance;
  5981. }(DraftEntityInstanceRecord);
  5982. var DraftEntityInstance_1 = DraftEntityInstance;
  5983. 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; };
  5984. /**
  5985. * Copyright (c) 2013-present, Facebook, Inc.
  5986. * All rights reserved.
  5987. *
  5988. * This source code is licensed under the BSD-style license found in the
  5989. * LICENSE file in the root directory of this source tree. An additional grant
  5990. * of patent rights can be found in the PATENTS file in the same directory.
  5991. *
  5992. * @providesModule DraftEntity
  5993. * @format
  5994. *
  5995. */
  5996. var Map$7 = immutable.Map;
  5997. var instances = Map$7();
  5998. var instanceKey = 0;
  5999. /**
  6000. * Temporary utility for generating the warnings
  6001. */
  6002. function logWarning(oldMethodCall, newMethodCall) {
  6003. console.warn('WARNING: ' + oldMethodCall + ' will be deprecated soon!\nPlease use "' + newMethodCall + '" instead.');
  6004. }
  6005. /**
  6006. * A "document entity" is an object containing metadata associated with a
  6007. * piece of text in a ContentBlock.
  6008. *
  6009. * For example, a `link` entity might include a `uri` property. When a
  6010. * ContentBlock is rendered in the browser, text that refers to that link
  6011. * entity may be rendered as an anchor, with the `uri` as the href value.
  6012. *
  6013. * In a ContentBlock, every position in the text may correspond to zero
  6014. * or one entities. This correspondence is tracked using a key string,
  6015. * generated via DraftEntity.create() and used to obtain entity metadata
  6016. * via DraftEntity.get().
  6017. */
  6018. var DraftEntity = {
  6019. /**
  6020. * WARNING: This method will be deprecated soon!
  6021. * Please use 'contentState.getLastCreatedEntityKey' instead.
  6022. * ---
  6023. * Get the random key string from whatever entity was last created.
  6024. * We need this to support the new API, as part of transitioning to put Entity
  6025. * storage in contentState.
  6026. */
  6027. getLastCreatedEntityKey: function getLastCreatedEntityKey() {
  6028. logWarning('DraftEntity.getLastCreatedEntityKey', 'contentState.getLastCreatedEntityKey');
  6029. return DraftEntity.__getLastCreatedEntityKey();
  6030. },
  6031. /**
  6032. * WARNING: This method will be deprecated soon!
  6033. * Please use 'contentState.createEntity' instead.
  6034. * ---
  6035. * Create a DraftEntityInstance and store it for later retrieval.
  6036. *
  6037. * A random key string will be generated and returned. This key may
  6038. * be used to track the entity's usage in a ContentBlock, and for
  6039. * retrieving data about the entity at render time.
  6040. */
  6041. create: function create(type, mutability, data) {
  6042. logWarning('DraftEntity.create', 'contentState.createEntity');
  6043. return DraftEntity.__create(type, mutability, data);
  6044. },
  6045. /**
  6046. * WARNING: This method will be deprecated soon!
  6047. * Please use 'contentState.addEntity' instead.
  6048. * ---
  6049. * Add an existing DraftEntityInstance to the DraftEntity map. This is
  6050. * useful when restoring instances from the server.
  6051. */
  6052. add: function add(instance) {
  6053. logWarning('DraftEntity.add', 'contentState.addEntity');
  6054. return DraftEntity.__add(instance);
  6055. },
  6056. /**
  6057. * WARNING: This method will be deprecated soon!
  6058. * Please use 'contentState.getEntity' instead.
  6059. * ---
  6060. * Retrieve the entity corresponding to the supplied key string.
  6061. */
  6062. get: function get(key) {
  6063. logWarning('DraftEntity.get', 'contentState.getEntity');
  6064. return DraftEntity.__get(key);
  6065. },
  6066. /**
  6067. * WARNING: This method will be deprecated soon!
  6068. * Please use 'contentState.mergeEntityData' instead.
  6069. * ---
  6070. * Entity instances are immutable. If you need to update the data for an
  6071. * instance, this method will merge your data updates and return a new
  6072. * instance.
  6073. */
  6074. mergeData: function mergeData(key, toMerge) {
  6075. logWarning('DraftEntity.mergeData', 'contentState.mergeEntityData');
  6076. return DraftEntity.__mergeData(key, toMerge);
  6077. },
  6078. /**
  6079. * WARNING: This method will be deprecated soon!
  6080. * Please use 'contentState.replaceEntityData' instead.
  6081. * ---
  6082. * Completely replace the data for a given instance.
  6083. */
  6084. replaceData: function replaceData(key, newData) {
  6085. logWarning('DraftEntity.replaceData', 'contentState.replaceEntityData');
  6086. return DraftEntity.__replaceData(key, newData);
  6087. },
  6088. // ***********************************WARNING******************************
  6089. // --- the above public API will be deprecated in the next version of Draft!
  6090. // The methods below this line are private - don't call them directly.
  6091. /**
  6092. * Get the random key string from whatever entity was last created.
  6093. * We need this to support the new API, as part of transitioning to put Entity
  6094. * storage in contentState.
  6095. */
  6096. __getLastCreatedEntityKey: function __getLastCreatedEntityKey() {
  6097. return '' + instanceKey;
  6098. },
  6099. /**
  6100. * Create a DraftEntityInstance and store it for later retrieval.
  6101. *
  6102. * A random key string will be generated and returned. This key may
  6103. * be used to track the entity's usage in a ContentBlock, and for
  6104. * retrieving data about the entity at render time.
  6105. */
  6106. __create: function __create(type, mutability, data) {
  6107. return DraftEntity.__add(new DraftEntityInstance_1({ type: type, mutability: mutability, data: data || {} }));
  6108. },
  6109. /**
  6110. * Add an existing DraftEntityInstance to the DraftEntity map. This is
  6111. * useful when restoring instances from the server.
  6112. */
  6113. __add: function __add(instance) {
  6114. var key = '' + ++instanceKey;
  6115. instances = instances.set(key, instance);
  6116. return key;
  6117. },
  6118. /**
  6119. * Retrieve the entity corresponding to the supplied key string.
  6120. */
  6121. __get: function __get(key) {
  6122. var instance = instances.get(key);
  6123. !!!instance ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Unknown DraftEntity key: %s.', key) : invariant_1(false) : void 0;
  6124. return instance;
  6125. },
  6126. /**
  6127. * Entity instances are immutable. If you need to update the data for an
  6128. * instance, this method will merge your data updates and return a new
  6129. * instance.
  6130. */
  6131. __mergeData: function __mergeData(key, toMerge) {
  6132. var instance = DraftEntity.__get(key);
  6133. var newData = _extends({}, instance.getData(), toMerge);
  6134. var newInstance = instance.set('data', newData);
  6135. instances = instances.set(key, newInstance);
  6136. return newInstance;
  6137. },
  6138. /**
  6139. * Completely replace the data for a given instance.
  6140. */
  6141. __replaceData: function __replaceData(key, newData) {
  6142. var instance = DraftEntity.__get(key);
  6143. var newInstance = instance.set('data', newData);
  6144. instances = instances.set(key, newInstance);
  6145. return newInstance;
  6146. }
  6147. };
  6148. var DraftEntity_1 = DraftEntity;
  6149. function _classCallCheck$4(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6150. 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; }
  6151. 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; }
  6152. var Record$5 = immutable.Record;
  6153. var defaultRecord$3 = {
  6154. anchorKey: '',
  6155. anchorOffset: 0,
  6156. focusKey: '',
  6157. focusOffset: 0,
  6158. isBackward: false,
  6159. hasFocus: false
  6160. };
  6161. var SelectionStateRecord = Record$5(defaultRecord$3);
  6162. var SelectionState = function (_SelectionStateRecord) {
  6163. _inherits$4(SelectionState, _SelectionStateRecord);
  6164. function SelectionState() {
  6165. _classCallCheck$4(this, SelectionState);
  6166. return _possibleConstructorReturn$4(this, _SelectionStateRecord.apply(this, arguments));
  6167. }
  6168. SelectionState.prototype.serialize = function serialize() {
  6169. return 'Anchor: ' + this.getAnchorKey() + ':' + this.getAnchorOffset() + ', ' + 'Focus: ' + this.getFocusKey() + ':' + this.getFocusOffset() + ', ' + 'Is Backward: ' + String(this.getIsBackward()) + ', ' + 'Has Focus: ' + String(this.getHasFocus());
  6170. };
  6171. SelectionState.prototype.getAnchorKey = function getAnchorKey() {
  6172. return this.get('anchorKey');
  6173. };
  6174. SelectionState.prototype.getAnchorOffset = function getAnchorOffset() {
  6175. return this.get('anchorOffset');
  6176. };
  6177. SelectionState.prototype.getFocusKey = function getFocusKey() {
  6178. return this.get('focusKey');
  6179. };
  6180. SelectionState.prototype.getFocusOffset = function getFocusOffset() {
  6181. return this.get('focusOffset');
  6182. };
  6183. SelectionState.prototype.getIsBackward = function getIsBackward() {
  6184. return this.get('isBackward');
  6185. };
  6186. SelectionState.prototype.getHasFocus = function getHasFocus() {
  6187. return this.get('hasFocus');
  6188. };
  6189. /**
  6190. * Return whether the specified range overlaps with an edge of the
  6191. * SelectionState.
  6192. */
  6193. SelectionState.prototype.hasEdgeWithin = function hasEdgeWithin(blockKey, start, end) {
  6194. var anchorKey = this.getAnchorKey();
  6195. var focusKey = this.getFocusKey();
  6196. if (anchorKey === focusKey && anchorKey === blockKey) {
  6197. var selectionStart = this.getStartOffset();
  6198. var selectionEnd = this.getEndOffset();
  6199. return start <= selectionEnd && selectionStart <= end;
  6200. }
  6201. if (blockKey !== anchorKey && blockKey !== focusKey) {
  6202. return false;
  6203. }
  6204. var offsetToCheck = blockKey === anchorKey ? this.getAnchorOffset() : this.getFocusOffset();
  6205. return start <= offsetToCheck && end >= offsetToCheck;
  6206. };
  6207. SelectionState.prototype.isCollapsed = function isCollapsed() {
  6208. return this.getAnchorKey() === this.getFocusKey() && this.getAnchorOffset() === this.getFocusOffset();
  6209. };
  6210. SelectionState.prototype.getStartKey = function getStartKey() {
  6211. return this.getIsBackward() ? this.getFocusKey() : this.getAnchorKey();
  6212. };
  6213. SelectionState.prototype.getStartOffset = function getStartOffset() {
  6214. return this.getIsBackward() ? this.getFocusOffset() : this.getAnchorOffset();
  6215. };
  6216. SelectionState.prototype.getEndKey = function getEndKey() {
  6217. return this.getIsBackward() ? this.getAnchorKey() : this.getFocusKey();
  6218. };
  6219. SelectionState.prototype.getEndOffset = function getEndOffset() {
  6220. return this.getIsBackward() ? this.getAnchorOffset() : this.getFocusOffset();
  6221. };
  6222. SelectionState.createEmpty = function createEmpty(key) {
  6223. return new SelectionState({
  6224. anchorKey: key,
  6225. anchorOffset: 0,
  6226. focusKey: key,
  6227. focusOffset: 0,
  6228. isBackward: false,
  6229. hasFocus: false
  6230. });
  6231. };
  6232. return SelectionState;
  6233. }(SelectionStateRecord);
  6234. var SelectionState_1 = SelectionState;
  6235. /**
  6236. * Copyright (c) 2013-present, Facebook, Inc.
  6237. * All rights reserved.
  6238. *
  6239. * This source code is licensed under the BSD-style license found in the
  6240. * LICENSE file in the root directory of this source tree. An additional grant
  6241. * of patent rights can be found in the PATENTS file in the same directory.
  6242. *
  6243. * @providesModule sanitizeDraftText
  6244. * @format
  6245. *
  6246. */
  6247. var REGEX_BLOCK_DELIMITER = new RegExp('\r', 'g');
  6248. function sanitizeDraftText(input) {
  6249. return input.replace(REGEX_BLOCK_DELIMITER, '');
  6250. }
  6251. var sanitizeDraftText_1 = sanitizeDraftText;
  6252. function _classCallCheck$5(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6253. 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; }
  6254. 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; }
  6255. var List$6 = immutable.List,
  6256. Record$6 = immutable.Record,
  6257. Repeat$4 = immutable.Repeat;
  6258. var defaultRecord$4 = {
  6259. entityMap: null,
  6260. blockMap: null,
  6261. selectionBefore: null,
  6262. selectionAfter: null
  6263. };
  6264. var ContentBlockNodeRecord = ContentBlock_1;
  6265. var ContentStateRecord = Record$6(defaultRecord$4);
  6266. var ContentState = function (_ContentStateRecord) {
  6267. _inherits$5(ContentState, _ContentStateRecord);
  6268. function ContentState() {
  6269. _classCallCheck$5(this, ContentState);
  6270. return _possibleConstructorReturn$5(this, _ContentStateRecord.apply(this, arguments));
  6271. }
  6272. ContentState.prototype.getEntityMap = function getEntityMap() {
  6273. // TODO: update this when we fully remove DraftEntity
  6274. return DraftEntity_1;
  6275. };
  6276. ContentState.prototype.getBlockMap = function getBlockMap() {
  6277. return this.get('blockMap');
  6278. };
  6279. ContentState.prototype.getSelectionBefore = function getSelectionBefore() {
  6280. return this.get('selectionBefore');
  6281. };
  6282. ContentState.prototype.getSelectionAfter = function getSelectionAfter() {
  6283. return this.get('selectionAfter');
  6284. };
  6285. ContentState.prototype.getBlockForKey = function getBlockForKey(key) {
  6286. var block = this.getBlockMap().get(key);
  6287. return block;
  6288. };
  6289. ContentState.prototype.getKeyBefore = function getKeyBefore(key) {
  6290. return this.getBlockMap().reverse().keySeq().skipUntil(function (v) {
  6291. return v === key;
  6292. }).skip(1).first();
  6293. };
  6294. ContentState.prototype.getKeyAfter = function getKeyAfter(key) {
  6295. return this.getBlockMap().keySeq().skipUntil(function (v) {
  6296. return v === key;
  6297. }).skip(1).first();
  6298. };
  6299. ContentState.prototype.getBlockAfter = function getBlockAfter(key) {
  6300. return this.getBlockMap().skipUntil(function (_, k) {
  6301. return k === key;
  6302. }).skip(1).first();
  6303. };
  6304. ContentState.prototype.getBlockBefore = function getBlockBefore(key) {
  6305. return this.getBlockMap().reverse().skipUntil(function (_, k) {
  6306. return k === key;
  6307. }).skip(1).first();
  6308. };
  6309. ContentState.prototype.getBlocksAsArray = function getBlocksAsArray() {
  6310. return this.getBlockMap().toArray();
  6311. };
  6312. ContentState.prototype.getFirstBlock = function getFirstBlock() {
  6313. return this.getBlockMap().first();
  6314. };
  6315. ContentState.prototype.getLastBlock = function getLastBlock() {
  6316. return this.getBlockMap().last();
  6317. };
  6318. ContentState.prototype.getPlainText = function getPlainText(delimiter) {
  6319. return this.getBlockMap().map(function (block) {
  6320. return block ? block.getText() : '';
  6321. }).join(delimiter || '\n');
  6322. };
  6323. ContentState.prototype.getLastCreatedEntityKey = function getLastCreatedEntityKey() {
  6324. // TODO: update this when we fully remove DraftEntity
  6325. return DraftEntity_1.__getLastCreatedEntityKey();
  6326. };
  6327. ContentState.prototype.hasText = function hasText() {
  6328. var blockMap = this.getBlockMap();
  6329. return blockMap.size > 1 || blockMap.first().getLength() > 0;
  6330. };
  6331. ContentState.prototype.createEntity = function createEntity(type, mutability, data) {
  6332. // TODO: update this when we fully remove DraftEntity
  6333. DraftEntity_1.__create(type, mutability, data);
  6334. return this;
  6335. };
  6336. ContentState.prototype.mergeEntityData = function mergeEntityData(key, toMerge) {
  6337. // TODO: update this when we fully remove DraftEntity
  6338. DraftEntity_1.__mergeData(key, toMerge);
  6339. return this;
  6340. };
  6341. ContentState.prototype.replaceEntityData = function replaceEntityData(key, newData) {
  6342. // TODO: update this when we fully remove DraftEntity
  6343. DraftEntity_1.__replaceData(key, newData);
  6344. return this;
  6345. };
  6346. ContentState.prototype.addEntity = function addEntity(instance) {
  6347. // TODO: update this when we fully remove DraftEntity
  6348. DraftEntity_1.__add(instance);
  6349. return this;
  6350. };
  6351. ContentState.prototype.getEntity = function getEntity(key) {
  6352. // TODO: update this when we fully remove DraftEntity
  6353. return DraftEntity_1.__get(key);
  6354. };
  6355. ContentState.createFromBlockArray = function createFromBlockArray(
  6356. // TODO: update flow type when we completely deprecate the old entity API
  6357. blocks, entityMap) {
  6358. // TODO: remove this when we completely deprecate the old entity API
  6359. var theBlocks = Array.isArray(blocks) ? blocks : blocks.contentBlocks;
  6360. var blockMap = BlockMapBuilder_1.createFromArray(theBlocks);
  6361. var selectionState = blockMap.isEmpty() ? new SelectionState_1() : SelectionState_1.createEmpty(blockMap.first().getKey());
  6362. return new ContentState({
  6363. blockMap: blockMap,
  6364. entityMap: entityMap || DraftEntity_1,
  6365. selectionBefore: selectionState,
  6366. selectionAfter: selectionState
  6367. });
  6368. };
  6369. ContentState.createFromText = function createFromText(text) {
  6370. var delimiter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : /\r\n?|\n/g;
  6371. var strings = text.split(delimiter);
  6372. var blocks = strings.map(function (block) {
  6373. block = sanitizeDraftText_1(block);
  6374. return new ContentBlockNodeRecord({
  6375. key: generateRandomKey_1(),
  6376. text: block,
  6377. type: 'unstyled',
  6378. characterList: List$6(Repeat$4(CharacterMetadata_1.EMPTY, block.length))
  6379. });
  6380. });
  6381. return ContentState.createFromBlockArray(blocks);
  6382. };
  6383. return ContentState;
  6384. }(ContentStateRecord);
  6385. var ContentState_1 = ContentState;
  6386. var NEUTRAL = 'NEUTRAL'; // No strong direction
  6387. var LTR = 'LTR'; // Left-to-Right direction
  6388. var RTL = 'RTL'; // Right-to-Left direction
  6389. var globalDir = null;
  6390. // == Helpers ==
  6391. /**
  6392. * Check if a directionality value is a Strong one
  6393. */
  6394. function isStrong(dir) {
  6395. return dir === LTR || dir === RTL;
  6396. }
  6397. /**
  6398. * Get string value to be used for `dir` HTML attribute or `direction` CSS
  6399. * property.
  6400. */
  6401. function getHTMLDir(dir) {
  6402. !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;
  6403. return dir === LTR ? 'ltr' : 'rtl';
  6404. }
  6405. /**
  6406. * Get string value to be used for `dir` HTML attribute or `direction` CSS
  6407. * property, but returns null if `dir` has same value as `otherDir`.
  6408. * `null`.
  6409. */
  6410. function getHTMLDirIfDifferent(dir, otherDir) {
  6411. !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;
  6412. !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;
  6413. return dir === otherDir ? null : getHTMLDir(dir);
  6414. }
  6415. // == Global Direction ==
  6416. /**
  6417. * Set the global direction.
  6418. */
  6419. function setGlobalDir(dir) {
  6420. globalDir = dir;
  6421. }
  6422. /**
  6423. * Initialize the global direction
  6424. */
  6425. function initGlobalDir() {
  6426. setGlobalDir(LTR);
  6427. }
  6428. /**
  6429. * Get the global direction
  6430. */
  6431. function getGlobalDir() {
  6432. if (!globalDir) {
  6433. this.initGlobalDir();
  6434. }
  6435. !globalDir ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Global direction not set.') : invariant_1(false) : void 0;
  6436. return globalDir;
  6437. }
  6438. var UnicodeBidiDirection = {
  6439. // Values
  6440. NEUTRAL: NEUTRAL,
  6441. LTR: LTR,
  6442. RTL: RTL,
  6443. // Helpers
  6444. isStrong: isStrong,
  6445. getHTMLDir: getHTMLDir,
  6446. getHTMLDirIfDifferent: getHTMLDirIfDifferent,
  6447. // Global Direction
  6448. setGlobalDir: setGlobalDir,
  6449. initGlobalDir: initGlobalDir,
  6450. getGlobalDir: getGlobalDir
  6451. };
  6452. var UnicodeBidiDirection_1 = UnicodeBidiDirection;
  6453. /**
  6454. * RegExp ranges of characters with a *Strong* Bidi_Class value.
  6455. *
  6456. * Data is based on DerivedBidiClass.txt in UCD version 7.0.0.
  6457. *
  6458. * NOTE: For performance reasons, we only support Unicode's
  6459. * Basic Multilingual Plane (BMP) for now.
  6460. */
  6461. var RANGE_BY_BIDI_TYPE = {
  6462. 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',
  6463. 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',
  6464. 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'
  6465. };
  6466. var REGEX_STRONG = new RegExp('[' + RANGE_BY_BIDI_TYPE.L + RANGE_BY_BIDI_TYPE.R + RANGE_BY_BIDI_TYPE.AL + ']');
  6467. var REGEX_RTL = new RegExp('[' + RANGE_BY_BIDI_TYPE.R + RANGE_BY_BIDI_TYPE.AL + ']');
  6468. /**
  6469. * Returns the first strong character (has Bidi_Class value of L, R, or AL).
  6470. *
  6471. * @param str A text block; e.g. paragraph, table cell, tag
  6472. * @return A character with strong bidi direction, or null if not found
  6473. */
  6474. function firstStrongChar(str) {
  6475. var match = REGEX_STRONG.exec(str);
  6476. return match == null ? null : match[0];
  6477. }
  6478. /**
  6479. * Returns the direction of a block of text, based on the direction of its
  6480. * first strong character (has Bidi_Class value of L, R, or AL).
  6481. *
  6482. * @param str A text block; e.g. paragraph, table cell, tag
  6483. * @return The resolved direction
  6484. */
  6485. function firstStrongCharDir(str) {
  6486. var strongChar = firstStrongChar(str);
  6487. if (strongChar == null) {
  6488. return UnicodeBidiDirection_1.NEUTRAL;
  6489. }
  6490. return REGEX_RTL.exec(strongChar) ? UnicodeBidiDirection_1.RTL : UnicodeBidiDirection_1.LTR;
  6491. }
  6492. /**
  6493. * Returns the direction of a block of text, based on the direction of its
  6494. * first strong character (has Bidi_Class value of L, R, or AL), or a fallback
  6495. * direction, if no strong character is found.
  6496. *
  6497. * This function is supposed to be used in respect to Higher-Level Protocol
  6498. * rule HL1. (http://www.unicode.org/reports/tr9/#HL1)
  6499. *
  6500. * @param str A text block; e.g. paragraph, table cell, tag
  6501. * @param fallback Fallback direction, used if no strong direction detected
  6502. * for the block (default = NEUTRAL)
  6503. * @return The resolved direction
  6504. */
  6505. function resolveBlockDir(str, fallback) {
  6506. fallback = fallback || UnicodeBidiDirection_1.NEUTRAL;
  6507. if (!str.length) {
  6508. return fallback;
  6509. }
  6510. var blockDir = firstStrongCharDir(str);
  6511. return blockDir === UnicodeBidiDirection_1.NEUTRAL ? fallback : blockDir;
  6512. }
  6513. /**
  6514. * Returns the direction of a block of text, based on the direction of its
  6515. * first strong character (has Bidi_Class value of L, R, or AL), or a fallback
  6516. * direction, if no strong character is found.
  6517. *
  6518. * NOTE: This function is similar to resolveBlockDir(), but uses the global
  6519. * direction as the fallback, so it *always* returns a Strong direction,
  6520. * making it useful for integration in places that you need to make the final
  6521. * decision, like setting some CSS class.
  6522. *
  6523. * This function is supposed to be used in respect to Higher-Level Protocol
  6524. * rule HL1. (http://www.unicode.org/reports/tr9/#HL1)
  6525. *
  6526. * @param str A text block; e.g. paragraph, table cell
  6527. * @param strongFallback Fallback direction, used if no strong direction
  6528. * detected for the block (default = global direction)
  6529. * @return The resolved Strong direction
  6530. */
  6531. function getDirection(str, strongFallback) {
  6532. if (!strongFallback) {
  6533. strongFallback = UnicodeBidiDirection_1.getGlobalDir();
  6534. }
  6535. !UnicodeBidiDirection_1.isStrong(strongFallback) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Fallback direction must be a strong direction') : invariant_1(false) : void 0;
  6536. return resolveBlockDir(str, strongFallback);
  6537. }
  6538. /**
  6539. * Returns true if getDirection(arguments...) returns LTR.
  6540. *
  6541. * @param str A text block; e.g. paragraph, table cell
  6542. * @param strongFallback Fallback direction, used if no strong direction
  6543. * detected for the block (default = global direction)
  6544. * @return True if the resolved direction is LTR
  6545. */
  6546. function isDirectionLTR(str, strongFallback) {
  6547. return getDirection(str, strongFallback) === UnicodeBidiDirection_1.LTR;
  6548. }
  6549. /**
  6550. * Returns true if getDirection(arguments...) returns RTL.
  6551. *
  6552. * @param str A text block; e.g. paragraph, table cell
  6553. * @param strongFallback Fallback direction, used if no strong direction
  6554. * detected for the block (default = global direction)
  6555. * @return True if the resolved direction is RTL
  6556. */
  6557. function isDirectionRTL(str, strongFallback) {
  6558. return getDirection(str, strongFallback) === UnicodeBidiDirection_1.RTL;
  6559. }
  6560. var UnicodeBidi = {
  6561. firstStrongChar: firstStrongChar,
  6562. firstStrongCharDir: firstStrongCharDir,
  6563. resolveBlockDir: resolveBlockDir,
  6564. getDirection: getDirection,
  6565. isDirectionLTR: isDirectionLTR,
  6566. isDirectionRTL: isDirectionRTL
  6567. };
  6568. var UnicodeBidi_1 = UnicodeBidi;
  6569. function _classCallCheck$6(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6570. var UnicodeBidiService = function () {
  6571. /**
  6572. * Stateful class for paragraph direction detection
  6573. *
  6574. * @param defaultDir Default direction of the service
  6575. */
  6576. function UnicodeBidiService(defaultDir) {
  6577. _classCallCheck$6(this, UnicodeBidiService);
  6578. if (!defaultDir) {
  6579. defaultDir = UnicodeBidiDirection_1.getGlobalDir();
  6580. } else {
  6581. !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;
  6582. }
  6583. this._defaultDir = defaultDir;
  6584. this.reset();
  6585. }
  6586. /**
  6587. * Reset the internal state
  6588. *
  6589. * Instead of creating a new instance, you can just reset() your instance
  6590. * everytime you start a new loop.
  6591. */
  6592. UnicodeBidiService.prototype.reset = function reset() {
  6593. this._lastDir = this._defaultDir;
  6594. };
  6595. /**
  6596. * Returns the direction of a block of text, and remembers it as the
  6597. * fall-back direction for the next paragraph.
  6598. *
  6599. * @param str A text block, e.g. paragraph, table cell, tag
  6600. * @return The resolved direction
  6601. */
  6602. UnicodeBidiService.prototype.getDirection = function getDirection(str) {
  6603. this._lastDir = UnicodeBidi_1.getDirection(str, this._lastDir);
  6604. return this._lastDir;
  6605. };
  6606. return UnicodeBidiService;
  6607. }();
  6608. var UnicodeBidiService_1 = UnicodeBidiService;
  6609. /**
  6610. * Copyright (c) 2013-present, Facebook, Inc.
  6611. *
  6612. * This source code is licensed under the MIT license found in the
  6613. * LICENSE file in the root directory of this source tree.
  6614. *
  6615. *
  6616. */
  6617. var nullthrows = function nullthrows(x) {
  6618. if (x != null) {
  6619. return x;
  6620. }
  6621. throw new Error("Got unexpected null or undefined");
  6622. };
  6623. var nullthrows_1 = nullthrows;
  6624. var OrderedMap$2 = immutable.OrderedMap;
  6625. var bidiService;
  6626. var EditorBidiService = {
  6627. getDirectionMap: function getDirectionMap(content, prevBidiMap) {
  6628. if (!bidiService) {
  6629. bidiService = new UnicodeBidiService_1();
  6630. } else {
  6631. bidiService.reset();
  6632. }
  6633. var blockMap = content.getBlockMap();
  6634. var nextBidi = blockMap.valueSeq().map(function (block) {
  6635. return nullthrows_1(bidiService).getDirection(block.getText());
  6636. });
  6637. var bidiMap = OrderedMap$2(blockMap.keySeq().zip(nextBidi));
  6638. if (prevBidiMap != null && immutable.is(prevBidiMap, bidiMap)) {
  6639. return prevBidiMap;
  6640. }
  6641. return bidiMap;
  6642. }
  6643. };
  6644. var EditorBidiService_1 = EditorBidiService;
  6645. 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; };
  6646. function _classCallCheck$7(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6647. var OrderedSet$4 = immutable.OrderedSet,
  6648. Record$7 = immutable.Record,
  6649. Stack = immutable.Stack;
  6650. var defaultRecord$5 = {
  6651. allowUndo: true,
  6652. currentContent: null,
  6653. decorator: null,
  6654. directionMap: null,
  6655. forceSelection: false,
  6656. inCompositionMode: false,
  6657. inlineStyleOverride: null,
  6658. lastChangeType: null,
  6659. nativelyRenderedContent: null,
  6660. redoStack: Stack(),
  6661. selection: null,
  6662. treeMap: null,
  6663. undoStack: Stack()
  6664. };
  6665. var EditorStateRecord = Record$7(defaultRecord$5);
  6666. var EditorState = function () {
  6667. EditorState.createEmpty = function createEmpty(decorator) {
  6668. return EditorState.createWithContent(ContentState_1.createFromText(''), decorator);
  6669. };
  6670. EditorState.createWithContent = function createWithContent(contentState, decorator) {
  6671. var firstKey = contentState.getBlockMap().first().getKey();
  6672. return EditorState.create({
  6673. currentContent: contentState,
  6674. undoStack: Stack(),
  6675. redoStack: Stack(),
  6676. decorator: decorator || null,
  6677. selection: SelectionState_1.createEmpty(firstKey)
  6678. });
  6679. };
  6680. EditorState.create = function create(config) {
  6681. var currentContent = config.currentContent,
  6682. decorator = config.decorator;
  6683. var recordConfig = _extends$1({}, config, {
  6684. treeMap: generateNewTreeMap(currentContent, decorator),
  6685. directionMap: EditorBidiService_1.getDirectionMap(currentContent)
  6686. });
  6687. return new EditorState(new EditorStateRecord(recordConfig));
  6688. };
  6689. EditorState.set = function set(editorState, put) {
  6690. var map = editorState.getImmutable().withMutations(function (state) {
  6691. var existingDecorator = state.get('decorator');
  6692. var decorator = existingDecorator;
  6693. if (put.decorator === null) {
  6694. decorator = null;
  6695. } else if (put.decorator) {
  6696. decorator = put.decorator;
  6697. }
  6698. var newContent = put.currentContent || editorState.getCurrentContent();
  6699. if (decorator !== existingDecorator) {
  6700. var treeMap = state.get('treeMap');
  6701. var newTreeMap;
  6702. if (decorator && existingDecorator) {
  6703. newTreeMap = regenerateTreeForNewDecorator(newContent, newContent.getBlockMap(), treeMap, decorator, existingDecorator);
  6704. } else {
  6705. newTreeMap = generateNewTreeMap(newContent, decorator);
  6706. }
  6707. state.merge({
  6708. decorator: decorator,
  6709. treeMap: newTreeMap,
  6710. nativelyRenderedContent: null
  6711. });
  6712. return;
  6713. }
  6714. var existingContent = editorState.getCurrentContent();
  6715. if (newContent !== existingContent) {
  6716. state.set('treeMap', regenerateTreeForNewBlocks(editorState, newContent.getBlockMap(), newContent.getEntityMap(), decorator));
  6717. }
  6718. state.merge(put);
  6719. });
  6720. return new EditorState(map);
  6721. };
  6722. EditorState.prototype.toJS = function toJS() {
  6723. return this.getImmutable().toJS();
  6724. };
  6725. EditorState.prototype.getAllowUndo = function getAllowUndo() {
  6726. return this.getImmutable().get('allowUndo');
  6727. };
  6728. EditorState.prototype.getCurrentContent = function getCurrentContent() {
  6729. return this.getImmutable().get('currentContent');
  6730. };
  6731. EditorState.prototype.getUndoStack = function getUndoStack() {
  6732. return this.getImmutable().get('undoStack');
  6733. };
  6734. EditorState.prototype.getRedoStack = function getRedoStack() {
  6735. return this.getImmutable().get('redoStack');
  6736. };
  6737. EditorState.prototype.getSelection = function getSelection() {
  6738. return this.getImmutable().get('selection');
  6739. };
  6740. EditorState.prototype.getDecorator = function getDecorator() {
  6741. return this.getImmutable().get('decorator');
  6742. };
  6743. EditorState.prototype.isInCompositionMode = function isInCompositionMode() {
  6744. return this.getImmutable().get('inCompositionMode');
  6745. };
  6746. EditorState.prototype.mustForceSelection = function mustForceSelection() {
  6747. return this.getImmutable().get('forceSelection');
  6748. };
  6749. EditorState.prototype.getNativelyRenderedContent = function getNativelyRenderedContent() {
  6750. return this.getImmutable().get('nativelyRenderedContent');
  6751. };
  6752. EditorState.prototype.getLastChangeType = function getLastChangeType() {
  6753. return this.getImmutable().get('lastChangeType');
  6754. };
  6755. /**
  6756. * While editing, the user may apply inline style commands with a collapsed
  6757. * cursor, intending to type text that adopts the specified style. In this
  6758. * case, we track the specified style as an "override" that takes precedence
  6759. * over the inline style of the text adjacent to the cursor.
  6760. *
  6761. * If null, there is no override in place.
  6762. */
  6763. EditorState.prototype.getInlineStyleOverride = function getInlineStyleOverride() {
  6764. return this.getImmutable().get('inlineStyleOverride');
  6765. };
  6766. EditorState.setInlineStyleOverride = function setInlineStyleOverride(editorState, inlineStyleOverride) {
  6767. return EditorState.set(editorState, { inlineStyleOverride: inlineStyleOverride });
  6768. };
  6769. /**
  6770. * Get the appropriate inline style for the editor state. If an
  6771. * override is in place, use it. Otherwise, the current style is
  6772. * based on the location of the selection state.
  6773. */
  6774. EditorState.prototype.getCurrentInlineStyle = function getCurrentInlineStyle() {
  6775. var override = this.getInlineStyleOverride();
  6776. if (override != null) {
  6777. return override;
  6778. }
  6779. var content = this.getCurrentContent();
  6780. var selection = this.getSelection();
  6781. if (selection.isCollapsed()) {
  6782. return getInlineStyleForCollapsedSelection(content, selection);
  6783. }
  6784. return getInlineStyleForNonCollapsedSelection(content, selection);
  6785. };
  6786. EditorState.prototype.getBlockTree = function getBlockTree(blockKey) {
  6787. return this.getImmutable().getIn(['treeMap', blockKey]);
  6788. };
  6789. EditorState.prototype.isSelectionAtStartOfContent = function isSelectionAtStartOfContent() {
  6790. var firstKey = this.getCurrentContent().getBlockMap().first().getKey();
  6791. return this.getSelection().hasEdgeWithin(firstKey, 0, 0);
  6792. };
  6793. EditorState.prototype.isSelectionAtEndOfContent = function isSelectionAtEndOfContent() {
  6794. var content = this.getCurrentContent();
  6795. var blockMap = content.getBlockMap();
  6796. var last = blockMap.last();
  6797. var end = last.getLength();
  6798. return this.getSelection().hasEdgeWithin(last.getKey(), end, end);
  6799. };
  6800. EditorState.prototype.getDirectionMap = function getDirectionMap() {
  6801. return this.getImmutable().get('directionMap');
  6802. };
  6803. /**
  6804. * Incorporate native DOM selection changes into the EditorState. This
  6805. * method can be used when we simply want to accept whatever the DOM
  6806. * has given us to represent selection, and we do not need to re-render
  6807. * the editor.
  6808. *
  6809. * To forcibly move the DOM selection, see `EditorState.forceSelection`.
  6810. */
  6811. EditorState.acceptSelection = function acceptSelection(editorState, selection) {
  6812. return updateSelection(editorState, selection, false);
  6813. };
  6814. /**
  6815. * At times, we need to force the DOM selection to be where we
  6816. * need it to be. This can occur when the anchor or focus nodes
  6817. * are non-text nodes, for instance. In this case, we want to trigger
  6818. * a re-render of the editor, which in turn forces selection into
  6819. * the correct place in the DOM. The `forceSelection` method
  6820. * accomplishes this.
  6821. *
  6822. * This method should be used in cases where you need to explicitly
  6823. * move the DOM selection from one place to another without a change
  6824. * in ContentState.
  6825. */
  6826. EditorState.forceSelection = function forceSelection(editorState, selection) {
  6827. if (!selection.getHasFocus()) {
  6828. selection = selection.set('hasFocus', true);
  6829. }
  6830. return updateSelection(editorState, selection, true);
  6831. };
  6832. /**
  6833. * Move selection to the end of the editor without forcing focus.
  6834. */
  6835. EditorState.moveSelectionToEnd = function moveSelectionToEnd(editorState) {
  6836. var content = editorState.getCurrentContent();
  6837. var lastBlock = content.getLastBlock();
  6838. var lastKey = lastBlock.getKey();
  6839. var length = lastBlock.getLength();
  6840. return EditorState.acceptSelection(editorState, new SelectionState_1({
  6841. anchorKey: lastKey,
  6842. anchorOffset: length,
  6843. focusKey: lastKey,
  6844. focusOffset: length,
  6845. isBackward: false
  6846. }));
  6847. };
  6848. /**
  6849. * Force focus to the end of the editor. This is useful in scenarios
  6850. * where we want to programmatically focus the input and it makes sense
  6851. * to allow the user to continue working seamlessly.
  6852. */
  6853. EditorState.moveFocusToEnd = function moveFocusToEnd(editorState) {
  6854. var afterSelectionMove = EditorState.moveSelectionToEnd(editorState);
  6855. return EditorState.forceSelection(afterSelectionMove, afterSelectionMove.getSelection());
  6856. };
  6857. /**
  6858. * Push the current ContentState onto the undo stack if it should be
  6859. * considered a boundary state, and set the provided ContentState as the
  6860. * new current content.
  6861. */
  6862. EditorState.push = function push(editorState, contentState, changeType) {
  6863. if (editorState.getCurrentContent() === contentState) {
  6864. return editorState;
  6865. }
  6866. var forceSelection = changeType !== 'insert-characters';
  6867. var directionMap = EditorBidiService_1.getDirectionMap(contentState, editorState.getDirectionMap());
  6868. if (!editorState.getAllowUndo()) {
  6869. return EditorState.set(editorState, {
  6870. currentContent: contentState,
  6871. directionMap: directionMap,
  6872. lastChangeType: changeType,
  6873. selection: contentState.getSelectionAfter(),
  6874. forceSelection: forceSelection,
  6875. inlineStyleOverride: null
  6876. });
  6877. }
  6878. var selection = editorState.getSelection();
  6879. var currentContent = editorState.getCurrentContent();
  6880. var undoStack = editorState.getUndoStack();
  6881. var newContent = contentState;
  6882. if (selection !== currentContent.getSelectionAfter() || mustBecomeBoundary(editorState, changeType)) {
  6883. undoStack = undoStack.push(currentContent);
  6884. newContent = newContent.set('selectionBefore', selection);
  6885. } else if (changeType === 'insert-characters' || changeType === 'backspace-character' || changeType === 'delete-character') {
  6886. // Preserve the previous selection.
  6887. newContent = newContent.set('selectionBefore', currentContent.getSelectionBefore());
  6888. }
  6889. var inlineStyleOverride = editorState.getInlineStyleOverride();
  6890. // Don't discard inline style overrides for the following change types:
  6891. var overrideChangeTypes = ['adjust-depth', 'change-block-type', 'split-block'];
  6892. if (overrideChangeTypes.indexOf(changeType) === -1) {
  6893. inlineStyleOverride = null;
  6894. }
  6895. var editorStateChanges = {
  6896. currentContent: newContent,
  6897. directionMap: directionMap,
  6898. undoStack: undoStack,
  6899. redoStack: Stack(),
  6900. lastChangeType: changeType,
  6901. selection: contentState.getSelectionAfter(),
  6902. forceSelection: forceSelection,
  6903. inlineStyleOverride: inlineStyleOverride
  6904. };
  6905. return EditorState.set(editorState, editorStateChanges);
  6906. };
  6907. /**
  6908. * Make the top ContentState in the undo stack the new current content and
  6909. * push the current content onto the redo stack.
  6910. */
  6911. EditorState.undo = function undo(editorState) {
  6912. if (!editorState.getAllowUndo()) {
  6913. return editorState;
  6914. }
  6915. var undoStack = editorState.getUndoStack();
  6916. var newCurrentContent = undoStack.peek();
  6917. if (!newCurrentContent) {
  6918. return editorState;
  6919. }
  6920. var currentContent = editorState.getCurrentContent();
  6921. var directionMap = EditorBidiService_1.getDirectionMap(newCurrentContent, editorState.getDirectionMap());
  6922. return EditorState.set(editorState, {
  6923. currentContent: newCurrentContent,
  6924. directionMap: directionMap,
  6925. undoStack: undoStack.shift(),
  6926. redoStack: editorState.getRedoStack().push(currentContent),
  6927. forceSelection: true,
  6928. inlineStyleOverride: null,
  6929. lastChangeType: 'undo',
  6930. nativelyRenderedContent: null,
  6931. selection: currentContent.getSelectionBefore()
  6932. });
  6933. };
  6934. /**
  6935. * Make the top ContentState in the redo stack the new current content and
  6936. * push the current content onto the undo stack.
  6937. */
  6938. EditorState.redo = function redo(editorState) {
  6939. if (!editorState.getAllowUndo()) {
  6940. return editorState;
  6941. }
  6942. var redoStack = editorState.getRedoStack();
  6943. var newCurrentContent = redoStack.peek();
  6944. if (!newCurrentContent) {
  6945. return editorState;
  6946. }
  6947. var currentContent = editorState.getCurrentContent();
  6948. var directionMap = EditorBidiService_1.getDirectionMap(newCurrentContent, editorState.getDirectionMap());
  6949. return EditorState.set(editorState, {
  6950. currentContent: newCurrentContent,
  6951. directionMap: directionMap,
  6952. undoStack: editorState.getUndoStack().push(currentContent),
  6953. redoStack: redoStack.shift(),
  6954. forceSelection: true,
  6955. inlineStyleOverride: null,
  6956. lastChangeType: 'redo',
  6957. nativelyRenderedContent: null,
  6958. selection: newCurrentContent.getSelectionAfter()
  6959. });
  6960. };
  6961. /**
  6962. * Not for public consumption.
  6963. */
  6964. function EditorState(immutable) {
  6965. _classCallCheck$7(this, EditorState);
  6966. this._immutable = immutable;
  6967. }
  6968. /**
  6969. * Not for public consumption.
  6970. */
  6971. EditorState.prototype.getImmutable = function getImmutable() {
  6972. return this._immutable;
  6973. };
  6974. return EditorState;
  6975. }();
  6976. /**
  6977. * Set the supplied SelectionState as the new current selection, and set
  6978. * the `force` flag to trigger manual selection placement by the view.
  6979. */
  6980. function updateSelection(editorState, selection, forceSelection) {
  6981. return EditorState.set(editorState, {
  6982. selection: selection,
  6983. forceSelection: forceSelection,
  6984. nativelyRenderedContent: null,
  6985. inlineStyleOverride: null
  6986. });
  6987. }
  6988. /**
  6989. * Regenerate the entire tree map for a given ContentState and decorator.
  6990. * Returns an OrderedMap that maps all available ContentBlock objects.
  6991. */
  6992. function generateNewTreeMap(contentState, decorator) {
  6993. return contentState.getBlockMap().map(function (block) {
  6994. return BlockTree_1.generate(contentState, block, decorator);
  6995. }).toOrderedMap();
  6996. }
  6997. /**
  6998. * Regenerate tree map objects for all ContentBlocks that have changed
  6999. * between the current editorState and newContent. Returns an OrderedMap
  7000. * with only changed regenerated tree map objects.
  7001. */
  7002. function regenerateTreeForNewBlocks(editorState, newBlockMap, newEntityMap, decorator) {
  7003. var contentState = editorState.getCurrentContent().set('entityMap', newEntityMap);
  7004. var prevBlockMap = contentState.getBlockMap();
  7005. var prevTreeMap = editorState.getImmutable().get('treeMap');
  7006. return prevTreeMap.merge(newBlockMap.toSeq().filter(function (block, key) {
  7007. return block !== prevBlockMap.get(key);
  7008. }).map(function (block) {
  7009. return BlockTree_1.generate(contentState, block, decorator);
  7010. }));
  7011. }
  7012. /**
  7013. * Generate tree map objects for a new decorator object, preserving any
  7014. * decorations that are unchanged from the previous decorator.
  7015. *
  7016. * Note that in order for this to perform optimally, decoration Lists for
  7017. * decorators should be preserved when possible to allow for direct immutable
  7018. * List comparison.
  7019. */
  7020. function regenerateTreeForNewDecorator(content, blockMap, previousTreeMap, decorator, existingDecorator) {
  7021. return previousTreeMap.merge(blockMap.toSeq().filter(function (block) {
  7022. return decorator.getDecorations(block, content) !== existingDecorator.getDecorations(block, content);
  7023. }).map(function (block) {
  7024. return BlockTree_1.generate(content, block, decorator);
  7025. }));
  7026. }
  7027. /**
  7028. * Return whether a change should be considered a boundary state, given
  7029. * the previous change type. Allows us to discard potential boundary states
  7030. * during standard typing or deletion behavior.
  7031. */
  7032. function mustBecomeBoundary(editorState, changeType) {
  7033. var lastChangeType = editorState.getLastChangeType();
  7034. return changeType !== lastChangeType || changeType !== 'insert-characters' && changeType !== 'backspace-character' && changeType !== 'delete-character';
  7035. }
  7036. function getInlineStyleForCollapsedSelection(content, selection) {
  7037. var startKey = selection.getStartKey();
  7038. var startOffset = selection.getStartOffset();
  7039. var startBlock = content.getBlockForKey(startKey);
  7040. // If the cursor is not at the start of the block, look backward to
  7041. // preserve the style of the preceding character.
  7042. if (startOffset > 0) {
  7043. return startBlock.getInlineStyleAt(startOffset - 1);
  7044. }
  7045. // The caret is at position zero in this block. If the block has any
  7046. // text at all, use the style of the first character.
  7047. if (startBlock.getLength()) {
  7048. return startBlock.getInlineStyleAt(0);
  7049. }
  7050. // Otherwise, look upward in the document to find the closest character.
  7051. return lookUpwardForInlineStyle(content, startKey);
  7052. }
  7053. function getInlineStyleForNonCollapsedSelection(content, selection) {
  7054. var startKey = selection.getStartKey();
  7055. var startOffset = selection.getStartOffset();
  7056. var startBlock = content.getBlockForKey(startKey);
  7057. // If there is a character just inside the selection, use its style.
  7058. if (startOffset < startBlock.getLength()) {
  7059. return startBlock.getInlineStyleAt(startOffset);
  7060. }
  7061. // Check if the selection at the end of a non-empty block. Use the last
  7062. // style in the block.
  7063. if (startOffset > 0) {
  7064. return startBlock.getInlineStyleAt(startOffset - 1);
  7065. }
  7066. // Otherwise, look upward in the document to find the closest character.
  7067. return lookUpwardForInlineStyle(content, startKey);
  7068. }
  7069. function lookUpwardForInlineStyle(content, fromKey) {
  7070. var lastNonEmpty = content.getBlockMap().reverse().skipUntil(function (_, k) {
  7071. return k === fromKey;
  7072. }).skip(1).skipUntil(function (block, _) {
  7073. return block.getLength();
  7074. }).first();
  7075. if (lastNonEmpty) return lastNonEmpty.getInlineStyleAt(lastNonEmpty.getLength() - 1);
  7076. return OrderedSet$4();
  7077. }
  7078. var EditorState_1 = EditorState;
  7079. var OrderedMap$3 = immutable.OrderedMap,
  7080. List$7 = immutable.List;
  7081. var transformBlock$2 = function transformBlock(key, blockMap, func) {
  7082. if (!key) {
  7083. return;
  7084. }
  7085. var block = blockMap.get(key);
  7086. if (!block) {
  7087. return;
  7088. }
  7089. blockMap.set(key, func(block));
  7090. };
  7091. var updateBlockMapLinks$3 = function updateBlockMapLinks(blockMap, originalBlockToBeMoved, originalTargetBlock, insertionMode, isExperimentalTreeBlock) {
  7092. if (!isExperimentalTreeBlock) {
  7093. return blockMap;
  7094. }
  7095. // possible values of 'insertionMode' are: 'after', 'before'
  7096. var isInsertedAfterTarget = insertionMode === 'after';
  7097. var originalBlockKey = originalBlockToBeMoved.getKey();
  7098. var originalTargetKey = originalTargetBlock.getKey();
  7099. var originalParentKey = originalBlockToBeMoved.getParentKey();
  7100. var originalNextSiblingKey = originalBlockToBeMoved.getNextSiblingKey();
  7101. var originalPrevSiblingKey = originalBlockToBeMoved.getPrevSiblingKey();
  7102. var newParentKey = originalTargetBlock.getParentKey();
  7103. var newNextSiblingKey = isInsertedAfterTarget ? originalTargetBlock.getNextSiblingKey() : originalTargetKey;
  7104. var newPrevSiblingKey = isInsertedAfterTarget ? originalTargetKey : originalTargetBlock.getPrevSiblingKey();
  7105. return blockMap.withMutations(function (blocks) {
  7106. // update old parent
  7107. transformBlock$2(originalParentKey, blocks, function (block) {
  7108. var parentChildrenList = block.getChildKeys();
  7109. return block.merge({
  7110. children: parentChildrenList['delete'](parentChildrenList.indexOf(originalBlockKey))
  7111. });
  7112. });
  7113. // update old prev
  7114. transformBlock$2(originalPrevSiblingKey, blocks, function (block) {
  7115. return block.merge({
  7116. nextSibling: originalNextSiblingKey
  7117. });
  7118. });
  7119. // update old next
  7120. transformBlock$2(originalNextSiblingKey, blocks, function (block) {
  7121. return block.merge({
  7122. prevSibling: originalPrevSiblingKey
  7123. });
  7124. });
  7125. // update new next
  7126. transformBlock$2(newNextSiblingKey, blocks, function (block) {
  7127. return block.merge({
  7128. prevSibling: originalBlockKey
  7129. });
  7130. });
  7131. // update new prev
  7132. transformBlock$2(newPrevSiblingKey, blocks, function (block) {
  7133. return block.merge({
  7134. nextSibling: originalBlockKey
  7135. });
  7136. });
  7137. // update new parent
  7138. transformBlock$2(newParentKey, blocks, function (block) {
  7139. var newParentChildrenList = block.getChildKeys();
  7140. var targetBlockIndex = newParentChildrenList.indexOf(originalTargetKey);
  7141. var insertionIndex = isInsertedAfterTarget ? targetBlockIndex + 1 : targetBlockIndex !== 0 ? targetBlockIndex - 1 : 0;
  7142. var newChildrenArray = newParentChildrenList.toArray();
  7143. newChildrenArray.splice(insertionIndex, 0, originalBlockKey);
  7144. return block.merge({
  7145. children: List$7(newChildrenArray)
  7146. });
  7147. });
  7148. // update block
  7149. transformBlock$2(originalBlockKey, blocks, function (block) {
  7150. return block.merge({
  7151. nextSibling: newNextSiblingKey,
  7152. prevSibling: newPrevSiblingKey,
  7153. parent: newParentKey
  7154. });
  7155. });
  7156. });
  7157. };
  7158. var moveBlockInContentState = function moveBlockInContentState(contentState, blockToBeMoved, targetBlock, insertionMode) {
  7159. !(insertionMode !== 'replace') ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Replacing blocks is not supported.') : invariant_1(false) : void 0;
  7160. var targetKey = targetBlock.getKey();
  7161. var blockKey = blockToBeMoved.getKey();
  7162. !(blockKey !== targetKey) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Block cannot be moved next to itself.') : invariant_1(false) : void 0;
  7163. var blockMap = contentState.getBlockMap();
  7164. var isExperimentalTreeBlock = blockToBeMoved instanceof ContentBlockNode_1;
  7165. var blocksToBeMoved = [blockToBeMoved];
  7166. var blockMapWithoutBlocksToBeMoved = blockMap['delete'](blockKey);
  7167. if (isExperimentalTreeBlock) {
  7168. blocksToBeMoved = [];
  7169. blockMapWithoutBlocksToBeMoved = blockMap.withMutations(function (blocks) {
  7170. var nextSiblingKey = blockToBeMoved.getNextSiblingKey();
  7171. var nextDelimiterBlockKey = getNextDelimiterBlockKey_1(blockToBeMoved, blocks);
  7172. blocks.toSeq().skipUntil(function (block) {
  7173. return block.getKey() === blockKey;
  7174. }).takeWhile(function (block) {
  7175. var key = block.getKey();
  7176. var isBlockToBeMoved = key === blockKey;
  7177. var hasNextSiblingAndIsNotNextSibling = nextSiblingKey && key !== nextSiblingKey;
  7178. var doesNotHaveNextSiblingAndIsNotDelimiter = !nextSiblingKey && block.getParentKey() && (!nextDelimiterBlockKey || key !== nextDelimiterBlockKey);
  7179. return !!(isBlockToBeMoved || hasNextSiblingAndIsNotNextSibling || doesNotHaveNextSiblingAndIsNotDelimiter);
  7180. }).forEach(function (block) {
  7181. blocksToBeMoved.push(block);
  7182. blocks['delete'](block.getKey());
  7183. });
  7184. });
  7185. }
  7186. var blocksBefore = blockMapWithoutBlocksToBeMoved.toSeq().takeUntil(function (v) {
  7187. return v === targetBlock;
  7188. });
  7189. var blocksAfter = blockMapWithoutBlocksToBeMoved.toSeq().skipUntil(function (v) {
  7190. return v === targetBlock;
  7191. }).skip(1);
  7192. var slicedBlocks = blocksToBeMoved.map(function (block) {
  7193. return [block.getKey(), block];
  7194. });
  7195. var newBlocks = OrderedMap$3();
  7196. if (insertionMode === 'before') {
  7197. var blockBefore = contentState.getBlockBefore(targetKey);
  7198. !(!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;
  7199. newBlocks = blocksBefore.concat([].concat(slicedBlocks, [[targetKey, targetBlock]]), blocksAfter).toOrderedMap();
  7200. } else if (insertionMode === 'after') {
  7201. var blockAfter = contentState.getBlockAfter(targetKey);
  7202. !(!blockAfter || blockAfter.getKey() !== blockKey) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Block cannot be moved next to itself.') : invariant_1(false) : void 0;
  7203. newBlocks = blocksBefore.concat([[targetKey, targetBlock]].concat(slicedBlocks), blocksAfter).toOrderedMap();
  7204. }
  7205. return contentState.merge({
  7206. blockMap: updateBlockMapLinks$3(newBlocks, blockToBeMoved, targetBlock, insertionMode, isExperimentalTreeBlock),
  7207. selectionBefore: contentState.getSelectionAfter(),
  7208. selectionAfter: contentState.getSelectionAfter().merge({
  7209. anchorKey: blockKey,
  7210. focusKey: blockKey
  7211. })
  7212. });
  7213. };
  7214. var moveBlockInContentState_1 = moveBlockInContentState;
  7215. var ContentBlockRecord$1 = ContentBlock_1;
  7216. var List$8 = immutable.List,
  7217. Repeat$5 = immutable.Repeat;
  7218. var AtomicBlockUtils = {
  7219. insertAtomicBlock: function insertAtomicBlock(editorState, entityKey, character) {
  7220. var contentState = editorState.getCurrentContent();
  7221. var selectionState = editorState.getSelection();
  7222. var afterRemoval = DraftModifier_1.removeRange(contentState, selectionState, 'backward');
  7223. var targetSelection = afterRemoval.getSelectionAfter();
  7224. var afterSplit = DraftModifier_1.splitBlock(afterRemoval, targetSelection);
  7225. var insertionTarget = afterSplit.getSelectionAfter();
  7226. var asAtomicBlock = DraftModifier_1.setBlockType(afterSplit, insertionTarget, 'atomic');
  7227. var charData = CharacterMetadata_1.create({ entity: entityKey });
  7228. var atomicBlockConfig = {
  7229. key: generateRandomKey_1(),
  7230. type: 'atomic',
  7231. text: character,
  7232. characterList: List$8(Repeat$5(charData, character.length))
  7233. };
  7234. var atomicDividerBlockConfig = {
  7235. key: generateRandomKey_1(),
  7236. type: 'unstyled'
  7237. };
  7238. var fragmentArray = [new ContentBlockRecord$1(atomicBlockConfig), new ContentBlockRecord$1(atomicDividerBlockConfig)];
  7239. var fragment = BlockMapBuilder_1.createFromArray(fragmentArray);
  7240. var withAtomicBlock = DraftModifier_1.replaceWithFragment(asAtomicBlock, insertionTarget, fragment);
  7241. var newContent = withAtomicBlock.merge({
  7242. selectionBefore: selectionState,
  7243. selectionAfter: withAtomicBlock.getSelectionAfter().set('hasFocus', true)
  7244. });
  7245. return EditorState_1.push(editorState, newContent, 'insert-fragment');
  7246. },
  7247. moveAtomicBlock: function moveAtomicBlock(editorState, atomicBlock, targetRange, insertionMode) {
  7248. var contentState = editorState.getCurrentContent();
  7249. var selectionState = editorState.getSelection();
  7250. var withMovedAtomicBlock = void 0;
  7251. if (insertionMode === 'before' || insertionMode === 'after') {
  7252. var targetBlock = contentState.getBlockForKey(insertionMode === 'before' ? targetRange.getStartKey() : targetRange.getEndKey());
  7253. withMovedAtomicBlock = moveBlockInContentState_1(contentState, atomicBlock, targetBlock, insertionMode);
  7254. } else {
  7255. var afterRemoval = DraftModifier_1.removeRange(contentState, targetRange, 'backward');
  7256. var selectionAfterRemoval = afterRemoval.getSelectionAfter();
  7257. var _targetBlock = afterRemoval.getBlockForKey(selectionAfterRemoval.getFocusKey());
  7258. if (selectionAfterRemoval.getStartOffset() === 0) {
  7259. withMovedAtomicBlock = moveBlockInContentState_1(afterRemoval, atomicBlock, _targetBlock, 'before');
  7260. } else if (selectionAfterRemoval.getEndOffset() === _targetBlock.getLength()) {
  7261. withMovedAtomicBlock = moveBlockInContentState_1(afterRemoval, atomicBlock, _targetBlock, 'after');
  7262. } else {
  7263. var afterSplit = DraftModifier_1.splitBlock(afterRemoval, selectionAfterRemoval);
  7264. var selectionAfterSplit = afterSplit.getSelectionAfter();
  7265. var _targetBlock2 = afterSplit.getBlockForKey(selectionAfterSplit.getFocusKey());
  7266. withMovedAtomicBlock = moveBlockInContentState_1(afterSplit, atomicBlock, _targetBlock2, 'before');
  7267. }
  7268. }
  7269. var newContent = withMovedAtomicBlock.merge({
  7270. selectionBefore: selectionState,
  7271. selectionAfter: withMovedAtomicBlock.getSelectionAfter().set('hasFocus', true)
  7272. });
  7273. return EditorState_1.push(editorState, newContent, 'move-block');
  7274. }
  7275. };
  7276. var AtomicBlockUtils_1 = AtomicBlockUtils;
  7277. function _classCallCheck$8(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7278. var List$9 = immutable.List;
  7279. var DELIMITER = '.';
  7280. /**
  7281. * A CompositeDraftDecorator traverses through a list of DraftDecorator
  7282. * instances to identify sections of a ContentBlock that should be rendered
  7283. * in a "decorated" manner. For example, hashtags, mentions, and links may
  7284. * be intended to stand out visually, be rendered as anchors, etc.
  7285. *
  7286. * The list of decorators supplied to the constructor will be used in the
  7287. * order they are provided. This allows the caller to specify a priority for
  7288. * string matching, in case of match collisions among decorators.
  7289. *
  7290. * For instance, I may have a link with a `#` in its text. Though this section
  7291. * of text may match our hashtag decorator, it should not be treated as a
  7292. * hashtag. I should therefore list my link DraftDecorator
  7293. * before my hashtag DraftDecorator when constructing this composite
  7294. * decorator instance.
  7295. *
  7296. * Thus, when a collision like this is encountered, the earlier match is
  7297. * preserved and the new match is discarded.
  7298. */
  7299. var CompositeDraftDecorator = function () {
  7300. function CompositeDraftDecorator(decorators) {
  7301. _classCallCheck$8(this, CompositeDraftDecorator);
  7302. // Copy the decorator array, since we use this array order to determine
  7303. // precedence of decoration matching. If the array is mutated externally,
  7304. // we don't want to be affected here.
  7305. this._decorators = decorators.slice();
  7306. }
  7307. CompositeDraftDecorator.prototype.getDecorations = function getDecorations(block, contentState) {
  7308. var decorations = Array(block.getText().length).fill(null);
  7309. this._decorators.forEach(function ( /*object*/decorator, /*number*/ii) {
  7310. var counter = 0;
  7311. var strategy = decorator.strategy;
  7312. var callback = function callback( /*number*/start, /*number*/end) {
  7313. // Find out if any of our matching range is already occupied
  7314. // by another decorator. If so, discard the match. Otherwise, store
  7315. // the component key for rendering.
  7316. if (canOccupySlice(decorations, start, end)) {
  7317. occupySlice(decorations, start, end, ii + DELIMITER + counter);
  7318. counter++;
  7319. }
  7320. };
  7321. strategy(block, callback, contentState);
  7322. });
  7323. return List$9(decorations);
  7324. };
  7325. CompositeDraftDecorator.prototype.getComponentForKey = function getComponentForKey(key) {
  7326. var componentKey = parseInt(key.split(DELIMITER)[0], 10);
  7327. return this._decorators[componentKey].component;
  7328. };
  7329. CompositeDraftDecorator.prototype.getPropsForKey = function getPropsForKey(key) {
  7330. var componentKey = parseInt(key.split(DELIMITER)[0], 10);
  7331. return this._decorators[componentKey].props;
  7332. };
  7333. return CompositeDraftDecorator;
  7334. }();
  7335. /**
  7336. * Determine whether we can occupy the specified slice of the decorations
  7337. * array.
  7338. */
  7339. function canOccupySlice(decorations, start, end) {
  7340. for (var ii = start; ii < end; ii++) {
  7341. if (decorations[ii] != null) {
  7342. return false;
  7343. }
  7344. }
  7345. return true;
  7346. }
  7347. /**
  7348. * Splice the specified component into our decoration array at the desired
  7349. * range.
  7350. */
  7351. function occupySlice(targetArr, start, end, componentKey) {
  7352. for (var ii = start; ii < end; ii++) {
  7353. targetArr[ii] = componentKey;
  7354. }
  7355. }
  7356. var CompositeDraftDecorator_1 = CompositeDraftDecorator;
  7357. /**
  7358. * Copyright (c) 2013-present, Facebook, Inc.
  7359. *
  7360. * This source code is licensed under the MIT license found in the
  7361. * LICENSE file in the root directory of this source tree.
  7362. *
  7363. */
  7364. /**
  7365. * This function is used to mark string literals representing CSS class names
  7366. * so that they can be transformed statically. This allows for modularization
  7367. * and minification of CSS class names.
  7368. *
  7369. * In static_upstream, this function is actually implemented, but it should
  7370. * eventually be replaced with something more descriptive, and the transform
  7371. * that is used in the main stack should be ported for use elsewhere.
  7372. *
  7373. * @param string|object className to modularize, or an object of key/values.
  7374. * In the object case, the values are conditions that
  7375. * determine if the className keys should be included.
  7376. * @param [string ...] Variable list of classNames in the string case.
  7377. * @return string Renderable space-separated CSS className.
  7378. */
  7379. function cx(classNames) {
  7380. if (typeof classNames == 'object') {
  7381. return Object.keys(classNames).filter(function (className) {
  7382. return classNames[className];
  7383. }).map(replace).join(' ');
  7384. }
  7385. return Array.prototype.map.call(arguments, replace).join(' ');
  7386. }
  7387. function replace(str) {
  7388. return str.replace(/\//g, '-');
  7389. }
  7390. var cx_1 = cx;
  7391. var Map$8 = immutable.Map;
  7392. var UL_WRAP = React.createElement('ul', { className: cx_1('public/DraftStyleDefault/ul') });
  7393. var OL_WRAP = React.createElement('ol', { className: cx_1('public/DraftStyleDefault/ol') });
  7394. var PRE_WRAP = React.createElement('pre', { className: cx_1('public/DraftStyleDefault/pre') });
  7395. var DefaultDraftBlockRenderMap = Map$8({
  7396. 'header-one': {
  7397. element: 'h1'
  7398. },
  7399. 'header-two': {
  7400. element: 'h2'
  7401. },
  7402. 'header-three': {
  7403. element: 'h3'
  7404. },
  7405. 'header-four': {
  7406. element: 'h4'
  7407. },
  7408. 'header-five': {
  7409. element: 'h5'
  7410. },
  7411. 'header-six': {
  7412. element: 'h6'
  7413. },
  7414. 'unordered-list-item': {
  7415. element: 'li',
  7416. wrapper: UL_WRAP
  7417. },
  7418. 'ordered-list-item': {
  7419. element: 'li',
  7420. wrapper: OL_WRAP
  7421. },
  7422. blockquote: {
  7423. element: 'blockquote'
  7424. },
  7425. atomic: {
  7426. element: 'figure'
  7427. },
  7428. 'code-block': {
  7429. element: 'pre',
  7430. wrapper: PRE_WRAP
  7431. },
  7432. unstyled: {
  7433. element: 'div',
  7434. aliasedElements: ['p']
  7435. }
  7436. });
  7437. var DefaultDraftBlockRenderMap_1 = DefaultDraftBlockRenderMap;
  7438. /**
  7439. * Copyright (c) 2013-present, Facebook, Inc.
  7440. * All rights reserved.
  7441. *
  7442. * This source code is licensed under the BSD-style license found in the
  7443. * LICENSE file in the root directory of this source tree. An additional grant
  7444. * of patent rights can be found in the PATENTS file in the same directory.
  7445. *
  7446. * @providesModule DefaultDraftInlineStyle
  7447. * @format
  7448. *
  7449. */
  7450. var DefaultDraftInlineStyle = {
  7451. BOLD: {
  7452. fontWeight: 'bold'
  7453. },
  7454. CODE: {
  7455. fontFamily: 'monospace',
  7456. wordWrap: 'break-word'
  7457. },
  7458. ITALIC: {
  7459. fontStyle: 'italic'
  7460. },
  7461. STRIKETHROUGH: {
  7462. textDecoration: 'line-through'
  7463. },
  7464. UNDERLINE: {
  7465. textDecoration: 'underline'
  7466. }
  7467. };
  7468. /**
  7469. * Copyright (c) 2013-present, Facebook, Inc.
  7470. *
  7471. * This source code is licensed under the MIT license found in the
  7472. * LICENSE file in the root directory of this source tree.
  7473. *
  7474. */
  7475. var Keys = {
  7476. BACKSPACE: 8,
  7477. TAB: 9,
  7478. RETURN: 13,
  7479. ALT: 18,
  7480. ESC: 27,
  7481. SPACE: 32,
  7482. PAGE_UP: 33,
  7483. PAGE_DOWN: 34,
  7484. END: 35,
  7485. HOME: 36,
  7486. LEFT: 37,
  7487. UP: 38,
  7488. RIGHT: 39,
  7489. DOWN: 40,
  7490. DELETE: 46,
  7491. COMMA: 188,
  7492. PERIOD: 190,
  7493. A: 65,
  7494. Z: 90,
  7495. ZERO: 48,
  7496. NUMPAD_0: 96,
  7497. NUMPAD_9: 105
  7498. };
  7499. /**
  7500. * Copyright (c) 2013-present, Facebook, Inc.
  7501. * All rights reserved.
  7502. *
  7503. * This source code is licensed under the BSD-style license found in the
  7504. * LICENSE file in the root directory of this source tree. An additional grant
  7505. * of patent rights can be found in the PATENTS file in the same directory.
  7506. *
  7507. * @providesModule getEntityKeyForSelection
  7508. * @format
  7509. *
  7510. */
  7511. /**
  7512. * Return the entity key that should be used when inserting text for the
  7513. * specified target selection, only if the entity is `MUTABLE`. `IMMUTABLE`
  7514. * and `SEGMENTED` entities should not be used for insertion behavior.
  7515. */
  7516. function getEntityKeyForSelection(contentState, targetSelection) {
  7517. var entityKey;
  7518. if (targetSelection.isCollapsed()) {
  7519. var key = targetSelection.getAnchorKey();
  7520. var offset = targetSelection.getAnchorOffset();
  7521. if (offset > 0) {
  7522. entityKey = contentState.getBlockForKey(key).getEntityAt(offset - 1);
  7523. if (entityKey !== contentState.getBlockForKey(key).getEntityAt(offset)) {
  7524. return null;
  7525. }
  7526. return filterKey(contentState.getEntityMap(), entityKey);
  7527. }
  7528. return null;
  7529. }
  7530. var startKey = targetSelection.getStartKey();
  7531. var startOffset = targetSelection.getStartOffset();
  7532. var startBlock = contentState.getBlockForKey(startKey);
  7533. entityKey = startOffset === startBlock.getLength() ? null : startBlock.getEntityAt(startOffset);
  7534. return filterKey(contentState.getEntityMap(), entityKey);
  7535. }
  7536. /**
  7537. * Determine whether an entity key corresponds to a `MUTABLE` entity. If so,
  7538. * return it. If not, return null.
  7539. */
  7540. function filterKey(entityMap, entityKey) {
  7541. if (entityKey) {
  7542. var entity = entityMap.__get(entityKey);
  7543. return entity.getMutability() === 'MUTABLE' ? entityKey : null;
  7544. }
  7545. return null;
  7546. }
  7547. var getEntityKeyForSelection_1 = getEntityKeyForSelection;
  7548. /**
  7549. * Copyright (c) 2013-present, Facebook, Inc.
  7550. * All rights reserved.
  7551. *
  7552. * This source code is licensed under the BSD-style license found in the
  7553. * LICENSE file in the root directory of this source tree. An additional grant
  7554. * of patent rights can be found in the PATENTS file in the same directory.
  7555. *
  7556. * @providesModule isEventHandled
  7557. * @format
  7558. *
  7559. */
  7560. /**
  7561. * Utility method for determining whether or not the value returned
  7562. * from a handler indicates that it was handled.
  7563. */
  7564. function isEventHandled(value) {
  7565. return value === 'handled' || value === true;
  7566. }
  7567. var isEventHandled_1 = isEventHandled;
  7568. /**
  7569. * Copyright (c) 2013-present, Facebook, Inc.
  7570. * All rights reserved.
  7571. *
  7572. * This source code is licensed under the BSD-style license found in the
  7573. * LICENSE file in the root directory of this source tree. An additional grant
  7574. * of patent rights can be found in the PATENTS file in the same directory.
  7575. *
  7576. * @providesModule isSelectionAtLeafStart
  7577. * @format
  7578. *
  7579. */
  7580. function isSelectionAtLeafStart(editorState) {
  7581. var selection = editorState.getSelection();
  7582. var anchorKey = selection.getAnchorKey();
  7583. var blockTree = editorState.getBlockTree(anchorKey);
  7584. var offset = selection.getStartOffset();
  7585. var isAtStart = false;
  7586. blockTree.some(function (leafSet) {
  7587. if (offset === leafSet.get('start')) {
  7588. isAtStart = true;
  7589. return true;
  7590. }
  7591. if (offset < leafSet.get('end')) {
  7592. return leafSet.get('leaves').some(function (leaf) {
  7593. var leafStart = leaf.get('start');
  7594. if (offset === leafStart) {
  7595. isAtStart = true;
  7596. return true;
  7597. }
  7598. return false;
  7599. });
  7600. }
  7601. return false;
  7602. });
  7603. return isAtStart;
  7604. }
  7605. var isSelectionAtLeafStart_1 = isSelectionAtLeafStart;
  7606. /**
  7607. * Millisecond delay to allow `compositionstart` to fire again upon
  7608. * `compositionend`.
  7609. *
  7610. * This is used for Korean input to ensure that typing can continue without
  7611. * the editor trying to render too quickly. More specifically, Safari 7.1+
  7612. * triggers `compositionstart` a little slower than Chrome/FF, which
  7613. * leads to composed characters being resolved and re-render occurring
  7614. * sooner than we want.
  7615. */
  7616. var RESOLVE_DELAY = 20;
  7617. /**
  7618. * A handful of variables used to track the current composition and its
  7619. * resolution status. These exist at the module level because it is not
  7620. * possible to have compositions occurring in multiple editors simultaneously,
  7621. * and it simplifies state management with respect to the DraftEditor component.
  7622. */
  7623. var resolved = false;
  7624. var stillComposing = false;
  7625. var textInputData = '';
  7626. var DraftEditorCompositionHandler = {
  7627. onBeforeInput: function onBeforeInput(editor, e) {
  7628. textInputData = (textInputData || '') + e.data;
  7629. },
  7630. /**
  7631. * A `compositionstart` event has fired while we're still in composition
  7632. * mode. Continue the current composition session to prevent a re-render.
  7633. */
  7634. onCompositionStart: function onCompositionStart(editor) {
  7635. stillComposing = true;
  7636. },
  7637. /**
  7638. * Attempt to end the current composition session.
  7639. *
  7640. * Defer handling because browser will still insert the chars into active
  7641. * element after `compositionend`. If a `compositionstart` event fires
  7642. * before `resolveComposition` executes, our composition session will
  7643. * continue.
  7644. *
  7645. * The `resolved` flag is useful because certain IME interfaces fire the
  7646. * `compositionend` event multiple times, thus queueing up multiple attempts
  7647. * at handling the composition. Since handling the same composition event
  7648. * twice could break the DOM, we only use the first event. Example: Arabic
  7649. * Google Input Tools on Windows 8.1 fires `compositionend` three times.
  7650. */
  7651. onCompositionEnd: function onCompositionEnd(editor) {
  7652. resolved = false;
  7653. stillComposing = false;
  7654. setTimeout(function () {
  7655. if (!resolved) {
  7656. DraftEditorCompositionHandler.resolveComposition(editor);
  7657. }
  7658. }, RESOLVE_DELAY);
  7659. },
  7660. /**
  7661. * In Safari, keydown events may fire when committing compositions. If
  7662. * the arrow keys are used to commit, prevent default so that the cursor
  7663. * doesn't move, otherwise it will jump back noticeably on re-render.
  7664. */
  7665. onKeyDown: function onKeyDown(editor, e) {
  7666. if (!stillComposing) {
  7667. // If a keydown event is received after compositionend but before the
  7668. // 20ms timer expires (ex: type option-E then backspace, or type A then
  7669. // backspace in 2-Set Korean), we should immediately resolve the
  7670. // composition and reinterpret the key press in edit mode.
  7671. DraftEditorCompositionHandler.resolveComposition(editor);
  7672. editor._onKeyDown(e);
  7673. return;
  7674. }
  7675. if (e.which === Keys.RIGHT || e.which === Keys.LEFT) {
  7676. e.preventDefault();
  7677. }
  7678. },
  7679. /**
  7680. * Keypress events may fire when committing compositions. In Firefox,
  7681. * pressing RETURN commits the composition and inserts extra newline
  7682. * characters that we do not want. `preventDefault` allows the composition
  7683. * to be committed while preventing the extra characters.
  7684. */
  7685. onKeyPress: function onKeyPress(editor, e) {
  7686. if (e.which === Keys.RETURN) {
  7687. e.preventDefault();
  7688. }
  7689. },
  7690. /**
  7691. * Attempt to insert composed characters into the document.
  7692. *
  7693. * If we are still in a composition session, do nothing. Otherwise, insert
  7694. * the characters into the document and terminate the composition session.
  7695. *
  7696. * If no characters were composed -- for instance, the user
  7697. * deleted all composed characters and committed nothing new --
  7698. * force a re-render. We also re-render when the composition occurs
  7699. * at the beginning of a leaf, to ensure that if the browser has
  7700. * created a new text node for the composition, we will discard it.
  7701. *
  7702. * Resetting innerHTML will move focus to the beginning of the editor,
  7703. * so we update to force it back to the correct place.
  7704. */
  7705. resolveComposition: function resolveComposition(editor) {
  7706. if (stillComposing) {
  7707. return;
  7708. }
  7709. resolved = true;
  7710. var composedChars = textInputData;
  7711. textInputData = '';
  7712. var editorState = EditorState_1.set(editor._latestEditorState, {
  7713. inCompositionMode: false
  7714. });
  7715. var currentStyle = editorState.getCurrentInlineStyle();
  7716. var entityKey = getEntityKeyForSelection_1(editorState.getCurrentContent(), editorState.getSelection());
  7717. var mustReset = !composedChars || isSelectionAtLeafStart_1(editorState) || currentStyle.size > 0 || entityKey !== null;
  7718. if (mustReset) {
  7719. editor.restoreEditorDOM();
  7720. }
  7721. editor.exitCurrentMode();
  7722. if (composedChars) {
  7723. // If characters have been composed, re-rendering with the update
  7724. // is sufficient to reset the editor.
  7725. var contentState = DraftModifier_1.replaceText(editorState.getCurrentContent(), editorState.getSelection(), composedChars, currentStyle, entityKey);
  7726. editor.update(EditorState_1.push(editorState, contentState, 'insert-characters'));
  7727. return;
  7728. }
  7729. if (mustReset) {
  7730. editor.update(EditorState_1.set(editorState, {
  7731. nativelyRenderedContent: null,
  7732. forceSelection: true
  7733. }));
  7734. }
  7735. }
  7736. };
  7737. var DraftEditorCompositionHandler_1 = DraftEditorCompositionHandler;
  7738. var uaParser = createCommonjsModule(function (module, exports) {
  7739. /*!
  7740. * UAParser.js v0.7.21
  7741. * Lightweight JavaScript-based User-Agent string parser
  7742. * https://github.com/faisalman/ua-parser-js
  7743. *
  7744. * Copyright © 2012-2019 Faisal Salman <f@faisalman.com>
  7745. * Licensed under MIT License
  7746. */
  7747. (function (window, undefined$1) {
  7748. //////////////
  7749. // Constants
  7750. /////////////
  7751. var LIBVERSION = '0.7.21',
  7752. EMPTY = '',
  7753. UNKNOWN = '?',
  7754. FUNC_TYPE = 'function',
  7755. OBJ_TYPE = 'object',
  7756. STR_TYPE = 'string',
  7757. MAJOR = 'major', // deprecated
  7758. MODEL = 'model',
  7759. NAME = 'name',
  7760. TYPE = 'type',
  7761. VENDOR = 'vendor',
  7762. VERSION = 'version',
  7763. ARCHITECTURE= 'architecture',
  7764. CONSOLE = 'console',
  7765. MOBILE = 'mobile',
  7766. TABLET = 'tablet',
  7767. SMARTTV = 'smarttv',
  7768. WEARABLE = 'wearable',
  7769. EMBEDDED = 'embedded';
  7770. ///////////
  7771. // Helper
  7772. //////////
  7773. var util = {
  7774. extend : function (regexes, extensions) {
  7775. var mergedRegexes = {};
  7776. for (var i in regexes) {
  7777. if (extensions[i] && extensions[i].length % 2 === 0) {
  7778. mergedRegexes[i] = extensions[i].concat(regexes[i]);
  7779. } else {
  7780. mergedRegexes[i] = regexes[i];
  7781. }
  7782. }
  7783. return mergedRegexes;
  7784. },
  7785. has : function (str1, str2) {
  7786. if (typeof str1 === "string") {
  7787. return str2.toLowerCase().indexOf(str1.toLowerCase()) !== -1;
  7788. } else {
  7789. return false;
  7790. }
  7791. },
  7792. lowerize : function (str) {
  7793. return str.toLowerCase();
  7794. },
  7795. major : function (version) {
  7796. return typeof(version) === STR_TYPE ? version.replace(/[^\d\.]/g,'').split(".")[0] : undefined$1;
  7797. },
  7798. trim : function (str) {
  7799. return str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
  7800. }
  7801. };
  7802. ///////////////
  7803. // Map helper
  7804. //////////////
  7805. var mapper = {
  7806. rgx : function (ua, arrays) {
  7807. var i = 0, j, k, p, q, matches, match;
  7808. // loop through all regexes maps
  7809. while (i < arrays.length && !matches) {
  7810. var regex = arrays[i], // even sequence (0,2,4,..)
  7811. props = arrays[i + 1]; // odd sequence (1,3,5,..)
  7812. j = k = 0;
  7813. // try matching uastring with regexes
  7814. while (j < regex.length && !matches) {
  7815. matches = regex[j++].exec(ua);
  7816. if (!!matches) {
  7817. for (p = 0; p < props.length; p++) {
  7818. match = matches[++k];
  7819. q = props[p];
  7820. // check if given property is actually array
  7821. if (typeof q === OBJ_TYPE && q.length > 0) {
  7822. if (q.length == 2) {
  7823. if (typeof q[1] == FUNC_TYPE) {
  7824. // assign modified match
  7825. this[q[0]] = q[1].call(this, match);
  7826. } else {
  7827. // assign given value, ignore regex match
  7828. this[q[0]] = q[1];
  7829. }
  7830. } else if (q.length == 3) {
  7831. // check whether function or regex
  7832. if (typeof q[1] === FUNC_TYPE && !(q[1].exec && q[1].test)) {
  7833. // call function (usually string mapper)
  7834. this[q[0]] = match ? q[1].call(this, match, q[2]) : undefined$1;
  7835. } else {
  7836. // sanitize match using given regex
  7837. this[q[0]] = match ? match.replace(q[1], q[2]) : undefined$1;
  7838. }
  7839. } else if (q.length == 4) {
  7840. this[q[0]] = match ? q[3].call(this, match.replace(q[1], q[2])) : undefined$1;
  7841. }
  7842. } else {
  7843. this[q] = match ? match : undefined$1;
  7844. }
  7845. }
  7846. }
  7847. }
  7848. i += 2;
  7849. }
  7850. },
  7851. str : function (str, map) {
  7852. for (var i in map) {
  7853. // check if array
  7854. if (typeof map[i] === OBJ_TYPE && map[i].length > 0) {
  7855. for (var j = 0; j < map[i].length; j++) {
  7856. if (util.has(map[i][j], str)) {
  7857. return (i === UNKNOWN) ? undefined$1 : i;
  7858. }
  7859. }
  7860. } else if (util.has(map[i], str)) {
  7861. return (i === UNKNOWN) ? undefined$1 : i;
  7862. }
  7863. }
  7864. return str;
  7865. }
  7866. };
  7867. ///////////////
  7868. // String map
  7869. //////////////
  7870. var maps = {
  7871. browser : {
  7872. oldsafari : {
  7873. version : {
  7874. '1.0' : '/8',
  7875. '1.2' : '/1',
  7876. '1.3' : '/3',
  7877. '2.0' : '/412',
  7878. '2.0.2' : '/416',
  7879. '2.0.3' : '/417',
  7880. '2.0.4' : '/419',
  7881. '?' : '/'
  7882. }
  7883. }
  7884. },
  7885. device : {
  7886. amazon : {
  7887. model : {
  7888. 'Fire Phone' : ['SD', 'KF']
  7889. }
  7890. },
  7891. sprint : {
  7892. model : {
  7893. 'Evo Shift 4G' : '7373KT'
  7894. },
  7895. vendor : {
  7896. 'HTC' : 'APA',
  7897. 'Sprint' : 'Sprint'
  7898. }
  7899. }
  7900. },
  7901. os : {
  7902. windows : {
  7903. version : {
  7904. 'ME' : '4.90',
  7905. 'NT 3.11' : 'NT3.51',
  7906. 'NT 4.0' : 'NT4.0',
  7907. '2000' : 'NT 5.0',
  7908. 'XP' : ['NT 5.1', 'NT 5.2'],
  7909. 'Vista' : 'NT 6.0',
  7910. '7' : 'NT 6.1',
  7911. '8' : 'NT 6.2',
  7912. '8.1' : 'NT 6.3',
  7913. '10' : ['NT 6.4', 'NT 10.0'],
  7914. 'RT' : 'ARM'
  7915. }
  7916. }
  7917. }
  7918. };
  7919. //////////////
  7920. // Regex map
  7921. /////////////
  7922. var regexes = {
  7923. browser : [[
  7924. // Presto based
  7925. /(opera\smini)\/([\w\.-]+)/i, // Opera Mini
  7926. /(opera\s[mobiletab]+).+version\/([\w\.-]+)/i, // Opera Mobi/Tablet
  7927. /(opera).+version\/([\w\.]+)/i, // Opera > 9.80
  7928. /(opera)[\/\s]+([\w\.]+)/i // Opera < 9.80
  7929. ], [NAME, VERSION], [
  7930. /(opios)[\/\s]+([\w\.]+)/i // Opera mini on iphone >= 8.0
  7931. ], [[NAME, 'Opera Mini'], VERSION], [
  7932. /\s(opr)\/([\w\.]+)/i // Opera Webkit
  7933. ], [[NAME, 'Opera'], VERSION], [
  7934. // Mixed
  7935. /(kindle)\/([\w\.]+)/i, // Kindle
  7936. /(lunascape|maxthon|netfront|jasmine|blazer)[\/\s]?([\w\.]*)/i,
  7937. // Lunascape/Maxthon/Netfront/Jasmine/Blazer
  7938. // Trident based
  7939. /(avant\s|iemobile|slim)(?:browser)?[\/\s]?([\w\.]*)/i,
  7940. // Avant/IEMobile/SlimBrowser
  7941. /(bidubrowser|baidubrowser)[\/\s]?([\w\.]+)/i, // Baidu Browser
  7942. /(?:ms|\()(ie)\s([\w\.]+)/i, // Internet Explorer
  7943. // Webkit/KHTML based
  7944. /(rekonq)\/([\w\.]*)/i, // Rekonq
  7945. /(chromium|flock|rockmelt|midori|epiphany|silk|skyfire|ovibrowser|bolt|iron|vivaldi|iridium|phantomjs|bowser|quark|qupzilla|falkon)\/([\w\.-]+)/i
  7946. // Chromium/Flock/RockMelt/Midori/Epiphany/Silk/Skyfire/Bolt/Iron/Iridium/PhantomJS/Bowser/QupZilla/Falkon
  7947. ], [NAME, VERSION], [
  7948. /(konqueror)\/([\w\.]+)/i // Konqueror
  7949. ], [[NAME, 'Konqueror'], VERSION], [
  7950. /(trident).+rv[:\s]([\w\.]+).+like\sgecko/i // IE11
  7951. ], [[NAME, 'IE'], VERSION], [
  7952. /(edge|edgios|edga|edg)\/((\d+)?[\w\.]+)/i // Microsoft Edge
  7953. ], [[NAME, 'Edge'], VERSION], [
  7954. /(yabrowser)\/([\w\.]+)/i // Yandex
  7955. ], [[NAME, 'Yandex'], VERSION], [
  7956. /(Avast)\/([\w\.]+)/i // Avast Secure Browser
  7957. ], [[NAME, 'Avast Secure Browser'], VERSION], [
  7958. /(AVG)\/([\w\.]+)/i // AVG Secure Browser
  7959. ], [[NAME, 'AVG Secure Browser'], VERSION], [
  7960. /(puffin)\/([\w\.]+)/i // Puffin
  7961. ], [[NAME, 'Puffin'], VERSION], [
  7962. /(focus)\/([\w\.]+)/i // Firefox Focus
  7963. ], [[NAME, 'Firefox Focus'], VERSION], [
  7964. /(opt)\/([\w\.]+)/i // Opera Touch
  7965. ], [[NAME, 'Opera Touch'], VERSION], [
  7966. /((?:[\s\/])uc?\s?browser|(?:juc.+)ucweb)[\/\s]?([\w\.]+)/i // UCBrowser
  7967. ], [[NAME, 'UCBrowser'], VERSION], [
  7968. /(comodo_dragon)\/([\w\.]+)/i // Comodo Dragon
  7969. ], [[NAME, /_/g, ' '], VERSION], [
  7970. /(windowswechat qbcore)\/([\w\.]+)/i // WeChat Desktop for Windows Built-in Browser
  7971. ], [[NAME, 'WeChat(Win) Desktop'], VERSION], [
  7972. /(micromessenger)\/([\w\.]+)/i // WeChat
  7973. ], [[NAME, 'WeChat'], VERSION], [
  7974. /(brave)\/([\w\.]+)/i // Brave browser
  7975. ], [[NAME, 'Brave'], VERSION], [
  7976. /(qqbrowserlite)\/([\w\.]+)/i // QQBrowserLite
  7977. ], [NAME, VERSION], [
  7978. /(QQ)\/([\d\.]+)/i // QQ, aka ShouQ
  7979. ], [NAME, VERSION], [
  7980. /m?(qqbrowser)[\/\s]?([\w\.]+)/i // QQBrowser
  7981. ], [NAME, VERSION], [
  7982. /(baiduboxapp)[\/\s]?([\w\.]+)/i // Baidu App
  7983. ], [NAME, VERSION], [
  7984. /(2345Explorer)[\/\s]?([\w\.]+)/i // 2345 Browser
  7985. ], [NAME, VERSION], [
  7986. /(MetaSr)[\/\s]?([\w\.]+)/i // SouGouBrowser
  7987. ], [NAME], [
  7988. /(LBBROWSER)/i // LieBao Browser
  7989. ], [NAME], [
  7990. /xiaomi\/miuibrowser\/([\w\.]+)/i // MIUI Browser
  7991. ], [VERSION, [NAME, 'MIUI Browser']], [
  7992. /;fbav\/([\w\.]+);/i // Facebook App for iOS & Android
  7993. ], [VERSION, [NAME, 'Facebook']], [
  7994. /safari\s(line)\/([\w\.]+)/i, // Line App for iOS
  7995. /android.+(line)\/([\w\.]+)\/iab/i // Line App for Android
  7996. ], [NAME, VERSION], [
  7997. /headlesschrome(?:\/([\w\.]+)|\s)/i // Chrome Headless
  7998. ], [VERSION, [NAME, 'Chrome Headless']], [
  7999. /\swv\).+(chrome)\/([\w\.]+)/i // Chrome WebView
  8000. ], [[NAME, /(.+)/, '$1 WebView'], VERSION], [
  8001. /((?:oculus|samsung)browser)\/([\w\.]+)/i
  8002. ], [[NAME, /(.+(?:g|us))(.+)/, '$1 $2'], VERSION], [ // Oculus / Samsung Browser
  8003. /android.+version\/([\w\.]+)\s+(?:mobile\s?safari|safari)*/i // Android Browser
  8004. ], [VERSION, [NAME, 'Android Browser']], [
  8005. /(sailfishbrowser)\/([\w\.]+)/i // Sailfish Browser
  8006. ], [[NAME, 'Sailfish Browser'], VERSION], [
  8007. /(chrome|omniweb|arora|[tizenoka]{5}\s?browser)\/v?([\w\.]+)/i
  8008. // Chrome/OmniWeb/Arora/Tizen/Nokia
  8009. ], [NAME, VERSION], [
  8010. /(dolfin)\/([\w\.]+)/i // Dolphin
  8011. ], [[NAME, 'Dolphin'], VERSION], [
  8012. /(qihu|qhbrowser|qihoobrowser|360browser)/i // 360
  8013. ], [[NAME, '360 Browser']], [
  8014. /((?:android.+)crmo|crios)\/([\w\.]+)/i // Chrome for Android/iOS
  8015. ], [[NAME, 'Chrome'], VERSION], [
  8016. /(coast)\/([\w\.]+)/i // Opera Coast
  8017. ], [[NAME, 'Opera Coast'], VERSION], [
  8018. /fxios\/([\w\.-]+)/i // Firefox for iOS
  8019. ], [VERSION, [NAME, 'Firefox']], [
  8020. /version\/([\w\.]+).+?mobile\/\w+\s(safari)/i // Mobile Safari
  8021. ], [VERSION, [NAME, 'Mobile Safari']], [
  8022. /version\/([\w\.]+).+?(mobile\s?safari|safari)/i // Safari & Safari Mobile
  8023. ], [VERSION, NAME], [
  8024. /webkit.+?(gsa)\/([\w\.]+).+?(mobile\s?safari|safari)(\/[\w\.]+)/i // Google Search Appliance on iOS
  8025. ], [[NAME, 'GSA'], VERSION], [
  8026. /webkit.+?(mobile\s?safari|safari)(\/[\w\.]+)/i // Safari < 3.0
  8027. ], [NAME, [VERSION, mapper.str, maps.browser.oldsafari.version]], [
  8028. /(webkit|khtml)\/([\w\.]+)/i
  8029. ], [NAME, VERSION], [
  8030. // Gecko based
  8031. /(navigator|netscape)\/([\w\.-]+)/i // Netscape
  8032. ], [[NAME, 'Netscape'], VERSION], [
  8033. /(swiftfox)/i, // Swiftfox
  8034. /(icedragon|iceweasel|camino|chimera|fennec|maemo\sbrowser|minimo|conkeror)[\/\s]?([\w\.\+]+)/i,
  8035. // IceDragon/Iceweasel/Camino/Chimera/Fennec/Maemo/Minimo/Conkeror
  8036. /(firefox|seamonkey|k-meleon|icecat|iceape|firebird|phoenix|palemoon|basilisk|waterfox)\/([\w\.-]+)$/i,
  8037. // Firefox/SeaMonkey/K-Meleon/IceCat/IceApe/Firebird/Phoenix
  8038. /(mozilla)\/([\w\.]+).+rv\:.+gecko\/\d+/i, // Mozilla
  8039. // Other
  8040. /(polaris|lynx|dillo|icab|doris|amaya|w3m|netsurf|sleipnir)[\/\s]?([\w\.]+)/i,
  8041. // Polaris/Lynx/Dillo/iCab/Doris/Amaya/w3m/NetSurf/Sleipnir
  8042. /(links)\s\(([\w\.]+)/i, // Links
  8043. /(gobrowser)\/?([\w\.]*)/i, // GoBrowser
  8044. /(ice\s?browser)\/v?([\w\._]+)/i, // ICE Browser
  8045. /(mosaic)[\/\s]([\w\.]+)/i // Mosaic
  8046. ], [NAME, VERSION]
  8047. ],
  8048. cpu : [[
  8049. /(?:(amd|x(?:(?:86|64)[_-])?|wow|win)64)[;\)]/i // AMD64
  8050. ], [[ARCHITECTURE, 'amd64']], [
  8051. /(ia32(?=;))/i // IA32 (quicktime)
  8052. ], [[ARCHITECTURE, util.lowerize]], [
  8053. /((?:i[346]|x)86)[;\)]/i // IA32
  8054. ], [[ARCHITECTURE, 'ia32']], [
  8055. // PocketPC mistakenly identified as PowerPC
  8056. /windows\s(ce|mobile);\sppc;/i
  8057. ], [[ARCHITECTURE, 'arm']], [
  8058. /((?:ppc|powerpc)(?:64)?)(?:\smac|;|\))/i // PowerPC
  8059. ], [[ARCHITECTURE, /ower/, '', util.lowerize]], [
  8060. /(sun4\w)[;\)]/i // SPARC
  8061. ], [[ARCHITECTURE, 'sparc']], [
  8062. /((?:avr32|ia64(?=;))|68k(?=\))|arm(?:64|(?=v\d+[;l]))|(?=atmel\s)avr|(?:irix|mips|sparc)(?:64)?(?=;)|pa-risc)/i
  8063. // IA64, 68K, ARM/64, AVR/32, IRIX/64, MIPS/64, SPARC/64, PA-RISC
  8064. ], [[ARCHITECTURE, util.lowerize]]
  8065. ],
  8066. device : [[
  8067. /\((ipad|playbook);[\w\s\),;-]+(rim|apple)/i // iPad/PlayBook
  8068. ], [MODEL, VENDOR, [TYPE, TABLET]], [
  8069. /applecoremedia\/[\w\.]+ \((ipad)/ // iPad
  8070. ], [MODEL, [VENDOR, 'Apple'], [TYPE, TABLET]], [
  8071. /(apple\s{0,1}tv)/i // Apple TV
  8072. ], [[MODEL, 'Apple TV'], [VENDOR, 'Apple'], [TYPE, SMARTTV]], [
  8073. /(archos)\s(gamepad2?)/i, // Archos
  8074. /(hp).+(touchpad)/i, // HP TouchPad
  8075. /(hp).+(tablet)/i, // HP Tablet
  8076. /(kindle)\/([\w\.]+)/i, // Kindle
  8077. /\s(nook)[\w\s]+build\/(\w+)/i, // Nook
  8078. /(dell)\s(strea[kpr\s\d]*[\dko])/i // Dell Streak
  8079. ], [VENDOR, MODEL, [TYPE, TABLET]], [
  8080. /(kf[A-z]+)\sbuild\/.+silk\//i // Kindle Fire HD
  8081. ], [MODEL, [VENDOR, 'Amazon'], [TYPE, TABLET]], [
  8082. /(sd|kf)[0349hijorstuw]+\sbuild\/.+silk\//i // Fire Phone
  8083. ], [[MODEL, mapper.str, maps.device.amazon.model], [VENDOR, 'Amazon'], [TYPE, MOBILE]], [
  8084. /android.+aft([bms])\sbuild/i // Fire TV
  8085. ], [MODEL, [VENDOR, 'Amazon'], [TYPE, SMARTTV]], [
  8086. /\((ip[honed|\s\w*]+);.+(apple)/i // iPod/iPhone
  8087. ], [MODEL, VENDOR, [TYPE, MOBILE]], [
  8088. /\((ip[honed|\s\w*]+);/i // iPod/iPhone
  8089. ], [MODEL, [VENDOR, 'Apple'], [TYPE, MOBILE]], [
  8090. /(blackberry)[\s-]?(\w+)/i, // BlackBerry
  8091. /(blackberry|benq|palm(?=\-)|sonyericsson|acer|asus|dell|meizu|motorola|polytron)[\s_-]?([\w-]*)/i,
  8092. // BenQ/Palm/Sony-Ericsson/Acer/Asus/Dell/Meizu/Motorola/Polytron
  8093. /(hp)\s([\w\s]+\w)/i, // HP iPAQ
  8094. /(asus)-?(\w+)/i // Asus
  8095. ], [VENDOR, MODEL, [TYPE, MOBILE]], [
  8096. /\(bb10;\s(\w+)/i // BlackBerry 10
  8097. ], [MODEL, [VENDOR, 'BlackBerry'], [TYPE, MOBILE]], [
  8098. // Asus Tablets
  8099. /android.+(transfo[prime\s]{4,10}\s\w+|eeepc|slider\s\w+|nexus 7|padfone|p00c)/i
  8100. ], [MODEL, [VENDOR, 'Asus'], [TYPE, TABLET]], [
  8101. /(sony)\s(tablet\s[ps])\sbuild\//i, // Sony
  8102. /(sony)?(?:sgp.+)\sbuild\//i
  8103. ], [[VENDOR, 'Sony'], [MODEL, 'Xperia Tablet'], [TYPE, TABLET]], [
  8104. /android.+\s([c-g]\d{4}|so[-l]\w+)(?=\sbuild\/|\).+chrome\/(?![1-6]{0,1}\d\.))/i
  8105. ], [MODEL, [VENDOR, 'Sony'], [TYPE, MOBILE]], [
  8106. /\s(ouya)\s/i, // Ouya
  8107. /(nintendo)\s([wids3u]+)/i // Nintendo
  8108. ], [VENDOR, MODEL, [TYPE, CONSOLE]], [
  8109. /android.+;\s(shield)\sbuild/i // Nvidia
  8110. ], [MODEL, [VENDOR, 'Nvidia'], [TYPE, CONSOLE]], [
  8111. /(playstation\s[34portablevi]+)/i // Playstation
  8112. ], [MODEL, [VENDOR, 'Sony'], [TYPE, CONSOLE]], [
  8113. /(sprint\s(\w+))/i // Sprint Phones
  8114. ], [[VENDOR, mapper.str, maps.device.sprint.vendor], [MODEL, mapper.str, maps.device.sprint.model], [TYPE, MOBILE]], [
  8115. /(htc)[;_\s-]+([\w\s]+(?=\)|\sbuild)|\w+)/i, // HTC
  8116. /(zte)-(\w*)/i, // ZTE
  8117. /(alcatel|geeksphone|nexian|panasonic|(?=;\s)sony)[_\s-]?([\w-]*)/i
  8118. // Alcatel/GeeksPhone/Nexian/Panasonic/Sony
  8119. ], [VENDOR, [MODEL, /_/g, ' '], [TYPE, MOBILE]], [
  8120. /(nexus\s9)/i // HTC Nexus 9
  8121. ], [MODEL, [VENDOR, 'HTC'], [TYPE, TABLET]], [
  8122. /d\/huawei([\w\s-]+)[;\)]/i,
  8123. /(nexus\s6p|vog-l29|ane-lx1|eml-l29)/i // Huawei
  8124. ], [MODEL, [VENDOR, 'Huawei'], [TYPE, MOBILE]], [
  8125. /android.+(bah2?-a?[lw]\d{2})/i // Huawei MediaPad
  8126. ], [MODEL, [VENDOR, 'Huawei'], [TYPE, TABLET]], [
  8127. /(microsoft);\s(lumia[\s\w]+)/i // Microsoft Lumia
  8128. ], [VENDOR, MODEL, [TYPE, MOBILE]], [
  8129. /[\s\(;](xbox(?:\sone)?)[\s\);]/i // Microsoft Xbox
  8130. ], [MODEL, [VENDOR, 'Microsoft'], [TYPE, CONSOLE]], [
  8131. /(kin\.[onetw]{3})/i // Microsoft Kin
  8132. ], [[MODEL, /\./g, ' '], [VENDOR, 'Microsoft'], [TYPE, MOBILE]], [
  8133. // Motorola
  8134. /\s(milestone|droid(?:[2-4x]|\s(?:bionic|x2|pro|razr))?:?(\s4g)?)[\w\s]+build\//i,
  8135. /mot[\s-]?(\w*)/i,
  8136. /(XT\d{3,4}) build\//i,
  8137. /(nexus\s6)/i
  8138. ], [MODEL, [VENDOR, 'Motorola'], [TYPE, MOBILE]], [
  8139. /android.+\s(mz60\d|xoom[\s2]{0,2})\sbuild\//i
  8140. ], [MODEL, [VENDOR, 'Motorola'], [TYPE, TABLET]], [
  8141. /hbbtv\/\d+\.\d+\.\d+\s+\([\w\s]*;\s*(\w[^;]*);([^;]*)/i // HbbTV devices
  8142. ], [[VENDOR, util.trim], [MODEL, util.trim], [TYPE, SMARTTV]], [
  8143. /hbbtv.+maple;(\d+)/i
  8144. ], [[MODEL, /^/, 'SmartTV'], [VENDOR, 'Samsung'], [TYPE, SMARTTV]], [
  8145. /\(dtv[\);].+(aquos)/i // Sharp
  8146. ], [MODEL, [VENDOR, 'Sharp'], [TYPE, SMARTTV]], [
  8147. /android.+((sch-i[89]0\d|shw-m380s|gt-p\d{4}|gt-n\d+|sgh-t8[56]9|nexus 10))/i,
  8148. /((SM-T\w+))/i
  8149. ], [[VENDOR, 'Samsung'], MODEL, [TYPE, TABLET]], [ // Samsung
  8150. /smart-tv.+(samsung)/i
  8151. ], [VENDOR, [TYPE, SMARTTV], MODEL], [
  8152. /((s[cgp]h-\w+|gt-\w+|galaxy\snexus|sm-\w[\w\d]+))/i,
  8153. /(sam[sung]*)[\s-]*(\w+-?[\w-]*)/i,
  8154. /sec-((sgh\w+))/i
  8155. ], [[VENDOR, 'Samsung'], MODEL, [TYPE, MOBILE]], [
  8156. /sie-(\w*)/i // Siemens
  8157. ], [MODEL, [VENDOR, 'Siemens'], [TYPE, MOBILE]], [
  8158. /(maemo|nokia).*(n900|lumia\s\d+)/i, // Nokia
  8159. /(nokia)[\s_-]?([\w-]*)/i
  8160. ], [[VENDOR, 'Nokia'], MODEL, [TYPE, MOBILE]], [
  8161. /android[x\d\.\s;]+\s([ab][1-7]\-?[0178a]\d\d?)/i // Acer
  8162. ], [MODEL, [VENDOR, 'Acer'], [TYPE, TABLET]], [
  8163. /android.+([vl]k\-?\d{3})\s+build/i // LG Tablet
  8164. ], [MODEL, [VENDOR, 'LG'], [TYPE, TABLET]], [
  8165. /android\s3\.[\s\w;-]{10}(lg?)-([06cv9]{3,4})/i // LG Tablet
  8166. ], [[VENDOR, 'LG'], MODEL, [TYPE, TABLET]], [
  8167. /(lg) netcast\.tv/i // LG SmartTV
  8168. ], [VENDOR, MODEL, [TYPE, SMARTTV]], [
  8169. /(nexus\s[45])/i, // LG
  8170. /lg[e;\s\/-]+(\w*)/i,
  8171. /android.+lg(\-?[\d\w]+)\s+build/i
  8172. ], [MODEL, [VENDOR, 'LG'], [TYPE, MOBILE]], [
  8173. /(lenovo)\s?(s(?:5000|6000)(?:[\w-]+)|tab(?:[\s\w]+))/i // Lenovo tablets
  8174. ], [VENDOR, MODEL, [TYPE, TABLET]], [
  8175. /android.+(ideatab[a-z0-9\-\s]+)/i // Lenovo
  8176. ], [MODEL, [VENDOR, 'Lenovo'], [TYPE, TABLET]], [
  8177. /(lenovo)[_\s-]?([\w-]+)/i
  8178. ], [VENDOR, MODEL, [TYPE, MOBILE]], [
  8179. /linux;.+((jolla));/i // Jolla
  8180. ], [VENDOR, MODEL, [TYPE, MOBILE]], [
  8181. /((pebble))app\/[\d\.]+\s/i // Pebble
  8182. ], [VENDOR, MODEL, [TYPE, WEARABLE]], [
  8183. /android.+;\s(oppo)\s?([\w\s]+)\sbuild/i // OPPO
  8184. ], [VENDOR, MODEL, [TYPE, MOBILE]], [
  8185. /crkey/i // Google Chromecast
  8186. ], [[MODEL, 'Chromecast'], [VENDOR, 'Google'], [TYPE, SMARTTV]], [
  8187. /android.+;\s(glass)\s\d/i // Google Glass
  8188. ], [MODEL, [VENDOR, 'Google'], [TYPE, WEARABLE]], [
  8189. /android.+;\s(pixel c)[\s)]/i // Google Pixel C
  8190. ], [MODEL, [VENDOR, 'Google'], [TYPE, TABLET]], [
  8191. /android.+;\s(pixel( [23])?( xl)?)[\s)]/i // Google Pixel
  8192. ], [MODEL, [VENDOR, 'Google'], [TYPE, MOBILE]], [
  8193. /android.+;\s(\w+)\s+build\/hm\1/i, // Xiaomi Hongmi 'numeric' models
  8194. /android.+(hm[\s\-_]*note?[\s_]*(?:\d\w)?)\s+build/i, // Xiaomi Hongmi
  8195. /android.+(mi[\s\-_]*(?:a\d|one|one[\s_]plus|note lte)?[\s_]*(?:\d?\w?)[\s_]*(?:plus)?)\s+build/i,
  8196. // Xiaomi Mi
  8197. /android.+(redmi[\s\-_]*(?:note)?(?:[\s_]*[\w\s]+))\s+build/i // Redmi Phones
  8198. ], [[MODEL, /_/g, ' '], [VENDOR, 'Xiaomi'], [TYPE, MOBILE]], [
  8199. /android.+(mi[\s\-_]*(?:pad)(?:[\s_]*[\w\s]+))\s+build/i // Mi Pad tablets
  8200. ],[[MODEL, /_/g, ' '], [VENDOR, 'Xiaomi'], [TYPE, TABLET]], [
  8201. /android.+;\s(m[1-5]\snote)\sbuild/i // Meizu
  8202. ], [MODEL, [VENDOR, 'Meizu'], [TYPE, MOBILE]], [
  8203. /(mz)-([\w-]{2,})/i
  8204. ], [[VENDOR, 'Meizu'], MODEL, [TYPE, MOBILE]], [
  8205. /android.+a000(1)\s+build/i, // OnePlus
  8206. /android.+oneplus\s(a\d{4})[\s)]/i
  8207. ], [MODEL, [VENDOR, 'OnePlus'], [TYPE, MOBILE]], [
  8208. /android.+[;\/]\s*(RCT[\d\w]+)\s+build/i // RCA Tablets
  8209. ], [MODEL, [VENDOR, 'RCA'], [TYPE, TABLET]], [
  8210. /android.+[;\/\s]+(Venue[\d\s]{2,7})\s+build/i // Dell Venue Tablets
  8211. ], [MODEL, [VENDOR, 'Dell'], [TYPE, TABLET]], [
  8212. /android.+[;\/]\s*(Q[T|M][\d\w]+)\s+build/i // Verizon Tablet
  8213. ], [MODEL, [VENDOR, 'Verizon'], [TYPE, TABLET]], [
  8214. /android.+[;\/]\s+(Barnes[&\s]+Noble\s+|BN[RT])(V?.*)\s+build/i // Barnes & Noble Tablet
  8215. ], [[VENDOR, 'Barnes & Noble'], MODEL, [TYPE, TABLET]], [
  8216. /android.+[;\/]\s+(TM\d{3}.*\b)\s+build/i // Barnes & Noble Tablet
  8217. ], [MODEL, [VENDOR, 'NuVision'], [TYPE, TABLET]], [
  8218. /android.+;\s(k88)\sbuild/i // ZTE K Series Tablet
  8219. ], [MODEL, [VENDOR, 'ZTE'], [TYPE, TABLET]], [
  8220. /android.+[;\/]\s*(gen\d{3})\s+build.*49h/i // Swiss GEN Mobile
  8221. ], [MODEL, [VENDOR, 'Swiss'], [TYPE, MOBILE]], [
  8222. /android.+[;\/]\s*(zur\d{3})\s+build/i // Swiss ZUR Tablet
  8223. ], [MODEL, [VENDOR, 'Swiss'], [TYPE, TABLET]], [
  8224. /android.+[;\/]\s*((Zeki)?TB.*\b)\s+build/i // Zeki Tablets
  8225. ], [MODEL, [VENDOR, 'Zeki'], [TYPE, TABLET]], [
  8226. /(android).+[;\/]\s+([YR]\d{2})\s+build/i,
  8227. /android.+[;\/]\s+(Dragon[\-\s]+Touch\s+|DT)(\w{5})\sbuild/i // Dragon Touch Tablet
  8228. ], [[VENDOR, 'Dragon Touch'], MODEL, [TYPE, TABLET]], [
  8229. /android.+[;\/]\s*(NS-?\w{0,9})\sbuild/i // Insignia Tablets
  8230. ], [MODEL, [VENDOR, 'Insignia'], [TYPE, TABLET]], [
  8231. /android.+[;\/]\s*((NX|Next)-?\w{0,9})\s+build/i // NextBook Tablets
  8232. ], [MODEL, [VENDOR, 'NextBook'], [TYPE, TABLET]], [
  8233. /android.+[;\/]\s*(Xtreme\_)?(V(1[045]|2[015]|30|40|60|7[05]|90))\s+build/i
  8234. ], [[VENDOR, 'Voice'], MODEL, [TYPE, MOBILE]], [ // Voice Xtreme Phones
  8235. /android.+[;\/]\s*(LVTEL\-)?(V1[12])\s+build/i // LvTel Phones
  8236. ], [[VENDOR, 'LvTel'], MODEL, [TYPE, MOBILE]], [
  8237. /android.+;\s(PH-1)\s/i
  8238. ], [MODEL, [VENDOR, 'Essential'], [TYPE, MOBILE]], [ // Essential PH-1
  8239. /android.+[;\/]\s*(V(100MD|700NA|7011|917G).*\b)\s+build/i // Envizen Tablets
  8240. ], [MODEL, [VENDOR, 'Envizen'], [TYPE, TABLET]], [
  8241. /android.+[;\/]\s*(Le[\s\-]+Pan)[\s\-]+(\w{1,9})\s+build/i // Le Pan Tablets
  8242. ], [VENDOR, MODEL, [TYPE, TABLET]], [
  8243. /android.+[;\/]\s*(Trio[\s\-]*.*)\s+build/i // MachSpeed Tablets
  8244. ], [MODEL, [VENDOR, 'MachSpeed'], [TYPE, TABLET]], [
  8245. /android.+[;\/]\s*(Trinity)[\-\s]*(T\d{3})\s+build/i // Trinity Tablets
  8246. ], [VENDOR, MODEL, [TYPE, TABLET]], [
  8247. /android.+[;\/]\s*TU_(1491)\s+build/i // Rotor Tablets
  8248. ], [MODEL, [VENDOR, 'Rotor'], [TYPE, TABLET]], [
  8249. /android.+(KS(.+))\s+build/i // Amazon Kindle Tablets
  8250. ], [MODEL, [VENDOR, 'Amazon'], [TYPE, TABLET]], [
  8251. /android.+(Gigaset)[\s\-]+(Q\w{1,9})\s+build/i // Gigaset Tablets
  8252. ], [VENDOR, MODEL, [TYPE, TABLET]], [
  8253. /\s(tablet|tab)[;\/]/i, // Unidentifiable Tablet
  8254. /\s(mobile)(?:[;\/]|\ssafari)/i // Unidentifiable Mobile
  8255. ], [[TYPE, util.lowerize], VENDOR, MODEL], [
  8256. /[\s\/\(](smart-?tv)[;\)]/i // SmartTV
  8257. ], [[TYPE, SMARTTV]], [
  8258. /(android[\w\.\s\-]{0,9});.+build/i // Generic Android Device
  8259. ], [MODEL, [VENDOR, 'Generic']]
  8260. ],
  8261. engine : [[
  8262. /windows.+\sedge\/([\w\.]+)/i // EdgeHTML
  8263. ], [VERSION, [NAME, 'EdgeHTML']], [
  8264. /webkit\/537\.36.+chrome\/(?!27)([\w\.]+)/i // Blink
  8265. ], [VERSION, [NAME, 'Blink']], [
  8266. /(presto)\/([\w\.]+)/i, // Presto
  8267. /(webkit|trident|netfront|netsurf|amaya|lynx|w3m|goanna)\/([\w\.]+)/i,
  8268. // WebKit/Trident/NetFront/NetSurf/Amaya/Lynx/w3m/Goanna
  8269. /(khtml|tasman|links)[\/\s]\(?([\w\.]+)/i, // KHTML/Tasman/Links
  8270. /(icab)[\/\s]([23]\.[\d\.]+)/i // iCab
  8271. ], [NAME, VERSION], [
  8272. /rv\:([\w\.]{1,9}).+(gecko)/i // Gecko
  8273. ], [VERSION, NAME]
  8274. ],
  8275. os : [[
  8276. // Windows based
  8277. /microsoft\s(windows)\s(vista|xp)/i // Windows (iTunes)
  8278. ], [NAME, VERSION], [
  8279. /(windows)\snt\s6\.2;\s(arm)/i, // Windows RT
  8280. /(windows\sphone(?:\sos)*)[\s\/]?([\d\.\s\w]*)/i, // Windows Phone
  8281. /(windows\smobile|windows)[\s\/]?([ntce\d\.\s]+\w)/i
  8282. ], [NAME, [VERSION, mapper.str, maps.os.windows.version]], [
  8283. /(win(?=3|9|n)|win\s9x\s)([nt\d\.]+)/i
  8284. ], [[NAME, 'Windows'], [VERSION, mapper.str, maps.os.windows.version]], [
  8285. // Mobile/Embedded OS
  8286. /\((bb)(10);/i // BlackBerry 10
  8287. ], [[NAME, 'BlackBerry'], VERSION], [
  8288. /(blackberry)\w*\/?([\w\.]*)/i, // Blackberry
  8289. /(tizen|kaios)[\/\s]([\w\.]+)/i, // Tizen/KaiOS
  8290. /(android|webos|palm\sos|qnx|bada|rim\stablet\sos|meego|sailfish|contiki)[\/\s-]?([\w\.]*)/i
  8291. // Android/WebOS/Palm/QNX/Bada/RIM/MeeGo/Contiki/Sailfish OS
  8292. ], [NAME, VERSION], [
  8293. /(symbian\s?os|symbos|s60(?=;))[\/\s-]?([\w\.]*)/i // Symbian
  8294. ], [[NAME, 'Symbian'], VERSION], [
  8295. /\((series40);/i // Series 40
  8296. ], [NAME], [
  8297. /mozilla.+\(mobile;.+gecko.+firefox/i // Firefox OS
  8298. ], [[NAME, 'Firefox OS'], VERSION], [
  8299. // Console
  8300. /(nintendo|playstation)\s([wids34portablevu]+)/i, // Nintendo/Playstation
  8301. // GNU/Linux based
  8302. /(mint)[\/\s\(]?(\w*)/i, // Mint
  8303. /(mageia|vectorlinux)[;\s]/i, // Mageia/VectorLinux
  8304. /(joli|[kxln]?ubuntu|debian|suse|opensuse|gentoo|(?=\s)arch|slackware|fedora|mandriva|centos|pclinuxos|redhat|zenwalk|linpus)[\/\s-]?(?!chrom)([\w\.-]*)/i,
  8305. // Joli/Ubuntu/Debian/SUSE/Gentoo/Arch/Slackware
  8306. // Fedora/Mandriva/CentOS/PCLinuxOS/RedHat/Zenwalk/Linpus
  8307. /(hurd|linux)\s?([\w\.]*)/i, // Hurd/Linux
  8308. /(gnu)\s?([\w\.]*)/i // GNU
  8309. ], [NAME, VERSION], [
  8310. /(cros)\s[\w]+\s([\w\.]+\w)/i // Chromium OS
  8311. ], [[NAME, 'Chromium OS'], VERSION],[
  8312. // Solaris
  8313. /(sunos)\s?([\w\.\d]*)/i // Solaris
  8314. ], [[NAME, 'Solaris'], VERSION], [
  8315. // BSD based
  8316. /\s([frentopc-]{0,4}bsd|dragonfly)\s?([\w\.]*)/i // FreeBSD/NetBSD/OpenBSD/PC-BSD/DragonFly
  8317. ], [NAME, VERSION],[
  8318. /(haiku)\s(\w+)/i // Haiku
  8319. ], [NAME, VERSION],[
  8320. /cfnetwork\/.+darwin/i,
  8321. /ip[honead]{2,4}(?:.*os\s([\w]+)\slike\smac|;\sopera)/i // iOS
  8322. ], [[VERSION, /_/g, '.'], [NAME, 'iOS']], [
  8323. /(mac\sos\sx)\s?([\w\s\.]*)/i,
  8324. /(macintosh|mac(?=_powerpc)\s)/i // Mac OS
  8325. ], [[NAME, 'Mac OS'], [VERSION, /_/g, '.']], [
  8326. // Other
  8327. /((?:open)?solaris)[\/\s-]?([\w\.]*)/i, // Solaris
  8328. /(aix)\s((\d)(?=\.|\)|\s)[\w\.])*/i, // AIX
  8329. /(plan\s9|minix|beos|os\/2|amigaos|morphos|risc\sos|openvms|fuchsia)/i,
  8330. // Plan9/Minix/BeOS/OS2/AmigaOS/MorphOS/RISCOS/OpenVMS/Fuchsia
  8331. /(unix)\s?([\w\.]*)/i // UNIX
  8332. ], [NAME, VERSION]
  8333. ]
  8334. };
  8335. /////////////////
  8336. // Constructor
  8337. ////////////////
  8338. var UAParser = function (uastring, extensions) {
  8339. if (typeof uastring === 'object') {
  8340. extensions = uastring;
  8341. uastring = undefined$1;
  8342. }
  8343. if (!(this instanceof UAParser)) {
  8344. return new UAParser(uastring, extensions).getResult();
  8345. }
  8346. var ua = uastring || ((window && window.navigator && window.navigator.userAgent) ? window.navigator.userAgent : EMPTY);
  8347. var rgxmap = extensions ? util.extend(regexes, extensions) : regexes;
  8348. this.getBrowser = function () {
  8349. var browser = { name: undefined$1, version: undefined$1 };
  8350. mapper.rgx.call(browser, ua, rgxmap.browser);
  8351. browser.major = util.major(browser.version); // deprecated
  8352. return browser;
  8353. };
  8354. this.getCPU = function () {
  8355. var cpu = { architecture: undefined$1 };
  8356. mapper.rgx.call(cpu, ua, rgxmap.cpu);
  8357. return cpu;
  8358. };
  8359. this.getDevice = function () {
  8360. var device = { vendor: undefined$1, model: undefined$1, type: undefined$1 };
  8361. mapper.rgx.call(device, ua, rgxmap.device);
  8362. return device;
  8363. };
  8364. this.getEngine = function () {
  8365. var engine = { name: undefined$1, version: undefined$1 };
  8366. mapper.rgx.call(engine, ua, rgxmap.engine);
  8367. return engine;
  8368. };
  8369. this.getOS = function () {
  8370. var os = { name: undefined$1, version: undefined$1 };
  8371. mapper.rgx.call(os, ua, rgxmap.os);
  8372. return os;
  8373. };
  8374. this.getResult = function () {
  8375. return {
  8376. ua : this.getUA(),
  8377. browser : this.getBrowser(),
  8378. engine : this.getEngine(),
  8379. os : this.getOS(),
  8380. device : this.getDevice(),
  8381. cpu : this.getCPU()
  8382. };
  8383. };
  8384. this.getUA = function () {
  8385. return ua;
  8386. };
  8387. this.setUA = function (uastring) {
  8388. ua = uastring;
  8389. return this;
  8390. };
  8391. return this;
  8392. };
  8393. UAParser.VERSION = LIBVERSION;
  8394. UAParser.BROWSER = {
  8395. NAME : NAME,
  8396. MAJOR : MAJOR, // deprecated
  8397. VERSION : VERSION
  8398. };
  8399. UAParser.CPU = {
  8400. ARCHITECTURE : ARCHITECTURE
  8401. };
  8402. UAParser.DEVICE = {
  8403. MODEL : MODEL,
  8404. VENDOR : VENDOR,
  8405. TYPE : TYPE,
  8406. CONSOLE : CONSOLE,
  8407. MOBILE : MOBILE,
  8408. SMARTTV : SMARTTV,
  8409. TABLET : TABLET,
  8410. WEARABLE: WEARABLE,
  8411. EMBEDDED: EMBEDDED
  8412. };
  8413. UAParser.ENGINE = {
  8414. NAME : NAME,
  8415. VERSION : VERSION
  8416. };
  8417. UAParser.OS = {
  8418. NAME : NAME,
  8419. VERSION : VERSION
  8420. };
  8421. ///////////
  8422. // Export
  8423. //////////
  8424. // check js environment
  8425. {
  8426. // nodejs env
  8427. if ( module.exports) {
  8428. exports = module.exports = UAParser;
  8429. }
  8430. exports.UAParser = UAParser;
  8431. }
  8432. // jQuery/Zepto specific (optional)
  8433. // Note:
  8434. // In AMD env the global scope should be kept clean, but jQuery is an exception.
  8435. // jQuery always exports to global scope, unless jQuery.noConflict(true) is used,
  8436. // and we should catch that.
  8437. var $ = window && (window.jQuery || window.Zepto);
  8438. if ($ && !$.ua) {
  8439. var parser = new UAParser();
  8440. $.ua = parser.getResult();
  8441. $.ua.get = function () {
  8442. return parser.getUA();
  8443. };
  8444. $.ua.set = function (uastring) {
  8445. parser.setUA(uastring);
  8446. var result = parser.getResult();
  8447. for (var prop in result) {
  8448. $.ua[prop] = result[prop];
  8449. }
  8450. };
  8451. }
  8452. })(typeof window === 'object' ? window : commonjsGlobal);
  8453. });
  8454. var uaParser_1 = uaParser.UAParser;
  8455. var UNKNOWN = 'Unknown';
  8456. var PLATFORM_MAP = {
  8457. 'Mac OS': 'Mac OS X'
  8458. };
  8459. /**
  8460. * Convert from UAParser platform name to what we expect.
  8461. */
  8462. function convertPlatformName(name) {
  8463. return PLATFORM_MAP[name] || name;
  8464. }
  8465. /**
  8466. * Get the version number in parts. This is very naive. We actually get major
  8467. * version as a part of UAParser already, which is generally good enough, but
  8468. * let's get the minor just in case.
  8469. */
  8470. function getBrowserVersion(version) {
  8471. if (!version) {
  8472. return {
  8473. major: '',
  8474. minor: ''
  8475. };
  8476. }
  8477. var parts = version.split('.');
  8478. return {
  8479. major: parts[0],
  8480. minor: parts[1]
  8481. };
  8482. }
  8483. /**
  8484. * Get the UA data fom UAParser and then convert it to the format we're
  8485. * expecting for our APIS.
  8486. */
  8487. var parser = new uaParser();
  8488. var results = parser.getResult();
  8489. // Do some conversion first.
  8490. var browserVersionData = getBrowserVersion(results.browser.version);
  8491. var uaData = {
  8492. browserArchitecture: results.cpu.architecture || UNKNOWN,
  8493. browserFullVersion: results.browser.version || UNKNOWN,
  8494. browserMinorVersion: browserVersionData.minor || UNKNOWN,
  8495. browserName: results.browser.name || UNKNOWN,
  8496. browserVersion: results.browser.major || UNKNOWN,
  8497. deviceName: results.device.model || UNKNOWN,
  8498. engineName: results.engine.name || UNKNOWN,
  8499. engineVersion: results.engine.version || UNKNOWN,
  8500. platformArchitecture: results.cpu.architecture || UNKNOWN,
  8501. platformName: convertPlatformName(results.os.name) || UNKNOWN,
  8502. platformVersion: results.os.version || UNKNOWN,
  8503. platformFullVersion: results.os.version || UNKNOWN
  8504. };
  8505. var UserAgentData = uaData;
  8506. var componentRegex = /\./;
  8507. var orRegex = /\|\|/;
  8508. var rangeRegex = /\s+\-\s+/;
  8509. var modifierRegex = /^(<=|<|=|>=|~>|~|>|)?\s*(.+)/;
  8510. var numericRegex = /^(\d*)(.*)/;
  8511. /**
  8512. * Splits input `range` on "||" and returns true if any subrange matches
  8513. * `version`.
  8514. *
  8515. * @param {string} range
  8516. * @param {string} version
  8517. * @returns {boolean}
  8518. */
  8519. function checkOrExpression(range, version) {
  8520. var expressions = range.split(orRegex);
  8521. if (expressions.length > 1) {
  8522. return expressions.some(function (range) {
  8523. return VersionRange.contains(range, version);
  8524. });
  8525. } else {
  8526. range = expressions[0].trim();
  8527. return checkRangeExpression(range, version);
  8528. }
  8529. }
  8530. /**
  8531. * Splits input `range` on " - " (the surrounding whitespace is required) and
  8532. * returns true if version falls between the two operands.
  8533. *
  8534. * @param {string} range
  8535. * @param {string} version
  8536. * @returns {boolean}
  8537. */
  8538. function checkRangeExpression(range, version) {
  8539. var expressions = range.split(rangeRegex);
  8540. !(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;
  8541. if (expressions.length === 1) {
  8542. return checkSimpleExpression(expressions[0], version);
  8543. } else {
  8544. var startVersion = expressions[0],
  8545. endVersion = expressions[1];
  8546. !(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;
  8547. return checkSimpleExpression('>=' + startVersion, version) && checkSimpleExpression('<=' + endVersion, version);
  8548. }
  8549. }
  8550. /**
  8551. * Checks if `range` matches `version`. `range` should be a "simple" range (ie.
  8552. * not a compound range using the " - " or "||" operators).
  8553. *
  8554. * @param {string} range
  8555. * @param {string} version
  8556. * @returns {boolean}
  8557. */
  8558. function checkSimpleExpression(range, version) {
  8559. range = range.trim();
  8560. if (range === '') {
  8561. return true;
  8562. }
  8563. var versionComponents = version.split(componentRegex);
  8564. var _getModifierAndCompon = getModifierAndComponents(range),
  8565. modifier = _getModifierAndCompon.modifier,
  8566. rangeComponents = _getModifierAndCompon.rangeComponents;
  8567. switch (modifier) {
  8568. case '<':
  8569. return checkLessThan(versionComponents, rangeComponents);
  8570. case '<=':
  8571. return checkLessThanOrEqual(versionComponents, rangeComponents);
  8572. case '>=':
  8573. return checkGreaterThanOrEqual(versionComponents, rangeComponents);
  8574. case '>':
  8575. return checkGreaterThan(versionComponents, rangeComponents);
  8576. case '~':
  8577. case '~>':
  8578. return checkApproximateVersion(versionComponents, rangeComponents);
  8579. default:
  8580. return checkEqual(versionComponents, rangeComponents);
  8581. }
  8582. }
  8583. /**
  8584. * Checks whether `a` is less than `b`.
  8585. *
  8586. * @param {array<string>} a
  8587. * @param {array<string>} b
  8588. * @returns {boolean}
  8589. */
  8590. function checkLessThan(a, b) {
  8591. return compareComponents(a, b) === -1;
  8592. }
  8593. /**
  8594. * Checks whether `a` is less than or equal to `b`.
  8595. *
  8596. * @param {array<string>} a
  8597. * @param {array<string>} b
  8598. * @returns {boolean}
  8599. */
  8600. function checkLessThanOrEqual(a, b) {
  8601. var result = compareComponents(a, b);
  8602. return result === -1 || result === 0;
  8603. }
  8604. /**
  8605. * Checks whether `a` is equal to `b`.
  8606. *
  8607. * @param {array<string>} a
  8608. * @param {array<string>} b
  8609. * @returns {boolean}
  8610. */
  8611. function checkEqual(a, b) {
  8612. return compareComponents(a, b) === 0;
  8613. }
  8614. /**
  8615. * Checks whether `a` is greater than or equal to `b`.
  8616. *
  8617. * @param {array<string>} a
  8618. * @param {array<string>} b
  8619. * @returns {boolean}
  8620. */
  8621. function checkGreaterThanOrEqual(a, b) {
  8622. var result = compareComponents(a, b);
  8623. return result === 1 || result === 0;
  8624. }
  8625. /**
  8626. * Checks whether `a` is greater than `b`.
  8627. *
  8628. * @param {array<string>} a
  8629. * @param {array<string>} b
  8630. * @returns {boolean}
  8631. */
  8632. function checkGreaterThan(a, b) {
  8633. return compareComponents(a, b) === 1;
  8634. }
  8635. /**
  8636. * Checks whether `a` is "reasonably close" to `b` (as described in
  8637. * https://www.npmjs.org/doc/misc/semver.html). For example, if `b` is "1.3.1"
  8638. * then "reasonably close" is defined as ">= 1.3.1 and < 1.4".
  8639. *
  8640. * @param {array<string>} a
  8641. * @param {array<string>} b
  8642. * @returns {boolean}
  8643. */
  8644. function checkApproximateVersion(a, b) {
  8645. var lowerBound = b.slice();
  8646. var upperBound = b.slice();
  8647. if (upperBound.length > 1) {
  8648. upperBound.pop();
  8649. }
  8650. var lastIndex = upperBound.length - 1;
  8651. var numeric = parseInt(upperBound[lastIndex], 10);
  8652. if (isNumber(numeric)) {
  8653. upperBound[lastIndex] = numeric + 1 + '';
  8654. }
  8655. return checkGreaterThanOrEqual(a, lowerBound) && checkLessThan(a, upperBound);
  8656. }
  8657. /**
  8658. * Extracts the optional modifier (<, <=, =, >=, >, ~, ~>) and version
  8659. * components from `range`.
  8660. *
  8661. * For example, given `range` ">= 1.2.3" returns an object with a `modifier` of
  8662. * `">="` and `components` of `[1, 2, 3]`.
  8663. *
  8664. * @param {string} range
  8665. * @returns {object}
  8666. */
  8667. function getModifierAndComponents(range) {
  8668. var rangeComponents = range.split(componentRegex);
  8669. var matches = rangeComponents[0].match(modifierRegex);
  8670. !matches ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'expected regex to match but it did not') : invariant_1(false) : void 0;
  8671. return {
  8672. modifier: matches[1],
  8673. rangeComponents: [matches[2]].concat(rangeComponents.slice(1))
  8674. };
  8675. }
  8676. /**
  8677. * Determines if `number` is a number.
  8678. *
  8679. * @param {mixed} number
  8680. * @returns {boolean}
  8681. */
  8682. function isNumber(number) {
  8683. return !isNaN(number) && isFinite(number);
  8684. }
  8685. /**
  8686. * Tests whether `range` is a "simple" version number without any modifiers
  8687. * (">", "~" etc).
  8688. *
  8689. * @param {string} range
  8690. * @returns {boolean}
  8691. */
  8692. function isSimpleVersion(range) {
  8693. return !getModifierAndComponents(range).modifier;
  8694. }
  8695. /**
  8696. * Zero-pads array `array` until it is at least `length` long.
  8697. *
  8698. * @param {array} array
  8699. * @param {number} length
  8700. */
  8701. function zeroPad(array, length) {
  8702. for (var i = array.length; i < length; i++) {
  8703. array[i] = '0';
  8704. }
  8705. }
  8706. /**
  8707. * Normalizes `a` and `b` in preparation for comparison by doing the following:
  8708. *
  8709. * - zero-pads `a` and `b`
  8710. * - marks any "x", "X" or "*" component in `b` as equivalent by zero-ing it out
  8711. * in both `a` and `b`
  8712. * - marks any final "*" component in `b` as a greedy wildcard by zero-ing it
  8713. * and all of its successors in `a`
  8714. *
  8715. * @param {array<string>} a
  8716. * @param {array<string>} b
  8717. * @returns {array<array<string>>}
  8718. */
  8719. function normalizeVersions(a, b) {
  8720. a = a.slice();
  8721. b = b.slice();
  8722. zeroPad(a, b.length);
  8723. // mark "x" and "*" components as equal
  8724. for (var i = 0; i < b.length; i++) {
  8725. var matches = b[i].match(/^[x*]$/i);
  8726. if (matches) {
  8727. b[i] = a[i] = '0';
  8728. // final "*" greedily zeros all remaining components
  8729. if (matches[0] === '*' && i === b.length - 1) {
  8730. for (var j = i; j < a.length; j++) {
  8731. a[j] = '0';
  8732. }
  8733. }
  8734. }
  8735. }
  8736. zeroPad(b, a.length);
  8737. return [a, b];
  8738. }
  8739. /**
  8740. * Returns the numerical -- not the lexicographical -- ordering of `a` and `b`.
  8741. *
  8742. * For example, `10-alpha` is greater than `2-beta`.
  8743. *
  8744. * @param {string} a
  8745. * @param {string} b
  8746. * @returns {number} -1, 0 or 1 to indicate whether `a` is less than, equal to,
  8747. * or greater than `b`, respectively
  8748. */
  8749. function compareNumeric(a, b) {
  8750. var aPrefix = a.match(numericRegex)[1];
  8751. var bPrefix = b.match(numericRegex)[1];
  8752. var aNumeric = parseInt(aPrefix, 10);
  8753. var bNumeric = parseInt(bPrefix, 10);
  8754. if (isNumber(aNumeric) && isNumber(bNumeric) && aNumeric !== bNumeric) {
  8755. return compare(aNumeric, bNumeric);
  8756. } else {
  8757. return compare(a, b);
  8758. }
  8759. }
  8760. /**
  8761. * Returns the ordering of `a` and `b`.
  8762. *
  8763. * @param {string|number} a
  8764. * @param {string|number} b
  8765. * @returns {number} -1, 0 or 1 to indicate whether `a` is less than, equal to,
  8766. * or greater than `b`, respectively
  8767. */
  8768. function compare(a, b) {
  8769. !(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;
  8770. if (a > b) {
  8771. return 1;
  8772. } else if (a < b) {
  8773. return -1;
  8774. } else {
  8775. return 0;
  8776. }
  8777. }
  8778. /**
  8779. * Compares arrays of version components.
  8780. *
  8781. * @param {array<string>} a
  8782. * @param {array<string>} b
  8783. * @returns {number} -1, 0 or 1 to indicate whether `a` is less than, equal to,
  8784. * or greater than `b`, respectively
  8785. */
  8786. function compareComponents(a, b) {
  8787. var _normalizeVersions = normalizeVersions(a, b),
  8788. aNormalized = _normalizeVersions[0],
  8789. bNormalized = _normalizeVersions[1];
  8790. for (var i = 0; i < bNormalized.length; i++) {
  8791. var result = compareNumeric(aNormalized[i], bNormalized[i]);
  8792. if (result) {
  8793. return result;
  8794. }
  8795. }
  8796. return 0;
  8797. }
  8798. var VersionRange = {
  8799. /**
  8800. * Checks whether `version` satisfies the `range` specification.
  8801. *
  8802. * We support a subset of the expressions defined in
  8803. * https://www.npmjs.org/doc/misc/semver.html:
  8804. *
  8805. * version Must match version exactly
  8806. * =version Same as just version
  8807. * >version Must be greater than version
  8808. * >=version Must be greater than or equal to version
  8809. * <version Must be less than version
  8810. * <=version Must be less than or equal to version
  8811. * ~version Must be at least version, but less than the next significant
  8812. * revision above version:
  8813. * "~1.2.3" is equivalent to ">= 1.2.3 and < 1.3"
  8814. * ~>version Equivalent to ~version
  8815. * 1.2.x Must match "1.2.x", where "x" is a wildcard that matches
  8816. * anything
  8817. * 1.2.* Similar to "1.2.x", but "*" in the trailing position is a
  8818. * "greedy" wildcard, so will match any number of additional
  8819. * components:
  8820. * "1.2.*" will match "1.2.1", "1.2.1.1", "1.2.1.1.1" etc
  8821. * * Any version
  8822. * "" (Empty string) Same as *
  8823. * v1 - v2 Equivalent to ">= v1 and <= v2"
  8824. * r1 || r2 Passes if either r1 or r2 are satisfied
  8825. *
  8826. * @param {string} range
  8827. * @param {string} version
  8828. * @returns {boolean}
  8829. */
  8830. contains: function contains(range, version) {
  8831. return checkOrExpression(range.trim(), version.trim());
  8832. }
  8833. };
  8834. var VersionRange_1 = VersionRange;
  8835. /**
  8836. * Copyright (c) 2013-present, Facebook, Inc.
  8837. *
  8838. * This source code is licensed under the MIT license found in the
  8839. * LICENSE file in the root directory of this source tree.
  8840. *
  8841. */
  8842. var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
  8843. /**
  8844. * Executes the provided `callback` once for each enumerable own property in the
  8845. * object and constructs a new object from the results. The `callback` is
  8846. * invoked with three arguments:
  8847. *
  8848. * - the property value
  8849. * - the property name
  8850. * - the object being traversed
  8851. *
  8852. * Properties that are added after the call to `mapObject` will not be visited
  8853. * by `callback`. If the values of existing properties are changed, the value
  8854. * passed to `callback` will be the value at the time `mapObject` visits them.
  8855. * Properties that are deleted before being visited are not visited.
  8856. *
  8857. * @grep function objectMap()
  8858. * @grep function objMap()
  8859. *
  8860. * @param {?object} object
  8861. * @param {function} callback
  8862. * @param {*} context
  8863. * @return {?object}
  8864. */
  8865. function mapObject(object, callback, context) {
  8866. if (!object) {
  8867. return null;
  8868. }
  8869. var result = {};
  8870. for (var name in object) {
  8871. if (hasOwnProperty$1.call(object, name)) {
  8872. result[name] = callback.call(context, object[name], name, object);
  8873. }
  8874. }
  8875. return result;
  8876. }
  8877. var mapObject_1 = mapObject;
  8878. /**
  8879. * Copyright (c) 2013-present, Facebook, Inc.
  8880. *
  8881. * This source code is licensed under the MIT license found in the
  8882. * LICENSE file in the root directory of this source tree.
  8883. *
  8884. *
  8885. * @typechecks static-only
  8886. */
  8887. /**
  8888. * Memoizes the return value of a function that accepts one string argument.
  8889. */
  8890. function memoizeStringOnly(callback) {
  8891. var cache = {};
  8892. return function (string) {
  8893. if (!cache.hasOwnProperty(string)) {
  8894. cache[string] = callback.call(this, string);
  8895. }
  8896. return cache[string];
  8897. };
  8898. }
  8899. var memoizeStringOnly_1 = memoizeStringOnly;
  8900. /**
  8901. * Checks to see whether `name` and `version` satisfy `query`.
  8902. *
  8903. * @param {string} name Name of the browser, device, engine or platform
  8904. * @param {?string} version Version of the browser, engine or platform
  8905. * @param {string} query Query of form "Name [range expression]"
  8906. * @param {?function} normalizer Optional pre-processor for range expression
  8907. * @return {boolean}
  8908. */
  8909. function compare$1(name, version, query, normalizer) {
  8910. // check for exact match with no version
  8911. if (name === query) {
  8912. return true;
  8913. }
  8914. // check for non-matching names
  8915. if (!query.startsWith(name)) {
  8916. return false;
  8917. }
  8918. // full comparison with version
  8919. var range = query.slice(name.length);
  8920. if (version) {
  8921. range = normalizer ? normalizer(range) : range;
  8922. return VersionRange_1.contains(range, version);
  8923. }
  8924. return false;
  8925. }
  8926. /**
  8927. * Normalizes `version` by stripping any "NT" prefix, but only on the Windows
  8928. * platform.
  8929. *
  8930. * Mimics the stripping performed by the `UserAgentWindowsPlatform` PHP class.
  8931. *
  8932. * @param {string} version
  8933. * @return {string}
  8934. */
  8935. function normalizePlatformVersion(version) {
  8936. if (UserAgentData.platformName === 'Windows') {
  8937. return version.replace(/^\s*NT/, '');
  8938. }
  8939. return version;
  8940. }
  8941. /**
  8942. * Provides client-side access to the authoritative PHP-generated User Agent
  8943. * information supplied by the server.
  8944. */
  8945. var UserAgent = {
  8946. /**
  8947. * Check if the User Agent browser matches `query`.
  8948. *
  8949. * `query` should be a string like "Chrome" or "Chrome > 33".
  8950. *
  8951. * Valid browser names include:
  8952. *
  8953. * - ACCESS NetFront
  8954. * - AOL
  8955. * - Amazon Silk
  8956. * - Android
  8957. * - BlackBerry
  8958. * - BlackBerry PlayBook
  8959. * - Chrome
  8960. * - Chrome for iOS
  8961. * - Chrome frame
  8962. * - Facebook PHP SDK
  8963. * - Facebook for iOS
  8964. * - Firefox
  8965. * - IE
  8966. * - IE Mobile
  8967. * - Mobile Safari
  8968. * - Motorola Internet Browser
  8969. * - Nokia
  8970. * - Openwave Mobile Browser
  8971. * - Opera
  8972. * - Opera Mini
  8973. * - Opera Mobile
  8974. * - Safari
  8975. * - UIWebView
  8976. * - Unknown
  8977. * - webOS
  8978. * - etc...
  8979. *
  8980. * An authoritative list can be found in the PHP `BrowserDetector` class and
  8981. * related classes in the same file (see calls to `new UserAgentBrowser` here:
  8982. * https://fburl.com/50728104).
  8983. *
  8984. * @note Function results are memoized
  8985. *
  8986. * @param {string} query Query of the form "Name [range expression]"
  8987. * @return {boolean}
  8988. */
  8989. isBrowser: function isBrowser(query) {
  8990. return compare$1(UserAgentData.browserName, UserAgentData.browserFullVersion, query);
  8991. },
  8992. /**
  8993. * Check if the User Agent browser uses a 32 or 64 bit architecture.
  8994. *
  8995. * @note Function results are memoized
  8996. *
  8997. * @param {string} query Query of the form "32" or "64".
  8998. * @return {boolean}
  8999. */
  9000. isBrowserArchitecture: function isBrowserArchitecture(query) {
  9001. return compare$1(UserAgentData.browserArchitecture, null, query);
  9002. },
  9003. /**
  9004. * Check if the User Agent device matches `query`.
  9005. *
  9006. * `query` should be a string like "iPhone" or "iPad".
  9007. *
  9008. * Valid device names include:
  9009. *
  9010. * - Kindle
  9011. * - Kindle Fire
  9012. * - Unknown
  9013. * - iPad
  9014. * - iPhone
  9015. * - iPod
  9016. * - etc...
  9017. *
  9018. * An authoritative list can be found in the PHP `DeviceDetector` class and
  9019. * related classes in the same file (see calls to `new UserAgentDevice` here:
  9020. * https://fburl.com/50728332).
  9021. *
  9022. * @note Function results are memoized
  9023. *
  9024. * @param {string} query Query of the form "Name"
  9025. * @return {boolean}
  9026. */
  9027. isDevice: function isDevice(query) {
  9028. return compare$1(UserAgentData.deviceName, null, query);
  9029. },
  9030. /**
  9031. * Check if the User Agent rendering engine matches `query`.
  9032. *
  9033. * `query` should be a string like "WebKit" or "WebKit >= 537".
  9034. *
  9035. * Valid engine names include:
  9036. *
  9037. * - Gecko
  9038. * - Presto
  9039. * - Trident
  9040. * - WebKit
  9041. * - etc...
  9042. *
  9043. * An authoritative list can be found in the PHP `RenderingEngineDetector`
  9044. * class related classes in the same file (see calls to `new
  9045. * UserAgentRenderingEngine` here: https://fburl.com/50728617).
  9046. *
  9047. * @note Function results are memoized
  9048. *
  9049. * @param {string} query Query of the form "Name [range expression]"
  9050. * @return {boolean}
  9051. */
  9052. isEngine: function isEngine(query) {
  9053. return compare$1(UserAgentData.engineName, UserAgentData.engineVersion, query);
  9054. },
  9055. /**
  9056. * Check if the User Agent platform matches `query`.
  9057. *
  9058. * `query` should be a string like "Windows" or "iOS 5 - 6".
  9059. *
  9060. * Valid platform names include:
  9061. *
  9062. * - Android
  9063. * - BlackBerry OS
  9064. * - Java ME
  9065. * - Linux
  9066. * - Mac OS X
  9067. * - Mac OS X Calendar
  9068. * - Mac OS X Internet Account
  9069. * - Symbian
  9070. * - SymbianOS
  9071. * - Windows
  9072. * - Windows Mobile
  9073. * - Windows Phone
  9074. * - iOS
  9075. * - iOS Facebook Integration Account
  9076. * - iOS Facebook Social Sharing UI
  9077. * - webOS
  9078. * - Chrome OS
  9079. * - etc...
  9080. *
  9081. * An authoritative list can be found in the PHP `PlatformDetector` class and
  9082. * related classes in the same file (see calls to `new UserAgentPlatform`
  9083. * here: https://fburl.com/50729226).
  9084. *
  9085. * @note Function results are memoized
  9086. *
  9087. * @param {string} query Query of the form "Name [range expression]"
  9088. * @return {boolean}
  9089. */
  9090. isPlatform: function isPlatform(query) {
  9091. return compare$1(UserAgentData.platformName, UserAgentData.platformFullVersion, query, normalizePlatformVersion);
  9092. },
  9093. /**
  9094. * Check if the User Agent platform is a 32 or 64 bit architecture.
  9095. *
  9096. * @note Function results are memoized
  9097. *
  9098. * @param {string} query Query of the form "32" or "64".
  9099. * @return {boolean}
  9100. */
  9101. isPlatformArchitecture: function isPlatformArchitecture(query) {
  9102. return compare$1(UserAgentData.platformArchitecture, null, query);
  9103. }
  9104. };
  9105. var UserAgent_1 = mapObject_1(UserAgent, memoizeStringOnly_1);
  9106. function _classCallCheck$9(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9107. 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; }
  9108. 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; }
  9109. // In IE, spans with <br> tags render as two newlines. By rendering a span
  9110. // with only a newline character, we can be sure to render a single line.
  9111. var useNewlineChar = UserAgent_1.isBrowser('IE <= 11');
  9112. /**
  9113. * Check whether the node should be considered a newline.
  9114. */
  9115. function isNewline(node) {
  9116. return useNewlineChar ? node.textContent === '\n' : node.tagName === 'BR';
  9117. }
  9118. /**
  9119. * Placeholder elements for empty text content.
  9120. *
  9121. * What is this `data-text` attribute, anyway? It turns out that we need to
  9122. * put an attribute on the lowest-level text node in order to preserve correct
  9123. * spellcheck handling. If the <span> is naked, Chrome and Safari may do
  9124. * bizarre things to do the DOM -- split text nodes, create extra spans, etc.
  9125. * If the <span> has an attribute, this appears not to happen.
  9126. * See http://jsfiddle.net/9khdavod/ for the failure case, and
  9127. * http://jsfiddle.net/7pg143f7/ for the fixed case.
  9128. */
  9129. var NEWLINE_A = useNewlineChar ? React.createElement(
  9130. 'span',
  9131. { key: 'A', 'data-text': 'true' },
  9132. '\n'
  9133. ) : React.createElement('br', { key: 'A', 'data-text': 'true' });
  9134. var NEWLINE_B = useNewlineChar ? React.createElement(
  9135. 'span',
  9136. { key: 'B', 'data-text': 'true' },
  9137. '\n'
  9138. ) : React.createElement('br', { key: 'B', 'data-text': 'true' });
  9139. /**
  9140. * The lowest-level component in a `DraftEditor`, the text node component
  9141. * replaces the default React text node implementation. This allows us to
  9142. * perform custom handling of newline behavior and avoid re-rendering text
  9143. * nodes with DOM state that already matches the expectations of our immutable
  9144. * editor state.
  9145. */
  9146. var DraftEditorTextNode = function (_React$Component) {
  9147. _inherits$6(DraftEditorTextNode, _React$Component);
  9148. function DraftEditorTextNode(props) {
  9149. _classCallCheck$9(this, DraftEditorTextNode);
  9150. // By flipping this flag, we also keep flipping keys which forces
  9151. // React to remount this node every time it rerenders.
  9152. var _this = _possibleConstructorReturn$6(this, _React$Component.call(this, props));
  9153. _this._forceFlag = false;
  9154. return _this;
  9155. }
  9156. DraftEditorTextNode.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
  9157. var node = ReactDOM.findDOMNode(this);
  9158. var shouldBeNewline = nextProps.children === '';
  9159. !(node instanceof Element) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'node is not an Element') : invariant_1(false) : void 0;
  9160. if (shouldBeNewline) {
  9161. return !isNewline(node);
  9162. }
  9163. return node.textContent !== nextProps.children;
  9164. };
  9165. DraftEditorTextNode.prototype.componentDidMount = function componentDidMount() {
  9166. this._forceFlag = !this._forceFlag;
  9167. };
  9168. DraftEditorTextNode.prototype.componentDidUpdate = function componentDidUpdate() {
  9169. this._forceFlag = !this._forceFlag;
  9170. };
  9171. DraftEditorTextNode.prototype.render = function render() {
  9172. if (this.props.children === '') {
  9173. return this._forceFlag ? NEWLINE_A : NEWLINE_B;
  9174. }
  9175. return React.createElement(
  9176. 'span',
  9177. { key: this._forceFlag ? 'A' : 'B', 'data-text': 'true' },
  9178. this.props.children
  9179. );
  9180. };
  9181. return DraftEditorTextNode;
  9182. }(React.Component);
  9183. var DraftEditorTextNode_react = DraftEditorTextNode;
  9184. /**
  9185. * Copyright (c) 2013-present, Facebook, Inc.
  9186. * All rights reserved.
  9187. *
  9188. * This source code is licensed under the BSD-style license found in the
  9189. * LICENSE file in the root directory of this source tree. An additional grant
  9190. * of patent rights can be found in the PATENTS file in the same directory.
  9191. *
  9192. * @providesModule DraftJsDebugLogging
  9193. */
  9194. var DraftJsDebugLogging = {
  9195. logSelectionStateFailure: function logSelectionStateFailure() {
  9196. return null;
  9197. }
  9198. };
  9199. /**
  9200. * Copyright (c) 2013-present, Facebook, Inc.
  9201. *
  9202. * This source code is licensed under the MIT license found in the
  9203. * LICENSE file in the root directory of this source tree.
  9204. *
  9205. * @typechecks
  9206. */
  9207. /**
  9208. * @param {*} object The object to check.
  9209. * @return {boolean} Whether or not the object is a DOM node.
  9210. */
  9211. function isNode(object) {
  9212. var doc = object ? object.ownerDocument || object : document;
  9213. var defaultView = doc.defaultView || window;
  9214. return !!(object && (typeof defaultView.Node === 'function' ? object instanceof defaultView.Node : typeof object === 'object' && typeof object.nodeType === 'number' && typeof object.nodeName === 'string'));
  9215. }
  9216. var isNode_1 = isNode;
  9217. /**
  9218. * Copyright (c) 2013-present, Facebook, Inc.
  9219. *
  9220. * This source code is licensed under the MIT license found in the
  9221. * LICENSE file in the root directory of this source tree.
  9222. *
  9223. * @typechecks
  9224. */
  9225. /**
  9226. * @param {*} object The object to check.
  9227. * @return {boolean} Whether or not the object is a DOM text node.
  9228. */
  9229. function isTextNode(object) {
  9230. return isNode_1(object) && object.nodeType == 3;
  9231. }
  9232. var isTextNode_1 = isTextNode;
  9233. /**
  9234. * Copyright (c) 2013-present, Facebook, Inc.
  9235. *
  9236. * This source code is licensed under the MIT license found in the
  9237. * LICENSE file in the root directory of this source tree.
  9238. *
  9239. *
  9240. */
  9241. /*eslint-disable no-bitwise */
  9242. /**
  9243. * Checks if a given DOM node contains or is another DOM node.
  9244. */
  9245. function containsNode(outerNode, innerNode) {
  9246. if (!outerNode || !innerNode) {
  9247. return false;
  9248. } else if (outerNode === innerNode) {
  9249. return true;
  9250. } else if (isTextNode_1(outerNode)) {
  9251. return false;
  9252. } else if (isTextNode_1(innerNode)) {
  9253. return containsNode(outerNode, innerNode.parentNode);
  9254. } else if ('contains' in outerNode) {
  9255. return outerNode.contains(innerNode);
  9256. } else if (outerNode.compareDocumentPosition) {
  9257. return !!(outerNode.compareDocumentPosition(innerNode) & 16);
  9258. } else {
  9259. return false;
  9260. }
  9261. }
  9262. var containsNode_1 = containsNode;
  9263. /**
  9264. * Copyright (c) 2013-present, Facebook, Inc.
  9265. *
  9266. * This source code is licensed under the MIT license found in the
  9267. * LICENSE file in the root directory of this source tree.
  9268. *
  9269. * @typechecks
  9270. */
  9271. /* eslint-disable fb-www/typeof-undefined */
  9272. /**
  9273. * Same as document.activeElement but wraps in a try-catch block. In IE it is
  9274. * not safe to call document.activeElement if there is nothing focused.
  9275. *
  9276. * The activeElement will be null only if the document or document body is not
  9277. * yet defined.
  9278. *
  9279. * @param {?DOMDocument} doc Defaults to current document.
  9280. * @return {?DOMElement}
  9281. */
  9282. function getActiveElement(doc) /*?DOMElement*/{
  9283. doc = doc || (typeof document !== 'undefined' ? document : undefined);
  9284. if (typeof doc === 'undefined') {
  9285. return null;
  9286. }
  9287. try {
  9288. return doc.activeElement || doc.body;
  9289. } catch (e) {
  9290. return doc.body;
  9291. }
  9292. }
  9293. var getActiveElement_1 = getActiveElement;
  9294. function getAnonymizedDOM(node, getNodeLabels) {
  9295. if (!node) {
  9296. return '[empty]';
  9297. }
  9298. var anonymized = anonymizeTextWithin(node, getNodeLabels);
  9299. if (anonymized.nodeType === Node.TEXT_NODE) {
  9300. return anonymized.textContent;
  9301. }
  9302. !(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;
  9303. return anonymized.outerHTML;
  9304. }
  9305. function anonymizeTextWithin(node, getNodeLabels) {
  9306. var labels = getNodeLabels !== undefined ? getNodeLabels(node) : [];
  9307. if (node.nodeType === Node.TEXT_NODE) {
  9308. var length = node.textContent.length;
  9309. return document.createTextNode('[text ' + length + (labels.length ? ' | ' + labels.join(', ') : '') + ']');
  9310. }
  9311. var clone = node.cloneNode();
  9312. if (clone.nodeType === 1 && labels.length) {
  9313. clone.setAttribute('data-labels', labels.join(', '));
  9314. }
  9315. var childNodes = node.childNodes;
  9316. for (var ii = 0; ii < childNodes.length; ii++) {
  9317. clone.appendChild(anonymizeTextWithin(childNodes[ii], getNodeLabels));
  9318. }
  9319. return clone;
  9320. }
  9321. function getAnonymizedEditorDOM(node, getNodeLabels) {
  9322. // grabbing the DOM content of the Draft editor
  9323. var currentNode = node;
  9324. while (currentNode) {
  9325. if (currentNode instanceof Element && currentNode.hasAttribute('contenteditable')) {
  9326. // found the Draft editor container
  9327. return getAnonymizedDOM(currentNode, getNodeLabels);
  9328. } else {
  9329. currentNode = currentNode.parentNode;
  9330. }
  9331. }
  9332. return 'Could not find contentEditable parent of node';
  9333. }
  9334. function getNodeLength(node) {
  9335. return node.nodeValue === null ? node.childNodes.length : node.nodeValue.length;
  9336. }
  9337. /**
  9338. * In modern non-IE browsers, we can support both forward and backward
  9339. * selections.
  9340. *
  9341. * Note: IE10+ supports the Selection object, but it does not support
  9342. * the `extend` method, which means that even in modern IE, it's not possible
  9343. * to programatically create a backward selection. Thus, for all IE
  9344. * versions, we use the old IE API to create our selections.
  9345. */
  9346. function setDraftEditorSelection(selectionState, node, blockKey, nodeStart, nodeEnd) {
  9347. // It's possible that the editor has been removed from the DOM but
  9348. // our selection code doesn't know it yet. Forcing selection in
  9349. // this case may lead to errors, so just bail now.
  9350. if (!containsNode_1(document.documentElement, node)) {
  9351. return;
  9352. }
  9353. var selection = commonjsGlobal.getSelection();
  9354. var anchorKey = selectionState.getAnchorKey();
  9355. var anchorOffset = selectionState.getAnchorOffset();
  9356. var focusKey = selectionState.getFocusKey();
  9357. var focusOffset = selectionState.getFocusOffset();
  9358. var isBackward = selectionState.getIsBackward();
  9359. // IE doesn't support backward selection. Swap key/offset pairs.
  9360. if (!selection.extend && isBackward) {
  9361. var tempKey = anchorKey;
  9362. var tempOffset = anchorOffset;
  9363. anchorKey = focusKey;
  9364. anchorOffset = focusOffset;
  9365. focusKey = tempKey;
  9366. focusOffset = tempOffset;
  9367. isBackward = false;
  9368. }
  9369. var hasAnchor = anchorKey === blockKey && nodeStart <= anchorOffset && nodeEnd >= anchorOffset;
  9370. var hasFocus = focusKey === blockKey && nodeStart <= focusOffset && nodeEnd >= focusOffset;
  9371. // If the selection is entirely bound within this node, set the selection
  9372. // and be done.
  9373. if (hasAnchor && hasFocus) {
  9374. selection.removeAllRanges();
  9375. addPointToSelection(selection, node, anchorOffset - nodeStart, selectionState);
  9376. addFocusToSelection(selection, node, focusOffset - nodeStart, selectionState);
  9377. return;
  9378. }
  9379. if (!isBackward) {
  9380. // If the anchor is within this node, set the range start.
  9381. if (hasAnchor) {
  9382. selection.removeAllRanges();
  9383. addPointToSelection(selection, node, anchorOffset - nodeStart, selectionState);
  9384. }
  9385. // If the focus is within this node, we can assume that we have
  9386. // already set the appropriate start range on the selection, and
  9387. // can simply extend the selection.
  9388. if (hasFocus) {
  9389. addFocusToSelection(selection, node, focusOffset - nodeStart, selectionState);
  9390. }
  9391. } else {
  9392. // If this node has the focus, set the selection range to be a
  9393. // collapsed range beginning here. Later, when we encounter the anchor,
  9394. // we'll use this information to extend the selection.
  9395. if (hasFocus) {
  9396. selection.removeAllRanges();
  9397. addPointToSelection(selection, node, focusOffset - nodeStart, selectionState);
  9398. }
  9399. // If this node has the anchor, we may assume that the correct
  9400. // focus information is already stored on the selection object.
  9401. // We keep track of it, reset the selection range, and extend it
  9402. // back to the focus point.
  9403. if (hasAnchor) {
  9404. var storedFocusNode = selection.focusNode;
  9405. var storedFocusOffset = selection.focusOffset;
  9406. selection.removeAllRanges();
  9407. addPointToSelection(selection, node, anchorOffset - nodeStart, selectionState);
  9408. addFocusToSelection(selection, storedFocusNode, storedFocusOffset, selectionState);
  9409. }
  9410. }
  9411. }
  9412. /**
  9413. * Extend selection towards focus point.
  9414. */
  9415. function addFocusToSelection(selection, node, offset, selectionState) {
  9416. var activeElement = getActiveElement_1();
  9417. if (selection.extend && containsNode_1(activeElement, node)) {
  9418. // If `extend` is called while another element has focus, an error is
  9419. // thrown. We therefore disable `extend` if the active element is somewhere
  9420. // other than the node we are selecting. This should only occur in Firefox,
  9421. // since it is the only browser to support multiple selections.
  9422. // See https://bugzilla.mozilla.org/show_bug.cgi?id=921444.
  9423. // logging to catch bug that is being reported in t16250795
  9424. if (offset > getNodeLength(node)) {
  9425. // the call to 'selection.extend' is about to throw
  9426. DraftJsDebugLogging.logSelectionStateFailure({
  9427. anonymizedDom: getAnonymizedEditorDOM(node),
  9428. extraParams: JSON.stringify({ offset: offset }),
  9429. selectionState: JSON.stringify(selectionState.toJS())
  9430. });
  9431. }
  9432. // logging to catch bug that is being reported in t18110632
  9433. var nodeWasFocus = node === selection.focusNode;
  9434. try {
  9435. selection.extend(node, offset);
  9436. } catch (e) {
  9437. DraftJsDebugLogging.logSelectionStateFailure({
  9438. anonymizedDom: getAnonymizedEditorDOM(node, function (n) {
  9439. var labels = [];
  9440. if (n === activeElement) {
  9441. labels.push('active element');
  9442. }
  9443. if (n === selection.anchorNode) {
  9444. labels.push('selection anchor node');
  9445. }
  9446. if (n === selection.focusNode) {
  9447. labels.push('selection focus node');
  9448. }
  9449. return labels;
  9450. }),
  9451. extraParams: JSON.stringify({
  9452. activeElementName: activeElement ? activeElement.nodeName : null,
  9453. nodeIsFocus: node === selection.focusNode,
  9454. nodeWasFocus: nodeWasFocus,
  9455. selectionRangeCount: selection.rangeCount,
  9456. selectionAnchorNodeName: selection.anchorNode ? selection.anchorNode.nodeName : null,
  9457. selectionAnchorOffset: selection.anchorOffset,
  9458. selectionFocusNodeName: selection.focusNode ? selection.focusNode.nodeName : null,
  9459. selectionFocusOffset: selection.focusOffset,
  9460. message: e ? '' + e : null,
  9461. offset: offset
  9462. }, null, 2),
  9463. selectionState: JSON.stringify(selectionState.toJS(), null, 2)
  9464. });
  9465. // allow the error to be thrown -
  9466. // better than continuing in a broken state
  9467. throw e;
  9468. }
  9469. } else {
  9470. // IE doesn't support extend. This will mean no backward selection.
  9471. // Extract the existing selection range and add focus to it.
  9472. // Additionally, clone the selection range. IE11 throws an
  9473. // InvalidStateError when attempting to access selection properties
  9474. // after the range is detached.
  9475. var range = selection.getRangeAt(0);
  9476. range.setEnd(node, offset);
  9477. selection.addRange(range.cloneRange());
  9478. }
  9479. }
  9480. function addPointToSelection(selection, node, offset, selectionState) {
  9481. var range = document.createRange();
  9482. // logging to catch bug that is being reported in t16250795
  9483. if (offset > getNodeLength(node)) {
  9484. // in this case we know that the call to 'range.setStart' is about to throw
  9485. DraftJsDebugLogging.logSelectionStateFailure({
  9486. anonymizedDom: getAnonymizedEditorDOM(node),
  9487. extraParams: JSON.stringify({ offset: offset }),
  9488. selectionState: JSON.stringify(selectionState.toJS())
  9489. });
  9490. }
  9491. range.setStart(node, offset);
  9492. selection.addRange(range);
  9493. }
  9494. var setDraftEditorSelection_1 = setDraftEditorSelection;
  9495. function _classCallCheck$a(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9496. 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; }
  9497. 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; }
  9498. /**
  9499. * All leaf nodes in the editor are spans with single text nodes. Leaf
  9500. * elements are styled based on the merging of an optional custom style map
  9501. * and a default style map.
  9502. *
  9503. * `DraftEditorLeaf` also provides a wrapper for calling into the imperative
  9504. * DOM Selection API. In this way, top-level components can declaratively
  9505. * maintain the selection state.
  9506. */
  9507. var DraftEditorLeaf = function (_React$Component) {
  9508. _inherits$7(DraftEditorLeaf, _React$Component);
  9509. function DraftEditorLeaf() {
  9510. _classCallCheck$a(this, DraftEditorLeaf);
  9511. return _possibleConstructorReturn$7(this, _React$Component.apply(this, arguments));
  9512. }
  9513. DraftEditorLeaf.prototype._setSelection = function _setSelection() {
  9514. var selection = this.props.selection;
  9515. // If selection state is irrelevant to the parent block, no-op.
  9516. if (selection == null || !selection.getHasFocus()) {
  9517. return;
  9518. }
  9519. var _props = this.props,
  9520. block = _props.block,
  9521. start = _props.start,
  9522. text = _props.text;
  9523. var blockKey = block.getKey();
  9524. var end = start + text.length;
  9525. if (!selection.hasEdgeWithin(blockKey, start, end)) {
  9526. return;
  9527. }
  9528. // Determine the appropriate target node for selection. If the child
  9529. // is not a text node, it is a <br /> spacer. In this case, use the
  9530. // <span> itself as the selection target.
  9531. var node = ReactDOM.findDOMNode(this);
  9532. !node ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing node') : invariant_1(false) : void 0;
  9533. var child = node.firstChild;
  9534. !child ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing child') : invariant_1(false) : void 0;
  9535. var targetNode = void 0;
  9536. if (child.nodeType === Node.TEXT_NODE) {
  9537. targetNode = child;
  9538. } else if (child.tagName === 'BR') {
  9539. targetNode = node;
  9540. } else {
  9541. targetNode = child.firstChild;
  9542. !targetNode ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing targetNode') : invariant_1(false) : void 0;
  9543. }
  9544. setDraftEditorSelection_1(selection, targetNode, blockKey, start, end);
  9545. };
  9546. /**
  9547. * By making individual leaf instances aware of their context within
  9548. * the text of the editor, we can set our selection range more
  9549. * easily than we could in the non-React world.
  9550. *
  9551. * Note that this depends on our maintaining tight control over the
  9552. * DOM structure of the DraftEditor component. If leaves had multiple
  9553. * text nodes, this would be harder.
  9554. */
  9555. DraftEditorLeaf.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
  9556. var leafNode = ReactDOM.findDOMNode(this.leaf);
  9557. !leafNode ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing leafNode') : invariant_1(false) : void 0;
  9558. return leafNode.textContent !== nextProps.text || nextProps.styleSet !== this.props.styleSet || nextProps.forceSelection;
  9559. };
  9560. DraftEditorLeaf.prototype.componentDidUpdate = function componentDidUpdate() {
  9561. this._setSelection();
  9562. };
  9563. DraftEditorLeaf.prototype.componentDidMount = function componentDidMount() {
  9564. this._setSelection();
  9565. };
  9566. DraftEditorLeaf.prototype.render = function render() {
  9567. var _this2 = this;
  9568. var block = this.props.block;
  9569. var text = this.props.text;
  9570. // If the leaf is at the end of its block and ends in a soft newline, append
  9571. // an extra line feed character. Browsers collapse trailing newline
  9572. // characters, which leaves the cursor in the wrong place after a
  9573. // shift+enter. The extra character repairs this.
  9574. if (text.endsWith('\n') && this.props.isLast) {
  9575. text += '\n';
  9576. }
  9577. var _props2 = this.props,
  9578. customStyleMap = _props2.customStyleMap,
  9579. customStyleFn = _props2.customStyleFn,
  9580. offsetKey = _props2.offsetKey,
  9581. styleSet = _props2.styleSet;
  9582. var styleObj = styleSet.reduce(function (map, styleName) {
  9583. var mergedStyles = {};
  9584. var style = customStyleMap[styleName];
  9585. if (style !== undefined && map.textDecoration !== style.textDecoration) {
  9586. // .trim() is necessary for IE9/10/11 and Edge
  9587. mergedStyles.textDecoration = [map.textDecoration, style.textDecoration].join(' ').trim();
  9588. }
  9589. return objectAssign(map, style, mergedStyles);
  9590. }, {});
  9591. if (customStyleFn) {
  9592. var newStyles = customStyleFn(styleSet, block);
  9593. styleObj = objectAssign(styleObj, newStyles);
  9594. }
  9595. return React.createElement(
  9596. 'span',
  9597. {
  9598. 'data-offset-key': offsetKey,
  9599. ref: function ref(_ref) {
  9600. return _this2.leaf = _ref;
  9601. },
  9602. style: styleObj },
  9603. React.createElement(
  9604. DraftEditorTextNode_react,
  9605. null,
  9606. text
  9607. )
  9608. );
  9609. };
  9610. return DraftEditorLeaf;
  9611. }(React.Component);
  9612. var DraftEditorLeaf_react = DraftEditorLeaf;
  9613. /**
  9614. * Copyright (c) 2013-present, Facebook, Inc.
  9615. * All rights reserved.
  9616. *
  9617. * This source code is licensed under the BSD-style license found in the
  9618. * LICENSE file in the root directory of this source tree. An additional grant
  9619. * of patent rights can be found in the PATENTS file in the same directory.
  9620. *
  9621. * @providesModule DraftOffsetKey
  9622. * @format
  9623. *
  9624. */
  9625. var KEY_DELIMITER = '-';
  9626. var DraftOffsetKey = {
  9627. encode: function encode(blockKey, decoratorKey, leafKey) {
  9628. return blockKey + KEY_DELIMITER + decoratorKey + KEY_DELIMITER + leafKey;
  9629. },
  9630. decode: function decode(offsetKey) {
  9631. var _offsetKey$split = offsetKey.split(KEY_DELIMITER),
  9632. blockKey = _offsetKey$split[0],
  9633. decoratorKey = _offsetKey$split[1],
  9634. leafKey = _offsetKey$split[2];
  9635. return {
  9636. blockKey: blockKey,
  9637. decoratorKey: parseInt(decoratorKey, 10),
  9638. leafKey: parseInt(leafKey, 10)
  9639. };
  9640. }
  9641. };
  9642. var DraftOffsetKey_1 = DraftOffsetKey;
  9643. /**
  9644. * Copyright (c) 2013-present, Facebook, Inc.
  9645. *
  9646. * This source code is licensed under the MIT license found in the
  9647. * LICENSE file in the root directory of this source tree.
  9648. *
  9649. */
  9650. /**
  9651. * @param {DOMElement} element
  9652. * @param {DOMDocument} doc
  9653. * @return {boolean}
  9654. */
  9655. function _isViewportScrollElement(element, doc) {
  9656. return !!doc && (element === doc.documentElement || element === doc.body);
  9657. }
  9658. /**
  9659. * Scroll Module. This class contains 4 simple static functions
  9660. * to be used to access Element.scrollTop/scrollLeft properties.
  9661. * To solve the inconsistencies between browsers when either
  9662. * document.body or document.documentElement is supplied,
  9663. * below logic will be used to alleviate the issue:
  9664. *
  9665. * 1. If 'element' is either 'document.body' or 'document.documentElement,
  9666. * get whichever element's 'scroll{Top,Left}' is larger.
  9667. * 2. If 'element' is either 'document.body' or 'document.documentElement',
  9668. * set the 'scroll{Top,Left}' on both elements.
  9669. */
  9670. var Scroll = {
  9671. /**
  9672. * @param {DOMElement} element
  9673. * @return {number}
  9674. */
  9675. getTop: function getTop(element) {
  9676. var doc = element.ownerDocument;
  9677. return _isViewportScrollElement(element, doc) ?
  9678. // In practice, they will either both have the same value,
  9679. // or one will be zero and the other will be the scroll position
  9680. // of the viewport. So we can use `X || Y` instead of `Math.max(X, Y)`
  9681. doc.body.scrollTop || doc.documentElement.scrollTop : element.scrollTop;
  9682. },
  9683. /**
  9684. * @param {DOMElement} element
  9685. * @param {number} newTop
  9686. */
  9687. setTop: function setTop(element, newTop) {
  9688. var doc = element.ownerDocument;
  9689. if (_isViewportScrollElement(element, doc)) {
  9690. doc.body.scrollTop = doc.documentElement.scrollTop = newTop;
  9691. } else {
  9692. element.scrollTop = newTop;
  9693. }
  9694. },
  9695. /**
  9696. * @param {DOMElement} element
  9697. * @return {number}
  9698. */
  9699. getLeft: function getLeft(element) {
  9700. var doc = element.ownerDocument;
  9701. return _isViewportScrollElement(element, doc) ? doc.body.scrollLeft || doc.documentElement.scrollLeft : element.scrollLeft;
  9702. },
  9703. /**
  9704. * @param {DOMElement} element
  9705. * @param {number} newLeft
  9706. */
  9707. setLeft: function setLeft(element, newLeft) {
  9708. var doc = element.ownerDocument;
  9709. if (_isViewportScrollElement(element, doc)) {
  9710. doc.body.scrollLeft = doc.documentElement.scrollLeft = newLeft;
  9711. } else {
  9712. element.scrollLeft = newLeft;
  9713. }
  9714. }
  9715. };
  9716. var Scroll_1 = Scroll;
  9717. /**
  9718. * Copyright (c) 2013-present, Facebook, Inc.
  9719. *
  9720. * This source code is licensed under the MIT license found in the
  9721. * LICENSE file in the root directory of this source tree.
  9722. *
  9723. * @typechecks
  9724. */
  9725. var _hyphenPattern = /-(.)/g;
  9726. /**
  9727. * Camelcases a hyphenated string, for example:
  9728. *
  9729. * > camelize('background-color')
  9730. * < "backgroundColor"
  9731. *
  9732. * @param {string} string
  9733. * @return {string}
  9734. */
  9735. function camelize(string) {
  9736. return string.replace(_hyphenPattern, function (_, character) {
  9737. return character.toUpperCase();
  9738. });
  9739. }
  9740. var camelize_1 = camelize;
  9741. /**
  9742. * Copyright (c) 2013-present, Facebook, Inc.
  9743. *
  9744. * This source code is licensed under the MIT license found in the
  9745. * LICENSE file in the root directory of this source tree.
  9746. *
  9747. * @typechecks
  9748. */
  9749. var _uppercasePattern = /([A-Z])/g;
  9750. /**
  9751. * Hyphenates a camelcased string, for example:
  9752. *
  9753. * > hyphenate('backgroundColor')
  9754. * < "background-color"
  9755. *
  9756. * For CSS style names, use `hyphenateStyleName` instead which works properly
  9757. * with all vendor prefixes, including `ms`.
  9758. *
  9759. * @param {string} string
  9760. * @return {string}
  9761. */
  9762. function hyphenate(string) {
  9763. return string.replace(_uppercasePattern, '-$1').toLowerCase();
  9764. }
  9765. var hyphenate_1 = hyphenate;
  9766. /**
  9767. * Copyright (c) 2013-present, Facebook, Inc.
  9768. *
  9769. * This source code is licensed under the MIT license found in the
  9770. * LICENSE file in the root directory of this source tree.
  9771. *
  9772. * @typechecks
  9773. */
  9774. function asString(value) /*?string*/{
  9775. return value == null ? value : String(value);
  9776. }
  9777. function getStyleProperty( /*DOMNode*/node, /*string*/name) /*?string*/{
  9778. var computedStyle = void 0;
  9779. // W3C Standard
  9780. if (window.getComputedStyle) {
  9781. // In certain cases such as within an iframe in FF3, this returns null.
  9782. computedStyle = window.getComputedStyle(node, null);
  9783. if (computedStyle) {
  9784. return asString(computedStyle.getPropertyValue(hyphenate_1(name)));
  9785. }
  9786. }
  9787. // Safari
  9788. if (document.defaultView && document.defaultView.getComputedStyle) {
  9789. computedStyle = document.defaultView.getComputedStyle(node, null);
  9790. // A Safari bug causes this to return null for `display: none` elements.
  9791. if (computedStyle) {
  9792. return asString(computedStyle.getPropertyValue(hyphenate_1(name)));
  9793. }
  9794. if (name === 'display') {
  9795. return 'none';
  9796. }
  9797. }
  9798. // Internet Explorer
  9799. if (node.currentStyle) {
  9800. if (name === 'float') {
  9801. return asString(node.currentStyle.cssFloat || node.currentStyle.styleFloat);
  9802. }
  9803. return asString(node.currentStyle[camelize_1(name)]);
  9804. }
  9805. return asString(node.style && node.style[camelize_1(name)]);
  9806. }
  9807. var getStyleProperty_1 = getStyleProperty;
  9808. /**
  9809. * Copyright (c) 2013-present, Facebook, Inc.
  9810. *
  9811. * This source code is licensed under the MIT license found in the
  9812. * LICENSE file in the root directory of this source tree.
  9813. *
  9814. * @typechecks
  9815. */
  9816. /**
  9817. * @param {DOMNode} element [description]
  9818. * @param {string} name Overflow style property name.
  9819. * @return {boolean} True if the supplied ndoe is scrollable.
  9820. */
  9821. function _isNodeScrollable(element, name) {
  9822. var overflow = Style.get(element, name);
  9823. return overflow === 'auto' || overflow === 'scroll';
  9824. }
  9825. /**
  9826. * Utilities for querying and mutating style properties.
  9827. */
  9828. var Style = {
  9829. /**
  9830. * Gets the style property for the supplied node. This will return either the
  9831. * computed style, if available, or the declared style.
  9832. *
  9833. * @param {DOMNode} node
  9834. * @param {string} name Style property name.
  9835. * @return {?string} Style property value.
  9836. */
  9837. get: getStyleProperty_1,
  9838. /**
  9839. * Determines the nearest ancestor of a node that is scrollable.
  9840. *
  9841. * NOTE: This can be expensive if used repeatedly or on a node nested deeply.
  9842. *
  9843. * @param {?DOMNode} node Node from which to start searching.
  9844. * @return {?DOMWindow|DOMElement} Scroll parent of the supplied node.
  9845. */
  9846. getScrollParent: function getScrollParent(node) {
  9847. if (!node) {
  9848. return null;
  9849. }
  9850. var ownerDocument = node.ownerDocument;
  9851. while (node && node !== ownerDocument.body) {
  9852. if (_isNodeScrollable(node, 'overflow') || _isNodeScrollable(node, 'overflowY') || _isNodeScrollable(node, 'overflowX')) {
  9853. return node;
  9854. }
  9855. node = node.parentNode;
  9856. }
  9857. return ownerDocument.defaultView || ownerDocument.parentWindow;
  9858. }
  9859. };
  9860. var Style_1 = Style;
  9861. /**
  9862. * Copyright (c) 2013-present, Facebook, Inc.
  9863. *
  9864. * This source code is licensed under the MIT license found in the
  9865. * LICENSE file in the root directory of this source tree.
  9866. *
  9867. * @typechecks
  9868. */
  9869. /**
  9870. * Gets an element's bounding rect in pixels relative to the viewport.
  9871. *
  9872. * @param {DOMElement} elem
  9873. * @return {object}
  9874. */
  9875. function getElementRect(elem) {
  9876. var docElem = elem.ownerDocument.documentElement;
  9877. // FF 2, Safari 3 and Opera 9.5- do not support getBoundingClientRect().
  9878. // IE9- will throw if the element is not in the document.
  9879. if (!('getBoundingClientRect' in elem) || !containsNode_1(docElem, elem)) {
  9880. return {
  9881. left: 0,
  9882. right: 0,
  9883. top: 0,
  9884. bottom: 0
  9885. };
  9886. }
  9887. // Subtracts clientTop/Left because IE8- added a 2px border to the
  9888. // <html> element (see http://fburl.com/1493213). IE 7 in
  9889. // Quicksmode does not report clientLeft/clientTop so there
  9890. // will be an unaccounted offset of 2px when in quirksmode
  9891. var rect = elem.getBoundingClientRect();
  9892. return {
  9893. left: Math.round(rect.left) - docElem.clientLeft,
  9894. right: Math.round(rect.right) - docElem.clientLeft,
  9895. top: Math.round(rect.top) - docElem.clientTop,
  9896. bottom: Math.round(rect.bottom) - docElem.clientTop
  9897. };
  9898. }
  9899. var getElementRect_1 = getElementRect;
  9900. /**
  9901. * Copyright (c) 2013-present, Facebook, Inc.
  9902. *
  9903. * This source code is licensed under the MIT license found in the
  9904. * LICENSE file in the root directory of this source tree.
  9905. *
  9906. * @typechecks
  9907. */
  9908. /**
  9909. * Gets an element's position in pixels relative to the viewport. The returned
  9910. * object represents the position of the element's top left corner.
  9911. *
  9912. * @param {DOMElement} element
  9913. * @return {object}
  9914. */
  9915. function getElementPosition(element) {
  9916. var rect = getElementRect_1(element);
  9917. return {
  9918. x: rect.left,
  9919. y: rect.top,
  9920. width: rect.right - rect.left,
  9921. height: rect.bottom - rect.top
  9922. };
  9923. }
  9924. var getElementPosition_1 = getElementPosition;
  9925. /**
  9926. * Copyright (c) 2013-present, Facebook, Inc.
  9927. *
  9928. * This source code is licensed under the MIT license found in the
  9929. * LICENSE file in the root directory of this source tree.
  9930. *
  9931. * @typechecks
  9932. */
  9933. var isWebkit = typeof navigator !== 'undefined' && navigator.userAgent.indexOf('AppleWebKit') > -1;
  9934. /**
  9935. * Gets the element with the document scroll properties such as `scrollLeft` and
  9936. * `scrollHeight`. This may differ across different browsers.
  9937. *
  9938. * NOTE: The return value can be null if the DOM is not yet ready.
  9939. *
  9940. * @param {?DOMDocument} doc Defaults to current document.
  9941. * @return {?DOMElement}
  9942. */
  9943. function getDocumentScrollElement(doc) {
  9944. doc = doc || document;
  9945. if (doc.scrollingElement) {
  9946. return doc.scrollingElement;
  9947. }
  9948. return !isWebkit && doc.compatMode === 'CSS1Compat' ? doc.documentElement : doc.body;
  9949. }
  9950. var getDocumentScrollElement_1 = getDocumentScrollElement;
  9951. /**
  9952. * Copyright (c) 2013-present, Facebook, Inc.
  9953. *
  9954. * This source code is licensed under the MIT license found in the
  9955. * LICENSE file in the root directory of this source tree.
  9956. *
  9957. * @typechecks
  9958. */
  9959. /**
  9960. * Gets the scroll position of the supplied element or window.
  9961. *
  9962. * The return values are unbounded, unlike `getScrollPosition`. This means they
  9963. * may be negative or exceed the element boundaries (which is possible using
  9964. * inertial scrolling).
  9965. *
  9966. * @param {DOMWindow|DOMElement} scrollable
  9967. * @return {object} Map with `x` and `y` keys.
  9968. */
  9969. function getUnboundedScrollPosition(scrollable) {
  9970. if (scrollable.Window && scrollable instanceof scrollable.Window) {
  9971. return {
  9972. x: scrollable.pageXOffset || scrollable.document.documentElement.scrollLeft,
  9973. y: scrollable.pageYOffset || scrollable.document.documentElement.scrollTop
  9974. };
  9975. }
  9976. return {
  9977. x: scrollable.scrollLeft,
  9978. y: scrollable.scrollTop
  9979. };
  9980. }
  9981. var getUnboundedScrollPosition_1 = getUnboundedScrollPosition;
  9982. /**
  9983. * Gets the scroll position of the supplied element or window.
  9984. *
  9985. * The return values are bounded. This means that if the scroll position is
  9986. * negative or exceeds the element boundaries (which is possible using inertial
  9987. * scrolling), you will get zero or the maximum scroll position, respectively.
  9988. *
  9989. * If you need the unbound scroll position, use `getUnboundedScrollPosition`.
  9990. *
  9991. * @param {DOMWindow|DOMElement} scrollable
  9992. * @return {object} Map with `x` and `y` keys.
  9993. */
  9994. function getScrollPosition(scrollable) {
  9995. var documentScrollElement = getDocumentScrollElement_1(scrollable.ownerDocument || scrollable.document);
  9996. if (scrollable.Window && scrollable instanceof scrollable.Window) {
  9997. scrollable = documentScrollElement;
  9998. }
  9999. var scrollPosition = getUnboundedScrollPosition_1(scrollable);
  10000. var viewport = scrollable === documentScrollElement ? scrollable.ownerDocument.documentElement : scrollable;
  10001. var xMax = scrollable.scrollWidth - viewport.clientWidth;
  10002. var yMax = scrollable.scrollHeight - viewport.clientHeight;
  10003. scrollPosition.x = Math.max(0, Math.min(scrollPosition.x, xMax));
  10004. scrollPosition.y = Math.max(0, Math.min(scrollPosition.y, yMax));
  10005. return scrollPosition;
  10006. }
  10007. var getScrollPosition_1 = getScrollPosition;
  10008. function getViewportWidth() {
  10009. var width = void 0;
  10010. if (document.documentElement) {
  10011. width = document.documentElement.clientWidth;
  10012. }
  10013. if (!width && document.body) {
  10014. width = document.body.clientWidth;
  10015. }
  10016. return width || 0;
  10017. } /**
  10018. * Copyright (c) 2013-present, Facebook, Inc.
  10019. *
  10020. * This source code is licensed under the MIT license found in the
  10021. * LICENSE file in the root directory of this source tree.
  10022. *
  10023. *
  10024. * @typechecks
  10025. */
  10026. function getViewportHeight() {
  10027. var height = void 0;
  10028. if (document.documentElement) {
  10029. height = document.documentElement.clientHeight;
  10030. }
  10031. if (!height && document.body) {
  10032. height = document.body.clientHeight;
  10033. }
  10034. return height || 0;
  10035. }
  10036. /**
  10037. * Gets the viewport dimensions including any scrollbars.
  10038. */
  10039. function getViewportDimensions() {
  10040. return {
  10041. width: window.innerWidth || getViewportWidth(),
  10042. height: window.innerHeight || getViewportHeight()
  10043. };
  10044. }
  10045. /**
  10046. * Gets the viewport dimensions excluding any scrollbars.
  10047. */
  10048. getViewportDimensions.withoutScrollbars = function () {
  10049. return {
  10050. width: getViewportWidth(),
  10051. height: getViewportHeight()
  10052. };
  10053. };
  10054. var getViewportDimensions_1 = getViewportDimensions;
  10055. 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; };
  10056. function _classCallCheck$b(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10057. 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; }
  10058. 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; }
  10059. var SCROLL_BUFFER = 10;
  10060. /**
  10061. * Return whether a block overlaps with either edge of the `SelectionState`.
  10062. */
  10063. var isBlockOnSelectionEdge = function isBlockOnSelectionEdge(selection, key) {
  10064. return selection.getAnchorKey() === key || selection.getFocusKey() === key;
  10065. };
  10066. /**
  10067. * The default block renderer for a `DraftEditor` component.
  10068. *
  10069. * A `DraftEditorBlock` is able to render a given `ContentBlock` to its
  10070. * appropriate decorator and inline style components.
  10071. */
  10072. var DraftEditorBlock = function (_React$Component) {
  10073. _inherits$8(DraftEditorBlock, _React$Component);
  10074. function DraftEditorBlock() {
  10075. _classCallCheck$b(this, DraftEditorBlock);
  10076. return _possibleConstructorReturn$8(this, _React$Component.apply(this, arguments));
  10077. }
  10078. DraftEditorBlock.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
  10079. return this.props.block !== nextProps.block || this.props.tree !== nextProps.tree || this.props.direction !== nextProps.direction || isBlockOnSelectionEdge(nextProps.selection, nextProps.block.getKey()) && nextProps.forceSelection;
  10080. };
  10081. /**
  10082. * When a block is mounted and overlaps the selection state, we need to make
  10083. * sure that the cursor is visible to match native behavior. This may not
  10084. * be the case if the user has pressed `RETURN` or pasted some content, since
  10085. * programatically creating these new blocks and setting the DOM selection
  10086. * will miss out on the browser natively scrolling to that position.
  10087. *
  10088. * To replicate native behavior, if the block overlaps the selection state
  10089. * on mount, force the scroll position. Check the scroll state of the scroll
  10090. * parent, and adjust it to align the entire block to the bottom of the
  10091. * scroll parent.
  10092. */
  10093. DraftEditorBlock.prototype.componentDidMount = function componentDidMount() {
  10094. var selection = this.props.selection;
  10095. var endKey = selection.getEndKey();
  10096. if (!selection.getHasFocus() || endKey !== this.props.block.getKey()) {
  10097. return;
  10098. }
  10099. var blockNode = ReactDOM.findDOMNode(this);
  10100. var scrollParent = Style_1.getScrollParent(blockNode);
  10101. var scrollPosition = getScrollPosition_1(scrollParent);
  10102. var scrollDelta = void 0;
  10103. if (scrollParent === window) {
  10104. var nodePosition = getElementPosition_1(blockNode);
  10105. var nodeBottom = nodePosition.y + nodePosition.height;
  10106. var viewportHeight = getViewportDimensions_1().height;
  10107. scrollDelta = nodeBottom - viewportHeight;
  10108. if (scrollDelta > 0) {
  10109. window.scrollTo(scrollPosition.x, scrollPosition.y + scrollDelta + SCROLL_BUFFER);
  10110. }
  10111. } else {
  10112. !(blockNode instanceof HTMLElement) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'blockNode is not an HTMLElement') : invariant_1(false) : void 0;
  10113. var blockBottom = blockNode.offsetHeight + blockNode.offsetTop;
  10114. var scrollBottom = scrollParent.offsetHeight + scrollPosition.y;
  10115. scrollDelta = blockBottom - scrollBottom;
  10116. if (scrollDelta > 0) {
  10117. Scroll_1.setTop(scrollParent, Scroll_1.getTop(scrollParent) + scrollDelta + SCROLL_BUFFER);
  10118. }
  10119. }
  10120. };
  10121. DraftEditorBlock.prototype._renderChildren = function _renderChildren() {
  10122. var _this2 = this;
  10123. var block = this.props.block;
  10124. var blockKey = block.getKey();
  10125. var text = block.getText();
  10126. var lastLeafSet = this.props.tree.size - 1;
  10127. var hasSelection = isBlockOnSelectionEdge(this.props.selection, blockKey);
  10128. return this.props.tree.map(function (leafSet, ii) {
  10129. var leavesForLeafSet = leafSet.get('leaves');
  10130. var lastLeaf = leavesForLeafSet.size - 1;
  10131. var leaves = leavesForLeafSet.map(function (leaf, jj) {
  10132. var offsetKey = DraftOffsetKey_1.encode(blockKey, ii, jj);
  10133. var start = leaf.get('start');
  10134. var end = leaf.get('end');
  10135. return React.createElement(DraftEditorLeaf_react, {
  10136. key: offsetKey,
  10137. offsetKey: offsetKey,
  10138. block: block,
  10139. start: start,
  10140. selection: hasSelection ? _this2.props.selection : null,
  10141. forceSelection: _this2.props.forceSelection,
  10142. text: text.slice(start, end),
  10143. styleSet: block.getInlineStyleAt(start),
  10144. customStyleMap: _this2.props.customStyleMap,
  10145. customStyleFn: _this2.props.customStyleFn,
  10146. isLast: ii === lastLeafSet && jj === lastLeaf
  10147. });
  10148. }).toArray();
  10149. var decoratorKey = leafSet.get('decoratorKey');
  10150. if (decoratorKey == null) {
  10151. return leaves;
  10152. }
  10153. if (!_this2.props.decorator) {
  10154. return leaves;
  10155. }
  10156. var decorator = nullthrows_1(_this2.props.decorator);
  10157. var DecoratorComponent = decorator.getComponentForKey(decoratorKey);
  10158. if (!DecoratorComponent) {
  10159. return leaves;
  10160. }
  10161. var decoratorProps = decorator.getPropsForKey(decoratorKey);
  10162. var decoratorOffsetKey = DraftOffsetKey_1.encode(blockKey, ii, 0);
  10163. var decoratedText = text.slice(leavesForLeafSet.first().get('start'), leavesForLeafSet.last().get('end'));
  10164. // Resetting dir to the same value on a child node makes Chrome/Firefox
  10165. // confused on cursor movement. See http://jsfiddle.net/d157kLck/3/
  10166. var dir = UnicodeBidiDirection_1.getHTMLDirIfDifferent(UnicodeBidi_1.getDirection(decoratedText), _this2.props.direction);
  10167. return React.createElement(
  10168. DecoratorComponent,
  10169. _extends$2({}, decoratorProps, {
  10170. contentState: _this2.props.contentState,
  10171. decoratedText: decoratedText,
  10172. dir: dir,
  10173. key: decoratorOffsetKey,
  10174. entityKey: block.getEntityAt(leafSet.get('start')),
  10175. offsetKey: decoratorOffsetKey }),
  10176. leaves
  10177. );
  10178. }).toArray();
  10179. };
  10180. DraftEditorBlock.prototype.render = function render() {
  10181. var _props = this.props,
  10182. direction = _props.direction,
  10183. offsetKey = _props.offsetKey;
  10184. var className = cx_1({
  10185. 'public/DraftStyleDefault/block': true,
  10186. 'public/DraftStyleDefault/ltr': direction === 'LTR',
  10187. 'public/DraftStyleDefault/rtl': direction === 'RTL'
  10188. });
  10189. return React.createElement(
  10190. 'div',
  10191. { 'data-offset-key': offsetKey, className: className },
  10192. this._renderChildren()
  10193. );
  10194. };
  10195. return DraftEditorBlock;
  10196. }(React.Component);
  10197. var DraftEditorBlock_react = DraftEditorBlock;
  10198. /**
  10199. * Copyright (c) 2013-present, Facebook, Inc.
  10200. *
  10201. * This source code is licensed under the MIT license found in the
  10202. * LICENSE file in the root directory of this source tree.
  10203. *
  10204. * @typechecks static-only
  10205. */
  10206. /**
  10207. * Combines multiple className strings into one.
  10208. * http://jsperf.com/joinclasses-args-vs-array
  10209. *
  10210. * @param {...?string} className
  10211. * @return {string}
  10212. */
  10213. function joinClasses(className /*, ... */) {
  10214. if (!className) {
  10215. className = '';
  10216. }
  10217. var nextClass = void 0;
  10218. var argLength = arguments.length;
  10219. if (argLength > 1) {
  10220. for (var ii = 1; ii < argLength; ii++) {
  10221. nextClass = arguments[ii];
  10222. if (nextClass) {
  10223. className = (className ? className + ' ' : '') + nextClass;
  10224. }
  10225. }
  10226. }
  10227. return className;
  10228. }
  10229. var joinClasses_1 = joinClasses;
  10230. 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; };
  10231. function _classCallCheck$c(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10232. 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; }
  10233. 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; }
  10234. /**
  10235. * Provide default styling for list items. This way, lists will be styled with
  10236. * proper counters and indentation even if the caller does not specify
  10237. * their own styling at all. If more than five levels of nesting are needed,
  10238. * the necessary CSS classes can be provided via `blockStyleFn` configuration.
  10239. */
  10240. var getListItemClasses = function getListItemClasses(type, depth, shouldResetCount, direction) {
  10241. return cx_1({
  10242. 'public/DraftStyleDefault/unorderedListItem': type === 'unordered-list-item',
  10243. 'public/DraftStyleDefault/orderedListItem': type === 'ordered-list-item',
  10244. 'public/DraftStyleDefault/reset': shouldResetCount,
  10245. 'public/DraftStyleDefault/depth0': depth === 0,
  10246. 'public/DraftStyleDefault/depth1': depth === 1,
  10247. 'public/DraftStyleDefault/depth2': depth === 2,
  10248. 'public/DraftStyleDefault/depth3': depth === 3,
  10249. 'public/DraftStyleDefault/depth4': depth === 4,
  10250. 'public/DraftStyleDefault/listLTR': direction === 'LTR',
  10251. 'public/DraftStyleDefault/listRTL': direction === 'RTL'
  10252. });
  10253. };
  10254. /**
  10255. * `DraftEditorContents` is the container component for all block components
  10256. * rendered for a `DraftEditor`. It is optimized to aggressively avoid
  10257. * re-rendering blocks whenever possible.
  10258. *
  10259. * This component is separate from `DraftEditor` because certain props
  10260. * (for instance, ARIA props) must be allowed to update without affecting
  10261. * the contents of the editor.
  10262. */
  10263. var DraftEditorContents = function (_React$Component) {
  10264. _inherits$9(DraftEditorContents, _React$Component);
  10265. function DraftEditorContents() {
  10266. _classCallCheck$c(this, DraftEditorContents);
  10267. return _possibleConstructorReturn$9(this, _React$Component.apply(this, arguments));
  10268. }
  10269. DraftEditorContents.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
  10270. var prevEditorState = this.props.editorState;
  10271. var nextEditorState = nextProps.editorState;
  10272. var prevDirectionMap = prevEditorState.getDirectionMap();
  10273. var nextDirectionMap = nextEditorState.getDirectionMap();
  10274. // Text direction has changed for one or more blocks. We must re-render.
  10275. if (prevDirectionMap !== nextDirectionMap) {
  10276. return true;
  10277. }
  10278. var didHaveFocus = prevEditorState.getSelection().getHasFocus();
  10279. var nowHasFocus = nextEditorState.getSelection().getHasFocus();
  10280. if (didHaveFocus !== nowHasFocus) {
  10281. return true;
  10282. }
  10283. var nextNativeContent = nextEditorState.getNativelyRenderedContent();
  10284. var wasComposing = prevEditorState.isInCompositionMode();
  10285. var nowComposing = nextEditorState.isInCompositionMode();
  10286. // If the state is unchanged or we're currently rendering a natively
  10287. // rendered state, there's nothing new to be done.
  10288. if (prevEditorState === nextEditorState || nextNativeContent !== null && nextEditorState.getCurrentContent() === nextNativeContent || wasComposing && nowComposing) {
  10289. return false;
  10290. }
  10291. var prevContent = prevEditorState.getCurrentContent();
  10292. var nextContent = nextEditorState.getCurrentContent();
  10293. var prevDecorator = prevEditorState.getDecorator();
  10294. var nextDecorator = nextEditorState.getDecorator();
  10295. return wasComposing !== nowComposing || prevContent !== nextContent || prevDecorator !== nextDecorator || nextEditorState.mustForceSelection();
  10296. };
  10297. DraftEditorContents.prototype.render = function render() {
  10298. var _props = this.props,
  10299. blockRenderMap = _props.blockRenderMap,
  10300. blockRendererFn = _props.blockRendererFn,
  10301. blockStyleFn = _props.blockStyleFn,
  10302. customStyleMap = _props.customStyleMap,
  10303. customStyleFn = _props.customStyleFn,
  10304. editorState = _props.editorState,
  10305. editorKey = _props.editorKey,
  10306. textDirectionality = _props.textDirectionality;
  10307. var content = editorState.getCurrentContent();
  10308. var selection = editorState.getSelection();
  10309. var forceSelection = editorState.mustForceSelection();
  10310. var decorator = editorState.getDecorator();
  10311. var directionMap = nullthrows_1(editorState.getDirectionMap());
  10312. var blocksAsArray = content.getBlocksAsArray();
  10313. var processedBlocks = [];
  10314. var currentDepth = null;
  10315. var lastWrapperTemplate = null;
  10316. for (var ii = 0; ii < blocksAsArray.length; ii++) {
  10317. var _block = blocksAsArray[ii];
  10318. var key = _block.getKey();
  10319. var blockType = _block.getType();
  10320. var customRenderer = blockRendererFn(_block);
  10321. var CustomComponent = void 0,
  10322. customProps = void 0,
  10323. customEditable = void 0;
  10324. if (customRenderer) {
  10325. CustomComponent = customRenderer.component;
  10326. customProps = customRenderer.props;
  10327. customEditable = customRenderer.editable;
  10328. }
  10329. var direction = textDirectionality ? textDirectionality : directionMap.get(key);
  10330. var offsetKey = DraftOffsetKey_1.encode(key, 0, 0);
  10331. var componentProps = {
  10332. contentState: content,
  10333. block: _block,
  10334. blockProps: customProps,
  10335. blockStyleFn: blockStyleFn,
  10336. customStyleMap: customStyleMap,
  10337. customStyleFn: customStyleFn,
  10338. decorator: decorator,
  10339. direction: direction,
  10340. forceSelection: forceSelection,
  10341. key: key,
  10342. offsetKey: offsetKey,
  10343. selection: selection,
  10344. tree: editorState.getBlockTree(key)
  10345. };
  10346. var configForType = blockRenderMap.get(blockType) || blockRenderMap.get('unstyled');
  10347. var wrapperTemplate = configForType.wrapper;
  10348. var Element = configForType.element || blockRenderMap.get('unstyled').element;
  10349. var depth = _block.getDepth();
  10350. var className = '';
  10351. if (blockStyleFn) {
  10352. className = blockStyleFn(_block);
  10353. }
  10354. // List items are special snowflakes, since we handle nesting and
  10355. // counters manually.
  10356. if (Element === 'li') {
  10357. var shouldResetCount = lastWrapperTemplate !== wrapperTemplate || currentDepth === null || depth > currentDepth;
  10358. className = joinClasses_1(className, getListItemClasses(blockType, depth, shouldResetCount, direction));
  10359. }
  10360. var Component = CustomComponent || DraftEditorBlock_react;
  10361. var childProps = {
  10362. className: className,
  10363. 'data-block': true,
  10364. 'data-editor': editorKey,
  10365. 'data-offset-key': offsetKey,
  10366. key: key
  10367. };
  10368. if (customEditable !== undefined) {
  10369. childProps = _extends$3({}, childProps, {
  10370. contentEditable: customEditable,
  10371. suppressContentEditableWarning: true
  10372. });
  10373. }
  10374. var child = React.createElement(Element, childProps, React.createElement(Component, componentProps));
  10375. processedBlocks.push({
  10376. block: child,
  10377. wrapperTemplate: wrapperTemplate,
  10378. key: key,
  10379. offsetKey: offsetKey
  10380. });
  10381. if (wrapperTemplate) {
  10382. currentDepth = _block.getDepth();
  10383. } else {
  10384. currentDepth = null;
  10385. }
  10386. lastWrapperTemplate = wrapperTemplate;
  10387. }
  10388. // Group contiguous runs of blocks that have the same wrapperTemplate
  10389. var outputBlocks = [];
  10390. for (var _ii = 0; _ii < processedBlocks.length;) {
  10391. var info = processedBlocks[_ii];
  10392. if (info.wrapperTemplate) {
  10393. var blocks = [];
  10394. do {
  10395. blocks.push(processedBlocks[_ii].block);
  10396. _ii++;
  10397. } while (_ii < processedBlocks.length && processedBlocks[_ii].wrapperTemplate === info.wrapperTemplate);
  10398. var wrapperElement = React.cloneElement(info.wrapperTemplate, {
  10399. key: info.key + '-wrap',
  10400. 'data-offset-key': info.offsetKey
  10401. }, blocks);
  10402. outputBlocks.push(wrapperElement);
  10403. } else {
  10404. outputBlocks.push(info.block);
  10405. _ii++;
  10406. }
  10407. }
  10408. return React.createElement(
  10409. 'div',
  10410. { 'data-contents': 'true' },
  10411. outputBlocks
  10412. );
  10413. };
  10414. return DraftEditorContents;
  10415. }(React.Component);
  10416. var DraftEditorContentsCore_react = DraftEditorContents;
  10417. var DraftEditorContents_react = DraftEditorContentsCore_react;
  10418. /**
  10419. * Copyright (c) 2013-present, Facebook, Inc.
  10420. *
  10421. * This source code is licensed under the MIT license found in the
  10422. * LICENSE file in the root directory of this source tree.
  10423. *
  10424. */
  10425. var PhotosMimeType = {
  10426. isImage: function isImage(mimeString) {
  10427. return getParts(mimeString)[0] === 'image';
  10428. },
  10429. isJpeg: function isJpeg(mimeString) {
  10430. var parts = getParts(mimeString);
  10431. return PhotosMimeType.isImage(mimeString) && (
  10432. // see http://fburl.com/10972194
  10433. parts[1] === 'jpeg' || parts[1] === 'pjpeg');
  10434. }
  10435. };
  10436. function getParts(mimeString) {
  10437. return mimeString.split('/');
  10438. }
  10439. var PhotosMimeType_1 = PhotosMimeType;
  10440. /**
  10441. * Copyright (c) 2013-present, Facebook, Inc.
  10442. *
  10443. * This source code is licensed under the MIT license found in the
  10444. * LICENSE file in the root directory of this source tree.
  10445. *
  10446. * @typechecks
  10447. */
  10448. /**
  10449. * Convert array-like objects to arrays.
  10450. *
  10451. * This API assumes the caller knows the contents of the data type. For less
  10452. * well defined inputs use createArrayFromMixed.
  10453. *
  10454. * @param {object|function|filelist} obj
  10455. * @return {array}
  10456. */
  10457. function toArray(obj) {
  10458. var length = obj.length;
  10459. // Some browsers builtin objects can report typeof 'function' (e.g. NodeList
  10460. // in old versions of Safari).
  10461. !(!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;
  10462. !(typeof length === 'number') ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'toArray: Object needs a length property') : invariant_1(false) : void 0;
  10463. !(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;
  10464. !(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;
  10465. // Old IE doesn't give collections access to hasOwnProperty. Assume inputs
  10466. // without method will throw during the slice call and skip straight to the
  10467. // fallback.
  10468. if (obj.hasOwnProperty) {
  10469. try {
  10470. return Array.prototype.slice.call(obj);
  10471. } catch (e) {
  10472. // IE < 9 does not support Array#slice on collections objects
  10473. }
  10474. }
  10475. // Fall back to copying key by key. This assumes all keys have a value,
  10476. // so will not preserve sparsely populated inputs.
  10477. var ret = Array(length);
  10478. for (var ii = 0; ii < length; ii++) {
  10479. ret[ii] = obj[ii];
  10480. }
  10481. return ret;
  10482. }
  10483. /**
  10484. * Perform a heuristic test to determine if an object is "array-like".
  10485. *
  10486. * A monk asked Joshu, a Zen master, "Has a dog Buddha nature?"
  10487. * Joshu replied: "Mu."
  10488. *
  10489. * This function determines if its argument has "array nature": it returns
  10490. * true if the argument is an actual array, an `arguments' object, or an
  10491. * HTMLCollection (e.g. node.childNodes or node.getElementsByTagName()).
  10492. *
  10493. * It will return false for other array-like objects like Filelist.
  10494. *
  10495. * @param {*} obj
  10496. * @return {boolean}
  10497. */
  10498. function hasArrayNature(obj) {
  10499. return (
  10500. // not null/false
  10501. !!obj && (
  10502. // arrays are objects, NodeLists are functions in Safari
  10503. typeof obj == 'object' || typeof obj == 'function') &&
  10504. // quacks like an array
  10505. 'length' in obj &&
  10506. // not window
  10507. !('setInterval' in obj) &&
  10508. // no DOM node should be considered an array-like
  10509. // a 'select' element has 'length' and 'item' properties on IE8
  10510. typeof obj.nodeType != 'number' && (
  10511. // a real array
  10512. Array.isArray(obj) ||
  10513. // arguments
  10514. 'callee' in obj ||
  10515. // HTMLCollection/NodeList
  10516. 'item' in obj)
  10517. );
  10518. }
  10519. /**
  10520. * Ensure that the argument is an array by wrapping it in an array if it is not.
  10521. * Creates a copy of the argument if it is already an array.
  10522. *
  10523. * This is mostly useful idiomatically:
  10524. *
  10525. * var createArrayFromMixed = require('createArrayFromMixed');
  10526. *
  10527. * function takesOneOrMoreThings(things) {
  10528. * things = createArrayFromMixed(things);
  10529. * ...
  10530. * }
  10531. *
  10532. * This allows you to treat `things' as an array, but accept scalars in the API.
  10533. *
  10534. * If you need to convert an array-like object, like `arguments`, into an array
  10535. * use toArray instead.
  10536. *
  10537. * @param {*} obj
  10538. * @return {array}
  10539. */
  10540. function createArrayFromMixed(obj) {
  10541. if (!hasArrayNature(obj)) {
  10542. return [obj];
  10543. } else if (Array.isArray(obj)) {
  10544. return obj.slice();
  10545. } else {
  10546. return toArray(obj);
  10547. }
  10548. }
  10549. var createArrayFromMixed_1 = createArrayFromMixed;
  10550. function _classCallCheck$d(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10551. /**
  10552. * Copyright (c) 2013-present, Facebook, Inc.
  10553. *
  10554. * This source code is licensed under the MIT license found in the
  10555. * LICENSE file in the root directory of this source tree.
  10556. *
  10557. * @typechecks
  10558. */
  10559. var CR_LF_REGEX = new RegExp('\r\n', 'g');
  10560. var LF_ONLY = '\n';
  10561. var RICH_TEXT_TYPES = {
  10562. 'text/rtf': 1,
  10563. 'text/html': 1
  10564. };
  10565. /**
  10566. * If DataTransferItem is a file then return the Blob of data.
  10567. *
  10568. * @param {object} item
  10569. * @return {?blob}
  10570. */
  10571. function getFileFromDataTransfer(item) {
  10572. if (item.kind == 'file') {
  10573. return item.getAsFile();
  10574. }
  10575. }
  10576. var DataTransfer = function () {
  10577. /**
  10578. * @param {object} data
  10579. */
  10580. function DataTransfer(data) {
  10581. _classCallCheck$d(this, DataTransfer);
  10582. this.data = data;
  10583. // Types could be DOMStringList or array
  10584. this.types = data.types ? createArrayFromMixed_1(data.types) : [];
  10585. }
  10586. /**
  10587. * Is this likely to be a rich text data transfer?
  10588. *
  10589. * @return {boolean}
  10590. */
  10591. DataTransfer.prototype.isRichText = function isRichText() {
  10592. // If HTML is available, treat this data as rich text. This way, we avoid
  10593. // using a pasted image if it is packaged with HTML -- this may occur with
  10594. // pastes from MS Word, for example. However this is only rich text if
  10595. // there's accompanying text.
  10596. if (this.getHTML() && this.getText()) {
  10597. return true;
  10598. }
  10599. // When an image is copied from a preview window, you end up with two
  10600. // DataTransferItems one of which is a file's metadata as text. Skip those.
  10601. if (this.isImage()) {
  10602. return false;
  10603. }
  10604. return this.types.some(function (type) {
  10605. return RICH_TEXT_TYPES[type];
  10606. });
  10607. };
  10608. /**
  10609. * Get raw text.
  10610. *
  10611. * @return {?string}
  10612. */
  10613. DataTransfer.prototype.getText = function getText() {
  10614. var text;
  10615. if (this.data.getData) {
  10616. if (!this.types.length) {
  10617. text = this.data.getData('Text');
  10618. } else if (this.types.indexOf('text/plain') != -1) {
  10619. text = this.data.getData('text/plain');
  10620. }
  10621. }
  10622. return text ? text.replace(CR_LF_REGEX, LF_ONLY) : null;
  10623. };
  10624. /**
  10625. * Get HTML paste data
  10626. *
  10627. * @return {?string}
  10628. */
  10629. DataTransfer.prototype.getHTML = function getHTML() {
  10630. if (this.data.getData) {
  10631. if (!this.types.length) {
  10632. return this.data.getData('Text');
  10633. } else if (this.types.indexOf('text/html') != -1) {
  10634. return this.data.getData('text/html');
  10635. }
  10636. }
  10637. };
  10638. /**
  10639. * Is this a link data transfer?
  10640. *
  10641. * @return {boolean}
  10642. */
  10643. DataTransfer.prototype.isLink = function isLink() {
  10644. return this.types.some(function (type) {
  10645. return type.indexOf('Url') != -1 || type.indexOf('text/uri-list') != -1 || type.indexOf('text/x-moz-url');
  10646. });
  10647. };
  10648. /**
  10649. * Get a link url.
  10650. *
  10651. * @return {?string}
  10652. */
  10653. DataTransfer.prototype.getLink = function getLink() {
  10654. if (this.data.getData) {
  10655. if (this.types.indexOf('text/x-moz-url') != -1) {
  10656. var url = this.data.getData('text/x-moz-url').split('\n');
  10657. return url[0];
  10658. }
  10659. return this.types.indexOf('text/uri-list') != -1 ? this.data.getData('text/uri-list') : this.data.getData('url');
  10660. }
  10661. return null;
  10662. };
  10663. /**
  10664. * Is this an image data transfer?
  10665. *
  10666. * @return {boolean}
  10667. */
  10668. DataTransfer.prototype.isImage = function isImage() {
  10669. var isImage = this.types.some(function (type) {
  10670. // Firefox will have a type of application/x-moz-file for images during
  10671. // dragging
  10672. return type.indexOf('application/x-moz-file') != -1;
  10673. });
  10674. if (isImage) {
  10675. return true;
  10676. }
  10677. var items = this.getFiles();
  10678. for (var i = 0; i < items.length; i++) {
  10679. var type = items[i].type;
  10680. if (!PhotosMimeType_1.isImage(type)) {
  10681. return false;
  10682. }
  10683. }
  10684. return true;
  10685. };
  10686. DataTransfer.prototype.getCount = function getCount() {
  10687. if (this.data.hasOwnProperty('items')) {
  10688. return this.data.items.length;
  10689. } else if (this.data.hasOwnProperty('mozItemCount')) {
  10690. return this.data.mozItemCount;
  10691. } else if (this.data.files) {
  10692. return this.data.files.length;
  10693. }
  10694. return null;
  10695. };
  10696. /**
  10697. * Get files.
  10698. *
  10699. * @return {array}
  10700. */
  10701. DataTransfer.prototype.getFiles = function getFiles() {
  10702. if (this.data.items) {
  10703. // createArrayFromMixed doesn't properly handle DataTransferItemLists.
  10704. return Array.prototype.slice.call(this.data.items).map(getFileFromDataTransfer).filter(emptyFunction_1.thatReturnsArgument);
  10705. } else if (this.data.files) {
  10706. return Array.prototype.slice.call(this.data.files);
  10707. } else {
  10708. return [];
  10709. }
  10710. };
  10711. /**
  10712. * Are there any files to fetch?
  10713. *
  10714. * @return {boolean}
  10715. */
  10716. DataTransfer.prototype.hasFiles = function hasFiles() {
  10717. return this.getFiles().length > 0;
  10718. };
  10719. return DataTransfer;
  10720. }();
  10721. var DataTransfer_1 = DataTransfer;
  10722. /**
  10723. * Copyright (c) 2013-present, Facebook, Inc.
  10724. * All rights reserved.
  10725. *
  10726. * This source code is licensed under the BSD-style license found in the
  10727. * LICENSE file in the root directory of this source tree. An additional grant
  10728. * of patent rights can be found in the PATENTS file in the same directory.
  10729. *
  10730. * @providesModule getSelectionOffsetKeyForNode
  10731. * @format
  10732. *
  10733. */
  10734. /**
  10735. * Get offset key from a node or it's child nodes. Return the first offset key
  10736. * found on the DOM tree of given node.
  10737. */
  10738. function getSelectionOffsetKeyForNode(node) {
  10739. if (node instanceof Element) {
  10740. var offsetKey = node.getAttribute('data-offset-key');
  10741. if (offsetKey) {
  10742. return offsetKey;
  10743. }
  10744. for (var ii = 0; ii < node.childNodes.length; ii++) {
  10745. var childOffsetKey = getSelectionOffsetKeyForNode(node.childNodes[ii]);
  10746. if (childOffsetKey) {
  10747. return childOffsetKey;
  10748. }
  10749. }
  10750. }
  10751. return null;
  10752. }
  10753. var getSelectionOffsetKeyForNode_1 = getSelectionOffsetKeyForNode;
  10754. /**
  10755. * Get the key from the node's nearest offset-aware ancestor.
  10756. */
  10757. function findAncestorOffsetKey(node) {
  10758. var searchNode = node;
  10759. while (searchNode && searchNode !== document.documentElement) {
  10760. var key = getSelectionOffsetKeyForNode_1(searchNode);
  10761. if (key != null) {
  10762. return key;
  10763. }
  10764. searchNode = searchNode.parentNode;
  10765. }
  10766. return null;
  10767. }
  10768. var findAncestorOffsetKey_1 = findAncestorOffsetKey;
  10769. var TEXT_CLIPPING_REGEX = /\.textClipping$/;
  10770. var TEXT_TYPES = {
  10771. 'text/plain': true,
  10772. 'text/html': true,
  10773. 'text/rtf': true
  10774. };
  10775. // Somewhat arbitrary upper bound on text size. Let's not lock up the browser.
  10776. var TEXT_SIZE_UPPER_BOUND = 5000;
  10777. /**
  10778. * Extract the text content from a file list.
  10779. */
  10780. function getTextContentFromFiles(files, callback) {
  10781. var readCount = 0;
  10782. var results = [];
  10783. files.forEach(function ( /*blob*/file) {
  10784. readFile(file, function ( /*string*/text) {
  10785. readCount++;
  10786. text && results.push(text.slice(0, TEXT_SIZE_UPPER_BOUND));
  10787. if (readCount == files.length) {
  10788. callback(results.join('\r'));
  10789. }
  10790. });
  10791. });
  10792. }
  10793. /**
  10794. * todo isaac: Do work to turn html/rtf into a content fragment.
  10795. */
  10796. function readFile(file, callback) {
  10797. if (!commonjsGlobal.FileReader || file.type && !(file.type in TEXT_TYPES)) {
  10798. callback('');
  10799. return;
  10800. }
  10801. if (file.type === '') {
  10802. var contents = '';
  10803. // Special-case text clippings, which have an empty type but include
  10804. // `.textClipping` in the file name. `readAsText` results in an empty
  10805. // string for text clippings, so we force the file name to serve
  10806. // as the text value for the file.
  10807. if (TEXT_CLIPPING_REGEX.test(file.name)) {
  10808. contents = file.name.replace(TEXT_CLIPPING_REGEX, '');
  10809. }
  10810. callback(contents);
  10811. return;
  10812. }
  10813. var reader = new FileReader();
  10814. reader.onload = function () {
  10815. var result = reader.result;
  10816. !(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;
  10817. callback(result);
  10818. };
  10819. reader.onerror = function () {
  10820. callback('');
  10821. };
  10822. reader.readAsText(file);
  10823. }
  10824. var getTextContentFromFiles_1 = getTextContentFromFiles;
  10825. function getUpdatedSelectionState(editorState, anchorKey, anchorOffset, focusKey, focusOffset) {
  10826. var selection = nullthrows_1(editorState.getSelection());
  10827. if (process.env.NODE_ENV !== 'production') {
  10828. if (!anchorKey || !focusKey) {
  10829. /*eslint-disable no-console */
  10830. console.warn('Invalid selection state.', arguments, editorState.toJS());
  10831. /*eslint-enable no-console */
  10832. return selection;
  10833. }
  10834. }
  10835. var anchorPath = DraftOffsetKey_1.decode(anchorKey);
  10836. var anchorBlockKey = anchorPath.blockKey;
  10837. var anchorLeaf = editorState.getBlockTree(anchorBlockKey).getIn([anchorPath.decoratorKey, 'leaves', anchorPath.leafKey]);
  10838. var focusPath = DraftOffsetKey_1.decode(focusKey);
  10839. var focusBlockKey = focusPath.blockKey;
  10840. var focusLeaf = editorState.getBlockTree(focusBlockKey).getIn([focusPath.decoratorKey, 'leaves', focusPath.leafKey]);
  10841. var anchorLeafStart = anchorLeaf.get('start');
  10842. var focusLeafStart = focusLeaf.get('start');
  10843. var anchorBlockOffset = anchorLeaf ? anchorLeafStart + anchorOffset : null;
  10844. var focusBlockOffset = focusLeaf ? focusLeafStart + focusOffset : null;
  10845. var areEqual = selection.getAnchorKey() === anchorBlockKey && selection.getAnchorOffset() === anchorBlockOffset && selection.getFocusKey() === focusBlockKey && selection.getFocusOffset() === focusBlockOffset;
  10846. if (areEqual) {
  10847. return selection;
  10848. }
  10849. var isBackward = false;
  10850. if (anchorBlockKey === focusBlockKey) {
  10851. var anchorLeafEnd = anchorLeaf.get('end');
  10852. var focusLeafEnd = focusLeaf.get('end');
  10853. if (focusLeafStart === anchorLeafStart && focusLeafEnd === anchorLeafEnd) {
  10854. isBackward = focusOffset < anchorOffset;
  10855. } else {
  10856. isBackward = focusLeafStart < anchorLeafStart;
  10857. }
  10858. } else {
  10859. var startKey = editorState.getCurrentContent().getBlockMap().keySeq().skipUntil(function (v) {
  10860. return v === anchorBlockKey || v === focusBlockKey;
  10861. }).first();
  10862. isBackward = startKey === focusBlockKey;
  10863. }
  10864. return selection.merge({
  10865. anchorKey: anchorBlockKey,
  10866. anchorOffset: anchorBlockOffset,
  10867. focusKey: focusBlockKey,
  10868. focusOffset: focusBlockOffset,
  10869. isBackward: isBackward
  10870. });
  10871. }
  10872. var getUpdatedSelectionState_1 = getUpdatedSelectionState;
  10873. /**
  10874. * Get a SelectionState for the supplied mouse event.
  10875. */
  10876. function getSelectionForEvent(event, editorState) {
  10877. var node = null;
  10878. var offset = null;
  10879. if (typeof document.caretRangeFromPoint === 'function') {
  10880. var dropRange = document.caretRangeFromPoint(event.x, event.y);
  10881. node = dropRange.startContainer;
  10882. offset = dropRange.startOffset;
  10883. } else if (event.rangeParent) {
  10884. node = event.rangeParent;
  10885. offset = event.rangeOffset;
  10886. } else {
  10887. return null;
  10888. }
  10889. node = nullthrows_1(node);
  10890. offset = nullthrows_1(offset);
  10891. var offsetKey = nullthrows_1(findAncestorOffsetKey_1(node));
  10892. return getUpdatedSelectionState_1(editorState, offsetKey, offset, offsetKey, offset);
  10893. }
  10894. var DraftEditorDragHandler = {
  10895. /**
  10896. * Drag originating from input terminated.
  10897. */
  10898. onDragEnd: function onDragEnd(editor) {
  10899. editor.exitCurrentMode();
  10900. },
  10901. /**
  10902. * Handle data being dropped.
  10903. */
  10904. onDrop: function onDrop(editor, e) {
  10905. var data = new DataTransfer_1(e.nativeEvent.dataTransfer);
  10906. var editorState = editor._latestEditorState;
  10907. var dropSelection = getSelectionForEvent(e.nativeEvent, editorState);
  10908. e.preventDefault();
  10909. editor.exitCurrentMode();
  10910. if (dropSelection == null) {
  10911. return;
  10912. }
  10913. var files = data.getFiles();
  10914. if (files.length > 0) {
  10915. if (editor.props.handleDroppedFiles && isEventHandled_1(editor.props.handleDroppedFiles(dropSelection, files))) {
  10916. return;
  10917. }
  10918. getTextContentFromFiles_1(files, function (fileText) {
  10919. fileText && editor.update(insertTextAtSelection(editorState, dropSelection, fileText));
  10920. });
  10921. return;
  10922. }
  10923. var dragType = editor._internalDrag ? 'internal' : 'external';
  10924. if (editor.props.handleDrop && isEventHandled_1(editor.props.handleDrop(dropSelection, data, dragType))) {
  10925. return;
  10926. }
  10927. if (editor._internalDrag) {
  10928. editor.update(moveText(editorState, dropSelection));
  10929. return;
  10930. }
  10931. editor.update(insertTextAtSelection(editorState, dropSelection, data.getText()));
  10932. }
  10933. };
  10934. function moveText(editorState, targetSelection) {
  10935. var newContentState = DraftModifier_1.moveText(editorState.getCurrentContent(), editorState.getSelection(), targetSelection);
  10936. return EditorState_1.push(editorState, newContentState, 'insert-fragment');
  10937. }
  10938. /**
  10939. * Insert text at a specified selection.
  10940. */
  10941. function insertTextAtSelection(editorState, selection, text) {
  10942. var newContentState = DraftModifier_1.insertText(editorState.getCurrentContent(), selection, text, editorState.getCurrentInlineStyle());
  10943. return EditorState_1.push(editorState, newContentState, 'insert-fragment');
  10944. }
  10945. var DraftEditorDragHandler_1 = DraftEditorDragHandler;
  10946. (function (global, undefined$1) {
  10947. if (global.setImmediate) {
  10948. return;
  10949. }
  10950. var nextHandle = 1; // Spec says greater than zero
  10951. var tasksByHandle = {};
  10952. var currentlyRunningATask = false;
  10953. var doc = global.document;
  10954. var registerImmediate;
  10955. function setImmediate(callback) {
  10956. // Callback can either be a function or a string
  10957. if (typeof callback !== "function") {
  10958. callback = new Function("" + callback);
  10959. }
  10960. // Copy function arguments
  10961. var args = new Array(arguments.length - 1);
  10962. for (var i = 0; i < args.length; i++) {
  10963. args[i] = arguments[i + 1];
  10964. }
  10965. // Store and register the task
  10966. var task = { callback: callback, args: args };
  10967. tasksByHandle[nextHandle] = task;
  10968. registerImmediate(nextHandle);
  10969. return nextHandle++;
  10970. }
  10971. function clearImmediate(handle) {
  10972. delete tasksByHandle[handle];
  10973. }
  10974. function run(task) {
  10975. var callback = task.callback;
  10976. var args = task.args;
  10977. switch (args.length) {
  10978. case 0:
  10979. callback();
  10980. break;
  10981. case 1:
  10982. callback(args[0]);
  10983. break;
  10984. case 2:
  10985. callback(args[0], args[1]);
  10986. break;
  10987. case 3:
  10988. callback(args[0], args[1], args[2]);
  10989. break;
  10990. default:
  10991. callback.apply(undefined$1, args);
  10992. break;
  10993. }
  10994. }
  10995. function runIfPresent(handle) {
  10996. // From the spec: "Wait until any invocations of this algorithm started before this one have completed."
  10997. // So if we're currently running a task, we'll need to delay this invocation.
  10998. if (currentlyRunningATask) {
  10999. // Delay by doing a setTimeout. setImmediate was tried instead, but in Firefox 7 it generated a
  11000. // "too much recursion" error.
  11001. setTimeout(runIfPresent, 0, handle);
  11002. } else {
  11003. var task = tasksByHandle[handle];
  11004. if (task) {
  11005. currentlyRunningATask = true;
  11006. try {
  11007. run(task);
  11008. } finally {
  11009. clearImmediate(handle);
  11010. currentlyRunningATask = false;
  11011. }
  11012. }
  11013. }
  11014. }
  11015. function installNextTickImplementation() {
  11016. registerImmediate = function(handle) {
  11017. process.nextTick(function () { runIfPresent(handle); });
  11018. };
  11019. }
  11020. function canUsePostMessage() {
  11021. // The test against `importScripts` prevents this implementation from being installed inside a web worker,
  11022. // where `global.postMessage` means something completely different and can't be used for this purpose.
  11023. if (global.postMessage && !global.importScripts) {
  11024. var postMessageIsAsynchronous = true;
  11025. var oldOnMessage = global.onmessage;
  11026. global.onmessage = function() {
  11027. postMessageIsAsynchronous = false;
  11028. };
  11029. global.postMessage("", "*");
  11030. global.onmessage = oldOnMessage;
  11031. return postMessageIsAsynchronous;
  11032. }
  11033. }
  11034. function installPostMessageImplementation() {
  11035. // Installs an event handler on `global` for the `message` event: see
  11036. // * https://developer.mozilla.org/en/DOM/window.postMessage
  11037. // * http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html#crossDocumentMessages
  11038. var messagePrefix = "setImmediate$" + Math.random() + "$";
  11039. var onGlobalMessage = function(event) {
  11040. if (event.source === global &&
  11041. typeof event.data === "string" &&
  11042. event.data.indexOf(messagePrefix) === 0) {
  11043. runIfPresent(+event.data.slice(messagePrefix.length));
  11044. }
  11045. };
  11046. if (global.addEventListener) {
  11047. global.addEventListener("message", onGlobalMessage, false);
  11048. } else {
  11049. global.attachEvent("onmessage", onGlobalMessage);
  11050. }
  11051. registerImmediate = function(handle) {
  11052. global.postMessage(messagePrefix + handle, "*");
  11053. };
  11054. }
  11055. function installMessageChannelImplementation() {
  11056. var channel = new MessageChannel();
  11057. channel.port1.onmessage = function(event) {
  11058. var handle = event.data;
  11059. runIfPresent(handle);
  11060. };
  11061. registerImmediate = function(handle) {
  11062. channel.port2.postMessage(handle);
  11063. };
  11064. }
  11065. function installReadyStateChangeImplementation() {
  11066. var html = doc.documentElement;
  11067. registerImmediate = function(handle) {
  11068. // Create a <script> element; its readystatechange event will be fired asynchronously once it is inserted
  11069. // into the document. Do so, thus queuing up the task. Remember to clean up once it's been called.
  11070. var script = doc.createElement("script");
  11071. script.onreadystatechange = function () {
  11072. runIfPresent(handle);
  11073. script.onreadystatechange = null;
  11074. html.removeChild(script);
  11075. script = null;
  11076. };
  11077. html.appendChild(script);
  11078. };
  11079. }
  11080. function installSetTimeoutImplementation() {
  11081. registerImmediate = function(handle) {
  11082. setTimeout(runIfPresent, 0, handle);
  11083. };
  11084. }
  11085. // If supported, we should attach to the prototype of global, since that is where setTimeout et al. live.
  11086. var attachTo = Object.getPrototypeOf && Object.getPrototypeOf(global);
  11087. attachTo = attachTo && attachTo.setTimeout ? attachTo : global;
  11088. // Don't get fooled by e.g. browserify environments.
  11089. if ({}.toString.call(global.process) === "[object process]") {
  11090. // For Node.js before 0.9
  11091. installNextTickImplementation();
  11092. } else if (canUsePostMessage()) {
  11093. // For non-IE10 modern browsers
  11094. installPostMessageImplementation();
  11095. } else if (global.MessageChannel) {
  11096. // For web workers, where supported
  11097. installMessageChannelImplementation();
  11098. } else if (doc && "onreadystatechange" in doc.createElement("script")) {
  11099. // For IE 6–8
  11100. installReadyStateChangeImplementation();
  11101. } else {
  11102. // For older browsers
  11103. installSetTimeoutImplementation();
  11104. }
  11105. attachTo.setImmediate = setImmediate;
  11106. attachTo.clearImmediate = clearImmediate;
  11107. }(typeof self === "undefined" ? typeof commonjsGlobal === "undefined" ? commonjsGlobal : commonjsGlobal : self));
  11108. // setimmediate adds setImmediate to the global. We want to make sure we export
  11109. // the actual function.
  11110. var setImmediate = commonjsGlobal.setImmediate;
  11111. // When nothing is focused, Firefox regards two characters, `'` and `/`, as
  11112. // commands that should open and focus the "quickfind" search bar. This should
  11113. // *never* happen while a contenteditable is focused, but as of v28, it
  11114. // sometimes does, even when the keypress event target is the contenteditable.
  11115. // This breaks the input. Special case these characters to ensure that when
  11116. // they are typed, we prevent default on the event to make sure not to
  11117. // trigger quickfind.
  11118. var FF_QUICKFIND_CHAR = "'";
  11119. var FF_QUICKFIND_LINK_CHAR = '/';
  11120. var isFirefox = UserAgent_1.isBrowser('Firefox');
  11121. function mustPreventDefaultForCharacter(character) {
  11122. return isFirefox && (character == FF_QUICKFIND_CHAR || character == FF_QUICKFIND_LINK_CHAR);
  11123. }
  11124. /**
  11125. * Replace the current selection with the specified text string, with the
  11126. * inline style and entity key applied to the newly inserted text.
  11127. */
  11128. function replaceText(editorState, text, inlineStyle, entityKey) {
  11129. var contentState = DraftModifier_1.replaceText(editorState.getCurrentContent(), editorState.getSelection(), text, inlineStyle, entityKey);
  11130. return EditorState_1.push(editorState, contentState, 'insert-characters');
  11131. }
  11132. /**
  11133. * When `onBeforeInput` executes, the browser is attempting to insert a
  11134. * character into the editor. Apply this character data to the document,
  11135. * allowing native insertion if possible.
  11136. *
  11137. * Native insertion is encouraged in order to limit re-rendering and to
  11138. * preserve spellcheck highlighting, which disappears or flashes if re-render
  11139. * occurs on the relevant text nodes.
  11140. */
  11141. function editOnBeforeInput(editor, e) {
  11142. if (editor._pendingStateFromBeforeInput !== undefined) {
  11143. editor.update(editor._pendingStateFromBeforeInput);
  11144. editor._pendingStateFromBeforeInput = undefined;
  11145. }
  11146. var editorState = editor._latestEditorState;
  11147. var chars = e.data;
  11148. // In some cases (ex: IE ideographic space insertion) no character data
  11149. // is provided. There's nothing to do when this happens.
  11150. if (!chars) {
  11151. return;
  11152. }
  11153. // Allow the top-level component to handle the insertion manually. This is
  11154. // useful when triggering interesting behaviors for a character insertion,
  11155. // Simple examples: replacing a raw text ':)' with a smile emoji or image
  11156. // decorator, or setting a block to be a list item after typing '- ' at the
  11157. // start of the block.
  11158. if (editor.props.handleBeforeInput && isEventHandled_1(editor.props.handleBeforeInput(chars, editorState))) {
  11159. e.preventDefault();
  11160. return;
  11161. }
  11162. // If selection is collapsed, conditionally allow native behavior. This
  11163. // reduces re-renders and preserves spellcheck highlighting. If the selection
  11164. // is not collapsed, we will re-render.
  11165. var selection = editorState.getSelection();
  11166. var selectionStart = selection.getStartOffset();
  11167. var selectionEnd = selection.getEndOffset();
  11168. var anchorKey = selection.getAnchorKey();
  11169. if (!selection.isCollapsed()) {
  11170. e.preventDefault();
  11171. // If the currently selected text matches what the user is trying to
  11172. // replace it with, let's just update the `SelectionState`. If not, update
  11173. // the `ContentState` with the new text.
  11174. var currentlySelectedChars = editorState.getCurrentContent().getPlainText().slice(selectionStart, selectionEnd);
  11175. if (chars === currentlySelectedChars) {
  11176. editor.update(EditorState_1.forceSelection(editorState, selection.merge({
  11177. focusOffset: selectionEnd
  11178. })));
  11179. } else {
  11180. editor.update(replaceText(editorState, chars, editorState.getCurrentInlineStyle(), getEntityKeyForSelection_1(editorState.getCurrentContent(), editorState.getSelection())));
  11181. }
  11182. return;
  11183. }
  11184. var newEditorState = replaceText(editorState, chars, editorState.getCurrentInlineStyle(), getEntityKeyForSelection_1(editorState.getCurrentContent(), editorState.getSelection()));
  11185. // Bunch of different cases follow where we need to prevent native insertion.
  11186. var mustPreventNative = false;
  11187. if (!mustPreventNative) {
  11188. // Browsers tend to insert text in weird places in the DOM when typing at
  11189. // the start of a leaf, so we'll handle it ourselves.
  11190. mustPreventNative = isSelectionAtLeafStart_1(editor._latestCommittedEditorState);
  11191. }
  11192. if (!mustPreventNative) {
  11193. // Chrome will also split up a node into two pieces if it contains a Tab
  11194. // char, for no explicable reason. Seemingly caused by this commit:
  11195. // https://chromium.googlesource.com/chromium/src/+/013ac5eaf3%5E%21/
  11196. var nativeSelection = commonjsGlobal.getSelection();
  11197. // Selection is necessarily collapsed at this point due to earlier check.
  11198. if (nativeSelection.anchorNode && nativeSelection.anchorNode.nodeType === Node.TEXT_NODE) {
  11199. // See isTabHTMLSpanElement in chromium EditingUtilities.cpp.
  11200. var parentNode = nativeSelection.anchorNode.parentNode;
  11201. mustPreventNative = parentNode.nodeName === 'SPAN' && parentNode.firstChild.nodeType === Node.TEXT_NODE && parentNode.firstChild.nodeValue.indexOf('\t') !== -1;
  11202. }
  11203. }
  11204. if (!mustPreventNative) {
  11205. // Check the old and new "fingerprints" of the current block to determine
  11206. // whether this insertion requires any addition or removal of text nodes,
  11207. // in which case we would prevent the native character insertion.
  11208. var originalFingerprint = BlockTree_1.getFingerprint(editorState.getBlockTree(anchorKey));
  11209. var newFingerprint = BlockTree_1.getFingerprint(newEditorState.getBlockTree(anchorKey));
  11210. mustPreventNative = originalFingerprint !== newFingerprint;
  11211. }
  11212. if (!mustPreventNative) {
  11213. mustPreventNative = mustPreventDefaultForCharacter(chars);
  11214. }
  11215. if (!mustPreventNative) {
  11216. mustPreventNative = nullthrows_1(newEditorState.getDirectionMap()).get(anchorKey) !== nullthrows_1(editorState.getDirectionMap()).get(anchorKey);
  11217. }
  11218. if (mustPreventNative) {
  11219. e.preventDefault();
  11220. editor.update(newEditorState);
  11221. return;
  11222. }
  11223. // We made it all the way! Let the browser do its thing and insert the char.
  11224. newEditorState = EditorState_1.set(newEditorState, {
  11225. nativelyRenderedContent: newEditorState.getCurrentContent()
  11226. });
  11227. // The native event is allowed to occur. To allow user onChange handlers to
  11228. // change the inserted text, we wait until the text is actually inserted
  11229. // before we actually update our state. That way when we rerender, the text
  11230. // we see in the DOM will already have been inserted properly.
  11231. editor._pendingStateFromBeforeInput = newEditorState;
  11232. setImmediate(function () {
  11233. if (editor._pendingStateFromBeforeInput !== undefined) {
  11234. editor.update(editor._pendingStateFromBeforeInput);
  11235. editor._pendingStateFromBeforeInput = undefined;
  11236. }
  11237. });
  11238. }
  11239. var editOnBeforeInput_1 = editOnBeforeInput;
  11240. function editOnBlur(editor, e) {
  11241. // In a contentEditable element, when you select a range and then click
  11242. // another active element, this does trigger a `blur` event but will not
  11243. // remove the DOM selection from the contenteditable.
  11244. // This is consistent across all browsers, but we prefer that the editor
  11245. // behave like a textarea, where a `blur` event clears the DOM selection.
  11246. // We therefore force the issue to be certain, checking whether the active
  11247. // element is `body` to force it when blurring occurs within the window (as
  11248. // opposed to clicking to another tab or window).
  11249. if (getActiveElement_1() === document.body) {
  11250. var _selection = commonjsGlobal.getSelection();
  11251. var editorNode = editor.editor;
  11252. if (_selection.rangeCount === 1 && containsNode_1(editorNode, _selection.anchorNode) && containsNode_1(editorNode, _selection.focusNode)) {
  11253. _selection.removeAllRanges();
  11254. }
  11255. }
  11256. var editorState = editor._latestEditorState;
  11257. var currentSelection = editorState.getSelection();
  11258. if (!currentSelection.getHasFocus()) {
  11259. return;
  11260. }
  11261. var selection = currentSelection.set('hasFocus', false);
  11262. editor.props.onBlur && editor.props.onBlur(e);
  11263. editor.update(EditorState_1.acceptSelection(editorState, selection));
  11264. }
  11265. var editOnBlur_1 = editOnBlur;
  11266. /**
  11267. * The user has begun using an IME input system. Switching to `composite` mode
  11268. * allows handling composition input and disables other edit behavior.
  11269. */
  11270. function editOnCompositionStart(editor, e) {
  11271. editor.setMode('composite');
  11272. editor.update(EditorState_1.set(editor._latestEditorState, { inCompositionMode: true }));
  11273. // Allow composition handler to interpret the compositionstart event
  11274. editor._onCompositionStart(e);
  11275. }
  11276. var editOnCompositionStart_1 = editOnCompositionStart;
  11277. function getFragmentFromSelection(editorState) {
  11278. var selectionState = editorState.getSelection();
  11279. if (selectionState.isCollapsed()) {
  11280. return null;
  11281. }
  11282. return getContentStateFragment_1(editorState.getCurrentContent(), selectionState);
  11283. }
  11284. var getFragmentFromSelection_1 = getFragmentFromSelection;
  11285. /**
  11286. * If we have a selection, create a ContentState fragment and store
  11287. * it in our internal clipboard. Subsequent paste events will use this
  11288. * fragment if no external clipboard data is supplied.
  11289. */
  11290. function editOnCopy(editor, e) {
  11291. var editorState = editor._latestEditorState;
  11292. var selection = editorState.getSelection();
  11293. // No selection, so there's nothing to copy.
  11294. if (selection.isCollapsed()) {
  11295. e.preventDefault();
  11296. return;
  11297. }
  11298. editor.setClipboard(getFragmentFromSelection_1(editor._latestEditorState));
  11299. }
  11300. var editOnCopy_1 = editOnCopy;
  11301. /**
  11302. * On `cut` events, native behavior is allowed to occur so that the system
  11303. * clipboard is set properly. This means that we need to take steps to recover
  11304. * the editor DOM state after the `cut` has occurred in order to maintain
  11305. * control of the component.
  11306. *
  11307. * In addition, we can keep a copy of the removed fragment, including all
  11308. * styles and entities, for use as an internal paste.
  11309. */
  11310. function editOnCut(editor, e) {
  11311. var editorState = editor._latestEditorState;
  11312. var selection = editorState.getSelection();
  11313. var element = e.target;
  11314. var scrollPosition = void 0;
  11315. // No selection, so there's nothing to cut.
  11316. if (selection.isCollapsed()) {
  11317. e.preventDefault();
  11318. return;
  11319. }
  11320. // Track the current scroll position so that it can be forced back in place
  11321. // after the editor regains control of the DOM.
  11322. if (element instanceof Node) {
  11323. scrollPosition = getScrollPosition_1(Style_1.getScrollParent(element));
  11324. }
  11325. var fragment = getFragmentFromSelection_1(editorState);
  11326. editor.setClipboard(fragment);
  11327. // Set `cut` mode to disable all event handling temporarily.
  11328. editor.setMode('cut');
  11329. // Let native `cut` behavior occur, then recover control.
  11330. setTimeout(function () {
  11331. editor.restoreEditorDOM(scrollPosition);
  11332. editor.exitCurrentMode();
  11333. editor.update(removeFragment(editorState));
  11334. }, 0);
  11335. }
  11336. function removeFragment(editorState) {
  11337. var newContent = DraftModifier_1.removeRange(editorState.getCurrentContent(), editorState.getSelection(), 'forward');
  11338. return EditorState_1.push(editorState, newContent, 'remove-range');
  11339. }
  11340. var editOnCut_1 = editOnCut;
  11341. /**
  11342. * Copyright (c) 2013-present, Facebook, Inc.
  11343. * All rights reserved.
  11344. *
  11345. * This source code is licensed under the BSD-style license found in the
  11346. * LICENSE file in the root directory of this source tree. An additional grant
  11347. * of patent rights can be found in the PATENTS file in the same directory.
  11348. *
  11349. * @providesModule editOnDragOver
  11350. * @format
  11351. *
  11352. */
  11353. /**
  11354. * Drag behavior has begun from outside the editor element.
  11355. */
  11356. function editOnDragOver(editor, e) {
  11357. editor._internalDrag = false;
  11358. editor.setMode('drag');
  11359. e.preventDefault();
  11360. }
  11361. var editOnDragOver_1 = editOnDragOver;
  11362. /**
  11363. * Copyright (c) 2013-present, Facebook, Inc.
  11364. * All rights reserved.
  11365. *
  11366. * This source code is licensed under the BSD-style license found in the
  11367. * LICENSE file in the root directory of this source tree. An additional grant
  11368. * of patent rights can be found in the PATENTS file in the same directory.
  11369. *
  11370. * @providesModule editOnDragStart
  11371. * @format
  11372. *
  11373. */
  11374. /**
  11375. * A `dragstart` event has begun within the text editor component.
  11376. */
  11377. function editOnDragStart(editor) {
  11378. editor._internalDrag = true;
  11379. editor.setMode('drag');
  11380. }
  11381. var editOnDragStart_1 = editOnDragStart;
  11382. function editOnFocus(editor, e) {
  11383. var editorState = editor._latestEditorState;
  11384. var currentSelection = editorState.getSelection();
  11385. if (currentSelection.getHasFocus()) {
  11386. return;
  11387. }
  11388. var selection = currentSelection.set('hasFocus', true);
  11389. editor.props.onFocus && editor.props.onFocus(e);
  11390. // When the tab containing this text editor is hidden and the user does a
  11391. // find-in-page in a _different_ tab, Chrome on Mac likes to forget what the
  11392. // selection was right after sending this focus event and (if you let it)
  11393. // moves the cursor back to the beginning of the editor, so we force the
  11394. // selection here instead of simply accepting it in order to preserve the
  11395. // old cursor position. See https://crbug.com/540004.
  11396. // But it looks like this is fixed in Chrome 60.0.3081.0.
  11397. // Other browsers also don't have this bug, so we prefer to acceptSelection
  11398. // when possible, to ensure that unfocusing and refocusing a Draft editor
  11399. // doesn't preserve the selection, matching how textareas work.
  11400. if (UserAgent_1.isBrowser('Chrome < 60.0.3081.0')) {
  11401. editor.update(EditorState_1.forceSelection(editorState, selection));
  11402. } else {
  11403. editor.update(EditorState_1.acceptSelection(editorState, selection));
  11404. }
  11405. }
  11406. var editOnFocus_1 = editOnFocus;
  11407. var isGecko = UserAgent_1.isEngine('Gecko');
  11408. var DOUBLE_NEWLINE = '\n\n';
  11409. /**
  11410. * This function is intended to handle spellcheck and autocorrect changes,
  11411. * which occur in the DOM natively without any opportunity to observe or
  11412. * interpret the changes before they occur.
  11413. *
  11414. * The `input` event fires in contentEditable elements reliably for non-IE
  11415. * browsers, immediately after changes occur to the editor DOM. Since our other
  11416. * handlers override or otherwise handle cover other varieties of text input,
  11417. * the DOM state should match the model in all controlled input cases. Thus,
  11418. * when an `input` change leads to a DOM/model mismatch, the change should be
  11419. * due to a spellcheck change, and we can incorporate it into our model.
  11420. */
  11421. function editOnInput(editor) {
  11422. if (editor._pendingStateFromBeforeInput !== undefined) {
  11423. editor.update(editor._pendingStateFromBeforeInput);
  11424. editor._pendingStateFromBeforeInput = undefined;
  11425. }
  11426. var domSelection = commonjsGlobal.getSelection();
  11427. var anchorNode = domSelection.anchorNode,
  11428. isCollapsed = domSelection.isCollapsed;
  11429. var isNotTextNode = anchorNode.nodeType !== Node.TEXT_NODE;
  11430. var isNotTextOrElementNode = anchorNode.nodeType !== Node.TEXT_NODE && anchorNode.nodeType !== Node.ELEMENT_NODE;
  11431. {
  11432. if (isNotTextOrElementNode) {
  11433. // TODO: (t16149272) figure out context for this change
  11434. return;
  11435. }
  11436. }
  11437. if (anchorNode.nodeType === Node.TEXT_NODE && (anchorNode.previousSibling !== null || anchorNode.nextSibling !== null)) {
  11438. // When typing at the beginning of a visual line, Chrome splits the text
  11439. // nodes into two. Why? No one knows. This commit is suspicious:
  11440. // https://chromium.googlesource.com/chromium/src/+/a3b600981286b135632371477f902214c55a1724
  11441. // To work around, we'll merge the sibling text nodes back into this one.
  11442. var span = anchorNode.parentNode;
  11443. anchorNode.nodeValue = span.textContent;
  11444. for (var child = span.firstChild; child !== null; child = child.nextSibling) {
  11445. if (child !== anchorNode) {
  11446. span.removeChild(child);
  11447. }
  11448. }
  11449. }
  11450. var domText = anchorNode.textContent;
  11451. var editorState = editor._latestEditorState;
  11452. var offsetKey = nullthrows_1(findAncestorOffsetKey_1(anchorNode));
  11453. var _DraftOffsetKey$decod = DraftOffsetKey_1.decode(offsetKey),
  11454. blockKey = _DraftOffsetKey$decod.blockKey,
  11455. decoratorKey = _DraftOffsetKey$decod.decoratorKey,
  11456. leafKey = _DraftOffsetKey$decod.leafKey;
  11457. var _editorState$getBlock = editorState.getBlockTree(blockKey).getIn([decoratorKey, 'leaves', leafKey]),
  11458. start = _editorState$getBlock.start,
  11459. end = _editorState$getBlock.end;
  11460. var content = editorState.getCurrentContent();
  11461. var block = content.getBlockForKey(blockKey);
  11462. var modelText = block.getText().slice(start, end);
  11463. // Special-case soft newlines here. If the DOM text ends in a soft newline,
  11464. // we will have manually inserted an extra soft newline in DraftEditorLeaf.
  11465. // We want to remove this extra newline for the purpose of our comparison
  11466. // of DOM and model text.
  11467. if (domText.endsWith(DOUBLE_NEWLINE)) {
  11468. domText = domText.slice(0, -1);
  11469. }
  11470. // No change -- the DOM is up to date. Nothing to do here.
  11471. if (domText === modelText) {
  11472. // This can be buggy for some Android keyboards because they don't fire
  11473. // standard onkeydown/pressed events and only fired editOnInput
  11474. // so domText is already changed by the browser and ends up being equal
  11475. // to modelText unexpectedly
  11476. return;
  11477. }
  11478. var selection = editorState.getSelection();
  11479. // We'll replace the entire leaf with the text content of the target.
  11480. var targetRange = selection.merge({
  11481. anchorOffset: start,
  11482. focusOffset: end,
  11483. isBackward: false
  11484. });
  11485. var entityKey = block.getEntityAt(start);
  11486. var entity = entityKey && content.getEntity(entityKey);
  11487. var entityType = entity && entity.getMutability();
  11488. var preserveEntity = entityType === 'MUTABLE';
  11489. // Immutable or segmented entities cannot properly be handled by the
  11490. // default browser undo, so we have to use a different change type to
  11491. // force using our internal undo method instead of falling through to the
  11492. // native browser undo.
  11493. var changeType = preserveEntity ? 'spellcheck-change' : 'apply-entity';
  11494. var newContent = DraftModifier_1.replaceText(content, targetRange, domText, block.getInlineStyleAt(start), preserveEntity ? block.getEntityAt(start) : null);
  11495. var anchorOffset, focusOffset, startOffset, endOffset;
  11496. if (isGecko) {
  11497. // Firefox selection does not change while the context menu is open, so
  11498. // we preserve the anchor and focus values of the DOM selection.
  11499. anchorOffset = domSelection.anchorOffset;
  11500. focusOffset = domSelection.focusOffset;
  11501. startOffset = start + Math.min(anchorOffset, focusOffset);
  11502. endOffset = startOffset + Math.abs(anchorOffset - focusOffset);
  11503. anchorOffset = startOffset;
  11504. focusOffset = endOffset;
  11505. } else {
  11506. // Browsers other than Firefox may adjust DOM selection while the context
  11507. // menu is open, and Safari autocorrect is prone to providing an inaccurate
  11508. // DOM selection. Don't trust it. Instead, use our existing SelectionState
  11509. // and adjust it based on the number of characters changed during the
  11510. // mutation.
  11511. var charDelta = domText.length - modelText.length;
  11512. startOffset = selection.getStartOffset();
  11513. endOffset = selection.getEndOffset();
  11514. anchorOffset = isCollapsed ? endOffset + charDelta : startOffset;
  11515. focusOffset = endOffset + charDelta;
  11516. }
  11517. // Segmented entities are completely or partially removed when their
  11518. // text content changes. For this case we do not want any text to be selected
  11519. // after the change, so we are not merging the selection.
  11520. var contentWithAdjustedDOMSelection = newContent.merge({
  11521. selectionBefore: content.getSelectionAfter(),
  11522. selectionAfter: selection.merge({ anchorOffset: anchorOffset, focusOffset: focusOffset })
  11523. });
  11524. editor.update(EditorState_1.push(editorState, contentWithAdjustedDOMSelection, changeType));
  11525. }
  11526. var editOnInput_1 = editOnInput;
  11527. var isOSX = UserAgent_1.isPlatform('Mac OS X');
  11528. var KeyBindingUtil = {
  11529. /**
  11530. * Check whether the ctrlKey modifier is *not* being used in conjunction with
  11531. * the altKey modifier. If they are combined, the result is an `altGraph`
  11532. * key modifier, which should not be handled by this set of key bindings.
  11533. */
  11534. isCtrlKeyCommand: function isCtrlKeyCommand(e) {
  11535. return !!e.ctrlKey && !e.altKey;
  11536. },
  11537. isOptionKeyCommand: function isOptionKeyCommand(e) {
  11538. return isOSX && e.altKey;
  11539. },
  11540. hasCommandModifier: function hasCommandModifier(e) {
  11541. return isOSX ? !!e.metaKey && !e.altKey : KeyBindingUtil.isCtrlKeyCommand(e);
  11542. }
  11543. };
  11544. var KeyBindingUtil_1 = KeyBindingUtil;
  11545. var clipboard = null;
  11546. /**
  11547. * Some systems offer a "secondary" clipboard to allow quick internal cut
  11548. * and paste behavior. For instance, Ctrl+K (cut) and Ctrl+Y (paste).
  11549. */
  11550. var SecondaryClipboard = {
  11551. cut: function cut(editorState) {
  11552. var content = editorState.getCurrentContent();
  11553. var selection = editorState.getSelection();
  11554. var targetRange = null;
  11555. if (selection.isCollapsed()) {
  11556. var anchorKey = selection.getAnchorKey();
  11557. var blockEnd = content.getBlockForKey(anchorKey).getLength();
  11558. if (blockEnd === selection.getAnchorOffset()) {
  11559. return editorState;
  11560. }
  11561. targetRange = selection.set('focusOffset', blockEnd);
  11562. } else {
  11563. targetRange = selection;
  11564. }
  11565. targetRange = nullthrows_1(targetRange);
  11566. clipboard = getContentStateFragment_1(content, targetRange);
  11567. var afterRemoval = DraftModifier_1.removeRange(content, targetRange, 'forward');
  11568. if (afterRemoval === content) {
  11569. return editorState;
  11570. }
  11571. return EditorState_1.push(editorState, afterRemoval, 'remove-range');
  11572. },
  11573. paste: function paste(editorState) {
  11574. if (!clipboard) {
  11575. return editorState;
  11576. }
  11577. var newContent = DraftModifier_1.replaceWithFragment(editorState.getCurrentContent(), editorState.getSelection(), clipboard);
  11578. return EditorState_1.push(editorState, newContent, 'insert-fragment');
  11579. }
  11580. };
  11581. var SecondaryClipboard_1 = SecondaryClipboard;
  11582. // These two ranges are consecutive so anything in [HIGH_START, LOW_END] is a
  11583. // surrogate code unit.
  11584. var SURROGATE_HIGH_START = 0xD800;
  11585. var SURROGATE_HIGH_END = 0xDBFF;
  11586. var SURROGATE_LOW_START = 0xDC00;
  11587. var SURROGATE_LOW_END = 0xDFFF;
  11588. var SURROGATE_UNITS_REGEX = /[\uD800-\uDFFF]/;
  11589. /**
  11590. * @param {number} codeUnit A Unicode code-unit, in range [0, 0x10FFFF]
  11591. * @return {boolean} Whether code-unit is in a surrogate (hi/low) range
  11592. */
  11593. function isCodeUnitInSurrogateRange(codeUnit) {
  11594. return SURROGATE_HIGH_START <= codeUnit && codeUnit <= SURROGATE_LOW_END;
  11595. }
  11596. /**
  11597. * Returns whether the two characters starting at `index` form a surrogate pair.
  11598. * For example, given the string s = "\uD83D\uDE0A", (s, 0) returns true and
  11599. * (s, 1) returns false.
  11600. *
  11601. * @param {string} str
  11602. * @param {number} index
  11603. * @return {boolean}
  11604. */
  11605. function isSurrogatePair(str, index) {
  11606. !(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;
  11607. if (index + 1 === str.length) {
  11608. return false;
  11609. }
  11610. var first = str.charCodeAt(index);
  11611. var second = str.charCodeAt(index + 1);
  11612. return SURROGATE_HIGH_START <= first && first <= SURROGATE_HIGH_END && SURROGATE_LOW_START <= second && second <= SURROGATE_LOW_END;
  11613. }
  11614. /**
  11615. * @param {string} str Non-empty string
  11616. * @return {boolean} True if the input includes any surrogate code units
  11617. */
  11618. function hasSurrogateUnit(str) {
  11619. return SURROGATE_UNITS_REGEX.test(str);
  11620. }
  11621. /**
  11622. * Return the length of the original Unicode character at given position in the
  11623. * String by looking into the UTF-16 code unit; that is equal to 1 for any
  11624. * non-surrogate characters in BMP ([U+0000..U+D7FF] and [U+E000, U+FFFF]); and
  11625. * returns 2 for the hi/low surrogates ([U+D800..U+DFFF]), which are in fact
  11626. * representing non-BMP characters ([U+10000..U+10FFFF]).
  11627. *
  11628. * Examples:
  11629. * - '\u0020' => 1
  11630. * - '\u3020' => 1
  11631. * - '\uD835' => 2
  11632. * - '\uD835\uDDEF' => 2
  11633. * - '\uDDEF' => 2
  11634. *
  11635. * @param {string} str Non-empty string
  11636. * @param {number} pos Position in the string to look for one code unit
  11637. * @return {number} Number 1 or 2
  11638. */
  11639. function getUTF16Length(str, pos) {
  11640. return 1 + isCodeUnitInSurrogateRange(str.charCodeAt(pos));
  11641. }
  11642. /**
  11643. * Fully Unicode-enabled replacement for String#length
  11644. *
  11645. * @param {string} str Valid Unicode string
  11646. * @return {number} The number of Unicode characters in the string
  11647. */
  11648. function strlen(str) {
  11649. // Call the native functions if there's no surrogate char
  11650. if (!hasSurrogateUnit(str)) {
  11651. return str.length;
  11652. }
  11653. var len = 0;
  11654. for (var pos = 0; pos < str.length; pos += getUTF16Length(str, pos)) {
  11655. len++;
  11656. }
  11657. return len;
  11658. }
  11659. /**
  11660. * Fully Unicode-enabled replacement for String#substr()
  11661. *
  11662. * @param {string} str Valid Unicode string
  11663. * @param {number} start Location in Unicode sequence to begin extracting
  11664. * @param {?number} length The number of Unicode characters to extract
  11665. * (default: to the end of the string)
  11666. * @return {string} Extracted sub-string
  11667. */
  11668. function substr(str, start, length) {
  11669. start = start || 0;
  11670. length = length === undefined ? Infinity : length || 0;
  11671. // Call the native functions if there's no surrogate char
  11672. if (!hasSurrogateUnit(str)) {
  11673. return str.substr(start, length);
  11674. }
  11675. // Obvious cases
  11676. var size = str.length;
  11677. if (size <= 0 || start > size || length <= 0) {
  11678. return '';
  11679. }
  11680. // Find the actual starting position
  11681. var posA = 0;
  11682. if (start > 0) {
  11683. for (; start > 0 && posA < size; start--) {
  11684. posA += getUTF16Length(str, posA);
  11685. }
  11686. if (posA >= size) {
  11687. return '';
  11688. }
  11689. } else if (start < 0) {
  11690. for (posA = size; start < 0 && 0 < posA; start++) {
  11691. posA -= getUTF16Length(str, posA - 1);
  11692. }
  11693. if (posA < 0) {
  11694. posA = 0;
  11695. }
  11696. }
  11697. // Find the actual ending position
  11698. var posB = size;
  11699. if (length < size) {
  11700. for (posB = posA; length > 0 && posB < size; length--) {
  11701. posB += getUTF16Length(str, posB);
  11702. }
  11703. }
  11704. return str.substring(posA, posB);
  11705. }
  11706. /**
  11707. * Fully Unicode-enabled replacement for String#substring()
  11708. *
  11709. * @param {string} str Valid Unicode string
  11710. * @param {number} start Location in Unicode sequence to begin extracting
  11711. * @param {?number} end Location in Unicode sequence to end extracting
  11712. * (default: end of the string)
  11713. * @return {string} Extracted sub-string
  11714. */
  11715. function substring(str, start, end) {
  11716. start = start || 0;
  11717. end = end === undefined ? Infinity : end || 0;
  11718. if (start < 0) {
  11719. start = 0;
  11720. }
  11721. if (end < 0) {
  11722. end = 0;
  11723. }
  11724. var length = Math.abs(end - start);
  11725. start = start < end ? start : end;
  11726. return substr(str, start, length);
  11727. }
  11728. /**
  11729. * Get a list of Unicode code-points from a String
  11730. *
  11731. * @param {string} str Valid Unicode string
  11732. * @return {array<number>} A list of code-points in [0..0x10FFFF]
  11733. */
  11734. function getCodePoints(str) {
  11735. var codePoints = [];
  11736. for (var pos = 0; pos < str.length; pos += getUTF16Length(str, pos)) {
  11737. codePoints.push(str.codePointAt(pos));
  11738. }
  11739. return codePoints;
  11740. }
  11741. var UnicodeUtils = {
  11742. getCodePoints: getCodePoints,
  11743. getUTF16Length: getUTF16Length,
  11744. hasSurrogateUnit: hasSurrogateUnit,
  11745. isCodeUnitInSurrogateRange: isCodeUnitInSurrogateRange,
  11746. isSurrogatePair: isSurrogatePair,
  11747. strlen: strlen,
  11748. substring: substring,
  11749. substr: substr
  11750. };
  11751. var UnicodeUtils_1 = UnicodeUtils;
  11752. var isChrome = UserAgent_1.isBrowser('Chrome');
  11753. // In Chrome, the client rects will include the entire bounds of all nodes that
  11754. // begin (have a start tag) within the selection, even if the selection does
  11755. // not overlap the entire node. To resolve this, we split the range at each
  11756. // start tag and join the client rects together.
  11757. // https://code.google.com/p/chromium/issues/detail?id=324437
  11758. /* eslint-disable consistent-return */
  11759. function getRangeClientRectsChrome(range) {
  11760. var tempRange = range.cloneRange();
  11761. var clientRects = [];
  11762. for (var ancestor = range.endContainer; ancestor != null; ancestor = ancestor.parentNode) {
  11763. // If we've climbed up to the common ancestor, we can now use the
  11764. // original start point and stop climbing the tree.
  11765. var atCommonAncestor = ancestor === range.commonAncestorContainer;
  11766. if (atCommonAncestor) {
  11767. tempRange.setStart(range.startContainer, range.startOffset);
  11768. } else {
  11769. tempRange.setStart(tempRange.endContainer, 0);
  11770. }
  11771. var rects = Array.from(tempRange.getClientRects());
  11772. clientRects.push(rects);
  11773. if (atCommonAncestor) {
  11774. var _ref;
  11775. clientRects.reverse();
  11776. return (_ref = []).concat.apply(_ref, clientRects);
  11777. }
  11778. tempRange.setEndBefore(ancestor);
  11779. }
  11780. process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Found an unexpected detached subtree when getting range client rects.') : invariant_1(false) ;
  11781. }
  11782. /* eslint-enable consistent-return */
  11783. /**
  11784. * Like range.getClientRects() but normalizes for browser bugs.
  11785. */
  11786. var getRangeClientRects = isChrome ? getRangeClientRectsChrome : function (range) {
  11787. return Array.from(range.getClientRects());
  11788. };
  11789. var getRangeClientRects_1 = getRangeClientRects;
  11790. /**
  11791. * Copyright (c) 2013-present, Facebook, Inc.
  11792. * All rights reserved.
  11793. *
  11794. * This source code is licensed under the BSD-style license found in the
  11795. * LICENSE file in the root directory of this source tree. An additional grant
  11796. * of patent rights can be found in the PATENTS file in the same directory.
  11797. *
  11798. * @providesModule expandRangeToStartOfLine
  11799. * @format
  11800. *
  11801. */
  11802. /**
  11803. * Return the computed line height, in pixels, for the provided element.
  11804. */
  11805. function getLineHeightPx(element) {
  11806. var computed = getComputedStyle(element);
  11807. var div = document.createElement('div');
  11808. div.style.fontFamily = computed.fontFamily;
  11809. div.style.fontSize = computed.fontSize;
  11810. div.style.fontStyle = computed.fontStyle;
  11811. div.style.fontWeight = computed.fontWeight;
  11812. div.style.lineHeight = computed.lineHeight;
  11813. div.style.position = 'absolute';
  11814. div.textContent = 'M';
  11815. var documentBody = document.body;
  11816. !documentBody ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing document.body') : invariant_1(false) : void 0;
  11817. // forced layout here
  11818. documentBody.appendChild(div);
  11819. var rect = div.getBoundingClientRect();
  11820. documentBody.removeChild(div);
  11821. return rect.height;
  11822. }
  11823. /**
  11824. * Return whether every ClientRect in the provided list lies on the same line.
  11825. *
  11826. * We assume that the rects on the same line all contain the baseline, so the
  11827. * lowest top line needs to be above the highest bottom line (i.e., if you were
  11828. * to project the rects onto the y-axis, their intersection would be nonempty).
  11829. *
  11830. * In addition, we require that no two boxes are lineHeight (or more) apart at
  11831. * either top or bottom, which helps protect against false positives for fonts
  11832. * with extremely large glyph heights (e.g., with a font size of 17px, Zapfino
  11833. * produces rects of height 58px!).
  11834. */
  11835. function areRectsOnOneLine(rects, lineHeight) {
  11836. var minTop = Infinity;
  11837. var minBottom = Infinity;
  11838. var maxTop = -Infinity;
  11839. var maxBottom = -Infinity;
  11840. for (var ii = 0; ii < rects.length; ii++) {
  11841. var rect = rects[ii];
  11842. if (rect.width === 0 || rect.width === 1) {
  11843. // When a range starts or ends a soft wrap, many browsers (Chrome, IE,
  11844. // Safari) include an empty rect on the previous or next line. When the
  11845. // text lies in a container whose position is not integral (e.g., from
  11846. // margin: auto), Safari makes these empty rects have width 1 (instead of
  11847. // 0). Having one-pixel-wide characters seems unlikely (and most browsers
  11848. // report widths in subpixel precision anyway) so it's relatively safe to
  11849. // skip over them.
  11850. continue;
  11851. }
  11852. minTop = Math.min(minTop, rect.top);
  11853. minBottom = Math.min(minBottom, rect.bottom);
  11854. maxTop = Math.max(maxTop, rect.top);
  11855. maxBottom = Math.max(maxBottom, rect.bottom);
  11856. }
  11857. return maxTop <= minBottom && maxTop - minTop < lineHeight && maxBottom - minBottom < lineHeight;
  11858. }
  11859. /**
  11860. * Return the length of a node, as used by Range offsets.
  11861. */
  11862. function getNodeLength$1(node) {
  11863. // http://www.w3.org/TR/dom/#concept-node-length
  11864. switch (node.nodeType) {
  11865. case Node.DOCUMENT_TYPE_NODE:
  11866. return 0;
  11867. case Node.TEXT_NODE:
  11868. case Node.PROCESSING_INSTRUCTION_NODE:
  11869. case Node.COMMENT_NODE:
  11870. return node.length;
  11871. default:
  11872. return node.childNodes.length;
  11873. }
  11874. }
  11875. /**
  11876. * Given a collapsed range, move the start position backwards as far as
  11877. * possible while the range still spans only a single line.
  11878. */
  11879. function expandRangeToStartOfLine(range) {
  11880. !range.collapsed ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'expandRangeToStartOfLine: Provided range is not collapsed.') : invariant_1(false) : void 0;
  11881. range = range.cloneRange();
  11882. var containingElement = range.startContainer;
  11883. if (containingElement.nodeType !== 1) {
  11884. containingElement = containingElement.parentNode;
  11885. }
  11886. var lineHeight = getLineHeightPx(containingElement);
  11887. // Imagine our text looks like:
  11888. // <div><span>once upon a time, there was a <em>boy
  11889. // who lived</em> </span><q><strong>under^ the
  11890. // stairs</strong> in a small closet.</q></div>
  11891. // where the caret represents the cursor. First, we crawl up the tree until
  11892. // the range spans multiple lines (setting the start point to before
  11893. // "<strong>", then before "<div>"), then at each level we do a search to
  11894. // find the latest point which is still on a previous line. We'll find that
  11895. // the break point is inside the span, then inside the <em>, then in its text
  11896. // node child, the actual break point before "who".
  11897. var bestContainer = range.endContainer;
  11898. var bestOffset = range.endOffset;
  11899. range.setStart(range.startContainer, 0);
  11900. while (areRectsOnOneLine(getRangeClientRects_1(range), lineHeight)) {
  11901. bestContainer = range.startContainer;
  11902. bestOffset = range.startOffset;
  11903. !bestContainer.parentNode ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Found unexpected detached subtree when traversing.') : invariant_1(false) : void 0;
  11904. range.setStartBefore(bestContainer);
  11905. if (bestContainer.nodeType === 1 && getComputedStyle(bestContainer).display !== 'inline') {
  11906. // The start of the line is never in a different block-level container.
  11907. break;
  11908. }
  11909. }
  11910. // In the above example, range now spans from "<div>" to "under",
  11911. // bestContainer is <div>, and bestOffset is 1 (index of <q> inside <div>)].
  11912. // Picking out which child to recurse into here is a special case since we
  11913. // don't want to check past <q> -- once we find that the final range starts
  11914. // in <span>, we can look at all of its children (and all of their children)
  11915. // to find the break point.
  11916. // At all times, (bestContainer, bestOffset) is the latest single-line start
  11917. // point that we know of.
  11918. var currentContainer = bestContainer;
  11919. var maxIndexToConsider = bestOffset - 1;
  11920. do {
  11921. var nodeValue = currentContainer.nodeValue;
  11922. for (var ii = maxIndexToConsider; ii >= 0; ii--) {
  11923. if (nodeValue != null && ii > 0 && UnicodeUtils_1.isSurrogatePair(nodeValue, ii - 1)) {
  11924. // We're in the middle of a surrogate pair -- skip over so we never
  11925. // return a range with an endpoint in the middle of a code point.
  11926. continue;
  11927. }
  11928. range.setStart(currentContainer, ii);
  11929. if (areRectsOnOneLine(getRangeClientRects_1(range), lineHeight)) {
  11930. bestContainer = currentContainer;
  11931. bestOffset = ii;
  11932. } else {
  11933. break;
  11934. }
  11935. }
  11936. if (ii === -1 || currentContainer.childNodes.length === 0) {
  11937. // If ii === -1, then (bestContainer, bestOffset), which is equal to
  11938. // (currentContainer, 0), was a single-line start point but a start
  11939. // point before currentContainer wasn't, so the line break seems to
  11940. // have occurred immediately after currentContainer's start tag
  11941. //
  11942. // If currentContainer.childNodes.length === 0, we're already at a
  11943. // terminal node (e.g., text node) and should return our current best.
  11944. break;
  11945. }
  11946. currentContainer = currentContainer.childNodes[ii];
  11947. maxIndexToConsider = getNodeLength$1(currentContainer);
  11948. } while (true);
  11949. range.setStart(bestContainer, bestOffset);
  11950. return range;
  11951. }
  11952. var expandRangeToStartOfLine_1 = expandRangeToStartOfLine;
  11953. /**
  11954. * Convert the current selection range to an anchor/focus pair of offset keys
  11955. * and values that can be interpreted by components.
  11956. */
  11957. function getDraftEditorSelectionWithNodes(editorState, root, anchorNode, anchorOffset, focusNode, focusOffset) {
  11958. var anchorIsTextNode = anchorNode.nodeType === Node.TEXT_NODE;
  11959. var focusIsTextNode = focusNode.nodeType === Node.TEXT_NODE;
  11960. // If the selection range lies only on text nodes, the task is simple.
  11961. // Find the nearest offset-aware elements and use the
  11962. // offset values supplied by the selection range.
  11963. if (anchorIsTextNode && focusIsTextNode) {
  11964. return {
  11965. selectionState: getUpdatedSelectionState_1(editorState, nullthrows_1(findAncestorOffsetKey_1(anchorNode)), anchorOffset, nullthrows_1(findAncestorOffsetKey_1(focusNode)), focusOffset),
  11966. needsRecovery: false
  11967. };
  11968. }
  11969. var anchorPoint = null;
  11970. var focusPoint = null;
  11971. var needsRecovery = true;
  11972. // An element is selected. Convert this selection range into leaf offset
  11973. // keys and offset values for consumption at the component level. This
  11974. // is common in Firefox, where select-all and triple click behavior leads
  11975. // to entire elements being selected.
  11976. //
  11977. // Note that we use the `needsRecovery` parameter in the callback here. This
  11978. // is because when certain elements are selected, the behavior for subsequent
  11979. // cursor movement (e.g. via arrow keys) is uncertain and may not match
  11980. // expectations at the component level. For example, if an entire <div> is
  11981. // selected and the user presses the right arrow, Firefox keeps the selection
  11982. // on the <div>. If we allow subsequent keypresses to insert characters
  11983. // natively, they will be inserted into a browser-created text node to the
  11984. // right of that <div>. This is obviously undesirable.
  11985. //
  11986. // With the `needsRecovery` flag, we inform the caller that it is responsible
  11987. // for manually setting the selection state on the rendered document to
  11988. // ensure proper selection state maintenance.
  11989. if (anchorIsTextNode) {
  11990. anchorPoint = {
  11991. key: nullthrows_1(findAncestorOffsetKey_1(anchorNode)),
  11992. offset: anchorOffset
  11993. };
  11994. focusPoint = getPointForNonTextNode(root, focusNode, focusOffset);
  11995. } else if (focusIsTextNode) {
  11996. focusPoint = {
  11997. key: nullthrows_1(findAncestorOffsetKey_1(focusNode)),
  11998. offset: focusOffset
  11999. };
  12000. anchorPoint = getPointForNonTextNode(root, anchorNode, anchorOffset);
  12001. } else {
  12002. anchorPoint = getPointForNonTextNode(root, anchorNode, anchorOffset);
  12003. focusPoint = getPointForNonTextNode(root, focusNode, focusOffset);
  12004. // If the selection is collapsed on an empty block, don't force recovery.
  12005. // This way, on arrow key selection changes, the browser can move the
  12006. // cursor from a non-zero offset on one block, through empty blocks,
  12007. // to a matching non-zero offset on other text blocks.
  12008. if (anchorNode === focusNode && anchorOffset === focusOffset) {
  12009. needsRecovery = !!anchorNode.firstChild && anchorNode.firstChild.nodeName !== 'BR';
  12010. }
  12011. }
  12012. return {
  12013. selectionState: getUpdatedSelectionState_1(editorState, anchorPoint.key, anchorPoint.offset, focusPoint.key, focusPoint.offset),
  12014. needsRecovery: needsRecovery
  12015. };
  12016. }
  12017. /**
  12018. * Identify the first leaf descendant for the given node.
  12019. */
  12020. function getFirstLeaf(node) {
  12021. while (node.firstChild && (
  12022. // data-blocks has no offset
  12023. node.firstChild instanceof Element && node.firstChild.getAttribute('data-blocks') === 'true' || getSelectionOffsetKeyForNode_1(node.firstChild))) {
  12024. node = node.firstChild;
  12025. }
  12026. return node;
  12027. }
  12028. /**
  12029. * Identify the last leaf descendant for the given node.
  12030. */
  12031. function getLastLeaf(node) {
  12032. while (node.lastChild && (
  12033. // data-blocks has no offset
  12034. node.lastChild instanceof Element && node.lastChild.getAttribute('data-blocks') === 'true' || getSelectionOffsetKeyForNode_1(node.lastChild))) {
  12035. node = node.lastChild;
  12036. }
  12037. return node;
  12038. }
  12039. function getPointForNonTextNode(editorRoot, startNode, childOffset) {
  12040. var node = startNode;
  12041. var offsetKey = findAncestorOffsetKey_1(node);
  12042. !(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;
  12043. // If the editorRoot is the selection, step downward into the content
  12044. // wrapper.
  12045. if (editorRoot === node) {
  12046. node = node.firstChild;
  12047. !(node instanceof Element && node.getAttribute('data-contents') === 'true') ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Invalid DraftEditorContents structure.') : invariant_1(false) : void 0;
  12048. if (childOffset > 0) {
  12049. childOffset = node.childNodes.length;
  12050. }
  12051. }
  12052. // If the child offset is zero and we have an offset key, we're done.
  12053. // If there's no offset key because the entire editor is selected,
  12054. // find the leftmost ("first") leaf in the tree and use that as the offset
  12055. // key.
  12056. if (childOffset === 0) {
  12057. var key = null;
  12058. if (offsetKey != null) {
  12059. key = offsetKey;
  12060. } else {
  12061. var firstLeaf = getFirstLeaf(node);
  12062. key = nullthrows_1(getSelectionOffsetKeyForNode_1(firstLeaf));
  12063. }
  12064. return { key: key, offset: 0 };
  12065. }
  12066. var nodeBeforeCursor = node.childNodes[childOffset - 1];
  12067. var leafKey = null;
  12068. var textLength = null;
  12069. if (!getSelectionOffsetKeyForNode_1(nodeBeforeCursor)) {
  12070. // Our target node may be a leaf or a text node, in which case we're
  12071. // already where we want to be and can just use the child's length as
  12072. // our offset.
  12073. leafKey = nullthrows_1(offsetKey);
  12074. textLength = getTextContentLength(nodeBeforeCursor);
  12075. } else {
  12076. // Otherwise, we'll look at the child to the left of the cursor and find
  12077. // the last leaf node in its subtree.
  12078. var lastLeaf = getLastLeaf(nodeBeforeCursor);
  12079. leafKey = nullthrows_1(getSelectionOffsetKeyForNode_1(lastLeaf));
  12080. textLength = getTextContentLength(lastLeaf);
  12081. }
  12082. return {
  12083. key: leafKey,
  12084. offset: textLength
  12085. };
  12086. }
  12087. /**
  12088. * Return the length of a node's textContent, regarding single newline
  12089. * characters as zero-length. This allows us to avoid problems with identifying
  12090. * the correct selection offset for empty blocks in IE, in which we
  12091. * render newlines instead of break tags.
  12092. */
  12093. function getTextContentLength(node) {
  12094. var textContent = node.textContent;
  12095. return textContent === '\n' ? 0 : textContent.length;
  12096. }
  12097. var getDraftEditorSelectionWithNodes_1 = getDraftEditorSelectionWithNodes;
  12098. /**
  12099. * Copyright (c) 2013-present, Facebook, Inc.
  12100. * All rights reserved.
  12101. *
  12102. * This source code is licensed under the BSD-style license found in the
  12103. * LICENSE file in the root directory of this source tree. An additional grant
  12104. * of patent rights can be found in the PATENTS file in the same directory.
  12105. *
  12106. * @providesModule moveSelectionBackward
  12107. * @format
  12108. *
  12109. */
  12110. /**
  12111. * Given a collapsed selection, move the focus `maxDistance` backward within
  12112. * the selected block. If the selection will go beyond the start of the block,
  12113. * move focus to the end of the previous block, but no further.
  12114. *
  12115. * This function is not Unicode-aware, so surrogate pairs will be treated
  12116. * as having length 2.
  12117. */
  12118. function moveSelectionBackward(editorState, maxDistance) {
  12119. var selection = editorState.getSelection();
  12120. var content = editorState.getCurrentContent();
  12121. var key = selection.getStartKey();
  12122. var offset = selection.getStartOffset();
  12123. var focusKey = key;
  12124. var focusOffset = 0;
  12125. if (maxDistance > offset) {
  12126. var keyBefore = content.getKeyBefore(key);
  12127. if (keyBefore == null) {
  12128. focusKey = key;
  12129. } else {
  12130. focusKey = keyBefore;
  12131. var blockBefore = content.getBlockForKey(keyBefore);
  12132. focusOffset = blockBefore.getText().length;
  12133. }
  12134. } else {
  12135. focusOffset = offset - maxDistance;
  12136. }
  12137. return selection.merge({
  12138. focusKey: focusKey,
  12139. focusOffset: focusOffset,
  12140. isBackward: true
  12141. });
  12142. }
  12143. var moveSelectionBackward_1 = moveSelectionBackward;
  12144. /**
  12145. * For a collapsed selection state, remove text based on the specified strategy.
  12146. * If the selection state is not collapsed, remove the entire selected range.
  12147. */
  12148. function removeTextWithStrategy(editorState, strategy, direction) {
  12149. var selection = editorState.getSelection();
  12150. var content = editorState.getCurrentContent();
  12151. var target = selection;
  12152. if (selection.isCollapsed()) {
  12153. if (direction === 'forward') {
  12154. if (editorState.isSelectionAtEndOfContent()) {
  12155. return content;
  12156. }
  12157. } else if (editorState.isSelectionAtStartOfContent()) {
  12158. return content;
  12159. }
  12160. target = strategy(editorState);
  12161. if (target === selection) {
  12162. return content;
  12163. }
  12164. }
  12165. return DraftModifier_1.removeRange(content, target, direction);
  12166. }
  12167. var removeTextWithStrategy_1 = removeTextWithStrategy;
  12168. function keyCommandBackspaceToStartOfLine(editorState) {
  12169. var afterRemoval = removeTextWithStrategy_1(editorState, function (strategyState) {
  12170. var selection = strategyState.getSelection();
  12171. if (selection.isCollapsed() && selection.getAnchorOffset() === 0) {
  12172. return moveSelectionBackward_1(strategyState, 1);
  12173. }
  12174. var domSelection = commonjsGlobal.getSelection();
  12175. var range = domSelection.getRangeAt(0);
  12176. range = expandRangeToStartOfLine_1(range);
  12177. return getDraftEditorSelectionWithNodes_1(strategyState, null, range.endContainer, range.endOffset, range.startContainer, range.startOffset).selectionState;
  12178. }, 'backward');
  12179. if (afterRemoval === editorState.getCurrentContent()) {
  12180. return editorState;
  12181. }
  12182. return EditorState_1.push(editorState, afterRemoval, 'remove-range');
  12183. }
  12184. var keyCommandBackspaceToStartOfLine_1 = keyCommandBackspaceToStartOfLine;
  12185. /**
  12186. * Copyright (c) 2013-present, Facebook, Inc.
  12187. *
  12188. * This source code is licensed under the MIT license found in the
  12189. * LICENSE file in the root directory of this source tree.
  12190. *
  12191. * @typechecks
  12192. * @stub
  12193. *
  12194. */
  12195. // \u00a1-\u00b1\u00b4-\u00b8\u00ba\u00bb\u00bf
  12196. // is latin supplement punctuation except fractions and superscript
  12197. // numbers
  12198. // \u2010-\u2027\u2030-\u205e
  12199. // is punctuation from the general punctuation block:
  12200. // weird quotes, commas, bullets, dashes, etc.
  12201. // \u30fb\u3001\u3002\u3008-\u3011\u3014-\u301f
  12202. // is CJK punctuation
  12203. // \uff1a-\uff1f\uff01-\uff0f\uff3b-\uff40\uff5b-\uff65
  12204. // is some full-width/half-width punctuation
  12205. // \u2E2E\u061f\u066a-\u066c\u061b\u060c\u060d\uFD3e\uFD3F
  12206. // is some Arabic punctuation marks
  12207. // \u1801\u0964\u104a\u104b
  12208. // is misc. other language punctuation marks
  12209. 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]';
  12210. var TokenizeUtil = {
  12211. getPunctuation: function getPunctuation() {
  12212. return PUNCTUATION;
  12213. }
  12214. };
  12215. var punctuation = TokenizeUtil.getPunctuation();
  12216. // The apostrophe and curly single quotes behave in a curious way: when
  12217. // surrounded on both sides by word characters, they behave as word chars; when
  12218. // either neighbor is punctuation or an end of the string, they behave as
  12219. // punctuation.
  12220. var CHAMELEON_CHARS = '[\'\u2018\u2019]';
  12221. // Remove the underscore, which should count as part of the removable word. The
  12222. // "chameleon chars" also count as punctuation in this regex.
  12223. var WHITESPACE_AND_PUNCTUATION = '\\s|(?![_])' + punctuation;
  12224. var DELETE_STRING = '^' + '(?:' + WHITESPACE_AND_PUNCTUATION + ')*' + '(?:' + CHAMELEON_CHARS + '|(?!' + WHITESPACE_AND_PUNCTUATION + ').)*' + '(?:(?!' + WHITESPACE_AND_PUNCTUATION + ').)';
  12225. var DELETE_REGEX = new RegExp(DELETE_STRING);
  12226. var BACKSPACE_STRING = '(?:(?!' + WHITESPACE_AND_PUNCTUATION + ').)' + '(?:' + CHAMELEON_CHARS + '|(?!' + WHITESPACE_AND_PUNCTUATION + ').)*' + '(?:' + WHITESPACE_AND_PUNCTUATION + ')*' + '$';
  12227. var BACKSPACE_REGEX = new RegExp(BACKSPACE_STRING);
  12228. function getRemovableWord(text, isBackward) {
  12229. var matches = isBackward ? BACKSPACE_REGEX.exec(text) : DELETE_REGEX.exec(text);
  12230. return matches ? matches[0] : text;
  12231. }
  12232. var DraftRemovableWord = {
  12233. getBackward: function getBackward(text) {
  12234. return getRemovableWord(text, true);
  12235. },
  12236. getForward: function getForward(text) {
  12237. return getRemovableWord(text, false);
  12238. }
  12239. };
  12240. var DraftRemovableWord_1 = DraftRemovableWord;
  12241. /**
  12242. * Delete the word that is left of the cursor, as well as any spaces or
  12243. * punctuation after the word.
  12244. */
  12245. function keyCommandBackspaceWord(editorState) {
  12246. var afterRemoval = removeTextWithStrategy_1(editorState, function (strategyState) {
  12247. var selection = strategyState.getSelection();
  12248. var offset = selection.getStartOffset();
  12249. // If there are no words before the cursor, remove the preceding newline.
  12250. if (offset === 0) {
  12251. return moveSelectionBackward_1(strategyState, 1);
  12252. }
  12253. var key = selection.getStartKey();
  12254. var content = strategyState.getCurrentContent();
  12255. var text = content.getBlockForKey(key).getText().slice(0, offset);
  12256. var toRemove = DraftRemovableWord_1.getBackward(text);
  12257. return moveSelectionBackward_1(strategyState, toRemove.length || 1);
  12258. }, 'backward');
  12259. if (afterRemoval === editorState.getCurrentContent()) {
  12260. return editorState;
  12261. }
  12262. return EditorState_1.push(editorState, afterRemoval, 'remove-range');
  12263. }
  12264. var keyCommandBackspaceWord_1 = keyCommandBackspaceWord;
  12265. /**
  12266. * Copyright (c) 2013-present, Facebook, Inc.
  12267. * All rights reserved.
  12268. *
  12269. * This source code is licensed under the BSD-style license found in the
  12270. * LICENSE file in the root directory of this source tree. An additional grant
  12271. * of patent rights can be found in the PATENTS file in the same directory.
  12272. *
  12273. * @providesModule moveSelectionForward
  12274. * @format
  12275. *
  12276. */
  12277. /**
  12278. * Given a collapsed selection, move the focus `maxDistance` forward within
  12279. * the selected block. If the selection will go beyond the end of the block,
  12280. * move focus to the start of the next block, but no further.
  12281. *
  12282. * This function is not Unicode-aware, so surrogate pairs will be treated
  12283. * as having length 2.
  12284. */
  12285. function moveSelectionForward(editorState, maxDistance) {
  12286. var selection = editorState.getSelection();
  12287. var key = selection.getStartKey();
  12288. var offset = selection.getStartOffset();
  12289. var content = editorState.getCurrentContent();
  12290. var focusKey = key;
  12291. var focusOffset;
  12292. var block = content.getBlockForKey(key);
  12293. if (maxDistance > block.getText().length - offset) {
  12294. focusKey = content.getKeyAfter(key);
  12295. focusOffset = 0;
  12296. } else {
  12297. focusOffset = offset + maxDistance;
  12298. }
  12299. return selection.merge({ focusKey: focusKey, focusOffset: focusOffset });
  12300. }
  12301. var moveSelectionForward_1 = moveSelectionForward;
  12302. /**
  12303. * Delete the word that is right of the cursor, as well as any spaces or
  12304. * punctuation before the word.
  12305. */
  12306. function keyCommandDeleteWord(editorState) {
  12307. var afterRemoval = removeTextWithStrategy_1(editorState, function (strategyState) {
  12308. var selection = strategyState.getSelection();
  12309. var offset = selection.getStartOffset();
  12310. var key = selection.getStartKey();
  12311. var content = strategyState.getCurrentContent();
  12312. var text = content.getBlockForKey(key).getText().slice(offset);
  12313. var toRemove = DraftRemovableWord_1.getForward(text);
  12314. // If there are no words in front of the cursor, remove the newline.
  12315. return moveSelectionForward_1(strategyState, toRemove.length || 1);
  12316. }, 'forward');
  12317. if (afterRemoval === editorState.getCurrentContent()) {
  12318. return editorState;
  12319. }
  12320. return EditorState_1.push(editorState, afterRemoval, 'remove-range');
  12321. }
  12322. var keyCommandDeleteWord_1 = keyCommandDeleteWord;
  12323. function keyCommandInsertNewline(editorState) {
  12324. var contentState = DraftModifier_1.splitBlock(editorState.getCurrentContent(), editorState.getSelection());
  12325. return EditorState_1.push(editorState, contentState, 'split-block');
  12326. }
  12327. var keyCommandInsertNewline_1 = keyCommandInsertNewline;
  12328. /**
  12329. * See comment for `moveSelectionToStartOfBlock`.
  12330. */
  12331. function keyCommandMoveSelectionToEndOfBlock(editorState) {
  12332. var selection = editorState.getSelection();
  12333. var endKey = selection.getEndKey();
  12334. var content = editorState.getCurrentContent();
  12335. var textLength = content.getBlockForKey(endKey).getLength();
  12336. return EditorState_1.set(editorState, {
  12337. selection: selection.merge({
  12338. anchorKey: endKey,
  12339. anchorOffset: textLength,
  12340. focusKey: endKey,
  12341. focusOffset: textLength,
  12342. isBackward: false
  12343. }),
  12344. forceSelection: true
  12345. });
  12346. }
  12347. var keyCommandMoveSelectionToEndOfBlock_1 = keyCommandMoveSelectionToEndOfBlock;
  12348. /**
  12349. * Collapse selection at the start of the first selected block. This is used
  12350. * for Firefox versions that attempt to navigate forward/backward instead of
  12351. * moving the cursor. Other browsers are able to move the cursor natively.
  12352. */
  12353. function keyCommandMoveSelectionToStartOfBlock(editorState) {
  12354. var selection = editorState.getSelection();
  12355. var startKey = selection.getStartKey();
  12356. return EditorState_1.set(editorState, {
  12357. selection: selection.merge({
  12358. anchorKey: startKey,
  12359. anchorOffset: 0,
  12360. focusKey: startKey,
  12361. focusOffset: 0,
  12362. isBackward: false
  12363. }),
  12364. forceSelection: true
  12365. });
  12366. }
  12367. var keyCommandMoveSelectionToStartOfBlock_1 = keyCommandMoveSelectionToStartOfBlock;
  12368. /**
  12369. * Remove the selected range. If the cursor is collapsed, remove the preceding
  12370. * character. This operation is Unicode-aware, so removing a single character
  12371. * will remove a surrogate pair properly as well.
  12372. */
  12373. function keyCommandPlainBackspace(editorState) {
  12374. var afterRemoval = removeTextWithStrategy_1(editorState, function (strategyState) {
  12375. var selection = strategyState.getSelection();
  12376. var content = strategyState.getCurrentContent();
  12377. var key = selection.getAnchorKey();
  12378. var offset = selection.getAnchorOffset();
  12379. var charBehind = content.getBlockForKey(key).getText()[offset - 1];
  12380. return moveSelectionBackward_1(strategyState, charBehind ? UnicodeUtils_1.getUTF16Length(charBehind, 0) : 1);
  12381. }, 'backward');
  12382. if (afterRemoval === editorState.getCurrentContent()) {
  12383. return editorState;
  12384. }
  12385. var selection = editorState.getSelection();
  12386. return EditorState_1.push(editorState, afterRemoval.set('selectionBefore', selection), selection.isCollapsed() ? 'backspace-character' : 'remove-range');
  12387. }
  12388. var keyCommandPlainBackspace_1 = keyCommandPlainBackspace;
  12389. /**
  12390. * Remove the selected range. If the cursor is collapsed, remove the following
  12391. * character. This operation is Unicode-aware, so removing a single character
  12392. * will remove a surrogate pair properly as well.
  12393. */
  12394. function keyCommandPlainDelete(editorState) {
  12395. var afterRemoval = removeTextWithStrategy_1(editorState, function (strategyState) {
  12396. var selection = strategyState.getSelection();
  12397. var content = strategyState.getCurrentContent();
  12398. var key = selection.getAnchorKey();
  12399. var offset = selection.getAnchorOffset();
  12400. var charAhead = content.getBlockForKey(key).getText()[offset];
  12401. return moveSelectionForward_1(strategyState, charAhead ? UnicodeUtils_1.getUTF16Length(charAhead, 0) : 1);
  12402. }, 'forward');
  12403. if (afterRemoval === editorState.getCurrentContent()) {
  12404. return editorState;
  12405. }
  12406. var selection = editorState.getSelection();
  12407. return EditorState_1.push(editorState, afterRemoval.set('selectionBefore', selection), selection.isCollapsed() ? 'delete-character' : 'remove-range');
  12408. }
  12409. var keyCommandPlainDelete_1 = keyCommandPlainDelete;
  12410. /**
  12411. * Transpose the characters on either side of a collapsed cursor, or
  12412. * if the cursor is at the end of the block, transpose the last two
  12413. * characters.
  12414. */
  12415. function keyCommandTransposeCharacters(editorState) {
  12416. var selection = editorState.getSelection();
  12417. if (!selection.isCollapsed()) {
  12418. return editorState;
  12419. }
  12420. var offset = selection.getAnchorOffset();
  12421. if (offset === 0) {
  12422. return editorState;
  12423. }
  12424. var blockKey = selection.getAnchorKey();
  12425. var content = editorState.getCurrentContent();
  12426. var block = content.getBlockForKey(blockKey);
  12427. var length = block.getLength();
  12428. // Nothing to transpose if there aren't two characters.
  12429. if (length <= 1) {
  12430. return editorState;
  12431. }
  12432. var removalRange;
  12433. var finalSelection;
  12434. if (offset === length) {
  12435. // The cursor is at the end of the block. Swap the last two characters.
  12436. removalRange = selection.set('anchorOffset', offset - 1);
  12437. finalSelection = selection;
  12438. } else {
  12439. removalRange = selection.set('focusOffset', offset + 1);
  12440. finalSelection = removalRange.set('anchorOffset', offset + 1);
  12441. }
  12442. // Extract the character to move as a fragment. This preserves its
  12443. // styling and entity, if any.
  12444. var movedFragment = getContentStateFragment_1(content, removalRange);
  12445. var afterRemoval = DraftModifier_1.removeRange(content, removalRange, 'backward');
  12446. // After the removal, the insertion target is one character back.
  12447. var selectionAfter = afterRemoval.getSelectionAfter();
  12448. var targetOffset = selectionAfter.getAnchorOffset() - 1;
  12449. var targetRange = selectionAfter.merge({
  12450. anchorOffset: targetOffset,
  12451. focusOffset: targetOffset
  12452. });
  12453. var afterInsert = DraftModifier_1.replaceWithFragment(afterRemoval, targetRange, movedFragment);
  12454. var newEditorState = EditorState_1.push(editorState, afterInsert, 'insert-fragment');
  12455. return EditorState_1.acceptSelection(newEditorState, finalSelection);
  12456. }
  12457. var keyCommandTransposeCharacters_1 = keyCommandTransposeCharacters;
  12458. function keyCommandUndo(e, editorState, updateFn) {
  12459. var undoneState = EditorState_1.undo(editorState);
  12460. // If the last change to occur was a spellcheck change, allow the undo
  12461. // event to fall through to the browser. This allows the browser to record
  12462. // the unwanted change, which should soon lead it to learn not to suggest
  12463. // the correction again.
  12464. if (editorState.getLastChangeType() === 'spellcheck-change') {
  12465. var nativelyRenderedContent = undoneState.getCurrentContent();
  12466. updateFn(EditorState_1.set(undoneState, { nativelyRenderedContent: nativelyRenderedContent }));
  12467. return;
  12468. }
  12469. // Otheriwse, manage the undo behavior manually.
  12470. e.preventDefault();
  12471. if (!editorState.getNativelyRenderedContent()) {
  12472. updateFn(undoneState);
  12473. return;
  12474. }
  12475. // Trigger a re-render with the current content state to ensure that the
  12476. // component tree has up-to-date props for comparison.
  12477. updateFn(EditorState_1.set(editorState, { nativelyRenderedContent: null }));
  12478. // Wait to ensure that the re-render has occurred before performing
  12479. // the undo action.
  12480. setTimeout(function () {
  12481. updateFn(undoneState);
  12482. }, 0);
  12483. }
  12484. var keyCommandUndo_1 = keyCommandUndo;
  12485. var isOptionKeyCommand = KeyBindingUtil_1.isOptionKeyCommand;
  12486. var isChrome$1 = UserAgent_1.isBrowser('Chrome');
  12487. /**
  12488. * Map a `DraftEditorCommand` command value to a corresponding function.
  12489. */
  12490. function onKeyCommand(command, editorState) {
  12491. switch (command) {
  12492. case 'redo':
  12493. return EditorState_1.redo(editorState);
  12494. case 'delete':
  12495. return keyCommandPlainDelete_1(editorState);
  12496. case 'delete-word':
  12497. return keyCommandDeleteWord_1(editorState);
  12498. case 'backspace':
  12499. return keyCommandPlainBackspace_1(editorState);
  12500. case 'backspace-word':
  12501. return keyCommandBackspaceWord_1(editorState);
  12502. case 'backspace-to-start-of-line':
  12503. return keyCommandBackspaceToStartOfLine_1(editorState);
  12504. case 'split-block':
  12505. return keyCommandInsertNewline_1(editorState);
  12506. case 'transpose-characters':
  12507. return keyCommandTransposeCharacters_1(editorState);
  12508. case 'move-selection-to-start-of-block':
  12509. return keyCommandMoveSelectionToStartOfBlock_1(editorState);
  12510. case 'move-selection-to-end-of-block':
  12511. return keyCommandMoveSelectionToEndOfBlock_1(editorState);
  12512. case 'secondary-cut':
  12513. return SecondaryClipboard_1.cut(editorState);
  12514. case 'secondary-paste':
  12515. return SecondaryClipboard_1.paste(editorState);
  12516. default:
  12517. return editorState;
  12518. }
  12519. }
  12520. /**
  12521. * Intercept keydown behavior to handle keys and commands manually, if desired.
  12522. *
  12523. * Keydown combinations may be mapped to `DraftCommand` values, which may
  12524. * correspond to command functions that modify the editor or its contents.
  12525. *
  12526. * See `getDefaultKeyBinding` for defaults. Alternatively, the top-level
  12527. * component may provide a custom mapping via the `keyBindingFn` prop.
  12528. */
  12529. function editOnKeyDown(editor, e) {
  12530. var keyCode = e.which;
  12531. var editorState = editor._latestEditorState;
  12532. switch (keyCode) {
  12533. case Keys.RETURN:
  12534. e.preventDefault();
  12535. // The top-level component may manually handle newline insertion. If
  12536. // no special handling is performed, fall through to command handling.
  12537. if (editor.props.handleReturn && isEventHandled_1(editor.props.handleReturn(e, editorState))) {
  12538. return;
  12539. }
  12540. break;
  12541. case Keys.ESC:
  12542. e.preventDefault();
  12543. editor.props.onEscape && editor.props.onEscape(e);
  12544. return;
  12545. case Keys.TAB:
  12546. editor.props.onTab && editor.props.onTab(e);
  12547. return;
  12548. case Keys.UP:
  12549. editor.props.onUpArrow && editor.props.onUpArrow(e);
  12550. return;
  12551. case Keys.RIGHT:
  12552. editor.props.onRightArrow && editor.props.onRightArrow(e);
  12553. return;
  12554. case Keys.DOWN:
  12555. editor.props.onDownArrow && editor.props.onDownArrow(e);
  12556. return;
  12557. case Keys.LEFT:
  12558. editor.props.onLeftArrow && editor.props.onLeftArrow(e);
  12559. return;
  12560. case Keys.SPACE:
  12561. // Handling for OSX where option + space scrolls.
  12562. if (isChrome$1 && isOptionKeyCommand(e)) {
  12563. e.preventDefault();
  12564. // Insert a nbsp into the editor.
  12565. var contentState = DraftModifier_1.replaceText(editorState.getCurrentContent(), editorState.getSelection(), '\xA0');
  12566. editor.update(EditorState_1.push(editorState, contentState, 'insert-characters'));
  12567. return;
  12568. }
  12569. }
  12570. var command = editor.props.keyBindingFn(e);
  12571. // If no command is specified, allow keydown event to continue.
  12572. if (!command) {
  12573. return;
  12574. }
  12575. if (command === 'undo') {
  12576. // Since undo requires some special updating behavior to keep the editor
  12577. // in sync, handle it separately.
  12578. keyCommandUndo_1(e, editorState, editor.update);
  12579. return;
  12580. }
  12581. // At this point, we know that we're handling a command of some kind, so
  12582. // we don't want to insert a character following the keydown.
  12583. e.preventDefault();
  12584. // Allow components higher up the tree to handle the command first.
  12585. if (editor.props.handleKeyCommand && isEventHandled_1(editor.props.handleKeyCommand(command, editorState))) {
  12586. return;
  12587. }
  12588. var newState = onKeyCommand(command, editorState);
  12589. if (newState !== editorState) {
  12590. editor.update(newState);
  12591. }
  12592. }
  12593. var editOnKeyDown_1 = editOnKeyDown;
  12594. /**
  12595. * Copyright (c) 2013-present, Facebook, Inc.
  12596. *
  12597. * This source code is licensed under the MIT license found in the
  12598. * LICENSE file in the root directory of this source tree.
  12599. *
  12600. *
  12601. */
  12602. function _classCallCheck$e(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  12603. var URI = function () {
  12604. function URI(uri) {
  12605. _classCallCheck$e(this, URI);
  12606. this._uri = uri;
  12607. }
  12608. URI.prototype.toString = function toString() {
  12609. return this._uri;
  12610. };
  12611. return URI;
  12612. }();
  12613. var URI_1 = URI;
  12614. var isOldIE = UserAgent_1.isBrowser('IE <= 9');
  12615. // Provides a dom node that will not execute scripts
  12616. // https://developer.mozilla.org/en-US/docs/Web/API/DOMImplementation.createHTMLDocument
  12617. // https://developer.mozilla.org/en-US/Add-ons/Code_snippets/HTML_to_DOM
  12618. function getSafeBodyFromHTML(html) {
  12619. var doc;
  12620. var root = null;
  12621. // Provides a safe context
  12622. if (!isOldIE && document.implementation && document.implementation.createHTMLDocument) {
  12623. doc = document.implementation.createHTMLDocument('foo');
  12624. !doc.documentElement ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing doc.documentElement') : invariant_1(false) : void 0;
  12625. doc.documentElement.innerHTML = html;
  12626. root = doc.getElementsByTagName('body')[0];
  12627. }
  12628. return root;
  12629. }
  12630. var getSafeBodyFromHTML_1 = getSafeBodyFromHTML;
  12631. 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; };
  12632. var _knownListItemDepthCl;
  12633. 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; }
  12634. var _require = immutable,
  12635. Set = _require.Set;
  12636. var experimentalTreeDataSupport = DraftFeatureFlags_1.draft_tree_data_support;
  12637. var List$a = immutable.List,
  12638. OrderedSet$5 = immutable.OrderedSet;
  12639. var NBSP = '&nbsp;';
  12640. var SPACE = ' ';
  12641. // Arbitrary max indent
  12642. var MAX_DEPTH = 4;
  12643. // used for replacing characters in HTML
  12644. var REGEX_CR = new RegExp('\r', 'g');
  12645. var REGEX_LF = new RegExp('\n', 'g');
  12646. var REGEX_NBSP = new RegExp(NBSP, 'g');
  12647. var REGEX_CARRIAGE = new RegExp('&#13;?', 'g');
  12648. var REGEX_ZWS = new RegExp('&#8203;?', 'g');
  12649. // https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight
  12650. var boldValues = ['bold', 'bolder', '500', '600', '700', '800', '900'];
  12651. var notBoldValues = ['light', 'lighter', '100', '200', '300', '400'];
  12652. // Block tag flow is different because LIs do not have
  12653. // a deterministic style ;_;
  12654. var inlineTags = {
  12655. b: 'BOLD',
  12656. code: 'CODE',
  12657. del: 'STRIKETHROUGH',
  12658. em: 'ITALIC',
  12659. i: 'ITALIC',
  12660. s: 'STRIKETHROUGH',
  12661. strike: 'STRIKETHROUGH',
  12662. strong: 'BOLD',
  12663. u: 'UNDERLINE'
  12664. };
  12665. 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);
  12666. var anchorAttr = ['className', 'href', 'rel', 'target', 'title'];
  12667. var imgAttr = ['alt', 'className', 'height', 'src', 'width'];
  12668. var lastBlock = void 0;
  12669. var EMPTY_CHUNK = {
  12670. text: '',
  12671. inlines: [],
  12672. entities: [],
  12673. blocks: []
  12674. };
  12675. var EMPTY_BLOCK = {
  12676. children: List$a(),
  12677. depth: 0,
  12678. key: '',
  12679. type: ''
  12680. };
  12681. var getListBlockType = function getListBlockType(tag, lastList) {
  12682. if (tag === 'li') {
  12683. return lastList === 'ol' ? 'ordered-list-item' : 'unordered-list-item';
  12684. }
  12685. return null;
  12686. };
  12687. var getBlockMapSupportedTags = function getBlockMapSupportedTags(blockRenderMap) {
  12688. var unstyledElement = blockRenderMap.get('unstyled').element;
  12689. var tags = Set([]);
  12690. blockRenderMap.forEach(function (draftBlock) {
  12691. if (draftBlock.aliasedElements) {
  12692. draftBlock.aliasedElements.forEach(function (tag) {
  12693. tags = tags.add(tag);
  12694. });
  12695. }
  12696. tags = tags.add(draftBlock.element);
  12697. });
  12698. return tags.filter(function (tag) {
  12699. return tag && tag !== unstyledElement;
  12700. }).toArray().sort();
  12701. };
  12702. // custom element conversions
  12703. var getMultiMatchedType = function getMultiMatchedType(tag, lastList, multiMatchExtractor) {
  12704. for (var ii = 0; ii < multiMatchExtractor.length; ii++) {
  12705. var matchType = multiMatchExtractor[ii](tag, lastList);
  12706. if (matchType) {
  12707. return matchType;
  12708. }
  12709. }
  12710. return null;
  12711. };
  12712. var getBlockTypeForTag = function getBlockTypeForTag(tag, lastList, blockRenderMap) {
  12713. var matchedTypes = blockRenderMap.filter(function (draftBlock) {
  12714. return draftBlock.element === tag || draftBlock.wrapper === tag || draftBlock.aliasedElements && draftBlock.aliasedElements.some(function (alias) {
  12715. return alias === tag;
  12716. });
  12717. }).keySeq().toSet().toArray().sort();
  12718. // if we dont have any matched type, return unstyled
  12719. // if we have one matched type return it
  12720. // if we have multi matched types use the multi-match function to gather type
  12721. switch (matchedTypes.length) {
  12722. case 0:
  12723. return 'unstyled';
  12724. case 1:
  12725. return matchedTypes[0];
  12726. default:
  12727. return getMultiMatchedType(tag, lastList, [getListBlockType]) || 'unstyled';
  12728. }
  12729. };
  12730. var processInlineTag = function processInlineTag(tag, node, currentStyle) {
  12731. var styleToCheck = inlineTags[tag];
  12732. if (styleToCheck) {
  12733. currentStyle = currentStyle.add(styleToCheck).toOrderedSet();
  12734. } else if (node instanceof HTMLElement) {
  12735. var htmlElement = node;
  12736. currentStyle = currentStyle.withMutations(function (style) {
  12737. var fontWeight = htmlElement.style.fontWeight;
  12738. var fontStyle = htmlElement.style.fontStyle;
  12739. var textDecoration = htmlElement.style.textDecoration;
  12740. if (boldValues.indexOf(fontWeight) >= 0) {
  12741. style.add('BOLD');
  12742. } else if (notBoldValues.indexOf(fontWeight) >= 0) {
  12743. style.remove('BOLD');
  12744. }
  12745. if (fontStyle === 'italic') {
  12746. style.add('ITALIC');
  12747. } else if (fontStyle === 'normal') {
  12748. style.remove('ITALIC');
  12749. }
  12750. if (textDecoration === 'underline') {
  12751. style.add('UNDERLINE');
  12752. }
  12753. if (textDecoration === 'line-through') {
  12754. style.add('STRIKETHROUGH');
  12755. }
  12756. if (textDecoration === 'none') {
  12757. style.remove('UNDERLINE');
  12758. style.remove('STRIKETHROUGH');
  12759. }
  12760. }).toOrderedSet();
  12761. }
  12762. return currentStyle;
  12763. };
  12764. var joinChunks = function joinChunks(A, B, experimentalHasNestedBlocks) {
  12765. // Sometimes two blocks will touch in the DOM and we need to strip the
  12766. // extra delimiter to preserve niceness.
  12767. var lastInA = A.text.slice(-1);
  12768. var firstInB = B.text.slice(0, 1);
  12769. if (lastInA === '\r' && firstInB === '\r' && !experimentalHasNestedBlocks) {
  12770. A.text = A.text.slice(0, -1);
  12771. A.inlines.pop();
  12772. A.entities.pop();
  12773. A.blocks.pop();
  12774. }
  12775. // Kill whitespace after blocks
  12776. if (lastInA === '\r') {
  12777. if (B.text === SPACE || B.text === '\n') {
  12778. return A;
  12779. } else if (firstInB === SPACE || firstInB === '\n') {
  12780. B.text = B.text.slice(1);
  12781. B.inlines.shift();
  12782. B.entities.shift();
  12783. }
  12784. }
  12785. return {
  12786. text: A.text + B.text,
  12787. inlines: A.inlines.concat(B.inlines),
  12788. entities: A.entities.concat(B.entities),
  12789. blocks: A.blocks.concat(B.blocks)
  12790. };
  12791. };
  12792. /**
  12793. * Check to see if we have anything like <p> <blockquote> <h1>... to create
  12794. * block tags from. If we do, we can use those and ignore <div> tags. If we
  12795. * don't, we can treat <div> tags as meaningful (unstyled) blocks.
  12796. */
  12797. var containsSemanticBlockMarkup = function containsSemanticBlockMarkup(html, blockTags) {
  12798. return blockTags.some(function (tag) {
  12799. return html.indexOf('<' + tag) !== -1;
  12800. });
  12801. };
  12802. var hasValidLinkText = function hasValidLinkText(link) {
  12803. !(link instanceof HTMLAnchorElement) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Link must be an HTMLAnchorElement.') : invariant_1(false) : void 0;
  12804. var protocol = link.protocol;
  12805. return protocol === 'http:' || protocol === 'https:' || protocol === 'mailto:';
  12806. };
  12807. var getWhitespaceChunk = function getWhitespaceChunk(inEntity) {
  12808. var entities = new Array(1);
  12809. if (inEntity) {
  12810. entities[0] = inEntity;
  12811. }
  12812. return _extends$4({}, EMPTY_CHUNK, {
  12813. text: SPACE,
  12814. inlines: [OrderedSet$5()],
  12815. entities: entities
  12816. });
  12817. };
  12818. var getSoftNewlineChunk = function getSoftNewlineChunk() {
  12819. return _extends$4({}, EMPTY_CHUNK, {
  12820. text: '\n',
  12821. inlines: [OrderedSet$5()],
  12822. entities: new Array(1)
  12823. });
  12824. };
  12825. var getChunkedBlock = function getChunkedBlock() {
  12826. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  12827. return _extends$4({}, EMPTY_BLOCK, props);
  12828. };
  12829. var getBlockDividerChunk = function getBlockDividerChunk(block, depth) {
  12830. var parentKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  12831. return {
  12832. text: '\r',
  12833. inlines: [OrderedSet$5()],
  12834. entities: new Array(1),
  12835. blocks: [getChunkedBlock({
  12836. parent: parentKey,
  12837. key: generateRandomKey_1(),
  12838. type: block,
  12839. depth: Math.max(0, Math.min(MAX_DEPTH, depth))
  12840. })]
  12841. };
  12842. };
  12843. /**
  12844. * If we're pasting from one DraftEditor to another we can check to see if
  12845. * existing list item depth classes are being used and preserve this style
  12846. */
  12847. var getListItemDepth = function getListItemDepth(node) {
  12848. var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  12849. Object.keys(knownListItemDepthClasses).some(function (depthClass) {
  12850. if (node.classList.contains(depthClass)) {
  12851. depth = knownListItemDepthClasses[depthClass];
  12852. }
  12853. });
  12854. return depth;
  12855. };
  12856. var genFragment = function genFragment(entityMap, node, inlineStyle, lastList, inBlock, blockTags, depth, blockRenderMap, inEntity, parentKey) {
  12857. var lastLastBlock = lastBlock;
  12858. var nodeName = node.nodeName.toLowerCase();
  12859. var newEntityMap = entityMap;
  12860. var nextBlockType = 'unstyled';
  12861. var newBlock = false;
  12862. var inBlockType = inBlock && getBlockTypeForTag(inBlock, lastList, blockRenderMap);
  12863. var chunk = _extends$4({}, EMPTY_CHUNK);
  12864. var newChunk = null;
  12865. var blockKey = void 0;
  12866. // Base Case
  12867. if (nodeName === '#text') {
  12868. var _text = node.textContent;
  12869. var nodeTextContent = _text.trim();
  12870. // We should not create blocks for leading spaces that are
  12871. // existing around ol/ul and their children list items
  12872. if (lastList && nodeTextContent === '' && node.parentElement) {
  12873. var parentNodeName = node.parentElement.nodeName.toLowerCase();
  12874. if (parentNodeName === 'ol' || parentNodeName === 'ul') {
  12875. return { chunk: _extends$4({}, EMPTY_CHUNK), entityMap: entityMap };
  12876. }
  12877. }
  12878. if (nodeTextContent === '' && inBlock !== 'pre') {
  12879. return { chunk: getWhitespaceChunk(inEntity), entityMap: entityMap };
  12880. }
  12881. if (inBlock !== 'pre') {
  12882. // Can't use empty string because MSWord
  12883. _text = _text.replace(REGEX_LF, SPACE);
  12884. }
  12885. // save the last block so we can use it later
  12886. lastBlock = nodeName;
  12887. return {
  12888. chunk: {
  12889. text: _text,
  12890. inlines: Array(_text.length).fill(inlineStyle),
  12891. entities: Array(_text.length).fill(inEntity),
  12892. blocks: []
  12893. },
  12894. entityMap: entityMap
  12895. };
  12896. }
  12897. // save the last block so we can use it later
  12898. lastBlock = nodeName;
  12899. // BR tags
  12900. if (nodeName === 'br') {
  12901. if (lastLastBlock === 'br' && (!inBlock || inBlockType === 'unstyled')) {
  12902. return {
  12903. chunk: getBlockDividerChunk('unstyled', depth, parentKey),
  12904. entityMap: entityMap
  12905. };
  12906. }
  12907. return { chunk: getSoftNewlineChunk(), entityMap: entityMap };
  12908. }
  12909. // IMG tags
  12910. if (nodeName === 'img' && node instanceof HTMLImageElement && node.attributes.getNamedItem('src') && node.attributes.getNamedItem('src').value) {
  12911. var image = node;
  12912. var entityConfig = {};
  12913. imgAttr.forEach(function (attr) {
  12914. var imageAttribute = image.getAttribute(attr);
  12915. if (imageAttribute) {
  12916. entityConfig[attr] = imageAttribute;
  12917. }
  12918. });
  12919. // Forcing this node to have children because otherwise no entity will be
  12920. // created for this node.
  12921. // The child text node cannot just have a space or return as content -
  12922. // we strip those out.
  12923. // See https://github.com/facebook/draft-js/issues/231 for some context.
  12924. node.textContent = '\uD83D\uDCF7';
  12925. // TODO: update this when we remove DraftEntity entirely
  12926. inEntity = DraftEntity_1.__create('IMAGE', 'MUTABLE', entityConfig || {});
  12927. }
  12928. // Inline tags
  12929. inlineStyle = processInlineTag(nodeName, node, inlineStyle);
  12930. // Handle lists
  12931. if (nodeName === 'ul' || nodeName === 'ol') {
  12932. if (lastList) {
  12933. depth += 1;
  12934. }
  12935. lastList = nodeName;
  12936. }
  12937. if ( nodeName === 'li' && node instanceof HTMLElement) {
  12938. depth = getListItemDepth(node, depth);
  12939. }
  12940. var blockType = getBlockTypeForTag(nodeName, lastList, blockRenderMap);
  12941. var inListBlock = lastList && inBlock === 'li' && nodeName === 'li';
  12942. var inBlockOrHasNestedBlocks = (!inBlock || experimentalTreeDataSupport) && blockTags.indexOf(nodeName) !== -1;
  12943. // Block Tags
  12944. if (inListBlock || inBlockOrHasNestedBlocks) {
  12945. chunk = getBlockDividerChunk(blockType, depth, parentKey);
  12946. blockKey = chunk.blocks[0].key;
  12947. inBlock = nodeName;
  12948. newBlock = !experimentalTreeDataSupport;
  12949. }
  12950. // this is required so that we can handle 'ul' and 'ol'
  12951. if (inListBlock) {
  12952. nextBlockType = lastList === 'ul' ? 'unordered-list-item' : 'ordered-list-item';
  12953. }
  12954. // Recurse through children
  12955. var child = node.firstChild;
  12956. if (child != null) {
  12957. nodeName = child.nodeName.toLowerCase();
  12958. }
  12959. var entityId = null;
  12960. while (child) {
  12961. if (child instanceof HTMLAnchorElement && child.href && hasValidLinkText(child)) {
  12962. (function () {
  12963. var anchor = child;
  12964. var entityConfig = {};
  12965. anchorAttr.forEach(function (attr) {
  12966. var anchorAttribute = anchor.getAttribute(attr);
  12967. if (anchorAttribute) {
  12968. entityConfig[attr] = anchorAttribute;
  12969. }
  12970. });
  12971. entityConfig.url = new URI_1(anchor.href).toString();
  12972. // TODO: update this when we remove DraftEntity completely
  12973. entityId = DraftEntity_1.__create('LINK', 'MUTABLE', entityConfig || {});
  12974. })();
  12975. } else {
  12976. entityId = undefined;
  12977. }
  12978. var _genFragment = genFragment(newEntityMap, child, inlineStyle, lastList, inBlock, blockTags, depth, blockRenderMap, entityId || inEntity, null),
  12979. generatedChunk = _genFragment.chunk,
  12980. maybeUpdatedEntityMap = _genFragment.entityMap;
  12981. newChunk = generatedChunk;
  12982. newEntityMap = maybeUpdatedEntityMap;
  12983. chunk = joinChunks(chunk, newChunk, experimentalTreeDataSupport);
  12984. var sibling = child.nextSibling;
  12985. // Put in a newline to break up blocks inside blocks
  12986. if (!parentKey && sibling && blockTags.indexOf(nodeName) >= 0 && inBlock) {
  12987. chunk = joinChunks(chunk, getSoftNewlineChunk());
  12988. }
  12989. if (sibling) {
  12990. nodeName = sibling.nodeName.toLowerCase();
  12991. }
  12992. child = sibling;
  12993. }
  12994. if (newBlock) {
  12995. chunk = joinChunks(chunk, getBlockDividerChunk(nextBlockType, depth, parentKey));
  12996. }
  12997. return { chunk: chunk, entityMap: newEntityMap };
  12998. };
  12999. var getChunkForHTML = function getChunkForHTML(html, DOMBuilder, blockRenderMap, entityMap) {
  13000. html = html.trim().replace(REGEX_CR, '').replace(REGEX_NBSP, SPACE).replace(REGEX_CARRIAGE, '').replace(REGEX_ZWS, '');
  13001. var supportedBlockTags = getBlockMapSupportedTags(blockRenderMap);
  13002. var safeBody = DOMBuilder(html);
  13003. if (!safeBody) {
  13004. return null;
  13005. }
  13006. lastBlock = null;
  13007. // Sometimes we aren't dealing with content that contains nice semantic
  13008. // tags. In this case, use divs to separate everything out into paragraphs
  13009. // and hope for the best.
  13010. var workingBlocks = containsSemanticBlockMarkup(html, supportedBlockTags) ? supportedBlockTags : ['div'];
  13011. // Start with -1 block depth to offset the fact that we are passing in a fake
  13012. // UL block to start with.
  13013. var fragment = genFragment(entityMap, safeBody, OrderedSet$5(), 'ul', null, workingBlocks, -1, blockRenderMap);
  13014. var chunk = fragment.chunk;
  13015. var newEntityMap = fragment.entityMap;
  13016. // join with previous block to prevent weirdness on paste
  13017. if (chunk.text.indexOf('\r') === 0) {
  13018. chunk = {
  13019. text: chunk.text.slice(1),
  13020. inlines: chunk.inlines.slice(1),
  13021. entities: chunk.entities.slice(1),
  13022. blocks: chunk.blocks
  13023. };
  13024. }
  13025. // Kill block delimiter at the end
  13026. if (chunk.text.slice(-1) === '\r') {
  13027. chunk.text = chunk.text.slice(0, -1);
  13028. chunk.inlines = chunk.inlines.slice(0, -1);
  13029. chunk.entities = chunk.entities.slice(0, -1);
  13030. chunk.blocks.pop();
  13031. }
  13032. // If we saw no block tags, put an unstyled one in
  13033. if (chunk.blocks.length === 0) {
  13034. chunk.blocks.push(_extends$4({}, EMPTY_CHUNK, {
  13035. type: 'unstyled',
  13036. depth: 0
  13037. }));
  13038. }
  13039. // Sometimes we start with text that isn't in a block, which is then
  13040. // followed by blocks. Need to fix up the blocks to add in
  13041. // an unstyled block for this content
  13042. if (chunk.text.split('\r').length === chunk.blocks.length + 1) {
  13043. chunk.blocks.unshift({ type: 'unstyled', depth: 0 });
  13044. }
  13045. return { chunk: chunk, entityMap: newEntityMap };
  13046. };
  13047. var convertChunkToContentBlocks = function convertChunkToContentBlocks(chunk) {
  13048. if (!chunk || !chunk.text || !Array.isArray(chunk.blocks)) {
  13049. return null;
  13050. }
  13051. var initialState = {
  13052. cacheRef: {},
  13053. contentBlocks: []
  13054. };
  13055. var start = 0;
  13056. var rawBlocks = chunk.blocks,
  13057. rawInlines = chunk.inlines,
  13058. rawEntities = chunk.entities;
  13059. var BlockNodeRecord = ContentBlock_1;
  13060. return chunk.text.split('\r').reduce(function (acc, textBlock, index) {
  13061. // Make absolutely certain that our text is acceptable.
  13062. textBlock = sanitizeDraftText_1(textBlock);
  13063. var block = rawBlocks[index];
  13064. var end = start + textBlock.length;
  13065. var inlines = rawInlines.slice(start, end);
  13066. var entities = rawEntities.slice(start, end);
  13067. var characterList = List$a(inlines.map(function (style, index) {
  13068. var data = { style: style, entity: null };
  13069. if (entities[index]) {
  13070. data.entity = entities[index];
  13071. }
  13072. return CharacterMetadata_1.create(data);
  13073. }));
  13074. start = end + 1;
  13075. var depth = block.depth,
  13076. type = block.type,
  13077. parent = block.parent;
  13078. var key = block.key || generateRandomKey_1();
  13079. var parentTextNodeKey = null; // will be used to store container text nodes
  13080. // childrens add themselves to their parents since we are iterating in order
  13081. if (parent) {
  13082. var parentIndex = acc.cacheRef[parent];
  13083. var parentRecord = acc.contentBlocks[parentIndex];
  13084. // if parent has text we need to split it into a separate unstyled element
  13085. if (parentRecord.getChildKeys().isEmpty() && parentRecord.getText()) {
  13086. var parentCharacterList = parentRecord.getCharacterList();
  13087. var parentText = parentRecord.getText();
  13088. parentTextNodeKey = generateRandomKey_1();
  13089. var textNode = new ContentBlockNode_1({
  13090. key: parentTextNodeKey,
  13091. text: parentText,
  13092. characterList: parentCharacterList,
  13093. parent: parent,
  13094. nextSibling: key
  13095. });
  13096. acc.contentBlocks.push(textNode);
  13097. parentRecord = parentRecord.withMutations(function (block) {
  13098. block.set('characterList', List$a()).set('text', '').set('children', parentRecord.children.push(textNode.getKey()));
  13099. });
  13100. }
  13101. acc.contentBlocks[parentIndex] = parentRecord.set('children', parentRecord.children.push(key));
  13102. }
  13103. var blockNode = new BlockNodeRecord({
  13104. key: key,
  13105. parent: parent,
  13106. type: type,
  13107. depth: depth,
  13108. text: textBlock,
  13109. characterList: characterList,
  13110. prevSibling: parentTextNodeKey || (index === 0 || rawBlocks[index - 1].parent !== parent ? null : rawBlocks[index - 1].key),
  13111. nextSibling: index === rawBlocks.length - 1 || rawBlocks[index + 1].parent !== parent ? null : rawBlocks[index + 1].key
  13112. });
  13113. // insert node
  13114. acc.contentBlocks.push(blockNode);
  13115. // cache ref for building links
  13116. acc.cacheRef[blockNode.key] = index;
  13117. return acc;
  13118. }, initialState).contentBlocks;
  13119. };
  13120. var convertFromHTMLtoContentBlocks = function convertFromHTMLtoContentBlocks(html) {
  13121. var DOMBuilder = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : getSafeBodyFromHTML_1;
  13122. var blockRenderMap = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DefaultDraftBlockRenderMap_1;
  13123. // Be ABSOLUTELY SURE that the dom builder you pass here won't execute
  13124. // arbitrary code in whatever environment you're running this in. For an
  13125. // example of how we try to do this in-browser, see getSafeBodyFromHTML.
  13126. // TODO: replace DraftEntity with an OrderedMap here
  13127. var chunkData = getChunkForHTML(html, DOMBuilder, blockRenderMap, DraftEntity_1);
  13128. if (chunkData == null) {
  13129. return null;
  13130. }
  13131. var chunk = chunkData.chunk,
  13132. entityMap = chunkData.entityMap;
  13133. var contentBlocks = convertChunkToContentBlocks(chunk);
  13134. return {
  13135. contentBlocks: contentBlocks,
  13136. entityMap: entityMap
  13137. };
  13138. };
  13139. var convertFromHTMLToContentBlocks = convertFromHTMLtoContentBlocks;
  13140. var List$b = immutable.List,
  13141. Repeat$6 = immutable.Repeat;
  13142. var ContentBlockRecord$2 = ContentBlock_1;
  13143. var DraftPasteProcessor = {
  13144. processHTML: function processHTML(html, blockRenderMap) {
  13145. return convertFromHTMLToContentBlocks(html, getSafeBodyFromHTML_1, blockRenderMap);
  13146. },
  13147. processText: function processText(textBlocks, character, type) {
  13148. return textBlocks.reduce(function (acc, textLine, index) {
  13149. textLine = sanitizeDraftText_1(textLine);
  13150. var key = generateRandomKey_1();
  13151. var blockNodeConfig = {
  13152. key: key,
  13153. type: type,
  13154. text: textLine,
  13155. characterList: List$b(Repeat$6(character, textLine.length))
  13156. };
  13157. acc.push(new ContentBlockRecord$2(blockNodeConfig));
  13158. return acc;
  13159. }, []);
  13160. }
  13161. };
  13162. var DraftPasteProcessor_1 = DraftPasteProcessor;
  13163. /**
  13164. * Copyright (c) 2013-present, Facebook, Inc.
  13165. * All rights reserved.
  13166. *
  13167. * This source code is licensed under the BSD-style license found in the
  13168. * LICENSE file in the root directory of this source tree. An additional grant
  13169. * of patent rights can be found in the PATENTS file in the same directory.
  13170. *
  13171. * @providesModule adjustBlockDepthForContentState
  13172. * @format
  13173. *
  13174. */
  13175. function adjustBlockDepthForContentState(contentState, selectionState, adjustment, maxDepth) {
  13176. var startKey = selectionState.getStartKey();
  13177. var endKey = selectionState.getEndKey();
  13178. var blockMap = contentState.getBlockMap();
  13179. var blocks = blockMap.toSeq().skipUntil(function (_, k) {
  13180. return k === startKey;
  13181. }).takeUntil(function (_, k) {
  13182. return k === endKey;
  13183. }).concat([[endKey, blockMap.get(endKey)]]).map(function (block) {
  13184. var depth = block.getDepth() + adjustment;
  13185. depth = Math.max(0, Math.min(depth, maxDepth));
  13186. return block.set('depth', depth);
  13187. });
  13188. blockMap = blockMap.merge(blocks);
  13189. return contentState.merge({
  13190. blockMap: blockMap,
  13191. selectionBefore: selectionState,
  13192. selectionAfter: selectionState
  13193. });
  13194. }
  13195. var adjustBlockDepthForContentState_1 = adjustBlockDepthForContentState;
  13196. var RichTextEditorUtil = {
  13197. currentBlockContainsLink: function currentBlockContainsLink(editorState) {
  13198. var selection = editorState.getSelection();
  13199. var contentState = editorState.getCurrentContent();
  13200. var entityMap = contentState.getEntityMap();
  13201. return contentState.getBlockForKey(selection.getAnchorKey()).getCharacterList().slice(selection.getStartOffset(), selection.getEndOffset()).some(function (v) {
  13202. var entity = v.getEntity();
  13203. return !!entity && entityMap.__get(entity).getType() === 'LINK';
  13204. });
  13205. },
  13206. getCurrentBlockType: function getCurrentBlockType(editorState) {
  13207. var selection = editorState.getSelection();
  13208. return editorState.getCurrentContent().getBlockForKey(selection.getStartKey()).getType();
  13209. },
  13210. getDataObjectForLinkURL: function getDataObjectForLinkURL(uri) {
  13211. return { url: uri.toString() };
  13212. },
  13213. handleKeyCommand: function handleKeyCommand(editorState, command) {
  13214. switch (command) {
  13215. case 'bold':
  13216. return RichTextEditorUtil.toggleInlineStyle(editorState, 'BOLD');
  13217. case 'italic':
  13218. return RichTextEditorUtil.toggleInlineStyle(editorState, 'ITALIC');
  13219. case 'underline':
  13220. return RichTextEditorUtil.toggleInlineStyle(editorState, 'UNDERLINE');
  13221. case 'code':
  13222. return RichTextEditorUtil.toggleCode(editorState);
  13223. case 'backspace':
  13224. case 'backspace-word':
  13225. case 'backspace-to-start-of-line':
  13226. return RichTextEditorUtil.onBackspace(editorState);
  13227. case 'delete':
  13228. case 'delete-word':
  13229. case 'delete-to-end-of-block':
  13230. return RichTextEditorUtil.onDelete(editorState);
  13231. default:
  13232. // they may have custom editor commands; ignore those
  13233. return null;
  13234. }
  13235. },
  13236. insertSoftNewline: function insertSoftNewline(editorState) {
  13237. var contentState = DraftModifier_1.insertText(editorState.getCurrentContent(), editorState.getSelection(), '\n', editorState.getCurrentInlineStyle(), null);
  13238. var newEditorState = EditorState_1.push(editorState, contentState, 'insert-characters');
  13239. return EditorState_1.forceSelection(newEditorState, contentState.getSelectionAfter());
  13240. },
  13241. /**
  13242. * For collapsed selections at the start of styled blocks, backspace should
  13243. * just remove the existing style.
  13244. */
  13245. onBackspace: function onBackspace(editorState) {
  13246. var selection = editorState.getSelection();
  13247. if (!selection.isCollapsed() || selection.getAnchorOffset() || selection.getFocusOffset()) {
  13248. return null;
  13249. }
  13250. // First, try to remove a preceding atomic block.
  13251. var content = editorState.getCurrentContent();
  13252. var startKey = selection.getStartKey();
  13253. var blockBefore = content.getBlockBefore(startKey);
  13254. if (blockBefore && blockBefore.getType() === 'atomic') {
  13255. var blockMap = content.getBlockMap()['delete'](blockBefore.getKey());
  13256. var withoutAtomicBlock = content.merge({
  13257. blockMap: blockMap,
  13258. selectionAfter: selection
  13259. });
  13260. if (withoutAtomicBlock !== content) {
  13261. return EditorState_1.push(editorState, withoutAtomicBlock, 'remove-range');
  13262. }
  13263. }
  13264. // If that doesn't succeed, try to remove the current block style.
  13265. var withoutBlockStyle = RichTextEditorUtil.tryToRemoveBlockStyle(editorState);
  13266. if (withoutBlockStyle) {
  13267. return EditorState_1.push(editorState, withoutBlockStyle, 'change-block-type');
  13268. }
  13269. return null;
  13270. },
  13271. onDelete: function onDelete(editorState) {
  13272. var selection = editorState.getSelection();
  13273. if (!selection.isCollapsed()) {
  13274. return null;
  13275. }
  13276. var content = editorState.getCurrentContent();
  13277. var startKey = selection.getStartKey();
  13278. var block = content.getBlockForKey(startKey);
  13279. var length = block.getLength();
  13280. // The cursor is somewhere within the text. Behave normally.
  13281. if (selection.getStartOffset() < length) {
  13282. return null;
  13283. }
  13284. var blockAfter = content.getBlockAfter(startKey);
  13285. if (!blockAfter || blockAfter.getType() !== 'atomic') {
  13286. return null;
  13287. }
  13288. var atomicBlockTarget = selection.merge({
  13289. focusKey: blockAfter.getKey(),
  13290. focusOffset: blockAfter.getLength()
  13291. });
  13292. var withoutAtomicBlock = DraftModifier_1.removeRange(content, atomicBlockTarget, 'forward');
  13293. if (withoutAtomicBlock !== content) {
  13294. return EditorState_1.push(editorState, withoutAtomicBlock, 'remove-range');
  13295. }
  13296. return null;
  13297. },
  13298. onTab: function onTab(event, editorState, maxDepth) {
  13299. var selection = editorState.getSelection();
  13300. var key = selection.getAnchorKey();
  13301. if (key !== selection.getFocusKey()) {
  13302. return editorState;
  13303. }
  13304. var content = editorState.getCurrentContent();
  13305. var block = content.getBlockForKey(key);
  13306. var type = block.getType();
  13307. if (type !== 'unordered-list-item' && type !== 'ordered-list-item') {
  13308. return editorState;
  13309. }
  13310. event.preventDefault();
  13311. // Only allow indenting one level beyond the block above, and only if
  13312. // the block above is a list item as well.
  13313. var blockAbove = content.getBlockBefore(key);
  13314. if (!blockAbove) {
  13315. return editorState;
  13316. }
  13317. var typeAbove = blockAbove.getType();
  13318. if (typeAbove !== 'unordered-list-item' && typeAbove !== 'ordered-list-item') {
  13319. return editorState;
  13320. }
  13321. var depth = block.getDepth();
  13322. if (!event.shiftKey && depth === maxDepth) {
  13323. return editorState;
  13324. }
  13325. maxDepth = Math.min(blockAbove.getDepth() + 1, maxDepth);
  13326. var withAdjustment = adjustBlockDepthForContentState_1(content, selection, event.shiftKey ? -1 : 1, maxDepth);
  13327. return EditorState_1.push(editorState, withAdjustment, 'adjust-depth');
  13328. },
  13329. toggleBlockType: function toggleBlockType(editorState, blockType) {
  13330. var selection = editorState.getSelection();
  13331. var startKey = selection.getStartKey();
  13332. var endKey = selection.getEndKey();
  13333. var content = editorState.getCurrentContent();
  13334. var target = selection;
  13335. // Triple-click can lead to a selection that includes offset 0 of the
  13336. // following block. The `SelectionState` for this case is accurate, but
  13337. // we should avoid toggling block type for the trailing block because it
  13338. // is a confusing interaction.
  13339. if (startKey !== endKey && selection.getEndOffset() === 0) {
  13340. var blockBefore = nullthrows_1(content.getBlockBefore(endKey));
  13341. endKey = blockBefore.getKey();
  13342. target = target.merge({
  13343. anchorKey: startKey,
  13344. anchorOffset: selection.getStartOffset(),
  13345. focusKey: endKey,
  13346. focusOffset: blockBefore.getLength(),
  13347. isBackward: false
  13348. });
  13349. }
  13350. var hasAtomicBlock = content.getBlockMap().skipWhile(function (_, k) {
  13351. return k !== startKey;
  13352. }).reverse().skipWhile(function (_, k) {
  13353. return k !== endKey;
  13354. }).some(function (v) {
  13355. return v.getType() === 'atomic';
  13356. });
  13357. if (hasAtomicBlock) {
  13358. return editorState;
  13359. }
  13360. var typeToSet = content.getBlockForKey(startKey).getType() === blockType ? 'unstyled' : blockType;
  13361. return EditorState_1.push(editorState, DraftModifier_1.setBlockType(content, target, typeToSet), 'change-block-type');
  13362. },
  13363. toggleCode: function toggleCode(editorState) {
  13364. var selection = editorState.getSelection();
  13365. var anchorKey = selection.getAnchorKey();
  13366. var focusKey = selection.getFocusKey();
  13367. if (selection.isCollapsed() || anchorKey !== focusKey) {
  13368. return RichTextEditorUtil.toggleBlockType(editorState, 'code-block');
  13369. }
  13370. return RichTextEditorUtil.toggleInlineStyle(editorState, 'CODE');
  13371. },
  13372. /**
  13373. * Toggle the specified inline style for the selection. If the
  13374. * user's selection is collapsed, apply or remove the style for the
  13375. * internal state. If it is not collapsed, apply the change directly
  13376. * to the document state.
  13377. */
  13378. toggleInlineStyle: function toggleInlineStyle(editorState, inlineStyle) {
  13379. var selection = editorState.getSelection();
  13380. var currentStyle = editorState.getCurrentInlineStyle();
  13381. // If the selection is collapsed, toggle the specified style on or off and
  13382. // set the result as the new inline style override. This will then be
  13383. // used as the inline style for the next character to be inserted.
  13384. if (selection.isCollapsed()) {
  13385. return EditorState_1.setInlineStyleOverride(editorState, currentStyle.has(inlineStyle) ? currentStyle.remove(inlineStyle) : currentStyle.add(inlineStyle));
  13386. }
  13387. // If characters are selected, immediately apply or remove the
  13388. // inline style on the document state itself.
  13389. var content = editorState.getCurrentContent();
  13390. var newContent;
  13391. // If the style is already present for the selection range, remove it.
  13392. // Otherwise, apply it.
  13393. if (currentStyle.has(inlineStyle)) {
  13394. newContent = DraftModifier_1.removeInlineStyle(content, selection, inlineStyle);
  13395. } else {
  13396. newContent = DraftModifier_1.applyInlineStyle(content, selection, inlineStyle);
  13397. }
  13398. return EditorState_1.push(editorState, newContent, 'change-inline-style');
  13399. },
  13400. toggleLink: function toggleLink(editorState, targetSelection, entityKey) {
  13401. var withoutLink = DraftModifier_1.applyEntity(editorState.getCurrentContent(), targetSelection, entityKey);
  13402. return EditorState_1.push(editorState, withoutLink, 'apply-entity');
  13403. },
  13404. /**
  13405. * When a collapsed cursor is at the start of the first styled block, or
  13406. * an empty styled block, changes block to 'unstyled'. Returns null if
  13407. * block or selection does not meet that criteria.
  13408. */
  13409. tryToRemoveBlockStyle: function tryToRemoveBlockStyle(editorState) {
  13410. var selection = editorState.getSelection();
  13411. var offset = selection.getAnchorOffset();
  13412. if (selection.isCollapsed() && offset === 0) {
  13413. var key = selection.getAnchorKey();
  13414. var content = editorState.getCurrentContent();
  13415. var block = content.getBlockForKey(key);
  13416. var firstBlock = content.getFirstBlock();
  13417. if (block.getLength() > 0 && block !== firstBlock) {
  13418. return null;
  13419. }
  13420. var type = block.getType();
  13421. var blockBefore = content.getBlockBefore(key);
  13422. if (type === 'code-block' && blockBefore && blockBefore.getType() === 'code-block' && blockBefore.getLength() !== 0) {
  13423. return null;
  13424. }
  13425. if (type !== 'unstyled') {
  13426. return DraftModifier_1.setBlockType(content, selection, 'unstyled');
  13427. }
  13428. }
  13429. return null;
  13430. }
  13431. };
  13432. var RichTextEditorUtil_1 = RichTextEditorUtil;
  13433. /**
  13434. * Copyright (c) 2013-present, Facebook, Inc.
  13435. * All rights reserved.
  13436. *
  13437. * This source code is licensed under the BSD-style license found in the
  13438. * LICENSE file in the root directory of this source tree. An additional grant
  13439. * of patent rights can be found in the PATENTS file in the same directory.
  13440. *
  13441. * @providesModule splitTextIntoTextBlocks
  13442. * @format
  13443. *
  13444. */
  13445. var NEWLINE_REGEX = /\r\n?|\n/g;
  13446. function splitTextIntoTextBlocks(text) {
  13447. return text.split(NEWLINE_REGEX);
  13448. }
  13449. var splitTextIntoTextBlocks_1 = splitTextIntoTextBlocks;
  13450. /**
  13451. * Paste content.
  13452. */
  13453. function editOnPaste(editor, e) {
  13454. e.preventDefault();
  13455. var data = new DataTransfer_1(e.clipboardData);
  13456. // Get files, unless this is likely to be a string the user wants inline.
  13457. if (!data.isRichText()) {
  13458. var files = data.getFiles();
  13459. var defaultFileText = data.getText();
  13460. if (files.length > 0) {
  13461. // Allow customized paste handling for images, etc. Otherwise, fall
  13462. // through to insert text contents into the editor.
  13463. if (editor.props.handlePastedFiles && isEventHandled_1(editor.props.handlePastedFiles(files))) {
  13464. return;
  13465. }
  13466. getTextContentFromFiles_1(files, function ( /*string*/fileText) {
  13467. fileText = fileText || defaultFileText;
  13468. if (!fileText) {
  13469. return;
  13470. }
  13471. var editorState = editor._latestEditorState;
  13472. var blocks = splitTextIntoTextBlocks_1(fileText);
  13473. var character = CharacterMetadata_1.create({
  13474. style: editorState.getCurrentInlineStyle(),
  13475. entity: getEntityKeyForSelection_1(editorState.getCurrentContent(), editorState.getSelection())
  13476. });
  13477. var currentBlockType = RichTextEditorUtil_1.getCurrentBlockType(editorState);
  13478. var text = DraftPasteProcessor_1.processText(blocks, character, currentBlockType);
  13479. var fragment = BlockMapBuilder_1.createFromArray(text);
  13480. var withInsertedText = DraftModifier_1.replaceWithFragment(editorState.getCurrentContent(), editorState.getSelection(), fragment);
  13481. editor.update(EditorState_1.push(editorState, withInsertedText, 'insert-fragment'));
  13482. });
  13483. return;
  13484. }
  13485. }
  13486. var textBlocks = [];
  13487. var text = data.getText();
  13488. var html = data.getHTML();
  13489. var editorState = editor._latestEditorState;
  13490. if (editor.props.handlePastedText && isEventHandled_1(editor.props.handlePastedText(text, html, editorState))) {
  13491. return;
  13492. }
  13493. if (text) {
  13494. textBlocks = splitTextIntoTextBlocks_1(text);
  13495. }
  13496. if (!editor.props.stripPastedStyles) {
  13497. // If the text from the paste event is rich content that matches what we
  13498. // already have on the internal clipboard, assume that we should just use
  13499. // the clipboard fragment for the paste. This will allow us to preserve
  13500. // styling and entities, if any are present. Note that newlines are
  13501. // stripped during comparison -- this is because copy/paste within the
  13502. // editor in Firefox and IE will not include empty lines. The resulting
  13503. // paste will preserve the newlines correctly.
  13504. var internalClipboard = editor.getClipboard();
  13505. if (data.isRichText() && internalClipboard) {
  13506. if (
  13507. // If the editorKey is present in the pasted HTML, it should be safe to
  13508. // assume this is an internal paste.
  13509. html.indexOf(editor.getEditorKey()) !== -1 ||
  13510. // The copy may have been made within a single block, in which case the
  13511. // editor key won't be part of the paste. In this case, just check
  13512. // whether the pasted text matches the internal clipboard.
  13513. textBlocks.length === 1 && internalClipboard.size === 1 && internalClipboard.first().getText() === text) {
  13514. editor.update(insertFragment$1(editor._latestEditorState, internalClipboard));
  13515. return;
  13516. }
  13517. } else if (internalClipboard && data.types.includes('com.apple.webarchive') && !data.types.includes('text/html') && areTextBlocksAndClipboardEqual(textBlocks, internalClipboard)) {
  13518. // Safari does not properly store text/html in some cases.
  13519. // Use the internalClipboard if present and equal to what is on
  13520. // the clipboard. See https://bugs.webkit.org/show_bug.cgi?id=19893.
  13521. editor.update(insertFragment$1(editor._latestEditorState, internalClipboard));
  13522. return;
  13523. }
  13524. // If there is html paste data, try to parse that.
  13525. if (html) {
  13526. var htmlFragment = DraftPasteProcessor_1.processHTML(html, editor.props.blockRenderMap);
  13527. if (htmlFragment) {
  13528. var contentBlocks = htmlFragment.contentBlocks,
  13529. entityMap = htmlFragment.entityMap;
  13530. if (contentBlocks) {
  13531. var htmlMap = BlockMapBuilder_1.createFromArray(contentBlocks);
  13532. editor.update(insertFragment$1(editor._latestEditorState, htmlMap, entityMap));
  13533. return;
  13534. }
  13535. }
  13536. }
  13537. // Otherwise, create a new fragment from our pasted text. Also
  13538. // empty the internal clipboard, since it's no longer valid.
  13539. editor.setClipboard(null);
  13540. }
  13541. if (textBlocks.length) {
  13542. var character = CharacterMetadata_1.create({
  13543. style: editorState.getCurrentInlineStyle(),
  13544. entity: getEntityKeyForSelection_1(editorState.getCurrentContent(), editorState.getSelection())
  13545. });
  13546. var currentBlockType = RichTextEditorUtil_1.getCurrentBlockType(editorState);
  13547. var textFragment = DraftPasteProcessor_1.processText(textBlocks, character, currentBlockType);
  13548. var textMap = BlockMapBuilder_1.createFromArray(textFragment);
  13549. editor.update(insertFragment$1(editor._latestEditorState, textMap));
  13550. }
  13551. }
  13552. function insertFragment$1(editorState, fragment, entityMap) {
  13553. var newContent = DraftModifier_1.replaceWithFragment(editorState.getCurrentContent(), editorState.getSelection(), fragment);
  13554. // TODO: merge the entity map once we stop using DraftEntity
  13555. // like this:
  13556. // const mergedEntityMap = newContent.getEntityMap().merge(entityMap);
  13557. return EditorState_1.push(editorState, newContent.set('entityMap', entityMap), 'insert-fragment');
  13558. }
  13559. function areTextBlocksAndClipboardEqual(textBlocks, blockMap) {
  13560. return textBlocks.length === blockMap.size && blockMap.valueSeq().every(function (block, ii) {
  13561. return block.getText() === textBlocks[ii];
  13562. });
  13563. }
  13564. var editOnPaste_1 = editOnPaste;
  13565. /**
  13566. * Convert the current selection range to an anchor/focus pair of offset keys
  13567. * and values that can be interpreted by components.
  13568. */
  13569. function getDraftEditorSelection(editorState, root) {
  13570. var selection = commonjsGlobal.getSelection();
  13571. // No active selection.
  13572. if (selection.rangeCount === 0) {
  13573. return {
  13574. selectionState: editorState.getSelection().set('hasFocus', false),
  13575. needsRecovery: false
  13576. };
  13577. }
  13578. return getDraftEditorSelectionWithNodes_1(editorState, root, selection.anchorNode, selection.anchorOffset, selection.focusNode, selection.focusOffset);
  13579. }
  13580. var getDraftEditorSelection_1 = getDraftEditorSelection;
  13581. function editOnSelect(editor) {
  13582. if (editor._blockSelectEvents || editor._latestEditorState !== editor.props.editorState) {
  13583. return;
  13584. }
  13585. var editorState = editor.props.editorState;
  13586. var editorNode = ReactDOM.findDOMNode(editor.editorContainer);
  13587. !editorNode ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing editorNode') : invariant_1(false) : void 0;
  13588. !(editorNode.firstChild instanceof HTMLElement) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'editorNode.firstChild is not an HTMLElement') : invariant_1(false) : void 0;
  13589. var documentSelection = getDraftEditorSelection_1(editorState, editorNode.firstChild);
  13590. var updatedSelectionState = documentSelection.selectionState;
  13591. if (updatedSelectionState !== editorState.getSelection()) {
  13592. if (documentSelection.needsRecovery) {
  13593. editorState = EditorState_1.forceSelection(editorState, updatedSelectionState);
  13594. } else {
  13595. editorState = EditorState_1.acceptSelection(editorState, updatedSelectionState);
  13596. }
  13597. editor.update(editorState);
  13598. }
  13599. }
  13600. var editOnSelect_1 = editOnSelect;
  13601. var DraftEditorEditHandler = {
  13602. onBeforeInput: editOnBeforeInput_1,
  13603. onBlur: editOnBlur_1,
  13604. onCompositionStart: editOnCompositionStart_1,
  13605. onCopy: editOnCopy_1,
  13606. onCut: editOnCut_1,
  13607. onDragOver: editOnDragOver_1,
  13608. onDragStart: editOnDragStart_1,
  13609. onFocus: editOnFocus_1,
  13610. onInput: editOnInput_1,
  13611. onKeyDown: editOnKeyDown_1,
  13612. onPaste: editOnPaste_1,
  13613. onSelect: editOnSelect_1
  13614. };
  13615. var DraftEditorEditHandler_1 = DraftEditorEditHandler;
  13616. function _classCallCheck$f(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13617. 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; }
  13618. 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; }
  13619. /**
  13620. * This component is responsible for rendering placeholder text for the
  13621. * `DraftEditor` component.
  13622. *
  13623. * Override placeholder style via CSS.
  13624. */
  13625. var DraftEditorPlaceholder = function (_React$Component) {
  13626. _inherits$a(DraftEditorPlaceholder, _React$Component);
  13627. function DraftEditorPlaceholder() {
  13628. _classCallCheck$f(this, DraftEditorPlaceholder);
  13629. return _possibleConstructorReturn$a(this, _React$Component.apply(this, arguments));
  13630. }
  13631. DraftEditorPlaceholder.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
  13632. return this.props.text !== nextProps.text || this.props.editorState.getSelection().getHasFocus() !== nextProps.editorState.getSelection().getHasFocus();
  13633. };
  13634. DraftEditorPlaceholder.prototype.render = function render() {
  13635. var hasFocus = this.props.editorState.getSelection().getHasFocus();
  13636. var className = cx_1({
  13637. 'public/DraftEditorPlaceholder/root': true,
  13638. 'public/DraftEditorPlaceholder/hasFocus': hasFocus
  13639. });
  13640. var contentStyle = {
  13641. whiteSpace: 'pre-wrap'
  13642. };
  13643. return React.createElement(
  13644. 'div',
  13645. { className: className },
  13646. React.createElement(
  13647. 'div',
  13648. {
  13649. className: cx_1('public/DraftEditorPlaceholder/inner'),
  13650. id: this.props.accessibilityID,
  13651. style: contentStyle },
  13652. this.props.text
  13653. )
  13654. );
  13655. };
  13656. return DraftEditorPlaceholder;
  13657. }(React.Component);
  13658. var DraftEditorPlaceholder_react = DraftEditorPlaceholder;
  13659. var isOSX$1 = UserAgent_1.isPlatform('Mac OS X');
  13660. var isWindows = UserAgent_1.isPlatform('Windows');
  13661. // Firefox on OSX had a bug resulting in navigation instead of cursor movement.
  13662. // This bug was fixed in Firefox 29. Feature detection is virtually impossible
  13663. // so we just check the version number. See #342765.
  13664. var shouldFixFirefoxMovement = isOSX$1 && UserAgent_1.isBrowser('Firefox < 29');
  13665. var hasCommandModifier = KeyBindingUtil_1.hasCommandModifier,
  13666. isCtrlKeyCommand = KeyBindingUtil_1.isCtrlKeyCommand;
  13667. function shouldRemoveWord(e) {
  13668. return isOSX$1 && e.altKey || isCtrlKeyCommand(e);
  13669. }
  13670. /**
  13671. * Get the appropriate undo/redo command for a Z key command.
  13672. */
  13673. function getZCommand(e) {
  13674. if (!hasCommandModifier(e)) {
  13675. return null;
  13676. }
  13677. return e.shiftKey ? 'redo' : 'undo';
  13678. }
  13679. function getDeleteCommand(e) {
  13680. // Allow default "cut" behavior for Windows on Shift + Delete.
  13681. if (isWindows && e.shiftKey) {
  13682. return null;
  13683. }
  13684. return shouldRemoveWord(e) ? 'delete-word' : 'delete';
  13685. }
  13686. function getBackspaceCommand(e) {
  13687. if (hasCommandModifier(e) && isOSX$1) {
  13688. return 'backspace-to-start-of-line';
  13689. }
  13690. return shouldRemoveWord(e) ? 'backspace-word' : 'backspace';
  13691. }
  13692. /**
  13693. * Retrieve a bound key command for the given event.
  13694. */
  13695. function getDefaultKeyBinding(e) {
  13696. switch (e.keyCode) {
  13697. case 66:
  13698. // B
  13699. return hasCommandModifier(e) ? 'bold' : null;
  13700. case 68:
  13701. // D
  13702. return isCtrlKeyCommand(e) ? 'delete' : null;
  13703. case 72:
  13704. // H
  13705. return isCtrlKeyCommand(e) ? 'backspace' : null;
  13706. case 73:
  13707. // I
  13708. return hasCommandModifier(e) ? 'italic' : null;
  13709. case 74:
  13710. // J
  13711. return hasCommandModifier(e) ? 'code' : null;
  13712. case 75:
  13713. // K
  13714. return !isWindows && isCtrlKeyCommand(e) ? 'secondary-cut' : null;
  13715. case 77:
  13716. // M
  13717. return isCtrlKeyCommand(e) ? 'split-block' : null;
  13718. case 79:
  13719. // O
  13720. return isCtrlKeyCommand(e) ? 'split-block' : null;
  13721. case 84:
  13722. // T
  13723. return isOSX$1 && isCtrlKeyCommand(e) ? 'transpose-characters' : null;
  13724. case 85:
  13725. // U
  13726. return hasCommandModifier(e) ? 'underline' : null;
  13727. case 87:
  13728. // W
  13729. return isOSX$1 && isCtrlKeyCommand(e) ? 'backspace-word' : null;
  13730. case 89:
  13731. // Y
  13732. if (isCtrlKeyCommand(e)) {
  13733. return isWindows ? 'redo' : 'secondary-paste';
  13734. }
  13735. return null;
  13736. case 90:
  13737. // Z
  13738. return getZCommand(e) || null;
  13739. case Keys.RETURN:
  13740. return 'split-block';
  13741. case Keys.DELETE:
  13742. return getDeleteCommand(e);
  13743. case Keys.BACKSPACE:
  13744. return getBackspaceCommand(e);
  13745. // LEFT/RIGHT handlers serve as a workaround for a Firefox bug.
  13746. case Keys.LEFT:
  13747. return shouldFixFirefoxMovement && hasCommandModifier(e) ? 'move-selection-to-start-of-block' : null;
  13748. case Keys.RIGHT:
  13749. return shouldFixFirefoxMovement && hasCommandModifier(e) ? 'move-selection-to-end-of-block' : null;
  13750. default:
  13751. return null;
  13752. }
  13753. }
  13754. var getDefaultKeyBinding_1 = getDefaultKeyBinding;
  13755. 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; };
  13756. function _classCallCheck$g(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13757. 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; }
  13758. 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; }
  13759. var isIE = UserAgent_1.isBrowser('IE');
  13760. // IE does not support the `input` event on contentEditable, so we can't
  13761. // observe spellcheck behavior.
  13762. var allowSpellCheck = !isIE;
  13763. // Define a set of handler objects to correspond to each possible `mode`
  13764. // of editor behavior.
  13765. var handlerMap = {
  13766. edit: DraftEditorEditHandler_1,
  13767. composite: DraftEditorCompositionHandler_1,
  13768. drag: DraftEditorDragHandler_1,
  13769. cut: null,
  13770. render: null
  13771. };
  13772. /**
  13773. * `DraftEditor` is the root editor component. It composes a `contentEditable`
  13774. * div, and provides a wide variety of useful function props for managing the
  13775. * state of the editor. See `DraftEditorProps` for details.
  13776. */
  13777. var DraftEditor = function (_React$Component) {
  13778. _inherits$b(DraftEditor, _React$Component);
  13779. function DraftEditor(props) {
  13780. _classCallCheck$g(this, DraftEditor);
  13781. var _this = _possibleConstructorReturn$b(this, _React$Component.call(this, props));
  13782. _this.focus = function (scrollPosition) {
  13783. var editorState = _this.props.editorState;
  13784. var alreadyHasFocus = editorState.getSelection().getHasFocus();
  13785. var editorNode = ReactDOM.findDOMNode(_this.editor);
  13786. if (!editorNode) {
  13787. // once in a while people call 'focus' in a setTimeout, and the node has
  13788. // been deleted, so it can be null in that case.
  13789. return;
  13790. }
  13791. var scrollParent = Style_1.getScrollParent(editorNode);
  13792. var _ref = scrollPosition || getScrollPosition_1(scrollParent),
  13793. x = _ref.x,
  13794. y = _ref.y;
  13795. !(editorNode instanceof HTMLElement) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'editorNode is not an HTMLElement') : invariant_1(false) : void 0;
  13796. editorNode.focus();
  13797. // Restore scroll position
  13798. if (scrollParent === window) {
  13799. window.scrollTo(x, y);
  13800. } else {
  13801. Scroll_1.setTop(scrollParent, y);
  13802. }
  13803. // On Chrome and Safari, calling focus on contenteditable focuses the
  13804. // cursor at the first character. This is something you don't expect when
  13805. // you're clicking on an input element but not directly on a character.
  13806. // Put the cursor back where it was before the blur.
  13807. if (!alreadyHasFocus) {
  13808. _this.update(EditorState_1.forceSelection(editorState, editorState.getSelection()));
  13809. }
  13810. };
  13811. _this.blur = function () {
  13812. var editorNode = ReactDOM.findDOMNode(_this.editor);
  13813. !(editorNode instanceof HTMLElement) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'editorNode is not an HTMLElement') : invariant_1(false) : void 0;
  13814. editorNode.blur();
  13815. };
  13816. _this.setMode = function (mode) {
  13817. _this._handler = handlerMap[mode];
  13818. };
  13819. _this.exitCurrentMode = function () {
  13820. _this.setMode('edit');
  13821. };
  13822. _this.restoreEditorDOM = function (scrollPosition) {
  13823. _this.setState({ contentsKey: _this.state.contentsKey + 1 }, function () {
  13824. _this.focus(scrollPosition);
  13825. });
  13826. };
  13827. _this.setClipboard = function (clipboard) {
  13828. _this._clipboard = clipboard;
  13829. };
  13830. _this.getClipboard = function () {
  13831. return _this._clipboard;
  13832. };
  13833. _this.update = function (editorState) {
  13834. _this._latestEditorState = editorState;
  13835. _this.props.onChange(editorState);
  13836. };
  13837. _this.onDragEnter = function () {
  13838. _this._dragCount++;
  13839. };
  13840. _this.onDragLeave = function () {
  13841. _this._dragCount--;
  13842. if (_this._dragCount === 0) {
  13843. _this.exitCurrentMode();
  13844. }
  13845. };
  13846. _this._blockSelectEvents = false;
  13847. _this._clipboard = null;
  13848. _this._handler = null;
  13849. _this._dragCount = 0;
  13850. _this._editorKey = props.editorKey || generateRandomKey_1();
  13851. _this._placeholderAccessibilityID = 'placeholder-' + _this._editorKey;
  13852. _this._latestEditorState = props.editorState;
  13853. _this._latestCommittedEditorState = props.editorState;
  13854. _this._onBeforeInput = _this._buildHandler('onBeforeInput');
  13855. _this._onBlur = _this._buildHandler('onBlur');
  13856. _this._onCharacterData = _this._buildHandler('onCharacterData');
  13857. _this._onCompositionEnd = _this._buildHandler('onCompositionEnd');
  13858. _this._onCompositionStart = _this._buildHandler('onCompositionStart');
  13859. _this._onCopy = _this._buildHandler('onCopy');
  13860. _this._onCut = _this._buildHandler('onCut');
  13861. _this._onDragEnd = _this._buildHandler('onDragEnd');
  13862. _this._onDragOver = _this._buildHandler('onDragOver');
  13863. _this._onDragStart = _this._buildHandler('onDragStart');
  13864. _this._onDrop = _this._buildHandler('onDrop');
  13865. _this._onInput = _this._buildHandler('onInput');
  13866. _this._onFocus = _this._buildHandler('onFocus');
  13867. _this._onKeyDown = _this._buildHandler('onKeyDown');
  13868. _this._onKeyPress = _this._buildHandler('onKeyPress');
  13869. _this._onKeyUp = _this._buildHandler('onKeyUp');
  13870. _this._onMouseDown = _this._buildHandler('onMouseDown');
  13871. _this._onMouseUp = _this._buildHandler('onMouseUp');
  13872. _this._onPaste = _this._buildHandler('onPaste');
  13873. _this._onSelect = _this._buildHandler('onSelect');
  13874. _this.getEditorKey = function () {
  13875. return _this._editorKey;
  13876. };
  13877. // See `restoreEditorDOM()`.
  13878. _this.state = { contentsKey: 0 };
  13879. return _this;
  13880. }
  13881. /**
  13882. * Build a method that will pass the event to the specified handler method.
  13883. * This allows us to look up the correct handler function for the current
  13884. * editor mode, if any has been specified.
  13885. */
  13886. /**
  13887. * Define proxies that can route events to the current handler.
  13888. */
  13889. DraftEditor.prototype._buildHandler = function _buildHandler(eventName) {
  13890. var _this2 = this;
  13891. return function (e) {
  13892. if (!_this2.props.readOnly) {
  13893. var method = _this2._handler && _this2._handler[eventName];
  13894. method && method(_this2, e);
  13895. }
  13896. };
  13897. };
  13898. DraftEditor.prototype._showPlaceholder = function _showPlaceholder() {
  13899. return !!this.props.placeholder && !this.props.editorState.isInCompositionMode() && !this.props.editorState.getCurrentContent().hasText();
  13900. };
  13901. DraftEditor.prototype._renderPlaceholder = function _renderPlaceholder() {
  13902. if (this._showPlaceholder()) {
  13903. var placeHolderProps = {
  13904. text: nullthrows_1(this.props.placeholder),
  13905. editorState: this.props.editorState,
  13906. textAlignment: this.props.textAlignment,
  13907. accessibilityID: this._placeholderAccessibilityID
  13908. };
  13909. return React.createElement(DraftEditorPlaceholder_react, placeHolderProps);
  13910. }
  13911. return null;
  13912. };
  13913. DraftEditor.prototype.render = function render() {
  13914. var _this3 = this;
  13915. var _props = this.props,
  13916. blockRenderMap = _props.blockRenderMap,
  13917. blockRendererFn = _props.blockRendererFn,
  13918. blockStyleFn = _props.blockStyleFn,
  13919. customStyleFn = _props.customStyleFn,
  13920. customStyleMap = _props.customStyleMap,
  13921. editorState = _props.editorState,
  13922. readOnly = _props.readOnly,
  13923. textAlignment = _props.textAlignment,
  13924. textDirectionality = _props.textDirectionality;
  13925. var rootClass = cx_1({
  13926. 'DraftEditor/root': true,
  13927. 'DraftEditor/alignLeft': textAlignment === 'left',
  13928. 'DraftEditor/alignRight': textAlignment === 'right',
  13929. 'DraftEditor/alignCenter': textAlignment === 'center'
  13930. });
  13931. var contentStyle = {
  13932. outline: 'none',
  13933. // fix parent-draggable Safari bug. #1326
  13934. userSelect: 'text',
  13935. WebkitUserSelect: 'text',
  13936. whiteSpace: 'pre-wrap',
  13937. wordWrap: 'break-word'
  13938. };
  13939. // The aria-expanded and aria-haspopup properties should only be rendered
  13940. // for a combobox.
  13941. var ariaRole = this.props.role || 'textbox';
  13942. var ariaExpanded = ariaRole === 'combobox' ? !!this.props.ariaExpanded : null;
  13943. var editorContentsProps = {
  13944. blockRenderMap: blockRenderMap,
  13945. blockRendererFn: blockRendererFn,
  13946. blockStyleFn: blockStyleFn,
  13947. customStyleMap: _extends$5({}, DefaultDraftInlineStyle, customStyleMap),
  13948. customStyleFn: customStyleFn,
  13949. editorKey: this._editorKey,
  13950. editorState: editorState,
  13951. key: 'contents' + this.state.contentsKey,
  13952. textDirectionality: textDirectionality
  13953. };
  13954. return React.createElement(
  13955. 'div',
  13956. { className: rootClass },
  13957. this._renderPlaceholder(),
  13958. React.createElement(
  13959. 'div',
  13960. {
  13961. className: cx_1('DraftEditor/editorContainer'),
  13962. ref: function ref(_ref3) {
  13963. return _this3.editorContainer = _ref3;
  13964. } },
  13965. React.createElement(
  13966. 'div',
  13967. {
  13968. 'aria-activedescendant': readOnly ? null : this.props.ariaActiveDescendantID,
  13969. 'aria-autocomplete': readOnly ? null : this.props.ariaAutoComplete,
  13970. 'aria-controls': readOnly ? null : this.props.ariaControls,
  13971. 'aria-describedby': this.props.ariaDescribedBy || this._placeholderAccessibilityID,
  13972. 'aria-expanded': readOnly ? null : ariaExpanded,
  13973. 'aria-label': this.props.ariaLabel,
  13974. 'aria-labelledby': this.props.ariaLabelledBy,
  13975. 'aria-multiline': this.props.ariaMultiline,
  13976. autoCapitalize: this.props.autoCapitalize,
  13977. autoComplete: this.props.autoComplete,
  13978. autoCorrect: this.props.autoCorrect,
  13979. className: cx_1({
  13980. // Chrome's built-in translation feature mutates the DOM in ways
  13981. // that Draft doesn't expect (ex: adding <font> tags inside
  13982. // DraftEditorLeaf spans) and causes problems. We add notranslate
  13983. // here which makes its autotranslation skip over this subtree.
  13984. notranslate: !readOnly,
  13985. 'public/DraftEditor/content': true
  13986. }),
  13987. contentEditable: !readOnly,
  13988. 'data-testid': this.props.webDriverTestID,
  13989. onBeforeInput: this._onBeforeInput,
  13990. onBlur: this._onBlur,
  13991. onCompositionEnd: this._onCompositionEnd,
  13992. onCompositionStart: this._onCompositionStart,
  13993. onCopy: this._onCopy,
  13994. onCut: this._onCut,
  13995. onDragEnd: this._onDragEnd,
  13996. onDragEnter: this.onDragEnter,
  13997. onDragLeave: this.onDragLeave,
  13998. onDragOver: this._onDragOver,
  13999. onDragStart: this._onDragStart,
  14000. onDrop: this._onDrop,
  14001. onFocus: this._onFocus,
  14002. onInput: this._onInput,
  14003. onKeyDown: this._onKeyDown,
  14004. onKeyPress: this._onKeyPress,
  14005. onKeyUp: this._onKeyUp,
  14006. onMouseUp: this._onMouseUp,
  14007. onPaste: this._onPaste,
  14008. onSelect: this._onSelect,
  14009. ref: function ref(_ref2) {
  14010. return _this3.editor = _ref2;
  14011. },
  14012. role: readOnly ? null : ariaRole,
  14013. spellCheck: allowSpellCheck && this.props.spellCheck,
  14014. style: contentStyle,
  14015. suppressContentEditableWarning: true,
  14016. tabIndex: this.props.tabIndex },
  14017. React.createElement(DraftEditorContents_react, editorContentsProps)
  14018. )
  14019. )
  14020. );
  14021. };
  14022. DraftEditor.prototype.componentDidMount = function componentDidMount() {
  14023. this.setMode('edit');
  14024. /**
  14025. * IE has a hardcoded "feature" that attempts to convert link text into
  14026. * anchors in contentEditable DOM. This breaks the editor's expectations of
  14027. * the DOM, and control is lost. Disable it to make IE behave.
  14028. * See: http://blogs.msdn.com/b/ieinternals/archive/2010/09/15/
  14029. * ie9-beta-minor-change-list.aspx
  14030. */
  14031. if (isIE) {
  14032. document.execCommand('AutoUrlDetect', false, false);
  14033. }
  14034. };
  14035. /**
  14036. * Prevent selection events from affecting the current editor state. This
  14037. * is mostly intended to defend against IE, which fires off `selectionchange`
  14038. * events regardless of whether the selection is set via the browser or
  14039. * programmatically. We only care about selection events that occur because
  14040. * of browser interaction, not re-renders and forced selections.
  14041. */
  14042. DraftEditor.prototype.componentWillUpdate = function componentWillUpdate(nextProps) {
  14043. this._blockSelectEvents = true;
  14044. this._latestEditorState = nextProps.editorState;
  14045. };
  14046. DraftEditor.prototype.componentDidUpdate = function componentDidUpdate() {
  14047. this._blockSelectEvents = false;
  14048. this._latestCommittedEditorState = this.props.editorState;
  14049. };
  14050. /**
  14051. * Used via `this.focus()`.
  14052. *
  14053. * Force focus back onto the editor node.
  14054. *
  14055. * We attempt to preserve scroll position when focusing. You can also pass
  14056. * a specified scroll position (for cases like `cut` behavior where it should
  14057. * be restored to a known position).
  14058. */
  14059. /**
  14060. * Used via `this.setMode(...)`.
  14061. *
  14062. * Set the behavior mode for the editor component. This switches the current
  14063. * handler module to ensure that DOM events are managed appropriately for
  14064. * the active mode.
  14065. */
  14066. /**
  14067. * Used via `this.restoreEditorDOM()`.
  14068. *
  14069. * Force a complete re-render of the DraftEditorContents based on the current
  14070. * EditorState. This is useful when we know we are going to lose control of
  14071. * the DOM state (cut command, IME) and we want to make sure that
  14072. * reconciliation occurs on a version of the DOM that is synchronized with
  14073. * our EditorState.
  14074. */
  14075. /**
  14076. * Used via `this.setClipboard(...)`.
  14077. *
  14078. * Set the clipboard state for a cut/copy event.
  14079. */
  14080. /**
  14081. * Used via `this.getClipboard()`.
  14082. *
  14083. * Retrieve the clipboard state for a cut/copy event.
  14084. */
  14085. /**
  14086. * Used via `this.update(...)`.
  14087. *
  14088. * Propagate a new `EditorState` object to higher-level components. This is
  14089. * the method by which event handlers inform the `DraftEditor` component of
  14090. * state changes. A component that composes a `DraftEditor` **must** provide
  14091. * an `onChange` prop to receive state updates passed along from this
  14092. * function.
  14093. */
  14094. /**
  14095. * Used in conjunction with `onDragLeave()`, by counting the number of times
  14096. * a dragged element enters and leaves the editor (or any of its children),
  14097. * to determine when the dragged element absolutely leaves the editor.
  14098. */
  14099. /**
  14100. * See `onDragEnter()`.
  14101. */
  14102. return DraftEditor;
  14103. }(React.Component);
  14104. DraftEditor.defaultProps = {
  14105. blockRenderMap: DefaultDraftBlockRenderMap_1,
  14106. blockRendererFn: emptyFunction_1.thatReturnsNull,
  14107. blockStyleFn: emptyFunction_1.thatReturns(''),
  14108. keyBindingFn: getDefaultKeyBinding_1,
  14109. readOnly: false,
  14110. spellCheck: false,
  14111. stripPastedStyles: false
  14112. };
  14113. var DraftEditor_react = DraftEditor;
  14114. /**
  14115. * Copyright (c) 2013-present, Facebook, Inc.
  14116. * All rights reserved.
  14117. *
  14118. * This source code is licensed under the BSD-style license found in the
  14119. * LICENSE file in the root directory of this source tree. An additional grant
  14120. * of patent rights can be found in the PATENTS file in the same directory.
  14121. *
  14122. * @providesModule DraftStringKey
  14123. * @format
  14124. *
  14125. */
  14126. var DraftStringKey = {
  14127. stringify: function stringify(key) {
  14128. return '_' + String(key);
  14129. },
  14130. unstringify: function unstringify(key) {
  14131. return key.slice(1);
  14132. }
  14133. };
  14134. var DraftStringKey_1 = DraftStringKey;
  14135. var strlen$1 = UnicodeUtils_1.strlen;
  14136. /**
  14137. * Convert to UTF-8 character counts for storage.
  14138. */
  14139. function encodeEntityRanges(block, storageMap) {
  14140. var encoded = [];
  14141. block.findEntityRanges(function (character) {
  14142. return !!character.getEntity();
  14143. }, function ( /*number*/start, /*number*/end) {
  14144. var text = block.getText();
  14145. var key = block.getEntityAt(start);
  14146. encoded.push({
  14147. offset: strlen$1(text.slice(0, start)),
  14148. length: strlen$1(text.slice(start, end)),
  14149. // Encode the key as a number for range storage.
  14150. key: Number(storageMap[DraftStringKey_1.stringify(key)])
  14151. });
  14152. });
  14153. return encoded;
  14154. }
  14155. var encodeEntityRanges_1 = encodeEntityRanges;
  14156. var areEqual$1 = function areEqual(a, b) {
  14157. return a === b;
  14158. };
  14159. var isTruthy = function isTruthy(a) {
  14160. return !!a;
  14161. };
  14162. var EMPTY_ARRAY = [];
  14163. /**
  14164. * Helper function for getting encoded styles for each inline style. Convert
  14165. * to UTF-8 character counts for storage.
  14166. */
  14167. function getEncodedInlinesForType(block, styleList, styleToEncode) {
  14168. var ranges = [];
  14169. // Obtain an array with ranges for only the specified style.
  14170. var filteredInlines = styleList.map(function (style) {
  14171. return style.has(styleToEncode);
  14172. }).toList();
  14173. findRangesImmutable_1(filteredInlines, areEqual$1,
  14174. // We only want to keep ranges with nonzero style values.
  14175. isTruthy, function (start, end) {
  14176. var text = block.getText();
  14177. ranges.push({
  14178. offset: UnicodeUtils_1.strlen(text.slice(0, start)),
  14179. length: UnicodeUtils_1.strlen(text.slice(start, end)),
  14180. style: styleToEncode
  14181. });
  14182. });
  14183. return ranges;
  14184. }
  14185. /*
  14186. * Retrieve the encoded arrays of inline styles, with each individual style
  14187. * treated separately.
  14188. */
  14189. function encodeInlineStyleRanges(block) {
  14190. var styleList = block.getCharacterList().map(function (c) {
  14191. return c.getStyle();
  14192. }).toList();
  14193. var ranges = styleList.flatten().toSet().map(function (style) {
  14194. return getEncodedInlinesForType(block, styleList, style);
  14195. });
  14196. return Array.prototype.concat.apply(EMPTY_ARRAY, ranges.toJS());
  14197. }
  14198. var encodeInlineStyleRanges_1 = encodeInlineStyleRanges;
  14199. 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; };
  14200. var createRawBlock = function createRawBlock(block, entityStorageMap) {
  14201. return {
  14202. key: block.getKey(),
  14203. text: block.getText(),
  14204. type: block.getType(),
  14205. depth: block.getDepth(),
  14206. inlineStyleRanges: encodeInlineStyleRanges_1(block),
  14207. entityRanges: encodeEntityRanges_1(block, entityStorageMap),
  14208. data: block.getData().toObject()
  14209. };
  14210. };
  14211. var insertRawBlock = function insertRawBlock(block, entityMap, rawBlocks, blockCacheRef) {
  14212. if (block instanceof ContentBlock_1) {
  14213. rawBlocks.push(createRawBlock(block, entityMap));
  14214. return;
  14215. }
  14216. !(block instanceof ContentBlockNode_1) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'block is not a BlockNode') : invariant_1(false) : void 0;
  14217. var parentKey = block.getParentKey();
  14218. var rawBlock = blockCacheRef[block.getKey()] = _extends$6({}, createRawBlock(block, entityMap), {
  14219. children: []
  14220. });
  14221. if (parentKey) {
  14222. blockCacheRef[parentKey].children.push(rawBlock);
  14223. return;
  14224. }
  14225. rawBlocks.push(rawBlock);
  14226. };
  14227. var encodeRawBlocks = function encodeRawBlocks(contentState, rawState) {
  14228. var entityMap = rawState.entityMap;
  14229. var rawBlocks = [];
  14230. var blockCacheRef = {};
  14231. var entityCacheRef = {};
  14232. var entityStorageKey = 0;
  14233. contentState.getBlockMap().forEach(function (block) {
  14234. block.findEntityRanges(function (character) {
  14235. return character.getEntity() !== null;
  14236. }, function (start) {
  14237. var entityKey = block.getEntityAt(start);
  14238. // Stringify to maintain order of otherwise numeric keys.
  14239. var stringifiedEntityKey = DraftStringKey_1.stringify(entityKey);
  14240. // This makes this function resilient to two entities
  14241. // erroneously having the same key
  14242. if (entityCacheRef[stringifiedEntityKey]) {
  14243. return;
  14244. }
  14245. entityCacheRef[stringifiedEntityKey] = entityKey;
  14246. // we need the `any` casting here since this is a temporary state
  14247. // where we will later on flip the entity map and populate it with
  14248. // real entity, at this stage we just need to map back the entity
  14249. // key used by the BlockNode
  14250. entityMap[stringifiedEntityKey] = '' + entityStorageKey;
  14251. entityStorageKey++;
  14252. });
  14253. insertRawBlock(block, entityMap, rawBlocks, blockCacheRef);
  14254. });
  14255. return {
  14256. blocks: rawBlocks,
  14257. entityMap: entityMap
  14258. };
  14259. };
  14260. // Flip storage map so that our storage keys map to global
  14261. // DraftEntity keys.
  14262. var encodeRawEntityMap = function encodeRawEntityMap(contentState, rawState) {
  14263. var blocks = rawState.blocks,
  14264. entityMap = rawState.entityMap;
  14265. var rawEntityMap = {};
  14266. Object.keys(entityMap).forEach(function (key, index) {
  14267. var entity = contentState.getEntity(DraftStringKey_1.unstringify(key));
  14268. rawEntityMap[index] = {
  14269. type: entity.getType(),
  14270. mutability: entity.getMutability(),
  14271. data: entity.getData()
  14272. };
  14273. });
  14274. return {
  14275. blocks: blocks,
  14276. entityMap: rawEntityMap
  14277. };
  14278. };
  14279. var convertFromDraftStateToRaw = function convertFromDraftStateToRaw(contentState) {
  14280. var rawDraftContentState = {
  14281. entityMap: {},
  14282. blocks: []
  14283. };
  14284. // add blocks
  14285. rawDraftContentState = encodeRawBlocks(contentState, rawDraftContentState);
  14286. // add entities
  14287. rawDraftContentState = encodeRawEntityMap(contentState, rawDraftContentState);
  14288. return rawDraftContentState;
  14289. };
  14290. var convertFromDraftStateToRaw_1 = convertFromDraftStateToRaw;
  14291. 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; };
  14292. /**
  14293. * Copyright (c) 2013-present, Facebook, Inc.
  14294. * All rights reserved.
  14295. *
  14296. * This source code is licensed under the BSD-style license found in the
  14297. * LICENSE file in the root directory of this source tree. An additional grant
  14298. * of patent rights can be found in the PATENTS file in the same directory.
  14299. *
  14300. * @providesModule DraftTreeAdapter
  14301. * @format
  14302. *
  14303. *
  14304. * This is unstable and not part of the public API and should not be used by
  14305. * production systems. This file may be update/removed without notice.
  14306. */
  14307. var traverseInDepthOrder = function traverseInDepthOrder(blocks, fn) {
  14308. var stack = [].concat(blocks).reverse();
  14309. while (stack.length) {
  14310. var _block = stack.pop();
  14311. fn(_block);
  14312. var children = _block.children;
  14313. !Array.isArray(children) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Invalid tree raw block') : invariant_1(false) : void 0;
  14314. stack = stack.concat([].concat(children.reverse()));
  14315. }
  14316. };
  14317. var isListBlock = function isListBlock(block) {
  14318. if (!(block && block.type)) {
  14319. return false;
  14320. }
  14321. var type = block.type;
  14322. return type === 'unordered-list-item' || type === 'ordered-list-item';
  14323. };
  14324. var addDepthToChildren = function addDepthToChildren(block) {
  14325. if (Array.isArray(block.children)) {
  14326. block.children = block.children.map(function (child) {
  14327. return child.type === block.type ? _extends$7({}, child, { depth: (block.depth || 0) + 1 }) : child;
  14328. });
  14329. }
  14330. };
  14331. /**
  14332. * This adapter is intended to be be used as an adapter to draft tree data
  14333. *
  14334. * draft state <=====> draft tree state
  14335. */
  14336. var DraftTreeAdapter = {
  14337. /**
  14338. * Converts from a tree raw state back to draft raw state
  14339. */
  14340. fromRawTreeStateToRawState: function fromRawTreeStateToRawState(draftTreeState) {
  14341. var blocks = draftTreeState.blocks;
  14342. var transformedBlocks = [];
  14343. !Array.isArray(blocks) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Invalid raw state') : invariant_1(false) : void 0;
  14344. if (!Array.isArray(blocks) || !blocks.length) {
  14345. return draftTreeState;
  14346. }
  14347. traverseInDepthOrder(blocks, function (block) {
  14348. var newBlock = _extends$7({}, block);
  14349. if (isListBlock(block)) {
  14350. newBlock.depth = newBlock.depth || 0;
  14351. addDepthToChildren(block);
  14352. }
  14353. delete newBlock.children;
  14354. transformedBlocks.push(newBlock);
  14355. });
  14356. draftTreeState.blocks = transformedBlocks;
  14357. return _extends$7({}, draftTreeState, {
  14358. blocks: transformedBlocks
  14359. });
  14360. },
  14361. /**
  14362. * Converts from draft raw state to tree draft state
  14363. */
  14364. fromRawStateToRawTreeState: function fromRawStateToRawTreeState(draftState) {
  14365. var lastListDepthCacheRef = {};
  14366. var transformedBlocks = [];
  14367. draftState.blocks.forEach(function (block) {
  14368. var isList = isListBlock(block);
  14369. var depth = block.depth || 0;
  14370. var treeBlock = _extends$7({}, block, {
  14371. children: []
  14372. });
  14373. if (!isList) {
  14374. // reset the cache path
  14375. lastListDepthCacheRef = {};
  14376. transformedBlocks.push(treeBlock);
  14377. return;
  14378. }
  14379. // update our depth cache reference path
  14380. lastListDepthCacheRef[depth] = treeBlock;
  14381. // if we are greater than zero we must have seen a parent already
  14382. if (depth > 0) {
  14383. var parent = lastListDepthCacheRef[depth - 1];
  14384. !parent ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Invalid depth for RawDraftContentBlock') : invariant_1(false) : void 0;
  14385. // push nested list blocks
  14386. parent.children.push(treeBlock);
  14387. return;
  14388. }
  14389. // push root list blocks
  14390. transformedBlocks.push(treeBlock);
  14391. });
  14392. return _extends$7({}, draftState, {
  14393. blocks: transformedBlocks
  14394. });
  14395. }
  14396. };
  14397. var DraftTreeAdapter_1 = DraftTreeAdapter;
  14398. var List$c = immutable.List;
  14399. function createCharacterList(inlineStyles, entities) {
  14400. var characterArray = inlineStyles.map(function (style, ii) {
  14401. var entity = entities[ii];
  14402. return CharacterMetadata_1.create({ style: style, entity: entity });
  14403. });
  14404. return List$c(characterArray);
  14405. }
  14406. var createCharacterList_1 = createCharacterList;
  14407. var substr$1 = UnicodeUtils_1.substr;
  14408. /**
  14409. * Convert to native JavaScript string lengths to determine ranges.
  14410. */
  14411. function decodeEntityRanges(text, ranges) {
  14412. var entities = Array(text.length).fill(null);
  14413. if (ranges) {
  14414. ranges.forEach(function (range) {
  14415. // Using Unicode-enabled substrings converted to JavaScript lengths,
  14416. // fill the output array with entity keys.
  14417. var start = substr$1(text, 0, range.offset).length;
  14418. var end = start + substr$1(text, range.offset, range.length).length;
  14419. for (var ii = start; ii < end; ii++) {
  14420. entities[ii] = range.key;
  14421. }
  14422. });
  14423. }
  14424. return entities;
  14425. }
  14426. var decodeEntityRanges_1 = decodeEntityRanges;
  14427. var OrderedSet$6 = immutable.OrderedSet;
  14428. var substr$2 = UnicodeUtils_1.substr;
  14429. var EMPTY_SET$3 = OrderedSet$6();
  14430. /**
  14431. * Convert to native JavaScript string lengths to determine ranges.
  14432. */
  14433. function decodeInlineStyleRanges(text, ranges) {
  14434. var styles = Array(text.length).fill(EMPTY_SET$3);
  14435. if (ranges) {
  14436. ranges.forEach(function ( /*object*/range) {
  14437. var cursor = substr$2(text, 0, range.offset).length;
  14438. var end = cursor + substr$2(text, range.offset, range.length).length;
  14439. while (cursor < end) {
  14440. styles[cursor] = styles[cursor].add(range.style);
  14441. cursor++;
  14442. }
  14443. });
  14444. }
  14445. return styles;
  14446. }
  14447. var decodeInlineStyleRanges_1 = decodeInlineStyleRanges;
  14448. 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; };
  14449. var List$d = immutable.List,
  14450. Map$9 = immutable.Map,
  14451. OrderedMap$4 = immutable.OrderedMap;
  14452. var decodeBlockNodeConfig = function decodeBlockNodeConfig(block, entityMap) {
  14453. var key = block.key,
  14454. type = block.type,
  14455. data = block.data,
  14456. text = block.text,
  14457. depth = block.depth;
  14458. var blockNodeConfig = {
  14459. text: text,
  14460. depth: depth || 0,
  14461. type: type || 'unstyled',
  14462. key: key || generateRandomKey_1(),
  14463. data: Map$9(data),
  14464. characterList: decodeCharacterList(block, entityMap)
  14465. };
  14466. return blockNodeConfig;
  14467. };
  14468. var decodeCharacterList = function decodeCharacterList(block, entityMap) {
  14469. var text = block.text,
  14470. rawEntityRanges = block.entityRanges,
  14471. rawInlineStyleRanges = block.inlineStyleRanges;
  14472. var entityRanges = rawEntityRanges || [];
  14473. var inlineStyleRanges = rawInlineStyleRanges || [];
  14474. // Translate entity range keys to the DraftEntity map.
  14475. return createCharacterList_1(decodeInlineStyleRanges_1(text, inlineStyleRanges), decodeEntityRanges_1(text, entityRanges.filter(function (range) {
  14476. return entityMap.hasOwnProperty(range.key);
  14477. }).map(function (range) {
  14478. return _extends$8({}, range, { key: entityMap[range.key] });
  14479. })));
  14480. };
  14481. var decodeContentBlocks = function decodeContentBlocks(blocks, entityMap) {
  14482. return OrderedMap$4(blocks.map(function (block) {
  14483. var contentBlock = new ContentBlock_1(decodeBlockNodeConfig(block, entityMap));
  14484. return [contentBlock.getKey(), contentBlock];
  14485. }));
  14486. };
  14487. var decodeRawBlocks = function decodeRawBlocks(rawState, entityMap) {
  14488. var isTreeRawBlock = Array.isArray(rawState.blocks[0].children);
  14489. var rawBlocks = rawState.blocks;
  14490. {
  14491. return decodeContentBlocks(isTreeRawBlock ? DraftTreeAdapter_1.fromRawTreeStateToRawState(rawState).blocks : rawBlocks, entityMap);
  14492. }
  14493. };
  14494. var decodeRawEntityMap = function decodeRawEntityMap(rawState) {
  14495. var rawEntityMap = rawState.entityMap;
  14496. var entityMap = {};
  14497. // TODO: Update this once we completely remove DraftEntity
  14498. Object.keys(rawEntityMap).forEach(function (rawEntityKey) {
  14499. var _rawEntityMap$rawEnti = rawEntityMap[rawEntityKey],
  14500. type = _rawEntityMap$rawEnti.type,
  14501. mutability = _rawEntityMap$rawEnti.mutability,
  14502. data = _rawEntityMap$rawEnti.data;
  14503. // get the key reference to created entity
  14504. entityMap[rawEntityKey] = DraftEntity_1.__create(type, mutability, data || {});
  14505. });
  14506. return entityMap;
  14507. };
  14508. var convertFromRawToDraftState = function convertFromRawToDraftState(rawState) {
  14509. !Array.isArray(rawState.blocks) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'invalid RawDraftContentState') : invariant_1(false) : void 0;
  14510. // decode entities
  14511. var entityMap = decodeRawEntityMap(rawState);
  14512. // decode blockMap
  14513. var blockMap = decodeRawBlocks(rawState, entityMap);
  14514. // create initial selection
  14515. var selectionState = blockMap.isEmpty() ? new SelectionState_1() : SelectionState_1.createEmpty(blockMap.first().getKey());
  14516. return new ContentState_1({
  14517. blockMap: blockMap,
  14518. entityMap: entityMap,
  14519. selectionBefore: selectionState,
  14520. selectionAfter: selectionState
  14521. });
  14522. };
  14523. var convertFromRawToDraftState_1 = convertFromRawToDraftState;
  14524. /**
  14525. * Like range.getBoundingClientRect() but normalizes for browser bugs.
  14526. */
  14527. function getRangeBoundingClientRect(range) {
  14528. // "Return a DOMRect object describing the smallest rectangle that includes
  14529. // the first rectangle in list and all of the remaining rectangles of which
  14530. // the height or width is not zero."
  14531. // http://www.w3.org/TR/cssom-view/#dom-range-getboundingclientrect
  14532. var rects = getRangeClientRects_1(range);
  14533. var top = 0;
  14534. var right = 0;
  14535. var bottom = 0;
  14536. var left = 0;
  14537. if (rects.length) {
  14538. // If the first rectangle has 0 width, we use the second, this is needed
  14539. // because Chrome renders a 0 width rectangle when the selection contains
  14540. // a line break.
  14541. if (rects.length > 1 && rects[0].width === 0) {
  14542. var _rects$ = rects[1];
  14543. top = _rects$.top;
  14544. right = _rects$.right;
  14545. bottom = _rects$.bottom;
  14546. left = _rects$.left;
  14547. } else {
  14548. var _rects$2 = rects[0];
  14549. top = _rects$2.top;
  14550. right = _rects$2.right;
  14551. bottom = _rects$2.bottom;
  14552. left = _rects$2.left;
  14553. }
  14554. for (var ii = 1; ii < rects.length; ii++) {
  14555. var rect = rects[ii];
  14556. if (rect.height !== 0 && rect.width !== 0) {
  14557. top = Math.min(top, rect.top);
  14558. right = Math.max(right, rect.right);
  14559. bottom = Math.max(bottom, rect.bottom);
  14560. left = Math.min(left, rect.left);
  14561. }
  14562. }
  14563. }
  14564. return {
  14565. top: top,
  14566. right: right,
  14567. bottom: bottom,
  14568. left: left,
  14569. width: right - left,
  14570. height: bottom - top
  14571. };
  14572. }
  14573. var getRangeBoundingClientRect_1 = getRangeBoundingClientRect;
  14574. /**
  14575. * Return the bounding ClientRect for the visible DOM selection, if any.
  14576. * In cases where there are no selected ranges or the bounding rect is
  14577. * temporarily invalid, return null.
  14578. */
  14579. function getVisibleSelectionRect(global) {
  14580. var selection = global.getSelection();
  14581. if (!selection.rangeCount) {
  14582. return null;
  14583. }
  14584. var range = selection.getRangeAt(0);
  14585. var boundingRect = getRangeBoundingClientRect_1(range);
  14586. var top = boundingRect.top,
  14587. right = boundingRect.right,
  14588. bottom = boundingRect.bottom,
  14589. left = boundingRect.left;
  14590. // When a re-render leads to a node being removed, the DOM selection will
  14591. // temporarily be placed on an ancestor node, which leads to an invalid
  14592. // bounding rect. Discard this state.
  14593. if (top === 0 && right === 0 && bottom === 0 && left === 0) {
  14594. return null;
  14595. }
  14596. return boundingRect;
  14597. }
  14598. var getVisibleSelectionRect_1 = getVisibleSelectionRect;
  14599. var DraftPublic = {
  14600. Editor: DraftEditor_react,
  14601. EditorBlock: DraftEditorBlock_react,
  14602. EditorState: EditorState_1,
  14603. CompositeDecorator: CompositeDraftDecorator_1,
  14604. Entity: DraftEntity_1,
  14605. EntityInstance: DraftEntityInstance_1,
  14606. BlockMapBuilder: BlockMapBuilder_1,
  14607. CharacterMetadata: CharacterMetadata_1,
  14608. ContentBlock: ContentBlock_1,
  14609. ContentState: ContentState_1,
  14610. SelectionState: SelectionState_1,
  14611. AtomicBlockUtils: AtomicBlockUtils_1,
  14612. KeyBindingUtil: KeyBindingUtil_1,
  14613. Modifier: DraftModifier_1,
  14614. RichUtils: RichTextEditorUtil_1,
  14615. DefaultDraftBlockRenderMap: DefaultDraftBlockRenderMap_1,
  14616. DefaultDraftInlineStyle: DefaultDraftInlineStyle,
  14617. convertFromHTML: convertFromHTMLToContentBlocks,
  14618. convertFromRaw: convertFromRawToDraftState_1,
  14619. convertToRaw: convertFromDraftStateToRaw_1,
  14620. genKey: generateRandomKey_1,
  14621. getDefaultKeyBinding: getDefaultKeyBinding_1,
  14622. getVisibleSelectionRect: getVisibleSelectionRect_1
  14623. };
  14624. var Draft = DraftPublic;
  14625. var immutable$1 = createCommonjsModule(function (module, exports) {
  14626. /**
  14627. * Copyright (c) 2014-2015, Facebook, Inc.
  14628. * All rights reserved.
  14629. *
  14630. * This source code is licensed under the BSD-style license found in the
  14631. * LICENSE file in the root directory of this source tree. An additional grant
  14632. * of patent rights can be found in the PATENTS file in the same directory.
  14633. */
  14634. (function (global, factory) {
  14635. module.exports = factory() ;
  14636. }(commonjsGlobal, function () {var SLICE$0 = Array.prototype.slice;
  14637. function createClass(ctor, superClass) {
  14638. if (superClass) {
  14639. ctor.prototype = Object.create(superClass.prototype);
  14640. }
  14641. ctor.prototype.constructor = ctor;
  14642. }
  14643. function Iterable(value) {
  14644. return isIterable(value) ? value : Seq(value);
  14645. }
  14646. createClass(KeyedIterable, Iterable);
  14647. function KeyedIterable(value) {
  14648. return isKeyed(value) ? value : KeyedSeq(value);
  14649. }
  14650. createClass(IndexedIterable, Iterable);
  14651. function IndexedIterable(value) {
  14652. return isIndexed(value) ? value : IndexedSeq(value);
  14653. }
  14654. createClass(SetIterable, Iterable);
  14655. function SetIterable(value) {
  14656. return isIterable(value) && !isAssociative(value) ? value : SetSeq(value);
  14657. }
  14658. function isIterable(maybeIterable) {
  14659. return !!(maybeIterable && maybeIterable[IS_ITERABLE_SENTINEL]);
  14660. }
  14661. function isKeyed(maybeKeyed) {
  14662. return !!(maybeKeyed && maybeKeyed[IS_KEYED_SENTINEL]);
  14663. }
  14664. function isIndexed(maybeIndexed) {
  14665. return !!(maybeIndexed && maybeIndexed[IS_INDEXED_SENTINEL]);
  14666. }
  14667. function isAssociative(maybeAssociative) {
  14668. return isKeyed(maybeAssociative) || isIndexed(maybeAssociative);
  14669. }
  14670. function isOrdered(maybeOrdered) {
  14671. return !!(maybeOrdered && maybeOrdered[IS_ORDERED_SENTINEL]);
  14672. }
  14673. Iterable.isIterable = isIterable;
  14674. Iterable.isKeyed = isKeyed;
  14675. Iterable.isIndexed = isIndexed;
  14676. Iterable.isAssociative = isAssociative;
  14677. Iterable.isOrdered = isOrdered;
  14678. Iterable.Keyed = KeyedIterable;
  14679. Iterable.Indexed = IndexedIterable;
  14680. Iterable.Set = SetIterable;
  14681. var IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
  14682. var IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
  14683. var IS_INDEXED_SENTINEL = '@@__IMMUTABLE_INDEXED__@@';
  14684. var IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
  14685. // Used for setting prototype methods that IE8 chokes on.
  14686. var DELETE = 'delete';
  14687. // Constants describing the size of trie nodes.
  14688. var SHIFT = 5; // Resulted in best performance after ______?
  14689. var SIZE = 1 << SHIFT;
  14690. var MASK = SIZE - 1;
  14691. // A consistent shared value representing "not set" which equals nothing other
  14692. // than itself, and nothing that could be provided externally.
  14693. var NOT_SET = {};
  14694. // Boolean references, Rough equivalent of `bool &`.
  14695. var CHANGE_LENGTH = { value: false };
  14696. var DID_ALTER = { value: false };
  14697. function MakeRef(ref) {
  14698. ref.value = false;
  14699. return ref;
  14700. }
  14701. function SetRef(ref) {
  14702. ref && (ref.value = true);
  14703. }
  14704. // A function which returns a value representing an "owner" for transient writes
  14705. // to tries. The return value will only ever equal itself, and will not equal
  14706. // the return of any subsequent call of this function.
  14707. function OwnerID() {}
  14708. // http://jsperf.com/copy-array-inline
  14709. function arrCopy(arr, offset) {
  14710. offset = offset || 0;
  14711. var len = Math.max(0, arr.length - offset);
  14712. var newArr = new Array(len);
  14713. for (var ii = 0; ii < len; ii++) {
  14714. newArr[ii] = arr[ii + offset];
  14715. }
  14716. return newArr;
  14717. }
  14718. function ensureSize(iter) {
  14719. if (iter.size === undefined) {
  14720. iter.size = iter.__iterate(returnTrue);
  14721. }
  14722. return iter.size;
  14723. }
  14724. function wrapIndex(iter, index) {
  14725. // This implements "is array index" which the ECMAString spec defines as:
  14726. //
  14727. // A String property name P is an array index if and only if
  14728. // ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal
  14729. // to 2^32−1.
  14730. //
  14731. // http://www.ecma-international.org/ecma-262/6.0/#sec-array-exotic-objects
  14732. if (typeof index !== 'number') {
  14733. var uint32Index = index >>> 0; // N >>> 0 is shorthand for ToUint32
  14734. if ('' + uint32Index !== index || uint32Index === 4294967295) {
  14735. return NaN;
  14736. }
  14737. index = uint32Index;
  14738. }
  14739. return index < 0 ? ensureSize(iter) + index : index;
  14740. }
  14741. function returnTrue() {
  14742. return true;
  14743. }
  14744. function wholeSlice(begin, end, size) {
  14745. return (begin === 0 || (size !== undefined && begin <= -size)) &&
  14746. (end === undefined || (size !== undefined && end >= size));
  14747. }
  14748. function resolveBegin(begin, size) {
  14749. return resolveIndex(begin, size, 0);
  14750. }
  14751. function resolveEnd(end, size) {
  14752. return resolveIndex(end, size, size);
  14753. }
  14754. function resolveIndex(index, size, defaultIndex) {
  14755. return index === undefined ?
  14756. defaultIndex :
  14757. index < 0 ?
  14758. Math.max(0, size + index) :
  14759. size === undefined ?
  14760. index :
  14761. Math.min(size, index);
  14762. }
  14763. /* global Symbol */
  14764. var ITERATE_KEYS = 0;
  14765. var ITERATE_VALUES = 1;
  14766. var ITERATE_ENTRIES = 2;
  14767. var REAL_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
  14768. var FAUX_ITERATOR_SYMBOL = '@@iterator';
  14769. var ITERATOR_SYMBOL = REAL_ITERATOR_SYMBOL || FAUX_ITERATOR_SYMBOL;
  14770. function Iterator(next) {
  14771. this.next = next;
  14772. }
  14773. Iterator.prototype.toString = function() {
  14774. return '[Iterator]';
  14775. };
  14776. Iterator.KEYS = ITERATE_KEYS;
  14777. Iterator.VALUES = ITERATE_VALUES;
  14778. Iterator.ENTRIES = ITERATE_ENTRIES;
  14779. Iterator.prototype.inspect =
  14780. Iterator.prototype.toSource = function () { return this.toString(); };
  14781. Iterator.prototype[ITERATOR_SYMBOL] = function () {
  14782. return this;
  14783. };
  14784. function iteratorValue(type, k, v, iteratorResult) {
  14785. var value = type === 0 ? k : type === 1 ? v : [k, v];
  14786. iteratorResult ? (iteratorResult.value = value) : (iteratorResult = {
  14787. value: value, done: false
  14788. });
  14789. return iteratorResult;
  14790. }
  14791. function iteratorDone() {
  14792. return { value: undefined, done: true };
  14793. }
  14794. function hasIterator(maybeIterable) {
  14795. return !!getIteratorFn(maybeIterable);
  14796. }
  14797. function isIterator(maybeIterator) {
  14798. return maybeIterator && typeof maybeIterator.next === 'function';
  14799. }
  14800. function getIterator(iterable) {
  14801. var iteratorFn = getIteratorFn(iterable);
  14802. return iteratorFn && iteratorFn.call(iterable);
  14803. }
  14804. function getIteratorFn(iterable) {
  14805. var iteratorFn = iterable && (
  14806. (REAL_ITERATOR_SYMBOL && iterable[REAL_ITERATOR_SYMBOL]) ||
  14807. iterable[FAUX_ITERATOR_SYMBOL]
  14808. );
  14809. if (typeof iteratorFn === 'function') {
  14810. return iteratorFn;
  14811. }
  14812. }
  14813. function isArrayLike(value) {
  14814. return value && typeof value.length === 'number';
  14815. }
  14816. createClass(Seq, Iterable);
  14817. function Seq(value) {
  14818. return value === null || value === undefined ? emptySequence() :
  14819. isIterable(value) ? value.toSeq() : seqFromValue(value);
  14820. }
  14821. Seq.of = function(/*...values*/) {
  14822. return Seq(arguments);
  14823. };
  14824. Seq.prototype.toSeq = function() {
  14825. return this;
  14826. };
  14827. Seq.prototype.toString = function() {
  14828. return this.__toString('Seq {', '}');
  14829. };
  14830. Seq.prototype.cacheResult = function() {
  14831. if (!this._cache && this.__iterateUncached) {
  14832. this._cache = this.entrySeq().toArray();
  14833. this.size = this._cache.length;
  14834. }
  14835. return this;
  14836. };
  14837. // abstract __iterateUncached(fn, reverse)
  14838. Seq.prototype.__iterate = function(fn, reverse) {
  14839. return seqIterate(this, fn, reverse, true);
  14840. };
  14841. // abstract __iteratorUncached(type, reverse)
  14842. Seq.prototype.__iterator = function(type, reverse) {
  14843. return seqIterator(this, type, reverse, true);
  14844. };
  14845. createClass(KeyedSeq, Seq);
  14846. function KeyedSeq(value) {
  14847. return value === null || value === undefined ?
  14848. emptySequence().toKeyedSeq() :
  14849. isIterable(value) ?
  14850. (isKeyed(value) ? value.toSeq() : value.fromEntrySeq()) :
  14851. keyedSeqFromValue(value);
  14852. }
  14853. KeyedSeq.prototype.toKeyedSeq = function() {
  14854. return this;
  14855. };
  14856. createClass(IndexedSeq, Seq);
  14857. function IndexedSeq(value) {
  14858. return value === null || value === undefined ? emptySequence() :
  14859. !isIterable(value) ? indexedSeqFromValue(value) :
  14860. isKeyed(value) ? value.entrySeq() : value.toIndexedSeq();
  14861. }
  14862. IndexedSeq.of = function(/*...values*/) {
  14863. return IndexedSeq(arguments);
  14864. };
  14865. IndexedSeq.prototype.toIndexedSeq = function() {
  14866. return this;
  14867. };
  14868. IndexedSeq.prototype.toString = function() {
  14869. return this.__toString('Seq [', ']');
  14870. };
  14871. IndexedSeq.prototype.__iterate = function(fn, reverse) {
  14872. return seqIterate(this, fn, reverse, false);
  14873. };
  14874. IndexedSeq.prototype.__iterator = function(type, reverse) {
  14875. return seqIterator(this, type, reverse, false);
  14876. };
  14877. createClass(SetSeq, Seq);
  14878. function SetSeq(value) {
  14879. return (
  14880. value === null || value === undefined ? emptySequence() :
  14881. !isIterable(value) ? indexedSeqFromValue(value) :
  14882. isKeyed(value) ? value.entrySeq() : value
  14883. ).toSetSeq();
  14884. }
  14885. SetSeq.of = function(/*...values*/) {
  14886. return SetSeq(arguments);
  14887. };
  14888. SetSeq.prototype.toSetSeq = function() {
  14889. return this;
  14890. };
  14891. Seq.isSeq = isSeq;
  14892. Seq.Keyed = KeyedSeq;
  14893. Seq.Set = SetSeq;
  14894. Seq.Indexed = IndexedSeq;
  14895. var IS_SEQ_SENTINEL = '@@__IMMUTABLE_SEQ__@@';
  14896. Seq.prototype[IS_SEQ_SENTINEL] = true;
  14897. createClass(ArraySeq, IndexedSeq);
  14898. function ArraySeq(array) {
  14899. this._array = array;
  14900. this.size = array.length;
  14901. }
  14902. ArraySeq.prototype.get = function(index, notSetValue) {
  14903. return this.has(index) ? this._array[wrapIndex(this, index)] : notSetValue;
  14904. };
  14905. ArraySeq.prototype.__iterate = function(fn, reverse) {
  14906. var array = this._array;
  14907. var maxIndex = array.length - 1;
  14908. for (var ii = 0; ii <= maxIndex; ii++) {
  14909. if (fn(array[reverse ? maxIndex - ii : ii], ii, this) === false) {
  14910. return ii + 1;
  14911. }
  14912. }
  14913. return ii;
  14914. };
  14915. ArraySeq.prototype.__iterator = function(type, reverse) {
  14916. var array = this._array;
  14917. var maxIndex = array.length - 1;
  14918. var ii = 0;
  14919. return new Iterator(function()
  14920. {return ii > maxIndex ?
  14921. iteratorDone() :
  14922. iteratorValue(type, ii, array[reverse ? maxIndex - ii++ : ii++])}
  14923. );
  14924. };
  14925. createClass(ObjectSeq, KeyedSeq);
  14926. function ObjectSeq(object) {
  14927. var keys = Object.keys(object);
  14928. this._object = object;
  14929. this._keys = keys;
  14930. this.size = keys.length;
  14931. }
  14932. ObjectSeq.prototype.get = function(key, notSetValue) {
  14933. if (notSetValue !== undefined && !this.has(key)) {
  14934. return notSetValue;
  14935. }
  14936. return this._object[key];
  14937. };
  14938. ObjectSeq.prototype.has = function(key) {
  14939. return this._object.hasOwnProperty(key);
  14940. };
  14941. ObjectSeq.prototype.__iterate = function(fn, reverse) {
  14942. var object = this._object;
  14943. var keys = this._keys;
  14944. var maxIndex = keys.length - 1;
  14945. for (var ii = 0; ii <= maxIndex; ii++) {
  14946. var key = keys[reverse ? maxIndex - ii : ii];
  14947. if (fn(object[key], key, this) === false) {
  14948. return ii + 1;
  14949. }
  14950. }
  14951. return ii;
  14952. };
  14953. ObjectSeq.prototype.__iterator = function(type, reverse) {
  14954. var object = this._object;
  14955. var keys = this._keys;
  14956. var maxIndex = keys.length - 1;
  14957. var ii = 0;
  14958. return new Iterator(function() {
  14959. var key = keys[reverse ? maxIndex - ii : ii];
  14960. return ii++ > maxIndex ?
  14961. iteratorDone() :
  14962. iteratorValue(type, key, object[key]);
  14963. });
  14964. };
  14965. ObjectSeq.prototype[IS_ORDERED_SENTINEL] = true;
  14966. createClass(IterableSeq, IndexedSeq);
  14967. function IterableSeq(iterable) {
  14968. this._iterable = iterable;
  14969. this.size = iterable.length || iterable.size;
  14970. }
  14971. IterableSeq.prototype.__iterateUncached = function(fn, reverse) {
  14972. if (reverse) {
  14973. return this.cacheResult().__iterate(fn, reverse);
  14974. }
  14975. var iterable = this._iterable;
  14976. var iterator = getIterator(iterable);
  14977. var iterations = 0;
  14978. if (isIterator(iterator)) {
  14979. var step;
  14980. while (!(step = iterator.next()).done) {
  14981. if (fn(step.value, iterations++, this) === false) {
  14982. break;
  14983. }
  14984. }
  14985. }
  14986. return iterations;
  14987. };
  14988. IterableSeq.prototype.__iteratorUncached = function(type, reverse) {
  14989. if (reverse) {
  14990. return this.cacheResult().__iterator(type, reverse);
  14991. }
  14992. var iterable = this._iterable;
  14993. var iterator = getIterator(iterable);
  14994. if (!isIterator(iterator)) {
  14995. return new Iterator(iteratorDone);
  14996. }
  14997. var iterations = 0;
  14998. return new Iterator(function() {
  14999. var step = iterator.next();
  15000. return step.done ? step : iteratorValue(type, iterations++, step.value);
  15001. });
  15002. };
  15003. createClass(IteratorSeq, IndexedSeq);
  15004. function IteratorSeq(iterator) {
  15005. this._iterator = iterator;
  15006. this._iteratorCache = [];
  15007. }
  15008. IteratorSeq.prototype.__iterateUncached = function(fn, reverse) {
  15009. if (reverse) {
  15010. return this.cacheResult().__iterate(fn, reverse);
  15011. }
  15012. var iterator = this._iterator;
  15013. var cache = this._iteratorCache;
  15014. var iterations = 0;
  15015. while (iterations < cache.length) {
  15016. if (fn(cache[iterations], iterations++, this) === false) {
  15017. return iterations;
  15018. }
  15019. }
  15020. var step;
  15021. while (!(step = iterator.next()).done) {
  15022. var val = step.value;
  15023. cache[iterations] = val;
  15024. if (fn(val, iterations++, this) === false) {
  15025. break;
  15026. }
  15027. }
  15028. return iterations;
  15029. };
  15030. IteratorSeq.prototype.__iteratorUncached = function(type, reverse) {
  15031. if (reverse) {
  15032. return this.cacheResult().__iterator(type, reverse);
  15033. }
  15034. var iterator = this._iterator;
  15035. var cache = this._iteratorCache;
  15036. var iterations = 0;
  15037. return new Iterator(function() {
  15038. if (iterations >= cache.length) {
  15039. var step = iterator.next();
  15040. if (step.done) {
  15041. return step;
  15042. }
  15043. cache[iterations] = step.value;
  15044. }
  15045. return iteratorValue(type, iterations, cache[iterations++]);
  15046. });
  15047. };
  15048. // # pragma Helper functions
  15049. function isSeq(maybeSeq) {
  15050. return !!(maybeSeq && maybeSeq[IS_SEQ_SENTINEL]);
  15051. }
  15052. var EMPTY_SEQ;
  15053. function emptySequence() {
  15054. return EMPTY_SEQ || (EMPTY_SEQ = new ArraySeq([]));
  15055. }
  15056. function keyedSeqFromValue(value) {
  15057. var seq =
  15058. Array.isArray(value) ? new ArraySeq(value).fromEntrySeq() :
  15059. isIterator(value) ? new IteratorSeq(value).fromEntrySeq() :
  15060. hasIterator(value) ? new IterableSeq(value).fromEntrySeq() :
  15061. typeof value === 'object' ? new ObjectSeq(value) :
  15062. undefined;
  15063. if (!seq) {
  15064. throw new TypeError(
  15065. 'Expected Array or iterable object of [k, v] entries, '+
  15066. 'or keyed object: ' + value
  15067. );
  15068. }
  15069. return seq;
  15070. }
  15071. function indexedSeqFromValue(value) {
  15072. var seq = maybeIndexedSeqFromValue(value);
  15073. if (!seq) {
  15074. throw new TypeError(
  15075. 'Expected Array or iterable object of values: ' + value
  15076. );
  15077. }
  15078. return seq;
  15079. }
  15080. function seqFromValue(value) {
  15081. var seq = maybeIndexedSeqFromValue(value) ||
  15082. (typeof value === 'object' && new ObjectSeq(value));
  15083. if (!seq) {
  15084. throw new TypeError(
  15085. 'Expected Array or iterable object of values, or keyed object: ' + value
  15086. );
  15087. }
  15088. return seq;
  15089. }
  15090. function maybeIndexedSeqFromValue(value) {
  15091. return (
  15092. isArrayLike(value) ? new ArraySeq(value) :
  15093. isIterator(value) ? new IteratorSeq(value) :
  15094. hasIterator(value) ? new IterableSeq(value) :
  15095. undefined
  15096. );
  15097. }
  15098. function seqIterate(seq, fn, reverse, useKeys) {
  15099. var cache = seq._cache;
  15100. if (cache) {
  15101. var maxIndex = cache.length - 1;
  15102. for (var ii = 0; ii <= maxIndex; ii++) {
  15103. var entry = cache[reverse ? maxIndex - ii : ii];
  15104. if (fn(entry[1], useKeys ? entry[0] : ii, seq) === false) {
  15105. return ii + 1;
  15106. }
  15107. }
  15108. return ii;
  15109. }
  15110. return seq.__iterateUncached(fn, reverse);
  15111. }
  15112. function seqIterator(seq, type, reverse, useKeys) {
  15113. var cache = seq._cache;
  15114. if (cache) {
  15115. var maxIndex = cache.length - 1;
  15116. var ii = 0;
  15117. return new Iterator(function() {
  15118. var entry = cache[reverse ? maxIndex - ii : ii];
  15119. return ii++ > maxIndex ?
  15120. iteratorDone() :
  15121. iteratorValue(type, useKeys ? entry[0] : ii - 1, entry[1]);
  15122. });
  15123. }
  15124. return seq.__iteratorUncached(type, reverse);
  15125. }
  15126. function fromJS(json, converter) {
  15127. return converter ?
  15128. fromJSWith(converter, json, '', {'': json}) :
  15129. fromJSDefault(json);
  15130. }
  15131. function fromJSWith(converter, json, key, parentJSON) {
  15132. if (Array.isArray(json)) {
  15133. return converter.call(parentJSON, key, IndexedSeq(json).map(function(v, k) {return fromJSWith(converter, v, k, json)}));
  15134. }
  15135. if (isPlainObj(json)) {
  15136. return converter.call(parentJSON, key, KeyedSeq(json).map(function(v, k) {return fromJSWith(converter, v, k, json)}));
  15137. }
  15138. return json;
  15139. }
  15140. function fromJSDefault(json) {
  15141. if (Array.isArray(json)) {
  15142. return IndexedSeq(json).map(fromJSDefault).toList();
  15143. }
  15144. if (isPlainObj(json)) {
  15145. return KeyedSeq(json).map(fromJSDefault).toMap();
  15146. }
  15147. return json;
  15148. }
  15149. function isPlainObj(value) {
  15150. return value && (value.constructor === Object || value.constructor === undefined);
  15151. }
  15152. /**
  15153. * An extension of the "same-value" algorithm as [described for use by ES6 Map
  15154. * and Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map#Key_equality)
  15155. *
  15156. * NaN is considered the same as NaN, however -0 and 0 are considered the same
  15157. * value, which is different from the algorithm described by
  15158. * [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is).
  15159. *
  15160. * This is extended further to allow Objects to describe the values they
  15161. * represent, by way of `valueOf` or `equals` (and `hashCode`).
  15162. *
  15163. * Note: because of this extension, the key equality of Immutable.Map and the
  15164. * value equality of Immutable.Set will differ from ES6 Map and Set.
  15165. *
  15166. * ### Defining custom values
  15167. *
  15168. * The easiest way to describe the value an object represents is by implementing
  15169. * `valueOf`. For example, `Date` represents a value by returning a unix
  15170. * timestamp for `valueOf`:
  15171. *
  15172. * var date1 = new Date(1234567890000); // Fri Feb 13 2009 ...
  15173. * var date2 = new Date(1234567890000);
  15174. * date1.valueOf(); // 1234567890000
  15175. * assert( date1 !== date2 );
  15176. * assert( Immutable.is( date1, date2 ) );
  15177. *
  15178. * Note: overriding `valueOf` may have other implications if you use this object
  15179. * where JavaScript expects a primitive, such as implicit string coercion.
  15180. *
  15181. * For more complex types, especially collections, implementing `valueOf` may
  15182. * not be performant. An alternative is to implement `equals` and `hashCode`.
  15183. *
  15184. * `equals` takes another object, presumably of similar type, and returns true
  15185. * if the it is equal. Equality is symmetrical, so the same result should be
  15186. * returned if this and the argument are flipped.
  15187. *
  15188. * assert( a.equals(b) === b.equals(a) );
  15189. *
  15190. * `hashCode` returns a 32bit integer number representing the object which will
  15191. * be used to determine how to store the value object in a Map or Set. You must
  15192. * provide both or neither methods, one must not exist without the other.
  15193. *
  15194. * Also, an important relationship between these methods must be upheld: if two
  15195. * values are equal, they *must* return the same hashCode. If the values are not
  15196. * equal, they might have the same hashCode; this is called a hash collision,
  15197. * and while undesirable for performance reasons, it is acceptable.
  15198. *
  15199. * if (a.equals(b)) {
  15200. * assert( a.hashCode() === b.hashCode() );
  15201. * }
  15202. *
  15203. * All Immutable collections implement `equals` and `hashCode`.
  15204. *
  15205. */
  15206. function is(valueA, valueB) {
  15207. if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
  15208. return true;
  15209. }
  15210. if (!valueA || !valueB) {
  15211. return false;
  15212. }
  15213. if (typeof valueA.valueOf === 'function' &&
  15214. typeof valueB.valueOf === 'function') {
  15215. valueA = valueA.valueOf();
  15216. valueB = valueB.valueOf();
  15217. if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
  15218. return true;
  15219. }
  15220. if (!valueA || !valueB) {
  15221. return false;
  15222. }
  15223. }
  15224. if (typeof valueA.equals === 'function' &&
  15225. typeof valueB.equals === 'function' &&
  15226. valueA.equals(valueB)) {
  15227. return true;
  15228. }
  15229. return false;
  15230. }
  15231. function deepEqual(a, b) {
  15232. if (a === b) {
  15233. return true;
  15234. }
  15235. if (
  15236. !isIterable(b) ||
  15237. a.size !== undefined && b.size !== undefined && a.size !== b.size ||
  15238. a.__hash !== undefined && b.__hash !== undefined && a.__hash !== b.__hash ||
  15239. isKeyed(a) !== isKeyed(b) ||
  15240. isIndexed(a) !== isIndexed(b) ||
  15241. isOrdered(a) !== isOrdered(b)
  15242. ) {
  15243. return false;
  15244. }
  15245. if (a.size === 0 && b.size === 0) {
  15246. return true;
  15247. }
  15248. var notAssociative = !isAssociative(a);
  15249. if (isOrdered(a)) {
  15250. var entries = a.entries();
  15251. return b.every(function(v, k) {
  15252. var entry = entries.next().value;
  15253. return entry && is(entry[1], v) && (notAssociative || is(entry[0], k));
  15254. }) && entries.next().done;
  15255. }
  15256. var flipped = false;
  15257. if (a.size === undefined) {
  15258. if (b.size === undefined) {
  15259. if (typeof a.cacheResult === 'function') {
  15260. a.cacheResult();
  15261. }
  15262. } else {
  15263. flipped = true;
  15264. var _ = a;
  15265. a = b;
  15266. b = _;
  15267. }
  15268. }
  15269. var allEqual = true;
  15270. var bSize = b.__iterate(function(v, k) {
  15271. if (notAssociative ? !a.has(v) :
  15272. flipped ? !is(v, a.get(k, NOT_SET)) : !is(a.get(k, NOT_SET), v)) {
  15273. allEqual = false;
  15274. return false;
  15275. }
  15276. });
  15277. return allEqual && a.size === bSize;
  15278. }
  15279. createClass(Repeat, IndexedSeq);
  15280. function Repeat(value, times) {
  15281. if (!(this instanceof Repeat)) {
  15282. return new Repeat(value, times);
  15283. }
  15284. this._value = value;
  15285. this.size = times === undefined ? Infinity : Math.max(0, times);
  15286. if (this.size === 0) {
  15287. if (EMPTY_REPEAT) {
  15288. return EMPTY_REPEAT;
  15289. }
  15290. EMPTY_REPEAT = this;
  15291. }
  15292. }
  15293. Repeat.prototype.toString = function() {
  15294. if (this.size === 0) {
  15295. return 'Repeat []';
  15296. }
  15297. return 'Repeat [ ' + this._value + ' ' + this.size + ' times ]';
  15298. };
  15299. Repeat.prototype.get = function(index, notSetValue) {
  15300. return this.has(index) ? this._value : notSetValue;
  15301. };
  15302. Repeat.prototype.includes = function(searchValue) {
  15303. return is(this._value, searchValue);
  15304. };
  15305. Repeat.prototype.slice = function(begin, end) {
  15306. var size = this.size;
  15307. return wholeSlice(begin, end, size) ? this :
  15308. new Repeat(this._value, resolveEnd(end, size) - resolveBegin(begin, size));
  15309. };
  15310. Repeat.prototype.reverse = function() {
  15311. return this;
  15312. };
  15313. Repeat.prototype.indexOf = function(searchValue) {
  15314. if (is(this._value, searchValue)) {
  15315. return 0;
  15316. }
  15317. return -1;
  15318. };
  15319. Repeat.prototype.lastIndexOf = function(searchValue) {
  15320. if (is(this._value, searchValue)) {
  15321. return this.size;
  15322. }
  15323. return -1;
  15324. };
  15325. Repeat.prototype.__iterate = function(fn, reverse) {
  15326. for (var ii = 0; ii < this.size; ii++) {
  15327. if (fn(this._value, ii, this) === false) {
  15328. return ii + 1;
  15329. }
  15330. }
  15331. return ii;
  15332. };
  15333. Repeat.prototype.__iterator = function(type, reverse) {var this$0 = this;
  15334. var ii = 0;
  15335. return new Iterator(function()
  15336. {return ii < this$0.size ? iteratorValue(type, ii++, this$0._value) : iteratorDone()}
  15337. );
  15338. };
  15339. Repeat.prototype.equals = function(other) {
  15340. return other instanceof Repeat ?
  15341. is(this._value, other._value) :
  15342. deepEqual(other);
  15343. };
  15344. var EMPTY_REPEAT;
  15345. function invariant(condition, error) {
  15346. if (!condition) throw new Error(error);
  15347. }
  15348. createClass(Range, IndexedSeq);
  15349. function Range(start, end, step) {
  15350. if (!(this instanceof Range)) {
  15351. return new Range(start, end, step);
  15352. }
  15353. invariant(step !== 0, 'Cannot step a Range by 0');
  15354. start = start || 0;
  15355. if (end === undefined) {
  15356. end = Infinity;
  15357. }
  15358. step = step === undefined ? 1 : Math.abs(step);
  15359. if (end < start) {
  15360. step = -step;
  15361. }
  15362. this._start = start;
  15363. this._end = end;
  15364. this._step = step;
  15365. this.size = Math.max(0, Math.ceil((end - start) / step - 1) + 1);
  15366. if (this.size === 0) {
  15367. if (EMPTY_RANGE) {
  15368. return EMPTY_RANGE;
  15369. }
  15370. EMPTY_RANGE = this;
  15371. }
  15372. }
  15373. Range.prototype.toString = function() {
  15374. if (this.size === 0) {
  15375. return 'Range []';
  15376. }
  15377. return 'Range [ ' +
  15378. this._start + '...' + this._end +
  15379. (this._step > 1 ? ' by ' + this._step : '') +
  15380. ' ]';
  15381. };
  15382. Range.prototype.get = function(index, notSetValue) {
  15383. return this.has(index) ?
  15384. this._start + wrapIndex(this, index) * this._step :
  15385. notSetValue;
  15386. };
  15387. Range.prototype.includes = function(searchValue) {
  15388. var possibleIndex = (searchValue - this._start) / this._step;
  15389. return possibleIndex >= 0 &&
  15390. possibleIndex < this.size &&
  15391. possibleIndex === Math.floor(possibleIndex);
  15392. };
  15393. Range.prototype.slice = function(begin, end) {
  15394. if (wholeSlice(begin, end, this.size)) {
  15395. return this;
  15396. }
  15397. begin = resolveBegin(begin, this.size);
  15398. end = resolveEnd(end, this.size);
  15399. if (end <= begin) {
  15400. return new Range(0, 0);
  15401. }
  15402. return new Range(this.get(begin, this._end), this.get(end, this._end), this._step);
  15403. };
  15404. Range.prototype.indexOf = function(searchValue) {
  15405. var offsetValue = searchValue - this._start;
  15406. if (offsetValue % this._step === 0) {
  15407. var index = offsetValue / this._step;
  15408. if (index >= 0 && index < this.size) {
  15409. return index
  15410. }
  15411. }
  15412. return -1;
  15413. };
  15414. Range.prototype.lastIndexOf = function(searchValue) {
  15415. return this.indexOf(searchValue);
  15416. };
  15417. Range.prototype.__iterate = function(fn, reverse) {
  15418. var maxIndex = this.size - 1;
  15419. var step = this._step;
  15420. var value = reverse ? this._start + maxIndex * step : this._start;
  15421. for (var ii = 0; ii <= maxIndex; ii++) {
  15422. if (fn(value, ii, this) === false) {
  15423. return ii + 1;
  15424. }
  15425. value += reverse ? -step : step;
  15426. }
  15427. return ii;
  15428. };
  15429. Range.prototype.__iterator = function(type, reverse) {
  15430. var maxIndex = this.size - 1;
  15431. var step = this._step;
  15432. var value = reverse ? this._start + maxIndex * step : this._start;
  15433. var ii = 0;
  15434. return new Iterator(function() {
  15435. var v = value;
  15436. value += reverse ? -step : step;
  15437. return ii > maxIndex ? iteratorDone() : iteratorValue(type, ii++, v);
  15438. });
  15439. };
  15440. Range.prototype.equals = function(other) {
  15441. return other instanceof Range ?
  15442. this._start === other._start &&
  15443. this._end === other._end &&
  15444. this._step === other._step :
  15445. deepEqual(this, other);
  15446. };
  15447. var EMPTY_RANGE;
  15448. createClass(Collection, Iterable);
  15449. function Collection() {
  15450. throw TypeError('Abstract');
  15451. }
  15452. createClass(KeyedCollection, Collection);function KeyedCollection() {}
  15453. createClass(IndexedCollection, Collection);function IndexedCollection() {}
  15454. createClass(SetCollection, Collection);function SetCollection() {}
  15455. Collection.Keyed = KeyedCollection;
  15456. Collection.Indexed = IndexedCollection;
  15457. Collection.Set = SetCollection;
  15458. var imul =
  15459. typeof Math.imul === 'function' && Math.imul(0xffffffff, 2) === -2 ?
  15460. Math.imul :
  15461. function imul(a, b) {
  15462. a = a | 0; // int
  15463. b = b | 0; // int
  15464. var c = a & 0xffff;
  15465. var d = b & 0xffff;
  15466. // Shift by 0 fixes the sign on the high part.
  15467. return (c * d) + ((((a >>> 16) * d + c * (b >>> 16)) << 16) >>> 0) | 0; // int
  15468. };
  15469. // v8 has an optimization for storing 31-bit signed numbers.
  15470. // Values which have either 00 or 11 as the high order bits qualify.
  15471. // This function drops the highest order bit in a signed number, maintaining
  15472. // the sign bit.
  15473. function smi(i32) {
  15474. return ((i32 >>> 1) & 0x40000000) | (i32 & 0xBFFFFFFF);
  15475. }
  15476. function hash(o) {
  15477. if (o === false || o === null || o === undefined) {
  15478. return 0;
  15479. }
  15480. if (typeof o.valueOf === 'function') {
  15481. o = o.valueOf();
  15482. if (o === false || o === null || o === undefined) {
  15483. return 0;
  15484. }
  15485. }
  15486. if (o === true) {
  15487. return 1;
  15488. }
  15489. var type = typeof o;
  15490. if (type === 'number') {
  15491. var h = o | 0;
  15492. if (h !== o) {
  15493. h ^= o * 0xFFFFFFFF;
  15494. }
  15495. while (o > 0xFFFFFFFF) {
  15496. o /= 0xFFFFFFFF;
  15497. h ^= o;
  15498. }
  15499. return smi(h);
  15500. }
  15501. if (type === 'string') {
  15502. return o.length > STRING_HASH_CACHE_MIN_STRLEN ? cachedHashString(o) : hashString(o);
  15503. }
  15504. if (typeof o.hashCode === 'function') {
  15505. return o.hashCode();
  15506. }
  15507. if (type === 'object') {
  15508. return hashJSObj(o);
  15509. }
  15510. if (typeof o.toString === 'function') {
  15511. return hashString(o.toString());
  15512. }
  15513. throw new Error('Value type ' + type + ' cannot be hashed.');
  15514. }
  15515. function cachedHashString(string) {
  15516. var hash = stringHashCache[string];
  15517. if (hash === undefined) {
  15518. hash = hashString(string);
  15519. if (STRING_HASH_CACHE_SIZE === STRING_HASH_CACHE_MAX_SIZE) {
  15520. STRING_HASH_CACHE_SIZE = 0;
  15521. stringHashCache = {};
  15522. }
  15523. STRING_HASH_CACHE_SIZE++;
  15524. stringHashCache[string] = hash;
  15525. }
  15526. return hash;
  15527. }
  15528. // http://jsperf.com/hashing-strings
  15529. function hashString(string) {
  15530. // This is the hash from JVM
  15531. // The hash code for a string is computed as
  15532. // s[0] * 31 ^ (n - 1) + s[1] * 31 ^ (n - 2) + ... + s[n - 1],
  15533. // where s[i] is the ith character of the string and n is the length of
  15534. // the string. We "mod" the result to make it between 0 (inclusive) and 2^31
  15535. // (exclusive) by dropping high bits.
  15536. var hash = 0;
  15537. for (var ii = 0; ii < string.length; ii++) {
  15538. hash = 31 * hash + string.charCodeAt(ii) | 0;
  15539. }
  15540. return smi(hash);
  15541. }
  15542. function hashJSObj(obj) {
  15543. var hash;
  15544. if (usingWeakMap) {
  15545. hash = weakMap.get(obj);
  15546. if (hash !== undefined) {
  15547. return hash;
  15548. }
  15549. }
  15550. hash = obj[UID_HASH_KEY];
  15551. if (hash !== undefined) {
  15552. return hash;
  15553. }
  15554. if (!canDefineProperty) {
  15555. hash = obj.propertyIsEnumerable && obj.propertyIsEnumerable[UID_HASH_KEY];
  15556. if (hash !== undefined) {
  15557. return hash;
  15558. }
  15559. hash = getIENodeHash(obj);
  15560. if (hash !== undefined) {
  15561. return hash;
  15562. }
  15563. }
  15564. hash = ++objHashUID;
  15565. if (objHashUID & 0x40000000) {
  15566. objHashUID = 0;
  15567. }
  15568. if (usingWeakMap) {
  15569. weakMap.set(obj, hash);
  15570. } else if (isExtensible !== undefined && isExtensible(obj) === false) {
  15571. throw new Error('Non-extensible objects are not allowed as keys.');
  15572. } else if (canDefineProperty) {
  15573. Object.defineProperty(obj, UID_HASH_KEY, {
  15574. 'enumerable': false,
  15575. 'configurable': false,
  15576. 'writable': false,
  15577. 'value': hash
  15578. });
  15579. } else if (obj.propertyIsEnumerable !== undefined &&
  15580. obj.propertyIsEnumerable === obj.constructor.prototype.propertyIsEnumerable) {
  15581. // Since we can't define a non-enumerable property on the object
  15582. // we'll hijack one of the less-used non-enumerable properties to
  15583. // save our hash on it. Since this is a function it will not show up in
  15584. // `JSON.stringify` which is what we want.
  15585. obj.propertyIsEnumerable = function() {
  15586. return this.constructor.prototype.propertyIsEnumerable.apply(this, arguments);
  15587. };
  15588. obj.propertyIsEnumerable[UID_HASH_KEY] = hash;
  15589. } else if (obj.nodeType !== undefined) {
  15590. // At this point we couldn't get the IE `uniqueID` to use as a hash
  15591. // and we couldn't use a non-enumerable property to exploit the
  15592. // dontEnum bug so we simply add the `UID_HASH_KEY` on the node
  15593. // itself.
  15594. obj[UID_HASH_KEY] = hash;
  15595. } else {
  15596. throw new Error('Unable to set a non-enumerable property on object.');
  15597. }
  15598. return hash;
  15599. }
  15600. // Get references to ES5 object methods.
  15601. var isExtensible = Object.isExtensible;
  15602. // True if Object.defineProperty works as expected. IE8 fails this test.
  15603. var canDefineProperty = (function() {
  15604. try {
  15605. Object.defineProperty({}, '@', {});
  15606. return true;
  15607. } catch (e) {
  15608. return false;
  15609. }
  15610. }());
  15611. // IE has a `uniqueID` property on DOM nodes. We can construct the hash from it
  15612. // and avoid memory leaks from the IE cloneNode bug.
  15613. function getIENodeHash(node) {
  15614. if (node && node.nodeType > 0) {
  15615. switch (node.nodeType) {
  15616. case 1: // Element
  15617. return node.uniqueID;
  15618. case 9: // Document
  15619. return node.documentElement && node.documentElement.uniqueID;
  15620. }
  15621. }
  15622. }
  15623. // If possible, use a WeakMap.
  15624. var usingWeakMap = typeof WeakMap === 'function';
  15625. var weakMap;
  15626. if (usingWeakMap) {
  15627. weakMap = new WeakMap();
  15628. }
  15629. var objHashUID = 0;
  15630. var UID_HASH_KEY = '__immutablehash__';
  15631. if (typeof Symbol === 'function') {
  15632. UID_HASH_KEY = Symbol(UID_HASH_KEY);
  15633. }
  15634. var STRING_HASH_CACHE_MIN_STRLEN = 16;
  15635. var STRING_HASH_CACHE_MAX_SIZE = 255;
  15636. var STRING_HASH_CACHE_SIZE = 0;
  15637. var stringHashCache = {};
  15638. function assertNotInfinite(size) {
  15639. invariant(
  15640. size !== Infinity,
  15641. 'Cannot perform this action with an infinite size.'
  15642. );
  15643. }
  15644. createClass(Map, KeyedCollection);
  15645. // @pragma Construction
  15646. function Map(value) {
  15647. return value === null || value === undefined ? emptyMap() :
  15648. isMap(value) && !isOrdered(value) ? value :
  15649. emptyMap().withMutations(function(map ) {
  15650. var iter = KeyedIterable(value);
  15651. assertNotInfinite(iter.size);
  15652. iter.forEach(function(v, k) {return map.set(k, v)});
  15653. });
  15654. }
  15655. Map.prototype.toString = function() {
  15656. return this.__toString('Map {', '}');
  15657. };
  15658. // @pragma Access
  15659. Map.prototype.get = function(k, notSetValue) {
  15660. return this._root ?
  15661. this._root.get(0, undefined, k, notSetValue) :
  15662. notSetValue;
  15663. };
  15664. // @pragma Modification
  15665. Map.prototype.set = function(k, v) {
  15666. return updateMap(this, k, v);
  15667. };
  15668. Map.prototype.setIn = function(keyPath, v) {
  15669. return this.updateIn(keyPath, NOT_SET, function() {return v});
  15670. };
  15671. Map.prototype.remove = function(k) {
  15672. return updateMap(this, k, NOT_SET);
  15673. };
  15674. Map.prototype.deleteIn = function(keyPath) {
  15675. return this.updateIn(keyPath, function() {return NOT_SET});
  15676. };
  15677. Map.prototype.update = function(k, notSetValue, updater) {
  15678. return arguments.length === 1 ?
  15679. k(this) :
  15680. this.updateIn([k], notSetValue, updater);
  15681. };
  15682. Map.prototype.updateIn = function(keyPath, notSetValue, updater) {
  15683. if (!updater) {
  15684. updater = notSetValue;
  15685. notSetValue = undefined;
  15686. }
  15687. var updatedValue = updateInDeepMap(
  15688. this,
  15689. forceIterator(keyPath),
  15690. notSetValue,
  15691. updater
  15692. );
  15693. return updatedValue === NOT_SET ? undefined : updatedValue;
  15694. };
  15695. Map.prototype.clear = function() {
  15696. if (this.size === 0) {
  15697. return this;
  15698. }
  15699. if (this.__ownerID) {
  15700. this.size = 0;
  15701. this._root = null;
  15702. this.__hash = undefined;
  15703. this.__altered = true;
  15704. return this;
  15705. }
  15706. return emptyMap();
  15707. };
  15708. // @pragma Composition
  15709. Map.prototype.merge = function(/*...iters*/) {
  15710. return mergeIntoMapWith(this, undefined, arguments);
  15711. };
  15712. Map.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  15713. return mergeIntoMapWith(this, merger, iters);
  15714. };
  15715. Map.prototype.mergeIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1);
  15716. return this.updateIn(
  15717. keyPath,
  15718. emptyMap(),
  15719. function(m ) {return typeof m.merge === 'function' ?
  15720. m.merge.apply(m, iters) :
  15721. iters[iters.length - 1]}
  15722. );
  15723. };
  15724. Map.prototype.mergeDeep = function(/*...iters*/) {
  15725. return mergeIntoMapWith(this, deepMerger, arguments);
  15726. };
  15727. Map.prototype.mergeDeepWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  15728. return mergeIntoMapWith(this, deepMergerWith(merger), iters);
  15729. };
  15730. Map.prototype.mergeDeepIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1);
  15731. return this.updateIn(
  15732. keyPath,
  15733. emptyMap(),
  15734. function(m ) {return typeof m.mergeDeep === 'function' ?
  15735. m.mergeDeep.apply(m, iters) :
  15736. iters[iters.length - 1]}
  15737. );
  15738. };
  15739. Map.prototype.sort = function(comparator) {
  15740. // Late binding
  15741. return OrderedMap(sortFactory(this, comparator));
  15742. };
  15743. Map.prototype.sortBy = function(mapper, comparator) {
  15744. // Late binding
  15745. return OrderedMap(sortFactory(this, comparator, mapper));
  15746. };
  15747. // @pragma Mutability
  15748. Map.prototype.withMutations = function(fn) {
  15749. var mutable = this.asMutable();
  15750. fn(mutable);
  15751. return mutable.wasAltered() ? mutable.__ensureOwner(this.__ownerID) : this;
  15752. };
  15753. Map.prototype.asMutable = function() {
  15754. return this.__ownerID ? this : this.__ensureOwner(new OwnerID());
  15755. };
  15756. Map.prototype.asImmutable = function() {
  15757. return this.__ensureOwner();
  15758. };
  15759. Map.prototype.wasAltered = function() {
  15760. return this.__altered;
  15761. };
  15762. Map.prototype.__iterator = function(type, reverse) {
  15763. return new MapIterator(this, type, reverse);
  15764. };
  15765. Map.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  15766. var iterations = 0;
  15767. this._root && this._root.iterate(function(entry ) {
  15768. iterations++;
  15769. return fn(entry[1], entry[0], this$0);
  15770. }, reverse);
  15771. return iterations;
  15772. };
  15773. Map.prototype.__ensureOwner = function(ownerID) {
  15774. if (ownerID === this.__ownerID) {
  15775. return this;
  15776. }
  15777. if (!ownerID) {
  15778. this.__ownerID = ownerID;
  15779. this.__altered = false;
  15780. return this;
  15781. }
  15782. return makeMap(this.size, this._root, ownerID, this.__hash);
  15783. };
  15784. function isMap(maybeMap) {
  15785. return !!(maybeMap && maybeMap[IS_MAP_SENTINEL]);
  15786. }
  15787. Map.isMap = isMap;
  15788. var IS_MAP_SENTINEL = '@@__IMMUTABLE_MAP__@@';
  15789. var MapPrototype = Map.prototype;
  15790. MapPrototype[IS_MAP_SENTINEL] = true;
  15791. MapPrototype[DELETE] = MapPrototype.remove;
  15792. MapPrototype.removeIn = MapPrototype.deleteIn;
  15793. // #pragma Trie Nodes
  15794. function ArrayMapNode(ownerID, entries) {
  15795. this.ownerID = ownerID;
  15796. this.entries = entries;
  15797. }
  15798. ArrayMapNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  15799. var entries = this.entries;
  15800. for (var ii = 0, len = entries.length; ii < len; ii++) {
  15801. if (is(key, entries[ii][0])) {
  15802. return entries[ii][1];
  15803. }
  15804. }
  15805. return notSetValue;
  15806. };
  15807. ArrayMapNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  15808. var removed = value === NOT_SET;
  15809. var entries = this.entries;
  15810. var idx = 0;
  15811. for (var len = entries.length; idx < len; idx++) {
  15812. if (is(key, entries[idx][0])) {
  15813. break;
  15814. }
  15815. }
  15816. var exists = idx < len;
  15817. if (exists ? entries[idx][1] === value : removed) {
  15818. return this;
  15819. }
  15820. SetRef(didAlter);
  15821. (removed || !exists) && SetRef(didChangeSize);
  15822. if (removed && entries.length === 1) {
  15823. return; // undefined
  15824. }
  15825. if (!exists && !removed && entries.length >= MAX_ARRAY_MAP_SIZE) {
  15826. return createNodes(ownerID, entries, key, value);
  15827. }
  15828. var isEditable = ownerID && ownerID === this.ownerID;
  15829. var newEntries = isEditable ? entries : arrCopy(entries);
  15830. if (exists) {
  15831. if (removed) {
  15832. idx === len - 1 ? newEntries.pop() : (newEntries[idx] = newEntries.pop());
  15833. } else {
  15834. newEntries[idx] = [key, value];
  15835. }
  15836. } else {
  15837. newEntries.push([key, value]);
  15838. }
  15839. if (isEditable) {
  15840. this.entries = newEntries;
  15841. return this;
  15842. }
  15843. return new ArrayMapNode(ownerID, newEntries);
  15844. };
  15845. function BitmapIndexedNode(ownerID, bitmap, nodes) {
  15846. this.ownerID = ownerID;
  15847. this.bitmap = bitmap;
  15848. this.nodes = nodes;
  15849. }
  15850. BitmapIndexedNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  15851. if (keyHash === undefined) {
  15852. keyHash = hash(key);
  15853. }
  15854. var bit = (1 << ((shift === 0 ? keyHash : keyHash >>> shift) & MASK));
  15855. var bitmap = this.bitmap;
  15856. return (bitmap & bit) === 0 ? notSetValue :
  15857. this.nodes[popCount(bitmap & (bit - 1))].get(shift + SHIFT, keyHash, key, notSetValue);
  15858. };
  15859. BitmapIndexedNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  15860. if (keyHash === undefined) {
  15861. keyHash = hash(key);
  15862. }
  15863. var keyHashFrag = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  15864. var bit = 1 << keyHashFrag;
  15865. var bitmap = this.bitmap;
  15866. var exists = (bitmap & bit) !== 0;
  15867. if (!exists && value === NOT_SET) {
  15868. return this;
  15869. }
  15870. var idx = popCount(bitmap & (bit - 1));
  15871. var nodes = this.nodes;
  15872. var node = exists ? nodes[idx] : undefined;
  15873. var newNode = updateNode(node, ownerID, shift + SHIFT, keyHash, key, value, didChangeSize, didAlter);
  15874. if (newNode === node) {
  15875. return this;
  15876. }
  15877. if (!exists && newNode && nodes.length >= MAX_BITMAP_INDEXED_SIZE) {
  15878. return expandNodes(ownerID, nodes, bitmap, keyHashFrag, newNode);
  15879. }
  15880. if (exists && !newNode && nodes.length === 2 && isLeafNode(nodes[idx ^ 1])) {
  15881. return nodes[idx ^ 1];
  15882. }
  15883. if (exists && newNode && nodes.length === 1 && isLeafNode(newNode)) {
  15884. return newNode;
  15885. }
  15886. var isEditable = ownerID && ownerID === this.ownerID;
  15887. var newBitmap = exists ? newNode ? bitmap : bitmap ^ bit : bitmap | bit;
  15888. var newNodes = exists ? newNode ?
  15889. setIn(nodes, idx, newNode, isEditable) :
  15890. spliceOut(nodes, idx, isEditable) :
  15891. spliceIn(nodes, idx, newNode, isEditable);
  15892. if (isEditable) {
  15893. this.bitmap = newBitmap;
  15894. this.nodes = newNodes;
  15895. return this;
  15896. }
  15897. return new BitmapIndexedNode(ownerID, newBitmap, newNodes);
  15898. };
  15899. function HashArrayMapNode(ownerID, count, nodes) {
  15900. this.ownerID = ownerID;
  15901. this.count = count;
  15902. this.nodes = nodes;
  15903. }
  15904. HashArrayMapNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  15905. if (keyHash === undefined) {
  15906. keyHash = hash(key);
  15907. }
  15908. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  15909. var node = this.nodes[idx];
  15910. return node ? node.get(shift + SHIFT, keyHash, key, notSetValue) : notSetValue;
  15911. };
  15912. HashArrayMapNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  15913. if (keyHash === undefined) {
  15914. keyHash = hash(key);
  15915. }
  15916. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  15917. var removed = value === NOT_SET;
  15918. var nodes = this.nodes;
  15919. var node = nodes[idx];
  15920. if (removed && !node) {
  15921. return this;
  15922. }
  15923. var newNode = updateNode(node, ownerID, shift + SHIFT, keyHash, key, value, didChangeSize, didAlter);
  15924. if (newNode === node) {
  15925. return this;
  15926. }
  15927. var newCount = this.count;
  15928. if (!node) {
  15929. newCount++;
  15930. } else if (!newNode) {
  15931. newCount--;
  15932. if (newCount < MIN_HASH_ARRAY_MAP_SIZE) {
  15933. return packNodes(ownerID, nodes, newCount, idx);
  15934. }
  15935. }
  15936. var isEditable = ownerID && ownerID === this.ownerID;
  15937. var newNodes = setIn(nodes, idx, newNode, isEditable);
  15938. if (isEditable) {
  15939. this.count = newCount;
  15940. this.nodes = newNodes;
  15941. return this;
  15942. }
  15943. return new HashArrayMapNode(ownerID, newCount, newNodes);
  15944. };
  15945. function HashCollisionNode(ownerID, keyHash, entries) {
  15946. this.ownerID = ownerID;
  15947. this.keyHash = keyHash;
  15948. this.entries = entries;
  15949. }
  15950. HashCollisionNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  15951. var entries = this.entries;
  15952. for (var ii = 0, len = entries.length; ii < len; ii++) {
  15953. if (is(key, entries[ii][0])) {
  15954. return entries[ii][1];
  15955. }
  15956. }
  15957. return notSetValue;
  15958. };
  15959. HashCollisionNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  15960. if (keyHash === undefined) {
  15961. keyHash = hash(key);
  15962. }
  15963. var removed = value === NOT_SET;
  15964. if (keyHash !== this.keyHash) {
  15965. if (removed) {
  15966. return this;
  15967. }
  15968. SetRef(didAlter);
  15969. SetRef(didChangeSize);
  15970. return mergeIntoNode(this, ownerID, shift, keyHash, [key, value]);
  15971. }
  15972. var entries = this.entries;
  15973. var idx = 0;
  15974. for (var len = entries.length; idx < len; idx++) {
  15975. if (is(key, entries[idx][0])) {
  15976. break;
  15977. }
  15978. }
  15979. var exists = idx < len;
  15980. if (exists ? entries[idx][1] === value : removed) {
  15981. return this;
  15982. }
  15983. SetRef(didAlter);
  15984. (removed || !exists) && SetRef(didChangeSize);
  15985. if (removed && len === 2) {
  15986. return new ValueNode(ownerID, this.keyHash, entries[idx ^ 1]);
  15987. }
  15988. var isEditable = ownerID && ownerID === this.ownerID;
  15989. var newEntries = isEditable ? entries : arrCopy(entries);
  15990. if (exists) {
  15991. if (removed) {
  15992. idx === len - 1 ? newEntries.pop() : (newEntries[idx] = newEntries.pop());
  15993. } else {
  15994. newEntries[idx] = [key, value];
  15995. }
  15996. } else {
  15997. newEntries.push([key, value]);
  15998. }
  15999. if (isEditable) {
  16000. this.entries = newEntries;
  16001. return this;
  16002. }
  16003. return new HashCollisionNode(ownerID, this.keyHash, newEntries);
  16004. };
  16005. function ValueNode(ownerID, keyHash, entry) {
  16006. this.ownerID = ownerID;
  16007. this.keyHash = keyHash;
  16008. this.entry = entry;
  16009. }
  16010. ValueNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  16011. return is(key, this.entry[0]) ? this.entry[1] : notSetValue;
  16012. };
  16013. ValueNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  16014. var removed = value === NOT_SET;
  16015. var keyMatch = is(key, this.entry[0]);
  16016. if (keyMatch ? value === this.entry[1] : removed) {
  16017. return this;
  16018. }
  16019. SetRef(didAlter);
  16020. if (removed) {
  16021. SetRef(didChangeSize);
  16022. return; // undefined
  16023. }
  16024. if (keyMatch) {
  16025. if (ownerID && ownerID === this.ownerID) {
  16026. this.entry[1] = value;
  16027. return this;
  16028. }
  16029. return new ValueNode(ownerID, this.keyHash, [key, value]);
  16030. }
  16031. SetRef(didChangeSize);
  16032. return mergeIntoNode(this, ownerID, shift, hash(key), [key, value]);
  16033. };
  16034. // #pragma Iterators
  16035. ArrayMapNode.prototype.iterate =
  16036. HashCollisionNode.prototype.iterate = function (fn, reverse) {
  16037. var entries = this.entries;
  16038. for (var ii = 0, maxIndex = entries.length - 1; ii <= maxIndex; ii++) {
  16039. if (fn(entries[reverse ? maxIndex - ii : ii]) === false) {
  16040. return false;
  16041. }
  16042. }
  16043. };
  16044. BitmapIndexedNode.prototype.iterate =
  16045. HashArrayMapNode.prototype.iterate = function (fn, reverse) {
  16046. var nodes = this.nodes;
  16047. for (var ii = 0, maxIndex = nodes.length - 1; ii <= maxIndex; ii++) {
  16048. var node = nodes[reverse ? maxIndex - ii : ii];
  16049. if (node && node.iterate(fn, reverse) === false) {
  16050. return false;
  16051. }
  16052. }
  16053. };
  16054. ValueNode.prototype.iterate = function (fn, reverse) {
  16055. return fn(this.entry);
  16056. };
  16057. createClass(MapIterator, Iterator);
  16058. function MapIterator(map, type, reverse) {
  16059. this._type = type;
  16060. this._reverse = reverse;
  16061. this._stack = map._root && mapIteratorFrame(map._root);
  16062. }
  16063. MapIterator.prototype.next = function() {
  16064. var type = this._type;
  16065. var stack = this._stack;
  16066. while (stack) {
  16067. var node = stack.node;
  16068. var index = stack.index++;
  16069. var maxIndex;
  16070. if (node.entry) {
  16071. if (index === 0) {
  16072. return mapIteratorValue(type, node.entry);
  16073. }
  16074. } else if (node.entries) {
  16075. maxIndex = node.entries.length - 1;
  16076. if (index <= maxIndex) {
  16077. return mapIteratorValue(type, node.entries[this._reverse ? maxIndex - index : index]);
  16078. }
  16079. } else {
  16080. maxIndex = node.nodes.length - 1;
  16081. if (index <= maxIndex) {
  16082. var subNode = node.nodes[this._reverse ? maxIndex - index : index];
  16083. if (subNode) {
  16084. if (subNode.entry) {
  16085. return mapIteratorValue(type, subNode.entry);
  16086. }
  16087. stack = this._stack = mapIteratorFrame(subNode, stack);
  16088. }
  16089. continue;
  16090. }
  16091. }
  16092. stack = this._stack = this._stack.__prev;
  16093. }
  16094. return iteratorDone();
  16095. };
  16096. function mapIteratorValue(type, entry) {
  16097. return iteratorValue(type, entry[0], entry[1]);
  16098. }
  16099. function mapIteratorFrame(node, prev) {
  16100. return {
  16101. node: node,
  16102. index: 0,
  16103. __prev: prev
  16104. };
  16105. }
  16106. function makeMap(size, root, ownerID, hash) {
  16107. var map = Object.create(MapPrototype);
  16108. map.size = size;
  16109. map._root = root;
  16110. map.__ownerID = ownerID;
  16111. map.__hash = hash;
  16112. map.__altered = false;
  16113. return map;
  16114. }
  16115. var EMPTY_MAP;
  16116. function emptyMap() {
  16117. return EMPTY_MAP || (EMPTY_MAP = makeMap(0));
  16118. }
  16119. function updateMap(map, k, v) {
  16120. var newRoot;
  16121. var newSize;
  16122. if (!map._root) {
  16123. if (v === NOT_SET) {
  16124. return map;
  16125. }
  16126. newSize = 1;
  16127. newRoot = new ArrayMapNode(map.__ownerID, [[k, v]]);
  16128. } else {
  16129. var didChangeSize = MakeRef(CHANGE_LENGTH);
  16130. var didAlter = MakeRef(DID_ALTER);
  16131. newRoot = updateNode(map._root, map.__ownerID, 0, undefined, k, v, didChangeSize, didAlter);
  16132. if (!didAlter.value) {
  16133. return map;
  16134. }
  16135. newSize = map.size + (didChangeSize.value ? v === NOT_SET ? -1 : 1 : 0);
  16136. }
  16137. if (map.__ownerID) {
  16138. map.size = newSize;
  16139. map._root = newRoot;
  16140. map.__hash = undefined;
  16141. map.__altered = true;
  16142. return map;
  16143. }
  16144. return newRoot ? makeMap(newSize, newRoot) : emptyMap();
  16145. }
  16146. function updateNode(node, ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  16147. if (!node) {
  16148. if (value === NOT_SET) {
  16149. return node;
  16150. }
  16151. SetRef(didAlter);
  16152. SetRef(didChangeSize);
  16153. return new ValueNode(ownerID, keyHash, [key, value]);
  16154. }
  16155. return node.update(ownerID, shift, keyHash, key, value, didChangeSize, didAlter);
  16156. }
  16157. function isLeafNode(node) {
  16158. return node.constructor === ValueNode || node.constructor === HashCollisionNode;
  16159. }
  16160. function mergeIntoNode(node, ownerID, shift, keyHash, entry) {
  16161. if (node.keyHash === keyHash) {
  16162. return new HashCollisionNode(ownerID, keyHash, [node.entry, entry]);
  16163. }
  16164. var idx1 = (shift === 0 ? node.keyHash : node.keyHash >>> shift) & MASK;
  16165. var idx2 = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  16166. var newNode;
  16167. var nodes = idx1 === idx2 ?
  16168. [mergeIntoNode(node, ownerID, shift + SHIFT, keyHash, entry)] :
  16169. ((newNode = new ValueNode(ownerID, keyHash, entry)), idx1 < idx2 ? [node, newNode] : [newNode, node]);
  16170. return new BitmapIndexedNode(ownerID, (1 << idx1) | (1 << idx2), nodes);
  16171. }
  16172. function createNodes(ownerID, entries, key, value) {
  16173. if (!ownerID) {
  16174. ownerID = new OwnerID();
  16175. }
  16176. var node = new ValueNode(ownerID, hash(key), [key, value]);
  16177. for (var ii = 0; ii < entries.length; ii++) {
  16178. var entry = entries[ii];
  16179. node = node.update(ownerID, 0, undefined, entry[0], entry[1]);
  16180. }
  16181. return node;
  16182. }
  16183. function packNodes(ownerID, nodes, count, excluding) {
  16184. var bitmap = 0;
  16185. var packedII = 0;
  16186. var packedNodes = new Array(count);
  16187. for (var ii = 0, bit = 1, len = nodes.length; ii < len; ii++, bit <<= 1) {
  16188. var node = nodes[ii];
  16189. if (node !== undefined && ii !== excluding) {
  16190. bitmap |= bit;
  16191. packedNodes[packedII++] = node;
  16192. }
  16193. }
  16194. return new BitmapIndexedNode(ownerID, bitmap, packedNodes);
  16195. }
  16196. function expandNodes(ownerID, nodes, bitmap, including, node) {
  16197. var count = 0;
  16198. var expandedNodes = new Array(SIZE);
  16199. for (var ii = 0; bitmap !== 0; ii++, bitmap >>>= 1) {
  16200. expandedNodes[ii] = bitmap & 1 ? nodes[count++] : undefined;
  16201. }
  16202. expandedNodes[including] = node;
  16203. return new HashArrayMapNode(ownerID, count + 1, expandedNodes);
  16204. }
  16205. function mergeIntoMapWith(map, merger, iterables) {
  16206. var iters = [];
  16207. for (var ii = 0; ii < iterables.length; ii++) {
  16208. var value = iterables[ii];
  16209. var iter = KeyedIterable(value);
  16210. if (!isIterable(value)) {
  16211. iter = iter.map(function(v ) {return fromJS(v)});
  16212. }
  16213. iters.push(iter);
  16214. }
  16215. return mergeIntoCollectionWith(map, merger, iters);
  16216. }
  16217. function deepMerger(existing, value, key) {
  16218. return existing && existing.mergeDeep && isIterable(value) ?
  16219. existing.mergeDeep(value) :
  16220. is(existing, value) ? existing : value;
  16221. }
  16222. function deepMergerWith(merger) {
  16223. return function(existing, value, key) {
  16224. if (existing && existing.mergeDeepWith && isIterable(value)) {
  16225. return existing.mergeDeepWith(merger, value);
  16226. }
  16227. var nextValue = merger(existing, value, key);
  16228. return is(existing, nextValue) ? existing : nextValue;
  16229. };
  16230. }
  16231. function mergeIntoCollectionWith(collection, merger, iters) {
  16232. iters = iters.filter(function(x ) {return x.size !== 0});
  16233. if (iters.length === 0) {
  16234. return collection;
  16235. }
  16236. if (collection.size === 0 && !collection.__ownerID && iters.length === 1) {
  16237. return collection.constructor(iters[0]);
  16238. }
  16239. return collection.withMutations(function(collection ) {
  16240. var mergeIntoMap = merger ?
  16241. function(value, key) {
  16242. collection.update(key, NOT_SET, function(existing )
  16243. {return existing === NOT_SET ? value : merger(existing, value, key)}
  16244. );
  16245. } :
  16246. function(value, key) {
  16247. collection.set(key, value);
  16248. };
  16249. for (var ii = 0; ii < iters.length; ii++) {
  16250. iters[ii].forEach(mergeIntoMap);
  16251. }
  16252. });
  16253. }
  16254. function updateInDeepMap(existing, keyPathIter, notSetValue, updater) {
  16255. var isNotSet = existing === NOT_SET;
  16256. var step = keyPathIter.next();
  16257. if (step.done) {
  16258. var existingValue = isNotSet ? notSetValue : existing;
  16259. var newValue = updater(existingValue);
  16260. return newValue === existingValue ? existing : newValue;
  16261. }
  16262. invariant(
  16263. isNotSet || (existing && existing.set),
  16264. 'invalid keyPath'
  16265. );
  16266. var key = step.value;
  16267. var nextExisting = isNotSet ? NOT_SET : existing.get(key, NOT_SET);
  16268. var nextUpdated = updateInDeepMap(
  16269. nextExisting,
  16270. keyPathIter,
  16271. notSetValue,
  16272. updater
  16273. );
  16274. return nextUpdated === nextExisting ? existing :
  16275. nextUpdated === NOT_SET ? existing.remove(key) :
  16276. (isNotSet ? emptyMap() : existing).set(key, nextUpdated);
  16277. }
  16278. function popCount(x) {
  16279. x = x - ((x >> 1) & 0x55555555);
  16280. x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
  16281. x = (x + (x >> 4)) & 0x0f0f0f0f;
  16282. x = x + (x >> 8);
  16283. x = x + (x >> 16);
  16284. return x & 0x7f;
  16285. }
  16286. function setIn(array, idx, val, canEdit) {
  16287. var newArray = canEdit ? array : arrCopy(array);
  16288. newArray[idx] = val;
  16289. return newArray;
  16290. }
  16291. function spliceIn(array, idx, val, canEdit) {
  16292. var newLen = array.length + 1;
  16293. if (canEdit && idx + 1 === newLen) {
  16294. array[idx] = val;
  16295. return array;
  16296. }
  16297. var newArray = new Array(newLen);
  16298. var after = 0;
  16299. for (var ii = 0; ii < newLen; ii++) {
  16300. if (ii === idx) {
  16301. newArray[ii] = val;
  16302. after = -1;
  16303. } else {
  16304. newArray[ii] = array[ii + after];
  16305. }
  16306. }
  16307. return newArray;
  16308. }
  16309. function spliceOut(array, idx, canEdit) {
  16310. var newLen = array.length - 1;
  16311. if (canEdit && idx === newLen) {
  16312. array.pop();
  16313. return array;
  16314. }
  16315. var newArray = new Array(newLen);
  16316. var after = 0;
  16317. for (var ii = 0; ii < newLen; ii++) {
  16318. if (ii === idx) {
  16319. after = 1;
  16320. }
  16321. newArray[ii] = array[ii + after];
  16322. }
  16323. return newArray;
  16324. }
  16325. var MAX_ARRAY_MAP_SIZE = SIZE / 4;
  16326. var MAX_BITMAP_INDEXED_SIZE = SIZE / 2;
  16327. var MIN_HASH_ARRAY_MAP_SIZE = SIZE / 4;
  16328. createClass(List, IndexedCollection);
  16329. // @pragma Construction
  16330. function List(value) {
  16331. var empty = emptyList();
  16332. if (value === null || value === undefined) {
  16333. return empty;
  16334. }
  16335. if (isList(value)) {
  16336. return value;
  16337. }
  16338. var iter = IndexedIterable(value);
  16339. var size = iter.size;
  16340. if (size === 0) {
  16341. return empty;
  16342. }
  16343. assertNotInfinite(size);
  16344. if (size > 0 && size < SIZE) {
  16345. return makeList(0, size, SHIFT, null, new VNode(iter.toArray()));
  16346. }
  16347. return empty.withMutations(function(list ) {
  16348. list.setSize(size);
  16349. iter.forEach(function(v, i) {return list.set(i, v)});
  16350. });
  16351. }
  16352. List.of = function(/*...values*/) {
  16353. return this(arguments);
  16354. };
  16355. List.prototype.toString = function() {
  16356. return this.__toString('List [', ']');
  16357. };
  16358. // @pragma Access
  16359. List.prototype.get = function(index, notSetValue) {
  16360. index = wrapIndex(this, index);
  16361. if (index >= 0 && index < this.size) {
  16362. index += this._origin;
  16363. var node = listNodeFor(this, index);
  16364. return node && node.array[index & MASK];
  16365. }
  16366. return notSetValue;
  16367. };
  16368. // @pragma Modification
  16369. List.prototype.set = function(index, value) {
  16370. return updateList(this, index, value);
  16371. };
  16372. List.prototype.remove = function(index) {
  16373. return !this.has(index) ? this :
  16374. index === 0 ? this.shift() :
  16375. index === this.size - 1 ? this.pop() :
  16376. this.splice(index, 1);
  16377. };
  16378. List.prototype.insert = function(index, value) {
  16379. return this.splice(index, 0, value);
  16380. };
  16381. List.prototype.clear = function() {
  16382. if (this.size === 0) {
  16383. return this;
  16384. }
  16385. if (this.__ownerID) {
  16386. this.size = this._origin = this._capacity = 0;
  16387. this._level = SHIFT;
  16388. this._root = this._tail = null;
  16389. this.__hash = undefined;
  16390. this.__altered = true;
  16391. return this;
  16392. }
  16393. return emptyList();
  16394. };
  16395. List.prototype.push = function(/*...values*/) {
  16396. var values = arguments;
  16397. var oldSize = this.size;
  16398. return this.withMutations(function(list ) {
  16399. setListBounds(list, 0, oldSize + values.length);
  16400. for (var ii = 0; ii < values.length; ii++) {
  16401. list.set(oldSize + ii, values[ii]);
  16402. }
  16403. });
  16404. };
  16405. List.prototype.pop = function() {
  16406. return setListBounds(this, 0, -1);
  16407. };
  16408. List.prototype.unshift = function(/*...values*/) {
  16409. var values = arguments;
  16410. return this.withMutations(function(list ) {
  16411. setListBounds(list, -values.length);
  16412. for (var ii = 0; ii < values.length; ii++) {
  16413. list.set(ii, values[ii]);
  16414. }
  16415. });
  16416. };
  16417. List.prototype.shift = function() {
  16418. return setListBounds(this, 1);
  16419. };
  16420. // @pragma Composition
  16421. List.prototype.merge = function(/*...iters*/) {
  16422. return mergeIntoListWith(this, undefined, arguments);
  16423. };
  16424. List.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  16425. return mergeIntoListWith(this, merger, iters);
  16426. };
  16427. List.prototype.mergeDeep = function(/*...iters*/) {
  16428. return mergeIntoListWith(this, deepMerger, arguments);
  16429. };
  16430. List.prototype.mergeDeepWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  16431. return mergeIntoListWith(this, deepMergerWith(merger), iters);
  16432. };
  16433. List.prototype.setSize = function(size) {
  16434. return setListBounds(this, 0, size);
  16435. };
  16436. // @pragma Iteration
  16437. List.prototype.slice = function(begin, end) {
  16438. var size = this.size;
  16439. if (wholeSlice(begin, end, size)) {
  16440. return this;
  16441. }
  16442. return setListBounds(
  16443. this,
  16444. resolveBegin(begin, size),
  16445. resolveEnd(end, size)
  16446. );
  16447. };
  16448. List.prototype.__iterator = function(type, reverse) {
  16449. var index = 0;
  16450. var values = iterateList(this, reverse);
  16451. return new Iterator(function() {
  16452. var value = values();
  16453. return value === DONE ?
  16454. iteratorDone() :
  16455. iteratorValue(type, index++, value);
  16456. });
  16457. };
  16458. List.prototype.__iterate = function(fn, reverse) {
  16459. var index = 0;
  16460. var values = iterateList(this, reverse);
  16461. var value;
  16462. while ((value = values()) !== DONE) {
  16463. if (fn(value, index++, this) === false) {
  16464. break;
  16465. }
  16466. }
  16467. return index;
  16468. };
  16469. List.prototype.__ensureOwner = function(ownerID) {
  16470. if (ownerID === this.__ownerID) {
  16471. return this;
  16472. }
  16473. if (!ownerID) {
  16474. this.__ownerID = ownerID;
  16475. return this;
  16476. }
  16477. return makeList(this._origin, this._capacity, this._level, this._root, this._tail, ownerID, this.__hash);
  16478. };
  16479. function isList(maybeList) {
  16480. return !!(maybeList && maybeList[IS_LIST_SENTINEL]);
  16481. }
  16482. List.isList = isList;
  16483. var IS_LIST_SENTINEL = '@@__IMMUTABLE_LIST__@@';
  16484. var ListPrototype = List.prototype;
  16485. ListPrototype[IS_LIST_SENTINEL] = true;
  16486. ListPrototype[DELETE] = ListPrototype.remove;
  16487. ListPrototype.setIn = MapPrototype.setIn;
  16488. ListPrototype.deleteIn =
  16489. ListPrototype.removeIn = MapPrototype.removeIn;
  16490. ListPrototype.update = MapPrototype.update;
  16491. ListPrototype.updateIn = MapPrototype.updateIn;
  16492. ListPrototype.mergeIn = MapPrototype.mergeIn;
  16493. ListPrototype.mergeDeepIn = MapPrototype.mergeDeepIn;
  16494. ListPrototype.withMutations = MapPrototype.withMutations;
  16495. ListPrototype.asMutable = MapPrototype.asMutable;
  16496. ListPrototype.asImmutable = MapPrototype.asImmutable;
  16497. ListPrototype.wasAltered = MapPrototype.wasAltered;
  16498. function VNode(array, ownerID) {
  16499. this.array = array;
  16500. this.ownerID = ownerID;
  16501. }
  16502. // TODO: seems like these methods are very similar
  16503. VNode.prototype.removeBefore = function(ownerID, level, index) {
  16504. if (index === level ? 1 << level : this.array.length === 0) {
  16505. return this;
  16506. }
  16507. var originIndex = (index >>> level) & MASK;
  16508. if (originIndex >= this.array.length) {
  16509. return new VNode([], ownerID);
  16510. }
  16511. var removingFirst = originIndex === 0;
  16512. var newChild;
  16513. if (level > 0) {
  16514. var oldChild = this.array[originIndex];
  16515. newChild = oldChild && oldChild.removeBefore(ownerID, level - SHIFT, index);
  16516. if (newChild === oldChild && removingFirst) {
  16517. return this;
  16518. }
  16519. }
  16520. if (removingFirst && !newChild) {
  16521. return this;
  16522. }
  16523. var editable = editableVNode(this, ownerID);
  16524. if (!removingFirst) {
  16525. for (var ii = 0; ii < originIndex; ii++) {
  16526. editable.array[ii] = undefined;
  16527. }
  16528. }
  16529. if (newChild) {
  16530. editable.array[originIndex] = newChild;
  16531. }
  16532. return editable;
  16533. };
  16534. VNode.prototype.removeAfter = function(ownerID, level, index) {
  16535. if (index === (level ? 1 << level : 0) || this.array.length === 0) {
  16536. return this;
  16537. }
  16538. var sizeIndex = ((index - 1) >>> level) & MASK;
  16539. if (sizeIndex >= this.array.length) {
  16540. return this;
  16541. }
  16542. var newChild;
  16543. if (level > 0) {
  16544. var oldChild = this.array[sizeIndex];
  16545. newChild = oldChild && oldChild.removeAfter(ownerID, level - SHIFT, index);
  16546. if (newChild === oldChild && sizeIndex === this.array.length - 1) {
  16547. return this;
  16548. }
  16549. }
  16550. var editable = editableVNode(this, ownerID);
  16551. editable.array.splice(sizeIndex + 1);
  16552. if (newChild) {
  16553. editable.array[sizeIndex] = newChild;
  16554. }
  16555. return editable;
  16556. };
  16557. var DONE = {};
  16558. function iterateList(list, reverse) {
  16559. var left = list._origin;
  16560. var right = list._capacity;
  16561. var tailPos = getTailOffset(right);
  16562. var tail = list._tail;
  16563. return iterateNodeOrLeaf(list._root, list._level, 0);
  16564. function iterateNodeOrLeaf(node, level, offset) {
  16565. return level === 0 ?
  16566. iterateLeaf(node, offset) :
  16567. iterateNode(node, level, offset);
  16568. }
  16569. function iterateLeaf(node, offset) {
  16570. var array = offset === tailPos ? tail && tail.array : node && node.array;
  16571. var from = offset > left ? 0 : left - offset;
  16572. var to = right - offset;
  16573. if (to > SIZE) {
  16574. to = SIZE;
  16575. }
  16576. return function() {
  16577. if (from === to) {
  16578. return DONE;
  16579. }
  16580. var idx = reverse ? --to : from++;
  16581. return array && array[idx];
  16582. };
  16583. }
  16584. function iterateNode(node, level, offset) {
  16585. var values;
  16586. var array = node && node.array;
  16587. var from = offset > left ? 0 : (left - offset) >> level;
  16588. var to = ((right - offset) >> level) + 1;
  16589. if (to > SIZE) {
  16590. to = SIZE;
  16591. }
  16592. return function() {
  16593. do {
  16594. if (values) {
  16595. var value = values();
  16596. if (value !== DONE) {
  16597. return value;
  16598. }
  16599. values = null;
  16600. }
  16601. if (from === to) {
  16602. return DONE;
  16603. }
  16604. var idx = reverse ? --to : from++;
  16605. values = iterateNodeOrLeaf(
  16606. array && array[idx], level - SHIFT, offset + (idx << level)
  16607. );
  16608. } while (true);
  16609. };
  16610. }
  16611. }
  16612. function makeList(origin, capacity, level, root, tail, ownerID, hash) {
  16613. var list = Object.create(ListPrototype);
  16614. list.size = capacity - origin;
  16615. list._origin = origin;
  16616. list._capacity = capacity;
  16617. list._level = level;
  16618. list._root = root;
  16619. list._tail = tail;
  16620. list.__ownerID = ownerID;
  16621. list.__hash = hash;
  16622. list.__altered = false;
  16623. return list;
  16624. }
  16625. var EMPTY_LIST;
  16626. function emptyList() {
  16627. return EMPTY_LIST || (EMPTY_LIST = makeList(0, 0, SHIFT));
  16628. }
  16629. function updateList(list, index, value) {
  16630. index = wrapIndex(list, index);
  16631. if (index !== index) {
  16632. return list;
  16633. }
  16634. if (index >= list.size || index < 0) {
  16635. return list.withMutations(function(list ) {
  16636. index < 0 ?
  16637. setListBounds(list, index).set(0, value) :
  16638. setListBounds(list, 0, index + 1).set(index, value);
  16639. });
  16640. }
  16641. index += list._origin;
  16642. var newTail = list._tail;
  16643. var newRoot = list._root;
  16644. var didAlter = MakeRef(DID_ALTER);
  16645. if (index >= getTailOffset(list._capacity)) {
  16646. newTail = updateVNode(newTail, list.__ownerID, 0, index, value, didAlter);
  16647. } else {
  16648. newRoot = updateVNode(newRoot, list.__ownerID, list._level, index, value, didAlter);
  16649. }
  16650. if (!didAlter.value) {
  16651. return list;
  16652. }
  16653. if (list.__ownerID) {
  16654. list._root = newRoot;
  16655. list._tail = newTail;
  16656. list.__hash = undefined;
  16657. list.__altered = true;
  16658. return list;
  16659. }
  16660. return makeList(list._origin, list._capacity, list._level, newRoot, newTail);
  16661. }
  16662. function updateVNode(node, ownerID, level, index, value, didAlter) {
  16663. var idx = (index >>> level) & MASK;
  16664. var nodeHas = node && idx < node.array.length;
  16665. if (!nodeHas && value === undefined) {
  16666. return node;
  16667. }
  16668. var newNode;
  16669. if (level > 0) {
  16670. var lowerNode = node && node.array[idx];
  16671. var newLowerNode = updateVNode(lowerNode, ownerID, level - SHIFT, index, value, didAlter);
  16672. if (newLowerNode === lowerNode) {
  16673. return node;
  16674. }
  16675. newNode = editableVNode(node, ownerID);
  16676. newNode.array[idx] = newLowerNode;
  16677. return newNode;
  16678. }
  16679. if (nodeHas && node.array[idx] === value) {
  16680. return node;
  16681. }
  16682. SetRef(didAlter);
  16683. newNode = editableVNode(node, ownerID);
  16684. if (value === undefined && idx === newNode.array.length - 1) {
  16685. newNode.array.pop();
  16686. } else {
  16687. newNode.array[idx] = value;
  16688. }
  16689. return newNode;
  16690. }
  16691. function editableVNode(node, ownerID) {
  16692. if (ownerID && node && ownerID === node.ownerID) {
  16693. return node;
  16694. }
  16695. return new VNode(node ? node.array.slice() : [], ownerID);
  16696. }
  16697. function listNodeFor(list, rawIndex) {
  16698. if (rawIndex >= getTailOffset(list._capacity)) {
  16699. return list._tail;
  16700. }
  16701. if (rawIndex < 1 << (list._level + SHIFT)) {
  16702. var node = list._root;
  16703. var level = list._level;
  16704. while (node && level > 0) {
  16705. node = node.array[(rawIndex >>> level) & MASK];
  16706. level -= SHIFT;
  16707. }
  16708. return node;
  16709. }
  16710. }
  16711. function setListBounds(list, begin, end) {
  16712. // Sanitize begin & end using this shorthand for ToInt32(argument)
  16713. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  16714. if (begin !== undefined) {
  16715. begin = begin | 0;
  16716. }
  16717. if (end !== undefined) {
  16718. end = end | 0;
  16719. }
  16720. var owner = list.__ownerID || new OwnerID();
  16721. var oldOrigin = list._origin;
  16722. var oldCapacity = list._capacity;
  16723. var newOrigin = oldOrigin + begin;
  16724. var newCapacity = end === undefined ? oldCapacity : end < 0 ? oldCapacity + end : oldOrigin + end;
  16725. if (newOrigin === oldOrigin && newCapacity === oldCapacity) {
  16726. return list;
  16727. }
  16728. // If it's going to end after it starts, it's empty.
  16729. if (newOrigin >= newCapacity) {
  16730. return list.clear();
  16731. }
  16732. var newLevel = list._level;
  16733. var newRoot = list._root;
  16734. // New origin might need creating a higher root.
  16735. var offsetShift = 0;
  16736. while (newOrigin + offsetShift < 0) {
  16737. newRoot = new VNode(newRoot && newRoot.array.length ? [undefined, newRoot] : [], owner);
  16738. newLevel += SHIFT;
  16739. offsetShift += 1 << newLevel;
  16740. }
  16741. if (offsetShift) {
  16742. newOrigin += offsetShift;
  16743. oldOrigin += offsetShift;
  16744. newCapacity += offsetShift;
  16745. oldCapacity += offsetShift;
  16746. }
  16747. var oldTailOffset = getTailOffset(oldCapacity);
  16748. var newTailOffset = getTailOffset(newCapacity);
  16749. // New size might need creating a higher root.
  16750. while (newTailOffset >= 1 << (newLevel + SHIFT)) {
  16751. newRoot = new VNode(newRoot && newRoot.array.length ? [newRoot] : [], owner);
  16752. newLevel += SHIFT;
  16753. }
  16754. // Locate or create the new tail.
  16755. var oldTail = list._tail;
  16756. var newTail = newTailOffset < oldTailOffset ?
  16757. listNodeFor(list, newCapacity - 1) :
  16758. newTailOffset > oldTailOffset ? new VNode([], owner) : oldTail;
  16759. // Merge Tail into tree.
  16760. if (oldTail && newTailOffset > oldTailOffset && newOrigin < oldCapacity && oldTail.array.length) {
  16761. newRoot = editableVNode(newRoot, owner);
  16762. var node = newRoot;
  16763. for (var level = newLevel; level > SHIFT; level -= SHIFT) {
  16764. var idx = (oldTailOffset >>> level) & MASK;
  16765. node = node.array[idx] = editableVNode(node.array[idx], owner);
  16766. }
  16767. node.array[(oldTailOffset >>> SHIFT) & MASK] = oldTail;
  16768. }
  16769. // If the size has been reduced, there's a chance the tail needs to be trimmed.
  16770. if (newCapacity < oldCapacity) {
  16771. newTail = newTail && newTail.removeAfter(owner, 0, newCapacity);
  16772. }
  16773. // If the new origin is within the tail, then we do not need a root.
  16774. if (newOrigin >= newTailOffset) {
  16775. newOrigin -= newTailOffset;
  16776. newCapacity -= newTailOffset;
  16777. newLevel = SHIFT;
  16778. newRoot = null;
  16779. newTail = newTail && newTail.removeBefore(owner, 0, newOrigin);
  16780. // Otherwise, if the root has been trimmed, garbage collect.
  16781. } else if (newOrigin > oldOrigin || newTailOffset < oldTailOffset) {
  16782. offsetShift = 0;
  16783. // Identify the new top root node of the subtree of the old root.
  16784. while (newRoot) {
  16785. var beginIndex = (newOrigin >>> newLevel) & MASK;
  16786. if (beginIndex !== (newTailOffset >>> newLevel) & MASK) {
  16787. break;
  16788. }
  16789. if (beginIndex) {
  16790. offsetShift += (1 << newLevel) * beginIndex;
  16791. }
  16792. newLevel -= SHIFT;
  16793. newRoot = newRoot.array[beginIndex];
  16794. }
  16795. // Trim the new sides of the new root.
  16796. if (newRoot && newOrigin > oldOrigin) {
  16797. newRoot = newRoot.removeBefore(owner, newLevel, newOrigin - offsetShift);
  16798. }
  16799. if (newRoot && newTailOffset < oldTailOffset) {
  16800. newRoot = newRoot.removeAfter(owner, newLevel, newTailOffset - offsetShift);
  16801. }
  16802. if (offsetShift) {
  16803. newOrigin -= offsetShift;
  16804. newCapacity -= offsetShift;
  16805. }
  16806. }
  16807. if (list.__ownerID) {
  16808. list.size = newCapacity - newOrigin;
  16809. list._origin = newOrigin;
  16810. list._capacity = newCapacity;
  16811. list._level = newLevel;
  16812. list._root = newRoot;
  16813. list._tail = newTail;
  16814. list.__hash = undefined;
  16815. list.__altered = true;
  16816. return list;
  16817. }
  16818. return makeList(newOrigin, newCapacity, newLevel, newRoot, newTail);
  16819. }
  16820. function mergeIntoListWith(list, merger, iterables) {
  16821. var iters = [];
  16822. var maxSize = 0;
  16823. for (var ii = 0; ii < iterables.length; ii++) {
  16824. var value = iterables[ii];
  16825. var iter = IndexedIterable(value);
  16826. if (iter.size > maxSize) {
  16827. maxSize = iter.size;
  16828. }
  16829. if (!isIterable(value)) {
  16830. iter = iter.map(function(v ) {return fromJS(v)});
  16831. }
  16832. iters.push(iter);
  16833. }
  16834. if (maxSize > list.size) {
  16835. list = list.setSize(maxSize);
  16836. }
  16837. return mergeIntoCollectionWith(list, merger, iters);
  16838. }
  16839. function getTailOffset(size) {
  16840. return size < SIZE ? 0 : (((size - 1) >>> SHIFT) << SHIFT);
  16841. }
  16842. createClass(OrderedMap, Map);
  16843. // @pragma Construction
  16844. function OrderedMap(value) {
  16845. return value === null || value === undefined ? emptyOrderedMap() :
  16846. isOrderedMap(value) ? value :
  16847. emptyOrderedMap().withMutations(function(map ) {
  16848. var iter = KeyedIterable(value);
  16849. assertNotInfinite(iter.size);
  16850. iter.forEach(function(v, k) {return map.set(k, v)});
  16851. });
  16852. }
  16853. OrderedMap.of = function(/*...values*/) {
  16854. return this(arguments);
  16855. };
  16856. OrderedMap.prototype.toString = function() {
  16857. return this.__toString('OrderedMap {', '}');
  16858. };
  16859. // @pragma Access
  16860. OrderedMap.prototype.get = function(k, notSetValue) {
  16861. var index = this._map.get(k);
  16862. return index !== undefined ? this._list.get(index)[1] : notSetValue;
  16863. };
  16864. // @pragma Modification
  16865. OrderedMap.prototype.clear = function() {
  16866. if (this.size === 0) {
  16867. return this;
  16868. }
  16869. if (this.__ownerID) {
  16870. this.size = 0;
  16871. this._map.clear();
  16872. this._list.clear();
  16873. return this;
  16874. }
  16875. return emptyOrderedMap();
  16876. };
  16877. OrderedMap.prototype.set = function(k, v) {
  16878. return updateOrderedMap(this, k, v);
  16879. };
  16880. OrderedMap.prototype.remove = function(k) {
  16881. return updateOrderedMap(this, k, NOT_SET);
  16882. };
  16883. OrderedMap.prototype.wasAltered = function() {
  16884. return this._map.wasAltered() || this._list.wasAltered();
  16885. };
  16886. OrderedMap.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  16887. return this._list.__iterate(
  16888. function(entry ) {return entry && fn(entry[1], entry[0], this$0)},
  16889. reverse
  16890. );
  16891. };
  16892. OrderedMap.prototype.__iterator = function(type, reverse) {
  16893. return this._list.fromEntrySeq().__iterator(type, reverse);
  16894. };
  16895. OrderedMap.prototype.__ensureOwner = function(ownerID) {
  16896. if (ownerID === this.__ownerID) {
  16897. return this;
  16898. }
  16899. var newMap = this._map.__ensureOwner(ownerID);
  16900. var newList = this._list.__ensureOwner(ownerID);
  16901. if (!ownerID) {
  16902. this.__ownerID = ownerID;
  16903. this._map = newMap;
  16904. this._list = newList;
  16905. return this;
  16906. }
  16907. return makeOrderedMap(newMap, newList, ownerID, this.__hash);
  16908. };
  16909. function isOrderedMap(maybeOrderedMap) {
  16910. return isMap(maybeOrderedMap) && isOrdered(maybeOrderedMap);
  16911. }
  16912. OrderedMap.isOrderedMap = isOrderedMap;
  16913. OrderedMap.prototype[IS_ORDERED_SENTINEL] = true;
  16914. OrderedMap.prototype[DELETE] = OrderedMap.prototype.remove;
  16915. function makeOrderedMap(map, list, ownerID, hash) {
  16916. var omap = Object.create(OrderedMap.prototype);
  16917. omap.size = map ? map.size : 0;
  16918. omap._map = map;
  16919. omap._list = list;
  16920. omap.__ownerID = ownerID;
  16921. omap.__hash = hash;
  16922. return omap;
  16923. }
  16924. var EMPTY_ORDERED_MAP;
  16925. function emptyOrderedMap() {
  16926. return EMPTY_ORDERED_MAP || (EMPTY_ORDERED_MAP = makeOrderedMap(emptyMap(), emptyList()));
  16927. }
  16928. function updateOrderedMap(omap, k, v) {
  16929. var map = omap._map;
  16930. var list = omap._list;
  16931. var i = map.get(k);
  16932. var has = i !== undefined;
  16933. var newMap;
  16934. var newList;
  16935. if (v === NOT_SET) { // removed
  16936. if (!has) {
  16937. return omap;
  16938. }
  16939. if (list.size >= SIZE && list.size >= map.size * 2) {
  16940. newList = list.filter(function(entry, idx) {return entry !== undefined && i !== idx});
  16941. newMap = newList.toKeyedSeq().map(function(entry ) {return entry[0]}).flip().toMap();
  16942. if (omap.__ownerID) {
  16943. newMap.__ownerID = newList.__ownerID = omap.__ownerID;
  16944. }
  16945. } else {
  16946. newMap = map.remove(k);
  16947. newList = i === list.size - 1 ? list.pop() : list.set(i, undefined);
  16948. }
  16949. } else {
  16950. if (has) {
  16951. if (v === list.get(i)[1]) {
  16952. return omap;
  16953. }
  16954. newMap = map;
  16955. newList = list.set(i, [k, v]);
  16956. } else {
  16957. newMap = map.set(k, list.size);
  16958. newList = list.set(list.size, [k, v]);
  16959. }
  16960. }
  16961. if (omap.__ownerID) {
  16962. omap.size = newMap.size;
  16963. omap._map = newMap;
  16964. omap._list = newList;
  16965. omap.__hash = undefined;
  16966. return omap;
  16967. }
  16968. return makeOrderedMap(newMap, newList);
  16969. }
  16970. createClass(ToKeyedSequence, KeyedSeq);
  16971. function ToKeyedSequence(indexed, useKeys) {
  16972. this._iter = indexed;
  16973. this._useKeys = useKeys;
  16974. this.size = indexed.size;
  16975. }
  16976. ToKeyedSequence.prototype.get = function(key, notSetValue) {
  16977. return this._iter.get(key, notSetValue);
  16978. };
  16979. ToKeyedSequence.prototype.has = function(key) {
  16980. return this._iter.has(key);
  16981. };
  16982. ToKeyedSequence.prototype.valueSeq = function() {
  16983. return this._iter.valueSeq();
  16984. };
  16985. ToKeyedSequence.prototype.reverse = function() {var this$0 = this;
  16986. var reversedSequence = reverseFactory(this, true);
  16987. if (!this._useKeys) {
  16988. reversedSequence.valueSeq = function() {return this$0._iter.toSeq().reverse()};
  16989. }
  16990. return reversedSequence;
  16991. };
  16992. ToKeyedSequence.prototype.map = function(mapper, context) {var this$0 = this;
  16993. var mappedSequence = mapFactory(this, mapper, context);
  16994. if (!this._useKeys) {
  16995. mappedSequence.valueSeq = function() {return this$0._iter.toSeq().map(mapper, context)};
  16996. }
  16997. return mappedSequence;
  16998. };
  16999. ToKeyedSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  17000. var ii;
  17001. return this._iter.__iterate(
  17002. this._useKeys ?
  17003. function(v, k) {return fn(v, k, this$0)} :
  17004. ((ii = reverse ? resolveSize(this) : 0),
  17005. function(v ) {return fn(v, reverse ? --ii : ii++, this$0)}),
  17006. reverse
  17007. );
  17008. };
  17009. ToKeyedSequence.prototype.__iterator = function(type, reverse) {
  17010. if (this._useKeys) {
  17011. return this._iter.__iterator(type, reverse);
  17012. }
  17013. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  17014. var ii = reverse ? resolveSize(this) : 0;
  17015. return new Iterator(function() {
  17016. var step = iterator.next();
  17017. return step.done ? step :
  17018. iteratorValue(type, reverse ? --ii : ii++, step.value, step);
  17019. });
  17020. };
  17021. ToKeyedSequence.prototype[IS_ORDERED_SENTINEL] = true;
  17022. createClass(ToIndexedSequence, IndexedSeq);
  17023. function ToIndexedSequence(iter) {
  17024. this._iter = iter;
  17025. this.size = iter.size;
  17026. }
  17027. ToIndexedSequence.prototype.includes = function(value) {
  17028. return this._iter.includes(value);
  17029. };
  17030. ToIndexedSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  17031. var iterations = 0;
  17032. return this._iter.__iterate(function(v ) {return fn(v, iterations++, this$0)}, reverse);
  17033. };
  17034. ToIndexedSequence.prototype.__iterator = function(type, reverse) {
  17035. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  17036. var iterations = 0;
  17037. return new Iterator(function() {
  17038. var step = iterator.next();
  17039. return step.done ? step :
  17040. iteratorValue(type, iterations++, step.value, step)
  17041. });
  17042. };
  17043. createClass(ToSetSequence, SetSeq);
  17044. function ToSetSequence(iter) {
  17045. this._iter = iter;
  17046. this.size = iter.size;
  17047. }
  17048. ToSetSequence.prototype.has = function(key) {
  17049. return this._iter.includes(key);
  17050. };
  17051. ToSetSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  17052. return this._iter.__iterate(function(v ) {return fn(v, v, this$0)}, reverse);
  17053. };
  17054. ToSetSequence.prototype.__iterator = function(type, reverse) {
  17055. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  17056. return new Iterator(function() {
  17057. var step = iterator.next();
  17058. return step.done ? step :
  17059. iteratorValue(type, step.value, step.value, step);
  17060. });
  17061. };
  17062. createClass(FromEntriesSequence, KeyedSeq);
  17063. function FromEntriesSequence(entries) {
  17064. this._iter = entries;
  17065. this.size = entries.size;
  17066. }
  17067. FromEntriesSequence.prototype.entrySeq = function() {
  17068. return this._iter.toSeq();
  17069. };
  17070. FromEntriesSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  17071. return this._iter.__iterate(function(entry ) {
  17072. // Check if entry exists first so array access doesn't throw for holes
  17073. // in the parent iteration.
  17074. if (entry) {
  17075. validateEntry(entry);
  17076. var indexedIterable = isIterable(entry);
  17077. return fn(
  17078. indexedIterable ? entry.get(1) : entry[1],
  17079. indexedIterable ? entry.get(0) : entry[0],
  17080. this$0
  17081. );
  17082. }
  17083. }, reverse);
  17084. };
  17085. FromEntriesSequence.prototype.__iterator = function(type, reverse) {
  17086. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  17087. return new Iterator(function() {
  17088. while (true) {
  17089. var step = iterator.next();
  17090. if (step.done) {
  17091. return step;
  17092. }
  17093. var entry = step.value;
  17094. // Check if entry exists first so array access doesn't throw for holes
  17095. // in the parent iteration.
  17096. if (entry) {
  17097. validateEntry(entry);
  17098. var indexedIterable = isIterable(entry);
  17099. return iteratorValue(
  17100. type,
  17101. indexedIterable ? entry.get(0) : entry[0],
  17102. indexedIterable ? entry.get(1) : entry[1],
  17103. step
  17104. );
  17105. }
  17106. }
  17107. });
  17108. };
  17109. ToIndexedSequence.prototype.cacheResult =
  17110. ToKeyedSequence.prototype.cacheResult =
  17111. ToSetSequence.prototype.cacheResult =
  17112. FromEntriesSequence.prototype.cacheResult =
  17113. cacheResultThrough;
  17114. function flipFactory(iterable) {
  17115. var flipSequence = makeSequence(iterable);
  17116. flipSequence._iter = iterable;
  17117. flipSequence.size = iterable.size;
  17118. flipSequence.flip = function() {return iterable};
  17119. flipSequence.reverse = function () {
  17120. var reversedSequence = iterable.reverse.apply(this); // super.reverse()
  17121. reversedSequence.flip = function() {return iterable.reverse()};
  17122. return reversedSequence;
  17123. };
  17124. flipSequence.has = function(key ) {return iterable.includes(key)};
  17125. flipSequence.includes = function(key ) {return iterable.has(key)};
  17126. flipSequence.cacheResult = cacheResultThrough;
  17127. flipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  17128. return iterable.__iterate(function(v, k) {return fn(k, v, this$0) !== false}, reverse);
  17129. };
  17130. flipSequence.__iteratorUncached = function(type, reverse) {
  17131. if (type === ITERATE_ENTRIES) {
  17132. var iterator = iterable.__iterator(type, reverse);
  17133. return new Iterator(function() {
  17134. var step = iterator.next();
  17135. if (!step.done) {
  17136. var k = step.value[0];
  17137. step.value[0] = step.value[1];
  17138. step.value[1] = k;
  17139. }
  17140. return step;
  17141. });
  17142. }
  17143. return iterable.__iterator(
  17144. type === ITERATE_VALUES ? ITERATE_KEYS : ITERATE_VALUES,
  17145. reverse
  17146. );
  17147. };
  17148. return flipSequence;
  17149. }
  17150. function mapFactory(iterable, mapper, context) {
  17151. var mappedSequence = makeSequence(iterable);
  17152. mappedSequence.size = iterable.size;
  17153. mappedSequence.has = function(key ) {return iterable.has(key)};
  17154. mappedSequence.get = function(key, notSetValue) {
  17155. var v = iterable.get(key, NOT_SET);
  17156. return v === NOT_SET ?
  17157. notSetValue :
  17158. mapper.call(context, v, key, iterable);
  17159. };
  17160. mappedSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  17161. return iterable.__iterate(
  17162. function(v, k, c) {return fn(mapper.call(context, v, k, c), k, this$0) !== false},
  17163. reverse
  17164. );
  17165. };
  17166. mappedSequence.__iteratorUncached = function (type, reverse) {
  17167. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  17168. return new Iterator(function() {
  17169. var step = iterator.next();
  17170. if (step.done) {
  17171. return step;
  17172. }
  17173. var entry = step.value;
  17174. var key = entry[0];
  17175. return iteratorValue(
  17176. type,
  17177. key,
  17178. mapper.call(context, entry[1], key, iterable),
  17179. step
  17180. );
  17181. });
  17182. };
  17183. return mappedSequence;
  17184. }
  17185. function reverseFactory(iterable, useKeys) {
  17186. var reversedSequence = makeSequence(iterable);
  17187. reversedSequence._iter = iterable;
  17188. reversedSequence.size = iterable.size;
  17189. reversedSequence.reverse = function() {return iterable};
  17190. if (iterable.flip) {
  17191. reversedSequence.flip = function () {
  17192. var flipSequence = flipFactory(iterable);
  17193. flipSequence.reverse = function() {return iterable.flip()};
  17194. return flipSequence;
  17195. };
  17196. }
  17197. reversedSequence.get = function(key, notSetValue)
  17198. {return iterable.get(useKeys ? key : -1 - key, notSetValue)};
  17199. reversedSequence.has = function(key )
  17200. {return iterable.has(useKeys ? key : -1 - key)};
  17201. reversedSequence.includes = function(value ) {return iterable.includes(value)};
  17202. reversedSequence.cacheResult = cacheResultThrough;
  17203. reversedSequence.__iterate = function (fn, reverse) {var this$0 = this;
  17204. return iterable.__iterate(function(v, k) {return fn(v, k, this$0)}, !reverse);
  17205. };
  17206. reversedSequence.__iterator =
  17207. function(type, reverse) {return iterable.__iterator(type, !reverse)};
  17208. return reversedSequence;
  17209. }
  17210. function filterFactory(iterable, predicate, context, useKeys) {
  17211. var filterSequence = makeSequence(iterable);
  17212. if (useKeys) {
  17213. filterSequence.has = function(key ) {
  17214. var v = iterable.get(key, NOT_SET);
  17215. return v !== NOT_SET && !!predicate.call(context, v, key, iterable);
  17216. };
  17217. filterSequence.get = function(key, notSetValue) {
  17218. var v = iterable.get(key, NOT_SET);
  17219. return v !== NOT_SET && predicate.call(context, v, key, iterable) ?
  17220. v : notSetValue;
  17221. };
  17222. }
  17223. filterSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  17224. var iterations = 0;
  17225. iterable.__iterate(function(v, k, c) {
  17226. if (predicate.call(context, v, k, c)) {
  17227. iterations++;
  17228. return fn(v, useKeys ? k : iterations - 1, this$0);
  17229. }
  17230. }, reverse);
  17231. return iterations;
  17232. };
  17233. filterSequence.__iteratorUncached = function (type, reverse) {
  17234. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  17235. var iterations = 0;
  17236. return new Iterator(function() {
  17237. while (true) {
  17238. var step = iterator.next();
  17239. if (step.done) {
  17240. return step;
  17241. }
  17242. var entry = step.value;
  17243. var key = entry[0];
  17244. var value = entry[1];
  17245. if (predicate.call(context, value, key, iterable)) {
  17246. return iteratorValue(type, useKeys ? key : iterations++, value, step);
  17247. }
  17248. }
  17249. });
  17250. };
  17251. return filterSequence;
  17252. }
  17253. function countByFactory(iterable, grouper, context) {
  17254. var groups = Map().asMutable();
  17255. iterable.__iterate(function(v, k) {
  17256. groups.update(
  17257. grouper.call(context, v, k, iterable),
  17258. 0,
  17259. function(a ) {return a + 1}
  17260. );
  17261. });
  17262. return groups.asImmutable();
  17263. }
  17264. function groupByFactory(iterable, grouper, context) {
  17265. var isKeyedIter = isKeyed(iterable);
  17266. var groups = (isOrdered(iterable) ? OrderedMap() : Map()).asMutable();
  17267. iterable.__iterate(function(v, k) {
  17268. groups.update(
  17269. grouper.call(context, v, k, iterable),
  17270. function(a ) {return (a = a || [], a.push(isKeyedIter ? [k, v] : v), a)}
  17271. );
  17272. });
  17273. var coerce = iterableClass(iterable);
  17274. return groups.map(function(arr ) {return reify(iterable, coerce(arr))});
  17275. }
  17276. function sliceFactory(iterable, begin, end, useKeys) {
  17277. var originalSize = iterable.size;
  17278. // Sanitize begin & end using this shorthand for ToInt32(argument)
  17279. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  17280. if (begin !== undefined) {
  17281. begin = begin | 0;
  17282. }
  17283. if (end !== undefined) {
  17284. end = end | 0;
  17285. }
  17286. if (wholeSlice(begin, end, originalSize)) {
  17287. return iterable;
  17288. }
  17289. var resolvedBegin = resolveBegin(begin, originalSize);
  17290. var resolvedEnd = resolveEnd(end, originalSize);
  17291. // begin or end will be NaN if they were provided as negative numbers and
  17292. // this iterable's size is unknown. In that case, cache first so there is
  17293. // a known size and these do not resolve to NaN.
  17294. if (resolvedBegin !== resolvedBegin || resolvedEnd !== resolvedEnd) {
  17295. return sliceFactory(iterable.toSeq().cacheResult(), begin, end, useKeys);
  17296. }
  17297. // Note: resolvedEnd is undefined when the original sequence's length is
  17298. // unknown and this slice did not supply an end and should contain all
  17299. // elements after resolvedBegin.
  17300. // In that case, resolvedSize will be NaN and sliceSize will remain undefined.
  17301. var resolvedSize = resolvedEnd - resolvedBegin;
  17302. var sliceSize;
  17303. if (resolvedSize === resolvedSize) {
  17304. sliceSize = resolvedSize < 0 ? 0 : resolvedSize;
  17305. }
  17306. var sliceSeq = makeSequence(iterable);
  17307. // If iterable.size is undefined, the size of the realized sliceSeq is
  17308. // unknown at this point unless the number of items to slice is 0
  17309. sliceSeq.size = sliceSize === 0 ? sliceSize : iterable.size && sliceSize || undefined;
  17310. if (!useKeys && isSeq(iterable) && sliceSize >= 0) {
  17311. sliceSeq.get = function (index, notSetValue) {
  17312. index = wrapIndex(this, index);
  17313. return index >= 0 && index < sliceSize ?
  17314. iterable.get(index + resolvedBegin, notSetValue) :
  17315. notSetValue;
  17316. };
  17317. }
  17318. sliceSeq.__iterateUncached = function(fn, reverse) {var this$0 = this;
  17319. if (sliceSize === 0) {
  17320. return 0;
  17321. }
  17322. if (reverse) {
  17323. return this.cacheResult().__iterate(fn, reverse);
  17324. }
  17325. var skipped = 0;
  17326. var isSkipping = true;
  17327. var iterations = 0;
  17328. iterable.__iterate(function(v, k) {
  17329. if (!(isSkipping && (isSkipping = skipped++ < resolvedBegin))) {
  17330. iterations++;
  17331. return fn(v, useKeys ? k : iterations - 1, this$0) !== false &&
  17332. iterations !== sliceSize;
  17333. }
  17334. });
  17335. return iterations;
  17336. };
  17337. sliceSeq.__iteratorUncached = function(type, reverse) {
  17338. if (sliceSize !== 0 && reverse) {
  17339. return this.cacheResult().__iterator(type, reverse);
  17340. }
  17341. // Don't bother instantiating parent iterator if taking 0.
  17342. var iterator = sliceSize !== 0 && iterable.__iterator(type, reverse);
  17343. var skipped = 0;
  17344. var iterations = 0;
  17345. return new Iterator(function() {
  17346. while (skipped++ < resolvedBegin) {
  17347. iterator.next();
  17348. }
  17349. if (++iterations > sliceSize) {
  17350. return iteratorDone();
  17351. }
  17352. var step = iterator.next();
  17353. if (useKeys || type === ITERATE_VALUES) {
  17354. return step;
  17355. } else if (type === ITERATE_KEYS) {
  17356. return iteratorValue(type, iterations - 1, undefined, step);
  17357. } else {
  17358. return iteratorValue(type, iterations - 1, step.value[1], step);
  17359. }
  17360. });
  17361. };
  17362. return sliceSeq;
  17363. }
  17364. function takeWhileFactory(iterable, predicate, context) {
  17365. var takeSequence = makeSequence(iterable);
  17366. takeSequence.__iterateUncached = function(fn, reverse) {var this$0 = this;
  17367. if (reverse) {
  17368. return this.cacheResult().__iterate(fn, reverse);
  17369. }
  17370. var iterations = 0;
  17371. iterable.__iterate(function(v, k, c)
  17372. {return predicate.call(context, v, k, c) && ++iterations && fn(v, k, this$0)}
  17373. );
  17374. return iterations;
  17375. };
  17376. takeSequence.__iteratorUncached = function(type, reverse) {var this$0 = this;
  17377. if (reverse) {
  17378. return this.cacheResult().__iterator(type, reverse);
  17379. }
  17380. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  17381. var iterating = true;
  17382. return new Iterator(function() {
  17383. if (!iterating) {
  17384. return iteratorDone();
  17385. }
  17386. var step = iterator.next();
  17387. if (step.done) {
  17388. return step;
  17389. }
  17390. var entry = step.value;
  17391. var k = entry[0];
  17392. var v = entry[1];
  17393. if (!predicate.call(context, v, k, this$0)) {
  17394. iterating = false;
  17395. return iteratorDone();
  17396. }
  17397. return type === ITERATE_ENTRIES ? step :
  17398. iteratorValue(type, k, v, step);
  17399. });
  17400. };
  17401. return takeSequence;
  17402. }
  17403. function skipWhileFactory(iterable, predicate, context, useKeys) {
  17404. var skipSequence = makeSequence(iterable);
  17405. skipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  17406. if (reverse) {
  17407. return this.cacheResult().__iterate(fn, reverse);
  17408. }
  17409. var isSkipping = true;
  17410. var iterations = 0;
  17411. iterable.__iterate(function(v, k, c) {
  17412. if (!(isSkipping && (isSkipping = predicate.call(context, v, k, c)))) {
  17413. iterations++;
  17414. return fn(v, useKeys ? k : iterations - 1, this$0);
  17415. }
  17416. });
  17417. return iterations;
  17418. };
  17419. skipSequence.__iteratorUncached = function(type, reverse) {var this$0 = this;
  17420. if (reverse) {
  17421. return this.cacheResult().__iterator(type, reverse);
  17422. }
  17423. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  17424. var skipping = true;
  17425. var iterations = 0;
  17426. return new Iterator(function() {
  17427. var step, k, v;
  17428. do {
  17429. step = iterator.next();
  17430. if (step.done) {
  17431. if (useKeys || type === ITERATE_VALUES) {
  17432. return step;
  17433. } else if (type === ITERATE_KEYS) {
  17434. return iteratorValue(type, iterations++, undefined, step);
  17435. } else {
  17436. return iteratorValue(type, iterations++, step.value[1], step);
  17437. }
  17438. }
  17439. var entry = step.value;
  17440. k = entry[0];
  17441. v = entry[1];
  17442. skipping && (skipping = predicate.call(context, v, k, this$0));
  17443. } while (skipping);
  17444. return type === ITERATE_ENTRIES ? step :
  17445. iteratorValue(type, k, v, step);
  17446. });
  17447. };
  17448. return skipSequence;
  17449. }
  17450. function concatFactory(iterable, values) {
  17451. var isKeyedIterable = isKeyed(iterable);
  17452. var iters = [iterable].concat(values).map(function(v ) {
  17453. if (!isIterable(v)) {
  17454. v = isKeyedIterable ?
  17455. keyedSeqFromValue(v) :
  17456. indexedSeqFromValue(Array.isArray(v) ? v : [v]);
  17457. } else if (isKeyedIterable) {
  17458. v = KeyedIterable(v);
  17459. }
  17460. return v;
  17461. }).filter(function(v ) {return v.size !== 0});
  17462. if (iters.length === 0) {
  17463. return iterable;
  17464. }
  17465. if (iters.length === 1) {
  17466. var singleton = iters[0];
  17467. if (singleton === iterable ||
  17468. isKeyedIterable && isKeyed(singleton) ||
  17469. isIndexed(iterable) && isIndexed(singleton)) {
  17470. return singleton;
  17471. }
  17472. }
  17473. var concatSeq = new ArraySeq(iters);
  17474. if (isKeyedIterable) {
  17475. concatSeq = concatSeq.toKeyedSeq();
  17476. } else if (!isIndexed(iterable)) {
  17477. concatSeq = concatSeq.toSetSeq();
  17478. }
  17479. concatSeq = concatSeq.flatten(true);
  17480. concatSeq.size = iters.reduce(
  17481. function(sum, seq) {
  17482. if (sum !== undefined) {
  17483. var size = seq.size;
  17484. if (size !== undefined) {
  17485. return sum + size;
  17486. }
  17487. }
  17488. },
  17489. 0
  17490. );
  17491. return concatSeq;
  17492. }
  17493. function flattenFactory(iterable, depth, useKeys) {
  17494. var flatSequence = makeSequence(iterable);
  17495. flatSequence.__iterateUncached = function(fn, reverse) {
  17496. var iterations = 0;
  17497. var stopped = false;
  17498. function flatDeep(iter, currentDepth) {var this$0 = this;
  17499. iter.__iterate(function(v, k) {
  17500. if ((!depth || currentDepth < depth) && isIterable(v)) {
  17501. flatDeep(v, currentDepth + 1);
  17502. } else if (fn(v, useKeys ? k : iterations++, this$0) === false) {
  17503. stopped = true;
  17504. }
  17505. return !stopped;
  17506. }, reverse);
  17507. }
  17508. flatDeep(iterable, 0);
  17509. return iterations;
  17510. };
  17511. flatSequence.__iteratorUncached = function(type, reverse) {
  17512. var iterator = iterable.__iterator(type, reverse);
  17513. var stack = [];
  17514. var iterations = 0;
  17515. return new Iterator(function() {
  17516. while (iterator) {
  17517. var step = iterator.next();
  17518. if (step.done !== false) {
  17519. iterator = stack.pop();
  17520. continue;
  17521. }
  17522. var v = step.value;
  17523. if (type === ITERATE_ENTRIES) {
  17524. v = v[1];
  17525. }
  17526. if ((!depth || stack.length < depth) && isIterable(v)) {
  17527. stack.push(iterator);
  17528. iterator = v.__iterator(type, reverse);
  17529. } else {
  17530. return useKeys ? step : iteratorValue(type, iterations++, v, step);
  17531. }
  17532. }
  17533. return iteratorDone();
  17534. });
  17535. };
  17536. return flatSequence;
  17537. }
  17538. function flatMapFactory(iterable, mapper, context) {
  17539. var coerce = iterableClass(iterable);
  17540. return iterable.toSeq().map(
  17541. function(v, k) {return coerce(mapper.call(context, v, k, iterable))}
  17542. ).flatten(true);
  17543. }
  17544. function interposeFactory(iterable, separator) {
  17545. var interposedSequence = makeSequence(iterable);
  17546. interposedSequence.size = iterable.size && iterable.size * 2 -1;
  17547. interposedSequence.__iterateUncached = function(fn, reverse) {var this$0 = this;
  17548. var iterations = 0;
  17549. iterable.__iterate(function(v, k)
  17550. {return (!iterations || fn(separator, iterations++, this$0) !== false) &&
  17551. fn(v, iterations++, this$0) !== false},
  17552. reverse
  17553. );
  17554. return iterations;
  17555. };
  17556. interposedSequence.__iteratorUncached = function(type, reverse) {
  17557. var iterator = iterable.__iterator(ITERATE_VALUES, reverse);
  17558. var iterations = 0;
  17559. var step;
  17560. return new Iterator(function() {
  17561. if (!step || iterations % 2) {
  17562. step = iterator.next();
  17563. if (step.done) {
  17564. return step;
  17565. }
  17566. }
  17567. return iterations % 2 ?
  17568. iteratorValue(type, iterations++, separator) :
  17569. iteratorValue(type, iterations++, step.value, step);
  17570. });
  17571. };
  17572. return interposedSequence;
  17573. }
  17574. function sortFactory(iterable, comparator, mapper) {
  17575. if (!comparator) {
  17576. comparator = defaultComparator;
  17577. }
  17578. var isKeyedIterable = isKeyed(iterable);
  17579. var index = 0;
  17580. var entries = iterable.toSeq().map(
  17581. function(v, k) {return [k, v, index++, mapper ? mapper(v, k, iterable) : v]}
  17582. ).toArray();
  17583. entries.sort(function(a, b) {return comparator(a[3], b[3]) || a[2] - b[2]}).forEach(
  17584. isKeyedIterable ?
  17585. function(v, i) { entries[i].length = 2; } :
  17586. function(v, i) { entries[i] = v[1]; }
  17587. );
  17588. return isKeyedIterable ? KeyedSeq(entries) :
  17589. isIndexed(iterable) ? IndexedSeq(entries) :
  17590. SetSeq(entries);
  17591. }
  17592. function maxFactory(iterable, comparator, mapper) {
  17593. if (!comparator) {
  17594. comparator = defaultComparator;
  17595. }
  17596. if (mapper) {
  17597. var entry = iterable.toSeq()
  17598. .map(function(v, k) {return [v, mapper(v, k, iterable)]})
  17599. .reduce(function(a, b) {return maxCompare(comparator, a[1], b[1]) ? b : a});
  17600. return entry && entry[0];
  17601. } else {
  17602. return iterable.reduce(function(a, b) {return maxCompare(comparator, a, b) ? b : a});
  17603. }
  17604. }
  17605. function maxCompare(comparator, a, b) {
  17606. var comp = comparator(b, a);
  17607. // b is considered the new max if the comparator declares them equal, but
  17608. // they are not equal and b is in fact a nullish value.
  17609. return (comp === 0 && b !== a && (b === undefined || b === null || b !== b)) || comp > 0;
  17610. }
  17611. function zipWithFactory(keyIter, zipper, iters) {
  17612. var zipSequence = makeSequence(keyIter);
  17613. zipSequence.size = new ArraySeq(iters).map(function(i ) {return i.size}).min();
  17614. // Note: this a generic base implementation of __iterate in terms of
  17615. // __iterator which may be more generically useful in the future.
  17616. zipSequence.__iterate = function(fn, reverse) {
  17617. /* generic:
  17618. var iterator = this.__iterator(ITERATE_ENTRIES, reverse);
  17619. var step;
  17620. var iterations = 0;
  17621. while (!(step = iterator.next()).done) {
  17622. iterations++;
  17623. if (fn(step.value[1], step.value[0], this) === false) {
  17624. break;
  17625. }
  17626. }
  17627. return iterations;
  17628. */
  17629. // indexed:
  17630. var iterator = this.__iterator(ITERATE_VALUES, reverse);
  17631. var step;
  17632. var iterations = 0;
  17633. while (!(step = iterator.next()).done) {
  17634. if (fn(step.value, iterations++, this) === false) {
  17635. break;
  17636. }
  17637. }
  17638. return iterations;
  17639. };
  17640. zipSequence.__iteratorUncached = function(type, reverse) {
  17641. var iterators = iters.map(function(i )
  17642. {return (i = Iterable(i), getIterator(reverse ? i.reverse() : i))}
  17643. );
  17644. var iterations = 0;
  17645. var isDone = false;
  17646. return new Iterator(function() {
  17647. var steps;
  17648. if (!isDone) {
  17649. steps = iterators.map(function(i ) {return i.next()});
  17650. isDone = steps.some(function(s ) {return s.done});
  17651. }
  17652. if (isDone) {
  17653. return iteratorDone();
  17654. }
  17655. return iteratorValue(
  17656. type,
  17657. iterations++,
  17658. zipper.apply(null, steps.map(function(s ) {return s.value}))
  17659. );
  17660. });
  17661. };
  17662. return zipSequence
  17663. }
  17664. // #pragma Helper Functions
  17665. function reify(iter, seq) {
  17666. return isSeq(iter) ? seq : iter.constructor(seq);
  17667. }
  17668. function validateEntry(entry) {
  17669. if (entry !== Object(entry)) {
  17670. throw new TypeError('Expected [K, V] tuple: ' + entry);
  17671. }
  17672. }
  17673. function resolveSize(iter) {
  17674. assertNotInfinite(iter.size);
  17675. return ensureSize(iter);
  17676. }
  17677. function iterableClass(iterable) {
  17678. return isKeyed(iterable) ? KeyedIterable :
  17679. isIndexed(iterable) ? IndexedIterable :
  17680. SetIterable;
  17681. }
  17682. function makeSequence(iterable) {
  17683. return Object.create(
  17684. (
  17685. isKeyed(iterable) ? KeyedSeq :
  17686. isIndexed(iterable) ? IndexedSeq :
  17687. SetSeq
  17688. ).prototype
  17689. );
  17690. }
  17691. function cacheResultThrough() {
  17692. if (this._iter.cacheResult) {
  17693. this._iter.cacheResult();
  17694. this.size = this._iter.size;
  17695. return this;
  17696. } else {
  17697. return Seq.prototype.cacheResult.call(this);
  17698. }
  17699. }
  17700. function defaultComparator(a, b) {
  17701. return a > b ? 1 : a < b ? -1 : 0;
  17702. }
  17703. function forceIterator(keyPath) {
  17704. var iter = getIterator(keyPath);
  17705. if (!iter) {
  17706. // Array might not be iterable in this environment, so we need a fallback
  17707. // to our wrapped type.
  17708. if (!isArrayLike(keyPath)) {
  17709. throw new TypeError('Expected iterable or array-like: ' + keyPath);
  17710. }
  17711. iter = getIterator(Iterable(keyPath));
  17712. }
  17713. return iter;
  17714. }
  17715. createClass(Record, KeyedCollection);
  17716. function Record(defaultValues, name) {
  17717. var hasInitialized;
  17718. var RecordType = function Record(values) {
  17719. if (values instanceof RecordType) {
  17720. return values;
  17721. }
  17722. if (!(this instanceof RecordType)) {
  17723. return new RecordType(values);
  17724. }
  17725. if (!hasInitialized) {
  17726. hasInitialized = true;
  17727. var keys = Object.keys(defaultValues);
  17728. setProps(RecordTypePrototype, keys);
  17729. RecordTypePrototype.size = keys.length;
  17730. RecordTypePrototype._name = name;
  17731. RecordTypePrototype._keys = keys;
  17732. RecordTypePrototype._defaultValues = defaultValues;
  17733. }
  17734. this._map = Map(values);
  17735. };
  17736. var RecordTypePrototype = RecordType.prototype = Object.create(RecordPrototype);
  17737. RecordTypePrototype.constructor = RecordType;
  17738. return RecordType;
  17739. }
  17740. Record.prototype.toString = function() {
  17741. return this.__toString(recordName(this) + ' {', '}');
  17742. };
  17743. // @pragma Access
  17744. Record.prototype.has = function(k) {
  17745. return this._defaultValues.hasOwnProperty(k);
  17746. };
  17747. Record.prototype.get = function(k, notSetValue) {
  17748. if (!this.has(k)) {
  17749. return notSetValue;
  17750. }
  17751. var defaultVal = this._defaultValues[k];
  17752. return this._map ? this._map.get(k, defaultVal) : defaultVal;
  17753. };
  17754. // @pragma Modification
  17755. Record.prototype.clear = function() {
  17756. if (this.__ownerID) {
  17757. this._map && this._map.clear();
  17758. return this;
  17759. }
  17760. var RecordType = this.constructor;
  17761. return RecordType._empty || (RecordType._empty = makeRecord(this, emptyMap()));
  17762. };
  17763. Record.prototype.set = function(k, v) {
  17764. if (!this.has(k)) {
  17765. throw new Error('Cannot set unknown key "' + k + '" on ' + recordName(this));
  17766. }
  17767. var newMap = this._map && this._map.set(k, v);
  17768. if (this.__ownerID || newMap === this._map) {
  17769. return this;
  17770. }
  17771. return makeRecord(this, newMap);
  17772. };
  17773. Record.prototype.remove = function(k) {
  17774. if (!this.has(k)) {
  17775. return this;
  17776. }
  17777. var newMap = this._map && this._map.remove(k);
  17778. if (this.__ownerID || newMap === this._map) {
  17779. return this;
  17780. }
  17781. return makeRecord(this, newMap);
  17782. };
  17783. Record.prototype.wasAltered = function() {
  17784. return this._map.wasAltered();
  17785. };
  17786. Record.prototype.__iterator = function(type, reverse) {var this$0 = this;
  17787. return KeyedIterable(this._defaultValues).map(function(_, k) {return this$0.get(k)}).__iterator(type, reverse);
  17788. };
  17789. Record.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  17790. return KeyedIterable(this._defaultValues).map(function(_, k) {return this$0.get(k)}).__iterate(fn, reverse);
  17791. };
  17792. Record.prototype.__ensureOwner = function(ownerID) {
  17793. if (ownerID === this.__ownerID) {
  17794. return this;
  17795. }
  17796. var newMap = this._map && this._map.__ensureOwner(ownerID);
  17797. if (!ownerID) {
  17798. this.__ownerID = ownerID;
  17799. this._map = newMap;
  17800. return this;
  17801. }
  17802. return makeRecord(this, newMap, ownerID);
  17803. };
  17804. var RecordPrototype = Record.prototype;
  17805. RecordPrototype[DELETE] = RecordPrototype.remove;
  17806. RecordPrototype.deleteIn =
  17807. RecordPrototype.removeIn = MapPrototype.removeIn;
  17808. RecordPrototype.merge = MapPrototype.merge;
  17809. RecordPrototype.mergeWith = MapPrototype.mergeWith;
  17810. RecordPrototype.mergeIn = MapPrototype.mergeIn;
  17811. RecordPrototype.mergeDeep = MapPrototype.mergeDeep;
  17812. RecordPrototype.mergeDeepWith = MapPrototype.mergeDeepWith;
  17813. RecordPrototype.mergeDeepIn = MapPrototype.mergeDeepIn;
  17814. RecordPrototype.setIn = MapPrototype.setIn;
  17815. RecordPrototype.update = MapPrototype.update;
  17816. RecordPrototype.updateIn = MapPrototype.updateIn;
  17817. RecordPrototype.withMutations = MapPrototype.withMutations;
  17818. RecordPrototype.asMutable = MapPrototype.asMutable;
  17819. RecordPrototype.asImmutable = MapPrototype.asImmutable;
  17820. function makeRecord(likeRecord, map, ownerID) {
  17821. var record = Object.create(Object.getPrototypeOf(likeRecord));
  17822. record._map = map;
  17823. record.__ownerID = ownerID;
  17824. return record;
  17825. }
  17826. function recordName(record) {
  17827. return record._name || record.constructor.name || 'Record';
  17828. }
  17829. function setProps(prototype, names) {
  17830. try {
  17831. names.forEach(setProp.bind(undefined, prototype));
  17832. } catch (error) {
  17833. // Object.defineProperty failed. Probably IE8.
  17834. }
  17835. }
  17836. function setProp(prototype, name) {
  17837. Object.defineProperty(prototype, name, {
  17838. get: function() {
  17839. return this.get(name);
  17840. },
  17841. set: function(value) {
  17842. invariant(this.__ownerID, 'Cannot set on an immutable record.');
  17843. this.set(name, value);
  17844. }
  17845. });
  17846. }
  17847. createClass(Set, SetCollection);
  17848. // @pragma Construction
  17849. function Set(value) {
  17850. return value === null || value === undefined ? emptySet() :
  17851. isSet(value) && !isOrdered(value) ? value :
  17852. emptySet().withMutations(function(set ) {
  17853. var iter = SetIterable(value);
  17854. assertNotInfinite(iter.size);
  17855. iter.forEach(function(v ) {return set.add(v)});
  17856. });
  17857. }
  17858. Set.of = function(/*...values*/) {
  17859. return this(arguments);
  17860. };
  17861. Set.fromKeys = function(value) {
  17862. return this(KeyedIterable(value).keySeq());
  17863. };
  17864. Set.prototype.toString = function() {
  17865. return this.__toString('Set {', '}');
  17866. };
  17867. // @pragma Access
  17868. Set.prototype.has = function(value) {
  17869. return this._map.has(value);
  17870. };
  17871. // @pragma Modification
  17872. Set.prototype.add = function(value) {
  17873. return updateSet(this, this._map.set(value, true));
  17874. };
  17875. Set.prototype.remove = function(value) {
  17876. return updateSet(this, this._map.remove(value));
  17877. };
  17878. Set.prototype.clear = function() {
  17879. return updateSet(this, this._map.clear());
  17880. };
  17881. // @pragma Composition
  17882. Set.prototype.union = function() {var iters = SLICE$0.call(arguments, 0);
  17883. iters = iters.filter(function(x ) {return x.size !== 0});
  17884. if (iters.length === 0) {
  17885. return this;
  17886. }
  17887. if (this.size === 0 && !this.__ownerID && iters.length === 1) {
  17888. return this.constructor(iters[0]);
  17889. }
  17890. return this.withMutations(function(set ) {
  17891. for (var ii = 0; ii < iters.length; ii++) {
  17892. SetIterable(iters[ii]).forEach(function(value ) {return set.add(value)});
  17893. }
  17894. });
  17895. };
  17896. Set.prototype.intersect = function() {var iters = SLICE$0.call(arguments, 0);
  17897. if (iters.length === 0) {
  17898. return this;
  17899. }
  17900. iters = iters.map(function(iter ) {return SetIterable(iter)});
  17901. var originalSet = this;
  17902. return this.withMutations(function(set ) {
  17903. originalSet.forEach(function(value ) {
  17904. if (!iters.every(function(iter ) {return iter.includes(value)})) {
  17905. set.remove(value);
  17906. }
  17907. });
  17908. });
  17909. };
  17910. Set.prototype.subtract = function() {var iters = SLICE$0.call(arguments, 0);
  17911. if (iters.length === 0) {
  17912. return this;
  17913. }
  17914. iters = iters.map(function(iter ) {return SetIterable(iter)});
  17915. var originalSet = this;
  17916. return this.withMutations(function(set ) {
  17917. originalSet.forEach(function(value ) {
  17918. if (iters.some(function(iter ) {return iter.includes(value)})) {
  17919. set.remove(value);
  17920. }
  17921. });
  17922. });
  17923. };
  17924. Set.prototype.merge = function() {
  17925. return this.union.apply(this, arguments);
  17926. };
  17927. Set.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  17928. return this.union.apply(this, iters);
  17929. };
  17930. Set.prototype.sort = function(comparator) {
  17931. // Late binding
  17932. return OrderedSet(sortFactory(this, comparator));
  17933. };
  17934. Set.prototype.sortBy = function(mapper, comparator) {
  17935. // Late binding
  17936. return OrderedSet(sortFactory(this, comparator, mapper));
  17937. };
  17938. Set.prototype.wasAltered = function() {
  17939. return this._map.wasAltered();
  17940. };
  17941. Set.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  17942. return this._map.__iterate(function(_, k) {return fn(k, k, this$0)}, reverse);
  17943. };
  17944. Set.prototype.__iterator = function(type, reverse) {
  17945. return this._map.map(function(_, k) {return k}).__iterator(type, reverse);
  17946. };
  17947. Set.prototype.__ensureOwner = function(ownerID) {
  17948. if (ownerID === this.__ownerID) {
  17949. return this;
  17950. }
  17951. var newMap = this._map.__ensureOwner(ownerID);
  17952. if (!ownerID) {
  17953. this.__ownerID = ownerID;
  17954. this._map = newMap;
  17955. return this;
  17956. }
  17957. return this.__make(newMap, ownerID);
  17958. };
  17959. function isSet(maybeSet) {
  17960. return !!(maybeSet && maybeSet[IS_SET_SENTINEL]);
  17961. }
  17962. Set.isSet = isSet;
  17963. var IS_SET_SENTINEL = '@@__IMMUTABLE_SET__@@';
  17964. var SetPrototype = Set.prototype;
  17965. SetPrototype[IS_SET_SENTINEL] = true;
  17966. SetPrototype[DELETE] = SetPrototype.remove;
  17967. SetPrototype.mergeDeep = SetPrototype.merge;
  17968. SetPrototype.mergeDeepWith = SetPrototype.mergeWith;
  17969. SetPrototype.withMutations = MapPrototype.withMutations;
  17970. SetPrototype.asMutable = MapPrototype.asMutable;
  17971. SetPrototype.asImmutable = MapPrototype.asImmutable;
  17972. SetPrototype.__empty = emptySet;
  17973. SetPrototype.__make = makeSet;
  17974. function updateSet(set, newMap) {
  17975. if (set.__ownerID) {
  17976. set.size = newMap.size;
  17977. set._map = newMap;
  17978. return set;
  17979. }
  17980. return newMap === set._map ? set :
  17981. newMap.size === 0 ? set.__empty() :
  17982. set.__make(newMap);
  17983. }
  17984. function makeSet(map, ownerID) {
  17985. var set = Object.create(SetPrototype);
  17986. set.size = map ? map.size : 0;
  17987. set._map = map;
  17988. set.__ownerID = ownerID;
  17989. return set;
  17990. }
  17991. var EMPTY_SET;
  17992. function emptySet() {
  17993. return EMPTY_SET || (EMPTY_SET = makeSet(emptyMap()));
  17994. }
  17995. createClass(OrderedSet, Set);
  17996. // @pragma Construction
  17997. function OrderedSet(value) {
  17998. return value === null || value === undefined ? emptyOrderedSet() :
  17999. isOrderedSet(value) ? value :
  18000. emptyOrderedSet().withMutations(function(set ) {
  18001. var iter = SetIterable(value);
  18002. assertNotInfinite(iter.size);
  18003. iter.forEach(function(v ) {return set.add(v)});
  18004. });
  18005. }
  18006. OrderedSet.of = function(/*...values*/) {
  18007. return this(arguments);
  18008. };
  18009. OrderedSet.fromKeys = function(value) {
  18010. return this(KeyedIterable(value).keySeq());
  18011. };
  18012. OrderedSet.prototype.toString = function() {
  18013. return this.__toString('OrderedSet {', '}');
  18014. };
  18015. function isOrderedSet(maybeOrderedSet) {
  18016. return isSet(maybeOrderedSet) && isOrdered(maybeOrderedSet);
  18017. }
  18018. OrderedSet.isOrderedSet = isOrderedSet;
  18019. var OrderedSetPrototype = OrderedSet.prototype;
  18020. OrderedSetPrototype[IS_ORDERED_SENTINEL] = true;
  18021. OrderedSetPrototype.__empty = emptyOrderedSet;
  18022. OrderedSetPrototype.__make = makeOrderedSet;
  18023. function makeOrderedSet(map, ownerID) {
  18024. var set = Object.create(OrderedSetPrototype);
  18025. set.size = map ? map.size : 0;
  18026. set._map = map;
  18027. set.__ownerID = ownerID;
  18028. return set;
  18029. }
  18030. var EMPTY_ORDERED_SET;
  18031. function emptyOrderedSet() {
  18032. return EMPTY_ORDERED_SET || (EMPTY_ORDERED_SET = makeOrderedSet(emptyOrderedMap()));
  18033. }
  18034. createClass(Stack, IndexedCollection);
  18035. // @pragma Construction
  18036. function Stack(value) {
  18037. return value === null || value === undefined ? emptyStack() :
  18038. isStack(value) ? value :
  18039. emptyStack().unshiftAll(value);
  18040. }
  18041. Stack.of = function(/*...values*/) {
  18042. return this(arguments);
  18043. };
  18044. Stack.prototype.toString = function() {
  18045. return this.__toString('Stack [', ']');
  18046. };
  18047. // @pragma Access
  18048. Stack.prototype.get = function(index, notSetValue) {
  18049. var head = this._head;
  18050. index = wrapIndex(this, index);
  18051. while (head && index--) {
  18052. head = head.next;
  18053. }
  18054. return head ? head.value : notSetValue;
  18055. };
  18056. Stack.prototype.peek = function() {
  18057. return this._head && this._head.value;
  18058. };
  18059. // @pragma Modification
  18060. Stack.prototype.push = function(/*...values*/) {
  18061. if (arguments.length === 0) {
  18062. return this;
  18063. }
  18064. var newSize = this.size + arguments.length;
  18065. var head = this._head;
  18066. for (var ii = arguments.length - 1; ii >= 0; ii--) {
  18067. head = {
  18068. value: arguments[ii],
  18069. next: head
  18070. };
  18071. }
  18072. if (this.__ownerID) {
  18073. this.size = newSize;
  18074. this._head = head;
  18075. this.__hash = undefined;
  18076. this.__altered = true;
  18077. return this;
  18078. }
  18079. return makeStack(newSize, head);
  18080. };
  18081. Stack.prototype.pushAll = function(iter) {
  18082. iter = IndexedIterable(iter);
  18083. if (iter.size === 0) {
  18084. return this;
  18085. }
  18086. assertNotInfinite(iter.size);
  18087. var newSize = this.size;
  18088. var head = this._head;
  18089. iter.reverse().forEach(function(value ) {
  18090. newSize++;
  18091. head = {
  18092. value: value,
  18093. next: head
  18094. };
  18095. });
  18096. if (this.__ownerID) {
  18097. this.size = newSize;
  18098. this._head = head;
  18099. this.__hash = undefined;
  18100. this.__altered = true;
  18101. return this;
  18102. }
  18103. return makeStack(newSize, head);
  18104. };
  18105. Stack.prototype.pop = function() {
  18106. return this.slice(1);
  18107. };
  18108. Stack.prototype.unshift = function(/*...values*/) {
  18109. return this.push.apply(this, arguments);
  18110. };
  18111. Stack.prototype.unshiftAll = function(iter) {
  18112. return this.pushAll(iter);
  18113. };
  18114. Stack.prototype.shift = function() {
  18115. return this.pop.apply(this, arguments);
  18116. };
  18117. Stack.prototype.clear = function() {
  18118. if (this.size === 0) {
  18119. return this;
  18120. }
  18121. if (this.__ownerID) {
  18122. this.size = 0;
  18123. this._head = undefined;
  18124. this.__hash = undefined;
  18125. this.__altered = true;
  18126. return this;
  18127. }
  18128. return emptyStack();
  18129. };
  18130. Stack.prototype.slice = function(begin, end) {
  18131. if (wholeSlice(begin, end, this.size)) {
  18132. return this;
  18133. }
  18134. var resolvedBegin = resolveBegin(begin, this.size);
  18135. var resolvedEnd = resolveEnd(end, this.size);
  18136. if (resolvedEnd !== this.size) {
  18137. // super.slice(begin, end);
  18138. return IndexedCollection.prototype.slice.call(this, begin, end);
  18139. }
  18140. var newSize = this.size - resolvedBegin;
  18141. var head = this._head;
  18142. while (resolvedBegin--) {
  18143. head = head.next;
  18144. }
  18145. if (this.__ownerID) {
  18146. this.size = newSize;
  18147. this._head = head;
  18148. this.__hash = undefined;
  18149. this.__altered = true;
  18150. return this;
  18151. }
  18152. return makeStack(newSize, head);
  18153. };
  18154. // @pragma Mutability
  18155. Stack.prototype.__ensureOwner = function(ownerID) {
  18156. if (ownerID === this.__ownerID) {
  18157. return this;
  18158. }
  18159. if (!ownerID) {
  18160. this.__ownerID = ownerID;
  18161. this.__altered = false;
  18162. return this;
  18163. }
  18164. return makeStack(this.size, this._head, ownerID, this.__hash);
  18165. };
  18166. // @pragma Iteration
  18167. Stack.prototype.__iterate = function(fn, reverse) {
  18168. if (reverse) {
  18169. return this.reverse().__iterate(fn);
  18170. }
  18171. var iterations = 0;
  18172. var node = this._head;
  18173. while (node) {
  18174. if (fn(node.value, iterations++, this) === false) {
  18175. break;
  18176. }
  18177. node = node.next;
  18178. }
  18179. return iterations;
  18180. };
  18181. Stack.prototype.__iterator = function(type, reverse) {
  18182. if (reverse) {
  18183. return this.reverse().__iterator(type);
  18184. }
  18185. var iterations = 0;
  18186. var node = this._head;
  18187. return new Iterator(function() {
  18188. if (node) {
  18189. var value = node.value;
  18190. node = node.next;
  18191. return iteratorValue(type, iterations++, value);
  18192. }
  18193. return iteratorDone();
  18194. });
  18195. };
  18196. function isStack(maybeStack) {
  18197. return !!(maybeStack && maybeStack[IS_STACK_SENTINEL]);
  18198. }
  18199. Stack.isStack = isStack;
  18200. var IS_STACK_SENTINEL = '@@__IMMUTABLE_STACK__@@';
  18201. var StackPrototype = Stack.prototype;
  18202. StackPrototype[IS_STACK_SENTINEL] = true;
  18203. StackPrototype.withMutations = MapPrototype.withMutations;
  18204. StackPrototype.asMutable = MapPrototype.asMutable;
  18205. StackPrototype.asImmutable = MapPrototype.asImmutable;
  18206. StackPrototype.wasAltered = MapPrototype.wasAltered;
  18207. function makeStack(size, head, ownerID, hash) {
  18208. var map = Object.create(StackPrototype);
  18209. map.size = size;
  18210. map._head = head;
  18211. map.__ownerID = ownerID;
  18212. map.__hash = hash;
  18213. map.__altered = false;
  18214. return map;
  18215. }
  18216. var EMPTY_STACK;
  18217. function emptyStack() {
  18218. return EMPTY_STACK || (EMPTY_STACK = makeStack(0));
  18219. }
  18220. /**
  18221. * Contributes additional methods to a constructor
  18222. */
  18223. function mixin(ctor, methods) {
  18224. var keyCopier = function(key ) { ctor.prototype[key] = methods[key]; };
  18225. Object.keys(methods).forEach(keyCopier);
  18226. Object.getOwnPropertySymbols &&
  18227. Object.getOwnPropertySymbols(methods).forEach(keyCopier);
  18228. return ctor;
  18229. }
  18230. Iterable.Iterator = Iterator;
  18231. mixin(Iterable, {
  18232. // ### Conversion to other types
  18233. toArray: function() {
  18234. assertNotInfinite(this.size);
  18235. var array = new Array(this.size || 0);
  18236. this.valueSeq().__iterate(function(v, i) { array[i] = v; });
  18237. return array;
  18238. },
  18239. toIndexedSeq: function() {
  18240. return new ToIndexedSequence(this);
  18241. },
  18242. toJS: function() {
  18243. return this.toSeq().map(
  18244. function(value ) {return value && typeof value.toJS === 'function' ? value.toJS() : value}
  18245. ).__toJS();
  18246. },
  18247. toJSON: function() {
  18248. return this.toSeq().map(
  18249. function(value ) {return value && typeof value.toJSON === 'function' ? value.toJSON() : value}
  18250. ).__toJS();
  18251. },
  18252. toKeyedSeq: function() {
  18253. return new ToKeyedSequence(this, true);
  18254. },
  18255. toMap: function() {
  18256. // Use Late Binding here to solve the circular dependency.
  18257. return Map(this.toKeyedSeq());
  18258. },
  18259. toObject: function() {
  18260. assertNotInfinite(this.size);
  18261. var object = {};
  18262. this.__iterate(function(v, k) { object[k] = v; });
  18263. return object;
  18264. },
  18265. toOrderedMap: function() {
  18266. // Use Late Binding here to solve the circular dependency.
  18267. return OrderedMap(this.toKeyedSeq());
  18268. },
  18269. toOrderedSet: function() {
  18270. // Use Late Binding here to solve the circular dependency.
  18271. return OrderedSet(isKeyed(this) ? this.valueSeq() : this);
  18272. },
  18273. toSet: function() {
  18274. // Use Late Binding here to solve the circular dependency.
  18275. return Set(isKeyed(this) ? this.valueSeq() : this);
  18276. },
  18277. toSetSeq: function() {
  18278. return new ToSetSequence(this);
  18279. },
  18280. toSeq: function() {
  18281. return isIndexed(this) ? this.toIndexedSeq() :
  18282. isKeyed(this) ? this.toKeyedSeq() :
  18283. this.toSetSeq();
  18284. },
  18285. toStack: function() {
  18286. // Use Late Binding here to solve the circular dependency.
  18287. return Stack(isKeyed(this) ? this.valueSeq() : this);
  18288. },
  18289. toList: function() {
  18290. // Use Late Binding here to solve the circular dependency.
  18291. return List(isKeyed(this) ? this.valueSeq() : this);
  18292. },
  18293. // ### Common JavaScript methods and properties
  18294. toString: function() {
  18295. return '[Iterable]';
  18296. },
  18297. __toString: function(head, tail) {
  18298. if (this.size === 0) {
  18299. return head + tail;
  18300. }
  18301. return head + ' ' + this.toSeq().map(this.__toStringMapper).join(', ') + ' ' + tail;
  18302. },
  18303. // ### ES6 Collection methods (ES6 Array and Map)
  18304. concat: function() {var values = SLICE$0.call(arguments, 0);
  18305. return reify(this, concatFactory(this, values));
  18306. },
  18307. includes: function(searchValue) {
  18308. return this.some(function(value ) {return is(value, searchValue)});
  18309. },
  18310. entries: function() {
  18311. return this.__iterator(ITERATE_ENTRIES);
  18312. },
  18313. every: function(predicate, context) {
  18314. assertNotInfinite(this.size);
  18315. var returnValue = true;
  18316. this.__iterate(function(v, k, c) {
  18317. if (!predicate.call(context, v, k, c)) {
  18318. returnValue = false;
  18319. return false;
  18320. }
  18321. });
  18322. return returnValue;
  18323. },
  18324. filter: function(predicate, context) {
  18325. return reify(this, filterFactory(this, predicate, context, true));
  18326. },
  18327. find: function(predicate, context, notSetValue) {
  18328. var entry = this.findEntry(predicate, context);
  18329. return entry ? entry[1] : notSetValue;
  18330. },
  18331. findEntry: function(predicate, context) {
  18332. var found;
  18333. this.__iterate(function(v, k, c) {
  18334. if (predicate.call(context, v, k, c)) {
  18335. found = [k, v];
  18336. return false;
  18337. }
  18338. });
  18339. return found;
  18340. },
  18341. findLastEntry: function(predicate, context) {
  18342. return this.toSeq().reverse().findEntry(predicate, context);
  18343. },
  18344. forEach: function(sideEffect, context) {
  18345. assertNotInfinite(this.size);
  18346. return this.__iterate(context ? sideEffect.bind(context) : sideEffect);
  18347. },
  18348. join: function(separator) {
  18349. assertNotInfinite(this.size);
  18350. separator = separator !== undefined ? '' + separator : ',';
  18351. var joined = '';
  18352. var isFirst = true;
  18353. this.__iterate(function(v ) {
  18354. isFirst ? (isFirst = false) : (joined += separator);
  18355. joined += v !== null && v !== undefined ? v.toString() : '';
  18356. });
  18357. return joined;
  18358. },
  18359. keys: function() {
  18360. return this.__iterator(ITERATE_KEYS);
  18361. },
  18362. map: function(mapper, context) {
  18363. return reify(this, mapFactory(this, mapper, context));
  18364. },
  18365. reduce: function(reducer, initialReduction, context) {
  18366. assertNotInfinite(this.size);
  18367. var reduction;
  18368. var useFirst;
  18369. if (arguments.length < 2) {
  18370. useFirst = true;
  18371. } else {
  18372. reduction = initialReduction;
  18373. }
  18374. this.__iterate(function(v, k, c) {
  18375. if (useFirst) {
  18376. useFirst = false;
  18377. reduction = v;
  18378. } else {
  18379. reduction = reducer.call(context, reduction, v, k, c);
  18380. }
  18381. });
  18382. return reduction;
  18383. },
  18384. reduceRight: function(reducer, initialReduction, context) {
  18385. var reversed = this.toKeyedSeq().reverse();
  18386. return reversed.reduce.apply(reversed, arguments);
  18387. },
  18388. reverse: function() {
  18389. return reify(this, reverseFactory(this, true));
  18390. },
  18391. slice: function(begin, end) {
  18392. return reify(this, sliceFactory(this, begin, end, true));
  18393. },
  18394. some: function(predicate, context) {
  18395. return !this.every(not(predicate), context);
  18396. },
  18397. sort: function(comparator) {
  18398. return reify(this, sortFactory(this, comparator));
  18399. },
  18400. values: function() {
  18401. return this.__iterator(ITERATE_VALUES);
  18402. },
  18403. // ### More sequential methods
  18404. butLast: function() {
  18405. return this.slice(0, -1);
  18406. },
  18407. isEmpty: function() {
  18408. return this.size !== undefined ? this.size === 0 : !this.some(function() {return true});
  18409. },
  18410. count: function(predicate, context) {
  18411. return ensureSize(
  18412. predicate ? this.toSeq().filter(predicate, context) : this
  18413. );
  18414. },
  18415. countBy: function(grouper, context) {
  18416. return countByFactory(this, grouper, context);
  18417. },
  18418. equals: function(other) {
  18419. return deepEqual(this, other);
  18420. },
  18421. entrySeq: function() {
  18422. var iterable = this;
  18423. if (iterable._cache) {
  18424. // We cache as an entries array, so we can just return the cache!
  18425. return new ArraySeq(iterable._cache);
  18426. }
  18427. var entriesSequence = iterable.toSeq().map(entryMapper).toIndexedSeq();
  18428. entriesSequence.fromEntrySeq = function() {return iterable.toSeq()};
  18429. return entriesSequence;
  18430. },
  18431. filterNot: function(predicate, context) {
  18432. return this.filter(not(predicate), context);
  18433. },
  18434. findLast: function(predicate, context, notSetValue) {
  18435. return this.toKeyedSeq().reverse().find(predicate, context, notSetValue);
  18436. },
  18437. first: function() {
  18438. return this.find(returnTrue);
  18439. },
  18440. flatMap: function(mapper, context) {
  18441. return reify(this, flatMapFactory(this, mapper, context));
  18442. },
  18443. flatten: function(depth) {
  18444. return reify(this, flattenFactory(this, depth, true));
  18445. },
  18446. fromEntrySeq: function() {
  18447. return new FromEntriesSequence(this);
  18448. },
  18449. get: function(searchKey, notSetValue) {
  18450. return this.find(function(_, key) {return is(key, searchKey)}, undefined, notSetValue);
  18451. },
  18452. getIn: function(searchKeyPath, notSetValue) {
  18453. var nested = this;
  18454. // Note: in an ES6 environment, we would prefer:
  18455. // for (var key of searchKeyPath) {
  18456. var iter = forceIterator(searchKeyPath);
  18457. var step;
  18458. while (!(step = iter.next()).done) {
  18459. var key = step.value;
  18460. nested = nested && nested.get ? nested.get(key, NOT_SET) : NOT_SET;
  18461. if (nested === NOT_SET) {
  18462. return notSetValue;
  18463. }
  18464. }
  18465. return nested;
  18466. },
  18467. groupBy: function(grouper, context) {
  18468. return groupByFactory(this, grouper, context);
  18469. },
  18470. has: function(searchKey) {
  18471. return this.get(searchKey, NOT_SET) !== NOT_SET;
  18472. },
  18473. hasIn: function(searchKeyPath) {
  18474. return this.getIn(searchKeyPath, NOT_SET) !== NOT_SET;
  18475. },
  18476. isSubset: function(iter) {
  18477. iter = typeof iter.includes === 'function' ? iter : Iterable(iter);
  18478. return this.every(function(value ) {return iter.includes(value)});
  18479. },
  18480. isSuperset: function(iter) {
  18481. iter = typeof iter.isSubset === 'function' ? iter : Iterable(iter);
  18482. return iter.isSubset(this);
  18483. },
  18484. keySeq: function() {
  18485. return this.toSeq().map(keyMapper).toIndexedSeq();
  18486. },
  18487. last: function() {
  18488. return this.toSeq().reverse().first();
  18489. },
  18490. max: function(comparator) {
  18491. return maxFactory(this, comparator);
  18492. },
  18493. maxBy: function(mapper, comparator) {
  18494. return maxFactory(this, comparator, mapper);
  18495. },
  18496. min: function(comparator) {
  18497. return maxFactory(this, comparator ? neg(comparator) : defaultNegComparator);
  18498. },
  18499. minBy: function(mapper, comparator) {
  18500. return maxFactory(this, comparator ? neg(comparator) : defaultNegComparator, mapper);
  18501. },
  18502. rest: function() {
  18503. return this.slice(1);
  18504. },
  18505. skip: function(amount) {
  18506. return this.slice(Math.max(0, amount));
  18507. },
  18508. skipLast: function(amount) {
  18509. return reify(this, this.toSeq().reverse().skip(amount).reverse());
  18510. },
  18511. skipWhile: function(predicate, context) {
  18512. return reify(this, skipWhileFactory(this, predicate, context, true));
  18513. },
  18514. skipUntil: function(predicate, context) {
  18515. return this.skipWhile(not(predicate), context);
  18516. },
  18517. sortBy: function(mapper, comparator) {
  18518. return reify(this, sortFactory(this, comparator, mapper));
  18519. },
  18520. take: function(amount) {
  18521. return this.slice(0, Math.max(0, amount));
  18522. },
  18523. takeLast: function(amount) {
  18524. return reify(this, this.toSeq().reverse().take(amount).reverse());
  18525. },
  18526. takeWhile: function(predicate, context) {
  18527. return reify(this, takeWhileFactory(this, predicate, context));
  18528. },
  18529. takeUntil: function(predicate, context) {
  18530. return this.takeWhile(not(predicate), context);
  18531. },
  18532. valueSeq: function() {
  18533. return this.toIndexedSeq();
  18534. },
  18535. // ### Hashable Object
  18536. hashCode: function() {
  18537. return this.__hash || (this.__hash = hashIterable(this));
  18538. }
  18539. // ### Internal
  18540. // abstract __iterate(fn, reverse)
  18541. // abstract __iterator(type, reverse)
  18542. });
  18543. // var IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
  18544. // var IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
  18545. // var IS_INDEXED_SENTINEL = '@@__IMMUTABLE_INDEXED__@@';
  18546. // var IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
  18547. var IterablePrototype = Iterable.prototype;
  18548. IterablePrototype[IS_ITERABLE_SENTINEL] = true;
  18549. IterablePrototype[ITERATOR_SYMBOL] = IterablePrototype.values;
  18550. IterablePrototype.__toJS = IterablePrototype.toArray;
  18551. IterablePrototype.__toStringMapper = quoteString;
  18552. IterablePrototype.inspect =
  18553. IterablePrototype.toSource = function() { return this.toString(); };
  18554. IterablePrototype.chain = IterablePrototype.flatMap;
  18555. IterablePrototype.contains = IterablePrototype.includes;
  18556. // Temporary warning about using length
  18557. (function () {
  18558. try {
  18559. Object.defineProperty(IterablePrototype, 'length', {
  18560. get: function () {
  18561. if (!Iterable.noLengthWarning) {
  18562. var stack;
  18563. try {
  18564. throw new Error();
  18565. } catch (error) {
  18566. stack = error.stack;
  18567. }
  18568. if (stack.indexOf('_wrapObject') === -1) {
  18569. console && console.warn && console.warn(
  18570. 'iterable.length has been deprecated, '+
  18571. 'use iterable.size or iterable.count(). '+
  18572. 'This warning will become a silent error in a future version. ' +
  18573. stack
  18574. );
  18575. return this.size;
  18576. }
  18577. }
  18578. }
  18579. });
  18580. } catch (e) {}
  18581. })();
  18582. mixin(KeyedIterable, {
  18583. // ### More sequential methods
  18584. flip: function() {
  18585. return reify(this, flipFactory(this));
  18586. },
  18587. findKey: function(predicate, context) {
  18588. var entry = this.findEntry(predicate, context);
  18589. return entry && entry[0];
  18590. },
  18591. findLastKey: function(predicate, context) {
  18592. return this.toSeq().reverse().findKey(predicate, context);
  18593. },
  18594. keyOf: function(searchValue) {
  18595. return this.findKey(function(value ) {return is(value, searchValue)});
  18596. },
  18597. lastKeyOf: function(searchValue) {
  18598. return this.findLastKey(function(value ) {return is(value, searchValue)});
  18599. },
  18600. mapEntries: function(mapper, context) {var this$0 = this;
  18601. var iterations = 0;
  18602. return reify(this,
  18603. this.toSeq().map(
  18604. function(v, k) {return mapper.call(context, [k, v], iterations++, this$0)}
  18605. ).fromEntrySeq()
  18606. );
  18607. },
  18608. mapKeys: function(mapper, context) {var this$0 = this;
  18609. return reify(this,
  18610. this.toSeq().flip().map(
  18611. function(k, v) {return mapper.call(context, k, v, this$0)}
  18612. ).flip()
  18613. );
  18614. }
  18615. });
  18616. var KeyedIterablePrototype = KeyedIterable.prototype;
  18617. KeyedIterablePrototype[IS_KEYED_SENTINEL] = true;
  18618. KeyedIterablePrototype[ITERATOR_SYMBOL] = IterablePrototype.entries;
  18619. KeyedIterablePrototype.__toJS = IterablePrototype.toObject;
  18620. KeyedIterablePrototype.__toStringMapper = function(v, k) {return JSON.stringify(k) + ': ' + quoteString(v)};
  18621. mixin(IndexedIterable, {
  18622. // ### Conversion to other types
  18623. toKeyedSeq: function() {
  18624. return new ToKeyedSequence(this, false);
  18625. },
  18626. // ### ES6 Collection methods (ES6 Array and Map)
  18627. filter: function(predicate, context) {
  18628. return reify(this, filterFactory(this, predicate, context, false));
  18629. },
  18630. findIndex: function(predicate, context) {
  18631. var entry = this.findEntry(predicate, context);
  18632. return entry ? entry[0] : -1;
  18633. },
  18634. indexOf: function(searchValue) {
  18635. var key = this.toKeyedSeq().keyOf(searchValue);
  18636. return key === undefined ? -1 : key;
  18637. },
  18638. lastIndexOf: function(searchValue) {
  18639. var key = this.toKeyedSeq().reverse().keyOf(searchValue);
  18640. return key === undefined ? -1 : key;
  18641. // var index =
  18642. // return this.toSeq().reverse().indexOf(searchValue);
  18643. },
  18644. reverse: function() {
  18645. return reify(this, reverseFactory(this, false));
  18646. },
  18647. slice: function(begin, end) {
  18648. return reify(this, sliceFactory(this, begin, end, false));
  18649. },
  18650. splice: function(index, removeNum /*, ...values*/) {
  18651. var numArgs = arguments.length;
  18652. removeNum = Math.max(removeNum | 0, 0);
  18653. if (numArgs === 0 || (numArgs === 2 && !removeNum)) {
  18654. return this;
  18655. }
  18656. // If index is negative, it should resolve relative to the size of the
  18657. // collection. However size may be expensive to compute if not cached, so
  18658. // only call count() if the number is in fact negative.
  18659. index = resolveBegin(index, index < 0 ? this.count() : this.size);
  18660. var spliced = this.slice(0, index);
  18661. return reify(
  18662. this,
  18663. numArgs === 1 ?
  18664. spliced :
  18665. spliced.concat(arrCopy(arguments, 2), this.slice(index + removeNum))
  18666. );
  18667. },
  18668. // ### More collection methods
  18669. findLastIndex: function(predicate, context) {
  18670. var key = this.toKeyedSeq().findLastKey(predicate, context);
  18671. return key === undefined ? -1 : key;
  18672. },
  18673. first: function() {
  18674. return this.get(0);
  18675. },
  18676. flatten: function(depth) {
  18677. return reify(this, flattenFactory(this, depth, false));
  18678. },
  18679. get: function(index, notSetValue) {
  18680. index = wrapIndex(this, index);
  18681. return (index < 0 || (this.size === Infinity ||
  18682. (this.size !== undefined && index > this.size))) ?
  18683. notSetValue :
  18684. this.find(function(_, key) {return key === index}, undefined, notSetValue);
  18685. },
  18686. has: function(index) {
  18687. index = wrapIndex(this, index);
  18688. return index >= 0 && (this.size !== undefined ?
  18689. this.size === Infinity || index < this.size :
  18690. this.indexOf(index) !== -1
  18691. );
  18692. },
  18693. interpose: function(separator) {
  18694. return reify(this, interposeFactory(this, separator));
  18695. },
  18696. interleave: function(/*...iterables*/) {
  18697. var iterables = [this].concat(arrCopy(arguments));
  18698. var zipped = zipWithFactory(this.toSeq(), IndexedSeq.of, iterables);
  18699. var interleaved = zipped.flatten(true);
  18700. if (zipped.size) {
  18701. interleaved.size = zipped.size * iterables.length;
  18702. }
  18703. return reify(this, interleaved);
  18704. },
  18705. last: function() {
  18706. return this.get(-1);
  18707. },
  18708. skipWhile: function(predicate, context) {
  18709. return reify(this, skipWhileFactory(this, predicate, context, false));
  18710. },
  18711. zip: function(/*, ...iterables */) {
  18712. var iterables = [this].concat(arrCopy(arguments));
  18713. return reify(this, zipWithFactory(this, defaultZipper, iterables));
  18714. },
  18715. zipWith: function(zipper/*, ...iterables */) {
  18716. var iterables = arrCopy(arguments);
  18717. iterables[0] = this;
  18718. return reify(this, zipWithFactory(this, zipper, iterables));
  18719. }
  18720. });
  18721. IndexedIterable.prototype[IS_INDEXED_SENTINEL] = true;
  18722. IndexedIterable.prototype[IS_ORDERED_SENTINEL] = true;
  18723. mixin(SetIterable, {
  18724. // ### ES6 Collection methods (ES6 Array and Map)
  18725. get: function(value, notSetValue) {
  18726. return this.has(value) ? value : notSetValue;
  18727. },
  18728. includes: function(value) {
  18729. return this.has(value);
  18730. },
  18731. // ### More sequential methods
  18732. keySeq: function() {
  18733. return this.valueSeq();
  18734. }
  18735. });
  18736. SetIterable.prototype.has = IterablePrototype.includes;
  18737. // Mixin subclasses
  18738. mixin(KeyedSeq, KeyedIterable.prototype);
  18739. mixin(IndexedSeq, IndexedIterable.prototype);
  18740. mixin(SetSeq, SetIterable.prototype);
  18741. mixin(KeyedCollection, KeyedIterable.prototype);
  18742. mixin(IndexedCollection, IndexedIterable.prototype);
  18743. mixin(SetCollection, SetIterable.prototype);
  18744. // #pragma Helper functions
  18745. function keyMapper(v, k) {
  18746. return k;
  18747. }
  18748. function entryMapper(v, k) {
  18749. return [k, v];
  18750. }
  18751. function not(predicate) {
  18752. return function() {
  18753. return !predicate.apply(this, arguments);
  18754. }
  18755. }
  18756. function neg(predicate) {
  18757. return function() {
  18758. return -predicate.apply(this, arguments);
  18759. }
  18760. }
  18761. function quoteString(value) {
  18762. return typeof value === 'string' ? JSON.stringify(value) : value;
  18763. }
  18764. function defaultZipper() {
  18765. return arrCopy(arguments);
  18766. }
  18767. function defaultNegComparator(a, b) {
  18768. return a < b ? 1 : a > b ? -1 : 0;
  18769. }
  18770. function hashIterable(iterable) {
  18771. if (iterable.size === Infinity) {
  18772. return 0;
  18773. }
  18774. var ordered = isOrdered(iterable);
  18775. var keyed = isKeyed(iterable);
  18776. var h = ordered ? 1 : 0;
  18777. var size = iterable.__iterate(
  18778. keyed ?
  18779. ordered ?
  18780. function(v, k) { h = 31 * h + hashMerge(hash(v), hash(k)) | 0; } :
  18781. function(v, k) { h = h + hashMerge(hash(v), hash(k)) | 0; } :
  18782. ordered ?
  18783. function(v ) { h = 31 * h + hash(v) | 0; } :
  18784. function(v ) { h = h + hash(v) | 0; }
  18785. );
  18786. return murmurHashOfSize(size, h);
  18787. }
  18788. function murmurHashOfSize(size, h) {
  18789. h = imul(h, 0xCC9E2D51);
  18790. h = imul(h << 15 | h >>> -15, 0x1B873593);
  18791. h = imul(h << 13 | h >>> -13, 5);
  18792. h = (h + 0xE6546B64 | 0) ^ size;
  18793. h = imul(h ^ h >>> 16, 0x85EBCA6B);
  18794. h = imul(h ^ h >>> 13, 0xC2B2AE35);
  18795. h = smi(h ^ h >>> 16);
  18796. return h;
  18797. }
  18798. function hashMerge(a, b) {
  18799. return a ^ b + 0x9E3779B9 + (a << 6) + (a >> 2) | 0; // int
  18800. }
  18801. var Immutable = {
  18802. Iterable: Iterable,
  18803. Seq: Seq,
  18804. Collection: Collection,
  18805. Map: Map,
  18806. OrderedMap: OrderedMap,
  18807. List: List,
  18808. Stack: Stack,
  18809. Set: Set,
  18810. OrderedSet: OrderedSet,
  18811. Record: Record,
  18812. Range: Range,
  18813. Repeat: Repeat,
  18814. is: is,
  18815. fromJS: fromJS
  18816. };
  18817. return Immutable;
  18818. }));
  18819. });
  18820. var draftjsUtils = createCommonjsModule(function (module, exports) {
  18821. !function(e,t){module.exports=t(Draft,immutable$1);}("undefined"!=typeof self?self: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);}])});
  18822. });
  18823. unwrapExports(draftjsUtils);
  18824. var draftjsUtils_1 = draftjsUtils.draftjsUtils;
  18825. var interopRequireDefault = createCommonjsModule(function (module) {
  18826. function _interopRequireDefault(obj) {
  18827. return obj && obj.__esModule ? obj : {
  18828. "default": obj
  18829. };
  18830. }
  18831. module.exports = _interopRequireDefault;
  18832. });
  18833. unwrapExports(interopRequireDefault);
  18834. /**
  18835. * Copyright (c) 2013-present, Facebook, Inc.
  18836. *
  18837. * This source code is licensed under the MIT license found in the
  18838. * LICENSE file in the root directory of this source tree.
  18839. */
  18840. /**
  18841. * Use invariant() to assert state which your program assumes to be true.
  18842. *
  18843. * Provide sprintf-style format (only %s is supported) and arguments
  18844. * to provide information about what broke and what you were
  18845. * expecting.
  18846. *
  18847. * The invariant message will be stripped in production, but the invariant
  18848. * will remain to ensure logic does not differ in production.
  18849. */
  18850. var invariant$1 = function(condition, format, a, b, c, d, e, f) {
  18851. if (process.env.NODE_ENV !== 'production') {
  18852. if (format === undefined) {
  18853. throw new Error('invariant requires an error message argument');
  18854. }
  18855. }
  18856. if (!condition) {
  18857. var error;
  18858. if (format === undefined) {
  18859. error = new Error(
  18860. 'Minified exception occurred; use the non-minified dev environment ' +
  18861. 'for the full error message and additional helpful warnings.'
  18862. );
  18863. } else {
  18864. var args = [a, b, c, d, e, f];
  18865. var argIndex = 0;
  18866. error = new Error(
  18867. format.replace(/%s/g, function() { return args[argIndex++]; })
  18868. );
  18869. error.name = 'Invariant Violation';
  18870. }
  18871. error.framesToPop = 1; // we don't care about invariant's own frame
  18872. throw error;
  18873. }
  18874. };
  18875. var browser = invariant$1;
  18876. function _arrayWithoutHoles(arr) {
  18877. if (Array.isArray(arr)) {
  18878. for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {
  18879. arr2[i] = arr[i];
  18880. }
  18881. return arr2;
  18882. }
  18883. }
  18884. var arrayWithoutHoles = _arrayWithoutHoles;
  18885. function _iterableToArray(iter) {
  18886. if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
  18887. }
  18888. var iterableToArray = _iterableToArray;
  18889. function _nonIterableSpread() {
  18890. throw new TypeError("Invalid attempt to spread non-iterable instance");
  18891. }
  18892. var nonIterableSpread = _nonIterableSpread;
  18893. function _toConsumableArray(arr) {
  18894. return arrayWithoutHoles(arr) || iterableToArray(arr) || nonIterableSpread();
  18895. }
  18896. var toConsumableArray = _toConsumableArray;
  18897. var updateMutation_1 = createCommonjsModule(function (module, exports) {
  18898. Object.defineProperty(exports, "__esModule", {
  18899. value: true
  18900. });
  18901. exports["default"] = updateMutation;
  18902. function updateMutation(mutation, originalOffset, originalLength, newLength, prefixLength, suffixLength) {
  18903. // three cases we can reasonably adjust - disjoint mutations that
  18904. // happen later on where the offset will need to be changed,
  18905. // mutations that completely contain the new one where we can adjust
  18906. // the length, and mutations that occur partially within the new one.
  18907. var lengthDiff = newLength - originalLength;
  18908. var mutationAfterChange = originalOffset + originalLength <= mutation.offset;
  18909. if (mutationAfterChange) {
  18910. return Object.assign({}, mutation, {
  18911. offset: mutation.offset + lengthDiff
  18912. });
  18913. }
  18914. var mutationContainsChange = originalOffset >= mutation.offset && originalOffset + originalLength <= mutation.offset + mutation.length;
  18915. if (mutationContainsChange) {
  18916. return Object.assign({}, mutation, {
  18917. length: mutation.length + lengthDiff
  18918. });
  18919. }
  18920. var mutationWithinPrefixChange = mutation.offset >= originalOffset && mutation.offset + mutation.length <= originalOffset + originalLength && prefixLength > 0;
  18921. if (mutationWithinPrefixChange) {
  18922. return Object.assign({}, mutation, {
  18923. offset: mutation.offset + prefixLength
  18924. });
  18925. }
  18926. var mutationContainsPrefix = mutation.offset < originalOffset && mutation.offset + mutation.length <= originalOffset + originalLength && mutation.offset + mutation.length > originalOffset && prefixLength > 0;
  18927. if (mutationContainsPrefix) {
  18928. return [Object.assign({}, mutation, {
  18929. length: originalOffset - mutation.offset
  18930. }), Object.assign({}, mutation, {
  18931. offset: originalOffset + prefixLength,
  18932. length: mutation.offset - originalOffset + mutation.length
  18933. })];
  18934. }
  18935. var mutationContainsSuffix = mutation.offset >= originalOffset && mutation.offset + mutation.length > originalOffset + originalLength && originalOffset + originalLength > mutation.offset && suffixLength > 0;
  18936. if (mutationContainsSuffix) {
  18937. return [Object.assign({}, mutation, {
  18938. offset: mutation.offset + prefixLength,
  18939. length: originalOffset + originalLength - mutation.offset
  18940. }), Object.assign({}, mutation, {
  18941. offset: originalOffset + originalLength + prefixLength + suffixLength,
  18942. length: mutation.offset + mutation.length - (originalOffset + originalLength)
  18943. })];
  18944. }
  18945. return mutation;
  18946. }
  18947. });
  18948. unwrapExports(updateMutation_1);
  18949. var rangeSort = createCommonjsModule(function (module, exports) {
  18950. Object.defineProperty(exports, "__esModule", {
  18951. value: true
  18952. });
  18953. exports["default"] = void 0;
  18954. var _default = function _default(r1, r2) {
  18955. if (r1.offset === r2.offset) {
  18956. return r2.length - r1.length;
  18957. }
  18958. return r1.offset - r2.offset;
  18959. };
  18960. exports["default"] = _default;
  18961. });
  18962. unwrapExports(rangeSort);
  18963. var encodeBlock = createCommonjsModule(function (module, exports) {
  18964. Object.defineProperty(exports, "__esModule", {
  18965. value: true
  18966. });
  18967. exports["default"] = void 0;
  18968. var _toConsumableArray2 = interopRequireDefault(toConsumableArray);
  18969. var _updateMutation = interopRequireDefault(updateMutation_1);
  18970. var _rangeSort = interopRequireDefault(rangeSort);
  18971. var ENTITY_MAP = {
  18972. '&': '&amp;',
  18973. '<': '&lt;',
  18974. '>': '&gt;',
  18975. '"': '&quot;',
  18976. "'": '&#x27;',
  18977. '`': '&#x60;',
  18978. '\n': '<br/>'
  18979. };
  18980. var _default = function _default(block) {
  18981. var blockText = (0, _toConsumableArray2["default"])(block.text);
  18982. var entities = block.entityRanges.sort(_rangeSort["default"]);
  18983. var styles = block.inlineStyleRanges.sort(_rangeSort["default"]);
  18984. var resultText = '';
  18985. var _loop = function _loop(index) {
  18986. var _char = blockText[index];
  18987. if (ENTITY_MAP[_char] !== undefined) {
  18988. var encoded = ENTITY_MAP[_char];
  18989. var resultIndex = (0, _toConsumableArray2["default"])(resultText).length;
  18990. resultText += encoded;
  18991. var updateForChar = function updateForChar(mutation) {
  18992. return (0, _updateMutation["default"])(mutation, resultIndex, _char.length, encoded.length, 0, 0);
  18993. };
  18994. entities = entities.map(updateForChar);
  18995. styles = styles.map(updateForChar);
  18996. } else {
  18997. resultText += _char;
  18998. }
  18999. };
  19000. for (var index = 0; index < blockText.length; index++) {
  19001. _loop(index);
  19002. }
  19003. return Object.assign({}, block, {
  19004. text: resultText,
  19005. inlineStyleRanges: styles,
  19006. entityRanges: entities
  19007. });
  19008. };
  19009. exports["default"] = _default;
  19010. });
  19011. unwrapExports(encodeBlock);
  19012. var _typeof_1 = createCommonjsModule(function (module) {
  19013. function _typeof(obj) {
  19014. "@babel/helpers - typeof";
  19015. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  19016. module.exports = _typeof = function _typeof(obj) {
  19017. return typeof obj;
  19018. };
  19019. } else {
  19020. module.exports = _typeof = function _typeof(obj) {
  19021. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  19022. };
  19023. }
  19024. return _typeof(obj);
  19025. }
  19026. module.exports = _typeof;
  19027. });
  19028. var splitReactElement_1 = createCommonjsModule(function (module, exports) {
  19029. Object.defineProperty(exports, "__esModule", {
  19030. value: true
  19031. });
  19032. exports["default"] = splitReactElement;
  19033. var _invariant = interopRequireDefault(browser);
  19034. var _react = interopRequireDefault(React);
  19035. var _server = interopRequireDefault(server);
  19036. // see http://w3c.github.io/html/syntax.html#writing-html-documents-elements
  19037. var VOID_TAGS = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr'];
  19038. function splitReactElement(element) {
  19039. if (VOID_TAGS.indexOf(element.type) !== -1) {
  19040. return _server["default"].renderToStaticMarkup(element);
  19041. }
  19042. var tags = _server["default"].renderToStaticMarkup(_react["default"].cloneElement(element, {}, '\r')).split('\r');
  19043. (0, _invariant["default"])(tags.length > 1, "convertToHTML: Element of type ".concat(element.type, " must render children"));
  19044. (0, _invariant["default"])(tags.length < 3, "convertToHTML: Element of type ".concat(element.type, " cannot use carriage return character"));
  19045. return {
  19046. start: tags[0],
  19047. end: tags[1]
  19048. };
  19049. }
  19050. });
  19051. unwrapExports(splitReactElement_1);
  19052. var getElementHTML_1 = createCommonjsModule(function (module, exports) {
  19053. Object.defineProperty(exports, "__esModule", {
  19054. value: true
  19055. });
  19056. exports["default"] = getElementHTML;
  19057. var _typeof2 = interopRequireDefault(_typeof_1);
  19058. var _invariant = interopRequireDefault(browser);
  19059. var _react = interopRequireDefault(React);
  19060. var _server = interopRequireDefault(server);
  19061. var _splitReactElement = interopRequireDefault(splitReactElement_1);
  19062. function hasChildren(element) {
  19063. return _react["default"].isValidElement(element) && _react["default"].Children.count(element.props.children) > 0;
  19064. }
  19065. function getElementHTML(element) {
  19066. var text = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  19067. if (element === undefined || element === null) {
  19068. return element;
  19069. }
  19070. if (typeof element === 'string') {
  19071. return element;
  19072. }
  19073. if (_react["default"].isValidElement(element)) {
  19074. if (hasChildren(element)) {
  19075. return _server["default"].renderToStaticMarkup(element);
  19076. }
  19077. var tags = (0, _splitReactElement["default"])(element);
  19078. if (text !== null && (0, _typeof2["default"])(tags) === 'object') {
  19079. var start = tags.start,
  19080. end = tags.end;
  19081. return start + text + end;
  19082. }
  19083. return tags;
  19084. }
  19085. (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');
  19086. if (text !== null) {
  19087. var _start = element.start,
  19088. _end = element.end;
  19089. return _start + text + _end;
  19090. }
  19091. return element;
  19092. }
  19093. });
  19094. unwrapExports(getElementHTML_1);
  19095. var getElementTagLength_1 = createCommonjsModule(function (module, exports) {
  19096. Object.defineProperty(exports, "__esModule", {
  19097. value: true
  19098. });
  19099. exports["default"] = void 0;
  19100. var _typeof2 = interopRequireDefault(_typeof_1);
  19101. var _react = interopRequireDefault(React);
  19102. var _splitReactElement = interopRequireDefault(splitReactElement_1);
  19103. var getElementTagLength = function getElementTagLength(element) {
  19104. var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'start';
  19105. if (_react["default"].isValidElement(element)) {
  19106. var splitElement = (0, _splitReactElement["default"])(element);
  19107. if (typeof splitElement === 'string') {
  19108. return 0;
  19109. }
  19110. var length = splitElement[type].length;
  19111. var child = _react["default"].Children.toArray(element.props.children)[0];
  19112. return length + (child && _react["default"].isValidElement(child) ? getElementTagLength(child, type) : 0);
  19113. }
  19114. if ((0, _typeof2["default"])(element) === 'object') {
  19115. return element[type] ? element[type].length : 0;
  19116. }
  19117. return 0;
  19118. };
  19119. var _default = getElementTagLength;
  19120. exports["default"] = _default;
  19121. });
  19122. unwrapExports(getElementTagLength_1);
  19123. var blockEntities = createCommonjsModule(function (module, exports) {
  19124. Object.defineProperty(exports, "__esModule", {
  19125. value: true
  19126. });
  19127. exports["default"] = void 0;
  19128. var _toConsumableArray2 = interopRequireDefault(toConsumableArray);
  19129. var _updateMutation = interopRequireDefault(updateMutation_1);
  19130. var _rangeSort = interopRequireDefault(rangeSort);
  19131. var _getElementHTML = interopRequireDefault(getElementHTML_1);
  19132. var _getElementTagLength = interopRequireDefault(getElementTagLength_1);
  19133. var converter = function converter() {
  19134. var originalText = arguments.length > 1 ? arguments[1] : undefined;
  19135. return originalText;
  19136. };
  19137. var _default = function _default(block, entityMap) {
  19138. var entityConverter = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : converter;
  19139. var resultText = (0, _toConsumableArray2["default"])(block.text);
  19140. var getEntityHTML = entityConverter;
  19141. if (entityConverter.__isMiddleware) {
  19142. getEntityHTML = entityConverter(converter);
  19143. }
  19144. if (Object.prototype.hasOwnProperty.call(block, 'entityRanges') && block.entityRanges.length > 0) {
  19145. var entities = block.entityRanges.sort(_rangeSort["default"]);
  19146. var styles = block.inlineStyleRanges;
  19147. var _loop = function _loop(index) {
  19148. var entityRange = entities[index];
  19149. var entity = entityMap[entityRange.key];
  19150. var originalText = resultText.slice(entityRange.offset, entityRange.offset + entityRange.length).join('');
  19151. var entityHTML = getEntityHTML(entity, originalText);
  19152. var converted = (0, _toConsumableArray2["default"])((0, _getElementHTML["default"])(entityHTML, originalText) || originalText);
  19153. var prefixLength = (0, _getElementTagLength["default"])(entityHTML, 'start');
  19154. var suffixLength = (0, _getElementTagLength["default"])(entityHTML, 'end');
  19155. var updateLaterMutation = function updateLaterMutation(mutation, mutationIndex) {
  19156. if (mutationIndex > index || Object.prototype.hasOwnProperty.call(mutation, 'style')) {
  19157. return (0, _updateMutation["default"])(mutation, entityRange.offset, entityRange.length, converted.length, prefixLength, suffixLength);
  19158. }
  19159. return mutation;
  19160. };
  19161. var updateLaterMutations = function updateLaterMutations(mutationList) {
  19162. return mutationList.reduce(function (acc, mutation, mutationIndex) {
  19163. var updatedMutation = updateLaterMutation(mutation, mutationIndex);
  19164. if (Array.isArray(updatedMutation)) {
  19165. return acc.concat(updatedMutation);
  19166. }
  19167. return acc.concat([updatedMutation]);
  19168. }, []);
  19169. };
  19170. entities = updateLaterMutations(entities);
  19171. styles = updateLaterMutations(styles);
  19172. resultText = [].concat((0, _toConsumableArray2["default"])(resultText.slice(0, entityRange.offset)), (0, _toConsumableArray2["default"])(converted), (0, _toConsumableArray2["default"])(resultText.slice(entityRange.offset + entityRange.length)));
  19173. };
  19174. for (var index = 0; index < entities.length; index++) {
  19175. _loop(index);
  19176. }
  19177. return Object.assign({}, block, {
  19178. text: resultText.join(''),
  19179. inlineStyleRanges: styles,
  19180. entityRanges: entities
  19181. });
  19182. }
  19183. return block;
  19184. };
  19185. exports["default"] = _default;
  19186. });
  19187. unwrapExports(blockEntities);
  19188. var styleObjectFunction = createCommonjsModule(function (module, exports) {
  19189. Object.defineProperty(exports, "__esModule", {
  19190. value: true
  19191. });
  19192. exports["default"] = void 0;
  19193. var _default = function _default(object) {
  19194. return function (style) {
  19195. if (typeof object === 'function') {
  19196. return object(style);
  19197. }
  19198. return object[style];
  19199. };
  19200. };
  19201. exports["default"] = _default;
  19202. });
  19203. unwrapExports(styleObjectFunction);
  19204. var accumulateFunction = createCommonjsModule(function (module, exports) {
  19205. Object.defineProperty(exports, "__esModule", {
  19206. value: true
  19207. });
  19208. exports["default"] = void 0;
  19209. var _default = function _default(newFn, rest) {
  19210. return function () {
  19211. var newResult = newFn.apply(void 0, arguments);
  19212. if (newResult !== undefined && newResult !== null) {
  19213. return newResult;
  19214. }
  19215. return rest.apply(void 0, arguments);
  19216. };
  19217. };
  19218. exports["default"] = _default;
  19219. });
  19220. unwrapExports(accumulateFunction);
  19221. var defaultInlineHTML_1 = createCommonjsModule(function (module, exports) {
  19222. Object.defineProperty(exports, "__esModule", {
  19223. value: true
  19224. });
  19225. exports["default"] = defaultInlineHTML;
  19226. var _react = interopRequireDefault(React);
  19227. function defaultInlineHTML(style) {
  19228. switch (style) {
  19229. case 'BOLD':
  19230. return _react["default"].createElement("strong", null);
  19231. case 'ITALIC':
  19232. return _react["default"].createElement("em", null);
  19233. case 'UNDERLINE':
  19234. return _react["default"].createElement("u", null);
  19235. case 'CODE':
  19236. return _react["default"].createElement("code", null);
  19237. default:
  19238. return {
  19239. start: '',
  19240. end: ''
  19241. };
  19242. }
  19243. }
  19244. });
  19245. unwrapExports(defaultInlineHTML_1);
  19246. var blockInlineStyles = createCommonjsModule(function (module, exports) {
  19247. Object.defineProperty(exports, "__esModule", {
  19248. value: true
  19249. });
  19250. exports["default"] = void 0;
  19251. var _toConsumableArray2 = interopRequireDefault(toConsumableArray);
  19252. var _invariant = interopRequireDefault(browser);
  19253. var _styleObjectFunction = interopRequireDefault(styleObjectFunction);
  19254. var _accumulateFunction = interopRequireDefault(accumulateFunction);
  19255. var _getElementHTML = interopRequireDefault(getElementHTML_1);
  19256. var _rangeSort = interopRequireDefault(rangeSort);
  19257. var _defaultInlineHTML = interopRequireDefault(defaultInlineHTML_1);
  19258. var subtractStyles = function subtractStyles(original, toRemove) {
  19259. return original.filter(function (el) {
  19260. return !toRemove.some(function (elToRemove) {
  19261. return elToRemove.style === el.style;
  19262. });
  19263. });
  19264. };
  19265. var popEndingStyles = function popEndingStyles(styleStack, endingStyles) {
  19266. return endingStyles.reduceRight(function (stack, style) {
  19267. var styleToRemove = stack[stack.length - 1];
  19268. (0, _invariant["default"])(styleToRemove.style === style.style, "Style ".concat(styleToRemove.style, " to be removed doesn't match expected ").concat(style.style));
  19269. return stack.slice(0, -1);
  19270. }, styleStack);
  19271. };
  19272. var characterStyles = function characterStyles(offset, ranges) {
  19273. return ranges.filter(function (range) {
  19274. return offset >= range.offset && offset < range.offset + range.length;
  19275. });
  19276. };
  19277. var rangeIsSubset = function rangeIsSubset(firstRange, secondRange) {
  19278. // returns true if the second range is a subset of the first
  19279. var secondStartWithinFirst = firstRange.offset <= secondRange.offset;
  19280. var secondEndWithinFirst = firstRange.offset + firstRange.length >= secondRange.offset + secondRange.length;
  19281. return secondStartWithinFirst && secondEndWithinFirst;
  19282. };
  19283. var latestStyleLast = function latestStyleLast(s1, s2) {
  19284. // make sure longer-lasting styles are added first
  19285. var s2endIndex = s2.offset + s2.length;
  19286. var s1endIndex = s1.offset + s1.length;
  19287. return s2endIndex - s1endIndex;
  19288. };
  19289. var getStylesToReset = function getStylesToReset(remainingStyles, newStyles) {
  19290. var i = 0;
  19291. while (i < remainingStyles.length) {
  19292. if (newStyles.every(rangeIsSubset.bind(null, remainingStyles[i]))) {
  19293. i++;
  19294. } else {
  19295. return remainingStyles.slice(i);
  19296. }
  19297. }
  19298. return [];
  19299. };
  19300. var appendStartMarkup = function appendStartMarkup(inlineHTML, string, styleRange) {
  19301. return string + (0, _getElementHTML["default"])(inlineHTML(styleRange.style)).start;
  19302. };
  19303. var prependEndMarkup = function prependEndMarkup(inlineHTML, string, styleRange) {
  19304. return (0, _getElementHTML["default"])(inlineHTML(styleRange.style)).end + string;
  19305. };
  19306. var defaultCustomInlineHTML = function defaultCustomInlineHTML(next) {
  19307. return function (style) {
  19308. return next(style);
  19309. };
  19310. };
  19311. defaultCustomInlineHTML.__isMiddleware = true;
  19312. var _default = function _default(rawBlock) {
  19313. var customInlineHTML = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultCustomInlineHTML;
  19314. (0, _invariant["default"])(rawBlock !== null && rawBlock !== undefined, 'Expected raw block to be non-null');
  19315. var inlineHTML;
  19316. if (customInlineHTML.__isMiddleware === true) {
  19317. inlineHTML = customInlineHTML(_defaultInlineHTML["default"]);
  19318. } else {
  19319. inlineHTML = (0, _accumulateFunction["default"])((0, _styleObjectFunction["default"])(customInlineHTML), (0, _styleObjectFunction["default"])(_defaultInlineHTML["default"]));
  19320. }
  19321. var result = '';
  19322. var styleStack = [];
  19323. var sortedRanges = rawBlock.inlineStyleRanges.sort(_rangeSort["default"]);
  19324. var originalTextArray = (0, _toConsumableArray2["default"])(rawBlock.text);
  19325. for (var i = 0; i < originalTextArray.length; i++) {
  19326. var styles = characterStyles(i, sortedRanges);
  19327. var endingStyles = subtractStyles(styleStack, styles);
  19328. var newStyles = subtractStyles(styles, styleStack);
  19329. var remainingStyles = subtractStyles(styleStack, endingStyles); // reset styles: look for any already existing styles that will need to
  19330. // end before styles that are being added on this character. to solve this
  19331. // close out those current tags and all nested children,
  19332. // then open new ones nested within the new styles.
  19333. var resetStyles = getStylesToReset(remainingStyles, newStyles);
  19334. var openingStyles = resetStyles.concat(newStyles).sort(latestStyleLast);
  19335. var openingStyleTags = openingStyles.reduce(appendStartMarkup.bind(null, inlineHTML), '');
  19336. var endingStyleTags = endingStyles.concat(resetStyles).reduce(prependEndMarkup.bind(null, inlineHTML), '');
  19337. result += endingStyleTags + openingStyleTags + originalTextArray[i];
  19338. styleStack = popEndingStyles(styleStack, resetStyles.concat(endingStyles));
  19339. styleStack = styleStack.concat(openingStyles);
  19340. (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"));
  19341. }
  19342. result = styleStack.reduceRight(function (res, openStyle) {
  19343. return res + (0, _getElementHTML["default"])(inlineHTML(openStyle.style)).end;
  19344. }, result);
  19345. return result;
  19346. };
  19347. exports["default"] = _default;
  19348. });
  19349. unwrapExports(blockInlineStyles);
  19350. var blockTypeObjectFunction = createCommonjsModule(function (module, exports) {
  19351. Object.defineProperty(exports, "__esModule", {
  19352. value: true
  19353. });
  19354. exports["default"] = void 0;
  19355. var _default = function _default(typeObject) {
  19356. return function (block) {
  19357. if (typeof typeObject === 'function') {
  19358. // handle case where typeObject is already a function
  19359. return typeObject(block);
  19360. }
  19361. return typeObject[block.type];
  19362. };
  19363. };
  19364. exports["default"] = _default;
  19365. });
  19366. unwrapExports(blockTypeObjectFunction);
  19367. var getBlockTags_1 = createCommonjsModule(function (module, exports) {
  19368. Object.defineProperty(exports, "__esModule", {
  19369. value: true
  19370. });
  19371. exports["default"] = getBlockTags;
  19372. var _invariant = interopRequireDefault(browser);
  19373. var _react = interopRequireDefault(React);
  19374. var _server = interopRequireDefault(server);
  19375. var _splitReactElement = interopRequireDefault(splitReactElement_1);
  19376. function hasChildren(element) {
  19377. return _react["default"].isValidElement(element) && _react["default"].Children.count(element.props.children) > 0;
  19378. }
  19379. function getBlockTags(blockHTML) {
  19380. (0, _invariant["default"])(blockHTML !== null && blockHTML !== undefined, 'Expected block HTML value to be non-null');
  19381. if (typeof blockHTML === 'string') {
  19382. return blockHTML;
  19383. }
  19384. if (_react["default"].isValidElement(blockHTML)) {
  19385. if (hasChildren(blockHTML)) {
  19386. return _server["default"].renderToStaticMarkup(blockHTML);
  19387. }
  19388. return (0, _splitReactElement["default"])(blockHTML);
  19389. }
  19390. if (Object.prototype.hasOwnProperty.call(blockHTML, 'element') && _react["default"].isValidElement(blockHTML.element)) {
  19391. return Object.assign({}, blockHTML, (0, _splitReactElement["default"])(blockHTML.element));
  19392. }
  19393. (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');
  19394. return blockHTML;
  19395. }
  19396. });
  19397. unwrapExports(getBlockTags_1);
  19398. var getNestedBlockTags_1 = createCommonjsModule(function (module, exports) {
  19399. Object.defineProperty(exports, "__esModule", {
  19400. value: true
  19401. });
  19402. exports["default"] = getNestedBlockTags;
  19403. var _invariant = interopRequireDefault(browser);
  19404. var _react = interopRequireDefault(React);
  19405. var _splitReactElement2 = interopRequireDefault(splitReactElement_1);
  19406. function getNestedBlockTags(blockHTML) {
  19407. (0, _invariant["default"])(blockHTML !== null && blockHTML !== undefined, 'Expected block HTML value to be non-null');
  19408. if (_react["default"].isValidElement(blockHTML.nest)) {
  19409. var _splitReactElement = (0, _splitReactElement2["default"])(blockHTML.nest),
  19410. start = _splitReactElement.start,
  19411. end = _splitReactElement.end;
  19412. return Object.assign({}, blockHTML, {
  19413. nestStart: start,
  19414. nestEnd: end
  19415. });
  19416. }
  19417. (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');
  19418. return blockHTML;
  19419. }
  19420. });
  19421. unwrapExports(getNestedBlockTags_1);
  19422. var defaultBlockHTML = createCommonjsModule(function (module, exports) {
  19423. Object.defineProperty(exports, "__esModule", {
  19424. value: true
  19425. });
  19426. exports["default"] = void 0;
  19427. var _react = interopRequireDefault(React);
  19428. var _default = {
  19429. unstyled: _react["default"].createElement("p", null),
  19430. paragraph: _react["default"].createElement("p", null),
  19431. 'header-one': _react["default"].createElement("h1", null),
  19432. 'header-two': _react["default"].createElement("h2", null),
  19433. 'header-three': _react["default"].createElement("h3", null),
  19434. 'header-four': _react["default"].createElement("h4", null),
  19435. 'header-five': _react["default"].createElement("h5", null),
  19436. 'header-six': _react["default"].createElement("h6", null),
  19437. blockquote: _react["default"].createElement("blockquote", null),
  19438. 'unordered-list-item': {
  19439. element: _react["default"].createElement("li", null),
  19440. nest: _react["default"].createElement("ul", null)
  19441. },
  19442. 'ordered-list-item': {
  19443. element: _react["default"].createElement("li", null),
  19444. nest: _react["default"].createElement("ol", null)
  19445. },
  19446. media: _react["default"].createElement("figure", null),
  19447. atomic: _react["default"].createElement("figure", null)
  19448. };
  19449. exports["default"] = _default;
  19450. });
  19451. unwrapExports(defaultBlockHTML);
  19452. var convertToHTML_1 = createCommonjsModule(function (module, exports) {
  19453. Object.defineProperty(exports, "__esModule", {
  19454. value: true
  19455. });
  19456. exports["default"] = void 0;
  19457. var _invariant = interopRequireDefault(browser);
  19458. var _react = interopRequireDefault(React);
  19459. var _server = interopRequireDefault(server);
  19460. var _encodeBlock = interopRequireDefault(encodeBlock);
  19461. var _blockEntities = interopRequireDefault(blockEntities);
  19462. var _blockInlineStyles = interopRequireDefault(blockInlineStyles);
  19463. var _accumulateFunction = interopRequireDefault(accumulateFunction);
  19464. var _blockTypeObjectFunction = interopRequireDefault(blockTypeObjectFunction);
  19465. var _getBlockTags = interopRequireDefault(getBlockTags_1);
  19466. var _getNestedBlockTags = interopRequireDefault(getNestedBlockTags_1);
  19467. var _defaultBlockHTML = interopRequireDefault(defaultBlockHTML);
  19468. // import Immutable from 'immutable'; // eslint-disable-line no-unused-vars
  19469. var defaultEntityToHTML = function defaultEntityToHTML(entity, originalText) {
  19470. return originalText;
  19471. };
  19472. var convertToHTML = function convertToHTML(_ref) {
  19473. var _ref$styleToHTML = _ref.styleToHTML,
  19474. styleToHTML = _ref$styleToHTML === void 0 ? {} : _ref$styleToHTML,
  19475. _ref$blockToHTML = _ref.blockToHTML,
  19476. blockToHTML = _ref$blockToHTML === void 0 ? {} : _ref$blockToHTML,
  19477. _ref$entityToHTML = _ref.entityToHTML,
  19478. entityToHTML = _ref$entityToHTML === void 0 ? defaultEntityToHTML : _ref$entityToHTML;
  19479. return function (contentState) {
  19480. (0, _invariant["default"])(contentState !== null && contentState !== undefined, 'Expected contentState to be non-null');
  19481. var getBlockHTML;
  19482. if (blockToHTML.__isMiddleware === true) {
  19483. getBlockHTML = blockToHTML((0, _blockTypeObjectFunction["default"])(_defaultBlockHTML["default"]));
  19484. } else {
  19485. getBlockHTML = (0, _accumulateFunction["default"])((0, _blockTypeObjectFunction["default"])(blockToHTML), (0, _blockTypeObjectFunction["default"])(_defaultBlockHTML["default"]));
  19486. }
  19487. var rawState = (0, Draft.convertToRaw)(contentState);
  19488. var listStack = [];
  19489. var result = rawState.blocks.map(function (block) {
  19490. var type = block.type,
  19491. depth = block.depth;
  19492. var closeNestTags = '';
  19493. var openNestTags = '';
  19494. var blockHTMLResult = getBlockHTML(block);
  19495. if (!blockHTMLResult) {
  19496. throw new Error("convertToHTML: missing HTML definition for block with type ".concat(block.type));
  19497. }
  19498. if (!blockHTMLResult.nest) {
  19499. // this block can't be nested, so reset all nesting if necessary
  19500. closeNestTags = listStack.reduceRight(function (string, nestedBlock) {
  19501. return string + (0, _getNestedBlockTags["default"])(getBlockHTML(nestedBlock)).nestEnd;
  19502. }, '');
  19503. listStack = [];
  19504. } else {
  19505. while (depth + 1 !== listStack.length || type !== listStack[depth].type) {
  19506. if (depth + 1 === listStack.length) {
  19507. // depth is right but doesn't match type
  19508. var blockToClose = listStack[depth];
  19509. closeNestTags += (0, _getNestedBlockTags["default"])(getBlockHTML(blockToClose)).nestEnd;
  19510. openNestTags += (0, _getNestedBlockTags["default"])(getBlockHTML(block)).nestStart;
  19511. listStack[depth] = block;
  19512. } else if (depth + 1 < listStack.length) {
  19513. var _blockToClose = listStack[listStack.length - 1];
  19514. closeNestTags += (0, _getNestedBlockTags["default"])(getBlockHTML(_blockToClose)).nestEnd;
  19515. listStack = listStack.slice(0, -1);
  19516. } else {
  19517. openNestTags += (0, _getNestedBlockTags["default"])(getBlockHTML(block)).nestStart;
  19518. listStack.push(block);
  19519. }
  19520. }
  19521. }
  19522. var innerHTML = (0, _blockInlineStyles["default"])((0, _blockEntities["default"])((0, _encodeBlock["default"])(block), rawState.entityMap, entityToHTML), styleToHTML);
  19523. var blockHTML = (0, _getBlockTags["default"])(getBlockHTML(block));
  19524. var html;
  19525. if (typeof blockHTML === 'string') {
  19526. html = blockHTML;
  19527. } else {
  19528. html = blockHTML.start + innerHTML + blockHTML.end;
  19529. }
  19530. if (innerHTML.length === 0 && Object.prototype.hasOwnProperty.call(blockHTML, 'empty')) {
  19531. if (_react["default"].isValidElement(blockHTML.empty)) {
  19532. html = _server["default"].renderToStaticMarkup(blockHTML.empty);
  19533. } else {
  19534. html = blockHTML.empty;
  19535. }
  19536. }
  19537. return closeNestTags + openNestTags + html;
  19538. }).join('');
  19539. result = listStack.reduce(function (res, nestBlock) {
  19540. return res + (0, _getNestedBlockTags["default"])(getBlockHTML(nestBlock)).nestEnd;
  19541. }, result);
  19542. return result;
  19543. };
  19544. };
  19545. var _default = function _default() {
  19546. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  19547. args[_key] = arguments[_key];
  19548. }
  19549. if (args.length === 1 && Object.prototype.hasOwnProperty.call(args[0], '_map') && args[0].getBlockMap != null) {
  19550. // skip higher-order function and use defaults
  19551. return convertToHTML({}).apply(void 0, args);
  19552. }
  19553. return convertToHTML.apply(void 0, args);
  19554. };
  19555. exports["default"] = _default;
  19556. });
  19557. unwrapExports(convertToHTML_1);
  19558. var immutable$2 = createCommonjsModule(function (module, exports) {
  19559. /**
  19560. * Copyright (c) 2014-2015, Facebook, Inc.
  19561. * All rights reserved.
  19562. *
  19563. * This source code is licensed under the BSD-style license found in the
  19564. * LICENSE file in the root directory of this source tree. An additional grant
  19565. * of patent rights can be found in the PATENTS file in the same directory.
  19566. */
  19567. (function (global, factory) {
  19568. module.exports = factory() ;
  19569. }(commonjsGlobal, function () {var SLICE$0 = Array.prototype.slice;
  19570. function createClass(ctor, superClass) {
  19571. if (superClass) {
  19572. ctor.prototype = Object.create(superClass.prototype);
  19573. }
  19574. ctor.prototype.constructor = ctor;
  19575. }
  19576. function Iterable(value) {
  19577. return isIterable(value) ? value : Seq(value);
  19578. }
  19579. createClass(KeyedIterable, Iterable);
  19580. function KeyedIterable(value) {
  19581. return isKeyed(value) ? value : KeyedSeq(value);
  19582. }
  19583. createClass(IndexedIterable, Iterable);
  19584. function IndexedIterable(value) {
  19585. return isIndexed(value) ? value : IndexedSeq(value);
  19586. }
  19587. createClass(SetIterable, Iterable);
  19588. function SetIterable(value) {
  19589. return isIterable(value) && !isAssociative(value) ? value : SetSeq(value);
  19590. }
  19591. function isIterable(maybeIterable) {
  19592. return !!(maybeIterable && maybeIterable[IS_ITERABLE_SENTINEL]);
  19593. }
  19594. function isKeyed(maybeKeyed) {
  19595. return !!(maybeKeyed && maybeKeyed[IS_KEYED_SENTINEL]);
  19596. }
  19597. function isIndexed(maybeIndexed) {
  19598. return !!(maybeIndexed && maybeIndexed[IS_INDEXED_SENTINEL]);
  19599. }
  19600. function isAssociative(maybeAssociative) {
  19601. return isKeyed(maybeAssociative) || isIndexed(maybeAssociative);
  19602. }
  19603. function isOrdered(maybeOrdered) {
  19604. return !!(maybeOrdered && maybeOrdered[IS_ORDERED_SENTINEL]);
  19605. }
  19606. Iterable.isIterable = isIterable;
  19607. Iterable.isKeyed = isKeyed;
  19608. Iterable.isIndexed = isIndexed;
  19609. Iterable.isAssociative = isAssociative;
  19610. Iterable.isOrdered = isOrdered;
  19611. Iterable.Keyed = KeyedIterable;
  19612. Iterable.Indexed = IndexedIterable;
  19613. Iterable.Set = SetIterable;
  19614. var IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
  19615. var IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
  19616. var IS_INDEXED_SENTINEL = '@@__IMMUTABLE_INDEXED__@@';
  19617. var IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
  19618. // Used for setting prototype methods that IE8 chokes on.
  19619. var DELETE = 'delete';
  19620. // Constants describing the size of trie nodes.
  19621. var SHIFT = 5; // Resulted in best performance after ______?
  19622. var SIZE = 1 << SHIFT;
  19623. var MASK = SIZE - 1;
  19624. // A consistent shared value representing "not set" which equals nothing other
  19625. // than itself, and nothing that could be provided externally.
  19626. var NOT_SET = {};
  19627. // Boolean references, Rough equivalent of `bool &`.
  19628. var CHANGE_LENGTH = { value: false };
  19629. var DID_ALTER = { value: false };
  19630. function MakeRef(ref) {
  19631. ref.value = false;
  19632. return ref;
  19633. }
  19634. function SetRef(ref) {
  19635. ref && (ref.value = true);
  19636. }
  19637. // A function which returns a value representing an "owner" for transient writes
  19638. // to tries. The return value will only ever equal itself, and will not equal
  19639. // the return of any subsequent call of this function.
  19640. function OwnerID() {}
  19641. // http://jsperf.com/copy-array-inline
  19642. function arrCopy(arr, offset) {
  19643. offset = offset || 0;
  19644. var len = Math.max(0, arr.length - offset);
  19645. var newArr = new Array(len);
  19646. for (var ii = 0; ii < len; ii++) {
  19647. newArr[ii] = arr[ii + offset];
  19648. }
  19649. return newArr;
  19650. }
  19651. function ensureSize(iter) {
  19652. if (iter.size === undefined) {
  19653. iter.size = iter.__iterate(returnTrue);
  19654. }
  19655. return iter.size;
  19656. }
  19657. function wrapIndex(iter, index) {
  19658. // This implements "is array index" which the ECMAString spec defines as:
  19659. //
  19660. // A String property name P is an array index if and only if
  19661. // ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal
  19662. // to 2^32−1.
  19663. //
  19664. // http://www.ecma-international.org/ecma-262/6.0/#sec-array-exotic-objects
  19665. if (typeof index !== 'number') {
  19666. var uint32Index = index >>> 0; // N >>> 0 is shorthand for ToUint32
  19667. if ('' + uint32Index !== index || uint32Index === 4294967295) {
  19668. return NaN;
  19669. }
  19670. index = uint32Index;
  19671. }
  19672. return index < 0 ? ensureSize(iter) + index : index;
  19673. }
  19674. function returnTrue() {
  19675. return true;
  19676. }
  19677. function wholeSlice(begin, end, size) {
  19678. return (begin === 0 || (size !== undefined && begin <= -size)) &&
  19679. (end === undefined || (size !== undefined && end >= size));
  19680. }
  19681. function resolveBegin(begin, size) {
  19682. return resolveIndex(begin, size, 0);
  19683. }
  19684. function resolveEnd(end, size) {
  19685. return resolveIndex(end, size, size);
  19686. }
  19687. function resolveIndex(index, size, defaultIndex) {
  19688. return index === undefined ?
  19689. defaultIndex :
  19690. index < 0 ?
  19691. Math.max(0, size + index) :
  19692. size === undefined ?
  19693. index :
  19694. Math.min(size, index);
  19695. }
  19696. /* global Symbol */
  19697. var ITERATE_KEYS = 0;
  19698. var ITERATE_VALUES = 1;
  19699. var ITERATE_ENTRIES = 2;
  19700. var REAL_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
  19701. var FAUX_ITERATOR_SYMBOL = '@@iterator';
  19702. var ITERATOR_SYMBOL = REAL_ITERATOR_SYMBOL || FAUX_ITERATOR_SYMBOL;
  19703. function Iterator(next) {
  19704. this.next = next;
  19705. }
  19706. Iterator.prototype.toString = function() {
  19707. return '[Iterator]';
  19708. };
  19709. Iterator.KEYS = ITERATE_KEYS;
  19710. Iterator.VALUES = ITERATE_VALUES;
  19711. Iterator.ENTRIES = ITERATE_ENTRIES;
  19712. Iterator.prototype.inspect =
  19713. Iterator.prototype.toSource = function () { return this.toString(); };
  19714. Iterator.prototype[ITERATOR_SYMBOL] = function () {
  19715. return this;
  19716. };
  19717. function iteratorValue(type, k, v, iteratorResult) {
  19718. var value = type === 0 ? k : type === 1 ? v : [k, v];
  19719. iteratorResult ? (iteratorResult.value = value) : (iteratorResult = {
  19720. value: value, done: false
  19721. });
  19722. return iteratorResult;
  19723. }
  19724. function iteratorDone() {
  19725. return { value: undefined, done: true };
  19726. }
  19727. function hasIterator(maybeIterable) {
  19728. return !!getIteratorFn(maybeIterable);
  19729. }
  19730. function isIterator(maybeIterator) {
  19731. return maybeIterator && typeof maybeIterator.next === 'function';
  19732. }
  19733. function getIterator(iterable) {
  19734. var iteratorFn = getIteratorFn(iterable);
  19735. return iteratorFn && iteratorFn.call(iterable);
  19736. }
  19737. function getIteratorFn(iterable) {
  19738. var iteratorFn = iterable && (
  19739. (REAL_ITERATOR_SYMBOL && iterable[REAL_ITERATOR_SYMBOL]) ||
  19740. iterable[FAUX_ITERATOR_SYMBOL]
  19741. );
  19742. if (typeof iteratorFn === 'function') {
  19743. return iteratorFn;
  19744. }
  19745. }
  19746. function isArrayLike(value) {
  19747. return value && typeof value.length === 'number';
  19748. }
  19749. createClass(Seq, Iterable);
  19750. function Seq(value) {
  19751. return value === null || value === undefined ? emptySequence() :
  19752. isIterable(value) ? value.toSeq() : seqFromValue(value);
  19753. }
  19754. Seq.of = function(/*...values*/) {
  19755. return Seq(arguments);
  19756. };
  19757. Seq.prototype.toSeq = function() {
  19758. return this;
  19759. };
  19760. Seq.prototype.toString = function() {
  19761. return this.__toString('Seq {', '}');
  19762. };
  19763. Seq.prototype.cacheResult = function() {
  19764. if (!this._cache && this.__iterateUncached) {
  19765. this._cache = this.entrySeq().toArray();
  19766. this.size = this._cache.length;
  19767. }
  19768. return this;
  19769. };
  19770. // abstract __iterateUncached(fn, reverse)
  19771. Seq.prototype.__iterate = function(fn, reverse) {
  19772. return seqIterate(this, fn, reverse, true);
  19773. };
  19774. // abstract __iteratorUncached(type, reverse)
  19775. Seq.prototype.__iterator = function(type, reverse) {
  19776. return seqIterator(this, type, reverse, true);
  19777. };
  19778. createClass(KeyedSeq, Seq);
  19779. function KeyedSeq(value) {
  19780. return value === null || value === undefined ?
  19781. emptySequence().toKeyedSeq() :
  19782. isIterable(value) ?
  19783. (isKeyed(value) ? value.toSeq() : value.fromEntrySeq()) :
  19784. keyedSeqFromValue(value);
  19785. }
  19786. KeyedSeq.prototype.toKeyedSeq = function() {
  19787. return this;
  19788. };
  19789. createClass(IndexedSeq, Seq);
  19790. function IndexedSeq(value) {
  19791. return value === null || value === undefined ? emptySequence() :
  19792. !isIterable(value) ? indexedSeqFromValue(value) :
  19793. isKeyed(value) ? value.entrySeq() : value.toIndexedSeq();
  19794. }
  19795. IndexedSeq.of = function(/*...values*/) {
  19796. return IndexedSeq(arguments);
  19797. };
  19798. IndexedSeq.prototype.toIndexedSeq = function() {
  19799. return this;
  19800. };
  19801. IndexedSeq.prototype.toString = function() {
  19802. return this.__toString('Seq [', ']');
  19803. };
  19804. IndexedSeq.prototype.__iterate = function(fn, reverse) {
  19805. return seqIterate(this, fn, reverse, false);
  19806. };
  19807. IndexedSeq.prototype.__iterator = function(type, reverse) {
  19808. return seqIterator(this, type, reverse, false);
  19809. };
  19810. createClass(SetSeq, Seq);
  19811. function SetSeq(value) {
  19812. return (
  19813. value === null || value === undefined ? emptySequence() :
  19814. !isIterable(value) ? indexedSeqFromValue(value) :
  19815. isKeyed(value) ? value.entrySeq() : value
  19816. ).toSetSeq();
  19817. }
  19818. SetSeq.of = function(/*...values*/) {
  19819. return SetSeq(arguments);
  19820. };
  19821. SetSeq.prototype.toSetSeq = function() {
  19822. return this;
  19823. };
  19824. Seq.isSeq = isSeq;
  19825. Seq.Keyed = KeyedSeq;
  19826. Seq.Set = SetSeq;
  19827. Seq.Indexed = IndexedSeq;
  19828. var IS_SEQ_SENTINEL = '@@__IMMUTABLE_SEQ__@@';
  19829. Seq.prototype[IS_SEQ_SENTINEL] = true;
  19830. createClass(ArraySeq, IndexedSeq);
  19831. function ArraySeq(array) {
  19832. this._array = array;
  19833. this.size = array.length;
  19834. }
  19835. ArraySeq.prototype.get = function(index, notSetValue) {
  19836. return this.has(index) ? this._array[wrapIndex(this, index)] : notSetValue;
  19837. };
  19838. ArraySeq.prototype.__iterate = function(fn, reverse) {
  19839. var array = this._array;
  19840. var maxIndex = array.length - 1;
  19841. for (var ii = 0; ii <= maxIndex; ii++) {
  19842. if (fn(array[reverse ? maxIndex - ii : ii], ii, this) === false) {
  19843. return ii + 1;
  19844. }
  19845. }
  19846. return ii;
  19847. };
  19848. ArraySeq.prototype.__iterator = function(type, reverse) {
  19849. var array = this._array;
  19850. var maxIndex = array.length - 1;
  19851. var ii = 0;
  19852. return new Iterator(function()
  19853. {return ii > maxIndex ?
  19854. iteratorDone() :
  19855. iteratorValue(type, ii, array[reverse ? maxIndex - ii++ : ii++])}
  19856. );
  19857. };
  19858. createClass(ObjectSeq, KeyedSeq);
  19859. function ObjectSeq(object) {
  19860. var keys = Object.keys(object);
  19861. this._object = object;
  19862. this._keys = keys;
  19863. this.size = keys.length;
  19864. }
  19865. ObjectSeq.prototype.get = function(key, notSetValue) {
  19866. if (notSetValue !== undefined && !this.has(key)) {
  19867. return notSetValue;
  19868. }
  19869. return this._object[key];
  19870. };
  19871. ObjectSeq.prototype.has = function(key) {
  19872. return this._object.hasOwnProperty(key);
  19873. };
  19874. ObjectSeq.prototype.__iterate = function(fn, reverse) {
  19875. var object = this._object;
  19876. var keys = this._keys;
  19877. var maxIndex = keys.length - 1;
  19878. for (var ii = 0; ii <= maxIndex; ii++) {
  19879. var key = keys[reverse ? maxIndex - ii : ii];
  19880. if (fn(object[key], key, this) === false) {
  19881. return ii + 1;
  19882. }
  19883. }
  19884. return ii;
  19885. };
  19886. ObjectSeq.prototype.__iterator = function(type, reverse) {
  19887. var object = this._object;
  19888. var keys = this._keys;
  19889. var maxIndex = keys.length - 1;
  19890. var ii = 0;
  19891. return new Iterator(function() {
  19892. var key = keys[reverse ? maxIndex - ii : ii];
  19893. return ii++ > maxIndex ?
  19894. iteratorDone() :
  19895. iteratorValue(type, key, object[key]);
  19896. });
  19897. };
  19898. ObjectSeq.prototype[IS_ORDERED_SENTINEL] = true;
  19899. createClass(IterableSeq, IndexedSeq);
  19900. function IterableSeq(iterable) {
  19901. this._iterable = iterable;
  19902. this.size = iterable.length || iterable.size;
  19903. }
  19904. IterableSeq.prototype.__iterateUncached = function(fn, reverse) {
  19905. if (reverse) {
  19906. return this.cacheResult().__iterate(fn, reverse);
  19907. }
  19908. var iterable = this._iterable;
  19909. var iterator = getIterator(iterable);
  19910. var iterations = 0;
  19911. if (isIterator(iterator)) {
  19912. var step;
  19913. while (!(step = iterator.next()).done) {
  19914. if (fn(step.value, iterations++, this) === false) {
  19915. break;
  19916. }
  19917. }
  19918. }
  19919. return iterations;
  19920. };
  19921. IterableSeq.prototype.__iteratorUncached = function(type, reverse) {
  19922. if (reverse) {
  19923. return this.cacheResult().__iterator(type, reverse);
  19924. }
  19925. var iterable = this._iterable;
  19926. var iterator = getIterator(iterable);
  19927. if (!isIterator(iterator)) {
  19928. return new Iterator(iteratorDone);
  19929. }
  19930. var iterations = 0;
  19931. return new Iterator(function() {
  19932. var step = iterator.next();
  19933. return step.done ? step : iteratorValue(type, iterations++, step.value);
  19934. });
  19935. };
  19936. createClass(IteratorSeq, IndexedSeq);
  19937. function IteratorSeq(iterator) {
  19938. this._iterator = iterator;
  19939. this._iteratorCache = [];
  19940. }
  19941. IteratorSeq.prototype.__iterateUncached = function(fn, reverse) {
  19942. if (reverse) {
  19943. return this.cacheResult().__iterate(fn, reverse);
  19944. }
  19945. var iterator = this._iterator;
  19946. var cache = this._iteratorCache;
  19947. var iterations = 0;
  19948. while (iterations < cache.length) {
  19949. if (fn(cache[iterations], iterations++, this) === false) {
  19950. return iterations;
  19951. }
  19952. }
  19953. var step;
  19954. while (!(step = iterator.next()).done) {
  19955. var val = step.value;
  19956. cache[iterations] = val;
  19957. if (fn(val, iterations++, this) === false) {
  19958. break;
  19959. }
  19960. }
  19961. return iterations;
  19962. };
  19963. IteratorSeq.prototype.__iteratorUncached = function(type, reverse) {
  19964. if (reverse) {
  19965. return this.cacheResult().__iterator(type, reverse);
  19966. }
  19967. var iterator = this._iterator;
  19968. var cache = this._iteratorCache;
  19969. var iterations = 0;
  19970. return new Iterator(function() {
  19971. if (iterations >= cache.length) {
  19972. var step = iterator.next();
  19973. if (step.done) {
  19974. return step;
  19975. }
  19976. cache[iterations] = step.value;
  19977. }
  19978. return iteratorValue(type, iterations, cache[iterations++]);
  19979. });
  19980. };
  19981. // # pragma Helper functions
  19982. function isSeq(maybeSeq) {
  19983. return !!(maybeSeq && maybeSeq[IS_SEQ_SENTINEL]);
  19984. }
  19985. var EMPTY_SEQ;
  19986. function emptySequence() {
  19987. return EMPTY_SEQ || (EMPTY_SEQ = new ArraySeq([]));
  19988. }
  19989. function keyedSeqFromValue(value) {
  19990. var seq =
  19991. Array.isArray(value) ? new ArraySeq(value).fromEntrySeq() :
  19992. isIterator(value) ? new IteratorSeq(value).fromEntrySeq() :
  19993. hasIterator(value) ? new IterableSeq(value).fromEntrySeq() :
  19994. typeof value === 'object' ? new ObjectSeq(value) :
  19995. undefined;
  19996. if (!seq) {
  19997. throw new TypeError(
  19998. 'Expected Array or iterable object of [k, v] entries, '+
  19999. 'or keyed object: ' + value
  20000. );
  20001. }
  20002. return seq;
  20003. }
  20004. function indexedSeqFromValue(value) {
  20005. var seq = maybeIndexedSeqFromValue(value);
  20006. if (!seq) {
  20007. throw new TypeError(
  20008. 'Expected Array or iterable object of values: ' + value
  20009. );
  20010. }
  20011. return seq;
  20012. }
  20013. function seqFromValue(value) {
  20014. var seq = maybeIndexedSeqFromValue(value) ||
  20015. (typeof value === 'object' && new ObjectSeq(value));
  20016. if (!seq) {
  20017. throw new TypeError(
  20018. 'Expected Array or iterable object of values, or keyed object: ' + value
  20019. );
  20020. }
  20021. return seq;
  20022. }
  20023. function maybeIndexedSeqFromValue(value) {
  20024. return (
  20025. isArrayLike(value) ? new ArraySeq(value) :
  20026. isIterator(value) ? new IteratorSeq(value) :
  20027. hasIterator(value) ? new IterableSeq(value) :
  20028. undefined
  20029. );
  20030. }
  20031. function seqIterate(seq, fn, reverse, useKeys) {
  20032. var cache = seq._cache;
  20033. if (cache) {
  20034. var maxIndex = cache.length - 1;
  20035. for (var ii = 0; ii <= maxIndex; ii++) {
  20036. var entry = cache[reverse ? maxIndex - ii : ii];
  20037. if (fn(entry[1], useKeys ? entry[0] : ii, seq) === false) {
  20038. return ii + 1;
  20039. }
  20040. }
  20041. return ii;
  20042. }
  20043. return seq.__iterateUncached(fn, reverse);
  20044. }
  20045. function seqIterator(seq, type, reverse, useKeys) {
  20046. var cache = seq._cache;
  20047. if (cache) {
  20048. var maxIndex = cache.length - 1;
  20049. var ii = 0;
  20050. return new Iterator(function() {
  20051. var entry = cache[reverse ? maxIndex - ii : ii];
  20052. return ii++ > maxIndex ?
  20053. iteratorDone() :
  20054. iteratorValue(type, useKeys ? entry[0] : ii - 1, entry[1]);
  20055. });
  20056. }
  20057. return seq.__iteratorUncached(type, reverse);
  20058. }
  20059. function fromJS(json, converter) {
  20060. return converter ?
  20061. fromJSWith(converter, json, '', {'': json}) :
  20062. fromJSDefault(json);
  20063. }
  20064. function fromJSWith(converter, json, key, parentJSON) {
  20065. if (Array.isArray(json)) {
  20066. return converter.call(parentJSON, key, IndexedSeq(json).map(function(v, k) {return fromJSWith(converter, v, k, json)}));
  20067. }
  20068. if (isPlainObj(json)) {
  20069. return converter.call(parentJSON, key, KeyedSeq(json).map(function(v, k) {return fromJSWith(converter, v, k, json)}));
  20070. }
  20071. return json;
  20072. }
  20073. function fromJSDefault(json) {
  20074. if (Array.isArray(json)) {
  20075. return IndexedSeq(json).map(fromJSDefault).toList();
  20076. }
  20077. if (isPlainObj(json)) {
  20078. return KeyedSeq(json).map(fromJSDefault).toMap();
  20079. }
  20080. return json;
  20081. }
  20082. function isPlainObj(value) {
  20083. return value && (value.constructor === Object || value.constructor === undefined);
  20084. }
  20085. /**
  20086. * An extension of the "same-value" algorithm as [described for use by ES6 Map
  20087. * and Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map#Key_equality)
  20088. *
  20089. * NaN is considered the same as NaN, however -0 and 0 are considered the same
  20090. * value, which is different from the algorithm described by
  20091. * [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is).
  20092. *
  20093. * This is extended further to allow Objects to describe the values they
  20094. * represent, by way of `valueOf` or `equals` (and `hashCode`).
  20095. *
  20096. * Note: because of this extension, the key equality of Immutable.Map and the
  20097. * value equality of Immutable.Set will differ from ES6 Map and Set.
  20098. *
  20099. * ### Defining custom values
  20100. *
  20101. * The easiest way to describe the value an object represents is by implementing
  20102. * `valueOf`. For example, `Date` represents a value by returning a unix
  20103. * timestamp for `valueOf`:
  20104. *
  20105. * var date1 = new Date(1234567890000); // Fri Feb 13 2009 ...
  20106. * var date2 = new Date(1234567890000);
  20107. * date1.valueOf(); // 1234567890000
  20108. * assert( date1 !== date2 );
  20109. * assert( Immutable.is( date1, date2 ) );
  20110. *
  20111. * Note: overriding `valueOf` may have other implications if you use this object
  20112. * where JavaScript expects a primitive, such as implicit string coercion.
  20113. *
  20114. * For more complex types, especially collections, implementing `valueOf` may
  20115. * not be performant. An alternative is to implement `equals` and `hashCode`.
  20116. *
  20117. * `equals` takes another object, presumably of similar type, and returns true
  20118. * if the it is equal. Equality is symmetrical, so the same result should be
  20119. * returned if this and the argument are flipped.
  20120. *
  20121. * assert( a.equals(b) === b.equals(a) );
  20122. *
  20123. * `hashCode` returns a 32bit integer number representing the object which will
  20124. * be used to determine how to store the value object in a Map or Set. You must
  20125. * provide both or neither methods, one must not exist without the other.
  20126. *
  20127. * Also, an important relationship between these methods must be upheld: if two
  20128. * values are equal, they *must* return the same hashCode. If the values are not
  20129. * equal, they might have the same hashCode; this is called a hash collision,
  20130. * and while undesirable for performance reasons, it is acceptable.
  20131. *
  20132. * if (a.equals(b)) {
  20133. * assert( a.hashCode() === b.hashCode() );
  20134. * }
  20135. *
  20136. * All Immutable collections implement `equals` and `hashCode`.
  20137. *
  20138. */
  20139. function is(valueA, valueB) {
  20140. if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
  20141. return true;
  20142. }
  20143. if (!valueA || !valueB) {
  20144. return false;
  20145. }
  20146. if (typeof valueA.valueOf === 'function' &&
  20147. typeof valueB.valueOf === 'function') {
  20148. valueA = valueA.valueOf();
  20149. valueB = valueB.valueOf();
  20150. if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
  20151. return true;
  20152. }
  20153. if (!valueA || !valueB) {
  20154. return false;
  20155. }
  20156. }
  20157. if (typeof valueA.equals === 'function' &&
  20158. typeof valueB.equals === 'function' &&
  20159. valueA.equals(valueB)) {
  20160. return true;
  20161. }
  20162. return false;
  20163. }
  20164. function deepEqual(a, b) {
  20165. if (a === b) {
  20166. return true;
  20167. }
  20168. if (
  20169. !isIterable(b) ||
  20170. a.size !== undefined && b.size !== undefined && a.size !== b.size ||
  20171. a.__hash !== undefined && b.__hash !== undefined && a.__hash !== b.__hash ||
  20172. isKeyed(a) !== isKeyed(b) ||
  20173. isIndexed(a) !== isIndexed(b) ||
  20174. isOrdered(a) !== isOrdered(b)
  20175. ) {
  20176. return false;
  20177. }
  20178. if (a.size === 0 && b.size === 0) {
  20179. return true;
  20180. }
  20181. var notAssociative = !isAssociative(a);
  20182. if (isOrdered(a)) {
  20183. var entries = a.entries();
  20184. return b.every(function(v, k) {
  20185. var entry = entries.next().value;
  20186. return entry && is(entry[1], v) && (notAssociative || is(entry[0], k));
  20187. }) && entries.next().done;
  20188. }
  20189. var flipped = false;
  20190. if (a.size === undefined) {
  20191. if (b.size === undefined) {
  20192. if (typeof a.cacheResult === 'function') {
  20193. a.cacheResult();
  20194. }
  20195. } else {
  20196. flipped = true;
  20197. var _ = a;
  20198. a = b;
  20199. b = _;
  20200. }
  20201. }
  20202. var allEqual = true;
  20203. var bSize = b.__iterate(function(v, k) {
  20204. if (notAssociative ? !a.has(v) :
  20205. flipped ? !is(v, a.get(k, NOT_SET)) : !is(a.get(k, NOT_SET), v)) {
  20206. allEqual = false;
  20207. return false;
  20208. }
  20209. });
  20210. return allEqual && a.size === bSize;
  20211. }
  20212. createClass(Repeat, IndexedSeq);
  20213. function Repeat(value, times) {
  20214. if (!(this instanceof Repeat)) {
  20215. return new Repeat(value, times);
  20216. }
  20217. this._value = value;
  20218. this.size = times === undefined ? Infinity : Math.max(0, times);
  20219. if (this.size === 0) {
  20220. if (EMPTY_REPEAT) {
  20221. return EMPTY_REPEAT;
  20222. }
  20223. EMPTY_REPEAT = this;
  20224. }
  20225. }
  20226. Repeat.prototype.toString = function() {
  20227. if (this.size === 0) {
  20228. return 'Repeat []';
  20229. }
  20230. return 'Repeat [ ' + this._value + ' ' + this.size + ' times ]';
  20231. };
  20232. Repeat.prototype.get = function(index, notSetValue) {
  20233. return this.has(index) ? this._value : notSetValue;
  20234. };
  20235. Repeat.prototype.includes = function(searchValue) {
  20236. return is(this._value, searchValue);
  20237. };
  20238. Repeat.prototype.slice = function(begin, end) {
  20239. var size = this.size;
  20240. return wholeSlice(begin, end, size) ? this :
  20241. new Repeat(this._value, resolveEnd(end, size) - resolveBegin(begin, size));
  20242. };
  20243. Repeat.prototype.reverse = function() {
  20244. return this;
  20245. };
  20246. Repeat.prototype.indexOf = function(searchValue) {
  20247. if (is(this._value, searchValue)) {
  20248. return 0;
  20249. }
  20250. return -1;
  20251. };
  20252. Repeat.prototype.lastIndexOf = function(searchValue) {
  20253. if (is(this._value, searchValue)) {
  20254. return this.size;
  20255. }
  20256. return -1;
  20257. };
  20258. Repeat.prototype.__iterate = function(fn, reverse) {
  20259. for (var ii = 0; ii < this.size; ii++) {
  20260. if (fn(this._value, ii, this) === false) {
  20261. return ii + 1;
  20262. }
  20263. }
  20264. return ii;
  20265. };
  20266. Repeat.prototype.__iterator = function(type, reverse) {var this$0 = this;
  20267. var ii = 0;
  20268. return new Iterator(function()
  20269. {return ii < this$0.size ? iteratorValue(type, ii++, this$0._value) : iteratorDone()}
  20270. );
  20271. };
  20272. Repeat.prototype.equals = function(other) {
  20273. return other instanceof Repeat ?
  20274. is(this._value, other._value) :
  20275. deepEqual(other);
  20276. };
  20277. var EMPTY_REPEAT;
  20278. function invariant(condition, error) {
  20279. if (!condition) throw new Error(error);
  20280. }
  20281. createClass(Range, IndexedSeq);
  20282. function Range(start, end, step) {
  20283. if (!(this instanceof Range)) {
  20284. return new Range(start, end, step);
  20285. }
  20286. invariant(step !== 0, 'Cannot step a Range by 0');
  20287. start = start || 0;
  20288. if (end === undefined) {
  20289. end = Infinity;
  20290. }
  20291. step = step === undefined ? 1 : Math.abs(step);
  20292. if (end < start) {
  20293. step = -step;
  20294. }
  20295. this._start = start;
  20296. this._end = end;
  20297. this._step = step;
  20298. this.size = Math.max(0, Math.ceil((end - start) / step - 1) + 1);
  20299. if (this.size === 0) {
  20300. if (EMPTY_RANGE) {
  20301. return EMPTY_RANGE;
  20302. }
  20303. EMPTY_RANGE = this;
  20304. }
  20305. }
  20306. Range.prototype.toString = function() {
  20307. if (this.size === 0) {
  20308. return 'Range []';
  20309. }
  20310. return 'Range [ ' +
  20311. this._start + '...' + this._end +
  20312. (this._step > 1 ? ' by ' + this._step : '') +
  20313. ' ]';
  20314. };
  20315. Range.prototype.get = function(index, notSetValue) {
  20316. return this.has(index) ?
  20317. this._start + wrapIndex(this, index) * this._step :
  20318. notSetValue;
  20319. };
  20320. Range.prototype.includes = function(searchValue) {
  20321. var possibleIndex = (searchValue - this._start) / this._step;
  20322. return possibleIndex >= 0 &&
  20323. possibleIndex < this.size &&
  20324. possibleIndex === Math.floor(possibleIndex);
  20325. };
  20326. Range.prototype.slice = function(begin, end) {
  20327. if (wholeSlice(begin, end, this.size)) {
  20328. return this;
  20329. }
  20330. begin = resolveBegin(begin, this.size);
  20331. end = resolveEnd(end, this.size);
  20332. if (end <= begin) {
  20333. return new Range(0, 0);
  20334. }
  20335. return new Range(this.get(begin, this._end), this.get(end, this._end), this._step);
  20336. };
  20337. Range.prototype.indexOf = function(searchValue) {
  20338. var offsetValue = searchValue - this._start;
  20339. if (offsetValue % this._step === 0) {
  20340. var index = offsetValue / this._step;
  20341. if (index >= 0 && index < this.size) {
  20342. return index
  20343. }
  20344. }
  20345. return -1;
  20346. };
  20347. Range.prototype.lastIndexOf = function(searchValue) {
  20348. return this.indexOf(searchValue);
  20349. };
  20350. Range.prototype.__iterate = function(fn, reverse) {
  20351. var maxIndex = this.size - 1;
  20352. var step = this._step;
  20353. var value = reverse ? this._start + maxIndex * step : this._start;
  20354. for (var ii = 0; ii <= maxIndex; ii++) {
  20355. if (fn(value, ii, this) === false) {
  20356. return ii + 1;
  20357. }
  20358. value += reverse ? -step : step;
  20359. }
  20360. return ii;
  20361. };
  20362. Range.prototype.__iterator = function(type, reverse) {
  20363. var maxIndex = this.size - 1;
  20364. var step = this._step;
  20365. var value = reverse ? this._start + maxIndex * step : this._start;
  20366. var ii = 0;
  20367. return new Iterator(function() {
  20368. var v = value;
  20369. value += reverse ? -step : step;
  20370. return ii > maxIndex ? iteratorDone() : iteratorValue(type, ii++, v);
  20371. });
  20372. };
  20373. Range.prototype.equals = function(other) {
  20374. return other instanceof Range ?
  20375. this._start === other._start &&
  20376. this._end === other._end &&
  20377. this._step === other._step :
  20378. deepEqual(this, other);
  20379. };
  20380. var EMPTY_RANGE;
  20381. createClass(Collection, Iterable);
  20382. function Collection() {
  20383. throw TypeError('Abstract');
  20384. }
  20385. createClass(KeyedCollection, Collection);function KeyedCollection() {}
  20386. createClass(IndexedCollection, Collection);function IndexedCollection() {}
  20387. createClass(SetCollection, Collection);function SetCollection() {}
  20388. Collection.Keyed = KeyedCollection;
  20389. Collection.Indexed = IndexedCollection;
  20390. Collection.Set = SetCollection;
  20391. var imul =
  20392. typeof Math.imul === 'function' && Math.imul(0xffffffff, 2) === -2 ?
  20393. Math.imul :
  20394. function imul(a, b) {
  20395. a = a | 0; // int
  20396. b = b | 0; // int
  20397. var c = a & 0xffff;
  20398. var d = b & 0xffff;
  20399. // Shift by 0 fixes the sign on the high part.
  20400. return (c * d) + ((((a >>> 16) * d + c * (b >>> 16)) << 16) >>> 0) | 0; // int
  20401. };
  20402. // v8 has an optimization for storing 31-bit signed numbers.
  20403. // Values which have either 00 or 11 as the high order bits qualify.
  20404. // This function drops the highest order bit in a signed number, maintaining
  20405. // the sign bit.
  20406. function smi(i32) {
  20407. return ((i32 >>> 1) & 0x40000000) | (i32 & 0xBFFFFFFF);
  20408. }
  20409. function hash(o) {
  20410. if (o === false || o === null || o === undefined) {
  20411. return 0;
  20412. }
  20413. if (typeof o.valueOf === 'function') {
  20414. o = o.valueOf();
  20415. if (o === false || o === null || o === undefined) {
  20416. return 0;
  20417. }
  20418. }
  20419. if (o === true) {
  20420. return 1;
  20421. }
  20422. var type = typeof o;
  20423. if (type === 'number') {
  20424. var h = o | 0;
  20425. if (h !== o) {
  20426. h ^= o * 0xFFFFFFFF;
  20427. }
  20428. while (o > 0xFFFFFFFF) {
  20429. o /= 0xFFFFFFFF;
  20430. h ^= o;
  20431. }
  20432. return smi(h);
  20433. }
  20434. if (type === 'string') {
  20435. return o.length > STRING_HASH_CACHE_MIN_STRLEN ? cachedHashString(o) : hashString(o);
  20436. }
  20437. if (typeof o.hashCode === 'function') {
  20438. return o.hashCode();
  20439. }
  20440. if (type === 'object') {
  20441. return hashJSObj(o);
  20442. }
  20443. if (typeof o.toString === 'function') {
  20444. return hashString(o.toString());
  20445. }
  20446. throw new Error('Value type ' + type + ' cannot be hashed.');
  20447. }
  20448. function cachedHashString(string) {
  20449. var hash = stringHashCache[string];
  20450. if (hash === undefined) {
  20451. hash = hashString(string);
  20452. if (STRING_HASH_CACHE_SIZE === STRING_HASH_CACHE_MAX_SIZE) {
  20453. STRING_HASH_CACHE_SIZE = 0;
  20454. stringHashCache = {};
  20455. }
  20456. STRING_HASH_CACHE_SIZE++;
  20457. stringHashCache[string] = hash;
  20458. }
  20459. return hash;
  20460. }
  20461. // http://jsperf.com/hashing-strings
  20462. function hashString(string) {
  20463. // This is the hash from JVM
  20464. // The hash code for a string is computed as
  20465. // s[0] * 31 ^ (n - 1) + s[1] * 31 ^ (n - 2) + ... + s[n - 1],
  20466. // where s[i] is the ith character of the string and n is the length of
  20467. // the string. We "mod" the result to make it between 0 (inclusive) and 2^31
  20468. // (exclusive) by dropping high bits.
  20469. var hash = 0;
  20470. for (var ii = 0; ii < string.length; ii++) {
  20471. hash = 31 * hash + string.charCodeAt(ii) | 0;
  20472. }
  20473. return smi(hash);
  20474. }
  20475. function hashJSObj(obj) {
  20476. var hash;
  20477. if (usingWeakMap) {
  20478. hash = weakMap.get(obj);
  20479. if (hash !== undefined) {
  20480. return hash;
  20481. }
  20482. }
  20483. hash = obj[UID_HASH_KEY];
  20484. if (hash !== undefined) {
  20485. return hash;
  20486. }
  20487. if (!canDefineProperty) {
  20488. hash = obj.propertyIsEnumerable && obj.propertyIsEnumerable[UID_HASH_KEY];
  20489. if (hash !== undefined) {
  20490. return hash;
  20491. }
  20492. hash = getIENodeHash(obj);
  20493. if (hash !== undefined) {
  20494. return hash;
  20495. }
  20496. }
  20497. hash = ++objHashUID;
  20498. if (objHashUID & 0x40000000) {
  20499. objHashUID = 0;
  20500. }
  20501. if (usingWeakMap) {
  20502. weakMap.set(obj, hash);
  20503. } else if (isExtensible !== undefined && isExtensible(obj) === false) {
  20504. throw new Error('Non-extensible objects are not allowed as keys.');
  20505. } else if (canDefineProperty) {
  20506. Object.defineProperty(obj, UID_HASH_KEY, {
  20507. 'enumerable': false,
  20508. 'configurable': false,
  20509. 'writable': false,
  20510. 'value': hash
  20511. });
  20512. } else if (obj.propertyIsEnumerable !== undefined &&
  20513. obj.propertyIsEnumerable === obj.constructor.prototype.propertyIsEnumerable) {
  20514. // Since we can't define a non-enumerable property on the object
  20515. // we'll hijack one of the less-used non-enumerable properties to
  20516. // save our hash on it. Since this is a function it will not show up in
  20517. // `JSON.stringify` which is what we want.
  20518. obj.propertyIsEnumerable = function() {
  20519. return this.constructor.prototype.propertyIsEnumerable.apply(this, arguments);
  20520. };
  20521. obj.propertyIsEnumerable[UID_HASH_KEY] = hash;
  20522. } else if (obj.nodeType !== undefined) {
  20523. // At this point we couldn't get the IE `uniqueID` to use as a hash
  20524. // and we couldn't use a non-enumerable property to exploit the
  20525. // dontEnum bug so we simply add the `UID_HASH_KEY` on the node
  20526. // itself.
  20527. obj[UID_HASH_KEY] = hash;
  20528. } else {
  20529. throw new Error('Unable to set a non-enumerable property on object.');
  20530. }
  20531. return hash;
  20532. }
  20533. // Get references to ES5 object methods.
  20534. var isExtensible = Object.isExtensible;
  20535. // True if Object.defineProperty works as expected. IE8 fails this test.
  20536. var canDefineProperty = (function() {
  20537. try {
  20538. Object.defineProperty({}, '@', {});
  20539. return true;
  20540. } catch (e) {
  20541. return false;
  20542. }
  20543. }());
  20544. // IE has a `uniqueID` property on DOM nodes. We can construct the hash from it
  20545. // and avoid memory leaks from the IE cloneNode bug.
  20546. function getIENodeHash(node) {
  20547. if (node && node.nodeType > 0) {
  20548. switch (node.nodeType) {
  20549. case 1: // Element
  20550. return node.uniqueID;
  20551. case 9: // Document
  20552. return node.documentElement && node.documentElement.uniqueID;
  20553. }
  20554. }
  20555. }
  20556. // If possible, use a WeakMap.
  20557. var usingWeakMap = typeof WeakMap === 'function';
  20558. var weakMap;
  20559. if (usingWeakMap) {
  20560. weakMap = new WeakMap();
  20561. }
  20562. var objHashUID = 0;
  20563. var UID_HASH_KEY = '__immutablehash__';
  20564. if (typeof Symbol === 'function') {
  20565. UID_HASH_KEY = Symbol(UID_HASH_KEY);
  20566. }
  20567. var STRING_HASH_CACHE_MIN_STRLEN = 16;
  20568. var STRING_HASH_CACHE_MAX_SIZE = 255;
  20569. var STRING_HASH_CACHE_SIZE = 0;
  20570. var stringHashCache = {};
  20571. function assertNotInfinite(size) {
  20572. invariant(
  20573. size !== Infinity,
  20574. 'Cannot perform this action with an infinite size.'
  20575. );
  20576. }
  20577. createClass(Map, KeyedCollection);
  20578. // @pragma Construction
  20579. function Map(value) {
  20580. return value === null || value === undefined ? emptyMap() :
  20581. isMap(value) && !isOrdered(value) ? value :
  20582. emptyMap().withMutations(function(map ) {
  20583. var iter = KeyedIterable(value);
  20584. assertNotInfinite(iter.size);
  20585. iter.forEach(function(v, k) {return map.set(k, v)});
  20586. });
  20587. }
  20588. Map.prototype.toString = function() {
  20589. return this.__toString('Map {', '}');
  20590. };
  20591. // @pragma Access
  20592. Map.prototype.get = function(k, notSetValue) {
  20593. return this._root ?
  20594. this._root.get(0, undefined, k, notSetValue) :
  20595. notSetValue;
  20596. };
  20597. // @pragma Modification
  20598. Map.prototype.set = function(k, v) {
  20599. return updateMap(this, k, v);
  20600. };
  20601. Map.prototype.setIn = function(keyPath, v) {
  20602. return this.updateIn(keyPath, NOT_SET, function() {return v});
  20603. };
  20604. Map.prototype.remove = function(k) {
  20605. return updateMap(this, k, NOT_SET);
  20606. };
  20607. Map.prototype.deleteIn = function(keyPath) {
  20608. return this.updateIn(keyPath, function() {return NOT_SET});
  20609. };
  20610. Map.prototype.update = function(k, notSetValue, updater) {
  20611. return arguments.length === 1 ?
  20612. k(this) :
  20613. this.updateIn([k], notSetValue, updater);
  20614. };
  20615. Map.prototype.updateIn = function(keyPath, notSetValue, updater) {
  20616. if (!updater) {
  20617. updater = notSetValue;
  20618. notSetValue = undefined;
  20619. }
  20620. var updatedValue = updateInDeepMap(
  20621. this,
  20622. forceIterator(keyPath),
  20623. notSetValue,
  20624. updater
  20625. );
  20626. return updatedValue === NOT_SET ? undefined : updatedValue;
  20627. };
  20628. Map.prototype.clear = function() {
  20629. if (this.size === 0) {
  20630. return this;
  20631. }
  20632. if (this.__ownerID) {
  20633. this.size = 0;
  20634. this._root = null;
  20635. this.__hash = undefined;
  20636. this.__altered = true;
  20637. return this;
  20638. }
  20639. return emptyMap();
  20640. };
  20641. // @pragma Composition
  20642. Map.prototype.merge = function(/*...iters*/) {
  20643. return mergeIntoMapWith(this, undefined, arguments);
  20644. };
  20645. Map.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  20646. return mergeIntoMapWith(this, merger, iters);
  20647. };
  20648. Map.prototype.mergeIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1);
  20649. return this.updateIn(
  20650. keyPath,
  20651. emptyMap(),
  20652. function(m ) {return typeof m.merge === 'function' ?
  20653. m.merge.apply(m, iters) :
  20654. iters[iters.length - 1]}
  20655. );
  20656. };
  20657. Map.prototype.mergeDeep = function(/*...iters*/) {
  20658. return mergeIntoMapWith(this, deepMerger, arguments);
  20659. };
  20660. Map.prototype.mergeDeepWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  20661. return mergeIntoMapWith(this, deepMergerWith(merger), iters);
  20662. };
  20663. Map.prototype.mergeDeepIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1);
  20664. return this.updateIn(
  20665. keyPath,
  20666. emptyMap(),
  20667. function(m ) {return typeof m.mergeDeep === 'function' ?
  20668. m.mergeDeep.apply(m, iters) :
  20669. iters[iters.length - 1]}
  20670. );
  20671. };
  20672. Map.prototype.sort = function(comparator) {
  20673. // Late binding
  20674. return OrderedMap(sortFactory(this, comparator));
  20675. };
  20676. Map.prototype.sortBy = function(mapper, comparator) {
  20677. // Late binding
  20678. return OrderedMap(sortFactory(this, comparator, mapper));
  20679. };
  20680. // @pragma Mutability
  20681. Map.prototype.withMutations = function(fn) {
  20682. var mutable = this.asMutable();
  20683. fn(mutable);
  20684. return mutable.wasAltered() ? mutable.__ensureOwner(this.__ownerID) : this;
  20685. };
  20686. Map.prototype.asMutable = function() {
  20687. return this.__ownerID ? this : this.__ensureOwner(new OwnerID());
  20688. };
  20689. Map.prototype.asImmutable = function() {
  20690. return this.__ensureOwner();
  20691. };
  20692. Map.prototype.wasAltered = function() {
  20693. return this.__altered;
  20694. };
  20695. Map.prototype.__iterator = function(type, reverse) {
  20696. return new MapIterator(this, type, reverse);
  20697. };
  20698. Map.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  20699. var iterations = 0;
  20700. this._root && this._root.iterate(function(entry ) {
  20701. iterations++;
  20702. return fn(entry[1], entry[0], this$0);
  20703. }, reverse);
  20704. return iterations;
  20705. };
  20706. Map.prototype.__ensureOwner = function(ownerID) {
  20707. if (ownerID === this.__ownerID) {
  20708. return this;
  20709. }
  20710. if (!ownerID) {
  20711. this.__ownerID = ownerID;
  20712. this.__altered = false;
  20713. return this;
  20714. }
  20715. return makeMap(this.size, this._root, ownerID, this.__hash);
  20716. };
  20717. function isMap(maybeMap) {
  20718. return !!(maybeMap && maybeMap[IS_MAP_SENTINEL]);
  20719. }
  20720. Map.isMap = isMap;
  20721. var IS_MAP_SENTINEL = '@@__IMMUTABLE_MAP__@@';
  20722. var MapPrototype = Map.prototype;
  20723. MapPrototype[IS_MAP_SENTINEL] = true;
  20724. MapPrototype[DELETE] = MapPrototype.remove;
  20725. MapPrototype.removeIn = MapPrototype.deleteIn;
  20726. // #pragma Trie Nodes
  20727. function ArrayMapNode(ownerID, entries) {
  20728. this.ownerID = ownerID;
  20729. this.entries = entries;
  20730. }
  20731. ArrayMapNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  20732. var entries = this.entries;
  20733. for (var ii = 0, len = entries.length; ii < len; ii++) {
  20734. if (is(key, entries[ii][0])) {
  20735. return entries[ii][1];
  20736. }
  20737. }
  20738. return notSetValue;
  20739. };
  20740. ArrayMapNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  20741. var removed = value === NOT_SET;
  20742. var entries = this.entries;
  20743. var idx = 0;
  20744. for (var len = entries.length; idx < len; idx++) {
  20745. if (is(key, entries[idx][0])) {
  20746. break;
  20747. }
  20748. }
  20749. var exists = idx < len;
  20750. if (exists ? entries[idx][1] === value : removed) {
  20751. return this;
  20752. }
  20753. SetRef(didAlter);
  20754. (removed || !exists) && SetRef(didChangeSize);
  20755. if (removed && entries.length === 1) {
  20756. return; // undefined
  20757. }
  20758. if (!exists && !removed && entries.length >= MAX_ARRAY_MAP_SIZE) {
  20759. return createNodes(ownerID, entries, key, value);
  20760. }
  20761. var isEditable = ownerID && ownerID === this.ownerID;
  20762. var newEntries = isEditable ? entries : arrCopy(entries);
  20763. if (exists) {
  20764. if (removed) {
  20765. idx === len - 1 ? newEntries.pop() : (newEntries[idx] = newEntries.pop());
  20766. } else {
  20767. newEntries[idx] = [key, value];
  20768. }
  20769. } else {
  20770. newEntries.push([key, value]);
  20771. }
  20772. if (isEditable) {
  20773. this.entries = newEntries;
  20774. return this;
  20775. }
  20776. return new ArrayMapNode(ownerID, newEntries);
  20777. };
  20778. function BitmapIndexedNode(ownerID, bitmap, nodes) {
  20779. this.ownerID = ownerID;
  20780. this.bitmap = bitmap;
  20781. this.nodes = nodes;
  20782. }
  20783. BitmapIndexedNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  20784. if (keyHash === undefined) {
  20785. keyHash = hash(key);
  20786. }
  20787. var bit = (1 << ((shift === 0 ? keyHash : keyHash >>> shift) & MASK));
  20788. var bitmap = this.bitmap;
  20789. return (bitmap & bit) === 0 ? notSetValue :
  20790. this.nodes[popCount(bitmap & (bit - 1))].get(shift + SHIFT, keyHash, key, notSetValue);
  20791. };
  20792. BitmapIndexedNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  20793. if (keyHash === undefined) {
  20794. keyHash = hash(key);
  20795. }
  20796. var keyHashFrag = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  20797. var bit = 1 << keyHashFrag;
  20798. var bitmap = this.bitmap;
  20799. var exists = (bitmap & bit) !== 0;
  20800. if (!exists && value === NOT_SET) {
  20801. return this;
  20802. }
  20803. var idx = popCount(bitmap & (bit - 1));
  20804. var nodes = this.nodes;
  20805. var node = exists ? nodes[idx] : undefined;
  20806. var newNode = updateNode(node, ownerID, shift + SHIFT, keyHash, key, value, didChangeSize, didAlter);
  20807. if (newNode === node) {
  20808. return this;
  20809. }
  20810. if (!exists && newNode && nodes.length >= MAX_BITMAP_INDEXED_SIZE) {
  20811. return expandNodes(ownerID, nodes, bitmap, keyHashFrag, newNode);
  20812. }
  20813. if (exists && !newNode && nodes.length === 2 && isLeafNode(nodes[idx ^ 1])) {
  20814. return nodes[idx ^ 1];
  20815. }
  20816. if (exists && newNode && nodes.length === 1 && isLeafNode(newNode)) {
  20817. return newNode;
  20818. }
  20819. var isEditable = ownerID && ownerID === this.ownerID;
  20820. var newBitmap = exists ? newNode ? bitmap : bitmap ^ bit : bitmap | bit;
  20821. var newNodes = exists ? newNode ?
  20822. setIn(nodes, idx, newNode, isEditable) :
  20823. spliceOut(nodes, idx, isEditable) :
  20824. spliceIn(nodes, idx, newNode, isEditable);
  20825. if (isEditable) {
  20826. this.bitmap = newBitmap;
  20827. this.nodes = newNodes;
  20828. return this;
  20829. }
  20830. return new BitmapIndexedNode(ownerID, newBitmap, newNodes);
  20831. };
  20832. function HashArrayMapNode(ownerID, count, nodes) {
  20833. this.ownerID = ownerID;
  20834. this.count = count;
  20835. this.nodes = nodes;
  20836. }
  20837. HashArrayMapNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  20838. if (keyHash === undefined) {
  20839. keyHash = hash(key);
  20840. }
  20841. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  20842. var node = this.nodes[idx];
  20843. return node ? node.get(shift + SHIFT, keyHash, key, notSetValue) : notSetValue;
  20844. };
  20845. HashArrayMapNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  20846. if (keyHash === undefined) {
  20847. keyHash = hash(key);
  20848. }
  20849. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  20850. var removed = value === NOT_SET;
  20851. var nodes = this.nodes;
  20852. var node = nodes[idx];
  20853. if (removed && !node) {
  20854. return this;
  20855. }
  20856. var newNode = updateNode(node, ownerID, shift + SHIFT, keyHash, key, value, didChangeSize, didAlter);
  20857. if (newNode === node) {
  20858. return this;
  20859. }
  20860. var newCount = this.count;
  20861. if (!node) {
  20862. newCount++;
  20863. } else if (!newNode) {
  20864. newCount--;
  20865. if (newCount < MIN_HASH_ARRAY_MAP_SIZE) {
  20866. return packNodes(ownerID, nodes, newCount, idx);
  20867. }
  20868. }
  20869. var isEditable = ownerID && ownerID === this.ownerID;
  20870. var newNodes = setIn(nodes, idx, newNode, isEditable);
  20871. if (isEditable) {
  20872. this.count = newCount;
  20873. this.nodes = newNodes;
  20874. return this;
  20875. }
  20876. return new HashArrayMapNode(ownerID, newCount, newNodes);
  20877. };
  20878. function HashCollisionNode(ownerID, keyHash, entries) {
  20879. this.ownerID = ownerID;
  20880. this.keyHash = keyHash;
  20881. this.entries = entries;
  20882. }
  20883. HashCollisionNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  20884. var entries = this.entries;
  20885. for (var ii = 0, len = entries.length; ii < len; ii++) {
  20886. if (is(key, entries[ii][0])) {
  20887. return entries[ii][1];
  20888. }
  20889. }
  20890. return notSetValue;
  20891. };
  20892. HashCollisionNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  20893. if (keyHash === undefined) {
  20894. keyHash = hash(key);
  20895. }
  20896. var removed = value === NOT_SET;
  20897. if (keyHash !== this.keyHash) {
  20898. if (removed) {
  20899. return this;
  20900. }
  20901. SetRef(didAlter);
  20902. SetRef(didChangeSize);
  20903. return mergeIntoNode(this, ownerID, shift, keyHash, [key, value]);
  20904. }
  20905. var entries = this.entries;
  20906. var idx = 0;
  20907. for (var len = entries.length; idx < len; idx++) {
  20908. if (is(key, entries[idx][0])) {
  20909. break;
  20910. }
  20911. }
  20912. var exists = idx < len;
  20913. if (exists ? entries[idx][1] === value : removed) {
  20914. return this;
  20915. }
  20916. SetRef(didAlter);
  20917. (removed || !exists) && SetRef(didChangeSize);
  20918. if (removed && len === 2) {
  20919. return new ValueNode(ownerID, this.keyHash, entries[idx ^ 1]);
  20920. }
  20921. var isEditable = ownerID && ownerID === this.ownerID;
  20922. var newEntries = isEditable ? entries : arrCopy(entries);
  20923. if (exists) {
  20924. if (removed) {
  20925. idx === len - 1 ? newEntries.pop() : (newEntries[idx] = newEntries.pop());
  20926. } else {
  20927. newEntries[idx] = [key, value];
  20928. }
  20929. } else {
  20930. newEntries.push([key, value]);
  20931. }
  20932. if (isEditable) {
  20933. this.entries = newEntries;
  20934. return this;
  20935. }
  20936. return new HashCollisionNode(ownerID, this.keyHash, newEntries);
  20937. };
  20938. function ValueNode(ownerID, keyHash, entry) {
  20939. this.ownerID = ownerID;
  20940. this.keyHash = keyHash;
  20941. this.entry = entry;
  20942. }
  20943. ValueNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  20944. return is(key, this.entry[0]) ? this.entry[1] : notSetValue;
  20945. };
  20946. ValueNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  20947. var removed = value === NOT_SET;
  20948. var keyMatch = is(key, this.entry[0]);
  20949. if (keyMatch ? value === this.entry[1] : removed) {
  20950. return this;
  20951. }
  20952. SetRef(didAlter);
  20953. if (removed) {
  20954. SetRef(didChangeSize);
  20955. return; // undefined
  20956. }
  20957. if (keyMatch) {
  20958. if (ownerID && ownerID === this.ownerID) {
  20959. this.entry[1] = value;
  20960. return this;
  20961. }
  20962. return new ValueNode(ownerID, this.keyHash, [key, value]);
  20963. }
  20964. SetRef(didChangeSize);
  20965. return mergeIntoNode(this, ownerID, shift, hash(key), [key, value]);
  20966. };
  20967. // #pragma Iterators
  20968. ArrayMapNode.prototype.iterate =
  20969. HashCollisionNode.prototype.iterate = function (fn, reverse) {
  20970. var entries = this.entries;
  20971. for (var ii = 0, maxIndex = entries.length - 1; ii <= maxIndex; ii++) {
  20972. if (fn(entries[reverse ? maxIndex - ii : ii]) === false) {
  20973. return false;
  20974. }
  20975. }
  20976. };
  20977. BitmapIndexedNode.prototype.iterate =
  20978. HashArrayMapNode.prototype.iterate = function (fn, reverse) {
  20979. var nodes = this.nodes;
  20980. for (var ii = 0, maxIndex = nodes.length - 1; ii <= maxIndex; ii++) {
  20981. var node = nodes[reverse ? maxIndex - ii : ii];
  20982. if (node && node.iterate(fn, reverse) === false) {
  20983. return false;
  20984. }
  20985. }
  20986. };
  20987. ValueNode.prototype.iterate = function (fn, reverse) {
  20988. return fn(this.entry);
  20989. };
  20990. createClass(MapIterator, Iterator);
  20991. function MapIterator(map, type, reverse) {
  20992. this._type = type;
  20993. this._reverse = reverse;
  20994. this._stack = map._root && mapIteratorFrame(map._root);
  20995. }
  20996. MapIterator.prototype.next = function() {
  20997. var type = this._type;
  20998. var stack = this._stack;
  20999. while (stack) {
  21000. var node = stack.node;
  21001. var index = stack.index++;
  21002. var maxIndex;
  21003. if (node.entry) {
  21004. if (index === 0) {
  21005. return mapIteratorValue(type, node.entry);
  21006. }
  21007. } else if (node.entries) {
  21008. maxIndex = node.entries.length - 1;
  21009. if (index <= maxIndex) {
  21010. return mapIteratorValue(type, node.entries[this._reverse ? maxIndex - index : index]);
  21011. }
  21012. } else {
  21013. maxIndex = node.nodes.length - 1;
  21014. if (index <= maxIndex) {
  21015. var subNode = node.nodes[this._reverse ? maxIndex - index : index];
  21016. if (subNode) {
  21017. if (subNode.entry) {
  21018. return mapIteratorValue(type, subNode.entry);
  21019. }
  21020. stack = this._stack = mapIteratorFrame(subNode, stack);
  21021. }
  21022. continue;
  21023. }
  21024. }
  21025. stack = this._stack = this._stack.__prev;
  21026. }
  21027. return iteratorDone();
  21028. };
  21029. function mapIteratorValue(type, entry) {
  21030. return iteratorValue(type, entry[0], entry[1]);
  21031. }
  21032. function mapIteratorFrame(node, prev) {
  21033. return {
  21034. node: node,
  21035. index: 0,
  21036. __prev: prev
  21037. };
  21038. }
  21039. function makeMap(size, root, ownerID, hash) {
  21040. var map = Object.create(MapPrototype);
  21041. map.size = size;
  21042. map._root = root;
  21043. map.__ownerID = ownerID;
  21044. map.__hash = hash;
  21045. map.__altered = false;
  21046. return map;
  21047. }
  21048. var EMPTY_MAP;
  21049. function emptyMap() {
  21050. return EMPTY_MAP || (EMPTY_MAP = makeMap(0));
  21051. }
  21052. function updateMap(map, k, v) {
  21053. var newRoot;
  21054. var newSize;
  21055. if (!map._root) {
  21056. if (v === NOT_SET) {
  21057. return map;
  21058. }
  21059. newSize = 1;
  21060. newRoot = new ArrayMapNode(map.__ownerID, [[k, v]]);
  21061. } else {
  21062. var didChangeSize = MakeRef(CHANGE_LENGTH);
  21063. var didAlter = MakeRef(DID_ALTER);
  21064. newRoot = updateNode(map._root, map.__ownerID, 0, undefined, k, v, didChangeSize, didAlter);
  21065. if (!didAlter.value) {
  21066. return map;
  21067. }
  21068. newSize = map.size + (didChangeSize.value ? v === NOT_SET ? -1 : 1 : 0);
  21069. }
  21070. if (map.__ownerID) {
  21071. map.size = newSize;
  21072. map._root = newRoot;
  21073. map.__hash = undefined;
  21074. map.__altered = true;
  21075. return map;
  21076. }
  21077. return newRoot ? makeMap(newSize, newRoot) : emptyMap();
  21078. }
  21079. function updateNode(node, ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  21080. if (!node) {
  21081. if (value === NOT_SET) {
  21082. return node;
  21083. }
  21084. SetRef(didAlter);
  21085. SetRef(didChangeSize);
  21086. return new ValueNode(ownerID, keyHash, [key, value]);
  21087. }
  21088. return node.update(ownerID, shift, keyHash, key, value, didChangeSize, didAlter);
  21089. }
  21090. function isLeafNode(node) {
  21091. return node.constructor === ValueNode || node.constructor === HashCollisionNode;
  21092. }
  21093. function mergeIntoNode(node, ownerID, shift, keyHash, entry) {
  21094. if (node.keyHash === keyHash) {
  21095. return new HashCollisionNode(ownerID, keyHash, [node.entry, entry]);
  21096. }
  21097. var idx1 = (shift === 0 ? node.keyHash : node.keyHash >>> shift) & MASK;
  21098. var idx2 = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  21099. var newNode;
  21100. var nodes = idx1 === idx2 ?
  21101. [mergeIntoNode(node, ownerID, shift + SHIFT, keyHash, entry)] :
  21102. ((newNode = new ValueNode(ownerID, keyHash, entry)), idx1 < idx2 ? [node, newNode] : [newNode, node]);
  21103. return new BitmapIndexedNode(ownerID, (1 << idx1) | (1 << idx2), nodes);
  21104. }
  21105. function createNodes(ownerID, entries, key, value) {
  21106. if (!ownerID) {
  21107. ownerID = new OwnerID();
  21108. }
  21109. var node = new ValueNode(ownerID, hash(key), [key, value]);
  21110. for (var ii = 0; ii < entries.length; ii++) {
  21111. var entry = entries[ii];
  21112. node = node.update(ownerID, 0, undefined, entry[0], entry[1]);
  21113. }
  21114. return node;
  21115. }
  21116. function packNodes(ownerID, nodes, count, excluding) {
  21117. var bitmap = 0;
  21118. var packedII = 0;
  21119. var packedNodes = new Array(count);
  21120. for (var ii = 0, bit = 1, len = nodes.length; ii < len; ii++, bit <<= 1) {
  21121. var node = nodes[ii];
  21122. if (node !== undefined && ii !== excluding) {
  21123. bitmap |= bit;
  21124. packedNodes[packedII++] = node;
  21125. }
  21126. }
  21127. return new BitmapIndexedNode(ownerID, bitmap, packedNodes);
  21128. }
  21129. function expandNodes(ownerID, nodes, bitmap, including, node) {
  21130. var count = 0;
  21131. var expandedNodes = new Array(SIZE);
  21132. for (var ii = 0; bitmap !== 0; ii++, bitmap >>>= 1) {
  21133. expandedNodes[ii] = bitmap & 1 ? nodes[count++] : undefined;
  21134. }
  21135. expandedNodes[including] = node;
  21136. return new HashArrayMapNode(ownerID, count + 1, expandedNodes);
  21137. }
  21138. function mergeIntoMapWith(map, merger, iterables) {
  21139. var iters = [];
  21140. for (var ii = 0; ii < iterables.length; ii++) {
  21141. var value = iterables[ii];
  21142. var iter = KeyedIterable(value);
  21143. if (!isIterable(value)) {
  21144. iter = iter.map(function(v ) {return fromJS(v)});
  21145. }
  21146. iters.push(iter);
  21147. }
  21148. return mergeIntoCollectionWith(map, merger, iters);
  21149. }
  21150. function deepMerger(existing, value, key) {
  21151. return existing && existing.mergeDeep && isIterable(value) ?
  21152. existing.mergeDeep(value) :
  21153. is(existing, value) ? existing : value;
  21154. }
  21155. function deepMergerWith(merger) {
  21156. return function(existing, value, key) {
  21157. if (existing && existing.mergeDeepWith && isIterable(value)) {
  21158. return existing.mergeDeepWith(merger, value);
  21159. }
  21160. var nextValue = merger(existing, value, key);
  21161. return is(existing, nextValue) ? existing : nextValue;
  21162. };
  21163. }
  21164. function mergeIntoCollectionWith(collection, merger, iters) {
  21165. iters = iters.filter(function(x ) {return x.size !== 0});
  21166. if (iters.length === 0) {
  21167. return collection;
  21168. }
  21169. if (collection.size === 0 && !collection.__ownerID && iters.length === 1) {
  21170. return collection.constructor(iters[0]);
  21171. }
  21172. return collection.withMutations(function(collection ) {
  21173. var mergeIntoMap = merger ?
  21174. function(value, key) {
  21175. collection.update(key, NOT_SET, function(existing )
  21176. {return existing === NOT_SET ? value : merger(existing, value, key)}
  21177. );
  21178. } :
  21179. function(value, key) {
  21180. collection.set(key, value);
  21181. };
  21182. for (var ii = 0; ii < iters.length; ii++) {
  21183. iters[ii].forEach(mergeIntoMap);
  21184. }
  21185. });
  21186. }
  21187. function updateInDeepMap(existing, keyPathIter, notSetValue, updater) {
  21188. var isNotSet = existing === NOT_SET;
  21189. var step = keyPathIter.next();
  21190. if (step.done) {
  21191. var existingValue = isNotSet ? notSetValue : existing;
  21192. var newValue = updater(existingValue);
  21193. return newValue === existingValue ? existing : newValue;
  21194. }
  21195. invariant(
  21196. isNotSet || (existing && existing.set),
  21197. 'invalid keyPath'
  21198. );
  21199. var key = step.value;
  21200. var nextExisting = isNotSet ? NOT_SET : existing.get(key, NOT_SET);
  21201. var nextUpdated = updateInDeepMap(
  21202. nextExisting,
  21203. keyPathIter,
  21204. notSetValue,
  21205. updater
  21206. );
  21207. return nextUpdated === nextExisting ? existing :
  21208. nextUpdated === NOT_SET ? existing.remove(key) :
  21209. (isNotSet ? emptyMap() : existing).set(key, nextUpdated);
  21210. }
  21211. function popCount(x) {
  21212. x = x - ((x >> 1) & 0x55555555);
  21213. x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
  21214. x = (x + (x >> 4)) & 0x0f0f0f0f;
  21215. x = x + (x >> 8);
  21216. x = x + (x >> 16);
  21217. return x & 0x7f;
  21218. }
  21219. function setIn(array, idx, val, canEdit) {
  21220. var newArray = canEdit ? array : arrCopy(array);
  21221. newArray[idx] = val;
  21222. return newArray;
  21223. }
  21224. function spliceIn(array, idx, val, canEdit) {
  21225. var newLen = array.length + 1;
  21226. if (canEdit && idx + 1 === newLen) {
  21227. array[idx] = val;
  21228. return array;
  21229. }
  21230. var newArray = new Array(newLen);
  21231. var after = 0;
  21232. for (var ii = 0; ii < newLen; ii++) {
  21233. if (ii === idx) {
  21234. newArray[ii] = val;
  21235. after = -1;
  21236. } else {
  21237. newArray[ii] = array[ii + after];
  21238. }
  21239. }
  21240. return newArray;
  21241. }
  21242. function spliceOut(array, idx, canEdit) {
  21243. var newLen = array.length - 1;
  21244. if (canEdit && idx === newLen) {
  21245. array.pop();
  21246. return array;
  21247. }
  21248. var newArray = new Array(newLen);
  21249. var after = 0;
  21250. for (var ii = 0; ii < newLen; ii++) {
  21251. if (ii === idx) {
  21252. after = 1;
  21253. }
  21254. newArray[ii] = array[ii + after];
  21255. }
  21256. return newArray;
  21257. }
  21258. var MAX_ARRAY_MAP_SIZE = SIZE / 4;
  21259. var MAX_BITMAP_INDEXED_SIZE = SIZE / 2;
  21260. var MIN_HASH_ARRAY_MAP_SIZE = SIZE / 4;
  21261. createClass(List, IndexedCollection);
  21262. // @pragma Construction
  21263. function List(value) {
  21264. var empty = emptyList();
  21265. if (value === null || value === undefined) {
  21266. return empty;
  21267. }
  21268. if (isList(value)) {
  21269. return value;
  21270. }
  21271. var iter = IndexedIterable(value);
  21272. var size = iter.size;
  21273. if (size === 0) {
  21274. return empty;
  21275. }
  21276. assertNotInfinite(size);
  21277. if (size > 0 && size < SIZE) {
  21278. return makeList(0, size, SHIFT, null, new VNode(iter.toArray()));
  21279. }
  21280. return empty.withMutations(function(list ) {
  21281. list.setSize(size);
  21282. iter.forEach(function(v, i) {return list.set(i, v)});
  21283. });
  21284. }
  21285. List.of = function(/*...values*/) {
  21286. return this(arguments);
  21287. };
  21288. List.prototype.toString = function() {
  21289. return this.__toString('List [', ']');
  21290. };
  21291. // @pragma Access
  21292. List.prototype.get = function(index, notSetValue) {
  21293. index = wrapIndex(this, index);
  21294. if (index >= 0 && index < this.size) {
  21295. index += this._origin;
  21296. var node = listNodeFor(this, index);
  21297. return node && node.array[index & MASK];
  21298. }
  21299. return notSetValue;
  21300. };
  21301. // @pragma Modification
  21302. List.prototype.set = function(index, value) {
  21303. return updateList(this, index, value);
  21304. };
  21305. List.prototype.remove = function(index) {
  21306. return !this.has(index) ? this :
  21307. index === 0 ? this.shift() :
  21308. index === this.size - 1 ? this.pop() :
  21309. this.splice(index, 1);
  21310. };
  21311. List.prototype.insert = function(index, value) {
  21312. return this.splice(index, 0, value);
  21313. };
  21314. List.prototype.clear = function() {
  21315. if (this.size === 0) {
  21316. return this;
  21317. }
  21318. if (this.__ownerID) {
  21319. this.size = this._origin = this._capacity = 0;
  21320. this._level = SHIFT;
  21321. this._root = this._tail = null;
  21322. this.__hash = undefined;
  21323. this.__altered = true;
  21324. return this;
  21325. }
  21326. return emptyList();
  21327. };
  21328. List.prototype.push = function(/*...values*/) {
  21329. var values = arguments;
  21330. var oldSize = this.size;
  21331. return this.withMutations(function(list ) {
  21332. setListBounds(list, 0, oldSize + values.length);
  21333. for (var ii = 0; ii < values.length; ii++) {
  21334. list.set(oldSize + ii, values[ii]);
  21335. }
  21336. });
  21337. };
  21338. List.prototype.pop = function() {
  21339. return setListBounds(this, 0, -1);
  21340. };
  21341. List.prototype.unshift = function(/*...values*/) {
  21342. var values = arguments;
  21343. return this.withMutations(function(list ) {
  21344. setListBounds(list, -values.length);
  21345. for (var ii = 0; ii < values.length; ii++) {
  21346. list.set(ii, values[ii]);
  21347. }
  21348. });
  21349. };
  21350. List.prototype.shift = function() {
  21351. return setListBounds(this, 1);
  21352. };
  21353. // @pragma Composition
  21354. List.prototype.merge = function(/*...iters*/) {
  21355. return mergeIntoListWith(this, undefined, arguments);
  21356. };
  21357. List.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  21358. return mergeIntoListWith(this, merger, iters);
  21359. };
  21360. List.prototype.mergeDeep = function(/*...iters*/) {
  21361. return mergeIntoListWith(this, deepMerger, arguments);
  21362. };
  21363. List.prototype.mergeDeepWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  21364. return mergeIntoListWith(this, deepMergerWith(merger), iters);
  21365. };
  21366. List.prototype.setSize = function(size) {
  21367. return setListBounds(this, 0, size);
  21368. };
  21369. // @pragma Iteration
  21370. List.prototype.slice = function(begin, end) {
  21371. var size = this.size;
  21372. if (wholeSlice(begin, end, size)) {
  21373. return this;
  21374. }
  21375. return setListBounds(
  21376. this,
  21377. resolveBegin(begin, size),
  21378. resolveEnd(end, size)
  21379. );
  21380. };
  21381. List.prototype.__iterator = function(type, reverse) {
  21382. var index = 0;
  21383. var values = iterateList(this, reverse);
  21384. return new Iterator(function() {
  21385. var value = values();
  21386. return value === DONE ?
  21387. iteratorDone() :
  21388. iteratorValue(type, index++, value);
  21389. });
  21390. };
  21391. List.prototype.__iterate = function(fn, reverse) {
  21392. var index = 0;
  21393. var values = iterateList(this, reverse);
  21394. var value;
  21395. while ((value = values()) !== DONE) {
  21396. if (fn(value, index++, this) === false) {
  21397. break;
  21398. }
  21399. }
  21400. return index;
  21401. };
  21402. List.prototype.__ensureOwner = function(ownerID) {
  21403. if (ownerID === this.__ownerID) {
  21404. return this;
  21405. }
  21406. if (!ownerID) {
  21407. this.__ownerID = ownerID;
  21408. return this;
  21409. }
  21410. return makeList(this._origin, this._capacity, this._level, this._root, this._tail, ownerID, this.__hash);
  21411. };
  21412. function isList(maybeList) {
  21413. return !!(maybeList && maybeList[IS_LIST_SENTINEL]);
  21414. }
  21415. List.isList = isList;
  21416. var IS_LIST_SENTINEL = '@@__IMMUTABLE_LIST__@@';
  21417. var ListPrototype = List.prototype;
  21418. ListPrototype[IS_LIST_SENTINEL] = true;
  21419. ListPrototype[DELETE] = ListPrototype.remove;
  21420. ListPrototype.setIn = MapPrototype.setIn;
  21421. ListPrototype.deleteIn =
  21422. ListPrototype.removeIn = MapPrototype.removeIn;
  21423. ListPrototype.update = MapPrototype.update;
  21424. ListPrototype.updateIn = MapPrototype.updateIn;
  21425. ListPrototype.mergeIn = MapPrototype.mergeIn;
  21426. ListPrototype.mergeDeepIn = MapPrototype.mergeDeepIn;
  21427. ListPrototype.withMutations = MapPrototype.withMutations;
  21428. ListPrototype.asMutable = MapPrototype.asMutable;
  21429. ListPrototype.asImmutable = MapPrototype.asImmutable;
  21430. ListPrototype.wasAltered = MapPrototype.wasAltered;
  21431. function VNode(array, ownerID) {
  21432. this.array = array;
  21433. this.ownerID = ownerID;
  21434. }
  21435. // TODO: seems like these methods are very similar
  21436. VNode.prototype.removeBefore = function(ownerID, level, index) {
  21437. if (index === level ? 1 << level : this.array.length === 0) {
  21438. return this;
  21439. }
  21440. var originIndex = (index >>> level) & MASK;
  21441. if (originIndex >= this.array.length) {
  21442. return new VNode([], ownerID);
  21443. }
  21444. var removingFirst = originIndex === 0;
  21445. var newChild;
  21446. if (level > 0) {
  21447. var oldChild = this.array[originIndex];
  21448. newChild = oldChild && oldChild.removeBefore(ownerID, level - SHIFT, index);
  21449. if (newChild === oldChild && removingFirst) {
  21450. return this;
  21451. }
  21452. }
  21453. if (removingFirst && !newChild) {
  21454. return this;
  21455. }
  21456. var editable = editableVNode(this, ownerID);
  21457. if (!removingFirst) {
  21458. for (var ii = 0; ii < originIndex; ii++) {
  21459. editable.array[ii] = undefined;
  21460. }
  21461. }
  21462. if (newChild) {
  21463. editable.array[originIndex] = newChild;
  21464. }
  21465. return editable;
  21466. };
  21467. VNode.prototype.removeAfter = function(ownerID, level, index) {
  21468. if (index === (level ? 1 << level : 0) || this.array.length === 0) {
  21469. return this;
  21470. }
  21471. var sizeIndex = ((index - 1) >>> level) & MASK;
  21472. if (sizeIndex >= this.array.length) {
  21473. return this;
  21474. }
  21475. var newChild;
  21476. if (level > 0) {
  21477. var oldChild = this.array[sizeIndex];
  21478. newChild = oldChild && oldChild.removeAfter(ownerID, level - SHIFT, index);
  21479. if (newChild === oldChild && sizeIndex === this.array.length - 1) {
  21480. return this;
  21481. }
  21482. }
  21483. var editable = editableVNode(this, ownerID);
  21484. editable.array.splice(sizeIndex + 1);
  21485. if (newChild) {
  21486. editable.array[sizeIndex] = newChild;
  21487. }
  21488. return editable;
  21489. };
  21490. var DONE = {};
  21491. function iterateList(list, reverse) {
  21492. var left = list._origin;
  21493. var right = list._capacity;
  21494. var tailPos = getTailOffset(right);
  21495. var tail = list._tail;
  21496. return iterateNodeOrLeaf(list._root, list._level, 0);
  21497. function iterateNodeOrLeaf(node, level, offset) {
  21498. return level === 0 ?
  21499. iterateLeaf(node, offset) :
  21500. iterateNode(node, level, offset);
  21501. }
  21502. function iterateLeaf(node, offset) {
  21503. var array = offset === tailPos ? tail && tail.array : node && node.array;
  21504. var from = offset > left ? 0 : left - offset;
  21505. var to = right - offset;
  21506. if (to > SIZE) {
  21507. to = SIZE;
  21508. }
  21509. return function() {
  21510. if (from === to) {
  21511. return DONE;
  21512. }
  21513. var idx = reverse ? --to : from++;
  21514. return array && array[idx];
  21515. };
  21516. }
  21517. function iterateNode(node, level, offset) {
  21518. var values;
  21519. var array = node && node.array;
  21520. var from = offset > left ? 0 : (left - offset) >> level;
  21521. var to = ((right - offset) >> level) + 1;
  21522. if (to > SIZE) {
  21523. to = SIZE;
  21524. }
  21525. return function() {
  21526. do {
  21527. if (values) {
  21528. var value = values();
  21529. if (value !== DONE) {
  21530. return value;
  21531. }
  21532. values = null;
  21533. }
  21534. if (from === to) {
  21535. return DONE;
  21536. }
  21537. var idx = reverse ? --to : from++;
  21538. values = iterateNodeOrLeaf(
  21539. array && array[idx], level - SHIFT, offset + (idx << level)
  21540. );
  21541. } while (true);
  21542. };
  21543. }
  21544. }
  21545. function makeList(origin, capacity, level, root, tail, ownerID, hash) {
  21546. var list = Object.create(ListPrototype);
  21547. list.size = capacity - origin;
  21548. list._origin = origin;
  21549. list._capacity = capacity;
  21550. list._level = level;
  21551. list._root = root;
  21552. list._tail = tail;
  21553. list.__ownerID = ownerID;
  21554. list.__hash = hash;
  21555. list.__altered = false;
  21556. return list;
  21557. }
  21558. var EMPTY_LIST;
  21559. function emptyList() {
  21560. return EMPTY_LIST || (EMPTY_LIST = makeList(0, 0, SHIFT));
  21561. }
  21562. function updateList(list, index, value) {
  21563. index = wrapIndex(list, index);
  21564. if (index !== index) {
  21565. return list;
  21566. }
  21567. if (index >= list.size || index < 0) {
  21568. return list.withMutations(function(list ) {
  21569. index < 0 ?
  21570. setListBounds(list, index).set(0, value) :
  21571. setListBounds(list, 0, index + 1).set(index, value);
  21572. });
  21573. }
  21574. index += list._origin;
  21575. var newTail = list._tail;
  21576. var newRoot = list._root;
  21577. var didAlter = MakeRef(DID_ALTER);
  21578. if (index >= getTailOffset(list._capacity)) {
  21579. newTail = updateVNode(newTail, list.__ownerID, 0, index, value, didAlter);
  21580. } else {
  21581. newRoot = updateVNode(newRoot, list.__ownerID, list._level, index, value, didAlter);
  21582. }
  21583. if (!didAlter.value) {
  21584. return list;
  21585. }
  21586. if (list.__ownerID) {
  21587. list._root = newRoot;
  21588. list._tail = newTail;
  21589. list.__hash = undefined;
  21590. list.__altered = true;
  21591. return list;
  21592. }
  21593. return makeList(list._origin, list._capacity, list._level, newRoot, newTail);
  21594. }
  21595. function updateVNode(node, ownerID, level, index, value, didAlter) {
  21596. var idx = (index >>> level) & MASK;
  21597. var nodeHas = node && idx < node.array.length;
  21598. if (!nodeHas && value === undefined) {
  21599. return node;
  21600. }
  21601. var newNode;
  21602. if (level > 0) {
  21603. var lowerNode = node && node.array[idx];
  21604. var newLowerNode = updateVNode(lowerNode, ownerID, level - SHIFT, index, value, didAlter);
  21605. if (newLowerNode === lowerNode) {
  21606. return node;
  21607. }
  21608. newNode = editableVNode(node, ownerID);
  21609. newNode.array[idx] = newLowerNode;
  21610. return newNode;
  21611. }
  21612. if (nodeHas && node.array[idx] === value) {
  21613. return node;
  21614. }
  21615. SetRef(didAlter);
  21616. newNode = editableVNode(node, ownerID);
  21617. if (value === undefined && idx === newNode.array.length - 1) {
  21618. newNode.array.pop();
  21619. } else {
  21620. newNode.array[idx] = value;
  21621. }
  21622. return newNode;
  21623. }
  21624. function editableVNode(node, ownerID) {
  21625. if (ownerID && node && ownerID === node.ownerID) {
  21626. return node;
  21627. }
  21628. return new VNode(node ? node.array.slice() : [], ownerID);
  21629. }
  21630. function listNodeFor(list, rawIndex) {
  21631. if (rawIndex >= getTailOffset(list._capacity)) {
  21632. return list._tail;
  21633. }
  21634. if (rawIndex < 1 << (list._level + SHIFT)) {
  21635. var node = list._root;
  21636. var level = list._level;
  21637. while (node && level > 0) {
  21638. node = node.array[(rawIndex >>> level) & MASK];
  21639. level -= SHIFT;
  21640. }
  21641. return node;
  21642. }
  21643. }
  21644. function setListBounds(list, begin, end) {
  21645. // Sanitize begin & end using this shorthand for ToInt32(argument)
  21646. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  21647. if (begin !== undefined) {
  21648. begin = begin | 0;
  21649. }
  21650. if (end !== undefined) {
  21651. end = end | 0;
  21652. }
  21653. var owner = list.__ownerID || new OwnerID();
  21654. var oldOrigin = list._origin;
  21655. var oldCapacity = list._capacity;
  21656. var newOrigin = oldOrigin + begin;
  21657. var newCapacity = end === undefined ? oldCapacity : end < 0 ? oldCapacity + end : oldOrigin + end;
  21658. if (newOrigin === oldOrigin && newCapacity === oldCapacity) {
  21659. return list;
  21660. }
  21661. // If it's going to end after it starts, it's empty.
  21662. if (newOrigin >= newCapacity) {
  21663. return list.clear();
  21664. }
  21665. var newLevel = list._level;
  21666. var newRoot = list._root;
  21667. // New origin might need creating a higher root.
  21668. var offsetShift = 0;
  21669. while (newOrigin + offsetShift < 0) {
  21670. newRoot = new VNode(newRoot && newRoot.array.length ? [undefined, newRoot] : [], owner);
  21671. newLevel += SHIFT;
  21672. offsetShift += 1 << newLevel;
  21673. }
  21674. if (offsetShift) {
  21675. newOrigin += offsetShift;
  21676. oldOrigin += offsetShift;
  21677. newCapacity += offsetShift;
  21678. oldCapacity += offsetShift;
  21679. }
  21680. var oldTailOffset = getTailOffset(oldCapacity);
  21681. var newTailOffset = getTailOffset(newCapacity);
  21682. // New size might need creating a higher root.
  21683. while (newTailOffset >= 1 << (newLevel + SHIFT)) {
  21684. newRoot = new VNode(newRoot && newRoot.array.length ? [newRoot] : [], owner);
  21685. newLevel += SHIFT;
  21686. }
  21687. // Locate or create the new tail.
  21688. var oldTail = list._tail;
  21689. var newTail = newTailOffset < oldTailOffset ?
  21690. listNodeFor(list, newCapacity - 1) :
  21691. newTailOffset > oldTailOffset ? new VNode([], owner) : oldTail;
  21692. // Merge Tail into tree.
  21693. if (oldTail && newTailOffset > oldTailOffset && newOrigin < oldCapacity && oldTail.array.length) {
  21694. newRoot = editableVNode(newRoot, owner);
  21695. var node = newRoot;
  21696. for (var level = newLevel; level > SHIFT; level -= SHIFT) {
  21697. var idx = (oldTailOffset >>> level) & MASK;
  21698. node = node.array[idx] = editableVNode(node.array[idx], owner);
  21699. }
  21700. node.array[(oldTailOffset >>> SHIFT) & MASK] = oldTail;
  21701. }
  21702. // If the size has been reduced, there's a chance the tail needs to be trimmed.
  21703. if (newCapacity < oldCapacity) {
  21704. newTail = newTail && newTail.removeAfter(owner, 0, newCapacity);
  21705. }
  21706. // If the new origin is within the tail, then we do not need a root.
  21707. if (newOrigin >= newTailOffset) {
  21708. newOrigin -= newTailOffset;
  21709. newCapacity -= newTailOffset;
  21710. newLevel = SHIFT;
  21711. newRoot = null;
  21712. newTail = newTail && newTail.removeBefore(owner, 0, newOrigin);
  21713. // Otherwise, if the root has been trimmed, garbage collect.
  21714. } else if (newOrigin > oldOrigin || newTailOffset < oldTailOffset) {
  21715. offsetShift = 0;
  21716. // Identify the new top root node of the subtree of the old root.
  21717. while (newRoot) {
  21718. var beginIndex = (newOrigin >>> newLevel) & MASK;
  21719. if (beginIndex !== (newTailOffset >>> newLevel) & MASK) {
  21720. break;
  21721. }
  21722. if (beginIndex) {
  21723. offsetShift += (1 << newLevel) * beginIndex;
  21724. }
  21725. newLevel -= SHIFT;
  21726. newRoot = newRoot.array[beginIndex];
  21727. }
  21728. // Trim the new sides of the new root.
  21729. if (newRoot && newOrigin > oldOrigin) {
  21730. newRoot = newRoot.removeBefore(owner, newLevel, newOrigin - offsetShift);
  21731. }
  21732. if (newRoot && newTailOffset < oldTailOffset) {
  21733. newRoot = newRoot.removeAfter(owner, newLevel, newTailOffset - offsetShift);
  21734. }
  21735. if (offsetShift) {
  21736. newOrigin -= offsetShift;
  21737. newCapacity -= offsetShift;
  21738. }
  21739. }
  21740. if (list.__ownerID) {
  21741. list.size = newCapacity - newOrigin;
  21742. list._origin = newOrigin;
  21743. list._capacity = newCapacity;
  21744. list._level = newLevel;
  21745. list._root = newRoot;
  21746. list._tail = newTail;
  21747. list.__hash = undefined;
  21748. list.__altered = true;
  21749. return list;
  21750. }
  21751. return makeList(newOrigin, newCapacity, newLevel, newRoot, newTail);
  21752. }
  21753. function mergeIntoListWith(list, merger, iterables) {
  21754. var iters = [];
  21755. var maxSize = 0;
  21756. for (var ii = 0; ii < iterables.length; ii++) {
  21757. var value = iterables[ii];
  21758. var iter = IndexedIterable(value);
  21759. if (iter.size > maxSize) {
  21760. maxSize = iter.size;
  21761. }
  21762. if (!isIterable(value)) {
  21763. iter = iter.map(function(v ) {return fromJS(v)});
  21764. }
  21765. iters.push(iter);
  21766. }
  21767. if (maxSize > list.size) {
  21768. list = list.setSize(maxSize);
  21769. }
  21770. return mergeIntoCollectionWith(list, merger, iters);
  21771. }
  21772. function getTailOffset(size) {
  21773. return size < SIZE ? 0 : (((size - 1) >>> SHIFT) << SHIFT);
  21774. }
  21775. createClass(OrderedMap, Map);
  21776. // @pragma Construction
  21777. function OrderedMap(value) {
  21778. return value === null || value === undefined ? emptyOrderedMap() :
  21779. isOrderedMap(value) ? value :
  21780. emptyOrderedMap().withMutations(function(map ) {
  21781. var iter = KeyedIterable(value);
  21782. assertNotInfinite(iter.size);
  21783. iter.forEach(function(v, k) {return map.set(k, v)});
  21784. });
  21785. }
  21786. OrderedMap.of = function(/*...values*/) {
  21787. return this(arguments);
  21788. };
  21789. OrderedMap.prototype.toString = function() {
  21790. return this.__toString('OrderedMap {', '}');
  21791. };
  21792. // @pragma Access
  21793. OrderedMap.prototype.get = function(k, notSetValue) {
  21794. var index = this._map.get(k);
  21795. return index !== undefined ? this._list.get(index)[1] : notSetValue;
  21796. };
  21797. // @pragma Modification
  21798. OrderedMap.prototype.clear = function() {
  21799. if (this.size === 0) {
  21800. return this;
  21801. }
  21802. if (this.__ownerID) {
  21803. this.size = 0;
  21804. this._map.clear();
  21805. this._list.clear();
  21806. return this;
  21807. }
  21808. return emptyOrderedMap();
  21809. };
  21810. OrderedMap.prototype.set = function(k, v) {
  21811. return updateOrderedMap(this, k, v);
  21812. };
  21813. OrderedMap.prototype.remove = function(k) {
  21814. return updateOrderedMap(this, k, NOT_SET);
  21815. };
  21816. OrderedMap.prototype.wasAltered = function() {
  21817. return this._map.wasAltered() || this._list.wasAltered();
  21818. };
  21819. OrderedMap.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  21820. return this._list.__iterate(
  21821. function(entry ) {return entry && fn(entry[1], entry[0], this$0)},
  21822. reverse
  21823. );
  21824. };
  21825. OrderedMap.prototype.__iterator = function(type, reverse) {
  21826. return this._list.fromEntrySeq().__iterator(type, reverse);
  21827. };
  21828. OrderedMap.prototype.__ensureOwner = function(ownerID) {
  21829. if (ownerID === this.__ownerID) {
  21830. return this;
  21831. }
  21832. var newMap = this._map.__ensureOwner(ownerID);
  21833. var newList = this._list.__ensureOwner(ownerID);
  21834. if (!ownerID) {
  21835. this.__ownerID = ownerID;
  21836. this._map = newMap;
  21837. this._list = newList;
  21838. return this;
  21839. }
  21840. return makeOrderedMap(newMap, newList, ownerID, this.__hash);
  21841. };
  21842. function isOrderedMap(maybeOrderedMap) {
  21843. return isMap(maybeOrderedMap) && isOrdered(maybeOrderedMap);
  21844. }
  21845. OrderedMap.isOrderedMap = isOrderedMap;
  21846. OrderedMap.prototype[IS_ORDERED_SENTINEL] = true;
  21847. OrderedMap.prototype[DELETE] = OrderedMap.prototype.remove;
  21848. function makeOrderedMap(map, list, ownerID, hash) {
  21849. var omap = Object.create(OrderedMap.prototype);
  21850. omap.size = map ? map.size : 0;
  21851. omap._map = map;
  21852. omap._list = list;
  21853. omap.__ownerID = ownerID;
  21854. omap.__hash = hash;
  21855. return omap;
  21856. }
  21857. var EMPTY_ORDERED_MAP;
  21858. function emptyOrderedMap() {
  21859. return EMPTY_ORDERED_MAP || (EMPTY_ORDERED_MAP = makeOrderedMap(emptyMap(), emptyList()));
  21860. }
  21861. function updateOrderedMap(omap, k, v) {
  21862. var map = omap._map;
  21863. var list = omap._list;
  21864. var i = map.get(k);
  21865. var has = i !== undefined;
  21866. var newMap;
  21867. var newList;
  21868. if (v === NOT_SET) { // removed
  21869. if (!has) {
  21870. return omap;
  21871. }
  21872. if (list.size >= SIZE && list.size >= map.size * 2) {
  21873. newList = list.filter(function(entry, idx) {return entry !== undefined && i !== idx});
  21874. newMap = newList.toKeyedSeq().map(function(entry ) {return entry[0]}).flip().toMap();
  21875. if (omap.__ownerID) {
  21876. newMap.__ownerID = newList.__ownerID = omap.__ownerID;
  21877. }
  21878. } else {
  21879. newMap = map.remove(k);
  21880. newList = i === list.size - 1 ? list.pop() : list.set(i, undefined);
  21881. }
  21882. } else {
  21883. if (has) {
  21884. if (v === list.get(i)[1]) {
  21885. return omap;
  21886. }
  21887. newMap = map;
  21888. newList = list.set(i, [k, v]);
  21889. } else {
  21890. newMap = map.set(k, list.size);
  21891. newList = list.set(list.size, [k, v]);
  21892. }
  21893. }
  21894. if (omap.__ownerID) {
  21895. omap.size = newMap.size;
  21896. omap._map = newMap;
  21897. omap._list = newList;
  21898. omap.__hash = undefined;
  21899. return omap;
  21900. }
  21901. return makeOrderedMap(newMap, newList);
  21902. }
  21903. createClass(ToKeyedSequence, KeyedSeq);
  21904. function ToKeyedSequence(indexed, useKeys) {
  21905. this._iter = indexed;
  21906. this._useKeys = useKeys;
  21907. this.size = indexed.size;
  21908. }
  21909. ToKeyedSequence.prototype.get = function(key, notSetValue) {
  21910. return this._iter.get(key, notSetValue);
  21911. };
  21912. ToKeyedSequence.prototype.has = function(key) {
  21913. return this._iter.has(key);
  21914. };
  21915. ToKeyedSequence.prototype.valueSeq = function() {
  21916. return this._iter.valueSeq();
  21917. };
  21918. ToKeyedSequence.prototype.reverse = function() {var this$0 = this;
  21919. var reversedSequence = reverseFactory(this, true);
  21920. if (!this._useKeys) {
  21921. reversedSequence.valueSeq = function() {return this$0._iter.toSeq().reverse()};
  21922. }
  21923. return reversedSequence;
  21924. };
  21925. ToKeyedSequence.prototype.map = function(mapper, context) {var this$0 = this;
  21926. var mappedSequence = mapFactory(this, mapper, context);
  21927. if (!this._useKeys) {
  21928. mappedSequence.valueSeq = function() {return this$0._iter.toSeq().map(mapper, context)};
  21929. }
  21930. return mappedSequence;
  21931. };
  21932. ToKeyedSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  21933. var ii;
  21934. return this._iter.__iterate(
  21935. this._useKeys ?
  21936. function(v, k) {return fn(v, k, this$0)} :
  21937. ((ii = reverse ? resolveSize(this) : 0),
  21938. function(v ) {return fn(v, reverse ? --ii : ii++, this$0)}),
  21939. reverse
  21940. );
  21941. };
  21942. ToKeyedSequence.prototype.__iterator = function(type, reverse) {
  21943. if (this._useKeys) {
  21944. return this._iter.__iterator(type, reverse);
  21945. }
  21946. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  21947. var ii = reverse ? resolveSize(this) : 0;
  21948. return new Iterator(function() {
  21949. var step = iterator.next();
  21950. return step.done ? step :
  21951. iteratorValue(type, reverse ? --ii : ii++, step.value, step);
  21952. });
  21953. };
  21954. ToKeyedSequence.prototype[IS_ORDERED_SENTINEL] = true;
  21955. createClass(ToIndexedSequence, IndexedSeq);
  21956. function ToIndexedSequence(iter) {
  21957. this._iter = iter;
  21958. this.size = iter.size;
  21959. }
  21960. ToIndexedSequence.prototype.includes = function(value) {
  21961. return this._iter.includes(value);
  21962. };
  21963. ToIndexedSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  21964. var iterations = 0;
  21965. return this._iter.__iterate(function(v ) {return fn(v, iterations++, this$0)}, reverse);
  21966. };
  21967. ToIndexedSequence.prototype.__iterator = function(type, reverse) {
  21968. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  21969. var iterations = 0;
  21970. return new Iterator(function() {
  21971. var step = iterator.next();
  21972. return step.done ? step :
  21973. iteratorValue(type, iterations++, step.value, step)
  21974. });
  21975. };
  21976. createClass(ToSetSequence, SetSeq);
  21977. function ToSetSequence(iter) {
  21978. this._iter = iter;
  21979. this.size = iter.size;
  21980. }
  21981. ToSetSequence.prototype.has = function(key) {
  21982. return this._iter.includes(key);
  21983. };
  21984. ToSetSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  21985. return this._iter.__iterate(function(v ) {return fn(v, v, this$0)}, reverse);
  21986. };
  21987. ToSetSequence.prototype.__iterator = function(type, reverse) {
  21988. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  21989. return new Iterator(function() {
  21990. var step = iterator.next();
  21991. return step.done ? step :
  21992. iteratorValue(type, step.value, step.value, step);
  21993. });
  21994. };
  21995. createClass(FromEntriesSequence, KeyedSeq);
  21996. function FromEntriesSequence(entries) {
  21997. this._iter = entries;
  21998. this.size = entries.size;
  21999. }
  22000. FromEntriesSequence.prototype.entrySeq = function() {
  22001. return this._iter.toSeq();
  22002. };
  22003. FromEntriesSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  22004. return this._iter.__iterate(function(entry ) {
  22005. // Check if entry exists first so array access doesn't throw for holes
  22006. // in the parent iteration.
  22007. if (entry) {
  22008. validateEntry(entry);
  22009. var indexedIterable = isIterable(entry);
  22010. return fn(
  22011. indexedIterable ? entry.get(1) : entry[1],
  22012. indexedIterable ? entry.get(0) : entry[0],
  22013. this$0
  22014. );
  22015. }
  22016. }, reverse);
  22017. };
  22018. FromEntriesSequence.prototype.__iterator = function(type, reverse) {
  22019. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  22020. return new Iterator(function() {
  22021. while (true) {
  22022. var step = iterator.next();
  22023. if (step.done) {
  22024. return step;
  22025. }
  22026. var entry = step.value;
  22027. // Check if entry exists first so array access doesn't throw for holes
  22028. // in the parent iteration.
  22029. if (entry) {
  22030. validateEntry(entry);
  22031. var indexedIterable = isIterable(entry);
  22032. return iteratorValue(
  22033. type,
  22034. indexedIterable ? entry.get(0) : entry[0],
  22035. indexedIterable ? entry.get(1) : entry[1],
  22036. step
  22037. );
  22038. }
  22039. }
  22040. });
  22041. };
  22042. ToIndexedSequence.prototype.cacheResult =
  22043. ToKeyedSequence.prototype.cacheResult =
  22044. ToSetSequence.prototype.cacheResult =
  22045. FromEntriesSequence.prototype.cacheResult =
  22046. cacheResultThrough;
  22047. function flipFactory(iterable) {
  22048. var flipSequence = makeSequence(iterable);
  22049. flipSequence._iter = iterable;
  22050. flipSequence.size = iterable.size;
  22051. flipSequence.flip = function() {return iterable};
  22052. flipSequence.reverse = function () {
  22053. var reversedSequence = iterable.reverse.apply(this); // super.reverse()
  22054. reversedSequence.flip = function() {return iterable.reverse()};
  22055. return reversedSequence;
  22056. };
  22057. flipSequence.has = function(key ) {return iterable.includes(key)};
  22058. flipSequence.includes = function(key ) {return iterable.has(key)};
  22059. flipSequence.cacheResult = cacheResultThrough;
  22060. flipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  22061. return iterable.__iterate(function(v, k) {return fn(k, v, this$0) !== false}, reverse);
  22062. };
  22063. flipSequence.__iteratorUncached = function(type, reverse) {
  22064. if (type === ITERATE_ENTRIES) {
  22065. var iterator = iterable.__iterator(type, reverse);
  22066. return new Iterator(function() {
  22067. var step = iterator.next();
  22068. if (!step.done) {
  22069. var k = step.value[0];
  22070. step.value[0] = step.value[1];
  22071. step.value[1] = k;
  22072. }
  22073. return step;
  22074. });
  22075. }
  22076. return iterable.__iterator(
  22077. type === ITERATE_VALUES ? ITERATE_KEYS : ITERATE_VALUES,
  22078. reverse
  22079. );
  22080. };
  22081. return flipSequence;
  22082. }
  22083. function mapFactory(iterable, mapper, context) {
  22084. var mappedSequence = makeSequence(iterable);
  22085. mappedSequence.size = iterable.size;
  22086. mappedSequence.has = function(key ) {return iterable.has(key)};
  22087. mappedSequence.get = function(key, notSetValue) {
  22088. var v = iterable.get(key, NOT_SET);
  22089. return v === NOT_SET ?
  22090. notSetValue :
  22091. mapper.call(context, v, key, iterable);
  22092. };
  22093. mappedSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  22094. return iterable.__iterate(
  22095. function(v, k, c) {return fn(mapper.call(context, v, k, c), k, this$0) !== false},
  22096. reverse
  22097. );
  22098. };
  22099. mappedSequence.__iteratorUncached = function (type, reverse) {
  22100. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  22101. return new Iterator(function() {
  22102. var step = iterator.next();
  22103. if (step.done) {
  22104. return step;
  22105. }
  22106. var entry = step.value;
  22107. var key = entry[0];
  22108. return iteratorValue(
  22109. type,
  22110. key,
  22111. mapper.call(context, entry[1], key, iterable),
  22112. step
  22113. );
  22114. });
  22115. };
  22116. return mappedSequence;
  22117. }
  22118. function reverseFactory(iterable, useKeys) {
  22119. var reversedSequence = makeSequence(iterable);
  22120. reversedSequence._iter = iterable;
  22121. reversedSequence.size = iterable.size;
  22122. reversedSequence.reverse = function() {return iterable};
  22123. if (iterable.flip) {
  22124. reversedSequence.flip = function () {
  22125. var flipSequence = flipFactory(iterable);
  22126. flipSequence.reverse = function() {return iterable.flip()};
  22127. return flipSequence;
  22128. };
  22129. }
  22130. reversedSequence.get = function(key, notSetValue)
  22131. {return iterable.get(useKeys ? key : -1 - key, notSetValue)};
  22132. reversedSequence.has = function(key )
  22133. {return iterable.has(useKeys ? key : -1 - key)};
  22134. reversedSequence.includes = function(value ) {return iterable.includes(value)};
  22135. reversedSequence.cacheResult = cacheResultThrough;
  22136. reversedSequence.__iterate = function (fn, reverse) {var this$0 = this;
  22137. return iterable.__iterate(function(v, k) {return fn(v, k, this$0)}, !reverse);
  22138. };
  22139. reversedSequence.__iterator =
  22140. function(type, reverse) {return iterable.__iterator(type, !reverse)};
  22141. return reversedSequence;
  22142. }
  22143. function filterFactory(iterable, predicate, context, useKeys) {
  22144. var filterSequence = makeSequence(iterable);
  22145. if (useKeys) {
  22146. filterSequence.has = function(key ) {
  22147. var v = iterable.get(key, NOT_SET);
  22148. return v !== NOT_SET && !!predicate.call(context, v, key, iterable);
  22149. };
  22150. filterSequence.get = function(key, notSetValue) {
  22151. var v = iterable.get(key, NOT_SET);
  22152. return v !== NOT_SET && predicate.call(context, v, key, iterable) ?
  22153. v : notSetValue;
  22154. };
  22155. }
  22156. filterSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  22157. var iterations = 0;
  22158. iterable.__iterate(function(v, k, c) {
  22159. if (predicate.call(context, v, k, c)) {
  22160. iterations++;
  22161. return fn(v, useKeys ? k : iterations - 1, this$0);
  22162. }
  22163. }, reverse);
  22164. return iterations;
  22165. };
  22166. filterSequence.__iteratorUncached = function (type, reverse) {
  22167. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  22168. var iterations = 0;
  22169. return new Iterator(function() {
  22170. while (true) {
  22171. var step = iterator.next();
  22172. if (step.done) {
  22173. return step;
  22174. }
  22175. var entry = step.value;
  22176. var key = entry[0];
  22177. var value = entry[1];
  22178. if (predicate.call(context, value, key, iterable)) {
  22179. return iteratorValue(type, useKeys ? key : iterations++, value, step);
  22180. }
  22181. }
  22182. });
  22183. };
  22184. return filterSequence;
  22185. }
  22186. function countByFactory(iterable, grouper, context) {
  22187. var groups = Map().asMutable();
  22188. iterable.__iterate(function(v, k) {
  22189. groups.update(
  22190. grouper.call(context, v, k, iterable),
  22191. 0,
  22192. function(a ) {return a + 1}
  22193. );
  22194. });
  22195. return groups.asImmutable();
  22196. }
  22197. function groupByFactory(iterable, grouper, context) {
  22198. var isKeyedIter = isKeyed(iterable);
  22199. var groups = (isOrdered(iterable) ? OrderedMap() : Map()).asMutable();
  22200. iterable.__iterate(function(v, k) {
  22201. groups.update(
  22202. grouper.call(context, v, k, iterable),
  22203. function(a ) {return (a = a || [], a.push(isKeyedIter ? [k, v] : v), a)}
  22204. );
  22205. });
  22206. var coerce = iterableClass(iterable);
  22207. return groups.map(function(arr ) {return reify(iterable, coerce(arr))});
  22208. }
  22209. function sliceFactory(iterable, begin, end, useKeys) {
  22210. var originalSize = iterable.size;
  22211. // Sanitize begin & end using this shorthand for ToInt32(argument)
  22212. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  22213. if (begin !== undefined) {
  22214. begin = begin | 0;
  22215. }
  22216. if (end !== undefined) {
  22217. end = end | 0;
  22218. }
  22219. if (wholeSlice(begin, end, originalSize)) {
  22220. return iterable;
  22221. }
  22222. var resolvedBegin = resolveBegin(begin, originalSize);
  22223. var resolvedEnd = resolveEnd(end, originalSize);
  22224. // begin or end will be NaN if they were provided as negative numbers and
  22225. // this iterable's size is unknown. In that case, cache first so there is
  22226. // a known size and these do not resolve to NaN.
  22227. if (resolvedBegin !== resolvedBegin || resolvedEnd !== resolvedEnd) {
  22228. return sliceFactory(iterable.toSeq().cacheResult(), begin, end, useKeys);
  22229. }
  22230. // Note: resolvedEnd is undefined when the original sequence's length is
  22231. // unknown and this slice did not supply an end and should contain all
  22232. // elements after resolvedBegin.
  22233. // In that case, resolvedSize will be NaN and sliceSize will remain undefined.
  22234. var resolvedSize = resolvedEnd - resolvedBegin;
  22235. var sliceSize;
  22236. if (resolvedSize === resolvedSize) {
  22237. sliceSize = resolvedSize < 0 ? 0 : resolvedSize;
  22238. }
  22239. var sliceSeq = makeSequence(iterable);
  22240. // If iterable.size is undefined, the size of the realized sliceSeq is
  22241. // unknown at this point unless the number of items to slice is 0
  22242. sliceSeq.size = sliceSize === 0 ? sliceSize : iterable.size && sliceSize || undefined;
  22243. if (!useKeys && isSeq(iterable) && sliceSize >= 0) {
  22244. sliceSeq.get = function (index, notSetValue) {
  22245. index = wrapIndex(this, index);
  22246. return index >= 0 && index < sliceSize ?
  22247. iterable.get(index + resolvedBegin, notSetValue) :
  22248. notSetValue;
  22249. };
  22250. }
  22251. sliceSeq.__iterateUncached = function(fn, reverse) {var this$0 = this;
  22252. if (sliceSize === 0) {
  22253. return 0;
  22254. }
  22255. if (reverse) {
  22256. return this.cacheResult().__iterate(fn, reverse);
  22257. }
  22258. var skipped = 0;
  22259. var isSkipping = true;
  22260. var iterations = 0;
  22261. iterable.__iterate(function(v, k) {
  22262. if (!(isSkipping && (isSkipping = skipped++ < resolvedBegin))) {
  22263. iterations++;
  22264. return fn(v, useKeys ? k : iterations - 1, this$0) !== false &&
  22265. iterations !== sliceSize;
  22266. }
  22267. });
  22268. return iterations;
  22269. };
  22270. sliceSeq.__iteratorUncached = function(type, reverse) {
  22271. if (sliceSize !== 0 && reverse) {
  22272. return this.cacheResult().__iterator(type, reverse);
  22273. }
  22274. // Don't bother instantiating parent iterator if taking 0.
  22275. var iterator = sliceSize !== 0 && iterable.__iterator(type, reverse);
  22276. var skipped = 0;
  22277. var iterations = 0;
  22278. return new Iterator(function() {
  22279. while (skipped++ < resolvedBegin) {
  22280. iterator.next();
  22281. }
  22282. if (++iterations > sliceSize) {
  22283. return iteratorDone();
  22284. }
  22285. var step = iterator.next();
  22286. if (useKeys || type === ITERATE_VALUES) {
  22287. return step;
  22288. } else if (type === ITERATE_KEYS) {
  22289. return iteratorValue(type, iterations - 1, undefined, step);
  22290. } else {
  22291. return iteratorValue(type, iterations - 1, step.value[1], step);
  22292. }
  22293. });
  22294. };
  22295. return sliceSeq;
  22296. }
  22297. function takeWhileFactory(iterable, predicate, context) {
  22298. var takeSequence = makeSequence(iterable);
  22299. takeSequence.__iterateUncached = function(fn, reverse) {var this$0 = this;
  22300. if (reverse) {
  22301. return this.cacheResult().__iterate(fn, reverse);
  22302. }
  22303. var iterations = 0;
  22304. iterable.__iterate(function(v, k, c)
  22305. {return predicate.call(context, v, k, c) && ++iterations && fn(v, k, this$0)}
  22306. );
  22307. return iterations;
  22308. };
  22309. takeSequence.__iteratorUncached = function(type, reverse) {var this$0 = this;
  22310. if (reverse) {
  22311. return this.cacheResult().__iterator(type, reverse);
  22312. }
  22313. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  22314. var iterating = true;
  22315. return new Iterator(function() {
  22316. if (!iterating) {
  22317. return iteratorDone();
  22318. }
  22319. var step = iterator.next();
  22320. if (step.done) {
  22321. return step;
  22322. }
  22323. var entry = step.value;
  22324. var k = entry[0];
  22325. var v = entry[1];
  22326. if (!predicate.call(context, v, k, this$0)) {
  22327. iterating = false;
  22328. return iteratorDone();
  22329. }
  22330. return type === ITERATE_ENTRIES ? step :
  22331. iteratorValue(type, k, v, step);
  22332. });
  22333. };
  22334. return takeSequence;
  22335. }
  22336. function skipWhileFactory(iterable, predicate, context, useKeys) {
  22337. var skipSequence = makeSequence(iterable);
  22338. skipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  22339. if (reverse) {
  22340. return this.cacheResult().__iterate(fn, reverse);
  22341. }
  22342. var isSkipping = true;
  22343. var iterations = 0;
  22344. iterable.__iterate(function(v, k, c) {
  22345. if (!(isSkipping && (isSkipping = predicate.call(context, v, k, c)))) {
  22346. iterations++;
  22347. return fn(v, useKeys ? k : iterations - 1, this$0);
  22348. }
  22349. });
  22350. return iterations;
  22351. };
  22352. skipSequence.__iteratorUncached = function(type, reverse) {var this$0 = this;
  22353. if (reverse) {
  22354. return this.cacheResult().__iterator(type, reverse);
  22355. }
  22356. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  22357. var skipping = true;
  22358. var iterations = 0;
  22359. return new Iterator(function() {
  22360. var step, k, v;
  22361. do {
  22362. step = iterator.next();
  22363. if (step.done) {
  22364. if (useKeys || type === ITERATE_VALUES) {
  22365. return step;
  22366. } else if (type === ITERATE_KEYS) {
  22367. return iteratorValue(type, iterations++, undefined, step);
  22368. } else {
  22369. return iteratorValue(type, iterations++, step.value[1], step);
  22370. }
  22371. }
  22372. var entry = step.value;
  22373. k = entry[0];
  22374. v = entry[1];
  22375. skipping && (skipping = predicate.call(context, v, k, this$0));
  22376. } while (skipping);
  22377. return type === ITERATE_ENTRIES ? step :
  22378. iteratorValue(type, k, v, step);
  22379. });
  22380. };
  22381. return skipSequence;
  22382. }
  22383. function concatFactory(iterable, values) {
  22384. var isKeyedIterable = isKeyed(iterable);
  22385. var iters = [iterable].concat(values).map(function(v ) {
  22386. if (!isIterable(v)) {
  22387. v = isKeyedIterable ?
  22388. keyedSeqFromValue(v) :
  22389. indexedSeqFromValue(Array.isArray(v) ? v : [v]);
  22390. } else if (isKeyedIterable) {
  22391. v = KeyedIterable(v);
  22392. }
  22393. return v;
  22394. }).filter(function(v ) {return v.size !== 0});
  22395. if (iters.length === 0) {
  22396. return iterable;
  22397. }
  22398. if (iters.length === 1) {
  22399. var singleton = iters[0];
  22400. if (singleton === iterable ||
  22401. isKeyedIterable && isKeyed(singleton) ||
  22402. isIndexed(iterable) && isIndexed(singleton)) {
  22403. return singleton;
  22404. }
  22405. }
  22406. var concatSeq = new ArraySeq(iters);
  22407. if (isKeyedIterable) {
  22408. concatSeq = concatSeq.toKeyedSeq();
  22409. } else if (!isIndexed(iterable)) {
  22410. concatSeq = concatSeq.toSetSeq();
  22411. }
  22412. concatSeq = concatSeq.flatten(true);
  22413. concatSeq.size = iters.reduce(
  22414. function(sum, seq) {
  22415. if (sum !== undefined) {
  22416. var size = seq.size;
  22417. if (size !== undefined) {
  22418. return sum + size;
  22419. }
  22420. }
  22421. },
  22422. 0
  22423. );
  22424. return concatSeq;
  22425. }
  22426. function flattenFactory(iterable, depth, useKeys) {
  22427. var flatSequence = makeSequence(iterable);
  22428. flatSequence.__iterateUncached = function(fn, reverse) {
  22429. var iterations = 0;
  22430. var stopped = false;
  22431. function flatDeep(iter, currentDepth) {var this$0 = this;
  22432. iter.__iterate(function(v, k) {
  22433. if ((!depth || currentDepth < depth) && isIterable(v)) {
  22434. flatDeep(v, currentDepth + 1);
  22435. } else if (fn(v, useKeys ? k : iterations++, this$0) === false) {
  22436. stopped = true;
  22437. }
  22438. return !stopped;
  22439. }, reverse);
  22440. }
  22441. flatDeep(iterable, 0);
  22442. return iterations;
  22443. };
  22444. flatSequence.__iteratorUncached = function(type, reverse) {
  22445. var iterator = iterable.__iterator(type, reverse);
  22446. var stack = [];
  22447. var iterations = 0;
  22448. return new Iterator(function() {
  22449. while (iterator) {
  22450. var step = iterator.next();
  22451. if (step.done !== false) {
  22452. iterator = stack.pop();
  22453. continue;
  22454. }
  22455. var v = step.value;
  22456. if (type === ITERATE_ENTRIES) {
  22457. v = v[1];
  22458. }
  22459. if ((!depth || stack.length < depth) && isIterable(v)) {
  22460. stack.push(iterator);
  22461. iterator = v.__iterator(type, reverse);
  22462. } else {
  22463. return useKeys ? step : iteratorValue(type, iterations++, v, step);
  22464. }
  22465. }
  22466. return iteratorDone();
  22467. });
  22468. };
  22469. return flatSequence;
  22470. }
  22471. function flatMapFactory(iterable, mapper, context) {
  22472. var coerce = iterableClass(iterable);
  22473. return iterable.toSeq().map(
  22474. function(v, k) {return coerce(mapper.call(context, v, k, iterable))}
  22475. ).flatten(true);
  22476. }
  22477. function interposeFactory(iterable, separator) {
  22478. var interposedSequence = makeSequence(iterable);
  22479. interposedSequence.size = iterable.size && iterable.size * 2 -1;
  22480. interposedSequence.__iterateUncached = function(fn, reverse) {var this$0 = this;
  22481. var iterations = 0;
  22482. iterable.__iterate(function(v, k)
  22483. {return (!iterations || fn(separator, iterations++, this$0) !== false) &&
  22484. fn(v, iterations++, this$0) !== false},
  22485. reverse
  22486. );
  22487. return iterations;
  22488. };
  22489. interposedSequence.__iteratorUncached = function(type, reverse) {
  22490. var iterator = iterable.__iterator(ITERATE_VALUES, reverse);
  22491. var iterations = 0;
  22492. var step;
  22493. return new Iterator(function() {
  22494. if (!step || iterations % 2) {
  22495. step = iterator.next();
  22496. if (step.done) {
  22497. return step;
  22498. }
  22499. }
  22500. return iterations % 2 ?
  22501. iteratorValue(type, iterations++, separator) :
  22502. iteratorValue(type, iterations++, step.value, step);
  22503. });
  22504. };
  22505. return interposedSequence;
  22506. }
  22507. function sortFactory(iterable, comparator, mapper) {
  22508. if (!comparator) {
  22509. comparator = defaultComparator;
  22510. }
  22511. var isKeyedIterable = isKeyed(iterable);
  22512. var index = 0;
  22513. var entries = iterable.toSeq().map(
  22514. function(v, k) {return [k, v, index++, mapper ? mapper(v, k, iterable) : v]}
  22515. ).toArray();
  22516. entries.sort(function(a, b) {return comparator(a[3], b[3]) || a[2] - b[2]}).forEach(
  22517. isKeyedIterable ?
  22518. function(v, i) { entries[i].length = 2; } :
  22519. function(v, i) { entries[i] = v[1]; }
  22520. );
  22521. return isKeyedIterable ? KeyedSeq(entries) :
  22522. isIndexed(iterable) ? IndexedSeq(entries) :
  22523. SetSeq(entries);
  22524. }
  22525. function maxFactory(iterable, comparator, mapper) {
  22526. if (!comparator) {
  22527. comparator = defaultComparator;
  22528. }
  22529. if (mapper) {
  22530. var entry = iterable.toSeq()
  22531. .map(function(v, k) {return [v, mapper(v, k, iterable)]})
  22532. .reduce(function(a, b) {return maxCompare(comparator, a[1], b[1]) ? b : a});
  22533. return entry && entry[0];
  22534. } else {
  22535. return iterable.reduce(function(a, b) {return maxCompare(comparator, a, b) ? b : a});
  22536. }
  22537. }
  22538. function maxCompare(comparator, a, b) {
  22539. var comp = comparator(b, a);
  22540. // b is considered the new max if the comparator declares them equal, but
  22541. // they are not equal and b is in fact a nullish value.
  22542. return (comp === 0 && b !== a && (b === undefined || b === null || b !== b)) || comp > 0;
  22543. }
  22544. function zipWithFactory(keyIter, zipper, iters) {
  22545. var zipSequence = makeSequence(keyIter);
  22546. zipSequence.size = new ArraySeq(iters).map(function(i ) {return i.size}).min();
  22547. // Note: this a generic base implementation of __iterate in terms of
  22548. // __iterator which may be more generically useful in the future.
  22549. zipSequence.__iterate = function(fn, reverse) {
  22550. /* generic:
  22551. var iterator = this.__iterator(ITERATE_ENTRIES, reverse);
  22552. var step;
  22553. var iterations = 0;
  22554. while (!(step = iterator.next()).done) {
  22555. iterations++;
  22556. if (fn(step.value[1], step.value[0], this) === false) {
  22557. break;
  22558. }
  22559. }
  22560. return iterations;
  22561. */
  22562. // indexed:
  22563. var iterator = this.__iterator(ITERATE_VALUES, reverse);
  22564. var step;
  22565. var iterations = 0;
  22566. while (!(step = iterator.next()).done) {
  22567. if (fn(step.value, iterations++, this) === false) {
  22568. break;
  22569. }
  22570. }
  22571. return iterations;
  22572. };
  22573. zipSequence.__iteratorUncached = function(type, reverse) {
  22574. var iterators = iters.map(function(i )
  22575. {return (i = Iterable(i), getIterator(reverse ? i.reverse() : i))}
  22576. );
  22577. var iterations = 0;
  22578. var isDone = false;
  22579. return new Iterator(function() {
  22580. var steps;
  22581. if (!isDone) {
  22582. steps = iterators.map(function(i ) {return i.next()});
  22583. isDone = steps.some(function(s ) {return s.done});
  22584. }
  22585. if (isDone) {
  22586. return iteratorDone();
  22587. }
  22588. return iteratorValue(
  22589. type,
  22590. iterations++,
  22591. zipper.apply(null, steps.map(function(s ) {return s.value}))
  22592. );
  22593. });
  22594. };
  22595. return zipSequence
  22596. }
  22597. // #pragma Helper Functions
  22598. function reify(iter, seq) {
  22599. return isSeq(iter) ? seq : iter.constructor(seq);
  22600. }
  22601. function validateEntry(entry) {
  22602. if (entry !== Object(entry)) {
  22603. throw new TypeError('Expected [K, V] tuple: ' + entry);
  22604. }
  22605. }
  22606. function resolveSize(iter) {
  22607. assertNotInfinite(iter.size);
  22608. return ensureSize(iter);
  22609. }
  22610. function iterableClass(iterable) {
  22611. return isKeyed(iterable) ? KeyedIterable :
  22612. isIndexed(iterable) ? IndexedIterable :
  22613. SetIterable;
  22614. }
  22615. function makeSequence(iterable) {
  22616. return Object.create(
  22617. (
  22618. isKeyed(iterable) ? KeyedSeq :
  22619. isIndexed(iterable) ? IndexedSeq :
  22620. SetSeq
  22621. ).prototype
  22622. );
  22623. }
  22624. function cacheResultThrough() {
  22625. if (this._iter.cacheResult) {
  22626. this._iter.cacheResult();
  22627. this.size = this._iter.size;
  22628. return this;
  22629. } else {
  22630. return Seq.prototype.cacheResult.call(this);
  22631. }
  22632. }
  22633. function defaultComparator(a, b) {
  22634. return a > b ? 1 : a < b ? -1 : 0;
  22635. }
  22636. function forceIterator(keyPath) {
  22637. var iter = getIterator(keyPath);
  22638. if (!iter) {
  22639. // Array might not be iterable in this environment, so we need a fallback
  22640. // to our wrapped type.
  22641. if (!isArrayLike(keyPath)) {
  22642. throw new TypeError('Expected iterable or array-like: ' + keyPath);
  22643. }
  22644. iter = getIterator(Iterable(keyPath));
  22645. }
  22646. return iter;
  22647. }
  22648. createClass(Record, KeyedCollection);
  22649. function Record(defaultValues, name) {
  22650. var hasInitialized;
  22651. var RecordType = function Record(values) {
  22652. if (values instanceof RecordType) {
  22653. return values;
  22654. }
  22655. if (!(this instanceof RecordType)) {
  22656. return new RecordType(values);
  22657. }
  22658. if (!hasInitialized) {
  22659. hasInitialized = true;
  22660. var keys = Object.keys(defaultValues);
  22661. setProps(RecordTypePrototype, keys);
  22662. RecordTypePrototype.size = keys.length;
  22663. RecordTypePrototype._name = name;
  22664. RecordTypePrototype._keys = keys;
  22665. RecordTypePrototype._defaultValues = defaultValues;
  22666. }
  22667. this._map = Map(values);
  22668. };
  22669. var RecordTypePrototype = RecordType.prototype = Object.create(RecordPrototype);
  22670. RecordTypePrototype.constructor = RecordType;
  22671. return RecordType;
  22672. }
  22673. Record.prototype.toString = function() {
  22674. return this.__toString(recordName(this) + ' {', '}');
  22675. };
  22676. // @pragma Access
  22677. Record.prototype.has = function(k) {
  22678. return this._defaultValues.hasOwnProperty(k);
  22679. };
  22680. Record.prototype.get = function(k, notSetValue) {
  22681. if (!this.has(k)) {
  22682. return notSetValue;
  22683. }
  22684. var defaultVal = this._defaultValues[k];
  22685. return this._map ? this._map.get(k, defaultVal) : defaultVal;
  22686. };
  22687. // @pragma Modification
  22688. Record.prototype.clear = function() {
  22689. if (this.__ownerID) {
  22690. this._map && this._map.clear();
  22691. return this;
  22692. }
  22693. var RecordType = this.constructor;
  22694. return RecordType._empty || (RecordType._empty = makeRecord(this, emptyMap()));
  22695. };
  22696. Record.prototype.set = function(k, v) {
  22697. if (!this.has(k)) {
  22698. throw new Error('Cannot set unknown key "' + k + '" on ' + recordName(this));
  22699. }
  22700. var newMap = this._map && this._map.set(k, v);
  22701. if (this.__ownerID || newMap === this._map) {
  22702. return this;
  22703. }
  22704. return makeRecord(this, newMap);
  22705. };
  22706. Record.prototype.remove = function(k) {
  22707. if (!this.has(k)) {
  22708. return this;
  22709. }
  22710. var newMap = this._map && this._map.remove(k);
  22711. if (this.__ownerID || newMap === this._map) {
  22712. return this;
  22713. }
  22714. return makeRecord(this, newMap);
  22715. };
  22716. Record.prototype.wasAltered = function() {
  22717. return this._map.wasAltered();
  22718. };
  22719. Record.prototype.__iterator = function(type, reverse) {var this$0 = this;
  22720. return KeyedIterable(this._defaultValues).map(function(_, k) {return this$0.get(k)}).__iterator(type, reverse);
  22721. };
  22722. Record.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  22723. return KeyedIterable(this._defaultValues).map(function(_, k) {return this$0.get(k)}).__iterate(fn, reverse);
  22724. };
  22725. Record.prototype.__ensureOwner = function(ownerID) {
  22726. if (ownerID === this.__ownerID) {
  22727. return this;
  22728. }
  22729. var newMap = this._map && this._map.__ensureOwner(ownerID);
  22730. if (!ownerID) {
  22731. this.__ownerID = ownerID;
  22732. this._map = newMap;
  22733. return this;
  22734. }
  22735. return makeRecord(this, newMap, ownerID);
  22736. };
  22737. var RecordPrototype = Record.prototype;
  22738. RecordPrototype[DELETE] = RecordPrototype.remove;
  22739. RecordPrototype.deleteIn =
  22740. RecordPrototype.removeIn = MapPrototype.removeIn;
  22741. RecordPrototype.merge = MapPrototype.merge;
  22742. RecordPrototype.mergeWith = MapPrototype.mergeWith;
  22743. RecordPrototype.mergeIn = MapPrototype.mergeIn;
  22744. RecordPrototype.mergeDeep = MapPrototype.mergeDeep;
  22745. RecordPrototype.mergeDeepWith = MapPrototype.mergeDeepWith;
  22746. RecordPrototype.mergeDeepIn = MapPrototype.mergeDeepIn;
  22747. RecordPrototype.setIn = MapPrototype.setIn;
  22748. RecordPrototype.update = MapPrototype.update;
  22749. RecordPrototype.updateIn = MapPrototype.updateIn;
  22750. RecordPrototype.withMutations = MapPrototype.withMutations;
  22751. RecordPrototype.asMutable = MapPrototype.asMutable;
  22752. RecordPrototype.asImmutable = MapPrototype.asImmutable;
  22753. function makeRecord(likeRecord, map, ownerID) {
  22754. var record = Object.create(Object.getPrototypeOf(likeRecord));
  22755. record._map = map;
  22756. record.__ownerID = ownerID;
  22757. return record;
  22758. }
  22759. function recordName(record) {
  22760. return record._name || record.constructor.name || 'Record';
  22761. }
  22762. function setProps(prototype, names) {
  22763. try {
  22764. names.forEach(setProp.bind(undefined, prototype));
  22765. } catch (error) {
  22766. // Object.defineProperty failed. Probably IE8.
  22767. }
  22768. }
  22769. function setProp(prototype, name) {
  22770. Object.defineProperty(prototype, name, {
  22771. get: function() {
  22772. return this.get(name);
  22773. },
  22774. set: function(value) {
  22775. invariant(this.__ownerID, 'Cannot set on an immutable record.');
  22776. this.set(name, value);
  22777. }
  22778. });
  22779. }
  22780. createClass(Set, SetCollection);
  22781. // @pragma Construction
  22782. function Set(value) {
  22783. return value === null || value === undefined ? emptySet() :
  22784. isSet(value) && !isOrdered(value) ? value :
  22785. emptySet().withMutations(function(set ) {
  22786. var iter = SetIterable(value);
  22787. assertNotInfinite(iter.size);
  22788. iter.forEach(function(v ) {return set.add(v)});
  22789. });
  22790. }
  22791. Set.of = function(/*...values*/) {
  22792. return this(arguments);
  22793. };
  22794. Set.fromKeys = function(value) {
  22795. return this(KeyedIterable(value).keySeq());
  22796. };
  22797. Set.prototype.toString = function() {
  22798. return this.__toString('Set {', '}');
  22799. };
  22800. // @pragma Access
  22801. Set.prototype.has = function(value) {
  22802. return this._map.has(value);
  22803. };
  22804. // @pragma Modification
  22805. Set.prototype.add = function(value) {
  22806. return updateSet(this, this._map.set(value, true));
  22807. };
  22808. Set.prototype.remove = function(value) {
  22809. return updateSet(this, this._map.remove(value));
  22810. };
  22811. Set.prototype.clear = function() {
  22812. return updateSet(this, this._map.clear());
  22813. };
  22814. // @pragma Composition
  22815. Set.prototype.union = function() {var iters = SLICE$0.call(arguments, 0);
  22816. iters = iters.filter(function(x ) {return x.size !== 0});
  22817. if (iters.length === 0) {
  22818. return this;
  22819. }
  22820. if (this.size === 0 && !this.__ownerID && iters.length === 1) {
  22821. return this.constructor(iters[0]);
  22822. }
  22823. return this.withMutations(function(set ) {
  22824. for (var ii = 0; ii < iters.length; ii++) {
  22825. SetIterable(iters[ii]).forEach(function(value ) {return set.add(value)});
  22826. }
  22827. });
  22828. };
  22829. Set.prototype.intersect = function() {var iters = SLICE$0.call(arguments, 0);
  22830. if (iters.length === 0) {
  22831. return this;
  22832. }
  22833. iters = iters.map(function(iter ) {return SetIterable(iter)});
  22834. var originalSet = this;
  22835. return this.withMutations(function(set ) {
  22836. originalSet.forEach(function(value ) {
  22837. if (!iters.every(function(iter ) {return iter.includes(value)})) {
  22838. set.remove(value);
  22839. }
  22840. });
  22841. });
  22842. };
  22843. Set.prototype.subtract = function() {var iters = SLICE$0.call(arguments, 0);
  22844. if (iters.length === 0) {
  22845. return this;
  22846. }
  22847. iters = iters.map(function(iter ) {return SetIterable(iter)});
  22848. var originalSet = this;
  22849. return this.withMutations(function(set ) {
  22850. originalSet.forEach(function(value ) {
  22851. if (iters.some(function(iter ) {return iter.includes(value)})) {
  22852. set.remove(value);
  22853. }
  22854. });
  22855. });
  22856. };
  22857. Set.prototype.merge = function() {
  22858. return this.union.apply(this, arguments);
  22859. };
  22860. Set.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  22861. return this.union.apply(this, iters);
  22862. };
  22863. Set.prototype.sort = function(comparator) {
  22864. // Late binding
  22865. return OrderedSet(sortFactory(this, comparator));
  22866. };
  22867. Set.prototype.sortBy = function(mapper, comparator) {
  22868. // Late binding
  22869. return OrderedSet(sortFactory(this, comparator, mapper));
  22870. };
  22871. Set.prototype.wasAltered = function() {
  22872. return this._map.wasAltered();
  22873. };
  22874. Set.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  22875. return this._map.__iterate(function(_, k) {return fn(k, k, this$0)}, reverse);
  22876. };
  22877. Set.prototype.__iterator = function(type, reverse) {
  22878. return this._map.map(function(_, k) {return k}).__iterator(type, reverse);
  22879. };
  22880. Set.prototype.__ensureOwner = function(ownerID) {
  22881. if (ownerID === this.__ownerID) {
  22882. return this;
  22883. }
  22884. var newMap = this._map.__ensureOwner(ownerID);
  22885. if (!ownerID) {
  22886. this.__ownerID = ownerID;
  22887. this._map = newMap;
  22888. return this;
  22889. }
  22890. return this.__make(newMap, ownerID);
  22891. };
  22892. function isSet(maybeSet) {
  22893. return !!(maybeSet && maybeSet[IS_SET_SENTINEL]);
  22894. }
  22895. Set.isSet = isSet;
  22896. var IS_SET_SENTINEL = '@@__IMMUTABLE_SET__@@';
  22897. var SetPrototype = Set.prototype;
  22898. SetPrototype[IS_SET_SENTINEL] = true;
  22899. SetPrototype[DELETE] = SetPrototype.remove;
  22900. SetPrototype.mergeDeep = SetPrototype.merge;
  22901. SetPrototype.mergeDeepWith = SetPrototype.mergeWith;
  22902. SetPrototype.withMutations = MapPrototype.withMutations;
  22903. SetPrototype.asMutable = MapPrototype.asMutable;
  22904. SetPrototype.asImmutable = MapPrototype.asImmutable;
  22905. SetPrototype.__empty = emptySet;
  22906. SetPrototype.__make = makeSet;
  22907. function updateSet(set, newMap) {
  22908. if (set.__ownerID) {
  22909. set.size = newMap.size;
  22910. set._map = newMap;
  22911. return set;
  22912. }
  22913. return newMap === set._map ? set :
  22914. newMap.size === 0 ? set.__empty() :
  22915. set.__make(newMap);
  22916. }
  22917. function makeSet(map, ownerID) {
  22918. var set = Object.create(SetPrototype);
  22919. set.size = map ? map.size : 0;
  22920. set._map = map;
  22921. set.__ownerID = ownerID;
  22922. return set;
  22923. }
  22924. var EMPTY_SET;
  22925. function emptySet() {
  22926. return EMPTY_SET || (EMPTY_SET = makeSet(emptyMap()));
  22927. }
  22928. createClass(OrderedSet, Set);
  22929. // @pragma Construction
  22930. function OrderedSet(value) {
  22931. return value === null || value === undefined ? emptyOrderedSet() :
  22932. isOrderedSet(value) ? value :
  22933. emptyOrderedSet().withMutations(function(set ) {
  22934. var iter = SetIterable(value);
  22935. assertNotInfinite(iter.size);
  22936. iter.forEach(function(v ) {return set.add(v)});
  22937. });
  22938. }
  22939. OrderedSet.of = function(/*...values*/) {
  22940. return this(arguments);
  22941. };
  22942. OrderedSet.fromKeys = function(value) {
  22943. return this(KeyedIterable(value).keySeq());
  22944. };
  22945. OrderedSet.prototype.toString = function() {
  22946. return this.__toString('OrderedSet {', '}');
  22947. };
  22948. function isOrderedSet(maybeOrderedSet) {
  22949. return isSet(maybeOrderedSet) && isOrdered(maybeOrderedSet);
  22950. }
  22951. OrderedSet.isOrderedSet = isOrderedSet;
  22952. var OrderedSetPrototype = OrderedSet.prototype;
  22953. OrderedSetPrototype[IS_ORDERED_SENTINEL] = true;
  22954. OrderedSetPrototype.__empty = emptyOrderedSet;
  22955. OrderedSetPrototype.__make = makeOrderedSet;
  22956. function makeOrderedSet(map, ownerID) {
  22957. var set = Object.create(OrderedSetPrototype);
  22958. set.size = map ? map.size : 0;
  22959. set._map = map;
  22960. set.__ownerID = ownerID;
  22961. return set;
  22962. }
  22963. var EMPTY_ORDERED_SET;
  22964. function emptyOrderedSet() {
  22965. return EMPTY_ORDERED_SET || (EMPTY_ORDERED_SET = makeOrderedSet(emptyOrderedMap()));
  22966. }
  22967. createClass(Stack, IndexedCollection);
  22968. // @pragma Construction
  22969. function Stack(value) {
  22970. return value === null || value === undefined ? emptyStack() :
  22971. isStack(value) ? value :
  22972. emptyStack().unshiftAll(value);
  22973. }
  22974. Stack.of = function(/*...values*/) {
  22975. return this(arguments);
  22976. };
  22977. Stack.prototype.toString = function() {
  22978. return this.__toString('Stack [', ']');
  22979. };
  22980. // @pragma Access
  22981. Stack.prototype.get = function(index, notSetValue) {
  22982. var head = this._head;
  22983. index = wrapIndex(this, index);
  22984. while (head && index--) {
  22985. head = head.next;
  22986. }
  22987. return head ? head.value : notSetValue;
  22988. };
  22989. Stack.prototype.peek = function() {
  22990. return this._head && this._head.value;
  22991. };
  22992. // @pragma Modification
  22993. Stack.prototype.push = function(/*...values*/) {
  22994. if (arguments.length === 0) {
  22995. return this;
  22996. }
  22997. var newSize = this.size + arguments.length;
  22998. var head = this._head;
  22999. for (var ii = arguments.length - 1; ii >= 0; ii--) {
  23000. head = {
  23001. value: arguments[ii],
  23002. next: head
  23003. };
  23004. }
  23005. if (this.__ownerID) {
  23006. this.size = newSize;
  23007. this._head = head;
  23008. this.__hash = undefined;
  23009. this.__altered = true;
  23010. return this;
  23011. }
  23012. return makeStack(newSize, head);
  23013. };
  23014. Stack.prototype.pushAll = function(iter) {
  23015. iter = IndexedIterable(iter);
  23016. if (iter.size === 0) {
  23017. return this;
  23018. }
  23019. assertNotInfinite(iter.size);
  23020. var newSize = this.size;
  23021. var head = this._head;
  23022. iter.reverse().forEach(function(value ) {
  23023. newSize++;
  23024. head = {
  23025. value: value,
  23026. next: head
  23027. };
  23028. });
  23029. if (this.__ownerID) {
  23030. this.size = newSize;
  23031. this._head = head;
  23032. this.__hash = undefined;
  23033. this.__altered = true;
  23034. return this;
  23035. }
  23036. return makeStack(newSize, head);
  23037. };
  23038. Stack.prototype.pop = function() {
  23039. return this.slice(1);
  23040. };
  23041. Stack.prototype.unshift = function(/*...values*/) {
  23042. return this.push.apply(this, arguments);
  23043. };
  23044. Stack.prototype.unshiftAll = function(iter) {
  23045. return this.pushAll(iter);
  23046. };
  23047. Stack.prototype.shift = function() {
  23048. return this.pop.apply(this, arguments);
  23049. };
  23050. Stack.prototype.clear = function() {
  23051. if (this.size === 0) {
  23052. return this;
  23053. }
  23054. if (this.__ownerID) {
  23055. this.size = 0;
  23056. this._head = undefined;
  23057. this.__hash = undefined;
  23058. this.__altered = true;
  23059. return this;
  23060. }
  23061. return emptyStack();
  23062. };
  23063. Stack.prototype.slice = function(begin, end) {
  23064. if (wholeSlice(begin, end, this.size)) {
  23065. return this;
  23066. }
  23067. var resolvedBegin = resolveBegin(begin, this.size);
  23068. var resolvedEnd = resolveEnd(end, this.size);
  23069. if (resolvedEnd !== this.size) {
  23070. // super.slice(begin, end);
  23071. return IndexedCollection.prototype.slice.call(this, begin, end);
  23072. }
  23073. var newSize = this.size - resolvedBegin;
  23074. var head = this._head;
  23075. while (resolvedBegin--) {
  23076. head = head.next;
  23077. }
  23078. if (this.__ownerID) {
  23079. this.size = newSize;
  23080. this._head = head;
  23081. this.__hash = undefined;
  23082. this.__altered = true;
  23083. return this;
  23084. }
  23085. return makeStack(newSize, head);
  23086. };
  23087. // @pragma Mutability
  23088. Stack.prototype.__ensureOwner = function(ownerID) {
  23089. if (ownerID === this.__ownerID) {
  23090. return this;
  23091. }
  23092. if (!ownerID) {
  23093. this.__ownerID = ownerID;
  23094. this.__altered = false;
  23095. return this;
  23096. }
  23097. return makeStack(this.size, this._head, ownerID, this.__hash);
  23098. };
  23099. // @pragma Iteration
  23100. Stack.prototype.__iterate = function(fn, reverse) {
  23101. if (reverse) {
  23102. return this.reverse().__iterate(fn);
  23103. }
  23104. var iterations = 0;
  23105. var node = this._head;
  23106. while (node) {
  23107. if (fn(node.value, iterations++, this) === false) {
  23108. break;
  23109. }
  23110. node = node.next;
  23111. }
  23112. return iterations;
  23113. };
  23114. Stack.prototype.__iterator = function(type, reverse) {
  23115. if (reverse) {
  23116. return this.reverse().__iterator(type);
  23117. }
  23118. var iterations = 0;
  23119. var node = this._head;
  23120. return new Iterator(function() {
  23121. if (node) {
  23122. var value = node.value;
  23123. node = node.next;
  23124. return iteratorValue(type, iterations++, value);
  23125. }
  23126. return iteratorDone();
  23127. });
  23128. };
  23129. function isStack(maybeStack) {
  23130. return !!(maybeStack && maybeStack[IS_STACK_SENTINEL]);
  23131. }
  23132. Stack.isStack = isStack;
  23133. var IS_STACK_SENTINEL = '@@__IMMUTABLE_STACK__@@';
  23134. var StackPrototype = Stack.prototype;
  23135. StackPrototype[IS_STACK_SENTINEL] = true;
  23136. StackPrototype.withMutations = MapPrototype.withMutations;
  23137. StackPrototype.asMutable = MapPrototype.asMutable;
  23138. StackPrototype.asImmutable = MapPrototype.asImmutable;
  23139. StackPrototype.wasAltered = MapPrototype.wasAltered;
  23140. function makeStack(size, head, ownerID, hash) {
  23141. var map = Object.create(StackPrototype);
  23142. map.size = size;
  23143. map._head = head;
  23144. map.__ownerID = ownerID;
  23145. map.__hash = hash;
  23146. map.__altered = false;
  23147. return map;
  23148. }
  23149. var EMPTY_STACK;
  23150. function emptyStack() {
  23151. return EMPTY_STACK || (EMPTY_STACK = makeStack(0));
  23152. }
  23153. /**
  23154. * Contributes additional methods to a constructor
  23155. */
  23156. function mixin(ctor, methods) {
  23157. var keyCopier = function(key ) { ctor.prototype[key] = methods[key]; };
  23158. Object.keys(methods).forEach(keyCopier);
  23159. Object.getOwnPropertySymbols &&
  23160. Object.getOwnPropertySymbols(methods).forEach(keyCopier);
  23161. return ctor;
  23162. }
  23163. Iterable.Iterator = Iterator;
  23164. mixin(Iterable, {
  23165. // ### Conversion to other types
  23166. toArray: function() {
  23167. assertNotInfinite(this.size);
  23168. var array = new Array(this.size || 0);
  23169. this.valueSeq().__iterate(function(v, i) { array[i] = v; });
  23170. return array;
  23171. },
  23172. toIndexedSeq: function() {
  23173. return new ToIndexedSequence(this);
  23174. },
  23175. toJS: function() {
  23176. return this.toSeq().map(
  23177. function(value ) {return value && typeof value.toJS === 'function' ? value.toJS() : value}
  23178. ).__toJS();
  23179. },
  23180. toJSON: function() {
  23181. return this.toSeq().map(
  23182. function(value ) {return value && typeof value.toJSON === 'function' ? value.toJSON() : value}
  23183. ).__toJS();
  23184. },
  23185. toKeyedSeq: function() {
  23186. return new ToKeyedSequence(this, true);
  23187. },
  23188. toMap: function() {
  23189. // Use Late Binding here to solve the circular dependency.
  23190. return Map(this.toKeyedSeq());
  23191. },
  23192. toObject: function() {
  23193. assertNotInfinite(this.size);
  23194. var object = {};
  23195. this.__iterate(function(v, k) { object[k] = v; });
  23196. return object;
  23197. },
  23198. toOrderedMap: function() {
  23199. // Use Late Binding here to solve the circular dependency.
  23200. return OrderedMap(this.toKeyedSeq());
  23201. },
  23202. toOrderedSet: function() {
  23203. // Use Late Binding here to solve the circular dependency.
  23204. return OrderedSet(isKeyed(this) ? this.valueSeq() : this);
  23205. },
  23206. toSet: function() {
  23207. // Use Late Binding here to solve the circular dependency.
  23208. return Set(isKeyed(this) ? this.valueSeq() : this);
  23209. },
  23210. toSetSeq: function() {
  23211. return new ToSetSequence(this);
  23212. },
  23213. toSeq: function() {
  23214. return isIndexed(this) ? this.toIndexedSeq() :
  23215. isKeyed(this) ? this.toKeyedSeq() :
  23216. this.toSetSeq();
  23217. },
  23218. toStack: function() {
  23219. // Use Late Binding here to solve the circular dependency.
  23220. return Stack(isKeyed(this) ? this.valueSeq() : this);
  23221. },
  23222. toList: function() {
  23223. // Use Late Binding here to solve the circular dependency.
  23224. return List(isKeyed(this) ? this.valueSeq() : this);
  23225. },
  23226. // ### Common JavaScript methods and properties
  23227. toString: function() {
  23228. return '[Iterable]';
  23229. },
  23230. __toString: function(head, tail) {
  23231. if (this.size === 0) {
  23232. return head + tail;
  23233. }
  23234. return head + ' ' + this.toSeq().map(this.__toStringMapper).join(', ') + ' ' + tail;
  23235. },
  23236. // ### ES6 Collection methods (ES6 Array and Map)
  23237. concat: function() {var values = SLICE$0.call(arguments, 0);
  23238. return reify(this, concatFactory(this, values));
  23239. },
  23240. includes: function(searchValue) {
  23241. return this.some(function(value ) {return is(value, searchValue)});
  23242. },
  23243. entries: function() {
  23244. return this.__iterator(ITERATE_ENTRIES);
  23245. },
  23246. every: function(predicate, context) {
  23247. assertNotInfinite(this.size);
  23248. var returnValue = true;
  23249. this.__iterate(function(v, k, c) {
  23250. if (!predicate.call(context, v, k, c)) {
  23251. returnValue = false;
  23252. return false;
  23253. }
  23254. });
  23255. return returnValue;
  23256. },
  23257. filter: function(predicate, context) {
  23258. return reify(this, filterFactory(this, predicate, context, true));
  23259. },
  23260. find: function(predicate, context, notSetValue) {
  23261. var entry = this.findEntry(predicate, context);
  23262. return entry ? entry[1] : notSetValue;
  23263. },
  23264. findEntry: function(predicate, context) {
  23265. var found;
  23266. this.__iterate(function(v, k, c) {
  23267. if (predicate.call(context, v, k, c)) {
  23268. found = [k, v];
  23269. return false;
  23270. }
  23271. });
  23272. return found;
  23273. },
  23274. findLastEntry: function(predicate, context) {
  23275. return this.toSeq().reverse().findEntry(predicate, context);
  23276. },
  23277. forEach: function(sideEffect, context) {
  23278. assertNotInfinite(this.size);
  23279. return this.__iterate(context ? sideEffect.bind(context) : sideEffect);
  23280. },
  23281. join: function(separator) {
  23282. assertNotInfinite(this.size);
  23283. separator = separator !== undefined ? '' + separator : ',';
  23284. var joined = '';
  23285. var isFirst = true;
  23286. this.__iterate(function(v ) {
  23287. isFirst ? (isFirst = false) : (joined += separator);
  23288. joined += v !== null && v !== undefined ? v.toString() : '';
  23289. });
  23290. return joined;
  23291. },
  23292. keys: function() {
  23293. return this.__iterator(ITERATE_KEYS);
  23294. },
  23295. map: function(mapper, context) {
  23296. return reify(this, mapFactory(this, mapper, context));
  23297. },
  23298. reduce: function(reducer, initialReduction, context) {
  23299. assertNotInfinite(this.size);
  23300. var reduction;
  23301. var useFirst;
  23302. if (arguments.length < 2) {
  23303. useFirst = true;
  23304. } else {
  23305. reduction = initialReduction;
  23306. }
  23307. this.__iterate(function(v, k, c) {
  23308. if (useFirst) {
  23309. useFirst = false;
  23310. reduction = v;
  23311. } else {
  23312. reduction = reducer.call(context, reduction, v, k, c);
  23313. }
  23314. });
  23315. return reduction;
  23316. },
  23317. reduceRight: function(reducer, initialReduction, context) {
  23318. var reversed = this.toKeyedSeq().reverse();
  23319. return reversed.reduce.apply(reversed, arguments);
  23320. },
  23321. reverse: function() {
  23322. return reify(this, reverseFactory(this, true));
  23323. },
  23324. slice: function(begin, end) {
  23325. return reify(this, sliceFactory(this, begin, end, true));
  23326. },
  23327. some: function(predicate, context) {
  23328. return !this.every(not(predicate), context);
  23329. },
  23330. sort: function(comparator) {
  23331. return reify(this, sortFactory(this, comparator));
  23332. },
  23333. values: function() {
  23334. return this.__iterator(ITERATE_VALUES);
  23335. },
  23336. // ### More sequential methods
  23337. butLast: function() {
  23338. return this.slice(0, -1);
  23339. },
  23340. isEmpty: function() {
  23341. return this.size !== undefined ? this.size === 0 : !this.some(function() {return true});
  23342. },
  23343. count: function(predicate, context) {
  23344. return ensureSize(
  23345. predicate ? this.toSeq().filter(predicate, context) : this
  23346. );
  23347. },
  23348. countBy: function(grouper, context) {
  23349. return countByFactory(this, grouper, context);
  23350. },
  23351. equals: function(other) {
  23352. return deepEqual(this, other);
  23353. },
  23354. entrySeq: function() {
  23355. var iterable = this;
  23356. if (iterable._cache) {
  23357. // We cache as an entries array, so we can just return the cache!
  23358. return new ArraySeq(iterable._cache);
  23359. }
  23360. var entriesSequence = iterable.toSeq().map(entryMapper).toIndexedSeq();
  23361. entriesSequence.fromEntrySeq = function() {return iterable.toSeq()};
  23362. return entriesSequence;
  23363. },
  23364. filterNot: function(predicate, context) {
  23365. return this.filter(not(predicate), context);
  23366. },
  23367. findLast: function(predicate, context, notSetValue) {
  23368. return this.toKeyedSeq().reverse().find(predicate, context, notSetValue);
  23369. },
  23370. first: function() {
  23371. return this.find(returnTrue);
  23372. },
  23373. flatMap: function(mapper, context) {
  23374. return reify(this, flatMapFactory(this, mapper, context));
  23375. },
  23376. flatten: function(depth) {
  23377. return reify(this, flattenFactory(this, depth, true));
  23378. },
  23379. fromEntrySeq: function() {
  23380. return new FromEntriesSequence(this);
  23381. },
  23382. get: function(searchKey, notSetValue) {
  23383. return this.find(function(_, key) {return is(key, searchKey)}, undefined, notSetValue);
  23384. },
  23385. getIn: function(searchKeyPath, notSetValue) {
  23386. var nested = this;
  23387. // Note: in an ES6 environment, we would prefer:
  23388. // for (var key of searchKeyPath) {
  23389. var iter = forceIterator(searchKeyPath);
  23390. var step;
  23391. while (!(step = iter.next()).done) {
  23392. var key = step.value;
  23393. nested = nested && nested.get ? nested.get(key, NOT_SET) : NOT_SET;
  23394. if (nested === NOT_SET) {
  23395. return notSetValue;
  23396. }
  23397. }
  23398. return nested;
  23399. },
  23400. groupBy: function(grouper, context) {
  23401. return groupByFactory(this, grouper, context);
  23402. },
  23403. has: function(searchKey) {
  23404. return this.get(searchKey, NOT_SET) !== NOT_SET;
  23405. },
  23406. hasIn: function(searchKeyPath) {
  23407. return this.getIn(searchKeyPath, NOT_SET) !== NOT_SET;
  23408. },
  23409. isSubset: function(iter) {
  23410. iter = typeof iter.includes === 'function' ? iter : Iterable(iter);
  23411. return this.every(function(value ) {return iter.includes(value)});
  23412. },
  23413. isSuperset: function(iter) {
  23414. iter = typeof iter.isSubset === 'function' ? iter : Iterable(iter);
  23415. return iter.isSubset(this);
  23416. },
  23417. keySeq: function() {
  23418. return this.toSeq().map(keyMapper).toIndexedSeq();
  23419. },
  23420. last: function() {
  23421. return this.toSeq().reverse().first();
  23422. },
  23423. max: function(comparator) {
  23424. return maxFactory(this, comparator);
  23425. },
  23426. maxBy: function(mapper, comparator) {
  23427. return maxFactory(this, comparator, mapper);
  23428. },
  23429. min: function(comparator) {
  23430. return maxFactory(this, comparator ? neg(comparator) : defaultNegComparator);
  23431. },
  23432. minBy: function(mapper, comparator) {
  23433. return maxFactory(this, comparator ? neg(comparator) : defaultNegComparator, mapper);
  23434. },
  23435. rest: function() {
  23436. return this.slice(1);
  23437. },
  23438. skip: function(amount) {
  23439. return this.slice(Math.max(0, amount));
  23440. },
  23441. skipLast: function(amount) {
  23442. return reify(this, this.toSeq().reverse().skip(amount).reverse());
  23443. },
  23444. skipWhile: function(predicate, context) {
  23445. return reify(this, skipWhileFactory(this, predicate, context, true));
  23446. },
  23447. skipUntil: function(predicate, context) {
  23448. return this.skipWhile(not(predicate), context);
  23449. },
  23450. sortBy: function(mapper, comparator) {
  23451. return reify(this, sortFactory(this, comparator, mapper));
  23452. },
  23453. take: function(amount) {
  23454. return this.slice(0, Math.max(0, amount));
  23455. },
  23456. takeLast: function(amount) {
  23457. return reify(this, this.toSeq().reverse().take(amount).reverse());
  23458. },
  23459. takeWhile: function(predicate, context) {
  23460. return reify(this, takeWhileFactory(this, predicate, context));
  23461. },
  23462. takeUntil: function(predicate, context) {
  23463. return this.takeWhile(not(predicate), context);
  23464. },
  23465. valueSeq: function() {
  23466. return this.toIndexedSeq();
  23467. },
  23468. // ### Hashable Object
  23469. hashCode: function() {
  23470. return this.__hash || (this.__hash = hashIterable(this));
  23471. }
  23472. // ### Internal
  23473. // abstract __iterate(fn, reverse)
  23474. // abstract __iterator(type, reverse)
  23475. });
  23476. // var IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
  23477. // var IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
  23478. // var IS_INDEXED_SENTINEL = '@@__IMMUTABLE_INDEXED__@@';
  23479. // var IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
  23480. var IterablePrototype = Iterable.prototype;
  23481. IterablePrototype[IS_ITERABLE_SENTINEL] = true;
  23482. IterablePrototype[ITERATOR_SYMBOL] = IterablePrototype.values;
  23483. IterablePrototype.__toJS = IterablePrototype.toArray;
  23484. IterablePrototype.__toStringMapper = quoteString;
  23485. IterablePrototype.inspect =
  23486. IterablePrototype.toSource = function() { return this.toString(); };
  23487. IterablePrototype.chain = IterablePrototype.flatMap;
  23488. IterablePrototype.contains = IterablePrototype.includes;
  23489. // Temporary warning about using length
  23490. (function () {
  23491. try {
  23492. Object.defineProperty(IterablePrototype, 'length', {
  23493. get: function () {
  23494. if (!Iterable.noLengthWarning) {
  23495. var stack;
  23496. try {
  23497. throw new Error();
  23498. } catch (error) {
  23499. stack = error.stack;
  23500. }
  23501. if (stack.indexOf('_wrapObject') === -1) {
  23502. console && console.warn && console.warn(
  23503. 'iterable.length has been deprecated, '+
  23504. 'use iterable.size or iterable.count(). '+
  23505. 'This warning will become a silent error in a future version. ' +
  23506. stack
  23507. );
  23508. return this.size;
  23509. }
  23510. }
  23511. }
  23512. });
  23513. } catch (e) {}
  23514. })();
  23515. mixin(KeyedIterable, {
  23516. // ### More sequential methods
  23517. flip: function() {
  23518. return reify(this, flipFactory(this));
  23519. },
  23520. findKey: function(predicate, context) {
  23521. var entry = this.findEntry(predicate, context);
  23522. return entry && entry[0];
  23523. },
  23524. findLastKey: function(predicate, context) {
  23525. return this.toSeq().reverse().findKey(predicate, context);
  23526. },
  23527. keyOf: function(searchValue) {
  23528. return this.findKey(function(value ) {return is(value, searchValue)});
  23529. },
  23530. lastKeyOf: function(searchValue) {
  23531. return this.findLastKey(function(value ) {return is(value, searchValue)});
  23532. },
  23533. mapEntries: function(mapper, context) {var this$0 = this;
  23534. var iterations = 0;
  23535. return reify(this,
  23536. this.toSeq().map(
  23537. function(v, k) {return mapper.call(context, [k, v], iterations++, this$0)}
  23538. ).fromEntrySeq()
  23539. );
  23540. },
  23541. mapKeys: function(mapper, context) {var this$0 = this;
  23542. return reify(this,
  23543. this.toSeq().flip().map(
  23544. function(k, v) {return mapper.call(context, k, v, this$0)}
  23545. ).flip()
  23546. );
  23547. }
  23548. });
  23549. var KeyedIterablePrototype = KeyedIterable.prototype;
  23550. KeyedIterablePrototype[IS_KEYED_SENTINEL] = true;
  23551. KeyedIterablePrototype[ITERATOR_SYMBOL] = IterablePrototype.entries;
  23552. KeyedIterablePrototype.__toJS = IterablePrototype.toObject;
  23553. KeyedIterablePrototype.__toStringMapper = function(v, k) {return JSON.stringify(k) + ': ' + quoteString(v)};
  23554. mixin(IndexedIterable, {
  23555. // ### Conversion to other types
  23556. toKeyedSeq: function() {
  23557. return new ToKeyedSequence(this, false);
  23558. },
  23559. // ### ES6 Collection methods (ES6 Array and Map)
  23560. filter: function(predicate, context) {
  23561. return reify(this, filterFactory(this, predicate, context, false));
  23562. },
  23563. findIndex: function(predicate, context) {
  23564. var entry = this.findEntry(predicate, context);
  23565. return entry ? entry[0] : -1;
  23566. },
  23567. indexOf: function(searchValue) {
  23568. var key = this.toKeyedSeq().keyOf(searchValue);
  23569. return key === undefined ? -1 : key;
  23570. },
  23571. lastIndexOf: function(searchValue) {
  23572. var key = this.toKeyedSeq().reverse().keyOf(searchValue);
  23573. return key === undefined ? -1 : key;
  23574. // var index =
  23575. // return this.toSeq().reverse().indexOf(searchValue);
  23576. },
  23577. reverse: function() {
  23578. return reify(this, reverseFactory(this, false));
  23579. },
  23580. slice: function(begin, end) {
  23581. return reify(this, sliceFactory(this, begin, end, false));
  23582. },
  23583. splice: function(index, removeNum /*, ...values*/) {
  23584. var numArgs = arguments.length;
  23585. removeNum = Math.max(removeNum | 0, 0);
  23586. if (numArgs === 0 || (numArgs === 2 && !removeNum)) {
  23587. return this;
  23588. }
  23589. // If index is negative, it should resolve relative to the size of the
  23590. // collection. However size may be expensive to compute if not cached, so
  23591. // only call count() if the number is in fact negative.
  23592. index = resolveBegin(index, index < 0 ? this.count() : this.size);
  23593. var spliced = this.slice(0, index);
  23594. return reify(
  23595. this,
  23596. numArgs === 1 ?
  23597. spliced :
  23598. spliced.concat(arrCopy(arguments, 2), this.slice(index + removeNum))
  23599. );
  23600. },
  23601. // ### More collection methods
  23602. findLastIndex: function(predicate, context) {
  23603. var key = this.toKeyedSeq().findLastKey(predicate, context);
  23604. return key === undefined ? -1 : key;
  23605. },
  23606. first: function() {
  23607. return this.get(0);
  23608. },
  23609. flatten: function(depth) {
  23610. return reify(this, flattenFactory(this, depth, false));
  23611. },
  23612. get: function(index, notSetValue) {
  23613. index = wrapIndex(this, index);
  23614. return (index < 0 || (this.size === Infinity ||
  23615. (this.size !== undefined && index > this.size))) ?
  23616. notSetValue :
  23617. this.find(function(_, key) {return key === index}, undefined, notSetValue);
  23618. },
  23619. has: function(index) {
  23620. index = wrapIndex(this, index);
  23621. return index >= 0 && (this.size !== undefined ?
  23622. this.size === Infinity || index < this.size :
  23623. this.indexOf(index) !== -1
  23624. );
  23625. },
  23626. interpose: function(separator) {
  23627. return reify(this, interposeFactory(this, separator));
  23628. },
  23629. interleave: function(/*...iterables*/) {
  23630. var iterables = [this].concat(arrCopy(arguments));
  23631. var zipped = zipWithFactory(this.toSeq(), IndexedSeq.of, iterables);
  23632. var interleaved = zipped.flatten(true);
  23633. if (zipped.size) {
  23634. interleaved.size = zipped.size * iterables.length;
  23635. }
  23636. return reify(this, interleaved);
  23637. },
  23638. last: function() {
  23639. return this.get(-1);
  23640. },
  23641. skipWhile: function(predicate, context) {
  23642. return reify(this, skipWhileFactory(this, predicate, context, false));
  23643. },
  23644. zip: function(/*, ...iterables */) {
  23645. var iterables = [this].concat(arrCopy(arguments));
  23646. return reify(this, zipWithFactory(this, defaultZipper, iterables));
  23647. },
  23648. zipWith: function(zipper/*, ...iterables */) {
  23649. var iterables = arrCopy(arguments);
  23650. iterables[0] = this;
  23651. return reify(this, zipWithFactory(this, zipper, iterables));
  23652. }
  23653. });
  23654. IndexedIterable.prototype[IS_INDEXED_SENTINEL] = true;
  23655. IndexedIterable.prototype[IS_ORDERED_SENTINEL] = true;
  23656. mixin(SetIterable, {
  23657. // ### ES6 Collection methods (ES6 Array and Map)
  23658. get: function(value, notSetValue) {
  23659. return this.has(value) ? value : notSetValue;
  23660. },
  23661. includes: function(value) {
  23662. return this.has(value);
  23663. },
  23664. // ### More sequential methods
  23665. keySeq: function() {
  23666. return this.valueSeq();
  23667. }
  23668. });
  23669. SetIterable.prototype.has = IterablePrototype.includes;
  23670. // Mixin subclasses
  23671. mixin(KeyedSeq, KeyedIterable.prototype);
  23672. mixin(IndexedSeq, IndexedIterable.prototype);
  23673. mixin(SetSeq, SetIterable.prototype);
  23674. mixin(KeyedCollection, KeyedIterable.prototype);
  23675. mixin(IndexedCollection, IndexedIterable.prototype);
  23676. mixin(SetCollection, SetIterable.prototype);
  23677. // #pragma Helper functions
  23678. function keyMapper(v, k) {
  23679. return k;
  23680. }
  23681. function entryMapper(v, k) {
  23682. return [k, v];
  23683. }
  23684. function not(predicate) {
  23685. return function() {
  23686. return !predicate.apply(this, arguments);
  23687. }
  23688. }
  23689. function neg(predicate) {
  23690. return function() {
  23691. return -predicate.apply(this, arguments);
  23692. }
  23693. }
  23694. function quoteString(value) {
  23695. return typeof value === 'string' ? JSON.stringify(value) : value;
  23696. }
  23697. function defaultZipper() {
  23698. return arrCopy(arguments);
  23699. }
  23700. function defaultNegComparator(a, b) {
  23701. return a < b ? 1 : a > b ? -1 : 0;
  23702. }
  23703. function hashIterable(iterable) {
  23704. if (iterable.size === Infinity) {
  23705. return 0;
  23706. }
  23707. var ordered = isOrdered(iterable);
  23708. var keyed = isKeyed(iterable);
  23709. var h = ordered ? 1 : 0;
  23710. var size = iterable.__iterate(
  23711. keyed ?
  23712. ordered ?
  23713. function(v, k) { h = 31 * h + hashMerge(hash(v), hash(k)) | 0; } :
  23714. function(v, k) { h = h + hashMerge(hash(v), hash(k)) | 0; } :
  23715. ordered ?
  23716. function(v ) { h = 31 * h + hash(v) | 0; } :
  23717. function(v ) { h = h + hash(v) | 0; }
  23718. );
  23719. return murmurHashOfSize(size, h);
  23720. }
  23721. function murmurHashOfSize(size, h) {
  23722. h = imul(h, 0xCC9E2D51);
  23723. h = imul(h << 15 | h >>> -15, 0x1B873593);
  23724. h = imul(h << 13 | h >>> -13, 5);
  23725. h = (h + 0xE6546B64 | 0) ^ size;
  23726. h = imul(h ^ h >>> 16, 0x85EBCA6B);
  23727. h = imul(h ^ h >>> 13, 0xC2B2AE35);
  23728. h = smi(h ^ h >>> 16);
  23729. return h;
  23730. }
  23731. function hashMerge(a, b) {
  23732. return a ^ b + 0x9E3779B9 + (a << 6) + (a >> 2) | 0; // int
  23733. }
  23734. var Immutable = {
  23735. Iterable: Iterable,
  23736. Seq: Seq,
  23737. Collection: Collection,
  23738. Map: Map,
  23739. OrderedMap: OrderedMap,
  23740. List: List,
  23741. Stack: Stack,
  23742. Set: Set,
  23743. OrderedSet: OrderedSet,
  23744. Record: Record,
  23745. Range: Range,
  23746. Repeat: Repeat,
  23747. is: is,
  23748. fromJS: fromJS
  23749. };
  23750. return Immutable;
  23751. }));
  23752. });
  23753. var parseHTML_1 = createCommonjsModule(function (module, exports) {
  23754. Object.defineProperty(exports, "__esModule", {
  23755. value: true
  23756. });
  23757. exports["default"] = parseHTML;
  23758. var fallback = function fallback(html) {
  23759. var doc = document.implementation.createHTMLDocument('');
  23760. doc.documentElement.innerHTML = html;
  23761. return doc;
  23762. };
  23763. function parseHTML(html) {
  23764. var doc;
  23765. if (typeof DOMParser !== 'undefined') {
  23766. var parser = new DOMParser();
  23767. doc = parser.parseFromString(html, 'text/html');
  23768. if (doc === null || doc.body === null) {
  23769. doc = fallback(html);
  23770. }
  23771. } else {
  23772. doc = fallback(html);
  23773. }
  23774. return doc.body;
  23775. }
  23776. });
  23777. unwrapExports(parseHTML_1);
  23778. var convertFromHTML_1 = createCommonjsModule(function (module, exports) {
  23779. Object.defineProperty(exports, "__esModule", {
  23780. value: true
  23781. });
  23782. exports["default"] = void 0;
  23783. var _parseHTML = interopRequireDefault(parseHTML_1);
  23784. var _rangeSort = interopRequireDefault(rangeSort);
  23785. /**
  23786. * Copyright (c) 2013-present, Facebook, Inc.
  23787. * All rights reserved.
  23788. *
  23789. * Copyright (c) 2013-present, Facebook, Inc.
  23790. * All rights reserved.
  23791. *
  23792. * This source code is licensed under the BSD-style license found in the
  23793. * LICENSE file in the /src directory of this source tree. An additional grant
  23794. * of patent rights can be found in the PATENTS file in the same directory.
  23795. */
  23796. var NBSP = '&nbsp;';
  23797. var SPACE = ' '; // Arbitrary max indent
  23798. var MAX_DEPTH = 4; // used for replacing characters in HTML
  23799. /* eslint-disable no-control-regex */
  23800. var REGEX_CR = new RegExp('\r', 'g');
  23801. var REGEX_LF = new RegExp('\n', 'g');
  23802. var REGEX_NBSP = new RegExp(NBSP, 'g');
  23803. var REGEX_BLOCK_DELIMITER = new RegExp('\r', 'g');
  23804. /* eslint-enable no-control-regex */
  23805. // Block tag flow is different because LIs do not have
  23806. // a deterministic style ;_;
  23807. var blockTags = ['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'li', 'blockquote', 'pre'];
  23808. var inlineTags = {
  23809. b: 'BOLD',
  23810. code: 'CODE',
  23811. del: 'STRIKETHROUGH',
  23812. em: 'ITALIC',
  23813. i: 'ITALIC',
  23814. s: 'STRIKETHROUGH',
  23815. strike: 'STRIKETHROUGH',
  23816. strong: 'BOLD',
  23817. u: 'UNDERLINE'
  23818. };
  23819. var handleMiddleware = function handleMiddleware(maybeMiddleware, base) {
  23820. if (maybeMiddleware && maybeMiddleware.__isMiddleware === true) {
  23821. return maybeMiddleware(base);
  23822. }
  23823. return maybeMiddleware;
  23824. };
  23825. var defaultHTMLToBlock = function defaultHTMLToBlock(nodeName, node, lastList) {
  23826. return undefined;
  23827. };
  23828. var defaultHTMLToStyle = function defaultHTMLToStyle(nodeName, node, currentStyle) {
  23829. return currentStyle;
  23830. };
  23831. var defaultHTMLToEntity = function defaultHTMLToEntity(nodeName, node) {
  23832. return undefined;
  23833. };
  23834. var defaultTextToEntity = function defaultTextToEntity(text) {
  23835. return [];
  23836. };
  23837. var nullthrows = function nullthrows(x) {
  23838. if (x != null) {
  23839. return x;
  23840. }
  23841. throw new Error('Got unexpected null or undefined');
  23842. };
  23843. var sanitizeDraftText = function sanitizeDraftText(input) {
  23844. return input.replace(REGEX_BLOCK_DELIMITER, '');
  23845. };
  23846. function getEmptyChunk() {
  23847. return {
  23848. text: '',
  23849. inlines: [],
  23850. entities: [],
  23851. blocks: []
  23852. };
  23853. }
  23854. function getWhitespaceChunk(inEntity) {
  23855. var entities = new Array(1);
  23856. if (inEntity) {
  23857. entities[0] = inEntity;
  23858. }
  23859. return {
  23860. text: SPACE,
  23861. inlines: [(0, immutable$2.OrderedSet)()],
  23862. entities: entities,
  23863. blocks: []
  23864. };
  23865. }
  23866. function getSoftNewlineChunk(block, depth) {
  23867. var flat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  23868. var data = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : (0, immutable$2.Map)();
  23869. if (flat === true) {
  23870. return {
  23871. text: '\r',
  23872. inlines: [(0, immutable$2.OrderedSet)()],
  23873. entities: new Array(1),
  23874. blocks: [{
  23875. type: block,
  23876. data: data,
  23877. depth: Math.max(0, Math.min(MAX_DEPTH, depth))
  23878. }],
  23879. isNewline: true
  23880. };
  23881. }
  23882. return {
  23883. text: '\n',
  23884. inlines: [(0, immutable$2.OrderedSet)()],
  23885. entities: new Array(1),
  23886. blocks: []
  23887. };
  23888. }
  23889. function getBlockDividerChunk(block, depth) {
  23890. var data = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : (0, immutable$2.Map)();
  23891. return {
  23892. text: '\r',
  23893. inlines: [(0, immutable$2.OrderedSet)()],
  23894. entities: new Array(1),
  23895. blocks: [{
  23896. type: block,
  23897. data: data,
  23898. depth: Math.max(0, Math.min(MAX_DEPTH, depth))
  23899. }]
  23900. };
  23901. }
  23902. function getBlockTypeForTag(tag, lastList) {
  23903. switch (tag) {
  23904. case 'h1':
  23905. return 'header-one';
  23906. case 'h2':
  23907. return 'header-two';
  23908. case 'h3':
  23909. return 'header-three';
  23910. case 'h4':
  23911. return 'header-four';
  23912. case 'h5':
  23913. return 'header-five';
  23914. case 'h6':
  23915. return 'header-six';
  23916. case 'li':
  23917. if (lastList === 'ol') {
  23918. return 'ordered-list-item';
  23919. }
  23920. return 'unordered-list-item';
  23921. case 'blockquote':
  23922. return 'blockquote';
  23923. case 'pre':
  23924. return 'code-block';
  23925. case 'div':
  23926. case 'p':
  23927. return 'unstyled';
  23928. default:
  23929. return null;
  23930. }
  23931. }
  23932. function baseCheckBlockType(nodeName, node, lastList) {
  23933. return getBlockTypeForTag(nodeName, lastList);
  23934. }
  23935. function processInlineTag(tag, node, currentStyle) {
  23936. var styleToCheck = inlineTags[tag];
  23937. if (styleToCheck) {
  23938. currentStyle = currentStyle.add(styleToCheck).toOrderedSet();
  23939. } else if (node instanceof HTMLElement) {
  23940. var htmlElement = node;
  23941. currentStyle = currentStyle.withMutations(function (style) {
  23942. if (htmlElement.style.fontWeight === 'bold') {
  23943. style.add('BOLD');
  23944. }
  23945. if (htmlElement.style.fontStyle === 'italic') {
  23946. style.add('ITALIC');
  23947. }
  23948. if (htmlElement.style.textDecoration === 'underline') {
  23949. style.add('UNDERLINE');
  23950. }
  23951. if (htmlElement.style.textDecoration === 'line-through') {
  23952. style.add('STRIKETHROUGH');
  23953. }
  23954. }).toOrderedSet();
  23955. }
  23956. return currentStyle;
  23957. }
  23958. function baseProcessInlineTag(tag, node) {
  23959. var inlineStyles = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : (0, immutable$2.OrderedSet)();
  23960. return processInlineTag(tag, node, inlineStyles);
  23961. }
  23962. function joinChunks(A, B) {
  23963. var flat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  23964. // Sometimes two blocks will touch in the DOM and we need to strip the
  23965. // extra delimiter to preserve niceness.
  23966. var firstInB = B.text.slice(0, 1);
  23967. var lastInA = A.text.slice(-1);
  23968. var adjacentDividers = lastInA === '\r' && firstInB === '\r';
  23969. var isJoiningBlocks = A.text !== '\r' && B.text !== '\r'; // when joining two full blocks like this we want to pop one divider
  23970. var addingNewlineToEmptyBlock = A.text === '\r' && !A.isNewline && B.isNewline; // when joining a newline to an empty block we want to remove the newline
  23971. if (adjacentDividers && (isJoiningBlocks || addingNewlineToEmptyBlock)) {
  23972. A.text = A.text.slice(0, -1);
  23973. A.inlines.pop();
  23974. A.entities.pop();
  23975. A.blocks.pop();
  23976. } // Kill whitespace after blocks if flat mode is on
  23977. if (A.text.slice(-1) === '\r' && flat === true) {
  23978. if (B.text === SPACE || B.text === '\n') {
  23979. return A;
  23980. } else if (firstInB === SPACE || firstInB === '\n') {
  23981. B.text = B.text.slice(1);
  23982. B.inlines.shift();
  23983. B.entities.shift();
  23984. }
  23985. }
  23986. var isNewline = A.text.length === 0 && B.isNewline;
  23987. return {
  23988. text: A.text + B.text,
  23989. inlines: A.inlines.concat(B.inlines),
  23990. entities: A.entities.concat(B.entities),
  23991. blocks: A.blocks.concat(B.blocks),
  23992. isNewline: isNewline
  23993. };
  23994. }
  23995. /*
  23996. * Check to see if we have anything like <p> <blockquote> <h1>... to create
  23997. * block tags from. If we do, we can use those and ignore <div> tags. If we
  23998. * don't, we can treat <div> tags as meaningful (unstyled) blocks.
  23999. */
  24000. function containsSemanticBlockMarkup(html) {
  24001. return blockTags.some(function (tag) {
  24002. return html.indexOf("<".concat(tag)) !== -1;
  24003. });
  24004. }
  24005. function genFragment(node, inlineStyle, lastList, inBlock, fragmentBlockTags, depth, processCustomInlineStyles, checkEntityNode, checkEntityText, checkBlockType, createEntity, getEntity, mergeEntityData, replaceEntityData, options, inEntity) {
  24006. var nodeName = node.nodeName.toLowerCase();
  24007. var newBlock = false;
  24008. var nextBlockType = 'unstyled'; // Base Case
  24009. if (nodeName === '#text') {
  24010. var text = node.textContent;
  24011. if (text.trim() === '' && inBlock === null) {
  24012. return getEmptyChunk();
  24013. }
  24014. if (text.trim() === '' && inBlock !== 'code-block') {
  24015. return getWhitespaceChunk(inEntity);
  24016. }
  24017. if (inBlock !== 'code-block') {
  24018. // Can't use empty string because MSWord
  24019. text = text.replace(REGEX_LF, SPACE);
  24020. }
  24021. var entities = Array(text.length).fill(inEntity);
  24022. var offsetChange = 0;
  24023. var textEntities = checkEntityText(text, createEntity, getEntity, mergeEntityData, replaceEntityData).sort(_rangeSort["default"]);
  24024. textEntities.forEach(function (_ref) {
  24025. var entity = _ref.entity,
  24026. offset = _ref.offset,
  24027. length = _ref.length,
  24028. result = _ref.result;
  24029. var adjustedOffset = offset + offsetChange;
  24030. if (result === null || result === undefined) {
  24031. result = text.substr(adjustedOffset, length);
  24032. }
  24033. var textArray = text.split('');
  24034. textArray.splice.bind(textArray, adjustedOffset, length).apply(textArray, result.split(''));
  24035. text = textArray.join('');
  24036. entities.splice.bind(entities, adjustedOffset, length).apply(entities, Array(result.length).fill(entity));
  24037. offsetChange += result.length - length;
  24038. });
  24039. return {
  24040. text: text,
  24041. inlines: Array(text.length).fill(inlineStyle),
  24042. entities: entities,
  24043. blocks: []
  24044. };
  24045. } // BR tags
  24046. if (nodeName === 'br') {
  24047. var _blockType = inBlock;
  24048. if (_blockType === null) {
  24049. // BR tag is at top level, treat it as an unstyled block
  24050. return getSoftNewlineChunk('unstyled', depth, true);
  24051. }
  24052. return getSoftNewlineChunk(_blockType || 'unstyled', depth, options.flat);
  24053. }
  24054. var chunk = getEmptyChunk();
  24055. var newChunk = null; // Inline tags
  24056. inlineStyle = processInlineTag(nodeName, node, inlineStyle);
  24057. inlineStyle = processCustomInlineStyles(nodeName, node, inlineStyle); // Handle lists
  24058. if (nodeName === 'ul' || nodeName === 'ol') {
  24059. if (lastList) {
  24060. depth += 1;
  24061. }
  24062. lastList = nodeName;
  24063. inBlock = null;
  24064. } // Block Tags
  24065. var blockInfo = checkBlockType(nodeName, node, lastList, inBlock);
  24066. var blockType;
  24067. var blockDataMap;
  24068. if (blockInfo === false) {
  24069. return getEmptyChunk();
  24070. }
  24071. blockInfo = blockInfo || {};
  24072. if (typeof blockInfo === 'string') {
  24073. blockType = blockInfo;
  24074. blockDataMap = (0, immutable$2.Map)();
  24075. } else {
  24076. blockType = typeof blockInfo === 'string' ? blockInfo : blockInfo.type;
  24077. blockDataMap = blockInfo.data ? (0, immutable$2.Map)(blockInfo.data) : (0, immutable$2.Map)();
  24078. }
  24079. if (!inBlock && (fragmentBlockTags.indexOf(nodeName) !== -1 || blockType)) {
  24080. chunk = getBlockDividerChunk(blockType || getBlockTypeForTag(nodeName, lastList), depth, blockDataMap);
  24081. inBlock = blockType || getBlockTypeForTag(nodeName, lastList);
  24082. newBlock = true;
  24083. } else if (lastList && (inBlock === 'ordered-list-item' || inBlock === 'unordered-list-item') && nodeName === 'li') {
  24084. var listItemBlockType = getBlockTypeForTag(nodeName, lastList);
  24085. chunk = getBlockDividerChunk(listItemBlockType, depth);
  24086. inBlock = listItemBlockType;
  24087. newBlock = true;
  24088. nextBlockType = lastList === 'ul' ? 'unordered-list-item' : 'ordered-list-item';
  24089. } else if (inBlock && inBlock !== 'atomic' && blockType === 'atomic') {
  24090. inBlock = blockType;
  24091. newBlock = true;
  24092. chunk = getSoftNewlineChunk(blockType, depth, true, // atomic blocks within non-atomic blocks must always be split out
  24093. blockDataMap);
  24094. } // Recurse through children
  24095. var child = node.firstChild; // hack to allow conversion of atomic blocks from HTML (e.g. <figure><img
  24096. // src="..." /></figure>). since metadata must be stored on an entity text
  24097. // must exist for the entity to apply to. the way chunks are joined strips
  24098. // whitespace at the end so it cannot be a space character.
  24099. if (child == null && inEntity && (blockType === 'atomic' || inBlock === 'atomic')) {
  24100. child = document.createTextNode('a');
  24101. }
  24102. if (child != null) {
  24103. nodeName = child.nodeName.toLowerCase();
  24104. }
  24105. var entityId = null;
  24106. while (child) {
  24107. entityId = checkEntityNode(nodeName, child, createEntity, getEntity, mergeEntityData, replaceEntityData);
  24108. newChunk = genFragment(child, inlineStyle, lastList, inBlock, fragmentBlockTags, depth, processCustomInlineStyles, checkEntityNode, checkEntityText, checkBlockType, createEntity, getEntity, mergeEntityData, replaceEntityData, options, entityId || inEntity);
  24109. chunk = joinChunks(chunk, newChunk, options.flat);
  24110. var sibling = child.nextSibling; // Put in a newline to break up blocks inside blocks
  24111. if (sibling && fragmentBlockTags.indexOf(nodeName) >= 0 && inBlock) {
  24112. var newBlockInfo = checkBlockType(nodeName, child, lastList, inBlock);
  24113. var newBlockType = void 0;
  24114. var newBlockData = void 0;
  24115. if (newBlockInfo !== false) {
  24116. newBlockInfo = newBlockInfo || {};
  24117. if (typeof newBlockInfo === 'string') {
  24118. newBlockType = newBlockInfo;
  24119. newBlockData = (0, immutable$2.Map)();
  24120. } else {
  24121. newBlockType = newBlockInfo.type || getBlockTypeForTag(nodeName, lastList);
  24122. newBlockData = newBlockInfo.data ? (0, immutable$2.Map)(newBlockInfo.data) : (0, immutable$2.Map)();
  24123. }
  24124. chunk = joinChunks(chunk, getSoftNewlineChunk(newBlockType, depth, options.flat, newBlockData), options.flat);
  24125. }
  24126. }
  24127. if (sibling) {
  24128. nodeName = sibling.nodeName.toLowerCase();
  24129. }
  24130. child = sibling;
  24131. }
  24132. if (newBlock) {
  24133. chunk = joinChunks(chunk, getBlockDividerChunk(nextBlockType, depth, (0, immutable$2.Map)()), options.flat);
  24134. }
  24135. return chunk;
  24136. }
  24137. function getChunkForHTML(html, processCustomInlineStyles, checkEntityNode, checkEntityText, checkBlockType, createEntity, getEntity, mergeEntityData, replaceEntityData, options, DOMBuilder) {
  24138. html = html.trim().replace(REGEX_CR, '').replace(REGEX_NBSP, SPACE);
  24139. var safeBody = DOMBuilder(html);
  24140. if (!safeBody) {
  24141. return null;
  24142. } // Sometimes we aren't dealing with content that contains nice semantic
  24143. // tags. In this case, use divs to separate everything out into paragraphs
  24144. // and hope for the best.
  24145. var workingBlocks = containsSemanticBlockMarkup(html) ? blockTags.concat(['div']) : ['div']; // Start with -1 block depth to offset the fact that we are passing in a fake
  24146. // UL block to sta rt with.
  24147. 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
  24148. if (chunk.text.indexOf('\r') === 0) {
  24149. chunk = {
  24150. text: chunk.text.slice(1),
  24151. inlines: chunk.inlines.slice(1),
  24152. entities: chunk.entities.slice(1),
  24153. blocks: chunk.blocks
  24154. };
  24155. } // Kill block delimiter at the end
  24156. if (chunk.text.slice(-1) === '\r') {
  24157. chunk.text = chunk.text.slice(0, -1);
  24158. chunk.inlines = chunk.inlines.slice(0, -1);
  24159. chunk.entities = chunk.entities.slice(0, -1);
  24160. chunk.blocks.pop();
  24161. } // If we saw no block tags, put an unstyled one in
  24162. if (chunk.blocks.length === 0) {
  24163. chunk.blocks.push({
  24164. type: 'unstyled',
  24165. data: (0, immutable$2.Map)(),
  24166. depth: 0
  24167. });
  24168. } // Sometimes we start with text that isn't in a block, which is then
  24169. // followed by blocks. Need to fix up the blocks to add in
  24170. // an unstyled block for this content
  24171. if (chunk.text.split('\r').length === chunk.blocks.length + 1) {
  24172. chunk.blocks.unshift({
  24173. type: 'unstyled',
  24174. data: (0, immutable$2.Map)(),
  24175. depth: 0
  24176. });
  24177. }
  24178. return chunk;
  24179. }
  24180. function convertFromHTMLtoContentBlocks(html, processCustomInlineStyles, checkEntityNode, checkEntityText, checkBlockType, createEntity, getEntity, mergeEntityData, replaceEntityData, options, DOMBuilder, generateKey) {
  24181. // Be ABSOLUTELY SURE that the dom builder you pass hare won't execute
  24182. // arbitrary code in whatever environment you're running this in. For an
  24183. // example of how we try to do this in-browser, see getSafeBodyFromHTML.
  24184. var chunk = getChunkForHTML(html, processCustomInlineStyles, checkEntityNode, checkEntityText, checkBlockType, createEntity, getEntity, mergeEntityData, replaceEntityData, options, DOMBuilder);
  24185. if (chunk == null) {
  24186. return [];
  24187. }
  24188. var start = 0;
  24189. return chunk.text.split('\r').map(function (textBlock, blockIndex) {
  24190. // Make absolutely certain that our text is acceptable.
  24191. textBlock = sanitizeDraftText(textBlock);
  24192. var end = start + textBlock.length;
  24193. var inlines = nullthrows(chunk).inlines.slice(start, end);
  24194. var entities = nullthrows(chunk).entities.slice(start, end);
  24195. var characterList = (0, immutable$2.List)(inlines.map(function (style, entityIndex) {
  24196. var data = {
  24197. style: style,
  24198. entity: null
  24199. };
  24200. if (entities[entityIndex]) {
  24201. data.entity = entities[entityIndex];
  24202. }
  24203. return Draft.CharacterMetadata.create(data);
  24204. }));
  24205. start = end + 1;
  24206. return new Draft.ContentBlock({
  24207. key: generateKey(),
  24208. type: nullthrows(chunk).blocks[blockIndex].type,
  24209. data: nullthrows(chunk).blocks[blockIndex].data,
  24210. depth: nullthrows(chunk).blocks[blockIndex].depth,
  24211. text: textBlock,
  24212. characterList: characterList
  24213. });
  24214. });
  24215. }
  24216. var convertFromHTML = function convertFromHTML(_ref2) {
  24217. var _ref2$htmlToStyle = _ref2.htmlToStyle,
  24218. htmlToStyle = _ref2$htmlToStyle === void 0 ? defaultHTMLToStyle : _ref2$htmlToStyle,
  24219. _ref2$htmlToEntity = _ref2.htmlToEntity,
  24220. htmlToEntity = _ref2$htmlToEntity === void 0 ? defaultHTMLToEntity : _ref2$htmlToEntity,
  24221. _ref2$textToEntity = _ref2.textToEntity,
  24222. textToEntity = _ref2$textToEntity === void 0 ? defaultTextToEntity : _ref2$textToEntity,
  24223. _ref2$htmlToBlock = _ref2.htmlToBlock,
  24224. htmlToBlock = _ref2$htmlToBlock === void 0 ? defaultHTMLToBlock : _ref2$htmlToBlock;
  24225. return function (html) {
  24226. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
  24227. flat: false
  24228. };
  24229. var DOMBuilder = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _parseHTML["default"];
  24230. var generateKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : Draft.genKey;
  24231. var contentState = Draft.ContentState.createFromText('');
  24232. var createEntityWithContentState = function createEntityWithContentState() {
  24233. if (contentState.createEntity) {
  24234. var _contentState;
  24235. contentState = (_contentState = contentState).createEntity.apply(_contentState, arguments);
  24236. return contentState.getLastCreatedEntityKey();
  24237. }
  24238. return Draft.Entity.create.apply(Draft.Entity, arguments);
  24239. };
  24240. var getEntityWithContentState = function getEntityWithContentState() {
  24241. if (contentState.getEntity) {
  24242. var _contentState2;
  24243. return (_contentState2 = contentState).getEntity.apply(_contentState2, arguments);
  24244. }
  24245. return Draft.Entity.get.apply(Draft.Entity, arguments);
  24246. };
  24247. var mergeEntityDataWithContentState = function mergeEntityDataWithContentState() {
  24248. if (contentState.mergeEntityData) {
  24249. var _contentState3;
  24250. contentState = (_contentState3 = contentState).mergeEntityData.apply(_contentState3, arguments);
  24251. return;
  24252. }
  24253. Draft.Entity.mergeData.apply(Draft.Entity, arguments);
  24254. };
  24255. var replaceEntityDataWithContentState = function replaceEntityDataWithContentState() {
  24256. if (contentState.replaceEntityData) {
  24257. var _contentState4;
  24258. contentState = (_contentState4 = contentState).replaceEntityData.apply(_contentState4, arguments);
  24259. return;
  24260. }
  24261. Draft.Entity.replaceData.apply(Draft.Entity, arguments);
  24262. };
  24263. var contentBlocks = convertFromHTMLtoContentBlocks(html, handleMiddleware(htmlToStyle, baseProcessInlineTag), handleMiddleware(htmlToEntity, defaultHTMLToEntity), handleMiddleware(textToEntity, defaultTextToEntity), handleMiddleware(htmlToBlock, baseCheckBlockType), createEntityWithContentState, getEntityWithContentState, mergeEntityDataWithContentState, replaceEntityDataWithContentState, options, DOMBuilder, generateKey);
  24264. var blockMap = Draft.BlockMapBuilder.createFromArray(contentBlocks);
  24265. var firstBlockKey = contentBlocks[0].getKey();
  24266. return contentState.merge({
  24267. blockMap: blockMap,
  24268. selectionBefore: Draft.SelectionState.createEmpty(firstBlockKey),
  24269. selectionAfter: Draft.SelectionState.createEmpty(firstBlockKey)
  24270. });
  24271. };
  24272. };
  24273. var _default = function _default() {
  24274. if (arguments.length >= 1 && typeof (arguments.length <= 0 ? undefined : arguments[0]) === 'string') {
  24275. return convertFromHTML({}).apply(void 0, arguments);
  24276. }
  24277. return convertFromHTML.apply(void 0, arguments);
  24278. };
  24279. exports["default"] = _default;
  24280. });
  24281. unwrapExports(convertFromHTML_1);
  24282. var lib = createCommonjsModule(function (module, exports) {
  24283. Object.defineProperty(exports, "__esModule", {
  24284. value: true
  24285. });
  24286. Object.defineProperty(exports, "convertToHTML", {
  24287. enumerable: true,
  24288. get: function get() {
  24289. return _convertToHTML["default"];
  24290. }
  24291. });
  24292. Object.defineProperty(exports, "convertFromHTML", {
  24293. enumerable: true,
  24294. get: function get() {
  24295. return _convertFromHTML["default"];
  24296. }
  24297. });
  24298. Object.defineProperty(exports, "parseHTML", {
  24299. enumerable: true,
  24300. get: function get() {
  24301. return _parseHTML["default"];
  24302. }
  24303. });
  24304. var _convertToHTML = interopRequireDefault(convertToHTML_1);
  24305. var _convertFromHTML = interopRequireDefault(convertFromHTML_1);
  24306. var _parseHTML = interopRequireDefault(parseHTML_1);
  24307. });
  24308. unwrapExports(lib);
  24309. var configs = createCommonjsModule(function (module, exports) {
  24310. Object.defineProperty(exports, "__esModule", {
  24311. value: true
  24312. });
  24313. exports.getFromHTMLConfig = exports.getToHTMLConfig = exports.blocks = exports.getHexColor = exports.defaultFontFamilies = exports.namedColors = undefined;
  24314. 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; };
  24315. var _react2 = _interopRequireDefault(React);
  24316. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  24317. 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; }
  24318. var namedColors = exports.namedColors = {
  24319. "aliceblue": "#f0f8ff",
  24320. "antiquewhite": "#faebd7",
  24321. "aqua": "#00ffff",
  24322. "aquamarine": "#7fffd4",
  24323. "azure": "#f0ffff",
  24324. "beige": "#f5f5dc",
  24325. "bisque": "#ffe4c4",
  24326. "black": "#000000",
  24327. "blanchedalmond": "#ffebcd",
  24328. "blue": "#0000ff",
  24329. "blueviolet": "#8a2be2",
  24330. "brown": "#a52a2a",
  24331. "burlywood": "#deb887",
  24332. "cadetblue": "#5f9ea0",
  24333. "chartreuse": "#7fff00",
  24334. "chocolate": "#d2691e",
  24335. "coral": "#ff7f50",
  24336. "cornflowerblue": "#6495ed",
  24337. "cornsilk": "#fff8dc",
  24338. "crimson": "#dc143c",
  24339. "cyan": "#00ffff",
  24340. "darkblue": "#00008b",
  24341. "darkcyan": "#008b8b",
  24342. "darkgoldenrod": "#b8860b",
  24343. "darkgray": "#a9a9a9",
  24344. "darkgreen": "#006400",
  24345. "darkkhaki": "#bdb76b",
  24346. "darkmagenta": "#8b008b",
  24347. "darkolivegreen": "#556b2f",
  24348. "darkorange": "#ff8c00",
  24349. "darkorchid": "#9932cc",
  24350. "darkred": "#8b0000",
  24351. "darksalmon": "#e9967a",
  24352. "darkseagreen": "#8fbc8f",
  24353. "darkslateblue": "#483d8b",
  24354. "darkslategray": "#2f4f4f",
  24355. "darkturquoise": "#00ced1",
  24356. "darkviolet": "#9400d3",
  24357. "deeppink": "#ff1493",
  24358. "deepskyblue": "#00bfff",
  24359. "dimgray": "#696969",
  24360. "dodgerblue": "#1e90ff",
  24361. "firebrick": "#b22222",
  24362. "floralwhite": "#fffaf0",
  24363. "forestgreen": "#228b22",
  24364. "fuchsia": "#ff00ff",
  24365. "gainsboro": "#dcdcdc",
  24366. "ghostwhite": "#f8f8ff",
  24367. "gold": "#ffd700",
  24368. "goldenrod": "#daa520",
  24369. "gray": "#808080",
  24370. "green": "#008000",
  24371. "greenyellow": "#adff2f",
  24372. "honeydew": "#f0fff0",
  24373. "hotpink": "#ff69b4",
  24374. "indianred ": "#cd5c5c",
  24375. "indigo": "#4b0082",
  24376. "ivory": "#fffff0",
  24377. "khaki": "#f0e68c",
  24378. "lavender": "#e6e6fa",
  24379. "lavenderblush": "#fff0f5",
  24380. "lawngreen": "#7cfc00",
  24381. "lemonchiffon": "#fffacd",
  24382. "lightblue": "#add8e6",
  24383. "lightcoral": "#f08080",
  24384. "lightcyan": "#e0ffff",
  24385. "lightgoldenrodyellow": "#fafad2",
  24386. "lightgrey": "#d3d3d3",
  24387. "lightgreen": "#90ee90",
  24388. "lightpink": "#ffb6c1",
  24389. "lightsalmon": "#ffa07a",
  24390. "lightseagreen": "#20b2aa",
  24391. "lightskyblue": "#87cefa",
  24392. "lightslategray": "#778899",
  24393. "lightsteelblue": "#b0c4de",
  24394. "lightyellow": "#ffffe0",
  24395. "lime": "#00ff00",
  24396. "limegreen": "#32cd32",
  24397. "linen": "#faf0e6",
  24398. "magenta": "#ff00ff",
  24399. "maroon": "#800000",
  24400. "mediumaquamarine": "#66cdaa",
  24401. "mediumblue": "#0000cd",
  24402. "mediumorchid": "#ba55d3",
  24403. "mediumpurple": "#9370d8",
  24404. "mediumseagreen": "#3cb371",
  24405. "mediumslateblue": "#7b68ee",
  24406. "mediumspringgreen": "#00fa9a",
  24407. "mediumturquoise": "#48d1cc",
  24408. "mediumvioletred": "#c71585",
  24409. "midnightblue": "#191970",
  24410. "mintcream": "#f5fffa",
  24411. "mistyrose": "#ffe4e1",
  24412. "moccasin": "#ffe4b5",
  24413. "navajowhite": "#ffdead",
  24414. "navy": "#000080",
  24415. "oldlace": "#fdf5e6",
  24416. "olive": "#808000",
  24417. "olivedrab": "#6b8e23",
  24418. "orange": "#ffa500",
  24419. "orangered": "#ff4500",
  24420. "orchid": "#da70d6",
  24421. "palegoldenrod": "#eee8aa",
  24422. "palegreen": "#98fb98",
  24423. "paleturquoise": "#afeeee",
  24424. "palevioletred": "#d87093",
  24425. "papayawhip": "#ffefd5",
  24426. "peachpuff": "#ffdab9",
  24427. "peru": "#cd853f",
  24428. "pink": "#ffc0cb",
  24429. "plum": "#dda0dd",
  24430. "powderblue": "#b0e0e6",
  24431. "purple": "#800080",
  24432. "rebeccapurple": "#663399",
  24433. "red": "#ff0000",
  24434. "rosybrown": "#bc8f8f",
  24435. "royalblue": "#4169e1",
  24436. "saddlebrown": "#8b4513",
  24437. "salmon": "#fa8072",
  24438. "sandybrown": "#f4a460",
  24439. "seagreen": "#2e8b57",
  24440. "seashell": "#fff5ee",
  24441. "sienna": "#a0522d",
  24442. "silver": "#c0c0c0",
  24443. "skyblue": "#87ceeb",
  24444. "slateblue": "#6a5acd",
  24445. "slategray": "#708090",
  24446. "snow": "#fffafa",
  24447. "springgreen": "#00ff7f",
  24448. "steelblue": "#4682b4",
  24449. "tan": "#d2b48c",
  24450. "teal": "#008080",
  24451. "thistle": "#d8bfd8",
  24452. "tomato": "#ff6347",
  24453. "turquoise": "#40e0d0",
  24454. "violet": "#ee82ee",
  24455. "wheat": "#f5deb3",
  24456. "white": "#ffffff",
  24457. "whitesmoke": "#f5f5f5",
  24458. "yellow": "#ffff00",
  24459. "yellowgreen": "#9acd32"
  24460. };
  24461. var getStyleValue = function getStyleValue(style) {
  24462. return style.split('-')[1];
  24463. };
  24464. var defaultUnitExportFn = function defaultUnitExportFn(unit) {
  24465. return unit + 'px';
  24466. };
  24467. var defaultUnitImportFn = function defaultUnitImportFn(unit) {
  24468. return unit.replace('px', '');
  24469. };
  24470. var ignoredNodeAttributes = ['style'];
  24471. var ignoredEntityNodeAttributes = ['style', 'href', 'target', 'alt', 'title', 'id', 'controls', 'autoplay', 'loop', 'poster'];
  24472. var spreadNodeAttributes = function spreadNodeAttributes(attributesObject) {
  24473. return Object.keys(attributesObject).reduce(function (attributeString, attributeName) {
  24474. return attributeString + " " + attributeName + "=\"" + attributesObject[attributeName] + "\"";
  24475. }, '').replace(/^\s$/, '');
  24476. };
  24477. var defaultFontFamilies = exports.defaultFontFamilies = [{
  24478. name: 'Araial',
  24479. family: 'Arial, Helvetica, sans-serif'
  24480. }, {
  24481. name: 'Georgia',
  24482. family: 'Georgia, serif'
  24483. }, {
  24484. name: 'Impact',
  24485. family: 'Impact, serif'
  24486. }, {
  24487. name: 'Monospace',
  24488. family: '"Courier New", Courier, monospace'
  24489. }, {
  24490. name: 'Tahoma',
  24491. family: "tahoma, arial, 'Hiragino Sans GB', 宋体, sans-serif"
  24492. }];
  24493. var getHexColor = exports.getHexColor = function getHexColor(color) {
  24494. color = color.replace('color:', '').replace(';', '').replace(' ', '');
  24495. if (/^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/.test(color)) {
  24496. return color;
  24497. } else if (namedColors[color]) {
  24498. return namedColors[color];
  24499. } else if (color.indexOf('rgb') === 0) {
  24500. var rgbArray = color.split(',');
  24501. var convertedColor = rgbArray.length < 3 ? null : '#' + [rgbArray[0], rgbArray[1], rgbArray[2]].map(function (x) {
  24502. var hex = parseInt(x.replace(/\D/g, ''), 10).toString(16);
  24503. return hex.length === 1 ? '0' + hex : hex;
  24504. }).join('');
  24505. return (/^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/.test(convertedColor) ? convertedColor : null
  24506. );
  24507. } else {
  24508. return null;
  24509. }
  24510. };
  24511. var blocks = exports.blocks = {
  24512. 'header-one': 'h1',
  24513. 'header-two': 'h2',
  24514. 'header-three': 'h3',
  24515. 'header-four': 'h4',
  24516. 'header-five': 'h5',
  24517. 'header-six': 'h6',
  24518. 'unstyled': 'p',
  24519. 'blockquote': 'blockquote'
  24520. };
  24521. var blockTypes = Object.keys(blocks);
  24522. var blockNames = blockTypes.map(function (key) {
  24523. return blocks[key];
  24524. });
  24525. var convertAtomicBlock = function convertAtomicBlock(block, contentState, blockNodeAttributes) {
  24526. if (!block || !block.key) {
  24527. return _react2.default.createElement("p", null);
  24528. }
  24529. var contentBlock = contentState.getBlockForKey(block.key);
  24530. var className = blockNodeAttributes.class,
  24531. nodeAttrAsProps = _objectWithoutProperties(blockNodeAttributes, ["class"]);
  24532. nodeAttrAsProps.className = className;
  24533. if (!contentBlock) {
  24534. return _react2.default.createElement("p", null);
  24535. }
  24536. var entityKey = contentBlock.getEntityAt(0);
  24537. if (!entityKey) {
  24538. return _react2.default.createElement("p", null);
  24539. }
  24540. var entity = contentState.getEntity(entityKey);
  24541. var mediaType = entity.getType().toLowerCase();
  24542. var _block$data = block.data,
  24543. float = _block$data.float,
  24544. alignment = _block$data.alignment;
  24545. var _entity$getData = entity.getData(),
  24546. url = _entity$getData.url,
  24547. link = _entity$getData.link,
  24548. link_target = _entity$getData.link_target,
  24549. width = _entity$getData.width,
  24550. height = _entity$getData.height,
  24551. meta = _entity$getData.meta;
  24552. if (mediaType === 'image') {
  24553. var imageWrapStyle = {};
  24554. var styledClassName = '';
  24555. if (float) {
  24556. imageWrapStyle.float = float;
  24557. styledClassName += ' float-' + float;
  24558. } else if (alignment) {
  24559. imageWrapStyle.textAlign = alignment;
  24560. styledClassName += ' align-' + alignment;
  24561. }
  24562. if (link) {
  24563. return _react2.default.createElement(
  24564. "div",
  24565. { className: "media-wrap image-wrap" + styledClassName, style: imageWrapStyle },
  24566. _react2.default.createElement(
  24567. "a",
  24568. { style: { display: 'inline-block' }, href: link, target: link_target },
  24569. _react2.default.createElement("img", _extends({}, nodeAttrAsProps, meta, { src: url, width: width, height: height, style: { width: width, height: height } }))
  24570. )
  24571. );
  24572. } else {
  24573. return _react2.default.createElement(
  24574. "div",
  24575. { className: "media-wrap image-wrap" + styledClassName, style: imageWrapStyle },
  24576. _react2.default.createElement("img", _extends({}, nodeAttrAsProps, meta, { src: url, width: width, height: height, style: { width: width, height: height } }))
  24577. );
  24578. }
  24579. } else if (mediaType === 'audio') {
  24580. return _react2.default.createElement(
  24581. "div",
  24582. { className: "media-wrap audio-wrap" },
  24583. _react2.default.createElement("audio", _extends({ controls: true }, nodeAttrAsProps, meta, { src: url }))
  24584. );
  24585. } else if (mediaType === 'video') {
  24586. return _react2.default.createElement(
  24587. "div",
  24588. { className: "media-wrap video-wrap" },
  24589. _react2.default.createElement("video", _extends({ controls: true }, nodeAttrAsProps, meta, { src: url, width: width, height: height }))
  24590. );
  24591. } else if (mediaType === 'embed') {
  24592. return _react2.default.createElement(
  24593. "div",
  24594. { className: "media-wrap embed-wrap" },
  24595. _react2.default.createElement("div", { dangerouslySetInnerHTML: { __html: url } })
  24596. );
  24597. } else if (mediaType === 'hr') {
  24598. return _react2.default.createElement("hr", null);
  24599. } else {
  24600. return _react2.default.createElement("p", null);
  24601. }
  24602. };
  24603. var entityToHTML = function entityToHTML(options) {
  24604. return function (entity, originalText) {
  24605. var entityExportFn = options.entityExportFn;
  24606. var entityType = entity.type.toLowerCase();
  24607. if (entityExportFn) {
  24608. var customOutput = entityExportFn(entity, originalText);
  24609. if (customOutput) {
  24610. return customOutput;
  24611. }
  24612. }
  24613. if (entityType === 'link') {
  24614. var _ref = entity.data.nodeAttributes || {},
  24615. className = _ref.class,
  24616. nodeAttrAsProps = _objectWithoutProperties(_ref, ["class"]);
  24617. nodeAttrAsProps.className = className;
  24618. return _react2.default.createElement("a", _extends({ href: entity.data.href, target: entity.data.target }, nodeAttrAsProps));
  24619. }
  24620. };
  24621. };
  24622. var styleToHTML = function styleToHTML(options) {
  24623. return function (style) {
  24624. var unitExportFn = options.unitExportFn || defaultUnitExportFn;
  24625. if (options.styleExportFn) {
  24626. var customOutput = options.styleExportFn(style, options);
  24627. if (customOutput) {
  24628. return customOutput;
  24629. }
  24630. }
  24631. style = style.toLowerCase();
  24632. if (style === 'strikethrough') {
  24633. return _react2.default.createElement("span", { style: { textDecoration: 'line-through' } });
  24634. } else if (style === 'superscript') {
  24635. return _react2.default.createElement("sup", null);
  24636. } else if (style === 'subscript') {
  24637. return _react2.default.createElement("sub", null);
  24638. } else if (style.indexOf('color-') === 0) {
  24639. return _react2.default.createElement("span", { style: { color: '#' + getStyleValue(style) } });
  24640. } else if (style.indexOf('bgcolor-') === 0) {
  24641. return _react2.default.createElement("span", { style: { backgroundColor: '#' + getStyleValue(style) } });
  24642. } else if (style.indexOf('fontsize-') === 0) {
  24643. return _react2.default.createElement("span", { style: { fontSize: unitExportFn(getStyleValue(style), 'font-size', 'html') } });
  24644. } else if (style.indexOf('lineheight-') === 0) {
  24645. return _react2.default.createElement("span", { style: { lineHeight: unitExportFn(getStyleValue(style), 'line-height', 'html') } });
  24646. } else if (style.indexOf('letterspacing-') === 0) {
  24647. return _react2.default.createElement("span", { style: { letterSpacing: unitExportFn(getStyleValue(style), 'letter-spacing', 'html') } });
  24648. } else if (style.indexOf('fontfamily-') === 0) {
  24649. var fontFamily = options.fontFamilies.find(function (item) {
  24650. return item.name.toLowerCase() === getStyleValue(style);
  24651. });
  24652. if (!fontFamily) return;
  24653. return _react2.default.createElement("span", { style: { fontFamily: fontFamily.family } });
  24654. }
  24655. };
  24656. };
  24657. var blockToHTML = function blockToHTML(options) {
  24658. return function (block) {
  24659. var blockExportFn = options.blockExportFn,
  24660. contentState = options.contentState;
  24661. if (blockExportFn) {
  24662. var customOutput = blockExportFn(contentState, block);
  24663. if (customOutput) {
  24664. return customOutput;
  24665. }
  24666. }
  24667. var blockStyle = '';
  24668. var blockType = block.type.toLowerCase();
  24669. var _block$data2 = block.data,
  24670. textAlign = _block$data2.textAlign,
  24671. textIndent = _block$data2.textIndent,
  24672. _block$data2$nodeAttr = _block$data2.nodeAttributes,
  24673. nodeAttributes = _block$data2$nodeAttr === undefined ? {} : _block$data2$nodeAttr;
  24674. var attributeString = spreadNodeAttributes(nodeAttributes);
  24675. if (textAlign || textIndent) {
  24676. blockStyle = ' style="';
  24677. if (textAlign) {
  24678. blockStyle += "text-align:" + textAlign + ";";
  24679. }
  24680. if (textIndent && !isNaN(textIndent) && textIndent > 0) {
  24681. blockStyle += "text-indent:" + textIndent * 2 + "em;";
  24682. }
  24683. blockStyle += '"';
  24684. }
  24685. if (blockType === 'atomic') {
  24686. return convertAtomicBlock(block, contentState, nodeAttributes);
  24687. } else if (blockType === 'code-block') {
  24688. var previousBlock = contentState.getBlockBefore(block.key);
  24689. var nextBlock = contentState.getBlockAfter(block.key);
  24690. var previousBlockType = previousBlock && previousBlock.getType();
  24691. var nextBlockType = nextBlock && nextBlock.getType();
  24692. var start = '';
  24693. var end = '';
  24694. if (previousBlockType !== 'code-block') {
  24695. start = "<pre" + attributeString + "><code>";
  24696. } else {
  24697. start = '';
  24698. }
  24699. if (nextBlockType !== 'code-block') {
  24700. end = '</code></pre>';
  24701. } else {
  24702. end = '<br/>';
  24703. }
  24704. return { start: start, end: end };
  24705. } else if (blocks[blockType]) {
  24706. return {
  24707. start: "<" + blocks[blockType] + blockStyle + attributeString + ">",
  24708. end: "</" + blocks[blockType] + ">"
  24709. };
  24710. } else if (blockType === 'unordered-list-item') {
  24711. return {
  24712. start: "<li" + blockStyle + attributeString + ">",
  24713. end: '</li>',
  24714. nest: _react2.default.createElement("ul", null)
  24715. };
  24716. } else if (blockType === 'ordered-list-item') {
  24717. return {
  24718. start: "<li" + blockStyle + attributeString + ">",
  24719. end: '</li>',
  24720. nest: _react2.default.createElement("ol", null)
  24721. };
  24722. }
  24723. };
  24724. };
  24725. var htmlToStyle = function htmlToStyle(options, source) {
  24726. return function (nodeName, node, currentStyle) {
  24727. if (!node || !node.style) {
  24728. return currentStyle;
  24729. }
  24730. var unitImportFn = options.unitImportFn || defaultUnitImportFn;
  24731. var newStyle = currentStyle;
  24732. [].forEach.call(node.style, function (style) {
  24733. if (nodeName === 'span' && style === 'color') {
  24734. var color = getHexColor(node.style.color);
  24735. newStyle = color ? newStyle.add('COLOR-' + color.replace('#', '').toUpperCase()) : newStyle;
  24736. } else if (nodeName === 'span' && style === 'background-color') {
  24737. var _color = getHexColor(node.style.backgroundColor);
  24738. newStyle = _color ? newStyle.add('BGCOLOR-' + _color.replace('#', '').toUpperCase()) : newStyle;
  24739. } else if (nodeName === 'span' && style === 'font-size') {
  24740. newStyle = newStyle.add('FONTSIZE-' + unitImportFn(node.style.fontSize, 'font-size', source));
  24741. } else if (nodeName === 'span' && style === 'line-height' && !isNaN(parseFloat(node.style.lineHeight, 10))) {
  24742. newStyle = newStyle.add('LINEHEIGHT-' + unitImportFn(node.style.lineHeight, 'line-height', source));
  24743. } else if (nodeName === 'span' && style === 'letter-spacing' && !isNaN(parseFloat(node.style.letterSpacing, 10))) {
  24744. newStyle = newStyle.add('LETTERSPACING-' + unitImportFn(node.style.letterSpacing, 'letter-spacing', source));
  24745. } else if (nodeName === 'span' && style === 'text-decoration') {
  24746. if (node.style.textDecoration === 'line-through') {
  24747. newStyle = newStyle.add('STRIKETHROUGH');
  24748. } else if (node.style.textDecoration === 'underline') {
  24749. newStyle = newStyle.add('UNDERLINE');
  24750. }
  24751. } else if (nodeName === 'span' && style === 'font-family') {
  24752. var fontFamily = options.fontFamilies.find(function (item) {
  24753. return item.family.toLowerCase() === node.style.fontFamily.toLowerCase();
  24754. });
  24755. if (!fontFamily) return;
  24756. newStyle = newStyle.add('FONTFAMILY-' + fontFamily.name.toUpperCase());
  24757. }
  24758. });
  24759. if (nodeName === 'sup') {
  24760. newStyle = newStyle.add('SUPERSCRIPT');
  24761. } else if (nodeName === 'sub') {
  24762. newStyle = newStyle.add('SUBSCRIPT');
  24763. }
  24764. options.styleImportFn && (newStyle = options.styleImportFn(nodeName, node, newStyle, source) || newStyle);
  24765. return newStyle;
  24766. };
  24767. };
  24768. var htmlToEntity = function htmlToEntity(options, source) {
  24769. return function (nodeName, node, createEntity) {
  24770. if (options && options.entityImportFn) {
  24771. var customInput = options.entityImportFn(nodeName, node, createEntity, source);
  24772. if (customInput) {
  24773. return customInput;
  24774. }
  24775. }
  24776. nodeName = nodeName.toLowerCase();
  24777. var alt = node.alt,
  24778. title = node.title,
  24779. id = node.id,
  24780. controls = node.controls,
  24781. autoplay = node.autoplay,
  24782. loop = node.loop,
  24783. poster = node.poster;
  24784. var meta = {};
  24785. var nodeAttributes = {};
  24786. id && (meta.id = id);
  24787. alt && (meta.alt = alt);
  24788. title && (meta.title = title);
  24789. controls && (meta.controls = controls);
  24790. autoplay && (meta.autoPlay = autoplay);
  24791. loop && (meta.loop = loop);
  24792. poster && (meta.poster = poster);
  24793. node.attributes && Object.keys(node.attributes).forEach(function (key) {
  24794. var attr = node.attributes[key];
  24795. ignoredEntityNodeAttributes.indexOf(attr.name) === -1 && (nodeAttributes[attr.name] = attr.value);
  24796. });
  24797. if (nodeName === 'a' && !node.querySelectorAll('img').length) {
  24798. var href = node.getAttribute('href');
  24799. var _target = node.getAttribute('target');
  24800. return createEntity('LINK', 'MUTABLE', { href: href, target: _target, nodeAttributes: nodeAttributes });
  24801. } else if (nodeName === 'audio') {
  24802. return createEntity('AUDIO', 'IMMUTABLE', { url: node.getAttribute('src'), meta: meta, nodeAttributes: nodeAttributes });
  24803. } else if (nodeName === 'video') {
  24804. return createEntity('VIDEO', 'IMMUTABLE', { url: node.getAttribute('src'), meta: meta, nodeAttributes: nodeAttributes });
  24805. } else if (nodeName === 'img') {
  24806. var parentNode = node.parentNode;
  24807. var entityData = { meta: meta };
  24808. var _node$style = node.style,
  24809. width = _node$style.width,
  24810. height = _node$style.height;
  24811. entityData.url = node.getAttribute('src');
  24812. width && (entityData.width = width);
  24813. height && (entityData.height = height);
  24814. if (parentNode.nodeName.toLowerCase() === 'a') {
  24815. entityData.link = parentNode.getAttribute('href');
  24816. entityData.link_target = parentNode.getAttribute('target');
  24817. }
  24818. return createEntity('IMAGE', 'IMMUTABLE', entityData);
  24819. } else if (nodeName === 'hr') {
  24820. return createEntity('HR', 'IMMUTABLE', {});
  24821. } else if (node.parentNode && node.parentNode.classList.contains('embed-wrap')) {
  24822. var embedContent = node.innerHTML || node.outerHTML;
  24823. if (embedContent) {
  24824. return createEntity('EMBED', 'IMMUTABLE', {
  24825. url: embedContent
  24826. });
  24827. }
  24828. }
  24829. };
  24830. };
  24831. var htmlToBlock = function htmlToBlock(options, source) {
  24832. return function (nodeName, node) {
  24833. if (options && options.blockImportFn) {
  24834. var customInput = options.blockImportFn(nodeName, node, source);
  24835. if (customInput) {
  24836. return customInput;
  24837. }
  24838. }
  24839. var nodeAttributes = {};
  24840. var nodeStyle = node.style || {};
  24841. node.attributes && Object.keys(node.attributes).forEach(function (key) {
  24842. var attr = node.attributes[key];
  24843. ignoredNodeAttributes.indexOf(attr.name) === -1 && (nodeAttributes[attr.name] = attr.value);
  24844. });
  24845. if (node.classList && node.classList.contains('media-wrap')) {
  24846. return {
  24847. type: 'atomic',
  24848. data: {
  24849. nodeAttributes: nodeAttributes,
  24850. float: nodeStyle.float,
  24851. alignment: nodeStyle.textAlign
  24852. }
  24853. };
  24854. } else if (nodeName === 'img') {
  24855. return {
  24856. type: 'atomic',
  24857. data: {
  24858. nodeAttributes: nodeAttributes,
  24859. float: nodeStyle.float,
  24860. alignment: nodeStyle.textAlign
  24861. }
  24862. };
  24863. } else if (nodeName === 'hr') {
  24864. return {
  24865. type: 'atomic',
  24866. data: { nodeAttributes: nodeAttributes }
  24867. };
  24868. } else if (nodeName === 'pre') {
  24869. node.innerHTML = node.innerHTML.replace(/<code(.*?)>/g, '').replace(/<\/code>/g, '');
  24870. return {
  24871. type: 'code-block',
  24872. data: { nodeAttributes: nodeAttributes }
  24873. };
  24874. } else if (blockNames.indexOf(nodeName) !== -1) {
  24875. var blockData = { nodeAttributes: nodeAttributes };
  24876. if (nodeStyle.textAlign) {
  24877. blockData.textAlign = nodeStyle.textAlign;
  24878. }
  24879. if (nodeStyle.textIndent) {
  24880. blockData.textIndent = /^\d+em$/.test(nodeStyle.textIndent) ? Math.ceil(parseInt(nodeStyle.textIndent, 10) / 2) : 1;
  24881. }
  24882. return {
  24883. type: blockTypes[blockNames.indexOf(nodeName)],
  24884. data: blockData
  24885. };
  24886. }
  24887. };
  24888. };
  24889. var getToHTMLConfig = exports.getToHTMLConfig = function getToHTMLConfig(options) {
  24890. return {
  24891. styleToHTML: styleToHTML(options),
  24892. entityToHTML: entityToHTML(options),
  24893. blockToHTML: blockToHTML(options)
  24894. };
  24895. };
  24896. var getFromHTMLConfig = exports.getFromHTMLConfig = function getFromHTMLConfig(options) {
  24897. var source = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'unknow';
  24898. return {
  24899. htmlToStyle: htmlToStyle(options, source),
  24900. htmlToEntity: htmlToEntity(options, source),
  24901. htmlToBlock: htmlToBlock(options, source)
  24902. };
  24903. };
  24904. });
  24905. unwrapExports(configs);
  24906. var configs_1 = configs.getFromHTMLConfig;
  24907. var configs_2 = configs.getToHTMLConfig;
  24908. var configs_3 = configs.blocks;
  24909. var configs_4 = configs.getHexColor;
  24910. var configs_5 = configs.defaultFontFamilies;
  24911. var configs_6 = configs.namedColors;
  24912. var dist = createCommonjsModule(function (module, exports) {
  24913. Object.defineProperty(exports, "__esModule", {
  24914. value: true
  24915. });
  24916. exports.convertRawToEditorState = exports.convertEditorStateToRaw = exports.convertHTMLToEditorState = exports.convertEditorStateToHTML = exports.convertHTMLToRaw = exports.convertRawToHTML = undefined;
  24917. 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; };
  24918. var defaultConvertOptions = {
  24919. fontFamilies: configs.defaultFontFamilies
  24920. };
  24921. var convertRawToHTML = exports.convertRawToHTML = function convertRawToHTML(rawContent, options) {
  24922. options = _extends({}, defaultConvertOptions, options);
  24923. try {
  24924. var contentState = (0, Draft.convertFromRaw)(rawContent);
  24925. options.contentState = contentState;
  24926. return (0, lib.convertToHTML)((0, configs.getToHTMLConfig)(options))(contentState);
  24927. } catch (error) {
  24928. console.warn(error);
  24929. return '';
  24930. }
  24931. };
  24932. var convertHTMLToRaw = exports.convertHTMLToRaw = function convertHTMLToRaw(HTMLString, options, source) {
  24933. options = _extends({}, defaultConvertOptions, options);
  24934. try {
  24935. var contentState = (0, lib.convertFromHTML)((0, configs.getFromHTMLConfig)(options, source))(HTMLString);
  24936. return (0, Draft.convertToRaw)(contentState);
  24937. } catch (error) {
  24938. console.warn(error);
  24939. return {};
  24940. }
  24941. };
  24942. var convertEditorStateToHTML = exports.convertEditorStateToHTML = function convertEditorStateToHTML(editorState, options) {
  24943. options = _extends({}, defaultConvertOptions, options);
  24944. try {
  24945. var contentState = editorState.getCurrentContent();
  24946. options.contentState = contentState;
  24947. return (0, lib.convertToHTML)((0, configs.getToHTMLConfig)(options))(contentState);
  24948. } catch (error) {
  24949. console.warn(error);
  24950. return '';
  24951. }
  24952. };
  24953. var convertHTMLToEditorState = exports.convertHTMLToEditorState = function convertHTMLToEditorState(HTMLString, editorDecorators, options, source) {
  24954. options = _extends({}, defaultConvertOptions, options);
  24955. try {
  24956. return Draft.EditorState.createWithContent((0, lib.convertFromHTML)((0, configs.getFromHTMLConfig)(options, source))(HTMLString), editorDecorators);
  24957. } catch (error) {
  24958. console.warn(error);
  24959. return Draft.EditorState.createEmpty(editorDecorators);
  24960. }
  24961. };
  24962. var convertEditorStateToRaw = exports.convertEditorStateToRaw = function convertEditorStateToRaw(editorState) {
  24963. return (0, Draft.convertToRaw)(editorState.getCurrentContent());
  24964. };
  24965. var convertRawToEditorState = exports.convertRawToEditorState = function convertRawToEditorState(rawContent, editorDecorators) {
  24966. try {
  24967. return Draft.EditorState.createWithContent((0, Draft.convertFromRaw)(rawContent), editorDecorators);
  24968. } catch (error) {
  24969. console.warn(error);
  24970. return Draft.EditorState.createEmpty(editorDecorators);
  24971. }
  24972. };
  24973. });
  24974. unwrapExports(dist);
  24975. var dist_1 = dist.convertRawToEditorState;
  24976. var dist_2 = dist.convertEditorStateToRaw;
  24977. var dist_3 = dist.convertHTMLToEditorState;
  24978. var dist_4 = dist.convertEditorStateToHTML;
  24979. var dist_5 = dist.convertHTMLToRaw;
  24980. var dist_6 = dist.convertRawToHTML;
  24981. var content = createCommonjsModule(function (module, exports) {
  24982. Object.defineProperty(exports, "__esModule", {
  24983. value: true
  24984. });
  24985. 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;
  24986. var _immutable2 = _interopRequireDefault(immutable$1);
  24987. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  24988. var strictBlockTypes = ['atomic'];
  24989. var registerStrictBlockType = exports.registerStrictBlockType = function registerStrictBlockType(blockType) {
  24990. strictBlockTypes.indexOf(blockType) === -1 && strictBlockTypes.push(blockType);
  24991. };
  24992. var isEditorState = exports.isEditorState = function isEditorState(editorState) {
  24993. return editorState instanceof Draft.EditorState;
  24994. };
  24995. var createEmptyEditorState = exports.createEmptyEditorState = function createEmptyEditorState(editorDecorators) {
  24996. return Draft.EditorState.createEmpty(editorDecorators);
  24997. };
  24998. var createEditorState = exports.createEditorState = function createEditorState(contentState, editorDecorators) {
  24999. return Draft.EditorState.createWithContent(contentState, editorDecorators);
  25000. };
  25001. var isSelectionCollapsed = exports.isSelectionCollapsed = function isSelectionCollapsed(editorState) {
  25002. return editorState.getSelection().isCollapsed();
  25003. };
  25004. var selectionContainsBlockType = exports.selectionContainsBlockType = function selectionContainsBlockType(editorState, blockType) {
  25005. return getSelectedBlocks(editorState).find(function (block) {
  25006. return block.getType() === blockType;
  25007. });
  25008. };
  25009. var selectionContainsStrictBlock = exports.selectionContainsStrictBlock = function selectionContainsStrictBlock(editorState) {
  25010. return getSelectedBlocks(editorState).find(function (block) {
  25011. return ~strictBlockTypes.indexOf(block.getType());
  25012. });
  25013. };
  25014. var selectBlock = exports.selectBlock = function selectBlock(editorState, block) {
  25015. var blockKey = block.getKey();
  25016. return Draft.EditorState.forceSelection(editorState, new Draft.SelectionState({
  25017. anchorKey: blockKey,
  25018. anchorOffset: 0,
  25019. focusKey: blockKey,
  25020. focusOffset: block.getLength()
  25021. }));
  25022. };
  25023. var selectNextBlock = exports.selectNextBlock = function selectNextBlock(editorState, block) {
  25024. var nextBlock = editorState.getCurrentContent().getBlockAfter(block.getKey());
  25025. return nextBlock ? selectBlock(editorState, nextBlock) : editorState;
  25026. };
  25027. var removeBlock = exports.removeBlock = function removeBlock(editorState, block) {
  25028. var lastSelection = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  25029. var nextContentState = void 0,
  25030. nextEditorState = void 0;
  25031. var blockKey = block.getKey();
  25032. nextContentState = Draft.Modifier.removeRange(editorState.getCurrentContent(), new Draft.SelectionState({
  25033. anchorKey: blockKey,
  25034. anchorOffset: 0,
  25035. focusKey: blockKey,
  25036. focusOffset: block.getLength()
  25037. }), 'backward');
  25038. nextContentState = Draft.Modifier.setBlockType(nextContentState, nextContentState.getSelectionAfter(), 'unstyled');
  25039. nextEditorState = Draft.EditorState.push(editorState, nextContentState, 'remove-range');
  25040. return Draft.EditorState.forceSelection(nextEditorState, lastSelection || nextContentState.getSelectionAfter());
  25041. };
  25042. var getSelectionBlock = exports.getSelectionBlock = function getSelectionBlock(editorState) {
  25043. return editorState.getCurrentContent().getBlockForKey(editorState.getSelection().getAnchorKey());
  25044. };
  25045. var updateEachCharacterOfSelection = exports.updateEachCharacterOfSelection = function updateEachCharacterOfSelection(editorState, callback) {
  25046. var selectionState = editorState.getSelection();
  25047. var contentState = editorState.getCurrentContent();
  25048. var contentBlocks = contentState.getBlockMap();
  25049. var selectedBlocks = getSelectedBlocks(editorState);
  25050. if (selectedBlocks.length === 0) {
  25051. return editorState;
  25052. }
  25053. var startKey = selectionState.getStartKey();
  25054. var startOffset = selectionState.getStartOffset();
  25055. var endKey = selectionState.getEndKey();
  25056. var endOffset = selectionState.getEndOffset();
  25057. var nextContentBlocks = contentBlocks.map(function (block) {
  25058. if (selectedBlocks.indexOf(block) === -1) {
  25059. return block;
  25060. }
  25061. var blockKey = block.getKey();
  25062. var charactersList = block.getCharacterList();
  25063. var nextCharactersList = null;
  25064. if (blockKey === startKey && blockKey === endKey) {
  25065. nextCharactersList = charactersList.map(function (character, index) {
  25066. if (index >= startOffset && index < endOffset) {
  25067. return callback(character);
  25068. }
  25069. return character;
  25070. });
  25071. } else if (blockKey === startKey) {
  25072. nextCharactersList = charactersList.map(function (character, index) {
  25073. if (index >= startOffset) {
  25074. return callback(character);
  25075. }
  25076. return character;
  25077. });
  25078. } else if (blockKey === endKey) {
  25079. nextCharactersList = charactersList.map(function (character, index) {
  25080. if (index < endOffset) {
  25081. return callback(character);
  25082. }
  25083. return character;
  25084. });
  25085. } else {
  25086. nextCharactersList = charactersList.map(function (character) {
  25087. return callback(character);
  25088. });
  25089. }
  25090. return block.merge({
  25091. 'characterList': nextCharactersList
  25092. });
  25093. });
  25094. return Draft.EditorState.push(editorState, contentState.merge({
  25095. blockMap: nextContentBlocks,
  25096. selectionBefore: selectionState,
  25097. selectionAfter: selectionState
  25098. }), 'update-selection-character-list');
  25099. };
  25100. var getSelectedBlocks = exports.getSelectedBlocks = function getSelectedBlocks(editorState) {
  25101. var selectionState = editorState.getSelection();
  25102. var contentState = editorState.getCurrentContent();
  25103. var startKey = selectionState.getStartKey();
  25104. var endKey = selectionState.getEndKey();
  25105. var isSameBlock = startKey === endKey;
  25106. var startingBlock = contentState.getBlockForKey(startKey);
  25107. var selectedBlocks = [startingBlock];
  25108. if (!isSameBlock) {
  25109. var blockKey = startKey;
  25110. while (blockKey !== endKey) {
  25111. var nextBlock = contentState.getBlockAfter(blockKey);
  25112. selectedBlocks.push(nextBlock);
  25113. blockKey = nextBlock.getKey();
  25114. }
  25115. }
  25116. return selectedBlocks;
  25117. };
  25118. var setSelectionBlockData = exports.setSelectionBlockData = function setSelectionBlockData(editorState, blockData, override) {
  25119. var newBlockData = override ? blockData : Object.assign({}, getSelectionBlockData(editorState).toJS(), blockData);
  25120. Object.keys(newBlockData).forEach(function (key) {
  25121. if (newBlockData.hasOwnProperty(key) && newBlockData[key] === undefined) {
  25122. delete newBlockData[key];
  25123. }
  25124. });
  25125. return (0, draftjsUtils.setBlockData)(editorState, newBlockData);
  25126. };
  25127. var getSelectionBlockData = exports.getSelectionBlockData = function getSelectionBlockData(editorState, name) {
  25128. var blockData = getSelectionBlock(editorState).getData();
  25129. return name ? blockData.get(name) : blockData;
  25130. };
  25131. var getSelectionBlockType = exports.getSelectionBlockType = function getSelectionBlockType(editorState) {
  25132. return getSelectionBlock(editorState).getType();
  25133. };
  25134. var getSelectionText = exports.getSelectionText = function getSelectionText(editorState) {
  25135. var selectionState = editorState.getSelection();
  25136. var contentState = editorState.getCurrentContent();
  25137. if (selectionState.isCollapsed() || getSelectionBlockType(editorState) === 'atomic') {
  25138. return '';
  25139. }
  25140. var anchorKey = selectionState.getAnchorKey();
  25141. var currentContentBlock = contentState.getBlockForKey(anchorKey);
  25142. var start = selectionState.getStartOffset();
  25143. var end = selectionState.getEndOffset();
  25144. return currentContentBlock.getText().slice(start, end);
  25145. };
  25146. var toggleSelectionBlockType = exports.toggleSelectionBlockType = function toggleSelectionBlockType(editorState, blockType) {
  25147. if (selectionContainsStrictBlock(editorState)) {
  25148. return editorState;
  25149. }
  25150. return Draft.RichUtils.toggleBlockType(editorState, blockType);
  25151. };
  25152. var getSelectionEntityType = exports.getSelectionEntityType = function getSelectionEntityType(editorState) {
  25153. var entityKey = (0, draftjsUtils.getSelectionEntity)(editorState);
  25154. if (entityKey) {
  25155. var entity = editorState.getCurrentContent().getEntity(entityKey);
  25156. return entity ? entity.get('type') : null;
  25157. }
  25158. return null;
  25159. };
  25160. var getSelectionEntityData = exports.getSelectionEntityData = function getSelectionEntityData(editorState, type) {
  25161. var entityKey = (0, draftjsUtils.getSelectionEntity)(editorState);
  25162. if (entityKey) {
  25163. var entity = editorState.getCurrentContent().getEntity(entityKey);
  25164. if (entity && entity.get('type') === type) {
  25165. return entity.getData();
  25166. } else {
  25167. return {};
  25168. }
  25169. } else {
  25170. return {};
  25171. }
  25172. };
  25173. var toggleSelectionEntity = exports.toggleSelectionEntity = function toggleSelectionEntity(editorState, entity) {
  25174. var contentState = editorState.getCurrentContent();
  25175. var selectionState = editorState.getSelection();
  25176. if (selectionState.isCollapsed() || getSelectionBlockType(editorState) === 'atomic') {
  25177. return editorState;
  25178. }
  25179. if (!entity || !entity.type || getSelectionEntityType(editorState) === entity.type) {
  25180. return Draft.EditorState.push(editorState, Draft.Modifier.applyEntity(contentState, selectionState, null), 'apply-entity');
  25181. }
  25182. try {
  25183. var nextContentState = contentState.createEntity(entity.type, entity.mutability, entity.data);
  25184. var entityKey = nextContentState.getLastCreatedEntityKey();
  25185. var nextEditorState = Draft.EditorState.set(editorState, {
  25186. currentContent: nextContentState
  25187. });
  25188. return Draft.EditorState.push(nextEditorState, Draft.Modifier.applyEntity(nextContentState, selectionState, entityKey), 'apply-entity');
  25189. } catch (error) {
  25190. console.warn(error);
  25191. return editorState;
  25192. }
  25193. };
  25194. var toggleSelectionLink = exports.toggleSelectionLink = function toggleSelectionLink(editorState, href, target) {
  25195. var contentState = editorState.getCurrentContent();
  25196. var selectionState = editorState.getSelection();
  25197. var entityData = { href: href, target: target };
  25198. if (selectionState.isCollapsed() || getSelectionBlockType(editorState) === 'atomic') {
  25199. return editorState;
  25200. }
  25201. if (href === false) {
  25202. return Draft.RichUtils.toggleLink(editorState, selectionState, null);
  25203. }
  25204. if (href === null) {
  25205. delete entityData.href;
  25206. }
  25207. try {
  25208. var nextContentState = contentState.createEntity('LINK', 'MUTABLE', entityData);
  25209. var entityKey = nextContentState.getLastCreatedEntityKey();
  25210. var nextEditorState = Draft.EditorState.set(editorState, {
  25211. currentContent: nextContentState
  25212. });
  25213. nextEditorState = Draft.RichUtils.toggleLink(nextEditorState, selectionState, entityKey);
  25214. nextEditorState = Draft.EditorState.forceSelection(nextEditorState, selectionState.merge({
  25215. anchorOffset: selectionState.getEndOffset(),
  25216. focusOffset: selectionState.getEndOffset()
  25217. }));
  25218. nextEditorState = Draft.EditorState.push(nextEditorState, Draft.Modifier.insertText(nextEditorState.getCurrentContent(), nextEditorState.getSelection(), ''), 'insert-text');
  25219. return nextEditorState;
  25220. } catch (error) {
  25221. console.warn(error);
  25222. return editorState;
  25223. }
  25224. };
  25225. var getSelectionInlineStyle = exports.getSelectionInlineStyle = function getSelectionInlineStyle(editorState) {
  25226. return editorState.getCurrentInlineStyle();
  25227. };
  25228. var selectionHasInlineStyle = exports.selectionHasInlineStyle = function selectionHasInlineStyle(editorState, style) {
  25229. return getSelectionInlineStyle(editorState).has(style.toUpperCase());
  25230. };
  25231. var toggleSelectionInlineStyle = exports.toggleSelectionInlineStyle = function toggleSelectionInlineStyle(editorState, style) {
  25232. var prefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
  25233. var nextEditorState = editorState;
  25234. style = prefix + style.toUpperCase();
  25235. if (prefix) {
  25236. nextEditorState = updateEachCharacterOfSelection(nextEditorState, function (characterMetadata) {
  25237. return characterMetadata.toJS().style.reduce(function (characterMetadata, characterStyle) {
  25238. if (characterStyle.indexOf(prefix) === 0 && style !== characterStyle) {
  25239. return Draft.CharacterMetadata.removeStyle(characterMetadata, characterStyle);
  25240. } else {
  25241. return characterMetadata;
  25242. }
  25243. }, characterMetadata);
  25244. });
  25245. }
  25246. return Draft.RichUtils.toggleInlineStyle(nextEditorState, style);
  25247. };
  25248. var removeSelectionInlineStyles = exports.removeSelectionInlineStyles = function removeSelectionInlineStyles(editorState) {
  25249. return updateEachCharacterOfSelection(editorState, function (characterMetadata) {
  25250. return characterMetadata.merge({
  25251. style: _immutable2.default.OrderedSet([])
  25252. });
  25253. });
  25254. };
  25255. var toggleSelectionAlignment = exports.toggleSelectionAlignment = function toggleSelectionAlignment(editorState, alignment) {
  25256. return setSelectionBlockData(editorState, {
  25257. textAlign: getSelectionBlockData(editorState, 'textAlign') !== alignment ? alignment : undefined
  25258. });
  25259. };
  25260. var toggleSelectionIndent = exports.toggleSelectionIndent = function toggleSelectionIndent(editorState, textIndent) {
  25261. var maxIndent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 6;
  25262. return textIndent < 0 || textIndent > maxIndent || isNaN(textIndent) ? editorState : setSelectionBlockData(editorState, {
  25263. textIndent: textIndent || undefined
  25264. });
  25265. };
  25266. var increaseSelectionIndent = exports.increaseSelectionIndent = function increaseSelectionIndent(editorState) {
  25267. var maxIndent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 6;
  25268. var currentIndent = getSelectionBlockData(editorState, 'textIndent') || 0;
  25269. return toggleSelectionIndent(editorState, currentIndent + 1, maxIndent);
  25270. };
  25271. var decreaseSelectionIndent = exports.decreaseSelectionIndent = function decreaseSelectionIndent(editorState) {
  25272. var currentIndent = getSelectionBlockData(editorState, 'textIndent') || 0;
  25273. return toggleSelectionIndent(editorState, currentIndent - 1);
  25274. };
  25275. var toggleSelectionColor = exports.toggleSelectionColor = function toggleSelectionColor(editorState, color) {
  25276. return toggleSelectionInlineStyle(editorState, color.replace('#', ''), 'COLOR-');
  25277. };
  25278. var toggleSelectionBackgroundColor = exports.toggleSelectionBackgroundColor = function toggleSelectionBackgroundColor(editorState, color) {
  25279. return toggleSelectionInlineStyle(editorState, color.replace('#', ''), 'BGCOLOR-');
  25280. };
  25281. var toggleSelectionFontSize = exports.toggleSelectionFontSize = function toggleSelectionFontSize(editorState, fontSize) {
  25282. return toggleSelectionInlineStyle(editorState, fontSize, 'FONTSIZE-');
  25283. };
  25284. var toggleSelectionLineHeight = exports.toggleSelectionLineHeight = function toggleSelectionLineHeight(editorState, lineHeight) {
  25285. return toggleSelectionInlineStyle(editorState, lineHeight, 'LINEHEIGHT-');
  25286. };
  25287. var toggleSelectionFontFamily = exports.toggleSelectionFontFamily = function toggleSelectionFontFamily(editorState, fontFamily) {
  25288. return toggleSelectionInlineStyle(editorState, fontFamily, 'FONTFAMILY-');
  25289. };
  25290. var toggleSelectionLetterSpacing = exports.toggleSelectionLetterSpacing = function toggleSelectionLetterSpacing(editorState, letterSpacing) {
  25291. return toggleSelectionInlineStyle(editorState, letterSpacing, 'LETTERSPACING-');
  25292. };
  25293. var insertText = exports.insertText = function insertText(editorState, text, inlineStyle, entity) {
  25294. var selectionState = editorState.getSelection();
  25295. var currentSelectedBlockType = getSelectionBlockType(editorState);
  25296. if (currentSelectedBlockType === 'atomic') {
  25297. return editorState;
  25298. }
  25299. var entityKey = void 0;
  25300. var contentState = editorState.getCurrentContent();
  25301. if (entity && entity.type) {
  25302. contentState = contentState.createEntity(entity.type, entity.mutability || 'MUTABLE', entity.data || entityData);
  25303. entityKey = contentState.getLastCreatedEntityKey();
  25304. }
  25305. if (!selectionState.isCollapsed()) {
  25306. return Draft.EditorState.push(editorState, Draft.Modifier.replaceText(contentState, selectionState, text, inlineStyle, entityKey), 'replace-text');
  25307. } else {
  25308. return Draft.EditorState.push(editorState, Draft.Modifier.insertText(contentState, selectionState, text, inlineStyle, entityKey), 'insert-text');
  25309. }
  25310. };
  25311. var insertHTML = exports.insertHTML = function insertHTML(editorState, htmlString, source) {
  25312. if (!htmlString) {
  25313. return editorState;
  25314. }
  25315. var selectionState = editorState.getSelection();
  25316. var contentState = editorState.getCurrentContent();
  25317. var options = editorState.convertOptions || {};
  25318. try {
  25319. var _convertFromRaw = (0, Draft.convertFromRaw)((0, dist.convertHTMLToRaw)(htmlString, options, source)),
  25320. blockMap = _convertFromRaw.blockMap;
  25321. return Draft.EditorState.push(editorState, Draft.Modifier.replaceWithFragment(contentState, selectionState, blockMap), 'insert-fragment');
  25322. } catch (error) {
  25323. console.warn(error);
  25324. return editorState;
  25325. }
  25326. };
  25327. var insertAtomicBlock = exports.insertAtomicBlock = function insertAtomicBlock(editorState, type) {
  25328. var immutable = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
  25329. var data = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
  25330. if (selectionContainsStrictBlock(editorState)) {
  25331. return insertAtomicBlock(selectNextBlock(editorState, getSelectionBlock(editorState)), type, immutable, data);
  25332. }
  25333. var selectionState = editorState.getSelection();
  25334. var contentState = editorState.getCurrentContent();
  25335. if (!selectionState.isCollapsed() || getSelectionBlockType(editorState) === 'atomic') {
  25336. return editorState;
  25337. }
  25338. var contentStateWithEntity = contentState.createEntity(type, immutable ? 'IMMUTABLE' : 'MUTABLE', data);
  25339. var entityKey = contentStateWithEntity.getLastCreatedEntityKey();
  25340. var newEditorState = Draft.AtomicBlockUtils.insertAtomicBlock(editorState, entityKey, ' ');
  25341. return newEditorState;
  25342. };
  25343. var insertHorizontalLine = exports.insertHorizontalLine = function insertHorizontalLine(editorState) {
  25344. return insertAtomicBlock(editorState, 'HR');
  25345. };
  25346. var insertMedias = exports.insertMedias = function insertMedias(editorState) {
  25347. var medias = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  25348. if (!medias.length) {
  25349. return editorState;
  25350. }
  25351. return medias.reduce(function (editorState, media) {
  25352. var url = media.url,
  25353. link = media.link,
  25354. link_target = media.link_target,
  25355. name = media.name,
  25356. type = media.type,
  25357. width = media.width,
  25358. height = media.height,
  25359. meta = media.meta;
  25360. return insertAtomicBlock(editorState, type, true, { url: url, link: link, link_target: link_target, name: name, type: type, width: width, height: height, meta: meta });
  25361. }, editorState);
  25362. };
  25363. var setMediaData = exports.setMediaData = function setMediaData(editorState, entityKey, data) {
  25364. return Draft.EditorState.push(editorState, editorState.getCurrentContent().mergeEntityData(entityKey, data), 'change-block-data');
  25365. };
  25366. var removeMedia = exports.removeMedia = function removeMedia(editorState, mediaBlock) {
  25367. return removeBlock(editorState, mediaBlock);
  25368. };
  25369. var setMediaPosition = exports.setMediaPosition = function setMediaPosition(editorState, mediaBlock, position) {
  25370. var newPosition = {};
  25371. var float = position.float,
  25372. alignment = position.alignment;
  25373. if (typeof float !== 'undefined') {
  25374. newPosition.float = mediaBlock.getData().get('float') === float ? null : float;
  25375. }
  25376. if (typeof alignment !== 'undefined') {
  25377. newPosition.alignment = mediaBlock.getData().get('alignment') === alignment ? null : alignment;
  25378. }
  25379. return setSelectionBlockData(selectBlock(editorState, mediaBlock), newPosition);
  25380. };
  25381. var clear = exports.clear = function clear(editorState) {
  25382. var contentState = editorState.getCurrentContent();
  25383. var firstBlock = contentState.getFirstBlock();
  25384. var lastBlock = contentState.getLastBlock();
  25385. var allSelected = new Draft.SelectionState({
  25386. anchorKey: firstBlock.getKey(),
  25387. anchorOffset: 0,
  25388. focusKey: lastBlock.getKey(),
  25389. focusOffset: lastBlock.getLength(),
  25390. hasFocus: true
  25391. });
  25392. return Draft.RichUtils.toggleBlockType(Draft.EditorState.push(editorState, Draft.Modifier.removeRange(contentState, allSelected, 'backward'), 'remove-range'), 'unstyled');
  25393. };
  25394. var handleKeyCommand = exports.handleKeyCommand = function handleKeyCommand(editorState, command) {
  25395. return Draft.RichUtils.handleKeyCommand(editorState, command);
  25396. };
  25397. var undo = exports.undo = function undo(editorState) {
  25398. return Draft.EditorState.undo(editorState);
  25399. };
  25400. var redo = exports.redo = function redo(editorState) {
  25401. return Draft.EditorState.redo(editorState);
  25402. };
  25403. });
  25404. unwrapExports(content);
  25405. var content_1 = content.redo;
  25406. var content_2 = content.undo;
  25407. var content_3 = content.handleKeyCommand;
  25408. var content_4 = content.clear;
  25409. var content_5 = content.setMediaPosition;
  25410. var content_6 = content.removeMedia;
  25411. var content_7 = content.setMediaData;
  25412. var content_8 = content.insertMedias;
  25413. var content_9 = content.insertHorizontalLine;
  25414. var content_10 = content.insertAtomicBlock;
  25415. var content_11 = content.insertHTML;
  25416. var content_12 = content.insertText;
  25417. var content_13 = content.toggleSelectionLetterSpacing;
  25418. var content_14 = content.toggleSelectionFontFamily;
  25419. var content_15 = content.toggleSelectionLineHeight;
  25420. var content_16 = content.toggleSelectionFontSize;
  25421. var content_17 = content.toggleSelectionBackgroundColor;
  25422. var content_18 = content.toggleSelectionColor;
  25423. var content_19 = content.decreaseSelectionIndent;
  25424. var content_20 = content.increaseSelectionIndent;
  25425. var content_21 = content.toggleSelectionIndent;
  25426. var content_22 = content.toggleSelectionAlignment;
  25427. var content_23 = content.removeSelectionInlineStyles;
  25428. var content_24 = content.toggleSelectionInlineStyle;
  25429. var content_25 = content.selectionHasInlineStyle;
  25430. var content_26 = content.getSelectionInlineStyle;
  25431. var content_27 = content.toggleSelectionLink;
  25432. var content_28 = content.toggleSelectionEntity;
  25433. var content_29 = content.getSelectionEntityData;
  25434. var content_30 = content.getSelectionEntityType;
  25435. var content_31 = content.toggleSelectionBlockType;
  25436. var content_32 = content.getSelectionText;
  25437. var content_33 = content.getSelectionBlockType;
  25438. var content_34 = content.getSelectionBlockData;
  25439. var content_35 = content.setSelectionBlockData;
  25440. var content_36 = content.getSelectedBlocks;
  25441. var content_37 = content.updateEachCharacterOfSelection;
  25442. var content_38 = content.getSelectionBlock;
  25443. var content_39 = content.removeBlock;
  25444. var content_40 = content.selectNextBlock;
  25445. var content_41 = content.selectBlock;
  25446. var content_42 = content.selectionContainsStrictBlock;
  25447. var content_43 = content.selectionContainsBlockType;
  25448. var content_44 = content.isSelectionCollapsed;
  25449. var content_45 = content.createEditorState;
  25450. var content_46 = content.createEmptyEditorState;
  25451. var content_47 = content.isEditorState;
  25452. var content_48 = content.registerStrictBlockType;
  25453. var base = createCommonjsModule(function (module, exports) {
  25454. Object.defineProperty(exports, "__esModule", {
  25455. value: true
  25456. });
  25457. var braftUniqueIndex = 0;
  25458. var UniqueIndex = exports.UniqueIndex = function UniqueIndex() {
  25459. return braftUniqueIndex += 1;
  25460. };
  25461. });
  25462. unwrapExports(base);
  25463. var base_1 = base.UniqueIndex;
  25464. var color = createCommonjsModule(function (module, exports) {
  25465. Object.defineProperty(exports, "__esModule", {
  25466. value: true
  25467. });
  25468. var _namedColors = {
  25469. "aliceblue": "#f0f8ff",
  25470. "antiquewhite": "#faebd7",
  25471. "aqua": "#00ffff",
  25472. "aquamarine": "#7fffd4",
  25473. "azure": "#f0ffff",
  25474. "beige": "#f5f5dc",
  25475. "bisque": "#ffe4c4",
  25476. "black": "#000000",
  25477. "blanchedalmond": "#ffebcd",
  25478. "blue": "#0000ff",
  25479. "blueviolet": "#8a2be2",
  25480. "brown": "#a52a2a",
  25481. "burlywood": "#deb887",
  25482. "cadetblue": "#5f9ea0",
  25483. "chartreuse": "#7fff00",
  25484. "chocolate": "#d2691e",
  25485. "coral": "#ff7f50",
  25486. "cornflowerblue": "#6495ed",
  25487. "cornsilk": "#fff8dc",
  25488. "crimson": "#dc143c",
  25489. "cyan": "#00ffff",
  25490. "darkblue": "#00008b",
  25491. "darkcyan": "#008b8b",
  25492. "darkgoldenrod": "#b8860b",
  25493. "darkgray": "#a9a9a9",
  25494. "darkgreen": "#006400",
  25495. "darkkhaki": "#bdb76b",
  25496. "darkmagenta": "#8b008b",
  25497. "darkolivegreen": "#556b2f",
  25498. "darkorange": "#ff8c00",
  25499. "darkorchid": "#9932cc",
  25500. "darkred": "#8b0000",
  25501. "darksalmon": "#e9967a",
  25502. "darkseagreen": "#8fbc8f",
  25503. "darkslateblue": "#483d8b",
  25504. "darkslategray": "#2f4f4f",
  25505. "darkturquoise": "#00ced1",
  25506. "darkviolet": "#9400d3",
  25507. "deeppink": "#ff1493",
  25508. "deepskyblue": "#00bfff",
  25509. "dimgray": "#696969",
  25510. "dodgerblue": "#1e90ff",
  25511. "firebrick": "#b22222",
  25512. "floralwhite": "#fffaf0",
  25513. "forestgreen": "#228b22",
  25514. "fuchsia": "#ff00ff",
  25515. "gainsboro": "#dcdcdc",
  25516. "ghostwhite": "#f8f8ff",
  25517. "gold": "#ffd700",
  25518. "goldenrod": "#daa520",
  25519. "gray": "#808080",
  25520. "green": "#008000",
  25521. "greenyellow": "#adff2f",
  25522. "honeydew": "#f0fff0",
  25523. "hotpink": "#ff69b4",
  25524. "indianred ": "#cd5c5c",
  25525. "indigo": "#4b0082",
  25526. "ivory": "#fffff0",
  25527. "khaki": "#f0e68c",
  25528. "lavender": "#e6e6fa",
  25529. "lavenderblush": "#fff0f5",
  25530. "lawngreen": "#7cfc00",
  25531. "lemonchiffon": "#fffacd",
  25532. "lightblue": "#add8e6",
  25533. "lightcoral": "#f08080",
  25534. "lightcyan": "#e0ffff",
  25535. "lightgoldenrodyellow": "#fafad2",
  25536. "lightgrey": "#d3d3d3",
  25537. "lightgreen": "#90ee90",
  25538. "lightpink": "#ffb6c1",
  25539. "lightsalmon": "#ffa07a",
  25540. "lightseagreen": "#20b2aa",
  25541. "lightskyblue": "#87cefa",
  25542. "lightslategray": "#778899",
  25543. "lightsteelblue": "#b0c4de",
  25544. "lightyellow": "#ffffe0",
  25545. "lime": "#00ff00",
  25546. "limegreen": "#32cd32",
  25547. "linen": "#faf0e6",
  25548. "magenta": "#ff00ff",
  25549. "maroon": "#800000",
  25550. "mediumaquamarine": "#66cdaa",
  25551. "mediumblue": "#0000cd",
  25552. "mediumorchid": "#ba55d3",
  25553. "mediumpurple": "#9370d8",
  25554. "mediumseagreen": "#3cb371",
  25555. "mediumslateblue": "#7b68ee",
  25556. "mediumspringgreen": "#00fa9a",
  25557. "mediumturquoise": "#48d1cc",
  25558. "mediumvioletred": "#c71585",
  25559. "midnightblue": "#191970",
  25560. "mintcream": "#f5fffa",
  25561. "mistyrose": "#ffe4e1",
  25562. "moccasin": "#ffe4b5",
  25563. "navajowhite": "#ffdead",
  25564. "navy": "#000080",
  25565. "oldlace": "#fdf5e6",
  25566. "olive": "#808000",
  25567. "olivedrab": "#6b8e23",
  25568. "orange": "#ffa500",
  25569. "orangered": "#ff4500",
  25570. "orchid": "#da70d6",
  25571. "palegoldenrod": "#eee8aa",
  25572. "palegreen": "#98fb98",
  25573. "paleturquoise": "#afeeee",
  25574. "palevioletred": "#d87093",
  25575. "papayawhip": "#ffefd5",
  25576. "peachpuff": "#ffdab9",
  25577. "peru": "#cd853f",
  25578. "pink": "#ffc0cb",
  25579. "plum": "#dda0dd",
  25580. "powderblue": "#b0e0e6",
  25581. "purple": "#800080",
  25582. "rebeccapurple": "#663399",
  25583. "red": "#ff0000",
  25584. "rosybrown": "#bc8f8f",
  25585. "royalblue": "#4169e1",
  25586. "saddlebrown": "#8b4513",
  25587. "salmon": "#fa8072",
  25588. "sandybrown": "#f4a460",
  25589. "seagreen": "#2e8b57",
  25590. "seashell": "#fff5ee",
  25591. "sienna": "#a0522d",
  25592. "silver": "#c0c0c0",
  25593. "skyblue": "#87ceeb",
  25594. "slateblue": "#6a5acd",
  25595. "slategray": "#708090",
  25596. "snow": "#fffafa",
  25597. "springgreen": "#00ff7f",
  25598. "steelblue": "#4682b4",
  25599. "tan": "#d2b48c",
  25600. "teal": "#008080",
  25601. "thistle": "#d8bfd8",
  25602. "tomato": "#ff6347",
  25603. "turquoise": "#40e0d0",
  25604. "violet": "#ee82ee",
  25605. "wheat": "#f5deb3",
  25606. "white": "#ffffff",
  25607. "whitesmoke": "#f5f5f5",
  25608. "yellow": "#ffff00",
  25609. "yellowgreen": "#9acd32"
  25610. };
  25611. var _getHexColor = function _getHexColor(color) {
  25612. color = color.replace('color:', '').replace(';', '').replace(' ', '');
  25613. if (/^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/.test(color)) {
  25614. return color;
  25615. } else if (namedColors[color]) {
  25616. return namedColors[color];
  25617. } else if (color.indexOf('rgb') === 0) {
  25618. var rgbArray = color.split(',');
  25619. var convertedColor = rgbArray.length < 3 ? null : '#' + [rgbArray[0], rgbArray[1], rgbArray[2]].map(function (x) {
  25620. var hex = parseInt(x.replace(/\D/g, ''), 10).toString(16);
  25621. return hex.length === 1 ? '0' + hex : hex;
  25622. }).join('');
  25623. return (/^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/.test(convertedColor) ? convertedColor : null
  25624. );
  25625. } else {
  25626. return null;
  25627. }
  25628. };
  25629. var namedColors = exports.namedColors = _namedColors;
  25630. var getHexColor = exports.getHexColor = _getHexColor;
  25631. var detectColorsFromHTMLString = exports.detectColorsFromHTMLString = function detectColorsFromHTMLString(html) {
  25632. return typeof html !== 'string' ? [] : (html.match(/color:[^;]{3,24};/g) || []).map(getHexColor).filter(function (color) {
  25633. return color;
  25634. });
  25635. };
  25636. var detectColorsFromDraftState = exports.detectColorsFromDraftState = function detectColorsFromDraftState(draftState) {
  25637. var result = [];
  25638. if (!draftState || !draftState.blocks || !draftState.blocks.length) {
  25639. return result;
  25640. }
  25641. draftState.blocks.forEach(function (block) {
  25642. if (block && block.inlineStyleRanges && block.inlineStyleRanges.length) {
  25643. block.inlineStyleRanges.forEach(function (inlineStyle) {
  25644. if (inlineStyle.style && inlineStyle.style.indexOf('COLOR-') >= 0) {
  25645. result.push('#' + inlineStyle.style.split('COLOR-')[1]);
  25646. }
  25647. });
  25648. }
  25649. });
  25650. return result.filter(function (color) {
  25651. return color;
  25652. });
  25653. };
  25654. });
  25655. unwrapExports(color);
  25656. var color_1 = color.namedColors;
  25657. var color_2 = color.getHexColor;
  25658. var color_3 = color.detectColorsFromHTMLString;
  25659. var color_4 = color.detectColorsFromDraftState;
  25660. var dist$1 = createCommonjsModule(function (module, exports) {
  25661. Object.defineProperty(exports, "__esModule", {
  25662. value: true
  25663. });
  25664. exports.ColorUtils = exports.BaseUtils = exports.ContentUtils = undefined;
  25665. var _ContentUtils = _interopRequireWildcard(content);
  25666. var _BaseUtils = _interopRequireWildcard(base);
  25667. var _ColorUtils = _interopRequireWildcard(color);
  25668. 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; } }
  25669. var ContentUtils = exports.ContentUtils = _ContentUtils;
  25670. var BaseUtils = exports.BaseUtils = _BaseUtils;
  25671. var ColorUtils = exports.ColorUtils = _ColorUtils;
  25672. });
  25673. unwrapExports(dist$1);
  25674. var dist_1$1 = dist$1.ColorUtils;
  25675. var dist_2$1 = dist$1.BaseUtils;
  25676. var dist_3$1 = dist$1.ContentUtils;
  25677. var dist$2 = createCommonjsModule(function (module, exports) {
  25678. (function webpackUniversalModuleDefinition(root, factory) {
  25679. module.exports = factory(React);
  25680. })(window, function(__WEBPACK_EXTERNAL_MODULE__2__) {
  25681. return /******/ (function(modules) { // webpackBootstrap
  25682. /******/ // The module cache
  25683. /******/ var installedModules = {};
  25684. /******/
  25685. /******/ // The require function
  25686. /******/ function __webpack_require__(moduleId) {
  25687. /******/
  25688. /******/ // Check if module is in cache
  25689. /******/ if(installedModules[moduleId]) {
  25690. /******/ return installedModules[moduleId].exports;
  25691. /******/ }
  25692. /******/ // Create a new module (and put it into the cache)
  25693. /******/ var module = installedModules[moduleId] = {
  25694. /******/ i: moduleId,
  25695. /******/ l: false,
  25696. /******/ exports: {}
  25697. /******/ };
  25698. /******/
  25699. /******/ // Execute the module function
  25700. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  25701. /******/
  25702. /******/ // Flag the module as loaded
  25703. /******/ module.l = true;
  25704. /******/
  25705. /******/ // Return the exports of the module
  25706. /******/ return module.exports;
  25707. /******/ }
  25708. /******/
  25709. /******/
  25710. /******/ // expose the modules object (__webpack_modules__)
  25711. /******/ __webpack_require__.m = modules;
  25712. /******/
  25713. /******/ // expose the module cache
  25714. /******/ __webpack_require__.c = installedModules;
  25715. /******/
  25716. /******/ // define getter function for harmony exports
  25717. /******/ __webpack_require__.d = function(exports, name, getter) {
  25718. /******/ if(!__webpack_require__.o(exports, name)) {
  25719. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  25720. /******/ }
  25721. /******/ };
  25722. /******/
  25723. /******/ // define __esModule on exports
  25724. /******/ __webpack_require__.r = function(exports) {
  25725. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  25726. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  25727. /******/ }
  25728. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  25729. /******/ };
  25730. /******/
  25731. /******/ // create a fake namespace object
  25732. /******/ // mode & 1: value is a module id, require it
  25733. /******/ // mode & 2: merge all properties of value into the ns
  25734. /******/ // mode & 4: return value when already ns object
  25735. /******/ // mode & 8|1: behave like require
  25736. /******/ __webpack_require__.t = function(value, mode) {
  25737. /******/ if(mode & 1) value = __webpack_require__(value);
  25738. /******/ if(mode & 8) return value;
  25739. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  25740. /******/ var ns = Object.create(null);
  25741. /******/ __webpack_require__.r(ns);
  25742. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  25743. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  25744. /******/ return ns;
  25745. /******/ };
  25746. /******/
  25747. /******/ // getDefaultExport function for compatibility with non-harmony modules
  25748. /******/ __webpack_require__.n = function(module) {
  25749. /******/ var getter = module && module.__esModule ?
  25750. /******/ function getDefault() { return module['default']; } :
  25751. /******/ function getModuleExports() { return module; };
  25752. /******/ __webpack_require__.d(getter, 'a', getter);
  25753. /******/ return getter;
  25754. /******/ };
  25755. /******/
  25756. /******/ // Object.prototype.hasOwnProperty.call
  25757. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  25758. /******/
  25759. /******/ // __webpack_public_path__
  25760. /******/ __webpack_require__.p = "/";
  25761. /******/
  25762. /******/
  25763. /******/ // Load entry module and return exports
  25764. /******/ return __webpack_require__(__webpack_require__.s = 20);
  25765. /******/ })
  25766. /************************************************************************/
  25767. /******/ ([
  25768. /* 0 */
  25769. /***/ (function(module, exports, __webpack_require__) {
  25770. Object.defineProperty(exports, "__esModule", {
  25771. value: true
  25772. });
  25773. var compressImage = exports.compressImage = function compressImage(url) {
  25774. var width = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1280;
  25775. var height = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 800;
  25776. return new Promise(function (resolve, reject) {
  25777. var image = new Image();
  25778. image.src = url;
  25779. image.onerror = function (error) {
  25780. reject(error);
  25781. };
  25782. image.onload = function () {
  25783. try {
  25784. var compressCanvas = document.createElement('canvas');
  25785. var scale = this.width > width || this.height > height ? this.width > this.height ? width / this.width : height / this.height : 1;
  25786. compressCanvas.width = this.width * scale;
  25787. compressCanvas.height = this.height * scale;
  25788. var canvasContext = compressCanvas.getContext('2d');
  25789. canvasContext.drawImage(this, 0, 0, compressCanvas.width, compressCanvas.height);
  25790. resolve({
  25791. url: compressCanvas.toDataURL('image/png', 1),
  25792. width: compressCanvas.width,
  25793. height: compressCanvas.height
  25794. });
  25795. } catch (error) {
  25796. reject(error);
  25797. }
  25798. };
  25799. });
  25800. };
  25801. /***/ }),
  25802. /* 1 */
  25803. /***/ (function(module, exports, __webpack_require__) {
  25804. Object.defineProperty(exports, "__esModule", {
  25805. value: true
  25806. });
  25807. var UniqueIndex = exports.UniqueIndex = function UniqueIndex() {
  25808. if (isNaN(window.__BRAFT_MM_UNIQUE_INDEX__)) {
  25809. window.__BRAFT_MM_UNIQUE_INDEX__ = 1;
  25810. } else {
  25811. window.__BRAFT_MM_UNIQUE_INDEX__ += 1;
  25812. }
  25813. return window.__BRAFT_MM_UNIQUE_INDEX__;
  25814. };
  25815. /***/ }),
  25816. /* 2 */
  25817. /***/ (function(module, exports) {
  25818. module.exports = __WEBPACK_EXTERNAL_MODULE__2__;
  25819. /***/ }),
  25820. /* 3 */
  25821. /***/ (function(module, exports, __webpack_require__) {
  25822. Object.defineProperty(exports, "__esModule", {
  25823. value: true
  25824. });
  25825. exports.default = {
  25826. remove: 'Kaldır',
  25827. cancel: 'İptal',
  25828. confirm: 'Onayla',
  25829. insert: 'Seçilenleri ekle',
  25830. width: 'Genişlik',
  25831. height: 'Yükseklik',
  25832. image: 'Resim',
  25833. video: 'Görüntü',
  25834. audio: 'Ses',
  25835. embed: 'Nesne göm',
  25836. caption: 'Kitaplık',
  25837. dragTip: 'Tıkla ya da dosya sürükle',
  25838. dropTip: 'Yüklemek için sürükleyin',
  25839. selectAll: 'Tümünü seç',
  25840. deselect: 'Seçimi kaldır',
  25841. removeSelected: 'Seçilenleri kaldır',
  25842. externalInputPlaceHolder: 'Kaynak adı|Kaynak bağlantısı',
  25843. externalInputTip: 'Kaynak asını ve bağlantısını "|" ile ayırın ve Enter\' a basın.',
  25844. addLocalFile: 'Yerel\' den ekle',
  25845. addExternalSource: 'Harici kaynaktan ekle',
  25846. unnamedItem: 'Adlandırılmamış giriş',
  25847. confirmInsert: 'Seçilenleri ekle'
  25848. };
  25849. /***/ }),
  25850. /* 4 */
  25851. /***/ (function(module, exports, __webpack_require__) {
  25852. Object.defineProperty(exports, "__esModule", {
  25853. value: true
  25854. });
  25855. exports.default = {
  25856. remove: '削除する',
  25857. cancel: 'キャンセル',
  25858. confirm: '確認する',
  25859. insert: '選択したアイテムを挿入',
  25860. width: '幅',
  25861. height: '身長',
  25862. image: '絵',
  25863. video: 'ビデオ',
  25864. audio: '音声',
  25865. embed: '埋め込みメディア',
  25866. caption: 'メディアライブラリー',
  25867. dragTip: 'ファイルをこの位置までクリックまたはドラッグします',
  25868. dropTip: 'アップロードするマウスを放します',
  25869. selectAll: 'すべて選択',
  25870. deselect: '選択を解除',
  25871. removeSelected: '選択したアイテムを削除',
  25872. externalInputPlaceHolder: 'リソース名|リソースアドレス',
  25873. externalInputTip: 'リソース名とリソースアドレスは "|"で区切ります。',
  25874. addLocalFile: 'ローカルリソースを追加する',
  25875. addExternalSource: 'ネットワークリソースを追加する',
  25876. unnamedItem: '名前のないアイテム',
  25877. confirmInsert: '選択したアイテムを挿入'
  25878. };
  25879. /***/ }),
  25880. /* 5 */
  25881. /***/ (function(module, exports, __webpack_require__) {
  25882. Object.defineProperty(exports, "__esModule", {
  25883. value: true
  25884. });
  25885. exports.default = {
  25886. remove: '삭제',
  25887. cancel: '취소',
  25888. confirm: '확인',
  25889. insert: '선택한항목삽입',
  25890. width: '너비',
  25891. height: '높이',
  25892. image: '그림',
  25893. video: '비디오',
  25894. audio: '오디오',
  25895. embed: '임베디드미디어',
  25896. caption: '미디어라이브러리',
  25897. dragTip: '파일을 클릭하거나이 지점으로 드래그하십시오.',
  25898. dropTip: '업로드하려면마우스를놓으십시오.',
  25899. selectAll: '모두 선택',
  25900. deselect: '선택 취소',
  25901. removeSelected: '선택한 항목 삭제',
  25902. externalInputPlaceHolder: '리소스 이름 | 리소스 주소',
  25903. externalInputTip: '자원 이름과 자원 주소를 "|"',
  25904. addLocalFile: '로컬 리소스 추가',
  25905. addExternalSource: '네트워크 리소스 추가',
  25906. unnamedItem: '이름없는 항목',
  25907. confirmInsert: '선택한 항목 삽입'
  25908. };
  25909. /***/ }),
  25910. /* 6 */
  25911. /***/ (function(module, exports, __webpack_require__) {
  25912. Object.defineProperty(exports, "__esModule", {
  25913. value: true
  25914. });
  25915. exports.default = {
  25916. remove: 'Usuń',
  25917. cancel: 'Anuluj',
  25918. confirm: 'Potwierdź',
  25919. insert: 'Wstaw wybrane elementy',
  25920. width: 'Szerokość',
  25921. height: 'Wysokość',
  25922. image: 'Obraz',
  25923. video: 'Wideo',
  25924. audio: 'Dźwięk',
  25925. embed: 'Obiekt',
  25926. caption: 'Biblioteka mediów',
  25927. dragTip: 'Kliknij lub przenieś tu pliki',
  25928. dropTip: 'Upuść aby dodać plik',
  25929. selectAll: 'Zaznacz wszystko',
  25930. deselect: 'Odznacz',
  25931. removeSelected: 'Usuń wybrane',
  25932. externalInputPlaceHolder: 'Nazwa źródła|Adres URL',
  25933. externalInputTip: 'Oddziel nazwę i adres URL źródła z pomocą "|", Potwierdź Enter-em',
  25934. addLocalFile: 'Dodaj z komputera',
  25935. addExternalSource: 'Dodaj z Internetu',
  25936. unnamedItem: 'Bez nazwy',
  25937. confirmInsert: 'Dodaj wybrane elementy'
  25938. };
  25939. /***/ }),
  25940. /* 7 */
  25941. /***/ (function(module, exports, __webpack_require__) {
  25942. Object.defineProperty(exports, "__esModule", {
  25943. value: true
  25944. });
  25945. exports.default = {
  25946. remove: '删除',
  25947. cancel: '取消',
  25948. confirm: '确认',
  25949. insert: '插入所选项目',
  25950. width: '宽度',
  25951. height: '高度',
  25952. image: '图片',
  25953. video: '视频',
  25954. audio: '音频',
  25955. embed: '嵌入式媒体',
  25956. caption: '媒体库',
  25957. dragTip: '点击或拖动文件至此',
  25958. dropTip: '放开鼠标以上传',
  25959. selectAll: '选择全部',
  25960. deselect: '取消选择',
  25961. removeSelected: '删除选中项目',
  25962. externalInputPlaceHolder: '资源名称|资源地址',
  25963. externalInputTip: '使用“|”分隔资源名称和资源地址',
  25964. addLocalFile: '添加本地资源',
  25965. addExternalSource: '添加网络资源',
  25966. unnamedItem: '未命名项目',
  25967. confirmInsert: '插入选中项目'
  25968. };
  25969. /***/ }),
  25970. /* 8 */
  25971. /***/ (function(module, exports, __webpack_require__) {
  25972. Object.defineProperty(exports, "__esModule", {
  25973. value: true
  25974. });
  25975. exports.default = {
  25976. remove: '删除',
  25977. cancel: '取消',
  25978. confirm: '确认',
  25979. insert: '插入所选项目',
  25980. width: '宽度',
  25981. height: '高度',
  25982. image: '图片',
  25983. video: '视频',
  25984. audio: '音频',
  25985. embed: '嵌入式媒体',
  25986. caption: '媒体库',
  25987. dragTip: '点击或拖动文件至此',
  25988. dropTip: '放开鼠标以上传',
  25989. selectAll: '选择全部',
  25990. deselect: '取消选择',
  25991. removeSelected: '删除选中项目',
  25992. externalInputPlaceHolder: '资源名称|资源地址',
  25993. externalInputTip: '使用“|”分隔资源名称和资源地址',
  25994. addLocalFile: '添加本地资源',
  25995. addExternalSource: '添加网络资源',
  25996. unnamedItem: '未命名项目',
  25997. confirmInsert: '插入选中项目'
  25998. };
  25999. /***/ }),
  26000. /* 9 */
  26001. /***/ (function(module, exports, __webpack_require__) {
  26002. Object.defineProperty(exports, "__esModule", {
  26003. value: true
  26004. });
  26005. exports.default = {
  26006. remove: 'Remove',
  26007. cancel: 'Cancel',
  26008. confirm: 'Confirm',
  26009. insert: 'Insert Selected Items',
  26010. width: 'Width',
  26011. height: 'Height',
  26012. image: 'Image',
  26013. video: 'Video',
  26014. audio: 'Audio',
  26015. embed: 'Embed',
  26016. caption: 'Media Library',
  26017. dragTip: 'Click Or Drag Files Here',
  26018. dropTip: 'Drop To Upload',
  26019. selectAll: 'Select All',
  26020. deselect: 'Deselect',
  26021. removeSelected: 'Remove Selected Items',
  26022. externalInputPlaceHolder: 'Source Name|Source URL',
  26023. externalInputTip: 'Split source name and source URL with "|", confirm by hit Enter.',
  26024. addLocalFile: 'Add from local',
  26025. addExternalSource: 'Add from Internet',
  26026. unnamedItem: 'Unnamed Item',
  26027. confirmInsert: 'Insert selected items'
  26028. };
  26029. /***/ }),
  26030. /* 10 */
  26031. /***/ (function(module, exports, __webpack_require__) {
  26032. Object.defineProperty(exports, "__esModule", {
  26033. value: true
  26034. });
  26035. var _en = __webpack_require__(9);
  26036. var _en2 = _interopRequireDefault(_en);
  26037. var _zh = __webpack_require__(8);
  26038. var _zh2 = _interopRequireDefault(_zh);
  26039. var _zhHant = __webpack_require__(7);
  26040. var _zhHant2 = _interopRequireDefault(_zhHant);
  26041. var _pl = __webpack_require__(6);
  26042. var _pl2 = _interopRequireDefault(_pl);
  26043. var _kr = __webpack_require__(5);
  26044. var _kr2 = _interopRequireDefault(_kr);
  26045. var _jpn = __webpack_require__(4);
  26046. var _jpn2 = _interopRequireDefault(_jpn);
  26047. var _tr = __webpack_require__(3);
  26048. var _tr2 = _interopRequireDefault(_tr);
  26049. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  26050. exports.default = {
  26051. "en": _en2.default,
  26052. "zh": _zh2.default,
  26053. "zh-hant": _zhHant2.default,
  26054. "pl": _pl2.default,
  26055. "kr": _kr2.default,
  26056. "jpn": _jpn2.default,
  26057. "tr": _tr2.default
  26058. };
  26059. /***/ }),
  26060. /* 11 */
  26061. /***/ (function(module, exports) {
  26062. /**
  26063. * When source maps are enabled, `style-loader` uses a link element with a data-uri to
  26064. * embed the css on the page. This breaks all relative urls because now they are relative to a
  26065. * bundle instead of the current page.
  26066. *
  26067. * One solution is to only use full urls, but that may be impossible.
  26068. *
  26069. * Instead, this function "fixes" the relative urls to be absolute according to the current page location.
  26070. *
  26071. * A rudimentary test suite is located at `test/fixUrls.js` and can be run via the `npm test` command.
  26072. *
  26073. */
  26074. module.exports = function (css) {
  26075. // get current location
  26076. var location = typeof window !== "undefined" && window.location;
  26077. if (!location) {
  26078. throw new Error("fixUrls requires window.location");
  26079. }
  26080. // blank or null?
  26081. if (!css || typeof css !== "string") {
  26082. return css;
  26083. }
  26084. var baseUrl = location.protocol + "//" + location.host;
  26085. var currentDir = baseUrl + location.pathname.replace(/\/[^\/]*$/, "/");
  26086. // convert each url(...)
  26087. /*
  26088. This regular expression is just a way to recursively match brackets within
  26089. a string.
  26090. /url\s*\( = Match on the word "url" with any whitespace after it and then a parens
  26091. ( = Start a capturing group
  26092. (?: = Start a non-capturing group
  26093. [^)(] = Match anything that isn't a parentheses
  26094. | = OR
  26095. \( = Match a start parentheses
  26096. (?: = Start another non-capturing groups
  26097. [^)(]+ = Match anything that isn't a parentheses
  26098. | = OR
  26099. \( = Match a start parentheses
  26100. [^)(]* = Match anything that isn't a parentheses
  26101. \) = Match a end parentheses
  26102. ) = End Group
  26103. *\) = Match anything and then a close parens
  26104. ) = Close non-capturing group
  26105. * = Match anything
  26106. ) = Close capturing group
  26107. \) = Match a close parens
  26108. /gi = Get all matches, not the first. Be case insensitive.
  26109. */
  26110. var fixedCss = css.replace(/url\s*\(((?:[^)(]|\((?:[^)(]+|\([^)(]*\))*\))*)\)/gi, function(fullMatch, origUrl) {
  26111. // strip quotes (if they exist)
  26112. var unquotedOrigUrl = origUrl
  26113. .trim()
  26114. .replace(/^"(.*)"$/, function(o, $1){ return $1; })
  26115. .replace(/^'(.*)'$/, function(o, $1){ return $1; });
  26116. // already a full url? no change
  26117. if (/^(#|data:|http:\/\/|https:\/\/|file:\/\/\/|\s*$)/i.test(unquotedOrigUrl)) {
  26118. return fullMatch;
  26119. }
  26120. // convert the url to a full url
  26121. var newUrl;
  26122. if (unquotedOrigUrl.indexOf("//") === 0) {
  26123. //TODO: should we add protocol?
  26124. newUrl = unquotedOrigUrl;
  26125. } else if (unquotedOrigUrl.indexOf("/") === 0) {
  26126. // path should be relative to the base url
  26127. newUrl = baseUrl + unquotedOrigUrl; // already starts with '/'
  26128. } else {
  26129. // path should be relative to current directory
  26130. newUrl = currentDir + unquotedOrigUrl.replace(/^\.\//, ""); // Strip leading './'
  26131. }
  26132. // send back the fixed url(...)
  26133. return "url(" + JSON.stringify(newUrl) + ")";
  26134. });
  26135. // send back the fixed css
  26136. return fixedCss;
  26137. };
  26138. /***/ }),
  26139. /* 12 */
  26140. /***/ (function(module, exports, __webpack_require__) {
  26141. /*
  26142. MIT License http://www.opensource.org/licenses/mit-license.php
  26143. Author Tobias Koppers @sokra
  26144. */
  26145. var stylesInDom = {};
  26146. var memoize = function (fn) {
  26147. var memo;
  26148. return function () {
  26149. if (typeof memo === "undefined") memo = fn.apply(this, arguments);
  26150. return memo;
  26151. };
  26152. };
  26153. var isOldIE = memoize(function () {
  26154. // Test for IE <= 9 as proposed by Browserhacks
  26155. // @see http://browserhacks.com/#hack-e71d8692f65334173fee715c222cb805
  26156. // Tests for existence of standard globals is to allow style-loader
  26157. // to operate correctly into non-standard environments
  26158. // @see https://github.com/webpack-contrib/style-loader/issues/177
  26159. return window && document && document.all && !window.atob;
  26160. });
  26161. var getTarget = function (target) {
  26162. return document.querySelector(target);
  26163. };
  26164. var getElement = (function (fn) {
  26165. var memo = {};
  26166. return function(target) {
  26167. // If passing function in options, then use it for resolve "head" element.
  26168. // Useful for Shadow Root style i.e
  26169. // {
  26170. // insertInto: function () { return document.querySelector("#foo").shadowRoot }
  26171. // }
  26172. if (typeof target === 'function') {
  26173. return target();
  26174. }
  26175. if (typeof memo[target] === "undefined") {
  26176. var styleTarget = getTarget.call(this, target);
  26177. // Special case to return head of iframe instead of iframe itself
  26178. if (window.HTMLIFrameElement && styleTarget instanceof window.HTMLIFrameElement) {
  26179. try {
  26180. // This will throw an exception if access to iframe is blocked
  26181. // due to cross-origin restrictions
  26182. styleTarget = styleTarget.contentDocument.head;
  26183. } catch(e) {
  26184. styleTarget = null;
  26185. }
  26186. }
  26187. memo[target] = styleTarget;
  26188. }
  26189. return memo[target]
  26190. };
  26191. })();
  26192. var singleton = null;
  26193. var singletonCounter = 0;
  26194. var stylesInsertedAtTop = [];
  26195. var fixUrls = __webpack_require__(11);
  26196. module.exports = function(list, options) {
  26197. if (typeof DEBUG !== "undefined" && DEBUG) {
  26198. if (typeof document !== "object") throw new Error("The style-loader cannot be used in a non-browser environment");
  26199. }
  26200. options = options || {};
  26201. options.attrs = typeof options.attrs === "object" ? options.attrs : {};
  26202. // Force single-tag solution on IE6-9, which has a hard limit on the # of <style>
  26203. // tags it will allow on a page
  26204. if (!options.singleton && typeof options.singleton !== "boolean") options.singleton = isOldIE();
  26205. // By default, add <style> tags to the <head> element
  26206. if (!options.insertInto) options.insertInto = "head";
  26207. // By default, add <style> tags to the bottom of the target
  26208. if (!options.insertAt) options.insertAt = "bottom";
  26209. var styles = listToStyles(list, options);
  26210. addStylesToDom(styles, options);
  26211. return function update (newList) {
  26212. var mayRemove = [];
  26213. for (var i = 0; i < styles.length; i++) {
  26214. var item = styles[i];
  26215. var domStyle = stylesInDom[item.id];
  26216. domStyle.refs--;
  26217. mayRemove.push(domStyle);
  26218. }
  26219. if(newList) {
  26220. var newStyles = listToStyles(newList, options);
  26221. addStylesToDom(newStyles, options);
  26222. }
  26223. for (var i = 0; i < mayRemove.length; i++) {
  26224. var domStyle = mayRemove[i];
  26225. if(domStyle.refs === 0) {
  26226. for (var j = 0; j < domStyle.parts.length; j++) domStyle.parts[j]();
  26227. delete stylesInDom[domStyle.id];
  26228. }
  26229. }
  26230. };
  26231. };
  26232. function addStylesToDom (styles, options) {
  26233. for (var i = 0; i < styles.length; i++) {
  26234. var item = styles[i];
  26235. var domStyle = stylesInDom[item.id];
  26236. if(domStyle) {
  26237. domStyle.refs++;
  26238. for(var j = 0; j < domStyle.parts.length; j++) {
  26239. domStyle.parts[j](item.parts[j]);
  26240. }
  26241. for(; j < item.parts.length; j++) {
  26242. domStyle.parts.push(addStyle(item.parts[j], options));
  26243. }
  26244. } else {
  26245. var parts = [];
  26246. for(var j = 0; j < item.parts.length; j++) {
  26247. parts.push(addStyle(item.parts[j], options));
  26248. }
  26249. stylesInDom[item.id] = {id: item.id, refs: 1, parts: parts};
  26250. }
  26251. }
  26252. }
  26253. function listToStyles (list, options) {
  26254. var styles = [];
  26255. var newStyles = {};
  26256. for (var i = 0; i < list.length; i++) {
  26257. var item = list[i];
  26258. var id = options.base ? item[0] + options.base : item[0];
  26259. var css = item[1];
  26260. var media = item[2];
  26261. var sourceMap = item[3];
  26262. var part = {css: css, media: media, sourceMap: sourceMap};
  26263. if(!newStyles[id]) styles.push(newStyles[id] = {id: id, parts: [part]});
  26264. else newStyles[id].parts.push(part);
  26265. }
  26266. return styles;
  26267. }
  26268. function insertStyleElement (options, style) {
  26269. var target = getElement(options.insertInto);
  26270. if (!target) {
  26271. throw new Error("Couldn't find a style target. This probably means that the value for the 'insertInto' parameter is invalid.");
  26272. }
  26273. var lastStyleElementInsertedAtTop = stylesInsertedAtTop[stylesInsertedAtTop.length - 1];
  26274. if (options.insertAt === "top") {
  26275. if (!lastStyleElementInsertedAtTop) {
  26276. target.insertBefore(style, target.firstChild);
  26277. } else if (lastStyleElementInsertedAtTop.nextSibling) {
  26278. target.insertBefore(style, lastStyleElementInsertedAtTop.nextSibling);
  26279. } else {
  26280. target.appendChild(style);
  26281. }
  26282. stylesInsertedAtTop.push(style);
  26283. } else if (options.insertAt === "bottom") {
  26284. target.appendChild(style);
  26285. } else if (typeof options.insertAt === "object" && options.insertAt.before) {
  26286. var nextSibling = getElement(options.insertInto + " " + options.insertAt.before);
  26287. target.insertBefore(style, nextSibling);
  26288. } else {
  26289. 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");
  26290. }
  26291. }
  26292. function removeStyleElement (style) {
  26293. if (style.parentNode === null) return false;
  26294. style.parentNode.removeChild(style);
  26295. var idx = stylesInsertedAtTop.indexOf(style);
  26296. if(idx >= 0) {
  26297. stylesInsertedAtTop.splice(idx, 1);
  26298. }
  26299. }
  26300. function createStyleElement (options) {
  26301. var style = document.createElement("style");
  26302. if(options.attrs.type === undefined) {
  26303. options.attrs.type = "text/css";
  26304. }
  26305. addAttrs(style, options.attrs);
  26306. insertStyleElement(options, style);
  26307. return style;
  26308. }
  26309. function createLinkElement (options) {
  26310. var link = document.createElement("link");
  26311. if(options.attrs.type === undefined) {
  26312. options.attrs.type = "text/css";
  26313. }
  26314. options.attrs.rel = "stylesheet";
  26315. addAttrs(link, options.attrs);
  26316. insertStyleElement(options, link);
  26317. return link;
  26318. }
  26319. function addAttrs (el, attrs) {
  26320. Object.keys(attrs).forEach(function (key) {
  26321. el.setAttribute(key, attrs[key]);
  26322. });
  26323. }
  26324. function addStyle (obj, options) {
  26325. var style, update, remove, result;
  26326. // If a transform function was defined, run it on the css
  26327. if (options.transform && obj.css) {
  26328. result = options.transform(obj.css);
  26329. if (result) {
  26330. // If transform returns a value, use that instead of the original css.
  26331. // This allows running runtime transformations on the css.
  26332. obj.css = result;
  26333. } else {
  26334. // If the transform function returns a falsy value, don't add this css.
  26335. // This allows conditional loading of css
  26336. return function() {
  26337. // noop
  26338. };
  26339. }
  26340. }
  26341. if (options.singleton) {
  26342. var styleIndex = singletonCounter++;
  26343. style = singleton || (singleton = createStyleElement(options));
  26344. update = applyToSingletonTag.bind(null, style, styleIndex, false);
  26345. remove = applyToSingletonTag.bind(null, style, styleIndex, true);
  26346. } else if (
  26347. obj.sourceMap &&
  26348. typeof URL === "function" &&
  26349. typeof URL.createObjectURL === "function" &&
  26350. typeof URL.revokeObjectURL === "function" &&
  26351. typeof Blob === "function" &&
  26352. typeof btoa === "function"
  26353. ) {
  26354. style = createLinkElement(options);
  26355. update = updateLink.bind(null, style, options);
  26356. remove = function () {
  26357. removeStyleElement(style);
  26358. if(style.href) URL.revokeObjectURL(style.href);
  26359. };
  26360. } else {
  26361. style = createStyleElement(options);
  26362. update = applyToTag.bind(null, style);
  26363. remove = function () {
  26364. removeStyleElement(style);
  26365. };
  26366. }
  26367. update(obj);
  26368. return function updateStyle (newObj) {
  26369. if (newObj) {
  26370. if (
  26371. newObj.css === obj.css &&
  26372. newObj.media === obj.media &&
  26373. newObj.sourceMap === obj.sourceMap
  26374. ) {
  26375. return;
  26376. }
  26377. update(obj = newObj);
  26378. } else {
  26379. remove();
  26380. }
  26381. };
  26382. }
  26383. var replaceText = (function () {
  26384. var textStore = [];
  26385. return function (index, replacement) {
  26386. textStore[index] = replacement;
  26387. return textStore.filter(Boolean).join('\n');
  26388. };
  26389. })();
  26390. function applyToSingletonTag (style, index, remove, obj) {
  26391. var css = remove ? "" : obj.css;
  26392. if (style.styleSheet) {
  26393. style.styleSheet.cssText = replaceText(index, css);
  26394. } else {
  26395. var cssNode = document.createTextNode(css);
  26396. var childNodes = style.childNodes;
  26397. if (childNodes[index]) style.removeChild(childNodes[index]);
  26398. if (childNodes.length) {
  26399. style.insertBefore(cssNode, childNodes[index]);
  26400. } else {
  26401. style.appendChild(cssNode);
  26402. }
  26403. }
  26404. }
  26405. function applyToTag (style, obj) {
  26406. var css = obj.css;
  26407. var media = obj.media;
  26408. if(media) {
  26409. style.setAttribute("media", media);
  26410. }
  26411. if(style.styleSheet) {
  26412. style.styleSheet.cssText = css;
  26413. } else {
  26414. while(style.firstChild) {
  26415. style.removeChild(style.firstChild);
  26416. }
  26417. style.appendChild(document.createTextNode(css));
  26418. }
  26419. }
  26420. function updateLink (link, options, obj) {
  26421. var css = obj.css;
  26422. var sourceMap = obj.sourceMap;
  26423. /*
  26424. If convertToAbsoluteUrls isn't defined, but sourcemaps are enabled
  26425. and there is no publicPath defined then lets turn convertToAbsoluteUrls
  26426. on by default. Otherwise default to the convertToAbsoluteUrls option
  26427. directly
  26428. */
  26429. var autoFixUrls = options.convertToAbsoluteUrls === undefined && sourceMap;
  26430. if (options.convertToAbsoluteUrls || autoFixUrls) {
  26431. css = fixUrls(css);
  26432. }
  26433. if (sourceMap) {
  26434. // http://stackoverflow.com/a/26603875
  26435. css += "\n/*# sourceMappingURL=data:application/json;base64," + btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap)))) + " */";
  26436. }
  26437. var blob = new Blob([css], { type: "text/css" });
  26438. var oldSrc = link.href;
  26439. link.href = URL.createObjectURL(blob);
  26440. if(oldSrc) URL.revokeObjectURL(oldSrc);
  26441. }
  26442. /***/ }),
  26443. /* 13 */
  26444. /***/ (function(module, exports) {
  26445. 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=";
  26446. /***/ }),
  26447. /* 14 */
  26448. /***/ (function(module, exports) {
  26449. /*
  26450. MIT License http://www.opensource.org/licenses/mit-license.php
  26451. Author Tobias Koppers @sokra
  26452. */
  26453. // css base code, injected by the css-loader
  26454. module.exports = function(useSourceMap) {
  26455. var list = [];
  26456. // return the list of modules as css string
  26457. list.toString = function toString() {
  26458. return this.map(function (item) {
  26459. var content = cssWithMappingToString(item, useSourceMap);
  26460. if(item[2]) {
  26461. return "@media " + item[2] + "{" + content + "}";
  26462. } else {
  26463. return content;
  26464. }
  26465. }).join("");
  26466. };
  26467. // import a list of modules into the list
  26468. list.i = function(modules, mediaQuery) {
  26469. if(typeof modules === "string")
  26470. modules = [[null, modules, ""]];
  26471. var alreadyImportedModules = {};
  26472. for(var i = 0; i < this.length; i++) {
  26473. var id = this[i][0];
  26474. if(typeof id === "number")
  26475. alreadyImportedModules[id] = true;
  26476. }
  26477. for(i = 0; i < modules.length; i++) {
  26478. var item = modules[i];
  26479. // skip already imported module
  26480. // this implementation is not 100% perfect for weird media query combinations
  26481. // when a module is imported multiple times with different media queries.
  26482. // I hope this will never occur (Hey this way we have smaller bundles)
  26483. if(typeof item[0] !== "number" || !alreadyImportedModules[item[0]]) {
  26484. if(mediaQuery && !item[2]) {
  26485. item[2] = mediaQuery;
  26486. } else if(mediaQuery) {
  26487. item[2] = "(" + item[2] + ") and (" + mediaQuery + ")";
  26488. }
  26489. list.push(item);
  26490. }
  26491. }
  26492. };
  26493. return list;
  26494. };
  26495. function cssWithMappingToString(item, useSourceMap) {
  26496. var content = item[1] || '';
  26497. var cssMapping = item[3];
  26498. if (!cssMapping) {
  26499. return content;
  26500. }
  26501. if (useSourceMap && typeof btoa === 'function') {
  26502. var sourceMapping = toComment(cssMapping);
  26503. var sourceURLs = cssMapping.sources.map(function (source) {
  26504. return '/*# sourceURL=' + cssMapping.sourceRoot + source + ' */'
  26505. });
  26506. return [content].concat(sourceURLs).concat([sourceMapping]).join('\n');
  26507. }
  26508. return [content].join('\n');
  26509. }
  26510. // Adapted from convert-source-map (MIT)
  26511. function toComment(sourceMap) {
  26512. // eslint-disable-next-line no-undef
  26513. var base64 = btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap))));
  26514. var data = 'sourceMappingURL=data:application/json;charset=utf-8;base64,' + base64;
  26515. return '/*# ' + data + ' */';
  26516. }
  26517. /***/ }),
  26518. /* 15 */
  26519. /***/ (function(module, exports) {
  26520. module.exports = function escape(url) {
  26521. if (typeof url !== 'string') {
  26522. return url
  26523. }
  26524. // If url is already wrapped in quotes, remove them
  26525. if (/^['"].*['"]$/.test(url)) {
  26526. url = url.slice(1, -1);
  26527. }
  26528. // Should url be wrapped?
  26529. // See https://drafts.csswg.org/css-values-3/#urls
  26530. if (/["'() \t\n]/.test(url)) {
  26531. return '"' + url.replace(/"/g, '\\"').replace(/\n/g, '\\n') + '"'
  26532. }
  26533. return url
  26534. };
  26535. /***/ }),
  26536. /* 16 */
  26537. /***/ (function(module, exports, __webpack_require__) {
  26538. var escape = __webpack_require__(15);
  26539. exports = module.exports = __webpack_require__(14)(false);
  26540. // imports
  26541. // module
  26542. 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", ""]);
  26543. // exports
  26544. /***/ }),
  26545. /* 17 */
  26546. /***/ (function(module, exports, __webpack_require__) {
  26547. var content = __webpack_require__(16);
  26548. if(typeof content === 'string') content = [[module.i, content, '']];
  26549. var transform;
  26550. var options = {"hmr":true};
  26551. options.transform = transform;
  26552. options.insertInto = undefined;
  26553. var update = __webpack_require__(12)(content, options);
  26554. if(content.locals) module.exports = content.locals;
  26555. /***/ }),
  26556. /* 18 */
  26557. /***/ (function(module, exports, __webpack_require__) {
  26558. Object.defineProperty(exports, "__esModule", {
  26559. value: true
  26560. });
  26561. 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; };
  26562. 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; }; }();
  26563. __webpack_require__(17);
  26564. var _react = __webpack_require__(2);
  26565. var _react2 = _interopRequireDefault(_react);
  26566. var _base = __webpack_require__(1);
  26567. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  26568. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  26569. 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; }
  26570. 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; }
  26571. var defaultAccepts = {
  26572. image: 'image/png,image/jpeg,image/gif,image/webp,image/apng,image/svg',
  26573. video: 'video/mp4',
  26574. audio: 'audio/mp3'
  26575. };
  26576. var BraftFinderView = function (_React$Component) {
  26577. _inherits(BraftFinderView, _React$Component);
  26578. function BraftFinderView(props) {
  26579. _classCallCheck(this, BraftFinderView);
  26580. var _this = _possibleConstructorReturn(this, (BraftFinderView.__proto__ || Object.getPrototypeOf(BraftFinderView)).call(this, props));
  26581. _this.toggleSelectItem = function (event) {
  26582. var itemId = event.currentTarget.dataset.id;
  26583. var item = _this.controller.getMediaItem(itemId);
  26584. if (!item) {
  26585. return false;
  26586. }
  26587. if (item.selected) {
  26588. if (!_this.props.onBeforeDeselect || _this.props.onBeforeDeselect([item], _this.controller.getItems()) !== false) {
  26589. _this.controller.deselectMediaItem(itemId);
  26590. _this.props.onDeselect && _this.props.onDeselect([item], _this.controller.getItems());
  26591. }
  26592. } else {
  26593. if (!_this.props.onBeforeSelect || _this.props.onBeforeSelect([item], _this.controller.getItems()) !== false) {
  26594. _this.controller.selectMediaItem(itemId);
  26595. _this.props.onSelect && _this.props.onSelect([item], _this.controller.getItems());
  26596. }
  26597. }
  26598. };
  26599. _this.removeItem = function (event) {
  26600. var itemId = event.currentTarget.dataset.id;
  26601. var item = _this.controller.getMediaItem(itemId);
  26602. if (!item) {
  26603. return false;
  26604. }
  26605. if (!_this.props.onBeforeRemove || _this.props.onBeforeRemove([item], _this.controller.getItems()) !== false) {
  26606. _this.controller.removeMediaItem(itemId);
  26607. _this.props.onRemove && _this.props.onRemove([item], _this.controller.getItems());
  26608. }
  26609. event.stopPropagation();
  26610. };
  26611. _this.selectAllItems = function () {
  26612. var allItems = _this.controller.getItems();
  26613. if (!_this.props.onBeforeSelect || _this.props.onBeforeSelect(allItems, allItems) !== false) {
  26614. _this.controller.selectAllItems();
  26615. _this.props.onSelect && _this.props.onSelect(allItems, allItems);
  26616. }
  26617. };
  26618. _this.deselectAllItems = function () {
  26619. var allItems = _this.controller.getItems();
  26620. if (!_this.props.onBeforeDeselect || _this.props.onBeforeDeselect(allItems, allItems) !== false) {
  26621. _this.controller.deselectAllItems();
  26622. _this.props.onDeselect && _this.props.onDeselect(allItems, allItems);
  26623. }
  26624. };
  26625. _this.removeSelectedItems = function () {
  26626. var selectedItems = _this.controller.getSelectedItems();
  26627. if (!_this.props.onBeforeRemove || _this.props.onBeforeRemove(selectedItems, _this.controller.getItems()) !== false) {
  26628. _this.controller.removeSelectedItems();
  26629. _this.props.onRemove && _this.props.onRemove(selectedItems, _this.controller.getItems());
  26630. }
  26631. };
  26632. _this.handleDragLeave = function (event) {
  26633. event.preventDefault();
  26634. _this.dragCounter--;
  26635. _this.dragCounter === 0 && _this.setState({
  26636. draging: false
  26637. });
  26638. };
  26639. _this.handleDragDrop = function (event) {
  26640. event.preventDefault();
  26641. _this.dragCounter = 0;
  26642. _this.setState({ draging: false });
  26643. _this.reslovePickedFiles(event);
  26644. };
  26645. _this.handleDragEnter = function (event) {
  26646. event.preventDefault();
  26647. _this.dragCounter++;
  26648. _this.setState({ draging: true });
  26649. };
  26650. _this.reslovePickedFiles = function (event) {
  26651. event.persist();
  26652. var _ref = event.type === 'drop' ? event.dataTransfer : event.target,
  26653. files = _ref.files;
  26654. if (_this.props.onFileSelect) {
  26655. var result = _this.props.onFileSelect(files);
  26656. if (result === false) {
  26657. return false;
  26658. } else if (result instanceof FileList || result instanceof Array) {
  26659. files = result;
  26660. }
  26661. }
  26662. var accepts = _extends({}, defaultAccepts, _this.props.accepts);
  26663. _this.controller.resolveFiles({
  26664. files: files,
  26665. onItemReady: function onItemReady(_ref2) {
  26666. var id = _ref2.id;
  26667. return _this.controller.selectMediaItem(id);
  26668. },
  26669. onAllReady: function onAllReady() {
  26670. return event.target.value = null;
  26671. }
  26672. }, 0, accepts);
  26673. };
  26674. _this.inputExternal = function (event) {
  26675. _this.setState({
  26676. external: _extends({}, _this.state.external, {
  26677. url: event.target.value
  26678. })
  26679. });
  26680. };
  26681. _this.switchExternalType = function (event) {
  26682. _this.setState({
  26683. external: _extends({}, _this.state.external, { type: event.target.dataset.type })
  26684. });
  26685. };
  26686. _this.confirmAddExternal = function (event) {
  26687. if (event.target.nodeName.toLowerCase() === 'button' || event.keyCode === 13) {
  26688. var _this$state$external = _this.state.external,
  26689. url = _this$state$external.url,
  26690. type = _this$state$external.type;
  26691. url = url.split('|');
  26692. var name = url.length > 1 ? url[0] : _this.props.language.unnamedItem;
  26693. url = url.length > 1 ? url[1] : url[0];
  26694. var thumbnail = type === 'IMAGE' ? url : null;
  26695. _this.controller.addItems([{
  26696. thumbnail: thumbnail, url: url, name: name, type: type,
  26697. id: new Date().getTime() + '_' + (0, _base.UniqueIndex)(),
  26698. uploading: false,
  26699. uploadProgress: 1,
  26700. selected: true
  26701. }]);
  26702. _this.setState({
  26703. showExternalForm: false,
  26704. external: {
  26705. url: '',
  26706. type: 'IMAGE'
  26707. }
  26708. });
  26709. }
  26710. };
  26711. _this.toggleExternalForm = function () {
  26712. _this.setState({
  26713. showExternalForm: !_this.state.showExternalForm
  26714. });
  26715. };
  26716. _this.cancelInsert = function () {
  26717. _this.props.onCancel && _this.props.onCancel();
  26718. };
  26719. _this.confirmInsert = function () {
  26720. var selectedItems = _this.controller.getSelectedItems();
  26721. if (_this.props.onBeforeInsert) {
  26722. var filteredItems = _this.props.onBeforeInsert(selectedItems);
  26723. if (filteredItems && filteredItems instanceof Array) {
  26724. _this.controller.deselectAllItems();
  26725. _this.props.onInsert && _this.props.onInsert(filteredItems);
  26726. } else if (filteredItems !== false) {
  26727. _this.controller.deselectAllItems();
  26728. _this.props.onInsert && _this.props.onInsert(selectedItems);
  26729. }
  26730. } else {
  26731. _this.controller.deselectAllItems();
  26732. _this.props.onInsert && _this.props.onInsert(selectedItems);
  26733. }
  26734. };
  26735. _this.dragCounter = 0;
  26736. _this.controller = _this.props.controller;
  26737. var initialItems = _this.controller.getItems();
  26738. _this.state = {
  26739. draging: false,
  26740. error: false,
  26741. confirmable: initialItems.find(function (_ref3) {
  26742. var selected = _ref3.selected;
  26743. return selected;
  26744. }),
  26745. external: {
  26746. url: '',
  26747. type: 'IMAGE'
  26748. },
  26749. fileAccept: '',
  26750. showExternalForm: false,
  26751. allowExternal: false,
  26752. items: initialItems
  26753. };
  26754. _this.changeListenerId = _this.controller.onChange(function (items) {
  26755. _this.setState({ items: items, confirmable: items.find(function (_ref4) {
  26756. var selected = _ref4.selected;
  26757. return selected;
  26758. }) });
  26759. _this.props.onChange && _this.props.onChange(items);
  26760. });
  26761. return _this;
  26762. }
  26763. _createClass(BraftFinderView, [{
  26764. key: 'mapPropsToState',
  26765. value: function mapPropsToState(props) {
  26766. var accepts = props.accepts,
  26767. externals = props.externals;
  26768. accepts = _extends({}, defaultAccepts, accepts);
  26769. var fileAccept = !accepts ? [defaultAccepts.image, defaultAccepts.video, defaultAccepts.audio].join(',') : [accepts.image, accepts.video, accepts.audio].filter(function (item) {
  26770. return item;
  26771. }).join(',');
  26772. var external = {
  26773. url: '',
  26774. type: externals.image ? 'IMAGE' : externals.audio ? 'AUDIO' : externals.video ? 'VIDEO' : externals.embed ? 'EMBED' : ''
  26775. };
  26776. return {
  26777. fileAccept: fileAccept,
  26778. external: external,
  26779. allowExternal: externals && (externals.image || externals.audio || externals.video || externals.embed)
  26780. };
  26781. }
  26782. }, {
  26783. key: 'componentDidMount',
  26784. value: function componentDidMount() {
  26785. this.setState(this.mapPropsToState(this.props));
  26786. }
  26787. }, {
  26788. key: 'componentWillReceiveProps',
  26789. value: function componentWillReceiveProps(nextProps) {
  26790. this.setState(this.mapPropsToState(nextProps));
  26791. }
  26792. }, {
  26793. key: 'componentWillUnmount',
  26794. value: function componentWillUnmount() {
  26795. this.controller.offChange(this.changeListenerId);
  26796. }
  26797. }, {
  26798. key: 'render',
  26799. value: function render() {
  26800. var _props = this.props,
  26801. language = _props.language,
  26802. externals = _props.externals;
  26803. var _state = this.state,
  26804. items = _state.items,
  26805. draging = _state.draging,
  26806. confirmable = _state.confirmable,
  26807. fileAccept = _state.fileAccept,
  26808. external = _state.external,
  26809. showExternalForm = _state.showExternalForm,
  26810. allowExternal = _state.allowExternal;
  26811. return _react2.default.createElement(
  26812. 'div',
  26813. { className: 'braft-finder' },
  26814. _react2.default.createElement(
  26815. 'div',
  26816. {
  26817. onDragEnter: this.handleDragEnter,
  26818. onDragOver: this.handleDragEnter,
  26819. onDragLeave: this.handleDragLeave,
  26820. onDrop: this.handleDragDrop,
  26821. className: 'bf-uploader'
  26822. },
  26823. _react2.default.createElement(
  26824. 'div',
  26825. { className: "bf-drag-uploader " + (draging || !items.length ? 'active ' : ' ') + (draging ? 'draging' : '') },
  26826. _react2.default.createElement(
  26827. 'span',
  26828. { className: 'bf-drag-tip' },
  26829. _react2.default.createElement('input', { accept: fileAccept, onChange: this.reslovePickedFiles, multiple: true, type: 'file' }),
  26830. draging ? language.dropTip : language.dragTip
  26831. )
  26832. ),
  26833. items.length ? _react2.default.createElement(
  26834. 'div',
  26835. { className: 'bf-list-wrap' },
  26836. _react2.default.createElement(
  26837. 'div',
  26838. { className: 'bf-list-tools' },
  26839. _react2.default.createElement(
  26840. 'span',
  26841. { onClick: this.selectAllItems, className: 'bf-select-all' },
  26842. _react2.default.createElement('i', { className: 'braft-icon-done' }),
  26843. ' ',
  26844. language.selectAll
  26845. ),
  26846. _react2.default.createElement(
  26847. 'span',
  26848. { onClick: this.deselectAllItems, disabled: !confirmable, className: 'bf-deselect-all' },
  26849. _react2.default.createElement('i', { className: 'braft-icon-close' }),
  26850. ' ',
  26851. language.deselect
  26852. ),
  26853. _react2.default.createElement(
  26854. 'span',
  26855. { onClick: this.removeSelectedItems, disabled: !confirmable, className: 'bf-remove-selected' },
  26856. _react2.default.createElement('i', { className: 'braft-icon-bin' }),
  26857. ' ',
  26858. language.removeSelected
  26859. )
  26860. ),
  26861. this.buildItemList()
  26862. ) : null,
  26863. showExternalForm && allowExternal ? _react2.default.createElement(
  26864. 'div',
  26865. { className: 'bf-add-external' },
  26866. _react2.default.createElement(
  26867. 'div',
  26868. { className: 'bf-external-form' },
  26869. _react2.default.createElement(
  26870. 'div',
  26871. { className: 'bf-external-input' },
  26872. _react2.default.createElement(
  26873. 'div',
  26874. null,
  26875. _react2.default.createElement('input', { onKeyDown: this.confirmAddExternal, value: external.url, onChange: this.inputExternal, placeholder: language.externalInputPlaceHolder })
  26876. ),
  26877. _react2.default.createElement(
  26878. 'button',
  26879. { type: 'button', onClick: this.confirmAddExternal, disabled: !external.url.trim().length },
  26880. language.confirm
  26881. )
  26882. ),
  26883. _react2.default.createElement(
  26884. 'div',
  26885. { 'data-type': external.type, className: 'bf-switch-external-type' },
  26886. externals.image ? _react2.default.createElement(
  26887. 'button',
  26888. { type: 'button', onClick: this.switchExternalType, 'data-type': 'IMAGE' },
  26889. language.image
  26890. ) : null,
  26891. externals.audio ? _react2.default.createElement(
  26892. 'button',
  26893. { type: 'button', onClick: this.switchExternalType, 'data-type': 'AUDIO' },
  26894. language.audio
  26895. ) : null,
  26896. externals.video ? _react2.default.createElement(
  26897. 'button',
  26898. { type: 'button', onClick: this.switchExternalType, 'data-type': 'VIDEO' },
  26899. language.video
  26900. ) : null,
  26901. externals.embed ? _react2.default.createElement(
  26902. 'button',
  26903. { type: 'button', onClick: this.switchExternalType, 'data-type': 'EMBED' },
  26904. language.embed
  26905. ) : null
  26906. ),
  26907. _react2.default.createElement(
  26908. 'span',
  26909. { className: 'bf-external-tip' },
  26910. language.externalInputTip
  26911. )
  26912. )
  26913. ) : null
  26914. ),
  26915. _react2.default.createElement(
  26916. 'footer',
  26917. { className: 'bf-manager-footer' },
  26918. _react2.default.createElement(
  26919. 'div',
  26920. { className: 'pull-left' },
  26921. allowExternal ? _react2.default.createElement(
  26922. 'span',
  26923. {
  26924. onClick: this.toggleExternalForm,
  26925. className: 'bf-toggle-external-form'
  26926. },
  26927. showExternalForm ? _react2.default.createElement(
  26928. 'span',
  26929. { className: 'bf-bottom-text' },
  26930. _react2.default.createElement('i', { className: 'braft-icon-add' }),
  26931. ' ',
  26932. language.addLocalFile
  26933. ) : _react2.default.createElement(
  26934. 'span',
  26935. { className: 'bf-bottom-text' },
  26936. _react2.default.createElement('i', { className: 'braft-icon-add' }),
  26937. ' ',
  26938. language.addExternalSource
  26939. )
  26940. ) : null
  26941. ),
  26942. _react2.default.createElement(
  26943. 'div',
  26944. { className: 'pull-right' },
  26945. _react2.default.createElement(
  26946. 'button',
  26947. { onClick: this.confirmInsert, className: 'button button-insert', disabled: !confirmable },
  26948. language.insert
  26949. ),
  26950. _react2.default.createElement(
  26951. 'button',
  26952. { onClick: this.cancelInsert, className: 'button button-cancel' },
  26953. language.cancel
  26954. )
  26955. )
  26956. )
  26957. );
  26958. }
  26959. }, {
  26960. key: 'buildItemList',
  26961. value: function buildItemList() {
  26962. var _this2 = this;
  26963. return _react2.default.createElement(
  26964. 'ul',
  26965. { className: 'bf-list' },
  26966. _react2.default.createElement(
  26967. 'li',
  26968. { className: 'bf-add-item' },
  26969. _react2.default.createElement('i', { className: 'braft-icon-add' }),
  26970. _react2.default.createElement('input', { accept: this.state.fileAccept, onChange: this.reslovePickedFiles, multiple: true, type: 'file' })
  26971. ),
  26972. this.state.items.map(function (item, index) {
  26973. var previewerComponents = null;
  26974. var progressMarker = item.uploading && !_this2.props.hideProgress ? _react2.default.createElement(
  26975. 'div',
  26976. { className: 'bf-item-uploading' },
  26977. _react2.default.createElement('div', { className: 'bf-item-uploading-bar', style: { width: item.uploadProgress / 1 + '%' } })
  26978. ) : '';
  26979. switch (item.type) {
  26980. case 'IMAGE':
  26981. previewerComponents = _react2.default.createElement(
  26982. 'div',
  26983. { className: 'bf-image' },
  26984. progressMarker,
  26985. _react2.default.createElement('img', { src: item.thumbnail || item.url })
  26986. );
  26987. break;
  26988. case 'VIDEO':
  26989. previewerComponents = _react2.default.createElement(
  26990. 'div',
  26991. { className: 'bf-icon bf-video', title: item.url },
  26992. progressMarker,
  26993. _react2.default.createElement('i', { className: 'braft-icon-film' }),
  26994. _react2.default.createElement(
  26995. 'span',
  26996. null,
  26997. item.name || item.url
  26998. )
  26999. );
  27000. break;
  27001. case 'AUDIO':
  27002. previewerComponents = _react2.default.createElement(
  27003. 'div',
  27004. { className: 'bf-icon bf-audio', title: item.url },
  27005. progressMarker,
  27006. _react2.default.createElement('i', { className: 'braft-icon-music' }),
  27007. _react2.default.createElement(
  27008. 'span',
  27009. null,
  27010. item.name || item.url
  27011. )
  27012. );
  27013. break;
  27014. case 'EMBED':
  27015. previewerComponents = _react2.default.createElement(
  27016. 'div',
  27017. { className: 'bf-icon bf-embed', title: item.url },
  27018. progressMarker,
  27019. _react2.default.createElement('i', { className: 'braft-icon-code' }),
  27020. _react2.default.createElement(
  27021. 'span',
  27022. null,
  27023. item.name || _this2.props.language.embed
  27024. )
  27025. );
  27026. break;
  27027. default:
  27028. previewerComponents = _react2.default.createElement(
  27029. 'a',
  27030. { className: 'bf-icon bf-file', title: item.url, href: item.url },
  27031. progressMarker,
  27032. _react2.default.createElement('i', { className: 'braft-icon-file-text' }),
  27033. _react2.default.createElement(
  27034. 'span',
  27035. null,
  27036. item.name || item.url
  27037. )
  27038. );
  27039. break;
  27040. }
  27041. var className = ['bf-item'];
  27042. item.selected && className.push('active');
  27043. item.uploading && className.push('uploading');
  27044. item.error && className.push('error');
  27045. return _react2.default.createElement(
  27046. 'li',
  27047. {
  27048. key: index,
  27049. title: item.name,
  27050. 'data-id': item.id,
  27051. className: className.join(' '),
  27052. onClick: _this2.toggleSelectItem
  27053. },
  27054. previewerComponents,
  27055. _react2.default.createElement('span', { 'data-id': item.id, onClick: _this2.removeItem, className: 'bf-item-remove braft-icon-close' }),
  27056. _react2.default.createElement(
  27057. 'span',
  27058. { className: 'bf-item-title' },
  27059. item.name
  27060. )
  27061. );
  27062. })
  27063. );
  27064. }
  27065. }]);
  27066. return BraftFinderView;
  27067. }(_react2.default.Component);
  27068. BraftFinderView.defaultProps = {
  27069. accepts: defaultAccepts,
  27070. externals: {
  27071. image: true,
  27072. video: true,
  27073. audio: true,
  27074. embed: true
  27075. }
  27076. };
  27077. exports.default = BraftFinderView;
  27078. /***/ }),
  27079. /* 19 */
  27080. /***/ (function(module, exports, __webpack_require__) {
  27081. Object.defineProperty(exports, "__esModule", {
  27082. value: true
  27083. });
  27084. 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; };
  27085. var _base = __webpack_require__(1);
  27086. var _image = __webpack_require__(0);
  27087. 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); } }
  27088. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  27089. var defaultValidator = function defaultValidator() {
  27090. return true;
  27091. };
  27092. var BraftFinderController = function BraftFinderController() {
  27093. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  27094. _classCallCheck(this, BraftFinderController);
  27095. _initialiseProps.call(this);
  27096. this.items = props.items || [];
  27097. this.uploadFn = props.uploader;
  27098. this.validateFn = props.validator || defaultValidator;
  27099. this.changeListeners = [];
  27100. }
  27101. // resolvePastedFiles ({ clipboardData }, callback) {
  27102. // if (clipboardData && clipboardData.items && clipboardData.items[0].type.indexOf('image') > -1) {
  27103. // this.uploadImage(clipboardData.items[0].getAsFile(), callback)
  27104. // }
  27105. // }
  27106. ;
  27107. var _initialiseProps = function _initialiseProps() {
  27108. var _this = this;
  27109. this.setProps = function () {
  27110. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  27111. _this.items = props.items || _this.items || [];
  27112. _this.uploadFn = props.uploader;
  27113. _this.validateFn = props.validator || defaultValidator;
  27114. };
  27115. this.getMediaItem = function (id) {
  27116. return _this.items.find(function (item) {
  27117. return item.id === id;
  27118. });
  27119. };
  27120. this.getSelectedItems = function () {
  27121. return _this.items.filter(function (item) {
  27122. return item.selected;
  27123. });
  27124. };
  27125. this.getItems = function () {
  27126. return _this.items;
  27127. };
  27128. this.setItems = function (items) {
  27129. _this.items = items.map(function (item) {
  27130. return _extends({}, item, { id: item.id.toString() });
  27131. }) || [];
  27132. _this.applyChange();
  27133. _this.uploadItems();
  27134. };
  27135. this.addMediaItem = function (item) {
  27136. _this.addItems([item]);
  27137. };
  27138. this.addItems = function (items) {
  27139. _this.items = [].concat(_toConsumableArray(_this.items), _toConsumableArray(items.map(function (item) {
  27140. return _extends({}, item, { id: item.id.toString() });
  27141. })));
  27142. _this.applyChange();
  27143. _this.uploadItems();
  27144. };
  27145. this.selectMediaItem = function (id) {
  27146. var item = _this.getMediaItem(id);
  27147. if (item && (item.uploading || item.error)) {
  27148. return false;
  27149. }
  27150. _this.setMediaItemState(id, {
  27151. selected: true
  27152. });
  27153. };
  27154. this.selectAllItems = function () {
  27155. _this.items = _this.items.filter(function (item) {
  27156. return !item.error && !item.uploading;
  27157. }).map(function (item) {
  27158. return _extends({}, item, { selected: true });
  27159. });
  27160. _this.applyChange();
  27161. };
  27162. this.deselectMediaItem = function (id) {
  27163. _this.setMediaItemState(id, {
  27164. selected: false
  27165. });
  27166. };
  27167. this.deselectAllItems = function () {
  27168. _this.items = _this.items.map(function (item) {
  27169. return _extends({}, item, { selected: false });
  27170. });
  27171. _this.applyChange();
  27172. };
  27173. this.removeMediaItem = function (id) {
  27174. _this.items = _this.items.filter(function (item) {
  27175. return item.id !== id;
  27176. });
  27177. _this.applyChange();
  27178. };
  27179. this.removeItems = function () {
  27180. var ids = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  27181. _this.items = _this.items.filter(function (item) {
  27182. return !ids.includes(item.id);
  27183. });
  27184. _this.applyChange();
  27185. };
  27186. this.removeSelectedItems = function () {
  27187. _this.items = _this.items.filter(function (item) {
  27188. return !item.selected;
  27189. });
  27190. _this.applyChange();
  27191. };
  27192. this.removeErrorItems = function () {
  27193. _this.items = _this.items.filter(function (item) {
  27194. return !item.error;
  27195. });
  27196. _this.applyChange();
  27197. };
  27198. this.removeAllItems = function () {
  27199. _this.items = [];
  27200. _this.applyChange();
  27201. };
  27202. this.setMediaItemState = function (id, state) {
  27203. _this.items = _this.items.map(function (item) {
  27204. return item.id === id ? _extends({}, item, state) : item;
  27205. });
  27206. _this.applyChange();
  27207. };
  27208. this.reuploadErrorItems = function () {
  27209. _this.uploadItems(true);
  27210. };
  27211. this.uploadItems = function () {
  27212. var ignoreError = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  27213. _this.items.forEach(function (item, index) {
  27214. if (item.uploading || item.url) {
  27215. return false;
  27216. }
  27217. if (!ignoreError && item.error) {
  27218. return false;
  27219. }
  27220. if (item.type === 'IMAGE') {
  27221. _this.createThumbnail(item);
  27222. _this.uploadFn = _this.uploadFn || _this.createInlineImage;
  27223. } else if (!_this.uploadFn) {
  27224. _this.setMediaItemState(item.id, { error: 1 });
  27225. return false;
  27226. }
  27227. _this.setMediaItemState(item.id, {
  27228. uploading: true,
  27229. uploadProgress: 0,
  27230. error: 0
  27231. });
  27232. _this.uploadFn({
  27233. id: item.id,
  27234. file: item.file,
  27235. success: function success(res) {
  27236. _this.handleUploadSuccess(item.id, res);
  27237. },
  27238. progress: function progress(_progress) {
  27239. _this.setMediaItemState(item.id, {
  27240. uploading: true,
  27241. uploadProgress: _progress
  27242. });
  27243. },
  27244. error: function error(_error) {
  27245. _this.setMediaItemState(item.id, {
  27246. uploading: false,
  27247. error: 2
  27248. });
  27249. }
  27250. });
  27251. });
  27252. };
  27253. this.createThumbnail = function (_ref) {
  27254. var id = _ref.id,
  27255. file = _ref.file;
  27256. (0, _image.compressImage)(URL.createObjectURL(file), 226, 226).then(function (result) {
  27257. _this.setMediaItemState(id, { thumbnail: result.url });
  27258. });
  27259. };
  27260. this.createInlineImage = function (param) {
  27261. (0, _image.compressImage)(URL.createObjectURL(param.file), 1280, 800).then(function (result) {
  27262. param.success({ url: result.url });
  27263. }).catch(function (error) {
  27264. param.error(error);
  27265. });
  27266. };
  27267. this.handleUploadSuccess = function (id, data) {
  27268. _this.setMediaItemState(id, _extends({}, data, {
  27269. file: null,
  27270. uploadProgress: 1,
  27271. uploading: false,
  27272. selected: false
  27273. }));
  27274. var item = _this.getMediaItem(data.id || id);
  27275. item.onReady && item.onReady(item);
  27276. };
  27277. this.applyChange = function () {
  27278. _this.changeListeners.forEach(function (_ref2) {
  27279. var callback = _ref2.callback;
  27280. return callback(_this.items);
  27281. });
  27282. };
  27283. this.uploadImage = function (file, callback) {
  27284. var fileId = new Date().getTime() + '_' + (0, _base.UniqueIndex)();
  27285. _this.addMediaItem({
  27286. type: 'IMAGE',
  27287. id: fileId,
  27288. file: file,
  27289. name: fileId,
  27290. size: file.size,
  27291. uploadProgress: 0,
  27292. uploading: false,
  27293. selected: false,
  27294. error: 0,
  27295. onReady: callback
  27296. });
  27297. };
  27298. this.uploadImageRecursively = function (files, callback) {
  27299. var index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
  27300. if (files[index] && files[index].type.indexOf('image') > -1) {
  27301. _this.uploadImage(files[index], function (image) {
  27302. callback && callback(image);
  27303. index < files.length - 1 && _this.uploadImageRecursively(files, callback, index + 1);
  27304. });
  27305. } else {
  27306. index < files.length - 1 && _this.uploadImageRecursively(files, callback, index + 1);
  27307. }
  27308. };
  27309. this.addResolvedFiles = function (param, index, accepts) {
  27310. var data = {
  27311. id: new Date().getTime() + '_' + (0, _base.UniqueIndex)(),
  27312. file: param.files[index],
  27313. name: param.files[index].name,
  27314. size: param.files[index].size,
  27315. uploadProgress: 0,
  27316. uploading: false,
  27317. selected: false,
  27318. error: 0,
  27319. onReady: function onReady(item) {
  27320. param.onItemReady && param.onItemReady(item);
  27321. }
  27322. };
  27323. if (param.files[index].type.indexOf('image/') === 0 && accepts.image) {
  27324. data.type = 'IMAGE';
  27325. _this.addMediaItem(data);
  27326. } else if (param.files[index].type.indexOf('video/') === 0 && accepts.video) {
  27327. data.type = 'VIDEO';
  27328. _this.addMediaItem(data);
  27329. } else if (param.files[index].type.indexOf('audio/') === 0 && accepts.audio) {
  27330. data.type = 'AUDIO';
  27331. _this.addMediaItem(data);
  27332. }
  27333. setTimeout(function () {
  27334. _this.resolveFiles(param, index + 1, accepts);
  27335. }, 60);
  27336. };
  27337. this.resolveFiles = function (param, index, accepts) {
  27338. if (index < param.files.length) {
  27339. var validateResult = _this.validateFn(param.files[index]);
  27340. if (validateResult instanceof Promise) {
  27341. validateResult.then(function () {
  27342. _this.addResolvedFiles(param, index, accepts);
  27343. });
  27344. } else if (validateResult) {
  27345. _this.addResolvedFiles(param, index, accepts);
  27346. }
  27347. } else {
  27348. param.onAllReady && param.onAllReady();
  27349. }
  27350. };
  27351. this.onChange = function (callback) {
  27352. var listenerId = (0, _base.UniqueIndex)();
  27353. _this.changeListeners.push({
  27354. id: listenerId,
  27355. callback: callback
  27356. });
  27357. return listenerId;
  27358. };
  27359. this.offChange = function (listenerId) {
  27360. _this.changeListeners = _this.changeListeners.filter(function (_ref3) {
  27361. var id = _ref3.id;
  27362. return id !== listenerId;
  27363. });
  27364. };
  27365. };
  27366. exports.default = BraftFinderController;
  27367. /***/ }),
  27368. /* 20 */
  27369. /***/ (function(module, exports, __webpack_require__) {
  27370. Object.defineProperty(exports, "__esModule", {
  27371. value: true
  27372. });
  27373. exports.ImageUtils = undefined;
  27374. 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; };
  27375. var _react = __webpack_require__(2);
  27376. var _react2 = _interopRequireDefault(_react);
  27377. var _controller = __webpack_require__(19);
  27378. var _controller2 = _interopRequireDefault(_controller);
  27379. var _view = __webpack_require__(18);
  27380. var _view2 = _interopRequireDefault(_view);
  27381. var _languages = __webpack_require__(10);
  27382. var _languages2 = _interopRequireDefault(_languages);
  27383. var _image = __webpack_require__(0);
  27384. var ImageUtils = _interopRequireWildcard(_image);
  27385. 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; } }
  27386. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  27387. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  27388. 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; }
  27389. 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; }
  27390. var BraftFinder = function (_FinderController) {
  27391. _inherits(BraftFinder, _FinderController);
  27392. function BraftFinder(props) {
  27393. _classCallCheck(this, BraftFinder);
  27394. var _this = _possibleConstructorReturn(this, (BraftFinder.__proto__ || Object.getPrototypeOf(BraftFinder)).call(this, props));
  27395. _initialiseProps.call(_this);
  27396. _this.superProps = props;
  27397. return _this;
  27398. }
  27399. return BraftFinder;
  27400. }(_controller2.default);
  27401. var _initialiseProps = function _initialiseProps() {
  27402. var _this2 = this;
  27403. this.ReactComponent = function () {
  27404. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  27405. var componentProps = _extends({}, _this2.superProps, props);
  27406. var language = (typeof componentProps.language === 'function' ? componentProps.language(_languages2.default, 'braft-finder') : _languages2.default[componentProps.language]) || _languages2.default['zh'];
  27407. return _react2.default.createElement(_view2.default, _extends({}, componentProps, {
  27408. language: language,
  27409. controller: _this2
  27410. }));
  27411. };
  27412. };
  27413. exports.default = BraftFinder;
  27414. exports.ImageUtils = ImageUtils;
  27415. /***/ })
  27416. /******/ ]);
  27417. });
  27418. });
  27419. unwrapExports(dist$2);
  27420. var dist$3 = createCommonjsModule(function (module, exports) {
  27421. (function webpackUniversalModuleDefinition(root, factory) {
  27422. module.exports = factory(React, dist$1, Draft, immutable$1, dist, ReactDOM, dist$2, draftjsUtils);
  27423. })(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__) {
  27424. return /******/ (function(modules) { // webpackBootstrap
  27425. /******/ // The module cache
  27426. /******/ var installedModules = {};
  27427. /******/
  27428. /******/ // The require function
  27429. /******/ function __webpack_require__(moduleId) {
  27430. /******/
  27431. /******/ // Check if module is in cache
  27432. /******/ if(installedModules[moduleId]) {
  27433. /******/ return installedModules[moduleId].exports;
  27434. /******/ }
  27435. /******/ // Create a new module (and put it into the cache)
  27436. /******/ var module = installedModules[moduleId] = {
  27437. /******/ i: moduleId,
  27438. /******/ l: false,
  27439. /******/ exports: {}
  27440. /******/ };
  27441. /******/
  27442. /******/ // Execute the module function
  27443. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  27444. /******/
  27445. /******/ // Flag the module as loaded
  27446. /******/ module.l = true;
  27447. /******/
  27448. /******/ // Return the exports of the module
  27449. /******/ return module.exports;
  27450. /******/ }
  27451. /******/
  27452. /******/
  27453. /******/ // expose the modules object (__webpack_modules__)
  27454. /******/ __webpack_require__.m = modules;
  27455. /******/
  27456. /******/ // expose the module cache
  27457. /******/ __webpack_require__.c = installedModules;
  27458. /******/
  27459. /******/ // define getter function for harmony exports
  27460. /******/ __webpack_require__.d = function(exports, name, getter) {
  27461. /******/ if(!__webpack_require__.o(exports, name)) {
  27462. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  27463. /******/ }
  27464. /******/ };
  27465. /******/
  27466. /******/ // define __esModule on exports
  27467. /******/ __webpack_require__.r = function(exports) {
  27468. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  27469. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  27470. /******/ }
  27471. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  27472. /******/ };
  27473. /******/
  27474. /******/ // create a fake namespace object
  27475. /******/ // mode & 1: value is a module id, require it
  27476. /******/ // mode & 2: merge all properties of value into the ns
  27477. /******/ // mode & 4: return value when already ns object
  27478. /******/ // mode & 8|1: behave like require
  27479. /******/ __webpack_require__.t = function(value, mode) {
  27480. /******/ if(mode & 1) value = __webpack_require__(value);
  27481. /******/ if(mode & 8) return value;
  27482. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  27483. /******/ var ns = Object.create(null);
  27484. /******/ __webpack_require__.r(ns);
  27485. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  27486. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  27487. /******/ return ns;
  27488. /******/ };
  27489. /******/
  27490. /******/ // getDefaultExport function for compatibility with non-harmony modules
  27491. /******/ __webpack_require__.n = function(module) {
  27492. /******/ var getter = module && module.__esModule ?
  27493. /******/ function getDefault() { return module['default']; } :
  27494. /******/ function getModuleExports() { return module; };
  27495. /******/ __webpack_require__.d(getter, 'a', getter);
  27496. /******/ return getter;
  27497. /******/ };
  27498. /******/
  27499. /******/ // Object.prototype.hasOwnProperty.call
  27500. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  27501. /******/
  27502. /******/ // __webpack_public_path__
  27503. /******/ __webpack_require__.p = "/";
  27504. /******/
  27505. /******/
  27506. /******/ // Load entry module and return exports
  27507. /******/ return __webpack_require__(__webpack_require__.s = 39);
  27508. /******/ })
  27509. /************************************************************************/
  27510. /******/ ([
  27511. /* 0 */
  27512. /***/ (function(module, exports) {
  27513. module.exports = __WEBPACK_EXTERNAL_MODULE__0__;
  27514. /***/ }),
  27515. /* 1 */
  27516. /***/ (function(module, exports) {
  27517. function _assertThisInitialized(self) {
  27518. if (self === void 0) {
  27519. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  27520. }
  27521. return self;
  27522. }
  27523. module.exports = _assertThisInitialized;
  27524. /***/ }),
  27525. /* 2 */
  27526. /***/ (function(module, exports) {
  27527. function _defineProperty(obj, key, value) {
  27528. if (key in obj) {
  27529. Object.defineProperty(obj, key, {
  27530. value: value,
  27531. enumerable: true,
  27532. configurable: true,
  27533. writable: true
  27534. });
  27535. } else {
  27536. obj[key] = value;
  27537. }
  27538. return obj;
  27539. }
  27540. module.exports = _defineProperty;
  27541. /***/ }),
  27542. /* 3 */
  27543. /***/ (function(module, exports) {
  27544. module.exports = __WEBPACK_EXTERNAL_MODULE__3__;
  27545. /***/ }),
  27546. /* 4 */
  27547. /***/ (function(module, exports) {
  27548. function _classCallCheck(instance, Constructor) {
  27549. if (!(instance instanceof Constructor)) {
  27550. throw new TypeError("Cannot call a class as a function");
  27551. }
  27552. }
  27553. module.exports = _classCallCheck;
  27554. /***/ }),
  27555. /* 5 */
  27556. /***/ (function(module, exports, __webpack_require__) {
  27557. var defineProperty = __webpack_require__(2);
  27558. function _objectSpread(target) {
  27559. for (var i = 1; i < arguments.length; i++) {
  27560. var source = arguments[i] != null ? arguments[i] : {};
  27561. var ownKeys = Object.keys(source);
  27562. if (typeof Object.getOwnPropertySymbols === 'function') {
  27563. ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
  27564. return Object.getOwnPropertyDescriptor(source, sym).enumerable;
  27565. }));
  27566. }
  27567. ownKeys.forEach(function (key) {
  27568. defineProperty(target, key, source[key]);
  27569. });
  27570. }
  27571. return target;
  27572. }
  27573. module.exports = _objectSpread;
  27574. /***/ }),
  27575. /* 6 */
  27576. /***/ (function(module, exports) {
  27577. module.exports = __WEBPACK_EXTERNAL_MODULE__6__;
  27578. /***/ }),
  27579. /* 7 */
  27580. /***/ (function(module, exports) {
  27581. function _defineProperties(target, props) {
  27582. for (var i = 0; i < props.length; i++) {
  27583. var descriptor = props[i];
  27584. descriptor.enumerable = descriptor.enumerable || false;
  27585. descriptor.configurable = true;
  27586. if ("value" in descriptor) descriptor.writable = true;
  27587. Object.defineProperty(target, descriptor.key, descriptor);
  27588. }
  27589. }
  27590. function _createClass(Constructor, protoProps, staticProps) {
  27591. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  27592. if (staticProps) _defineProperties(Constructor, staticProps);
  27593. return Constructor;
  27594. }
  27595. module.exports = _createClass;
  27596. /***/ }),
  27597. /* 8 */
  27598. /***/ (function(module, exports, __webpack_require__) {
  27599. var _typeof = __webpack_require__(15);
  27600. var assertThisInitialized = __webpack_require__(1);
  27601. function _possibleConstructorReturn(self, call) {
  27602. if (call && (_typeof(call) === "object" || typeof call === "function")) {
  27603. return call;
  27604. }
  27605. return assertThisInitialized(self);
  27606. }
  27607. module.exports = _possibleConstructorReturn;
  27608. /***/ }),
  27609. /* 9 */
  27610. /***/ (function(module, exports) {
  27611. function _getPrototypeOf(o) {
  27612. module.exports = _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
  27613. return o.__proto__ || Object.getPrototypeOf(o);
  27614. };
  27615. return _getPrototypeOf(o);
  27616. }
  27617. module.exports = _getPrototypeOf;
  27618. /***/ }),
  27619. /* 10 */
  27620. /***/ (function(module, exports, __webpack_require__) {
  27621. var setPrototypeOf = __webpack_require__(26);
  27622. function _inherits(subClass, superClass) {
  27623. if (typeof superClass !== "function" && superClass !== null) {
  27624. throw new TypeError("Super expression must either be null or a function");
  27625. }
  27626. subClass.prototype = Object.create(superClass && superClass.prototype, {
  27627. constructor: {
  27628. value: subClass,
  27629. writable: true,
  27630. configurable: true
  27631. }
  27632. });
  27633. if (superClass) setPrototypeOf(subClass, superClass);
  27634. }
  27635. module.exports = _inherits;
  27636. /***/ }),
  27637. /* 11 */
  27638. /***/ (function(module, exports) {
  27639. function _extends() {
  27640. module.exports = _extends = Object.assign || function (target) {
  27641. for (var i = 1; i < arguments.length; i++) {
  27642. var source = arguments[i];
  27643. for (var key in source) {
  27644. if (Object.prototype.hasOwnProperty.call(source, key)) {
  27645. target[key] = source[key];
  27646. }
  27647. }
  27648. }
  27649. return target;
  27650. };
  27651. return _extends.apply(this, arguments);
  27652. }
  27653. module.exports = _extends;
  27654. /***/ }),
  27655. /* 12 */
  27656. /***/ (function(module, exports, __webpack_require__) {
  27657. var arrayWithoutHoles = __webpack_require__(27);
  27658. var iterableToArray = __webpack_require__(28);
  27659. var nonIterableSpread = __webpack_require__(29);
  27660. function _toConsumableArray(arr) {
  27661. return arrayWithoutHoles(arr) || iterableToArray(arr) || nonIterableSpread();
  27662. }
  27663. module.exports = _toConsumableArray;
  27664. /***/ }),
  27665. /* 13 */
  27666. /***/ (function(module, exports) {
  27667. module.exports = __WEBPACK_EXTERNAL_MODULE__13__;
  27668. /***/ }),
  27669. /* 14 */
  27670. /***/ (function(module, exports) {
  27671. module.exports = __WEBPACK_EXTERNAL_MODULE__14__;
  27672. /***/ }),
  27673. /* 15 */
  27674. /***/ (function(module, exports) {
  27675. 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); }
  27676. function _typeof(obj) {
  27677. if (typeof Symbol === "function" && _typeof2(Symbol.iterator) === "symbol") {
  27678. module.exports = _typeof = function _typeof(obj) {
  27679. return _typeof2(obj);
  27680. };
  27681. } else {
  27682. module.exports = _typeof = function _typeof(obj) {
  27683. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : _typeof2(obj);
  27684. };
  27685. }
  27686. return _typeof(obj);
  27687. }
  27688. module.exports = _typeof;
  27689. /***/ }),
  27690. /* 16 */
  27691. /***/ (function(module, exports) {
  27692. module.exports = __WEBPACK_EXTERNAL_MODULE__16__;
  27693. /***/ }),
  27694. /* 17 */
  27695. /***/ (function(module, exports) {
  27696. module.exports = __WEBPACK_EXTERNAL_MODULE__17__;
  27697. /***/ }),
  27698. /* 18 */
  27699. /***/ (function(module, exports, __webpack_require__) {
  27700. var Immutable = __webpack_require__(13);
  27701. var KEY_SEPARATOR = '-';
  27702. function MultiDecorator(decorators) {
  27703. this.decorators = Immutable.List(decorators);
  27704. }
  27705. /**
  27706. Return list of decoration IDs per character
  27707. @param {ContentBlock}
  27708. @return {List<String>}
  27709. */
  27710. MultiDecorator.prototype.getDecorations = function(block) {
  27711. var decorations = Array(block.getText().length).fill(null);
  27712. this.decorators.forEach(function(decorator, i) {
  27713. var _decorations = decorator.getDecorations(block);
  27714. _decorations.forEach(function(key, offset) {
  27715. if (!key) {
  27716. return;
  27717. }
  27718. key = i + KEY_SEPARATOR + key;
  27719. decorations[offset] = key;
  27720. });
  27721. });
  27722. return Immutable.List(decorations);
  27723. };
  27724. /**
  27725. Return component to render a decoration
  27726. @param {String}
  27727. @return {Function}
  27728. */
  27729. MultiDecorator.prototype.getComponentForKey = function(key) {
  27730. var decorator = this.getDecoratorForKey(key);
  27731. return decorator.getComponentForKey(
  27732. this.getInnerKey(key)
  27733. );
  27734. };
  27735. /**
  27736. Return props to render a decoration
  27737. @param {String}
  27738. @return {Object}
  27739. */
  27740. MultiDecorator.prototype.getPropsForKey = function(key) {
  27741. var decorator = this.getDecoratorForKey(key);
  27742. return decorator.getPropsForKey(
  27743. this.getInnerKey(key)
  27744. );
  27745. };
  27746. /**
  27747. Return a decorator for a specific key
  27748. @param {String}
  27749. @return {Decorator}
  27750. */
  27751. MultiDecorator.prototype.getDecoratorForKey = function(key) {
  27752. var parts = key.split(KEY_SEPARATOR);
  27753. var index = Number(parts[0]);
  27754. return this.decorators.get(index);
  27755. };
  27756. /**
  27757. Return inner key for a decorator
  27758. @param {String}
  27759. @return {String}
  27760. */
  27761. MultiDecorator.prototype.getInnerKey = function(key) {
  27762. var parts = key.split(KEY_SEPARATOR);
  27763. return parts.slice(1).join(KEY_SEPARATOR);
  27764. };
  27765. module.exports = MultiDecorator;
  27766. /***/ }),
  27767. /* 19 */
  27768. /***/ (function(module, exports, __webpack_require__) {
  27769. /**
  27770. * Copyright (c) 2013-present, Facebook, Inc.
  27771. * All rights reserved.
  27772. *
  27773. * This source code is licensed under the BSD-style license found in the
  27774. * LICENSE file in the root directory of this source tree. An additional grant
  27775. * of patent rights can be found in the PATENTS file in the same directory.
  27776. *
  27777. * @providesModule CharacterMetadata
  27778. * @format
  27779. *
  27780. */
  27781. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  27782. 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; }
  27783. 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; }
  27784. var _require = __webpack_require__(13),
  27785. Map = _require.Map,
  27786. OrderedSet = _require.OrderedSet,
  27787. Record = _require.Record;
  27788. // Immutable.map is typed such that the value for every key in the map
  27789. // must be the same type
  27790. var EMPTY_SET = OrderedSet();
  27791. var defaultRecord = {
  27792. style: EMPTY_SET,
  27793. entity: null
  27794. };
  27795. var CharacterMetadataRecord = Record(defaultRecord);
  27796. var CharacterMetadata = function (_CharacterMetadataRec) {
  27797. _inherits(CharacterMetadata, _CharacterMetadataRec);
  27798. function CharacterMetadata() {
  27799. _classCallCheck(this, CharacterMetadata);
  27800. return _possibleConstructorReturn(this, _CharacterMetadataRec.apply(this, arguments));
  27801. }
  27802. CharacterMetadata.prototype.getStyle = function getStyle() {
  27803. return this.get('style');
  27804. };
  27805. CharacterMetadata.prototype.getEntity = function getEntity() {
  27806. return this.get('entity');
  27807. };
  27808. CharacterMetadata.prototype.hasStyle = function hasStyle(style) {
  27809. return this.getStyle().includes(style);
  27810. };
  27811. CharacterMetadata.applyStyle = function applyStyle(record, style) {
  27812. var withStyle = record.set('style', record.getStyle().add(style));
  27813. return CharacterMetadata.create(withStyle);
  27814. };
  27815. CharacterMetadata.removeStyle = function removeStyle(record, style) {
  27816. var withoutStyle = record.set('style', record.getStyle().remove(style));
  27817. return CharacterMetadata.create(withoutStyle);
  27818. };
  27819. CharacterMetadata.applyEntity = function applyEntity(record, entityKey) {
  27820. var withEntity = record.getEntity() === entityKey ? record : record.set('entity', entityKey);
  27821. return CharacterMetadata.create(withEntity);
  27822. };
  27823. /**
  27824. * Use this function instead of the `CharacterMetadata` constructor.
  27825. * Since most content generally uses only a very small number of
  27826. * style/entity permutations, we can reuse these objects as often as
  27827. * possible.
  27828. */
  27829. CharacterMetadata.create = function create(config) {
  27830. if (!config) {
  27831. return EMPTY;
  27832. }
  27833. var defaultConfig = {
  27834. style: EMPTY_SET,
  27835. entity: null
  27836. };
  27837. // Fill in unspecified properties, if necessary.
  27838. var configMap = Map(defaultConfig).merge(config);
  27839. var existing = pool.get(configMap);
  27840. if (existing) {
  27841. return existing;
  27842. }
  27843. var newCharacter = new CharacterMetadata(configMap);
  27844. pool = pool.set(configMap, newCharacter);
  27845. return newCharacter;
  27846. };
  27847. return CharacterMetadata;
  27848. }(CharacterMetadataRecord);
  27849. var EMPTY = new CharacterMetadata();
  27850. var pool = Map([[Map(defaultRecord), EMPTY]]);
  27851. CharacterMetadata.EMPTY = EMPTY;
  27852. module.exports = CharacterMetadata;
  27853. /***/ }),
  27854. /* 20 */
  27855. /***/ (function(module, exports, __webpack_require__) {
  27856. /**
  27857. * Copyright (c) 2013-present, Facebook, Inc.
  27858. * All rights reserved.
  27859. *
  27860. * This source code is licensed under the BSD-style license found in the
  27861. * LICENSE file in the root directory of this source tree. An additional grant
  27862. * of patent rights can be found in the PATENTS file in the same directory.
  27863. *
  27864. * @providesModule findRangesImmutable
  27865. * @format
  27866. *
  27867. */
  27868. /**
  27869. * Search through an array to find contiguous stretches of elements that
  27870. * match a specified filter function.
  27871. *
  27872. * When ranges are found, execute a specified `found` function to supply
  27873. * the values to the caller.
  27874. */
  27875. function findRangesImmutable(haystack, areEqualFn, filterFn, foundFn) {
  27876. if (!haystack.size) {
  27877. return;
  27878. }
  27879. var cursor = 0;
  27880. haystack.reduce(function (value, nextValue, nextIndex) {
  27881. if (!areEqualFn(value, nextValue)) {
  27882. if (filterFn(value)) {
  27883. foundFn(cursor, nextIndex);
  27884. }
  27885. cursor = nextIndex;
  27886. }
  27887. return nextValue;
  27888. });
  27889. filterFn(haystack.last()) && foundFn(cursor, haystack.count());
  27890. }
  27891. module.exports = findRangesImmutable;
  27892. /***/ }),
  27893. /* 21 */
  27894. /***/ (function(module, exports, __webpack_require__) {
  27895. var objectWithoutPropertiesLoose = __webpack_require__(25);
  27896. function _objectWithoutProperties(source, excluded) {
  27897. if (source == null) return {};
  27898. var target = objectWithoutPropertiesLoose(source, excluded);
  27899. var key, i;
  27900. if (Object.getOwnPropertySymbols) {
  27901. var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
  27902. for (i = 0; i < sourceSymbolKeys.length; i++) {
  27903. key = sourceSymbolKeys[i];
  27904. if (excluded.indexOf(key) >= 0) continue;
  27905. if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
  27906. target[key] = source[key];
  27907. }
  27908. }
  27909. return target;
  27910. }
  27911. module.exports = _objectWithoutProperties;
  27912. /***/ }),
  27913. /* 22 */
  27914. /***/ (function(module, exports, __webpack_require__) {
  27915. /**
  27916. * Copyright (c) 2013-present, Facebook, Inc.
  27917. * All rights reserved.
  27918. *
  27919. * This source code is licensed under the BSD-style license found in the
  27920. * LICENSE file in the root directory of this source tree. An additional grant
  27921. * of patent rights can be found in the PATENTS file in the same directory.
  27922. *
  27923. * @providesModule getFragmentFromSelection
  27924. * @format
  27925. *
  27926. */
  27927. var getContentStateFragment = __webpack_require__(30);
  27928. function getFragmentFromSelection(editorState) {
  27929. var selectionState = editorState.getSelection();
  27930. if (selectionState.isCollapsed()) {
  27931. return null;
  27932. }
  27933. return getContentStateFragment(editorState.getCurrentContent(), selectionState);
  27934. }
  27935. module.exports = getFragmentFromSelection;
  27936. /***/ }),
  27937. /* 23 */
  27938. /***/ (function(module, exports) {
  27939. module.exports = __WEBPACK_EXTERNAL_MODULE__23__;
  27940. /***/ }),
  27941. /* 24 */
  27942. /***/ (function(module, exports, __webpack_require__) {
  27943. var arrayWithHoles = __webpack_require__(36);
  27944. var iterableToArrayLimit = __webpack_require__(37);
  27945. var nonIterableRest = __webpack_require__(38);
  27946. function _slicedToArray(arr, i) {
  27947. return arrayWithHoles(arr) || iterableToArrayLimit(arr, i) || nonIterableRest();
  27948. }
  27949. module.exports = _slicedToArray;
  27950. /***/ }),
  27951. /* 25 */
  27952. /***/ (function(module, exports) {
  27953. function _objectWithoutPropertiesLoose(source, excluded) {
  27954. if (source == null) return {};
  27955. var target = {};
  27956. var sourceKeys = Object.keys(source);
  27957. var key, i;
  27958. for (i = 0; i < sourceKeys.length; i++) {
  27959. key = sourceKeys[i];
  27960. if (excluded.indexOf(key) >= 0) continue;
  27961. target[key] = source[key];
  27962. }
  27963. return target;
  27964. }
  27965. module.exports = _objectWithoutPropertiesLoose;
  27966. /***/ }),
  27967. /* 26 */
  27968. /***/ (function(module, exports) {
  27969. function _setPrototypeOf(o, p) {
  27970. module.exports = _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  27971. o.__proto__ = p;
  27972. return o;
  27973. };
  27974. return _setPrototypeOf(o, p);
  27975. }
  27976. module.exports = _setPrototypeOf;
  27977. /***/ }),
  27978. /* 27 */
  27979. /***/ (function(module, exports) {
  27980. function _arrayWithoutHoles(arr) {
  27981. if (Array.isArray(arr)) {
  27982. for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {
  27983. arr2[i] = arr[i];
  27984. }
  27985. return arr2;
  27986. }
  27987. }
  27988. module.exports = _arrayWithoutHoles;
  27989. /***/ }),
  27990. /* 28 */
  27991. /***/ (function(module, exports) {
  27992. function _iterableToArray(iter) {
  27993. if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
  27994. }
  27995. module.exports = _iterableToArray;
  27996. /***/ }),
  27997. /* 29 */
  27998. /***/ (function(module, exports) {
  27999. function _nonIterableSpread() {
  28000. throw new TypeError("Invalid attempt to spread non-iterable instance");
  28001. }
  28002. module.exports = _nonIterableSpread;
  28003. /***/ }),
  28004. /* 30 */
  28005. /***/ (function(module, exports, __webpack_require__) {
  28006. /**
  28007. * Copyright (c) 2013-present, Facebook, Inc.
  28008. * All rights reserved.
  28009. *
  28010. * This source code is licensed under the BSD-style license found in the
  28011. * LICENSE file in the root directory of this source tree. An additional grant
  28012. * of patent rights can be found in the PATENTS file in the same directory.
  28013. *
  28014. * @providesModule getContentStateFragment
  28015. * @format
  28016. *
  28017. */
  28018. var randomizeBlockMapKeys = __webpack_require__(31);
  28019. var removeEntitiesAtEdges = __webpack_require__(34);
  28020. var getContentStateFragment = function getContentStateFragment(contentState, selectionState) {
  28021. var startKey = selectionState.getStartKey();
  28022. var startOffset = selectionState.getStartOffset();
  28023. var endKey = selectionState.getEndKey();
  28024. var endOffset = selectionState.getEndOffset();
  28025. // Edge entities should be stripped to ensure that we don't preserve
  28026. // invalid partial entities when the fragment is reused. We do, however,
  28027. // preserve entities that are entirely within the selection range.
  28028. var contentWithoutEdgeEntities = removeEntitiesAtEdges(contentState, selectionState);
  28029. var blockMap = contentWithoutEdgeEntities.getBlockMap();
  28030. var blockKeys = blockMap.keySeq();
  28031. var startIndex = blockKeys.indexOf(startKey);
  28032. var endIndex = blockKeys.indexOf(endKey) + 1;
  28033. return randomizeBlockMapKeys(blockMap.slice(startIndex, endIndex).map(function (block, blockKey) {
  28034. var text = block.getText();
  28035. var chars = block.getCharacterList();
  28036. if (startKey === endKey) {
  28037. return block.merge({
  28038. text: text.slice(startOffset, endOffset),
  28039. characterList: chars.slice(startOffset, endOffset)
  28040. });
  28041. }
  28042. if (blockKey === startKey) {
  28043. return block.merge({
  28044. text: text.slice(startOffset),
  28045. characterList: chars.slice(startOffset)
  28046. });
  28047. }
  28048. if (blockKey === endKey) {
  28049. return block.merge({
  28050. text: text.slice(0, endOffset),
  28051. characterList: chars.slice(0, endOffset)
  28052. });
  28053. }
  28054. return block;
  28055. }));
  28056. };
  28057. module.exports = getContentStateFragment;
  28058. /***/ }),
  28059. /* 31 */
  28060. /***/ (function(module, exports, __webpack_require__) {
  28061. /**
  28062. * Copyright (c) 2013-present, Facebook, Inc.
  28063. * All rights reserved.
  28064. *
  28065. * This source code is licensed under the BSD-style license found in the
  28066. * LICENSE file in the root directory of this source tree. An additional grant
  28067. * of patent rights can be found in the PATENTS file in the same directory.
  28068. *
  28069. * @providesModule randomizeBlockMapKeys
  28070. * @format
  28071. *
  28072. */
  28073. var ContentBlockNode = __webpack_require__(32);
  28074. var Immutable = __webpack_require__(13);
  28075. var generateRandomKey = __webpack_require__(33);
  28076. var OrderedMap = Immutable.OrderedMap;
  28077. var randomizeContentBlockNodeKeys = function randomizeContentBlockNodeKeys(blockMap) {
  28078. var newKeysRef = {};
  28079. // we keep track of root blocks in order to update subsequent sibling links
  28080. var lastRootBlock = void 0;
  28081. return OrderedMap(blockMap.withMutations(function (blockMapState) {
  28082. blockMapState.forEach(function (block, index) {
  28083. var oldKey = block.getKey();
  28084. var nextKey = block.getNextSiblingKey();
  28085. var prevKey = block.getPrevSiblingKey();
  28086. var childrenKeys = block.getChildKeys();
  28087. var parentKey = block.getParentKey();
  28088. // new key that we will use to build linking
  28089. var key = generateRandomKey();
  28090. // we will add it here to re-use it later
  28091. newKeysRef[oldKey] = key;
  28092. if (nextKey) {
  28093. var nextBlock = blockMapState.get(nextKey);
  28094. if (nextBlock) {
  28095. blockMapState.setIn([nextKey, 'prevSibling'], key);
  28096. } else {
  28097. // this can happen when generating random keys for fragments
  28098. blockMapState.setIn([oldKey, 'nextSibling'], null);
  28099. }
  28100. }
  28101. if (prevKey) {
  28102. var prevBlock = blockMapState.get(prevKey);
  28103. if (prevBlock) {
  28104. blockMapState.setIn([prevKey, 'nextSibling'], key);
  28105. } else {
  28106. // this can happen when generating random keys for fragments
  28107. blockMapState.setIn([oldKey, 'prevSibling'], null);
  28108. }
  28109. }
  28110. if (parentKey && blockMapState.get(parentKey)) {
  28111. var parentBlock = blockMapState.get(parentKey);
  28112. var parentChildrenList = parentBlock.getChildKeys();
  28113. blockMapState.setIn([parentKey, 'children'], parentChildrenList.set(parentChildrenList.indexOf(block.getKey()), key));
  28114. } else {
  28115. // blocks will then be treated as root block nodes
  28116. blockMapState.setIn([oldKey, 'parent'], null);
  28117. if (lastRootBlock) {
  28118. blockMapState.setIn([lastRootBlock.getKey(), 'nextSibling'], key);
  28119. blockMapState.setIn([oldKey, 'prevSibling'], newKeysRef[lastRootBlock.getKey()]);
  28120. }
  28121. lastRootBlock = blockMapState.get(oldKey);
  28122. }
  28123. childrenKeys.forEach(function (childKey) {
  28124. var childBlock = blockMapState.get(childKey);
  28125. if (childBlock) {
  28126. blockMapState.setIn([childKey, 'parent'], key);
  28127. } else {
  28128. blockMapState.setIn([oldKey, 'children'], block.getChildKeys().filter(function (child) {
  28129. return child !== childKey;
  28130. }));
  28131. }
  28132. });
  28133. });
  28134. }).toArray().map(function (block) {
  28135. return [newKeysRef[block.getKey()], block.set('key', newKeysRef[block.getKey()])];
  28136. }));
  28137. };
  28138. var randomizeContentBlockKeys = function randomizeContentBlockKeys(blockMap) {
  28139. return OrderedMap(blockMap.toArray().map(function (block) {
  28140. var key = generateRandomKey();
  28141. return [key, block.set('key', key)];
  28142. }));
  28143. };
  28144. var randomizeBlockMapKeys = function randomizeBlockMapKeys(blockMap) {
  28145. var isTreeBasedBlockMap = blockMap.first() instanceof ContentBlockNode;
  28146. if (!isTreeBasedBlockMap) {
  28147. return randomizeContentBlockKeys(blockMap);
  28148. }
  28149. return randomizeContentBlockNodeKeys(blockMap);
  28150. };
  28151. module.exports = randomizeBlockMapKeys;
  28152. /***/ }),
  28153. /* 32 */
  28154. /***/ (function(module, exports, __webpack_require__) {
  28155. /**
  28156. * Copyright (c) 2013-present, Facebook, Inc.
  28157. * All rights reserved.
  28158. *
  28159. * This source code is licensed under the BSD-style license found in the
  28160. * LICENSE file in the root directory of this source tree. An additional grant
  28161. * of patent rights can be found in the PATENTS file in the same directory.
  28162. *
  28163. * @providesModule ContentBlockNode
  28164. * @format
  28165. *
  28166. *
  28167. * This file is a fork of ContentBlock adding support for nesting references by
  28168. * providing links to children, parent, prevSibling, and nextSibling.
  28169. *
  28170. * This is unstable and not part of the public API and should not be used by
  28171. * production systems. This file may be update/removed without notice.
  28172. */
  28173. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  28174. 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; }
  28175. 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; }
  28176. var CharacterMetadata = __webpack_require__(19);
  28177. var Immutable = __webpack_require__(13);
  28178. var findRangesImmutable = __webpack_require__(20);
  28179. var List = Immutable.List,
  28180. Map = Immutable.Map,
  28181. OrderedSet = Immutable.OrderedSet,
  28182. Record = Immutable.Record,
  28183. Repeat = Immutable.Repeat;
  28184. var EMPTY_SET = OrderedSet();
  28185. var defaultRecord = {
  28186. parent: null,
  28187. characterList: List(),
  28188. data: Map(),
  28189. depth: 0,
  28190. key: '',
  28191. text: '',
  28192. type: 'unstyled',
  28193. children: List(),
  28194. prevSibling: null,
  28195. nextSibling: null
  28196. };
  28197. var haveEqualStyle = function haveEqualStyle(charA, charB) {
  28198. return charA.getStyle() === charB.getStyle();
  28199. };
  28200. var haveEqualEntity = function haveEqualEntity(charA, charB) {
  28201. return charA.getEntity() === charB.getEntity();
  28202. };
  28203. var decorateCharacterList = function decorateCharacterList(config) {
  28204. if (!config) {
  28205. return config;
  28206. }
  28207. var characterList = config.characterList,
  28208. text = config.text;
  28209. if (text && !characterList) {
  28210. config.characterList = List(Repeat(CharacterMetadata.EMPTY, text.length));
  28211. }
  28212. return config;
  28213. };
  28214. var ContentBlockNode = function (_Record) {
  28215. _inherits(ContentBlockNode, _Record);
  28216. function ContentBlockNode() {
  28217. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultRecord;
  28218. _classCallCheck(this, ContentBlockNode);
  28219. return _possibleConstructorReturn(this, _Record.call(this, decorateCharacterList(props)));
  28220. }
  28221. ContentBlockNode.prototype.getKey = function getKey() {
  28222. return this.get('key');
  28223. };
  28224. ContentBlockNode.prototype.getType = function getType() {
  28225. return this.get('type');
  28226. };
  28227. ContentBlockNode.prototype.getText = function getText() {
  28228. return this.get('text');
  28229. };
  28230. ContentBlockNode.prototype.getCharacterList = function getCharacterList() {
  28231. return this.get('characterList');
  28232. };
  28233. ContentBlockNode.prototype.getLength = function getLength() {
  28234. return this.getText().length;
  28235. };
  28236. ContentBlockNode.prototype.getDepth = function getDepth() {
  28237. return this.get('depth');
  28238. };
  28239. ContentBlockNode.prototype.getData = function getData() {
  28240. return this.get('data');
  28241. };
  28242. ContentBlockNode.prototype.getInlineStyleAt = function getInlineStyleAt(offset) {
  28243. var character = this.getCharacterList().get(offset);
  28244. return character ? character.getStyle() : EMPTY_SET;
  28245. };
  28246. ContentBlockNode.prototype.getEntityAt = function getEntityAt(offset) {
  28247. var character = this.getCharacterList().get(offset);
  28248. return character ? character.getEntity() : null;
  28249. };
  28250. ContentBlockNode.prototype.getChildKeys = function getChildKeys() {
  28251. return this.get('children');
  28252. };
  28253. ContentBlockNode.prototype.getParentKey = function getParentKey() {
  28254. return this.get('parent');
  28255. };
  28256. ContentBlockNode.prototype.getPrevSiblingKey = function getPrevSiblingKey() {
  28257. return this.get('prevSibling');
  28258. };
  28259. ContentBlockNode.prototype.getNextSiblingKey = function getNextSiblingKey() {
  28260. return this.get('nextSibling');
  28261. };
  28262. ContentBlockNode.prototype.findStyleRanges = function findStyleRanges(filterFn, callback) {
  28263. findRangesImmutable(this.getCharacterList(), haveEqualStyle, filterFn, callback);
  28264. };
  28265. ContentBlockNode.prototype.findEntityRanges = function findEntityRanges(filterFn, callback) {
  28266. findRangesImmutable(this.getCharacterList(), haveEqualEntity, filterFn, callback);
  28267. };
  28268. return ContentBlockNode;
  28269. }(Record(defaultRecord));
  28270. module.exports = ContentBlockNode;
  28271. /***/ }),
  28272. /* 33 */
  28273. /***/ (function(module, exports, __webpack_require__) {
  28274. /**
  28275. * Copyright (c) 2013-present, Facebook, Inc.
  28276. * All rights reserved.
  28277. *
  28278. * This source code is licensed under the BSD-style license found in the
  28279. * LICENSE file in the root directory of this source tree. An additional grant
  28280. * of patent rights can be found in the PATENTS file in the same directory.
  28281. *
  28282. * @providesModule generateRandomKey
  28283. * @format
  28284. *
  28285. */
  28286. var seenKeys = {};
  28287. var MULTIPLIER = Math.pow(2, 24);
  28288. function generateRandomKey() {
  28289. var key = void 0;
  28290. while (key === undefined || seenKeys.hasOwnProperty(key) || !isNaN(+key)) {
  28291. key = Math.floor(Math.random() * MULTIPLIER).toString(32);
  28292. }
  28293. seenKeys[key] = true;
  28294. return key;
  28295. }
  28296. module.exports = generateRandomKey;
  28297. /***/ }),
  28298. /* 34 */
  28299. /***/ (function(module, exports, __webpack_require__) {
  28300. /**
  28301. * Copyright (c) 2013-present, Facebook, Inc.
  28302. * All rights reserved.
  28303. *
  28304. * This source code is licensed under the BSD-style license found in the
  28305. * LICENSE file in the root directory of this source tree. An additional grant
  28306. * of patent rights can be found in the PATENTS file in the same directory.
  28307. *
  28308. * @providesModule removeEntitiesAtEdges
  28309. * @format
  28310. *
  28311. */
  28312. var CharacterMetadata = __webpack_require__(19);
  28313. var findRangesImmutable = __webpack_require__(20);
  28314. var invariant = __webpack_require__(35);
  28315. function removeEntitiesAtEdges(contentState, selectionState) {
  28316. var blockMap = contentState.getBlockMap();
  28317. var entityMap = contentState.getEntityMap();
  28318. var updatedBlocks = {};
  28319. var startKey = selectionState.getStartKey();
  28320. var startOffset = selectionState.getStartOffset();
  28321. var startBlock = blockMap.get(startKey);
  28322. var updatedStart = removeForBlock(entityMap, startBlock, startOffset);
  28323. if (updatedStart !== startBlock) {
  28324. updatedBlocks[startKey] = updatedStart;
  28325. }
  28326. var endKey = selectionState.getEndKey();
  28327. var endOffset = selectionState.getEndOffset();
  28328. var endBlock = blockMap.get(endKey);
  28329. if (startKey === endKey) {
  28330. endBlock = updatedStart;
  28331. }
  28332. var updatedEnd = removeForBlock(entityMap, endBlock, endOffset);
  28333. if (updatedEnd !== endBlock) {
  28334. updatedBlocks[endKey] = updatedEnd;
  28335. }
  28336. if (!Object.keys(updatedBlocks).length) {
  28337. return contentState.set('selectionAfter', selectionState);
  28338. }
  28339. return contentState.merge({
  28340. blockMap: blockMap.merge(updatedBlocks),
  28341. selectionAfter: selectionState
  28342. });
  28343. }
  28344. function getRemovalRange(characters, key, offset) {
  28345. var removalRange;
  28346. findRangesImmutable(characters, function (a, b) {
  28347. return a.getEntity() === b.getEntity();
  28348. }, function (element) {
  28349. return element.getEntity() === key;
  28350. }, function (start, end) {
  28351. if (start <= offset && end >= offset) {
  28352. removalRange = { start: start, end: end };
  28353. }
  28354. });
  28355. !(typeof removalRange === 'object') ? invariant(false) : void 0;
  28356. return removalRange;
  28357. }
  28358. function removeForBlock(entityMap, block, offset) {
  28359. var chars = block.getCharacterList();
  28360. var charBefore = offset > 0 ? chars.get(offset - 1) : undefined;
  28361. var charAfter = offset < chars.count() ? chars.get(offset) : undefined;
  28362. var entityBeforeCursor = charBefore ? charBefore.getEntity() : undefined;
  28363. var entityAfterCursor = charAfter ? charAfter.getEntity() : undefined;
  28364. if (entityAfterCursor && entityAfterCursor === entityBeforeCursor) {
  28365. var entity = entityMap.__get(entityAfterCursor);
  28366. if (entity.getMutability() !== 'MUTABLE') {
  28367. var _getRemovalRange = getRemovalRange(chars, entityAfterCursor, offset),
  28368. start = _getRemovalRange.start,
  28369. end = _getRemovalRange.end;
  28370. var current;
  28371. while (start < end) {
  28372. current = chars.get(start);
  28373. chars = chars.set(start, CharacterMetadata.applyEntity(current, null));
  28374. start++;
  28375. }
  28376. return block.set('characterList', chars);
  28377. }
  28378. }
  28379. return block;
  28380. }
  28381. module.exports = removeEntitiesAtEdges;
  28382. /***/ }),
  28383. /* 35 */
  28384. /***/ (function(module, exports, __webpack_require__) {
  28385. function invariant(condition, format, a, b, c, d, e, f) {
  28386. if (!condition) {
  28387. var error;
  28388. if (format === undefined) {
  28389. error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
  28390. } else {
  28391. var args = [a, b, c, d, e, f];
  28392. var argIndex = 0;
  28393. error = new Error(format.replace(/%s/g, function () {
  28394. return args[argIndex++];
  28395. }));
  28396. error.name = 'Invariant Violation';
  28397. }
  28398. error.framesToPop = 1; // we don't care about invariant's own frame
  28399. throw error;
  28400. }
  28401. }
  28402. module.exports = invariant;
  28403. /***/ }),
  28404. /* 36 */
  28405. /***/ (function(module, exports) {
  28406. function _arrayWithHoles(arr) {
  28407. if (Array.isArray(arr)) return arr;
  28408. }
  28409. module.exports = _arrayWithHoles;
  28410. /***/ }),
  28411. /* 37 */
  28412. /***/ (function(module, exports) {
  28413. function _iterableToArrayLimit(arr, i) {
  28414. var _arr = [];
  28415. var _n = true;
  28416. var _d = false;
  28417. var _e = undefined;
  28418. try {
  28419. for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
  28420. _arr.push(_s.value);
  28421. if (i && _arr.length === i) break;
  28422. }
  28423. } catch (err) {
  28424. _d = true;
  28425. _e = err;
  28426. } finally {
  28427. try {
  28428. if (!_n && _i["return"] != null) _i["return"]();
  28429. } finally {
  28430. if (_d) throw _e;
  28431. }
  28432. }
  28433. return _arr;
  28434. }
  28435. module.exports = _iterableToArrayLimit;
  28436. /***/ }),
  28437. /* 38 */
  28438. /***/ (function(module, exports) {
  28439. function _nonIterableRest() {
  28440. throw new TypeError("Invalid attempt to destructure non-iterable instance");
  28441. }
  28442. module.exports = _nonIterableRest;
  28443. /***/ }),
  28444. /* 39 */
  28445. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  28446. __webpack_require__.r(__webpack_exports__);
  28447. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/typeof.js
  28448. var helpers_typeof = __webpack_require__(15);
  28449. var typeof_default = /*#__PURE__*/__webpack_require__.n(helpers_typeof);
  28450. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/objectSpread.js
  28451. var objectSpread = __webpack_require__(5);
  28452. var objectSpread_default = /*#__PURE__*/__webpack_require__.n(objectSpread);
  28453. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/objectWithoutProperties.js
  28454. var objectWithoutProperties = __webpack_require__(21);
  28455. var objectWithoutProperties_default = /*#__PURE__*/__webpack_require__.n(objectWithoutProperties);
  28456. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/classCallCheck.js
  28457. var classCallCheck = __webpack_require__(4);
  28458. var classCallCheck_default = /*#__PURE__*/__webpack_require__.n(classCallCheck);
  28459. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/createClass.js
  28460. var createClass = __webpack_require__(7);
  28461. var createClass_default = /*#__PURE__*/__webpack_require__.n(createClass);
  28462. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js
  28463. var possibleConstructorReturn = __webpack_require__(8);
  28464. var possibleConstructorReturn_default = /*#__PURE__*/__webpack_require__.n(possibleConstructorReturn);
  28465. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/getPrototypeOf.js
  28466. var getPrototypeOf = __webpack_require__(9);
  28467. var getPrototypeOf_default = /*#__PURE__*/__webpack_require__.n(getPrototypeOf);
  28468. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/inherits.js
  28469. var inherits = __webpack_require__(10);
  28470. var inherits_default = /*#__PURE__*/__webpack_require__.n(inherits);
  28471. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/assertThisInitialized.js
  28472. var assertThisInitialized = __webpack_require__(1);
  28473. var assertThisInitialized_default = /*#__PURE__*/__webpack_require__.n(assertThisInitialized);
  28474. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/defineProperty.js
  28475. var defineProperty = __webpack_require__(2);
  28476. var defineProperty_default = /*#__PURE__*/__webpack_require__.n(defineProperty);
  28477. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/toConsumableArray.js
  28478. var toConsumableArray = __webpack_require__(12);
  28479. var toConsumableArray_default = /*#__PURE__*/__webpack_require__.n(toConsumableArray);
  28480. // EXTERNAL MODULE: ../node_modules/draft-js/dist/Draft.css
  28481. var Draft = __webpack_require__(40);
  28482. // EXTERNAL MODULE: ./assets/scss/_base.scss
  28483. var _base = __webpack_require__(42);
  28484. // EXTERNAL MODULE: external "react"
  28485. var external_react_ = __webpack_require__(0);
  28486. var external_react_default = /*#__PURE__*/__webpack_require__.n(external_react_);
  28487. // CONCATENATED MODULE: ./languages/en.js
  28488. /* harmony default export */ var en = ({
  28489. base: {
  28490. remove: 'Remove',
  28491. cancel: 'Cancel',
  28492. confirm: 'Confirm',
  28493. inert: 'Insert',
  28494. width: 'Width',
  28495. height: 'Height'
  28496. },
  28497. controls: {
  28498. clear: 'Clear',
  28499. undo: 'Undo',
  28500. redo: 'Redo',
  28501. fontSize: 'Font Size',
  28502. color: 'Color',
  28503. textColor: 'Text',
  28504. tempColors: 'Temp Colors',
  28505. backgroundColor: 'Background',
  28506. bold: 'Bold',
  28507. lineHeight: 'Line Height',
  28508. letterSpacing: 'Letter Spacing',
  28509. textIndent: 'Text Indent',
  28510. increaseIndent: 'Increase Indent',
  28511. decreaseIndent: 'Decrease Indent',
  28512. italic: 'Italic',
  28513. underline: 'Underline',
  28514. strikeThrough: 'Strike Through',
  28515. fontFamily: 'Font Family',
  28516. textAlign: 'Text Alignment',
  28517. alignLeft: 'Left Alignment',
  28518. alignCenter: 'Center Alignment',
  28519. alignRight: 'Right Alignment',
  28520. alignJustify: 'Justify Alignment',
  28521. floatLeft: 'Left Float',
  28522. floatRight: 'Right Float',
  28523. superScript: 'Super Script',
  28524. subScript: 'Sub Script',
  28525. removeStyles: 'Remove Styles',
  28526. headings: 'Headings',
  28527. header: 'Header',
  28528. normal: 'Normal',
  28529. orderedList: 'Ordered List',
  28530. unorderedList: 'Unordered List',
  28531. blockQuote: 'Quote',
  28532. code: 'Code',
  28533. link: 'Link',
  28534. unlink: 'Unlink',
  28535. hr: 'Horizontal Line',
  28536. media: 'Media',
  28537. mediaLibirary: 'Media Library',
  28538. emoji: 'Emoji',
  28539. fullscreen: 'Fullscreen',
  28540. exitFullscreen: 'Exit Fullscreen'
  28541. },
  28542. linkEditor: {
  28543. textInputPlaceHolder: 'Input link text',
  28544. linkInputPlaceHolder: 'Input link URL',
  28545. inputWithEnterPlaceHolder: 'Input link URL and press Enter',
  28546. openInNewWindow: 'Open in new window',
  28547. removeLink: 'Remove Link'
  28548. },
  28549. audioPlayer: {
  28550. title: 'Play Audio'
  28551. },
  28552. videoPlayer: {
  28553. title: 'Play Video',
  28554. embedTitle: 'Embed Media'
  28555. },
  28556. media: {
  28557. image: 'Image',
  28558. video: 'Video',
  28559. audio: 'Audio',
  28560. embed: 'Embed'
  28561. }
  28562. });
  28563. // CONCATENATED MODULE: ./languages/zh.js
  28564. /* harmony default export */ var zh = ({
  28565. base: {
  28566. remove: '删除',
  28567. cancel: '取消',
  28568. confirm: '确定',
  28569. inert: '插入',
  28570. width: '宽度',
  28571. height: '高度'
  28572. },
  28573. controls: {
  28574. clear: '清除内容',
  28575. undo: '撤销',
  28576. redo: '重做',
  28577. fontSize: '字号',
  28578. lineHeight: '行高',
  28579. letterSpacing: '字间距',
  28580. textIndent: '段落缩进',
  28581. increaseIndent: '增加缩进',
  28582. decreaseIndent: '减少缩进',
  28583. border: '边框',
  28584. color: '颜色',
  28585. textColor: '文字颜色',
  28586. backgroundColor: '背景颜色',
  28587. tempColors: '临时颜色',
  28588. bold: '加粗',
  28589. italic: '斜体',
  28590. underline: '下划线',
  28591. strikeThrough: '删除线',
  28592. fontFamily: '字体',
  28593. textAlign: '文本对齐',
  28594. alignLeft: '居左',
  28595. alignCenter: '居中',
  28596. alignRight: '居右',
  28597. alignJustify: '两端',
  28598. floatLeft: '左浮动',
  28599. floatRight: '右浮动',
  28600. superScript: '上标',
  28601. subScript: '下标',
  28602. removeStyles: '清除样式',
  28603. headings: '标题',
  28604. header: '标题',
  28605. normal: '常规',
  28606. orderedList: '有序列表',
  28607. unorderedList: '无序列表',
  28608. blockQuote: '引用',
  28609. code: '代码',
  28610. link: '链接',
  28611. unlink: '清除链接',
  28612. hr: '水平线',
  28613. media: '媒体',
  28614. mediaLibirary: '媒体库',
  28615. emoji: '小表情',
  28616. fullscreen: '全屏',
  28617. exitFullscreen: '退出全屏'
  28618. },
  28619. linkEditor: {
  28620. textInputPlaceHolder: '输入链接文字',
  28621. linkInputPlaceHolder: '输入链接地址',
  28622. inputWithEnterPlaceHolder: '输入链接地址并回车',
  28623. openInNewWindow: '在新窗口打开',
  28624. removeLink: '移除链接'
  28625. },
  28626. audioPlayer: {
  28627. title: '播放音频文件'
  28628. },
  28629. videoPlayer: {
  28630. title: '播放视频文件',
  28631. embedTitle: '嵌入式媒体'
  28632. },
  28633. media: {
  28634. image: '图像',
  28635. video: '视频',
  28636. audio: '音频',
  28637. embed: '嵌入式媒体'
  28638. }
  28639. });
  28640. // CONCATENATED MODULE: ./languages/zh-hant.js
  28641. /* harmony default export */ var zh_hant = ({
  28642. base: {
  28643. remove: '刪除',
  28644. cancel: '取消',
  28645. confirm: '確定',
  28646. inert: '插入',
  28647. width: '宽度',
  28648. height: '高度'
  28649. },
  28650. controls: {
  28651. clear: '清除内容',
  28652. undo: '撤銷',
  28653. redo: '重做',
  28654. fontSize: '字號',
  28655. color: '顏色',
  28656. textColor: '文字顏色',
  28657. backgroundColor: '背景顏色',
  28658. tempColors: '臨時顏色',
  28659. bold: '加粗',
  28660. lineHeight: '行高',
  28661. letterSpacing: '字間距',
  28662. textIndent: '段落縮進',
  28663. increaseIndent: '增加縮進',
  28664. decreaseIndent: '减少縮進',
  28665. border: '邊框',
  28666. italic: '斜體',
  28667. underline: '下劃線',
  28668. strikeThrough: '刪除線',
  28669. fontFamily: '字體',
  28670. textAlign: '文本對齊',
  28671. alignLeft: '居左',
  28672. alignCenter: '居中',
  28673. alignRight: '居右',
  28674. alignJustify: '兩端對齊',
  28675. floatLeft: '左浮動',
  28676. floatRight: '右浮動',
  28677. superScript: '上標',
  28678. subScript: '下標',
  28679. removeStyles: '清除样式',
  28680. headings: '標題',
  28681. header: '標題',
  28682. normal: '常規',
  28683. orderedList: '有序列表',
  28684. unorderedList: '無序列表',
  28685. blockQuote: '引用',
  28686. code: '代碼',
  28687. link: '鏈接',
  28688. unlink: '清除鏈接',
  28689. hr: '水平线',
  28690. media: '媒體',
  28691. mediaLibirary: '媒體库',
  28692. emoji: '小表情',
  28693. fullscreen: '全熒幕',
  28694. exitFullscreen: '退出全熒幕'
  28695. },
  28696. linkEditor: {
  28697. textInputPlaceHolder: '輸入鏈接文字',
  28698. linkInputPlaceHolder: '輸入鏈接地址',
  28699. inputWithEnterPlaceHolder: '輸入鏈接地址並回車',
  28700. openInNewWindow: '在新窗口打開',
  28701. removeLink: '移除鏈接'
  28702. },
  28703. audioPlayer: {
  28704. title: '播放音頻文件'
  28705. },
  28706. videoPlayer: {
  28707. title: '播放視頻文件',
  28708. embedTitle: '嵌入式媒體'
  28709. },
  28710. media: {
  28711. image: '圖像',
  28712. video: '視頻',
  28713. audio: '音頻',
  28714. embed: '嵌入式媒體'
  28715. }
  28716. });
  28717. // CONCATENATED MODULE: ./languages/pl.js
  28718. /* harmony default export */ var pl = ({
  28719. base: {
  28720. remove: 'Usuń',
  28721. cancel: 'Anuluj',
  28722. confirm: 'Potwierdź',
  28723. inert: 'Wstaw',
  28724. width: 'Szerokość',
  28725. height: 'Wysokość'
  28726. },
  28727. controls: {
  28728. clear: 'Wyczyść',
  28729. undo: 'Cofnij',
  28730. redo: 'Przywróć',
  28731. fontSize: 'Wielkość',
  28732. color: 'Kolor',
  28733. textColor: 'Kolor tekstu',
  28734. tempColors: 'Kolory',
  28735. backgroundColor: 'Tło',
  28736. bold: 'Pogrubienie',
  28737. lineHeight: 'Wysokość linii',
  28738. letterSpacing: 'Odstęp znaków',
  28739. textIndent: 'Wcięcie tekstu',
  28740. increaseIndent: 'Zwiększ wcięcie',
  28741. decreaseIndent: 'Zmniejsz wcięcie',
  28742. italic: 'Italiki',
  28743. underline: 'Podkreślenie',
  28744. strikeThrough: 'Przekreślenie',
  28745. fontFamily: 'Czcionka',
  28746. textAlign: 'Wyrównanie tekstu',
  28747. alignLeft: 'Do lewej',
  28748. alignCenter: 'Wycentruj',
  28749. alignRight: 'Do prawej',
  28750. alignJustify: 'Wyjustuj',
  28751. floatLeft: 'Do lewej',
  28752. floatRight: 'Do prawej',
  28753. superScript: 'Superskrypt',
  28754. subScript: 'Subskrypt',
  28755. removeStyles: 'Usuń stylowanie',
  28756. headings: 'Nagłówki',
  28757. header: 'Nagłówek',
  28758. normal: 'Normalny',
  28759. orderedList: 'Lista uporządkowana',
  28760. unorderedList: 'Lista nieuporządkowana',
  28761. blockQuote: 'Cytat',
  28762. code: 'Kod',
  28763. link: 'Link',
  28764. unlink: 'Usuń link',
  28765. hr: 'Linia pozioma',
  28766. media: 'Media',
  28767. mediaLibirary: 'Biblioteka mediów',
  28768. emoji: 'Emoji'
  28769. },
  28770. linkEditor: {
  28771. textInputPlaceHolder: 'Wpisz tekst linku',
  28772. linkInputPlaceHolder: 'Wpisz Adres URL',
  28773. inputWithEnterPlaceHolder: 'Wpisz adres URL i naciśnij Enter',
  28774. openInNewWindow: 'Otwórz w nowym oknie',
  28775. removeLink: 'Usuń link'
  28776. },
  28777. audioPlayer: {
  28778. title: 'Odtwórz audio'
  28779. },
  28780. videoPlayer: {
  28781. title: 'Odtwórz wideo',
  28782. embedTitle: 'Tytuł'
  28783. },
  28784. media: {
  28785. image: 'Obraz',
  28786. video: 'Wideo',
  28787. audio: 'Audio',
  28788. embed: 'Obiekt osadzony'
  28789. }
  28790. });
  28791. // CONCATENATED MODULE: ./languages/kr.js
  28792. /* harmony default export */ var kr = ({
  28793. base: {
  28794. remove: '삭제',
  28795. cancel: '취소',
  28796. confirm: '결정',
  28797. inert: '삽입',
  28798. width: '너비',
  28799. height: '높이'
  28800. },
  28801. controls: {
  28802. clear: '콘텐츠지우기',
  28803. undo: '취소',
  28804. redo: '다시하기',
  28805. fontSize: '글자크기',
  28806. lineHeight: '행높이',
  28807. letterSpacing: '단어간격',
  28808. textIndent: '단락들여쓰기',
  28809. increaseIndent: '들여쓰기늘리기',
  28810. decreaseIndent: '들여쓰기줄이기',
  28811. border: '국경',
  28812. color: '색상',
  28813. textColor: '텍스트색상',
  28814. backgroundColor: '배경색상',
  28815. tempColors: '임시색',
  28816. bold: '굵게',
  28817. italic: '기울임꼴',
  28818. underline: '밑줄',
  28819. strikeThrough: '취소선',
  28820. fontFamily: '글꼴',
  28821. textAlign: '텍스트정렬',
  28822. alignLeft: '왼쪽',
  28823. alignCenter: '중심',
  28824. alignRight: '오른쪽',
  28825. alignJustify: '양쪽끝',
  28826. floatLeft: '떠다니기',
  28827. floatRight: '오른쪽부동',
  28828. superScript: '위첨자',
  28829. subScript: '첨자',
  28830. removeStyles: '스타일지우기',
  28831. headings: '제목',
  28832. header: '제목',
  28833. normal: '재래식',
  28834. orderedList: '순서가지정된목록',
  28835. unorderedList: '정렬되지않은목록',
  28836. blockQuote: '참고문헌',
  28837. code: '코드',
  28838. link: '링크',
  28839. unlink: '링크삭제',
  28840. hr: '수평선',
  28841. media: '미디어',
  28842. mediaLibirary: '미디어라이브러리',
  28843. emoji: '작은표현',
  28844. fullscreen: '전체화면',
  28845. exitFullscreen: '전체화면종료'
  28846. },
  28847. linkEditor: {
  28848. textInputPlaceHolder: '링크텍스트입력',
  28849. linkInputPlaceHolder: '링크주소입력',
  28850. inputWithEnterPlaceHolder: '링크주소입력.',
  28851. openInNewWindow: '새창열기',
  28852. removeLink: '링크삭제'
  28853. },
  28854. audioPlayer: {
  28855. title: '오디오파일재생'
  28856. },
  28857. videoPlayer: {
  28858. title: '비디오파일재생',
  28859. embedTitle: '임베디드미디어'
  28860. },
  28861. media: {
  28862. image: '이미지',
  28863. video: '비디오',
  28864. audio: '오디오',
  28865. embed: '임베디드미디어'
  28866. }
  28867. });
  28868. // CONCATENATED MODULE: ./languages/tr.js
  28869. /* harmony default export */ var tr = ({
  28870. base: {
  28871. remove: 'Kaldır',
  28872. cancel: 'İptal',
  28873. confirm: 'Onayla',
  28874. inert: 'Ekle',
  28875. width: 'Genişlik',
  28876. height: 'Yükseklik'
  28877. },
  28878. controls: {
  28879. clear: 'Temizle',
  28880. undo: 'Geri al',
  28881. redo: 'İleri al',
  28882. fontSize: 'Yazı boyutu',
  28883. color: 'Renk',
  28884. textColor: 'Yazı rengi',
  28885. tempColors: 'Geçici renkler',
  28886. backgroundColor: 'Arkaplan',
  28887. bold: 'Kalın',
  28888. lineHeight: 'Satır yüksekliği',
  28889. letterSpacing: 'Harf aralığı',
  28890. textIndent: 'Çentik aralığı',
  28891. increaseIndent: 'Çentiği genişlet',
  28892. decreaseIndent: 'Çentiği daralt',
  28893. italic: 'Eğik',
  28894. underline: 'Altı çizili',
  28895. strikeThrough: 'Üstü çizili',
  28896. fontFamily: 'Yazı tipi',
  28897. textAlign: 'Metin Hizalama',
  28898. alignLeft: 'Sola hizala',
  28899. alignCenter: 'Ortaya hizala',
  28900. alignRight: 'Sağa hizala',
  28901. alignJustify: 'Her iki tarafa hizala',
  28902. floatLeft: 'Sola yatır',
  28903. floatRight: 'Sağa yatır',
  28904. superScript: 'Ana kod',
  28905. subScript: 'Alt kod',
  28906. removeStyles: 'Stilleri kaldır',
  28907. headings: 'Başlıklar',
  28908. header: 'Başlık',
  28909. normal: 'Normal',
  28910. orderedList: 'Sıralı liste',
  28911. unorderedList: 'Sırasız liste',
  28912. blockQuote: 'Alıntı',
  28913. code: 'Kod',
  28914. link: 'Bağlantı',
  28915. unlink: 'Bağlantıyı kaldır',
  28916. hr: 'Yatay çizgi',
  28917. media: 'Medya',
  28918. mediaLibirary: 'Kütüphane',
  28919. emoji: 'İfade',
  28920. fullscreen: 'Tam ekran',
  28921. exitFullscreen: 'Tam ekrandan çık'
  28922. },
  28923. linkEditor: {
  28924. textInputPlaceHolder: 'Bağlantı metnini girin',
  28925. linkInputPlaceHolder: 'Bağlantı URL\' si girin',
  28926. inputWithEnterPlaceHolder: 'Bağlantı URL\'si girin ve Enter\' a basın',
  28927. openInNewWindow: 'Yeni pencerede aç',
  28928. removeLink: 'Bağlantıyı kaldır'
  28929. },
  28930. audioPlayer: {
  28931. title: 'Ses çal'
  28932. },
  28933. videoPlayer: {
  28934. title: 'Görüntü oynat',
  28935. embedTitle: 'Görüntüyü göm'
  28936. },
  28937. media: {
  28938. image: 'Resim',
  28939. video: 'Görüntü',
  28940. audio: 'Ses',
  28941. embed: 'Gömülü nesne'
  28942. }
  28943. });
  28944. // CONCATENATED MODULE: ./languages/jpn.js
  28945. /* harmony default export */ var jpn = ({
  28946. base: {
  28947. remove: '削除',
  28948. cancel: 'キャンセル',
  28949. confirm: '決定',
  28950. inert: '挿入',
  28951. width: '幅',
  28952. height: '高さ'
  28953. },
  28954. controls: {
  28955. clear: 'クリアコンテンツ',
  28956. undo: 'キャンセル',
  28957. redo: 'キャンセル',
  28958. fontSize: 'フォントサイズ',
  28959. lineHeight: 'フォントサイズ',
  28960. letterSpacing: 'ワード間隔',
  28961. textIndent: '段落のインデント',
  28962. increaseIndent: 'インデントを増やす',
  28963. decreaseIndent: 'インデントを減らす',
  28964. border: '国境',
  28965. color: '色',
  28966. textColor: 'テキストの色',
  28967. backgroundColor: '背景色',
  28968. tempColors: '仮色',
  28969. bold: '太字',
  28970. italic: 'イタリック体',
  28971. underline: '下線',
  28972. strikeThrough: '取り消し線',
  28973. fontFamily: 'フォント',
  28974. textAlign: 'テキストの配置',
  28975. alignLeft: '左',
  28976. alignCenter: '中央揃え',
  28977. alignRight: '右に立つ',
  28978. alignJustify: '両端',
  28979. floatLeft: '左フローティング',
  28980. floatRight: '右フローティング',
  28981. superScript: '上付き',
  28982. subScript: '下付き文字',
  28983. removeStyles: 'クリアスタイル',
  28984. headings: '役職',
  28985. header: '役職',
  28986. normal: '従来の',
  28987. orderedList: '順序付きリスト',
  28988. unorderedList: '番号なしリスト',
  28989. blockQuote: '参照',
  28990. code: 'コード',
  28991. link: 'リンク',
  28992. unlink: 'リンクを解除',
  28993. hr: '横線',
  28994. media: 'メディア',
  28995. mediaLibirary: 'メディアライブラリー',
  28996. emoji: '小さな表現',
  28997. fullscreen: '全画面',
  28998. exitFullscreen: '全画面を退く'
  28999. },
  29000. linkEditor: {
  29001. textInputPlaceHolder: 'リンクテキストを入力',
  29002. linkInputPlaceHolder: 'リンクアドレスを入力',
  29003. inputWithEnterPlaceHolder: 'リンクアドレスを入力して戻ります',
  29004. openInNewWindow: '新しいウィンドウで開く',
  29005. removeLink: '新しいウィンドウで開く'
  29006. },
  29007. audioPlayer: {
  29008. title: 'オーディオファイルを再生する'
  29009. },
  29010. videoPlayer: {
  29011. title: 'ビデオファイルを再生する',
  29012. embedTitle: '埋め込みメディア'
  29013. },
  29014. media: {
  29015. image: '画像',
  29016. video: 'ビデオ',
  29017. audio: '音声',
  29018. embed: '埋め込みメディア'
  29019. }
  29020. });
  29021. // CONCATENATED MODULE: ./languages/ru.js
  29022. /* harmony default export */ var ru = ({
  29023. base: {
  29024. remove: 'Удалить',
  29025. cancel: 'Отмена',
  29026. confirm: 'Подтвердить',
  29027. insert: 'Вставить',
  29028. width: 'Ширина',
  29029. height: 'Высота'
  29030. },
  29031. controls: {
  29032. clear: 'Очистить',
  29033. undo: 'Отменить',
  29034. redo: 'Повторить',
  29035. fontSize: 'Размер шрифта',
  29036. color: 'Цвет',
  29037. textColor: 'Цвет текста',
  29038. tempColors: 'Temp Colors',
  29039. backgroundColor: 'Цвет фона',
  29040. bold: 'Жирный',
  29041. lineHeight: 'Межстрочный интервал',
  29042. letterSpacing: 'Межбуквенный интервал',
  29043. textIndent: 'Отступ',
  29044. increaseIndent: 'Увеличить отступ',
  29045. decreaseIndent: 'Уменьшить отступ',
  29046. italic: 'Курсив',
  29047. underline: 'Подчеркнутый',
  29048. strikeThrough: 'Перечеркнутый',
  29049. fontFamily: 'Шрифт',
  29050. textAlign: 'Расположение текста',
  29051. alignLeft: 'По левому краю',
  29052. alignCenter: 'По центру',
  29053. alignRight: 'По правому краю',
  29054. alignJustify: 'По ширине',
  29055. floatLeft: 'Обтекание слева',
  29056. floatRight: 'Обтекание справа',
  29057. superScript: 'Надстрочный индекс',
  29058. subScript: 'Подстрочный индекс',
  29059. removeStyles: 'Убрать стили',
  29060. headings: 'Заголовки',
  29061. header: 'Заголовок',
  29062. normal: 'Обычный',
  29063. orderedList: 'Упорядоченный список',
  29064. unorderedList: 'Неупорядоченный список',
  29065. blockQuote: 'Цитата',
  29066. code: 'Код',
  29067. link: 'Вставить ссылку',
  29068. unlink: 'Убрать ссылку',
  29069. hr: 'Горизонтальная линия',
  29070. media: 'Медиа',
  29071. mediaLibirary: 'Медиа библиотека',
  29072. emoji: 'Emoji',
  29073. fullscreen: 'Полноэкранный режим',
  29074. exitFullscreen: 'Выйти из полноэкранного режима'
  29075. },
  29076. linkEditor: {
  29077. textInputPlaceHolder: 'Введите текст ссылки',
  29078. linkInputPlaceHolder: 'Вставить ссылку',
  29079. inputWithEnterPlaceHolder: 'Вставить ссылку и нажать Enter',
  29080. openInNewWindow: 'Открыть в новом окне',
  29081. removeLink: 'Убрать ссылку'
  29082. },
  29083. audioPlayer: {
  29084. title: 'Воспроизвести аудиофайл'
  29085. },
  29086. videoPlayer: {
  29087. title: 'Воспроизвести видеофайл',
  29088. embedTitle: 'Embed Media'
  29089. },
  29090. media: {
  29091. image: 'Картинка',
  29092. video: 'Видео',
  29093. audio: 'Аудио',
  29094. embed: 'Встроенное'
  29095. }
  29096. });
  29097. // CONCATENATED MODULE: ./languages/fr.js
  29098. /* harmony default export */ var fr = ({
  29099. base: {
  29100. remove: 'Supprimer',
  29101. cancel: 'Annuler',
  29102. confirm: 'Confirmer',
  29103. inert: 'Insérer',
  29104. width: 'Largeur',
  29105. height: 'Hauteur'
  29106. },
  29107. controls: {
  29108. clear: 'Effacer',
  29109. undo: 'Annuler',
  29110. redo: 'Refaire',
  29111. fontSize: 'Taille de police',
  29112. color: 'Couleur',
  29113. textColor: 'Texte',
  29114. tempColors: 'Couleurs temporaire',
  29115. backgroundColor: 'Couleur d\'arrière plan',
  29116. bold: 'Gras',
  29117. lineHeight: 'Hauteur de ligne',
  29118. letterSpacing: 'Espacement des lettres',
  29119. textIndent: 'Indentation du texte',
  29120. increaseIndent: 'Augmenter l\'indentation',
  29121. decreaseIndent: 'Réduire l\'indentation',
  29122. italic: 'Italique',
  29123. underline: 'Souligner',
  29124. strikeThrough: 'Barrer',
  29125. fontFamily: 'Police d\'écriture',
  29126. textAlign: 'Alignement du texte',
  29127. alignLeft: 'Aligner à gauche',
  29128. alignCenter: 'Aligner au centre',
  29129. alignRight: 'Aligner à droite',
  29130. alignJustify: 'Justifier',
  29131. floatLeft: 'Déplacer à gauche',
  29132. floatRight: 'Déplacer à droite',
  29133. superScript: 'Super-script',
  29134. subScript: 'Sous-script',
  29135. removeStyles: 'Supprimer les styles',
  29136. headings: 'Titres',
  29137. header: 'Entêtes',
  29138. normal: 'Normal',
  29139. orderedList: 'Liste ordonnée',
  29140. unorderedList: 'Liste non-ordonnée',
  29141. blockQuote: 'Citation',
  29142. code: 'Code',
  29143. link: 'Insérer un lien',
  29144. unlink: 'Supprimer le lien',
  29145. hr: 'Ligne horizontale',
  29146. media: 'Média',
  29147. mediaLibirary: 'Bibliothêque',
  29148. emoji: 'Emoji',
  29149. fullscreen: 'Plein écran',
  29150. exitFullscreen: 'Quitter le plein écran'
  29151. },
  29152. linkEditor: {
  29153. textInputPlaceHolder: 'Insérer le texte à afficher',
  29154. linkInputPlaceHolder: 'Insérer le lien URL',
  29155. inputWithEnterPlaceHolder: 'Insérer le lien URL puis appuyer sur Entrée',
  29156. openInNewWindow: 'Ouvrir dans une nouvelle fenêtre',
  29157. removeLink: 'Supprimer le lien'
  29158. },
  29159. audioPlayer: {
  29160. title: 'Lancer le son audio'
  29161. },
  29162. videoPlayer: {
  29163. title: 'Lancer la video',
  29164. embedTitle: 'Intégrer média'
  29165. },
  29166. media: {
  29167. image: 'Image',
  29168. video: 'Vidéo',
  29169. audio: 'Audio',
  29170. embed: 'Intégré'
  29171. }
  29172. });
  29173. // CONCATENATED MODULE: ./languages/pt-br.js
  29174. /* harmony default export */ var pt_br = ({
  29175. base: {
  29176. remove: 'Remover',
  29177. cancel: 'Cancelar',
  29178. confirm: 'Confirmar',
  29179. inert: 'Inserir',
  29180. width: 'Largura',
  29181. height: 'Altura'
  29182. },
  29183. controls: {
  29184. clear: 'Limpar',
  29185. undo: 'Desfazer',
  29186. redo: 'Refazer',
  29187. fontSize: 'Tamanho da Fonte',
  29188. color: 'Cor',
  29189. textColor: 'Texto',
  29190. tempColors: 'Temp Colors',
  29191. backgroundColor: 'Cor de Fundo',
  29192. bold: 'Negrito',
  29193. lineHeight: 'Altura da LinhaLine Height',
  29194. letterSpacing: 'Espaçamento entre Letras',
  29195. textIndent: 'Identação de Texto',
  29196. increaseIndent: 'Aumentar Identação',
  29197. decreaseIndent: 'Diminuir Identção',
  29198. italic: 'Itálico',
  29199. underline: 'Sublinhado',
  29200. strikeThrough: 'Riscado',
  29201. fontFamily: 'Família da Fonte',
  29202. textAlign: 'Alinhamento de Texto',
  29203. alignLeft: 'Alinhamento à Esquerda',
  29204. alignCenter: 'Alinhamento Centralizado',
  29205. alignRight: 'Alinhamento à Direita',
  29206. alignJustify: 'Alinhamento Justificado',
  29207. floatLeft: 'Flutuação à Esquerda',
  29208. floatRight: 'Flutuação à Direita',
  29209. superScript: 'Sobrescrito',
  29210. subScript: 'Subscrito',
  29211. removeStyles: 'Remover Estilos',
  29212. headings: 'Cabeçalhos',
  29213. header: 'Cabeçalho',
  29214. normal: 'Normal',
  29215. orderedList: 'Lista Ordenada',
  29216. unorderedList: 'Lista Não Ordenada',
  29217. blockQuote: 'Citação',
  29218. code: 'Código',
  29219. link: 'Link',
  29220. unlink: 'Remover Link',
  29221. hr: 'Linha Horizontal',
  29222. media: 'Mídia',
  29223. mediaLibirary: 'Biblioteca de Mídia',
  29224. emoji: 'Emoji',
  29225. fullscreen: 'Tela Cheia',
  29226. exitFullscreen: 'Sair de Tela Cheia'
  29227. },
  29228. linkEditor: {
  29229. textInputPlaceHolder: 'Insira o texto do link',
  29230. linkInputPlaceHolder: 'Insira a URL do link',
  29231. inputWithEnterPlaceHolder: 'Insira a URL do link e aperte Enter',
  29232. openInNewWindow: 'Abrir em nova janela',
  29233. removeLink: 'Remover Link'
  29234. },
  29235. audioPlayer: {
  29236. title: 'Tocar Áudio'
  29237. },
  29238. videoPlayer: {
  29239. title: 'Tocar Vídeo',
  29240. embedTitle: 'Mídia Embutida'
  29241. },
  29242. media: {
  29243. image: 'Imagem',
  29244. video: 'Vídeo',
  29245. audio: 'Áudio',
  29246. embed: 'Embutido'
  29247. }
  29248. });
  29249. // CONCATENATED MODULE: ./languages/index.js
  29250. /* harmony default export */ var languages = ({
  29251. 'en': en,
  29252. 'zh': zh,
  29253. 'zh-hant': zh_hant,
  29254. 'pl': pl,
  29255. 'kr': kr,
  29256. 'tr': tr,
  29257. 'jpn': jpn,
  29258. 'ru': ru,
  29259. 'fr': fr,
  29260. 'pt-br': pt_br
  29261. });
  29262. // EXTERNAL MODULE: external "braft-finder"
  29263. var external_braft_finder_ = __webpack_require__(17);
  29264. var external_braft_finder_default = /*#__PURE__*/__webpack_require__.n(external_braft_finder_);
  29265. // EXTERNAL MODULE: external "braft-utils"
  29266. var external_braft_utils_ = __webpack_require__(3);
  29267. // EXTERNAL MODULE: external "draft-js"
  29268. var external_draft_js_ = __webpack_require__(6);
  29269. // EXTERNAL MODULE: external "immutable"
  29270. var external_immutable_ = __webpack_require__(13);
  29271. var external_immutable_default = /*#__PURE__*/__webpack_require__.n(external_immutable_);
  29272. // CONCATENATED MODULE: ./configs/keybindings.js
  29273. // TODO
  29274. // 允许自定义的快捷键设置
  29275. /* harmony default export */ var keybindings = (function (customKeyBindingFn) {
  29276. return function (event) {
  29277. if (event.keyCode === 83 && (external_draft_js_["KeyBindingUtil"].hasCommandModifier(event) || external_draft_js_["KeyBindingUtil"].isCtrlKeyCommand(event))) {
  29278. return 'braft-save';
  29279. }
  29280. if (customKeyBindingFn) {
  29281. return customKeyBindingFn(event) || Object(external_draft_js_["getDefaultKeyBinding"])(event);
  29282. }
  29283. return Object(external_draft_js_["getDefaultKeyBinding"])(event);
  29284. };
  29285. });
  29286. // CONCATENATED MODULE: ./configs/props.js
  29287. /* harmony default export */ var configs_props = ({
  29288. language: 'zh',
  29289. 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'],
  29290. excludeControls: [],
  29291. extendControls: [],
  29292. extendAtomics: [],
  29293. componentBelowControlBar: null,
  29294. media: {
  29295. pasteImage: true,
  29296. imagePasteLimit: 5,
  29297. image: true,
  29298. video: true,
  29299. audio: true,
  29300. uploadFn: null,
  29301. validateFn: null,
  29302. onBeforeDeselect: null,
  29303. onDeselect: null,
  29304. onBeforeSelect: null,
  29305. onSelect: null,
  29306. onBeforeRemove: null,
  29307. onRemove: null,
  29308. onCancel: null,
  29309. onFileSelect: null,
  29310. onBeforeInsert: null,
  29311. onInsert: null,
  29312. onChange: null,
  29313. accepts: {
  29314. image: 'image/png,image/jpeg,image/gif,image/webp,image/apng,image/svg',
  29315. video: 'video/mp4',
  29316. audio: 'audio/mp3'
  29317. },
  29318. externals: {
  29319. audio: true,
  29320. video: true,
  29321. image: true,
  29322. embed: true
  29323. }
  29324. },
  29325. imageControls: ['float-left', 'float-right', 'align-left', 'align-center', 'align-right', 'link', 'size', 'remove'],
  29326. imageResizable: true,
  29327. colors: ['#000000', '#333333', '#666666', '#999999', '#cccccc', '#ffffff', '#61a951', '#16a085', '#07a9fe', '#003ba5', '#8e44ad', '#f32784', '#c0392b', '#d35400', '#f39c12', '#fdda00'],
  29328. colorPicker: null,
  29329. colorPickerTheme: 'dark',
  29330. colorPickerAutoHide: true,
  29331. codeTabIndents: 2,
  29332. headings: ['header-one', 'header-two', 'header-three', 'header-four', 'header-five', 'header-six', 'unstyled'],
  29333. textAligns: ['left', 'center', 'right', 'justify'],
  29334. textBackgroundColor: true,
  29335. allowInsertLinkText: false,
  29336. defaultLinkTarget: '',
  29337. letterSpacings: [0, 1, 2, 3, 4, 5, 6],
  29338. lineHeights: [1, 1.2, 1.5, 1.75, 2, 2.5, 3, 4],
  29339. fontSizes: [12, 14, 16, 18, 20, 24, 28, 30, 32, 36, 40, 48, 56, 64, 72, 96, 120, 144],
  29340. fontFamilies: [{
  29341. name: 'Araial',
  29342. family: 'Arial, Helvetica, sans-serif'
  29343. }, {
  29344. name: 'Georgia',
  29345. family: 'Georgia, serif'
  29346. }, {
  29347. name: 'Impact',
  29348. family: 'Impact, serif'
  29349. }, {
  29350. name: 'Monospace',
  29351. family: '"Courier New", Courier, monospace'
  29352. }, {
  29353. name: 'Tahoma',
  29354. family: 'tahoma, arial, "Hiragino Sans GB", 宋体, sans-serif'
  29355. }],
  29356. converts: {
  29357. unitExportFn: function unitExportFn(value, type) {
  29358. return type === 'line-height' ? value : "".concat(value, "px");
  29359. }
  29360. },
  29361. emojis: ['🤣', '🙌', '💚', '💛', '👏', '😉', '💯', '💕', '💞', '💘', '💙', '💝', '🖤', '💜', '❤️', '😍', '😻', '💓', '💗', '😋', '😇', '😂', '😹', '😘', '💖', '😁', '😀', '🤞', '😲', '😄', '😊', '👍', '😌', '😃', '😅', '✌️', '🤗', '💋', '😗', '😽', '😚', '🤠', '😙', '😺', '👄', '😸', '😏', '😼', '👌', '😎', '😆', '😛', '🙏', '🤝', '🙂', '🤑', '😝', '😐', '😑', '🤤', '😤', '🙃', '🤡', '😶', '😪', '😴', '😵', '😓', '👊', '😦', '😷', '🤐', '😜', '🤓', '👻', '😥', '🙄', '🤔', '🤒', '🙁', '😔', '😯', '☹️', '☠️', '😰', '😩', '😖', '😕', '😒', '😣', '😢', '😮', '😿', '🤧', '😫', '🤥', '😞', '😬', '👎', '💀', '😳', '😨', '🤕', '🤢', '😱', '😭', '😠', '😈', '😧', '💔', '😟', '🙀', '💩', '👿', '😡', '😾', '🖕'],
  29362. stripPastedStyles: false,
  29363. triggerChangeOnMount: true,
  29364. className: '',
  29365. style: {},
  29366. controlBarClassName: '',
  29367. controlBarStyle: {},
  29368. contentClassName: '',
  29369. contentStyle: {},
  29370. draftProps: {},
  29371. hooks: {},
  29372. onChange: null,
  29373. onFocus: null,
  29374. onBlur: null,
  29375. onTab: null,
  29376. onDelete: null,
  29377. onSave: null,
  29378. fixPlaceholder: false
  29379. });
  29380. // EXTERNAL MODULE: ../node_modules/draft-js/lib/getFragmentFromSelection.js
  29381. var getFragmentFromSelection = __webpack_require__(22);
  29382. var getFragmentFromSelection_default = /*#__PURE__*/__webpack_require__.n(getFragmentFromSelection);
  29383. // EXTERNAL MODULE: external "draftjs-utils"
  29384. var external_draftjs_utils_ = __webpack_require__(23);
  29385. // CONCATENATED MODULE: ./configs/handlers.js
  29386. var handlers_keyCommandHandlers = function keyCommandHandlers(command, editorState, editor) {
  29387. if (editor.editorProps.handleKeyCommand && editor.editorProps.handleKeyCommand(command, editorState, editor) === 'handled') {
  29388. return 'handled';
  29389. }
  29390. if (command === 'braft-save') {
  29391. editor.editorProps.onSave && editor.editorProps.onSave(editorState);
  29392. return 'handled';
  29393. }
  29394. var _editor$editorProps = editor.editorProps,
  29395. controls = _editor$editorProps.controls,
  29396. excludeControls = _editor$editorProps.excludeControls;
  29397. var allowIndent = (controls.indexOf('text-indent') !== 0 || controls.find(function (item) {
  29398. return item.key === 'text-indent';
  29399. })) && excludeControls.indexOf('text-indent') === -1;
  29400. var cursorStart = editorState.getSelection().getStartOffset();
  29401. var cursorEnd = editorState.getSelection().getEndOffset();
  29402. var cursorIsAtFirst = cursorStart === 0 && cursorEnd === 0;
  29403. if (command === 'backspace') {
  29404. if (editor.editorProps.onDelete && editor.editorProps.onDelete(editorState) === false) {
  29405. return 'handled';
  29406. }
  29407. var blockType = external_braft_utils_["ContentUtils"].getSelectionBlockType(editorState);
  29408. if (allowIndent && cursorIsAtFirst && blockType !== 'code-block') {
  29409. editor.setValue(external_braft_utils_["ContentUtils"].decreaseSelectionIndent(editorState));
  29410. }
  29411. }
  29412. if (command === 'tab') {
  29413. var _blockType = external_braft_utils_["ContentUtils"].getSelectionBlockType(editorState);
  29414. if (_blockType === 'code-block') {
  29415. editor.setValue(external_braft_utils_["ContentUtils"].insertText(editorState, ' '.repeat(editor.editorProps.codeTabIndents)));
  29416. return 'handled';
  29417. } else if (_blockType === 'ordered-list-item' || _blockType === 'unordered-list-item') {
  29418. var newEditorState = external_draft_js_["RichUtils"].onTab(event, editorState, 4);
  29419. if (newEditorState !== editorState) {
  29420. editor.setValue(newEditorState);
  29421. }
  29422. return 'handled';
  29423. } else if (_blockType !== 'atomic' && allowIndent && cursorIsAtFirst) {
  29424. editor.setValue(external_braft_utils_["ContentUtils"].increaseSelectionIndent(editorState));
  29425. return 'handled';
  29426. }
  29427. }
  29428. var nextEditorState = external_braft_utils_["ContentUtils"].handleKeyCommand(editorState, command);
  29429. if (nextEditorState) {
  29430. editor.setValue(nextEditorState);
  29431. return 'handled';
  29432. }
  29433. return 'not-handled';
  29434. };
  29435. var handlers_returnHandlers = function returnHandlers(event, editorState, editor) {
  29436. if (editor.editorProps.handleReturn && editor.editorProps.handleReturn(event, editorState, editor) === 'handled') {
  29437. return 'handled';
  29438. }
  29439. var currentBlock = external_braft_utils_["ContentUtils"].getSelectionBlock(editorState);
  29440. var currentBlockType = currentBlock.getType();
  29441. if (currentBlockType === 'unordered-list-item' || currentBlockType === 'ordered-list-item') {
  29442. if (currentBlock.getLength() === 0) {
  29443. editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionBlockType(editorState, 'unstyled'));
  29444. return 'handled';
  29445. }
  29446. return 'not-handled';
  29447. } else if (currentBlockType === 'code-block') {
  29448. if (event.which === 13 && (event.getModifierState('Shift') || event.getModifierState('Alt') || event.getModifierState('Control'))) {
  29449. editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionBlockType(editorState, 'unstyled'));
  29450. return 'handled';
  29451. }
  29452. return 'not-handled';
  29453. } else if (currentBlockType === 'blockquote') {
  29454. if (event.which === 13) {
  29455. if (event.getModifierState('Shift') || event.getModifierState('Alt') || event.getModifierState('Control')) {
  29456. event.which = 0;
  29457. } else {
  29458. editor.setValue(external_draft_js_["RichUtils"].insertSoftNewline(editorState));
  29459. return 'handled';
  29460. }
  29461. }
  29462. }
  29463. var nextEditorState = Object(external_draftjs_utils_["handleNewLine"])(editorState, event);
  29464. if (nextEditorState) {
  29465. editor.setValue(nextEditorState);
  29466. return 'handled';
  29467. }
  29468. return 'not-handled';
  29469. };
  29470. var beforeInputHandlers = function beforeInputHandlers(chars, editorState, editor) {
  29471. if (editor.editorProps.handleBeforeInput && editor.editorProps.handleBeforeInput(chars, editorState, editor) === 'handled') {
  29472. return 'handled';
  29473. }
  29474. return 'not-handled';
  29475. };
  29476. var handlers_compositionStartHandler = function compositionStartHandler(_, editor) {
  29477. var editorState = editor.state.editorState;
  29478. var selectedBlocks = external_braft_utils_["ContentUtils"].getSelectedBlocks(editorState);
  29479. if (selectedBlocks && selectedBlocks.length > 1) {
  29480. var nextEditorState = external_draft_js_["EditorState"].push(editorState, external_draft_js_["Modifier"].removeRange(editorState.getCurrentContent(), editorState.getSelection(), 'backward'), 'remove-range');
  29481. editor.setValue(nextEditorState);
  29482. }
  29483. };
  29484. var handlers_dropHandlers = function dropHandlers(selectionState, dataTransfer, editor) {
  29485. if (editor.editorProps.readOnly || editor.editorProps.disabled) {
  29486. return 'handled';
  29487. }
  29488. if (window && window.__BRAFT_DRAGING__IMAGE__) {
  29489. var nextEditorState = external_draft_js_["EditorState"].forceSelection(editor.state.editorState, selectionState);
  29490. nextEditorState = external_braft_utils_["ContentUtils"].insertMedias(nextEditorState, [window.__BRAFT_DRAGING__IMAGE__.mediaData]);
  29491. nextEditorState = external_braft_utils_["ContentUtils"].removeBlock(nextEditorState, window.__BRAFT_DRAGING__IMAGE__.block, nextEditorState.getSelection());
  29492. window.__BRAFT_DRAGING__IMAGE__ = null;
  29493. editor.lockOrUnlockEditor(true);
  29494. editor.setValue(nextEditorState);
  29495. return 'handled';
  29496. } else if (!dataTransfer || !dataTransfer.getText()) {
  29497. return 'handled';
  29498. }
  29499. return 'not-handled';
  29500. };
  29501. var handlers_handleFiles = function handleFiles(files, editor) {
  29502. var _editor$constructor$d = objectSpread_default()({}, editor.constructor.defaultProps.media, editor.editorProps.media),
  29503. pasteImage = _editor$constructor$d.pasteImage,
  29504. validateFn = _editor$constructor$d.validateFn,
  29505. imagePasteLimit = _editor$constructor$d.imagePasteLimit;
  29506. pasteImage && files.slice(0, imagePasteLimit).forEach(function (file) {
  29507. if (file && file.type.indexOf('image') > -1 && editor.braftFinder) {
  29508. var validateResult = validateFn ? validateFn(file) : true;
  29509. if (validateResult instanceof Promise) {
  29510. validateResult.then(function () {
  29511. editor.braftFinder.uploadImage(file, function (image) {
  29512. editor.isLiving && editor.setValue(external_braft_utils_["ContentUtils"].insertMedias(editor.state.editorState, [image]));
  29513. });
  29514. });
  29515. } else if (validateResult) {
  29516. editor.braftFinder.uploadImage(file, function (image) {
  29517. editor.isLiving && editor.setValue(external_braft_utils_["ContentUtils"].insertMedias(editor.state.editorState, [image]));
  29518. });
  29519. }
  29520. }
  29521. });
  29522. if (files[0] && files[0].type.indexOf('image') > -1 && pasteImage) {
  29523. return 'handled';
  29524. }
  29525. return 'not-handled';
  29526. };
  29527. var droppedFilesHandlers = function droppedFilesHandlers(selectionState, files, editor) {
  29528. if (editor.editorProps.handleDroppedFiles && editor.editorProps.handleDroppedFiles(selectionState, files, editor) === 'handled') {
  29529. return 'handled';
  29530. }
  29531. return handlers_handleFiles(files, editor);
  29532. };
  29533. var pastedFilesHandlers = function pastedFilesHandlers(files, editor) {
  29534. if (editor.editorProps.handlePastedFiles && editor.editorProps.handlePastedFiles(files, editor) === 'handled') {
  29535. return 'handled';
  29536. }
  29537. return handlers_handleFiles(files, editor);
  29538. };
  29539. var handlers_copyHandlers = function copyHandlers(event, editor) {
  29540. var blockMap = getFragmentFromSelection_default()(editor.state.editorState);
  29541. if (blockMap && blockMap.toArray) {
  29542. try {
  29543. var tempContentState = external_draft_js_["ContentState"].createFromBlockArray(blockMap.toArray());
  29544. var tempEditorState = external_draft_js_["EditorState"].createWithContent(tempContentState);
  29545. var clipboardData = event.clipboardData || window.clipboardData || event.originalEvent.clipboardData;
  29546. tempEditorState.setConvertOptions(editor.state.editorState.convertOptions);
  29547. clipboardData.setData('text/html', tempEditorState.toHTML());
  29548. clipboardData.setData('text/plain', tempEditorState.toText());
  29549. event.preventDefault();
  29550. } catch (error) {
  29551. console.warn(error);
  29552. }
  29553. }
  29554. };
  29555. var handlers_pastedTextHandlers = function pastedTextHandlers(text, html, editorState, editor) {
  29556. if (editor.editorProps.handlePastedText && editor.editorProps.handlePastedText(text, html, editorState, editor) === 'handled') {
  29557. return 'handled';
  29558. }
  29559. if (!html || editor.editorProps.stripPastedStyles) {
  29560. return false;
  29561. }
  29562. var tempColors = external_braft_utils_["ColorUtils"].detectColorsFromHTMLString(html);
  29563. editor.setState({
  29564. tempColors: toConsumableArray_default()(editor.state.tempColors).concat(toConsumableArray_default()(tempColors)).filter(function (item) {
  29565. return editor.editorProps.colors.indexOf(item) === -1;
  29566. }).filter(function (item, index, array) {
  29567. return array.indexOf(item) === index;
  29568. })
  29569. }, function () {
  29570. editor.setValue(external_braft_utils_["ContentUtils"].insertHTML(editorState, html, 'paste'));
  29571. });
  29572. return 'handled';
  29573. };
  29574. // CONCATENATED MODULE: ./helpers/extension.js
  29575. // TODO
  29576. // - block-style和atomic类型的扩展支持
  29577. var extension_extensionControls = [];
  29578. var extension_extensionDecorators = [];
  29579. var extension_propInterceptors = [];
  29580. var extension_extensionBlockRenderMaps = [];
  29581. var extension_extensionBlockRendererFns = [];
  29582. var extensionInlineStyleMaps = [];
  29583. var extension_extensionInlineStyleFns = [];
  29584. var extensionEntities = [];
  29585. var inlineStyleImporters = [];
  29586. var inlineStyleExporters = [];
  29587. var blockImporters = [];
  29588. var blockExporters = [];
  29589. var filterByEditorId = function filterByEditorId(items, editorId) {
  29590. if (!editorId) {
  29591. return items.filter(function (item) {
  29592. return !item.includeEditors;
  29593. }).map(function (item) {
  29594. return item.data;
  29595. });
  29596. }
  29597. return items.map(function (item) {
  29598. if (!item.includeEditors && !item.excludeEditors) {
  29599. return item.data;
  29600. }
  29601. if (item.includeEditors) {
  29602. return item.includeEditors.indexOf(editorId) !== -1 ? item.data : false;
  29603. }
  29604. if (item.excludeEditors) {
  29605. return item.excludeEditors.indexOf(editorId) !== -1 ? false : item.data;
  29606. }
  29607. return false;
  29608. }).filter(function (item) {
  29609. return item;
  29610. });
  29611. };
  29612. var getPropInterceptors = function getPropInterceptors(editorId) {
  29613. return filterByEditorId(extension_propInterceptors, editorId);
  29614. };
  29615. var getExtensionControls = function getExtensionControls(editorId) {
  29616. return filterByEditorId(extension_extensionControls, editorId);
  29617. };
  29618. var getExtensionDecorators = function getExtensionDecorators(editorId) {
  29619. return filterByEditorId(extension_extensionDecorators, editorId);
  29620. };
  29621. var getExtensionBlockRenderMaps = function getExtensionBlockRenderMaps(editorId) {
  29622. return filterByEditorId(extension_extensionBlockRenderMaps, editorId);
  29623. };
  29624. var getExtensionBlockRendererFns = function getExtensionBlockRendererFns(editorId) {
  29625. return filterByEditorId(extension_extensionBlockRendererFns, editorId);
  29626. };
  29627. var getExtensionInlineStyleMap = function getExtensionInlineStyleMap(editorId) {
  29628. var inlineStyleMap = {};
  29629. filterByEditorId(extensionInlineStyleMaps, editorId).forEach(function (item) {
  29630. inlineStyleMap[item.inlineStyleName] = item.styleMap;
  29631. });
  29632. return inlineStyleMap;
  29633. };
  29634. var getExtensionInlineStyleFns = function getExtensionInlineStyleFns(editorId) {
  29635. return filterByEditorId(extension_extensionInlineStyleFns, editorId);
  29636. };
  29637. var compositeStyleImportFn = function compositeStyleImportFn(styleImportFn, editorId) {
  29638. return function (nodeName, node, style) {
  29639. filterByEditorId(inlineStyleImporters, editorId).forEach(function (styleImporter) {
  29640. if (styleImporter.importer && styleImporter.importer(nodeName, node)) {
  29641. style = style.add(styleImporter.inlineStyleName);
  29642. }
  29643. });
  29644. return styleImportFn ? styleImportFn(nodeName, node, style) : style;
  29645. };
  29646. };
  29647. var compositeStyleExportFn = function compositeStyleExportFn(styleExportFn, editorId) {
  29648. return function (style) {
  29649. style = style.toUpperCase();
  29650. var result = styleExportFn ? styleExportFn(style) : undefined;
  29651. if (result) {
  29652. return result;
  29653. }
  29654. filterByEditorId(inlineStyleExporters, editorId).find(function (item) {
  29655. if (item.inlineStyleName === style) {
  29656. result = item.exporter;
  29657. return true;
  29658. }
  29659. });
  29660. return result;
  29661. };
  29662. };
  29663. var compositeEntityImportFn = function compositeEntityImportFn(entityImportFn, editorId) {
  29664. return function (nodeName, node, createEntity, source) {
  29665. var result = entityImportFn ? entityImportFn(nodeName, node, createEntity, source) : null;
  29666. if (result) {
  29667. return result;
  29668. }
  29669. filterByEditorId(extensionEntities, editorId).find(function (entityItem) {
  29670. var matched = entityItem.importer ? entityItem.importer(nodeName, node, source) : null;
  29671. matched && (result = createEntity(entityItem.entityType, matched.mutability || 'MUTABLE', matched.data || {}));
  29672. return !!matched;
  29673. });
  29674. return result;
  29675. };
  29676. };
  29677. var compositeEntityExportFn = function compositeEntityExportFn(entityExportFn, editorId) {
  29678. return function (entity, originalText) {
  29679. var result = entityExportFn ? entityExportFn(entity, originalText) : undefined;
  29680. if (result) {
  29681. return result;
  29682. }
  29683. var entityType = entity.type.toUpperCase();
  29684. filterByEditorId(extensionEntities, editorId).find(function (entityItem) {
  29685. if (entityItem.entityType === entityType) {
  29686. result = entityItem.exporter ? entityItem.exporter(entity, originalText) : undefined;
  29687. return true;
  29688. }
  29689. });
  29690. return result;
  29691. };
  29692. };
  29693. var compositeBlockImportFn = function compositeBlockImportFn(blockImportFn, editorId) {
  29694. return function (nodeName, node, source) {
  29695. var result = blockImportFn ? blockImportFn(nodeName, node, source) : null;
  29696. if (result) {
  29697. return result;
  29698. }
  29699. filterByEditorId(blockImporters, editorId).find(function (blockImporter) {
  29700. var matched = blockImporter.importer ? blockImporter.importer(nodeName, node, source) : undefined;
  29701. matched && (result = matched);
  29702. return !!matched;
  29703. });
  29704. return result;
  29705. };
  29706. };
  29707. var compositeBlockExportFn = function compositeBlockExportFn(blockExportFn, editorId) {
  29708. return function (contentState, block) {
  29709. var result = blockExportFn ? blockExportFn(contentState, block) : null;
  29710. if (result) {
  29711. return result;
  29712. }
  29713. filterByEditorId(blockExporters, editorId).find(function (blockExporter) {
  29714. var matched = blockExporter.exporter ? blockExporter.exporter(contentState, block) : undefined;
  29715. matched && (result = matched);
  29716. return !!matched;
  29717. });
  29718. return result;
  29719. };
  29720. };
  29721. var extension_useExtension = function useExtension(extension) {
  29722. if (extension instanceof Array) {
  29723. extension.forEach(useExtension);
  29724. return false;
  29725. }
  29726. if (!extension || !extension.type || typeof extension.type !== 'string') {
  29727. return false;
  29728. }
  29729. var includeEditors = extension.includeEditors,
  29730. excludeEditors = extension.excludeEditors;
  29731. if (extension.type === 'control') {
  29732. extension_extensionControls.push({
  29733. includeEditors: includeEditors,
  29734. excludeEditors: excludeEditors,
  29735. data: extension.control
  29736. });
  29737. } else if (extension.type === 'inline-style') {
  29738. var inlineStyleName = extension.name.toUpperCase();
  29739. if (extension.control) {
  29740. extension_extensionControls.push({
  29741. includeEditors: includeEditors,
  29742. excludeEditors: excludeEditors,
  29743. data: objectSpread_default()({
  29744. key: inlineStyleName,
  29745. type: 'inline-style',
  29746. command: inlineStyleName
  29747. }, extension.control)
  29748. });
  29749. }
  29750. if (extension.style) {
  29751. extensionInlineStyleMaps.push({
  29752. includeEditors: includeEditors,
  29753. excludeEditors: excludeEditors,
  29754. data: {
  29755. inlineStyleName: inlineStyleName,
  29756. styleMap: extension.style
  29757. }
  29758. });
  29759. }
  29760. if (extension.styleFn) {
  29761. extension_extensionInlineStyleFns.push({
  29762. includeEditors: includeEditors,
  29763. excludeEditors: excludeEditors,
  29764. data: {
  29765. inlineStyleName: inlineStyleName,
  29766. styleFn: extension.styleFn
  29767. }
  29768. });
  29769. }
  29770. if (extension.importer) {
  29771. inlineStyleImporters.push({
  29772. includeEditors: includeEditors,
  29773. excludeEditors: excludeEditors,
  29774. data: {
  29775. inlineStyleName: inlineStyleName,
  29776. importer: extension.importer
  29777. }
  29778. });
  29779. }
  29780. inlineStyleExporters.push({
  29781. includeEditors: includeEditors,
  29782. excludeEditors: excludeEditors,
  29783. data: {
  29784. inlineStyleName: inlineStyleName,
  29785. exporter: extension.exporter ? extension.exporter(extension) : external_react_default.a.createElement("span", {
  29786. style: extension.style
  29787. })
  29788. }
  29789. });
  29790. } else if (extension.type === 'block-style') ; else if (extension.type === 'entity') {
  29791. var entityType = extension.name.toUpperCase();
  29792. if (extension.control) {
  29793. extension_extensionControls.push({
  29794. includeEditors: includeEditors,
  29795. excludeEditors: excludeEditors,
  29796. data: typeof extension.control === 'function' ? extension.control : objectSpread_default()({
  29797. key: entityType,
  29798. type: 'entity',
  29799. command: entityType,
  29800. data: {
  29801. mutability: extension.mutability || 'MUTABLE',
  29802. data: extension.data || {}
  29803. }
  29804. }, extension.control)
  29805. });
  29806. }
  29807. extensionEntities.push({
  29808. includeEditors: includeEditors,
  29809. excludeEditors: excludeEditors,
  29810. data: {
  29811. entityType: entityType,
  29812. importer: extension.importer,
  29813. exporter: extension.exporter
  29814. }
  29815. });
  29816. extension_extensionDecorators.push({
  29817. includeEditors: includeEditors,
  29818. excludeEditors: excludeEditors,
  29819. data: {
  29820. type: 'entity',
  29821. decorator: {
  29822. key: entityType,
  29823. component: extension.component
  29824. }
  29825. }
  29826. });
  29827. } else if (extension.type === 'block') {
  29828. var blockType = extension.name;
  29829. if (extension.renderMap) {
  29830. extension_extensionBlockRenderMaps.push({
  29831. includeEditors: includeEditors,
  29832. excludeEditors: excludeEditors,
  29833. data: {
  29834. blockType: blockType,
  29835. renderMap: extension.renderMap
  29836. }
  29837. });
  29838. }
  29839. if (extension.rendererFn) {
  29840. extension_extensionBlockRendererFns.push({
  29841. includeEditors: includeEditors,
  29842. excludeEditors: excludeEditors,
  29843. data: {
  29844. blockType: blockType,
  29845. rendererFn: extension.rendererFn
  29846. }
  29847. });
  29848. }
  29849. if (extension.importer) {
  29850. blockImporters.push({
  29851. includeEditors: includeEditors,
  29852. excludeEditors: excludeEditors,
  29853. data: {
  29854. blockType: blockType,
  29855. importer: extension.importer
  29856. }
  29857. });
  29858. }
  29859. if (extension.exporter) {
  29860. blockExporters.push({
  29861. includeEditors: includeEditors,
  29862. excludeEditors: excludeEditors,
  29863. data: {
  29864. blockType: blockType,
  29865. exporter: extension.exporter
  29866. }
  29867. });
  29868. }
  29869. } else if (extension.type === 'atomic') ; else if (extension.type === 'decorator') {
  29870. var decorator = extension.decorator;
  29871. if (decorator && decorator.strategy && decorator.component) {
  29872. extension_extensionDecorators.push({
  29873. includeEditors: includeEditors,
  29874. excludeEditors: excludeEditors,
  29875. data: {
  29876. type: 'strategy',
  29877. decorator: decorator
  29878. }
  29879. });
  29880. } else if (decorator && decorator.getDecorations) {
  29881. extension_extensionDecorators.push({
  29882. includeEditors: includeEditors,
  29883. excludeEditors: excludeEditors,
  29884. data: {
  29885. type: 'class',
  29886. decorator: decorator
  29887. }
  29888. });
  29889. }
  29890. } else if (extension.type === 'prop-interception') {
  29891. extension_propInterceptors.push({
  29892. includeEditors: includeEditors,
  29893. excludeEditors: excludeEditors,
  29894. data: extension.interceptor
  29895. });
  29896. }
  29897. };
  29898. var createExtensibleEditor = function createExtensibleEditor(BraftEditor) {
  29899. BraftEditor.use = extension_useExtension;
  29900. return BraftEditor;
  29901. };
  29902. // CONCATENATED MODULE: ./renderers/block/blockRenderMap.js
  29903. /* harmony default export */ var block_blockRenderMap = (function (props, blockRenderMap) {
  29904. var customBlockRenderMap = Object(external_immutable_["Map"])({
  29905. 'atomic': {
  29906. element: ''
  29907. },
  29908. 'code-block': {
  29909. element: 'code',
  29910. wrapper: external_react_default.a.createElement("pre", {
  29911. className: "braft-code-block"
  29912. })
  29913. }
  29914. });
  29915. try {
  29916. var extensionBlockRenderMaps = getExtensionBlockRenderMaps(props.editorId);
  29917. customBlockRenderMap = extensionBlockRenderMaps.reduce(function (customBlockRenderMap, item) {
  29918. return customBlockRenderMap.merge(typeof item.renderMap === 'function' ? item.renderMap(props) : item.renderMap);
  29919. }, customBlockRenderMap);
  29920. if (blockRenderMap) {
  29921. if (typeof blockRenderMap === 'function') {
  29922. customBlockRenderMap = customBlockRenderMap.merge(blockRenderMap(props));
  29923. } else {
  29924. customBlockRenderMap = customBlockRenderMap.merge(blockRenderMap);
  29925. }
  29926. }
  29927. customBlockRenderMap = external_draft_js_["DefaultDraftBlockRenderMap"].merge(customBlockRenderMap);
  29928. } catch (error) {
  29929. console.warn(error);
  29930. }
  29931. return customBlockRenderMap;
  29932. });
  29933. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/extends.js
  29934. var helpers_extends = __webpack_require__(11);
  29935. var extends_default = /*#__PURE__*/__webpack_require__.n(helpers_extends);
  29936. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/slicedToArray.js
  29937. var slicedToArray = __webpack_require__(24);
  29938. var slicedToArray_default = /*#__PURE__*/__webpack_require__.n(slicedToArray);
  29939. // EXTERNAL MODULE: ./renderers/atomics/Image/style.scss
  29940. var Image_style = __webpack_require__(45);
  29941. // EXTERNAL MODULE: ./components/common/Switch/style.scss
  29942. var Switch_style = __webpack_require__(46);
  29943. // CONCATENATED MODULE: ./components/common/Switch/index.jsx
  29944. /* harmony default export */ var Switch = (function (props) {
  29945. var active = props.active,
  29946. _onClick = props.onClick,
  29947. className = props.className;
  29948. return external_react_default.a.createElement("div", {
  29949. onClick: function onClick() {
  29950. return _onClick();
  29951. },
  29952. className: 'bf-switch ' + className + (active ? ' active' : '')
  29953. });
  29954. });
  29955. // CONCATENATED MODULE: ./configs/controls.js
  29956. /* harmony default export */ var configs_controls = (function (lang, editor) {
  29957. return [{
  29958. key: 'undo',
  29959. title: lang.controls.undo,
  29960. text: external_react_default.a.createElement("i", {
  29961. className: "bfi-undo"
  29962. }),
  29963. type: 'editor-method',
  29964. command: 'undo'
  29965. }, {
  29966. key: 'redo',
  29967. title: lang.controls.redo,
  29968. text: external_react_default.a.createElement("i", {
  29969. className: "bfi-redo"
  29970. }),
  29971. type: 'editor-method',
  29972. command: 'redo'
  29973. }, {
  29974. key: 'remove-styles',
  29975. title: lang.controls.removeStyles,
  29976. text: external_react_default.a.createElement("i", {
  29977. className: "bfi-format_clear"
  29978. }),
  29979. type: 'editor-method',
  29980. command: 'removeSelectionInlineStyles'
  29981. }, {
  29982. key: 'hr',
  29983. title: lang.controls.hr,
  29984. text: external_react_default.a.createElement("i", {
  29985. className: "bfi-hr"
  29986. }),
  29987. type: 'editor-method',
  29988. command: 'insertHorizontalLine'
  29989. }, {
  29990. key: 'bold',
  29991. title: lang.controls.bold,
  29992. text: external_react_default.a.createElement("i", {
  29993. className: "bfi-bold"
  29994. }),
  29995. type: 'inline-style',
  29996. command: 'bold'
  29997. }, {
  29998. key: 'italic',
  29999. title: lang.controls.italic,
  30000. text: external_react_default.a.createElement("i", {
  30001. className: "bfi-italic"
  30002. }),
  30003. type: 'inline-style',
  30004. command: 'italic'
  30005. }, {
  30006. key: 'underline',
  30007. title: lang.controls.underline,
  30008. text: external_react_default.a.createElement("i", {
  30009. className: "bfi-underlined"
  30010. }),
  30011. type: 'inline-style',
  30012. command: 'underline'
  30013. }, {
  30014. key: 'strike-through',
  30015. title: lang.controls.strikeThrough,
  30016. text: external_react_default.a.createElement("i", {
  30017. className: "bfi-strikethrough"
  30018. }),
  30019. type: 'inline-style',
  30020. command: 'strikethrough'
  30021. }, {
  30022. key: 'superscript',
  30023. title: lang.controls.superScript,
  30024. text: external_react_default.a.createElement("i", {
  30025. className: "bfi-superscript"
  30026. }),
  30027. type: 'inline-style',
  30028. command: 'superscript'
  30029. }, {
  30030. key: 'subscript',
  30031. title: lang.controls.subScript,
  30032. text: external_react_default.a.createElement("i", {
  30033. className: "bfi-subscript"
  30034. }),
  30035. type: 'inline-style',
  30036. command: 'subscript'
  30037. }, {
  30038. key: 'headings',
  30039. title: lang.controls.headings,
  30040. type: 'headings'
  30041. }, {
  30042. key: 'blockquote',
  30043. title: lang.controls.blockQuote,
  30044. text: external_react_default.a.createElement("i", {
  30045. className: "bfi-quote"
  30046. }),
  30047. type: 'block-type',
  30048. command: 'blockquote'
  30049. }, {
  30050. key: 'code',
  30051. title: lang.controls.code,
  30052. text: external_react_default.a.createElement("i", {
  30053. className: "bfi-code"
  30054. }),
  30055. type: 'block-type',
  30056. command: 'code-block'
  30057. }, {
  30058. key: 'list-ul',
  30059. title: lang.controls.unorderedList,
  30060. text: external_react_default.a.createElement("i", {
  30061. className: "bfi-list"
  30062. }),
  30063. type: 'block-type',
  30064. command: 'unordered-list-item'
  30065. }, {
  30066. key: 'list-ol',
  30067. title: lang.controls.orderedList,
  30068. text: external_react_default.a.createElement("i", {
  30069. className: "bfi-list-numbered"
  30070. }),
  30071. type: 'block-type',
  30072. command: 'ordered-list-item'
  30073. }, {
  30074. key: 'link',
  30075. title: lang.controls.link,
  30076. type: 'link'
  30077. }, {
  30078. key: 'text-color',
  30079. title: lang.controls.color,
  30080. type: 'text-color'
  30081. }, {
  30082. key: 'line-height',
  30083. title: lang.controls.lineHeight,
  30084. type: 'line-height'
  30085. }, {
  30086. key: 'letter-spacing',
  30087. title: lang.controls.letterSpacing,
  30088. type: 'letter-spacing'
  30089. }, {
  30090. key: 'text-indent',
  30091. title: lang.controls.textIndent,
  30092. type: 'text-indent'
  30093. }, {
  30094. key: 'font-size',
  30095. title: lang.controls.fontSize,
  30096. type: 'font-size'
  30097. }, {
  30098. key: 'font-family',
  30099. title: lang.controls.fontFamily,
  30100. type: 'font-family'
  30101. }, {
  30102. key: 'text-align',
  30103. title: lang.controls.textAlign,
  30104. type: 'text-align'
  30105. }, {
  30106. key: 'media',
  30107. title: lang.controls.media,
  30108. text: external_react_default.a.createElement("i", {
  30109. className: "bfi-media"
  30110. }),
  30111. type: 'media'
  30112. }, {
  30113. key: 'emoji',
  30114. title: lang.controls.emoji,
  30115. text: external_react_default.a.createElement("i", {
  30116. className: "bfi-emoji"
  30117. }),
  30118. type: 'emoji'
  30119. }, {
  30120. key: 'clear',
  30121. title: lang.controls.clear,
  30122. text: external_react_default.a.createElement("i", {
  30123. className: "bfi-clear_all"
  30124. }),
  30125. type: 'editor-method',
  30126. command: 'clearEditorContent'
  30127. }, {
  30128. key: 'fullscreen',
  30129. title: editor.state.isFullscreen ? lang.controls.exitFullscreen : lang.controls.fullscreen,
  30130. text: external_react_default.a.createElement("i", {
  30131. className: editor.state.isFullscreen ? 'bfi-fullscreen-exit' : 'bfi-fullscreen'
  30132. }),
  30133. type: 'editor-method',
  30134. command: 'toggleFullscreen'
  30135. }, {
  30136. key: 'modal',
  30137. type: 'modal'
  30138. }, {
  30139. key: 'button',
  30140. type: 'button'
  30141. }, {
  30142. key: 'dropdown',
  30143. type: 'dropdown'
  30144. }, {
  30145. key: 'component',
  30146. type: 'component'
  30147. }];
  30148. });
  30149. var imageControlItems = {
  30150. 'float-left': {
  30151. text: external_react_default.a.createElement("span", {
  30152. "data-float": "left"
  30153. }, "\uE91E"),
  30154. command: 'setImageFloat|left'
  30155. },
  30156. 'float-right': {
  30157. text: external_react_default.a.createElement("span", {
  30158. "data-float": "right"
  30159. }, "\uE914"),
  30160. command: 'setImageFloat|right'
  30161. },
  30162. 'align-left': {
  30163. text: external_react_default.a.createElement("span", {
  30164. "data-align": "left"
  30165. }, "\uE027"),
  30166. command: 'setImageAlignment|left'
  30167. },
  30168. 'align-center': {
  30169. text: external_react_default.a.createElement("span", {
  30170. "data-align": "center"
  30171. }, "\uE028"),
  30172. command: 'setImageAlignment|center'
  30173. },
  30174. 'align-right': {
  30175. text: external_react_default.a.createElement("span", {
  30176. "data-align": "right"
  30177. }, "\uE029"),
  30178. command: 'setImageAlignment|right'
  30179. },
  30180. 'size': {
  30181. text: external_react_default.a.createElement("span", null, "\uE3C2"),
  30182. command: 'toggleSizeEditor'
  30183. },
  30184. 'link': {
  30185. text: external_react_default.a.createElement("span", null, "\uE91A"),
  30186. command: 'toggleLinkEditor'
  30187. },
  30188. 'remove': {
  30189. text: external_react_default.a.createElement("span", null, "\uE9AC"),
  30190. command: 'removeImage'
  30191. }
  30192. };
  30193. // CONCATENATED MODULE: ./renderers/atomics/Image/index.jsx
  30194. var Image_Image =
  30195. /*#__PURE__*/
  30196. function (_React$Component) {
  30197. inherits_default()(Image, _React$Component);
  30198. function Image() {
  30199. var _getPrototypeOf2;
  30200. var _this;
  30201. classCallCheck_default()(this, Image);
  30202. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  30203. args[_key] = arguments[_key];
  30204. }
  30205. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(Image)).call.apply(_getPrototypeOf2, [this].concat(args)));
  30206. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "state", {
  30207. toolbarVisible: false,
  30208. toolbarOffset: 0,
  30209. linkEditorVisible: false,
  30210. sizeEditorVisible: false,
  30211. tempLink: null,
  30212. tempWidth: null,
  30213. tempHeight: null
  30214. });
  30215. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "initialLeft", void 0);
  30216. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "initialTop", void 0);
  30217. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "initialWidth", void 0);
  30218. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "initialHeight", void 0);
  30219. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "reSizeType", void 0);
  30220. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "changeSize", function (e) {
  30221. var type = _this.reSizeType;
  30222. if (!_this.initialLeft) {
  30223. _this.initialLeft = e.screenX;
  30224. _this.initialTop = e.screenY;
  30225. }
  30226. if (type === 'rightbottom') {
  30227. _this.initialHeight += e.screenY - _this.initialTop;
  30228. _this.initialWidth += e.screenX - _this.initialLeft;
  30229. }
  30230. if (type === 'leftbottom') {
  30231. _this.initialHeight += e.screenY - _this.initialTop;
  30232. _this.initialWidth += -e.screenX + _this.initialLeft;
  30233. }
  30234. _this.initialLeft = e.screenX;
  30235. _this.initialTop = e.screenY;
  30236. });
  30237. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "moveImage", function (e) {
  30238. _this.changeSize(e);
  30239. _this.setState({
  30240. tempWidth: Math.abs(_this.initialWidth),
  30241. tempHeight: Math.abs(_this.initialHeight)
  30242. });
  30243. });
  30244. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "upImage", function () {
  30245. _this.confirmImageSize();
  30246. document.removeEventListener('mousemove', _this.moveImage);
  30247. document.removeEventListener('mouseup', _this.upImage);
  30248. });
  30249. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "repareChangeSize", function (type) {
  30250. return function (e) {
  30251. _this.reSizeType = type;
  30252. var imageRect = _this.imageElement.getBoundingClientRect();
  30253. _this.initialLeft = _this.initialTop = 0;
  30254. _this.initialWidth = imageRect.width;
  30255. _this.initialHeight = imageRect.height;
  30256. e.preventDefault();
  30257. document.addEventListener('mousemove', _this.moveImage);
  30258. document.addEventListener('mouseup', _this.upImage);
  30259. };
  30260. });
  30261. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "preventDragEvent", function (event) {
  30262. event.stopPropagation();
  30263. event.preventDefault();
  30264. });
  30265. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleDragStart", function () {
  30266. if (_this.props.editor.editorProps.readOnly || _this.props.editor.editorProps.disabled) {
  30267. return false;
  30268. }
  30269. window.__BRAFT_DRAGING__IMAGE__ = {
  30270. block: _this.props.block,
  30271. mediaData: objectSpread_default()({
  30272. type: 'IMAGE'
  30273. }, _this.props.mediaData)
  30274. };
  30275. _this.setState({
  30276. toolbarVisible: false
  30277. }, function () {
  30278. _this.unlockEditor();
  30279. });
  30280. return true;
  30281. });
  30282. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleDragEnd", function () {
  30283. window.__BRAFT_DRAGING__IMAGE__ = null;
  30284. return false;
  30285. });
  30286. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "executeCommand", function (command) {
  30287. if (typeof command === 'string') {
  30288. var _command$split = command.split('|'),
  30289. _command$split2 = slicedToArray_default()(_command$split, 2),
  30290. method = _command$split2[0],
  30291. param = _command$split2[1];
  30292. _this[method] && _this[method](param);
  30293. } else if (typeof command === 'function') {
  30294. command(_this.props.block, _this.props.mediaData, _this.props.editor.getValue());
  30295. }
  30296. });
  30297. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "removeImage", function () {
  30298. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].removeBlock(_this.props.editor.getValue(), _this.props.block));
  30299. _this.unlockEditor();
  30300. });
  30301. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "toggleLinkEditor", function () {
  30302. _this.setState({
  30303. linkEditorVisible: !_this.state.linkEditorVisible,
  30304. sizeEditorVisible: false
  30305. });
  30306. });
  30307. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "toggleSizeEditor", function () {
  30308. _this.setState({
  30309. linkEditorVisible: false,
  30310. sizeEditorVisible: !_this.state.sizeEditorVisible
  30311. });
  30312. });
  30313. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleLinkInputKeyDown", function (e) {
  30314. if (e.keyCode === 13) {
  30315. _this.confirmImageLink();
  30316. } else {
  30317. return;
  30318. }
  30319. });
  30320. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "setImageLink", function (e) {
  30321. _this.setState({
  30322. tempLink: e.currentTarget.value
  30323. });
  30324. return;
  30325. });
  30326. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "confirmImageLink", function () {
  30327. var link = _this.state.tempLink;
  30328. var hookReturns = _this.props.hooks('set-image-link', link)(link);
  30329. if (hookReturns === false) {
  30330. return false;
  30331. }
  30332. if (typeof hookReturns === 'string') {
  30333. link = hookReturns;
  30334. }
  30335. if (link !== null) {
  30336. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].setMediaData(_this.props.editor.getValue(), _this.props.entityKey, {
  30337. link: link
  30338. }));
  30339. window.setImmediate(_this.props.editor.forceRender);
  30340. }
  30341. });
  30342. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleSizeInputKeyDown", function (e) {
  30343. if (e.keyCode === 13) {
  30344. _this.confirmImageSize();
  30345. } else {
  30346. return;
  30347. }
  30348. });
  30349. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "setImageWidth", function (_ref) {
  30350. var currentTarget = _ref.currentTarget;
  30351. var value = currentTarget.value;
  30352. value && !isNaN(value) && (value = value + 'px');
  30353. _this.setState({
  30354. tempWidth: value
  30355. });
  30356. return;
  30357. });
  30358. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "setImageHeight", function (_ref2) {
  30359. var currentTarget = _ref2.currentTarget;
  30360. var value = currentTarget.value;
  30361. value && !isNaN(value) && (value = value + 'px');
  30362. _this.setState({
  30363. tempHeight: value
  30364. });
  30365. return;
  30366. });
  30367. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "confirmImageSize", function () {
  30368. var _this$state = _this.state,
  30369. width = _this$state.tempWidth,
  30370. height = _this$state.tempHeight;
  30371. var newImageSize = {};
  30372. width !== null && (newImageSize.width = width);
  30373. height !== null && (newImageSize.height = height);
  30374. var hookReturns = _this.props.hooks('set-image-size', newImageSize)(newImageSize);
  30375. if (hookReturns === false) {
  30376. return false;
  30377. }
  30378. if (hookReturns && (hookReturns.width || hookReturns.height)) {
  30379. newImageSize = hookReturns;
  30380. }
  30381. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].setMediaData(_this.props.editor.getValue(), _this.props.entityKey, newImageSize));
  30382. window.setImmediate(_this.props.editor.forceRender);
  30383. });
  30384. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "setImageFloat", function (float) {
  30385. var hookReturns = _this.props.hooks('set-image-float', float)(float);
  30386. if (hookReturns === false) {
  30387. return false;
  30388. }
  30389. if (typeof hookReturns === 'string') {
  30390. float = hookReturns;
  30391. }
  30392. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].setMediaPosition(_this.props.editor.getValue(), _this.props.block, {
  30393. float: float
  30394. }));
  30395. _this.unlockEditor();
  30396. });
  30397. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "setImageAlignment", function (alignment) {
  30398. var hookReturns = _this.props.hooks('set-image-alignment', alignment)(alignment);
  30399. if (hookReturns === false) {
  30400. return false;
  30401. }
  30402. if (typeof hookReturns === 'string') {
  30403. alignment = hookReturns;
  30404. }
  30405. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].setMediaPosition(_this.props.editor.getValue(), _this.props.block, {
  30406. alignment: alignment
  30407. }));
  30408. _this.unlockEditor();
  30409. });
  30410. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "showToolbar", function (event) {
  30411. if (_this.props.editor.editorProps.readOnly || _this.props.editor.editorProps.disabled) {
  30412. return false;
  30413. }
  30414. event.preventDefault();
  30415. if (!_this.state.toolbarVisible) {
  30416. _this.setState({
  30417. toolbarVisible: true
  30418. }, function () {
  30419. _this.lockEditor();
  30420. _this.setState({
  30421. toolbarOffset: _this.calcToolbarOffset()
  30422. });
  30423. });
  30424. }
  30425. });
  30426. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "hideToolbar", function (event) {
  30427. event.preventDefault();
  30428. _this.setState({
  30429. toolbarVisible: false
  30430. }, function () {
  30431. _this.unlockEditor(); // this.props.editor.requestFocus()
  30432. });
  30433. });
  30434. return _this;
  30435. }
  30436. createClass_default()(Image, [{
  30437. key: "render",
  30438. value: function render() {
  30439. var _this2 = this;
  30440. var _this$props = this.props,
  30441. mediaData = _this$props.mediaData,
  30442. language = _this$props.language,
  30443. imageControls = _this$props.imageControls,
  30444. imageResizable = _this$props.imageResizable;
  30445. var _this$state2 = this.state,
  30446. toolbarVisible = _this$state2.toolbarVisible,
  30447. toolbarOffset = _this$state2.toolbarOffset,
  30448. linkEditorVisible = _this$state2.linkEditorVisible,
  30449. sizeEditorVisible = _this$state2.sizeEditorVisible,
  30450. tempWidth = _this$state2.tempWidth,
  30451. tempHeight = _this$state2.tempHeight;
  30452. var blockData = this.props.block.getData();
  30453. var float = blockData.get('float');
  30454. var alignment = blockData.get('alignment');
  30455. var url = mediaData.url,
  30456. link = mediaData.link,
  30457. link_target = mediaData.link_target,
  30458. width = mediaData.width,
  30459. height = mediaData.height,
  30460. meta = mediaData.meta;
  30461. var imageStyles = {};
  30462. var clearFix = false;
  30463. if (float) {
  30464. alignment = null;
  30465. } else if (alignment === 'left') {
  30466. imageStyles.float = 'left';
  30467. clearFix = true;
  30468. } else if (alignment === 'right') {
  30469. imageStyles.float = 'right';
  30470. clearFix = true;
  30471. } else if (alignment === 'center') {
  30472. imageStyles.textAlign = 'center';
  30473. } else {
  30474. imageStyles.float = 'left';
  30475. clearFix = true;
  30476. }
  30477. var renderedControlItems = imageControls.map(function (item, index) {
  30478. if (typeof item === 'string' && imageControlItems[item]) {
  30479. return external_react_default.a.createElement("a", {
  30480. className: item === 'link' && link ? 'active' : '',
  30481. key: index,
  30482. onClick: function onClick() {
  30483. return _this2.executeCommand(imageControlItems[item].command);
  30484. }
  30485. }, imageControlItems[item].text);
  30486. } else if (item && (item.render || item.text)) {
  30487. return item.render ? item.render(mediaData, _this2.props.block) : external_react_default.a.createElement("a", {
  30488. key: index,
  30489. onClick: function onClick() {
  30490. return item.onClick && _this2.executeCommand(item.onClick);
  30491. }
  30492. }, item.text);
  30493. } else {
  30494. return null;
  30495. }
  30496. });
  30497. return external_react_default.a.createElement("div", {
  30498. className: "bf-media"
  30499. }, external_react_default.a.createElement("div", {
  30500. style: imageStyles,
  30501. draggable: true,
  30502. onMouseEnter: this.showToolbar,
  30503. onMouseMove: this.showToolbar,
  30504. onMouseLeave: this.hideToolbar,
  30505. onDragStart: this.handleDragStart,
  30506. onDragEnd: this.handleDragEnd,
  30507. ref: function ref(instance) {
  30508. return _this2.mediaEmbederInstance = instance;
  30509. },
  30510. className: "bf-image"
  30511. }, toolbarVisible ? external_react_default.a.createElement("div", {
  30512. style: {
  30513. marginLeft: toolbarOffset
  30514. },
  30515. ref: function ref(instance) {
  30516. return _this2.toolbarElement = instance;
  30517. },
  30518. "data-float": float,
  30519. "data-align": alignment,
  30520. className: "bf-media-toolbar"
  30521. }, linkEditorVisible ? external_react_default.a.createElement("div", {
  30522. className: "bf-image-link-editor"
  30523. }, external_react_default.a.createElement("div", {
  30524. className: "editor-input-group"
  30525. }, external_react_default.a.createElement("input", {
  30526. type: "text",
  30527. placeholder: language.linkEditor.inputWithEnterPlaceHolder,
  30528. onKeyDown: this.handleLinkInputKeyDown,
  30529. onChange: this.setImageLink,
  30530. defaultValue: link
  30531. }), external_react_default.a.createElement("button", {
  30532. type: "button",
  30533. onClick: this.confirmImageLink
  30534. }, language.base.confirm)), external_react_default.a.createElement("div", {
  30535. className: "switch-group"
  30536. }, external_react_default.a.createElement(Switch, {
  30537. active: link_target === '_blank',
  30538. onClick: function onClick() {
  30539. return _this2.setImageLinkTarget(link_target);
  30540. }
  30541. }), external_react_default.a.createElement("label", null, language.linkEditor.openInNewWindow))) : null, sizeEditorVisible ? external_react_default.a.createElement("div", {
  30542. className: "bf-image-size-editor"
  30543. }, external_react_default.a.createElement("div", {
  30544. className: "editor-input-group"
  30545. }, external_react_default.a.createElement("input", {
  30546. type: "text",
  30547. placeholder: language.base.width,
  30548. onKeyDown: this.handleSizeInputKeyDown,
  30549. onChange: this.setImageWidth,
  30550. defaultValue: width
  30551. }), external_react_default.a.createElement("input", {
  30552. type: "text",
  30553. placeholder: language.base.height,
  30554. onKeyDown: this.handleSizeInputKeyDown,
  30555. onChange: this.setImageHeight,
  30556. defaultValue: height
  30557. }), external_react_default.a.createElement("button", {
  30558. type: "button",
  30559. onClick: this.confirmImageSize
  30560. }, language.base.confirm))) : null, renderedControlItems, external_react_default.a.createElement("i", {
  30561. style: {
  30562. marginLeft: toolbarOffset * -1
  30563. },
  30564. className: "bf-media-toolbar-arrow"
  30565. })) : null, external_react_default.a.createElement("div", {
  30566. style: {
  30567. position: 'relative',
  30568. width: "".concat(width, "px"),
  30569. height: "".concat(height, "px"),
  30570. display: 'inline-block'
  30571. }
  30572. }, external_react_default.a.createElement("img", extends_default()({
  30573. ref: function ref(instance) {
  30574. return _this2.imageElement = instance;
  30575. },
  30576. src: url,
  30577. width: width,
  30578. height: height
  30579. }, meta)), toolbarVisible && imageResizable ? external_react_default.a.createElement("div", {
  30580. className: "bf-csize-icon right-bottom",
  30581. onMouseDown: this.repareChangeSize('rightbottom')
  30582. }) : null, toolbarVisible && imageResizable ? external_react_default.a.createElement("div", {
  30583. className: "bf-csize-icon left-bottom",
  30584. onMouseDown: this.repareChangeSize('leftbottom')
  30585. }) : null, external_react_default.a.createElement("div", {
  30586. className: "bf-pre-csize ".concat(this.reSizeType),
  30587. style: {
  30588. width: "".concat(tempWidth, "px"),
  30589. height: "".concat(tempHeight, "px")
  30590. }
  30591. }))), clearFix && external_react_default.a.createElement("div", {
  30592. className: "clearfix",
  30593. style: {
  30594. clear: 'both',
  30595. height: 0,
  30596. lineHeight: 0,
  30597. float: 'none'
  30598. }
  30599. }));
  30600. }
  30601. }, {
  30602. key: "lockEditor",
  30603. value: function lockEditor() {
  30604. this.props.editor.lockOrUnlockEditor(true);
  30605. }
  30606. }, {
  30607. key: "unlockEditor",
  30608. value: function unlockEditor() {
  30609. this.props.editor.lockOrUnlockEditor(false);
  30610. }
  30611. }, {
  30612. key: "calcToolbarOffset",
  30613. value: function calcToolbarOffset() {
  30614. var _this$props2 = this.props,
  30615. getContainerNode = _this$props2.getContainerNode,
  30616. containerNode = _this$props2.containerNode;
  30617. var container = getContainerNode ? getContainerNode() : containerNode;
  30618. if (!container) {
  30619. return 0;
  30620. }
  30621. var viewRect = container.querySelector('.bf-content').getBoundingClientRect();
  30622. var toolbarRect = this.toolbarElement.getBoundingClientRect();
  30623. var imageRect = this.imageElement.getBoundingClientRect();
  30624. var right = viewRect.right - (imageRect.right - imageRect.width / 2 + toolbarRect.width / 2);
  30625. var left = imageRect.left + imageRect.width / 2 - toolbarRect.width / 2 - viewRect.left;
  30626. if (right < 10) {
  30627. return right - 10;
  30628. } else if (left < 10) {
  30629. return left * -1 + 10;
  30630. } else {
  30631. return 0;
  30632. }
  30633. }
  30634. }, {
  30635. key: "setImageLinkTarget",
  30636. value: function setImageLinkTarget(link_target) {
  30637. var hookReturns = this.props.hooks('set-image-link-target', link_target)(link_target);
  30638. if (hookReturns === false) {
  30639. return false;
  30640. }
  30641. if (typeof hookReturns === 'string') {
  30642. link_target = hookReturns;
  30643. }
  30644. link_target = link_target === '_blank' ? '' : '_blank';
  30645. this.props.editor.setValue(external_braft_utils_["ContentUtils"].setMediaData(this.props.editor.getValue(), this.props.entityKey, {
  30646. link_target: link_target
  30647. }));
  30648. window.setImmediate(this.props.editor.forceRender);
  30649. }
  30650. }]);
  30651. return Image;
  30652. }(external_react_default.a.Component);
  30653. // EXTERNAL MODULE: ./renderers/atomics/Video/style.scss
  30654. var Video_style = __webpack_require__(47);
  30655. // EXTERNAL MODULE: ./components/common/Modal/style.scss
  30656. var Modal_style = __webpack_require__(48);
  30657. // EXTERNAL MODULE: external "react-dom"
  30658. var external_react_dom_ = __webpack_require__(16);
  30659. var external_react_dom_default = /*#__PURE__*/__webpack_require__.n(external_react_dom_);
  30660. // CONCATENATED MODULE: ./components/common/Modal/index.jsx
  30661. var Modal_Modal =
  30662. /*#__PURE__*/
  30663. function (_React$Component) {
  30664. inherits_default()(Modal, _React$Component);
  30665. function Modal(props) {
  30666. var _this;
  30667. classCallCheck_default()(this, Modal);
  30668. _this = possibleConstructorReturn_default()(this, getPrototypeOf_default()(Modal).call(this, props));
  30669. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleTransitionEnd", function () {
  30670. if (!_this.rootElement || !_this.rootElement.classList) {
  30671. return false;
  30672. }
  30673. if (!_this.rootElement.classList.contains('active')) {
  30674. external_react_dom_default.a.unmountComponentAtNode(_this.rootElement) && _this.rootElement.parentNode.removeChild(_this.rootElement);
  30675. }
  30676. });
  30677. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleMouseDown", function (event) {
  30678. var tagName = event.target.tagName.toLowerCase();
  30679. if (tagName === 'input' || tagName === 'textarea') {
  30680. return false;
  30681. }
  30682. event.preventDefault();
  30683. });
  30684. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleCancel", function () {
  30685. _this.props.closeOnCancel && _this.close();
  30686. _this.props.onCancel && _this.props.onCancel();
  30687. });
  30688. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleConfirm", function () {
  30689. _this.props.closeOnConfirm && _this.close();
  30690. _this.props.onConfirm && _this.props.onConfirm();
  30691. });
  30692. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleMaskClick", function () {
  30693. _this.props.closeOnBlur && _this.close();
  30694. _this.props.onBlue && _this.props.onBlue();
  30695. });
  30696. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "close", function () {
  30697. _this.unrenderComponent();
  30698. _this.props.onClose && _this.props.onClose();
  30699. });
  30700. _this.active = false;
  30701. _this.componentId = 'BRAFT-MODAL-' + external_braft_utils_["BaseUtils"].UniqueIndex();
  30702. return _this;
  30703. }
  30704. createClass_default()(Modal, [{
  30705. key: "componentDidMount",
  30706. value: function componentDidMount() {
  30707. if (this.props.visible) {
  30708. this.active = true;
  30709. this.renderComponent(this.props);
  30710. }
  30711. }
  30712. }, {
  30713. key: "componentWillReceiveProps",
  30714. value: function componentWillReceiveProps(next) {
  30715. if (this.props.visible && !next.visible) {
  30716. this.unrenderComponent();
  30717. } else if (this.props.visible || next.visible) {
  30718. this.active = true;
  30719. this.renderComponent(next);
  30720. }
  30721. }
  30722. }, {
  30723. key: "render",
  30724. value: function render() {
  30725. return null;
  30726. }
  30727. }, {
  30728. key: "unrenderComponent",
  30729. value: function unrenderComponent() {
  30730. this.active = false;
  30731. this.activeId && window.clearImmediate(this.activeId);
  30732. if (this.rootElement && this.rootElement.classList) {
  30733. this.rootElement.classList.remove('active');
  30734. }
  30735. }
  30736. }, {
  30737. key: "renderComponent",
  30738. value: function renderComponent(props) {
  30739. var _this2 = this;
  30740. if (!this.active) {
  30741. return false;
  30742. }
  30743. var title = props.title,
  30744. className = props.className,
  30745. width = props.width,
  30746. height = props.height,
  30747. children = props.children,
  30748. component = props.component,
  30749. confirmable = props.confirmable,
  30750. showFooter = props.showFooter,
  30751. showCancel = props.showCancel,
  30752. showConfirm = props.showConfirm,
  30753. showClose = props.showClose,
  30754. cancelText = props.cancelText,
  30755. confirmText = props.confirmText,
  30756. bottomText = props.bottomText,
  30757. language = props.language;
  30758. typeof showCancel === 'undefined' && (showCancel = true);
  30759. typeof showClose === 'undefined' && (showClose = true);
  30760. typeof showConfirm === 'undefined' && (showConfirm = true);
  30761. typeof showFooter === 'undefined' && (showFooter = true);
  30762. var childComponent = external_react_default.a.createElement("div", {
  30763. onMouseDown: this.handleMouseDown,
  30764. className: 'bf-modal ' + (className || '')
  30765. }, external_react_default.a.createElement("div", {
  30766. className: "bf-modal-mask",
  30767. onClick: this.handleMaskClick
  30768. }), external_react_default.a.createElement("div", {
  30769. onTransitionEnd: this.handleTransitionEnd,
  30770. style: {
  30771. width: width,
  30772. height: height
  30773. },
  30774. className: "bf-modal-content"
  30775. }, external_react_default.a.createElement("div", {
  30776. className: "bf-modal-header"
  30777. }, external_react_default.a.createElement("h3", {
  30778. className: "bf-modal-caption"
  30779. }, title), showClose && external_react_default.a.createElement("button", {
  30780. type: "button",
  30781. onClick: this.close,
  30782. className: "bf-modal-close-button"
  30783. }, external_react_default.a.createElement("i", {
  30784. className: "bfi-close"
  30785. }))), external_react_default.a.createElement("div", {
  30786. className: "bf-modal-body"
  30787. }, children || component), showFooter ? external_react_default.a.createElement("div", {
  30788. className: "bf-modal-footer"
  30789. }, external_react_default.a.createElement("div", {
  30790. className: "bf-modal-addon-text"
  30791. }, bottomText), external_react_default.a.createElement("div", {
  30792. className: "bf-modal-buttons"
  30793. }, showCancel && external_react_default.a.createElement("button", {
  30794. type: "button",
  30795. onClick: this.handleCancel,
  30796. className: "bf-modal-cancel"
  30797. }, cancelText || language.base.cancel), showConfirm && external_react_default.a.createElement("button", {
  30798. type: "button",
  30799. onClick: this.handleConfirm,
  30800. className: 'bf-modal-confirm ' + (!confirmable ? 'disabled' : '')
  30801. }, confirmText || language.base.confirm))) : null));
  30802. this.rootElement = document.querySelector('#' + this.componentId);
  30803. if (!this.rootElement) {
  30804. this.rootElement = document.createElement('div');
  30805. this.rootElement.id = this.componentId;
  30806. this.rootElement.className = 'bf-modal-root';
  30807. document.body.appendChild(this.rootElement);
  30808. }
  30809. external_react_dom_default.a.render(childComponent, this.rootElement);
  30810. this.activeId = window.setImmediate(function () {
  30811. _this2.rootElement.classList.add('active');
  30812. });
  30813. }
  30814. }]);
  30815. return Modal;
  30816. }(external_react_default.a.Component);
  30817. defineProperty_default()(Modal_Modal, "defaultProps", {
  30818. showFooter: true,
  30819. closeOnBlur: true
  30820. });
  30821. var Modal_showModal = function showModal(props) {
  30822. var hostNode = document.createElement('div');
  30823. hostNode.style.display = 'none';
  30824. document.body.appendChild(hostNode);
  30825. props = objectSpread_default()({
  30826. visible: true,
  30827. closeOnConfirm: true,
  30828. closeOnCancel: true
  30829. }, props);
  30830. var close = function close() {
  30831. external_react_dom_default.a.unmountComponentAtNode(hostNode) && hostNode.parentNode.removeChild(hostNode);
  30832. };
  30833. var onConfirm = function onConfirm() {
  30834. props.onConfirm && props.onConfirm();
  30835. };
  30836. var onCancel = function onCancel() {
  30837. props.onCancel && props.onCancel();
  30838. };
  30839. var onClose = function onClose() {
  30840. close();
  30841. props.onClose && props.onClose();
  30842. };
  30843. var modalInstance = external_react_dom_default.a.render(external_react_default.a.createElement(Modal_Modal, extends_default()({}, props, {
  30844. onConfirm: onConfirm,
  30845. onCancel: onCancel,
  30846. onClose: onClose
  30847. })), hostNode);
  30848. modalInstance.destroy = close;
  30849. modalInstance.update = modalInstance.renderComponent;
  30850. return modalInstance;
  30851. };
  30852. // EXTERNAL MODULE: ./components/business/PlayerModal/style.scss
  30853. var PlayerModal_style = __webpack_require__(49);
  30854. // CONCATENATED MODULE: ./components/business/PlayerModal/index.jsx
  30855. var PlayerModal_playViaModal = function playViaModal(title, component, language) {
  30856. return Modal_showModal({
  30857. title: title,
  30858. component: component,
  30859. language: language,
  30860. showFooter: false
  30861. });
  30862. };
  30863. var typeIconsMap = {
  30864. 'video': 'bfi-film',
  30865. 'audio': 'bfi-music',
  30866. 'embed': 'bfi-code'
  30867. };
  30868. /* harmony default export */ var PlayerModal = (function (_ref) {
  30869. var title = _ref.title,
  30870. type = _ref.type,
  30871. language = _ref.language,
  30872. name = _ref.name,
  30873. url = _ref.url,
  30874. poster = _ref.poster,
  30875. children = _ref.children,
  30876. onRemove = _ref.onRemove;
  30877. return external_react_default.a.createElement("div", {
  30878. className: "bf-player-holder ".concat(type)
  30879. }, external_react_default.a.createElement("div", {
  30880. className: "icon-badge"
  30881. }, external_react_default.a.createElement("i", {
  30882. className: typeIconsMap[type]
  30883. }), external_react_default.a.createElement("span", {
  30884. className: "text"
  30885. }, language.media[type])), external_react_default.a.createElement("button", {
  30886. onMouseDown: onRemove,
  30887. className: "button-remove"
  30888. }, external_react_default.a.createElement("i", {
  30889. className: "bfi-close"
  30890. })), external_react_default.a.createElement("button", {
  30891. onMouseDown: function onMouseDown() {
  30892. return PlayerModal_playViaModal(name ? "".concat(title, ":").concat(name) : title, children, language);
  30893. },
  30894. className: "button-play"
  30895. }, external_react_default.a.createElement("i", {
  30896. className: "bfi-play_arrow"
  30897. })), name ? external_react_default.a.createElement("h5", {
  30898. className: "bf-name"
  30899. }, name) : null, external_react_default.a.createElement("h6", {
  30900. className: "bf-url"
  30901. }, url), poster ? external_react_default.a.createElement("div", {
  30902. className: "bf-poster",
  30903. style: {
  30904. backgroundImage: "url(".concat(poster, ")")
  30905. }
  30906. }) : null);
  30907. });
  30908. // CONCATENATED MODULE: ./renderers/atomics/Video/index.jsx
  30909. var Video_Video =
  30910. /*#__PURE__*/
  30911. function (_React$Component) {
  30912. inherits_default()(Video, _React$Component);
  30913. function Video() {
  30914. var _getPrototypeOf2;
  30915. var _this;
  30916. classCallCheck_default()(this, Video);
  30917. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  30918. args[_key] = arguments[_key];
  30919. }
  30920. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(Video)).call.apply(_getPrototypeOf2, [this].concat(args)));
  30921. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "removeVideo", function () {
  30922. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].removeBlock(_this.props.editorState, _this.props.block));
  30923. });
  30924. return _this;
  30925. }
  30926. createClass_default()(Video, [{
  30927. key: "render",
  30928. value: function render() {
  30929. var _this$props = this.props,
  30930. mediaData = _this$props.mediaData,
  30931. language = _this$props.language;
  30932. var url = mediaData.url,
  30933. name = mediaData.name,
  30934. meta = mediaData.meta;
  30935. return external_react_default.a.createElement("div", {
  30936. className: "bf-video-wrap"
  30937. }, external_react_default.a.createElement(PlayerModal, {
  30938. type: "video",
  30939. onRemove: this.removeVideo,
  30940. poster: meta ? meta.poster || '' : '',
  30941. language: language,
  30942. url: url,
  30943. name: name,
  30944. title: language.videoPlayer.title
  30945. }, external_react_default.a.createElement("div", {
  30946. className: "bf-video-player"
  30947. }, external_react_default.a.createElement("video", {
  30948. controls: true,
  30949. poster: meta ? meta.poster || '' : ''
  30950. }, external_react_default.a.createElement("source", {
  30951. src: url
  30952. })))));
  30953. }
  30954. }]);
  30955. return Video;
  30956. }(external_react_default.a.Component);
  30957. // EXTERNAL MODULE: ./renderers/atomics/Audio/style.scss
  30958. var Audio_style = __webpack_require__(50);
  30959. // CONCATENATED MODULE: ./renderers/atomics/Audio/index.jsx
  30960. var Audio_Audio =
  30961. /*#__PURE__*/
  30962. function (_React$Component) {
  30963. inherits_default()(Audio, _React$Component);
  30964. function Audio() {
  30965. var _getPrototypeOf2;
  30966. var _this;
  30967. classCallCheck_default()(this, Audio);
  30968. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  30969. args[_key] = arguments[_key];
  30970. }
  30971. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(Audio)).call.apply(_getPrototypeOf2, [this].concat(args)));
  30972. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "removeAudio", function () {
  30973. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].removeBlock(_this.props.editorState, _this.props.block));
  30974. });
  30975. return _this;
  30976. }
  30977. createClass_default()(Audio, [{
  30978. key: "render",
  30979. value: function render() {
  30980. var _this$props = this.props,
  30981. mediaData = _this$props.mediaData,
  30982. language = _this$props.language;
  30983. var url = mediaData.url,
  30984. name = mediaData.name,
  30985. meta = mediaData.meta;
  30986. return external_react_default.a.createElement("div", {
  30987. className: "bf-audio-wrap"
  30988. }, external_react_default.a.createElement(PlayerModal, {
  30989. type: "audio",
  30990. onRemove: this.removeAudio,
  30991. poster: meta ? meta.poster || '' : '',
  30992. language: language,
  30993. url: url,
  30994. name: name,
  30995. title: language.audioPlayer.title
  30996. }, external_react_default.a.createElement("div", {
  30997. className: "bf-audio-player"
  30998. }, external_react_default.a.createElement("audio", {
  30999. controls: true,
  31000. src: url
  31001. }))));
  31002. }
  31003. }]);
  31004. return Audio;
  31005. }(external_react_default.a.Component);
  31006. // EXTERNAL MODULE: ./renderers/atomics/Embed/style.scss
  31007. var Embed_style = __webpack_require__(51);
  31008. // CONCATENATED MODULE: ./renderers/atomics/Embed/index.jsx
  31009. var Embed_Embed =
  31010. /*#__PURE__*/
  31011. function (_React$Component) {
  31012. inherits_default()(Embed, _React$Component);
  31013. function Embed() {
  31014. var _getPrototypeOf2;
  31015. var _this;
  31016. classCallCheck_default()(this, Embed);
  31017. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  31018. args[_key] = arguments[_key];
  31019. }
  31020. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(Embed)).call.apply(_getPrototypeOf2, [this].concat(args)));
  31021. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "removeEmbed", function () {
  31022. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].removeBlock(_this.props.editorState, _this.props.block));
  31023. });
  31024. return _this;
  31025. }
  31026. createClass_default()(Embed, [{
  31027. key: "render",
  31028. value: function render() {
  31029. var _this$props = this.props,
  31030. mediaData = _this$props.mediaData,
  31031. language = _this$props.language;
  31032. var name = mediaData.name,
  31033. url = mediaData.url,
  31034. meta = mediaData.meta;
  31035. return external_react_default.a.createElement("div", {
  31036. className: "bf-embed-wrap"
  31037. }, external_react_default.a.createElement(PlayerModal, {
  31038. type: "embed",
  31039. onRemove: this.removeEmbed,
  31040. poster: meta ? meta.poster || '' : '',
  31041. language: language,
  31042. url: url,
  31043. name: name,
  31044. title: language.videoPlayer.embedTitle
  31045. }, external_react_default.a.createElement("div", {
  31046. className: "bf-embed-player",
  31047. dangerouslySetInnerHTML: {
  31048. __html: url
  31049. }
  31050. })));
  31051. }
  31052. }]);
  31053. return Embed;
  31054. }(external_react_default.a.Component);
  31055. // EXTERNAL MODULE: ./renderers/atomics/HorizontalLine/style.scss
  31056. var HorizontalLine_style = __webpack_require__(52);
  31057. // CONCATENATED MODULE: ./renderers/atomics/HorizontalLine/index.jsx
  31058. var HorizontalLine_HorizontalLine =
  31059. /*#__PURE__*/
  31060. function (_React$Component) {
  31061. inherits_default()(HorizontalLine, _React$Component);
  31062. function HorizontalLine() {
  31063. var _getPrototypeOf2;
  31064. var _this;
  31065. classCallCheck_default()(this, HorizontalLine);
  31066. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  31067. args[_key] = arguments[_key];
  31068. }
  31069. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(HorizontalLine)).call.apply(_getPrototypeOf2, [this].concat(args)));
  31070. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "removeHorizontalLine", function () {
  31071. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].removeBlock(_this.props.editorState, _this.props.block));
  31072. });
  31073. return _this;
  31074. }
  31075. createClass_default()(HorizontalLine, [{
  31076. key: "render",
  31077. value: function render() {
  31078. return external_react_default.a.createElement("div", {
  31079. className: "bf-hr"
  31080. }, external_react_default.a.createElement("div", {
  31081. className: "bf-media-toolbar"
  31082. }, external_react_default.a.createElement("a", {
  31083. onClick: this.removeHorizontalLine
  31084. }, "\uE9AC")));
  31085. }
  31086. }]);
  31087. return HorizontalLine;
  31088. }(external_react_default.a.Component);
  31089. // CONCATENATED MODULE: ./renderers/block/blockRendererFn.js
  31090. var blockRendererFn_BlockRenderFnContext = function BlockRenderFnContext() {
  31091. var _this = this;
  31092. classCallCheck_default()(this, BlockRenderFnContext);
  31093. defineProperty_default()(this, "superProps", void 0);
  31094. defineProperty_default()(this, "customBlockRendererFn", void 0);
  31095. defineProperty_default()(this, "getRenderFn", function (superProps, customBlockRendererFn) {
  31096. _this.superProps = superProps;
  31097. _this.customBlockRendererFn = customBlockRendererFn;
  31098. return _this.blockRendererFn;
  31099. });
  31100. defineProperty_default()(this, "renderAtomicBlock", function (props) {
  31101. var superProps = _this.superProps;
  31102. var entityKey = props.block.getEntityAt(0);
  31103. if (!entityKey) {
  31104. return null;
  31105. }
  31106. var entity = props.contentState.getEntity(entityKey);
  31107. var mediaData = entity.getData();
  31108. var mediaType = entity.getType();
  31109. var mediaProps = objectSpread_default()({}, superProps, {
  31110. block: props.block,
  31111. mediaData: mediaData,
  31112. entityKey: entityKey
  31113. });
  31114. if (mediaType === 'IMAGE') {
  31115. return external_react_default.a.createElement(Image_Image, mediaProps);
  31116. } else if (mediaType === 'AUDIO') {
  31117. return external_react_default.a.createElement(Audio_Audio, mediaProps);
  31118. } else if (mediaType === 'VIDEO') {
  31119. return external_react_default.a.createElement(Video_Video, mediaProps);
  31120. } else if (mediaType === 'EMBED') {
  31121. return external_react_default.a.createElement(Embed_Embed, mediaProps);
  31122. } else if (mediaType === 'HR') {
  31123. return external_react_default.a.createElement(HorizontalLine_HorizontalLine, mediaProps);
  31124. }
  31125. if (superProps.extendAtomics) {
  31126. var atomics = superProps.extendAtomics;
  31127. for (var i = 0; i < atomics.length; i++) {
  31128. if (mediaType === atomics[i].type) {
  31129. var Component = atomics[i].component;
  31130. return external_react_default.a.createElement(Component, mediaProps);
  31131. }
  31132. }
  31133. }
  31134. return null;
  31135. });
  31136. defineProperty_default()(this, "blockRendererFn", function (block) {
  31137. var customBlockRendererFn = _this.customBlockRendererFn,
  31138. superProps = _this.superProps;
  31139. var blockType = block.getType();
  31140. var blockRenderer = null;
  31141. if (customBlockRendererFn) {
  31142. blockRenderer = customBlockRendererFn(block, superProps) || null;
  31143. }
  31144. if (blockRenderer) {
  31145. return blockRenderer;
  31146. }
  31147. var extensionBlockRendererFns = getExtensionBlockRendererFns(superProps.editorId);
  31148. extensionBlockRendererFns.find(function (item) {
  31149. if (item.blockType === blockType || item.blockType instanceof RegExp && item.blockType.test(blockType)) {
  31150. blockRenderer = item.rendererFn ? item.rendererFn(superProps) : null;
  31151. return true;
  31152. }
  31153. });
  31154. if (blockRenderer) {
  31155. return blockRenderer;
  31156. }
  31157. if (blockType === 'atomic') {
  31158. blockRenderer = {
  31159. component: _this.renderAtomicBlock,
  31160. editable: false
  31161. };
  31162. }
  31163. return blockRenderer;
  31164. });
  31165. };
  31166. var blockRenderFnContext = new blockRendererFn_BlockRenderFnContext();
  31167. /* harmony default export */ var block_blockRendererFn = (blockRenderFnContext.getRenderFn);
  31168. // CONCATENATED MODULE: ./renderers/block/blockStyleFn.js
  31169. /* harmony default export */ var block_blockStyleFn = (function (customBlockStyleFn) {
  31170. return function (block) {
  31171. var blockAlignment = block.getData() && block.getData().get('textAlign');
  31172. var blockIndent = block.getData() && block.getData().get('textIndent');
  31173. var blockFloat = block.getData() && block.getData().get('float');
  31174. var result = '';
  31175. if (blockAlignment) {
  31176. result = "bfa-".concat(blockAlignment);
  31177. }
  31178. if (blockIndent && blockIndent !== 0) {
  31179. result += " bftd-".concat(blockIndent);
  31180. }
  31181. if (blockFloat) {
  31182. result += " bff-".concat(blockFloat);
  31183. }
  31184. if (customBlockStyleFn) {
  31185. result += customBlockStyleFn(block) || '';
  31186. }
  31187. return result;
  31188. };
  31189. });
  31190. // CONCATENATED MODULE: ./renderers/inline/inlineStyleMap.js
  31191. /* harmony default export */ var inlineStyleMap = (function (props) {
  31192. var customStyleMap = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  31193. var extensionInlineStyleMap = getExtensionInlineStyleMap(props.editorId);
  31194. return objectSpread_default()({
  31195. 'SUPERSCRIPT': {
  31196. position: 'relative',
  31197. top: '-8px',
  31198. fontSize: '11px'
  31199. },
  31200. 'SUBSCRIPT': {
  31201. position: 'relative',
  31202. bottom: '-8px',
  31203. fontSize: '11px'
  31204. }
  31205. }, extensionInlineStyleMap, customStyleMap);
  31206. });
  31207. // CONCATENATED MODULE: ./renderers/inline/inlineStyleFn.js
  31208. var getStyleValue = function getStyleValue(style) {
  31209. return style.split('-')[1];
  31210. };
  31211. /* harmony default export */ var inlineStyleFn = (function (props, options) {
  31212. return function (styles, block) {
  31213. var output = {};
  31214. var fontFamilies = options.fontFamilies,
  31215. unitExportFn = options.unitExportFn,
  31216. customStyleFn = options.customStyleFn;
  31217. var extensionInlineStyleFns = getExtensionInlineStyleFns(props.editorId);
  31218. extensionInlineStyleFns.forEach(function (item) {
  31219. output = item.styleFn ? item.styleFn(styles, block, output) : output;
  31220. });
  31221. output = customStyleFn ? customStyleFn(styles, block, output) : {};
  31222. styles.forEach(function (style) {
  31223. if (style.indexOf('COLOR-') === 0) {
  31224. output.color = '#' + getStyleValue(style);
  31225. } else if (style.indexOf('BGCOLOR-') === 0) {
  31226. output.backgroundColor = '#' + getStyleValue(style);
  31227. } else if (style.indexOf('FONTSIZE-') === 0) {
  31228. output.fontSize = unitExportFn(getStyleValue(style), 'font-size', 'editor');
  31229. } else if (style.indexOf('LINEHEIGHT-') === 0) {
  31230. output.lineHeight = unitExportFn(getStyleValue(style), 'line-height', 'editor');
  31231. } else if (style.indexOf('LETTERSPACING-') === 0) {
  31232. output.letterSpacing = unitExportFn(getStyleValue(style), 'letter-spacing', 'editor');
  31233. } else if (style.indexOf('TEXTINDENT-') === 0) {
  31234. output.textIndent = unitExportFn(getStyleValue(style), 'text-indent', 'editor');
  31235. } else if (style.indexOf('FONTFAMILY-') === 0) {
  31236. output.fontFamily = (fontFamilies.find(function (item) {
  31237. return item.name.toUpperCase() === getStyleValue(style);
  31238. }) || {}).family || '';
  31239. }
  31240. });
  31241. return output;
  31242. };
  31243. });
  31244. // EXTERNAL MODULE: ../node_modules/draft-js-multidecorators/index.js
  31245. var draft_js_multidecorators = __webpack_require__(18);
  31246. var draft_js_multidecorators_default = /*#__PURE__*/__webpack_require__.n(draft_js_multidecorators);
  31247. // CONCATENATED MODULE: ./renderers/decorators/Link/index.jsx
  31248. /* harmony default export */ var Link = (function (props) {
  31249. var children = props.children,
  31250. entityKey = props.entityKey,
  31251. contentState = props.contentState;
  31252. var _contentState$getEnti = contentState.getEntity(entityKey).getData(),
  31253. href = _contentState$getEnti.href,
  31254. target = _contentState$getEnti.target;
  31255. return external_react_default.a.createElement("span", {
  31256. className: "bf-link-wrap"
  31257. }, external_react_default.a.createElement("a", {
  31258. onClick: function onClick(event) {
  31259. return viewLink(event, href);
  31260. },
  31261. className: "bf-link",
  31262. href: href,
  31263. target: target
  31264. }, children));
  31265. });
  31266. var viewLink = function viewLink(event, link) {
  31267. // 当按下Ctrl/command键时,点击打开链接文字中的url
  31268. if (event.getModifierState('Control') || event.getModifierState('Meta')) {
  31269. var tempLink = document.createElement('a');
  31270. tempLink.href = link;
  31271. tempLink.target = event.currentTarget.target;
  31272. tempLink.click();
  31273. }
  31274. };
  31275. // CONCATENATED MODULE: ./renderers/decorators/index.js
  31276. var KEY_SEPARATOR = '-';
  31277. draft_js_multidecorators_default.a.prototype.getDecorations = function (block, contentState) {
  31278. var decorations = Array(block.getText().length).fill(null);
  31279. this.decorators.forEach(function (decorator, i) {
  31280. decorator.getDecorations(block, contentState).forEach(function (key, offset) {
  31281. if (!key) {
  31282. return;
  31283. }
  31284. key = i + KEY_SEPARATOR + key;
  31285. decorations[offset] = key;
  31286. });
  31287. });
  31288. return external_immutable_default.a.List(decorations);
  31289. };
  31290. var builtinDecorators = [{
  31291. type: 'entity',
  31292. decorator: {
  31293. key: 'LINK',
  31294. component: Link
  31295. }
  31296. }];
  31297. var createStrategy = function createStrategy(type) {
  31298. return function (block, callback, contentState) {
  31299. block.findEntityRanges(function (character) {
  31300. var entityKey = character.getEntity();
  31301. return entityKey !== null && contentState.getEntity(entityKey).getType() === type;
  31302. }, callback);
  31303. };
  31304. };
  31305. /* harmony default export */ var decorators = (function (editorId) {
  31306. var extensionDecorators = getExtensionDecorators(editorId);
  31307. var entityDecorators = builtinDecorators.concat(toConsumableArray_default()(extensionDecorators.filter(function (item) {
  31308. return item.type === 'entity';
  31309. })));
  31310. var strategyDecorators = extensionDecorators.filter(function (item) {
  31311. return item.type === 'strategy';
  31312. });
  31313. var classDecorators = extensionDecorators.filter(function (item) {
  31314. return item.type === 'class';
  31315. });
  31316. return new draft_js_multidecorators_default.a(toConsumableArray_default()(classDecorators.map(function (item) {
  31317. return item.decorator;
  31318. })).concat([// combine decorators created with strategy
  31319. new external_draft_js_["CompositeDecorator"](strategyDecorators.map(function (item) {
  31320. return item.decorator;
  31321. })), // combine decorators for entities
  31322. new external_draft_js_["CompositeDecorator"](entityDecorators.map(function (item) {
  31323. return {
  31324. strategy: createStrategy(item.decorator.key),
  31325. component: item.decorator.component
  31326. };
  31327. }))]));
  31328. });
  31329. // CONCATENATED MODULE: ./renderers/index.js
  31330. var getBlockRenderMap = block_blockRenderMap;
  31331. var getBlockRendererFn = block_blockRendererFn;
  31332. var getBlockStyleFn = block_blockStyleFn;
  31333. var getCustomStyleMap = inlineStyleMap;
  31334. var getCustomStyleFn = inlineStyleFn;
  31335. var getDecorators = decorators;
  31336. // EXTERNAL MODULE: ./components/business/ControlBar/style.scss
  31337. var ControlBar_style = __webpack_require__(53);
  31338. // EXTERNAL MODULE: ./components/business/LinkEditor/style.scss
  31339. var LinkEditor_style = __webpack_require__(54);
  31340. // EXTERNAL MODULE: ./components/common/DropDown/style.scss
  31341. var DropDown_style = __webpack_require__(55);
  31342. // CONCATENATED MODULE: ./helpers/responsive.js
  31343. var resizeEventHandlers = [];
  31344. var responsiveHelperInited = false;
  31345. var debouce = false;
  31346. /* harmony default export */ var responsive = ({
  31347. resolve: function resolve(eventHandler) {
  31348. var id = external_braft_utils_["BaseUtils"].UniqueIndex();
  31349. resizeEventHandlers.push({
  31350. id: id,
  31351. eventHandler: eventHandler
  31352. });
  31353. return id;
  31354. },
  31355. unresolve: function unresolve(id) {
  31356. resizeEventHandlers = resizeEventHandlers.filter(function (item) {
  31357. return item.id !== id;
  31358. });
  31359. }
  31360. });
  31361. if (!responsiveHelperInited && (typeof window === "undefined" ? "undefined" : typeof_default()(window)) === 'object') {
  31362. window.addEventListener('resize', function (event) {
  31363. clearTimeout(debouce);
  31364. debouce = setTimeout(function () {
  31365. resizeEventHandlers.map(function (item) {
  31366. typeof item.eventHandler === 'function' && item.eventHandler(event);
  31367. });
  31368. debouce = false;
  31369. }, 100);
  31370. });
  31371. responsiveHelperInited = true;
  31372. }
  31373. // CONCATENATED MODULE: ./components/common/DropDown/index.jsx
  31374. var DropDown_DropDown =
  31375. /*#__PURE__*/
  31376. function (_React$Component) {
  31377. inherits_default()(DropDown, _React$Component);
  31378. function DropDown() {
  31379. var _getPrototypeOf2;
  31380. var _this;
  31381. classCallCheck_default()(this, DropDown);
  31382. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  31383. args[_key] = arguments[_key];
  31384. }
  31385. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(DropDown)).call.apply(_getPrototypeOf2, [this].concat(args)));
  31386. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "responsiveResolveId", null);
  31387. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "dropDownHandlerElement", null);
  31388. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "dropDownContentElement", null);
  31389. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "state", {
  31390. active: false,
  31391. offset: 0
  31392. });
  31393. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "fixDropDownPosition", function () {
  31394. var viewRect = _this.props.getContainerNode().getBoundingClientRect();
  31395. var handlerRect = _this.dropDownHandlerElement.getBoundingClientRect();
  31396. var contentRect = _this.dropDownContentElement.getBoundingClientRect();
  31397. var offset = 0;
  31398. var right = handlerRect.right - handlerRect.width / 2 + contentRect.width / 2;
  31399. var left = handlerRect.left + handlerRect.width / 2 - contentRect.width / 2;
  31400. right = viewRect.right - right;
  31401. left = left - viewRect.left;
  31402. if (right < 10) {
  31403. offset = right - 10;
  31404. } else if (left < 10) {
  31405. offset = left * -1 + 10;
  31406. }
  31407. if (offset !== _this.state.offset) {
  31408. _this.setState({
  31409. offset: offset
  31410. });
  31411. }
  31412. });
  31413. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "registerClickEvent", function (event) {
  31414. var autoHide = _this.props.autoHide;
  31415. var active = _this.state.active;
  31416. if (_this.dropDownContentElement.contains(event.target) || _this.dropDownHandlerElement.contains(event.target)) {
  31417. return false;
  31418. }
  31419. autoHide && active && _this.hide();
  31420. });
  31421. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "toggle", function () {
  31422. _this.setState({
  31423. active: !_this.state.active
  31424. });
  31425. });
  31426. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "show", function () {
  31427. _this.setState({
  31428. active: true
  31429. });
  31430. });
  31431. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "hide", function () {
  31432. _this.setState({
  31433. active: false
  31434. });
  31435. });
  31436. return _this;
  31437. }
  31438. createClass_default()(DropDown, [{
  31439. key: "componentDidMount",
  31440. value: function componentDidMount() {
  31441. if (document) {
  31442. document.body.addEventListener('click', this.registerClickEvent);
  31443. this.responsiveResolveId = responsive.resolve(this.fixDropDownPosition);
  31444. }
  31445. }
  31446. }, {
  31447. key: "componentWillReceiveProps",
  31448. value: function componentWillReceiveProps(next) {
  31449. if (!this.props.disabled && next.disabled) {
  31450. this.hide();
  31451. }
  31452. }
  31453. }, {
  31454. key: "componentDidUpdate",
  31455. value: function componentDidUpdate(prevState) {
  31456. if (!prevState.active && this.state.active) {
  31457. this.fixDropDownPosition();
  31458. }
  31459. }
  31460. }, {
  31461. key: "componentWillUnmount",
  31462. value: function componentWillUnmount() {
  31463. if (document) {
  31464. document.body.removeEventListener('click', this.registerClickEvent);
  31465. responsive.unresolve(this.responsiveResolveId);
  31466. }
  31467. }
  31468. }, {
  31469. key: "render",
  31470. value: function render() {
  31471. var _this2 = this;
  31472. var _this$state = this.state,
  31473. active = _this$state.active,
  31474. offset = _this$state.offset;
  31475. var _this$props = this.props,
  31476. caption = _this$props.caption,
  31477. htmlCaption = _this$props.htmlCaption,
  31478. title = _this$props.title,
  31479. disabled = _this$props.disabled,
  31480. showArrow = _this$props.showArrow,
  31481. arrowActive = _this$props.arrowActive,
  31482. className = _this$props.className,
  31483. children = _this$props.children,
  31484. theme = _this$props.theme;
  31485. disabled && (active = false);
  31486. theme === 'light' && (className = ' light-theme ' + className);
  31487. return external_react_default.a.createElement("div", {
  31488. className: 'bf-dropdown ' + (active ? 'active ' : '') + (disabled ? 'disabled ' : '') + className
  31489. }, htmlCaption ? external_react_default.a.createElement("button", {
  31490. type: "button",
  31491. className: "dropdown-handler",
  31492. "data-title": title,
  31493. onClick: this.toggle,
  31494. dangerouslySetInnerHTML: htmlCaption ? {
  31495. __html: htmlCaption
  31496. } : null,
  31497. ref: function ref(instance) {
  31498. return _this2.dropDownHandlerElement = instance;
  31499. }
  31500. }) : external_react_default.a.createElement("button", {
  31501. type: "button",
  31502. className: "dropdown-handler",
  31503. "data-title": title,
  31504. onClick: this.toggle,
  31505. ref: function ref(instance) {
  31506. return _this2.dropDownHandlerElement = instance;
  31507. }
  31508. }, external_react_default.a.createElement("span", null, caption), showArrow !== false ? external_react_default.a.createElement("i", {
  31509. className: "bfi-drop-down"
  31510. }) : null), external_react_default.a.createElement("div", {
  31511. className: "dropdown-content",
  31512. style: {
  31513. marginLeft: offset
  31514. },
  31515. ref: function ref(instance) {
  31516. return _this2.dropDownContentElement = instance;
  31517. }
  31518. }, external_react_default.a.createElement("i", {
  31519. style: {
  31520. marginLeft: offset * -1
  31521. },
  31522. className: 'dropdown-arrow' + (arrowActive ? ' active' : '')
  31523. }), external_react_default.a.createElement("div", {
  31524. className: "dropdown-content-inner"
  31525. }, children)));
  31526. }
  31527. }]);
  31528. return DropDown;
  31529. }(external_react_default.a.Component);
  31530. // CONCATENATED MODULE: ./components/business/ControlGroup/index.jsx
  31531. /* harmony default export */ var ControlGroup = (function (props) {
  31532. if (external_react_default.a.Fragment) {
  31533. return external_react_default.a.createElement(external_react_default.a.Fragment, null, props.children);
  31534. } else {
  31535. return external_react_default.a.createElement("div", {
  31536. className: "control-item-group"
  31537. }, props.children);
  31538. }
  31539. });
  31540. // CONCATENATED MODULE: ./components/business/LinkEditor/index.jsx
  31541. var LinkEditor_LinkEditor =
  31542. /*#__PURE__*/
  31543. function (_React$Component) {
  31544. inherits_default()(LinkEditor, _React$Component);
  31545. function LinkEditor(props) {
  31546. var _this;
  31547. classCallCheck_default()(this, LinkEditor);
  31548. _this = possibleConstructorReturn_default()(this, getPrototypeOf_default()(LinkEditor).call(this, props));
  31549. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "dropDownInstance", null);
  31550. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handeKeyDown", function (e) {
  31551. if (e.keyCode === 13) {
  31552. _this.handleConfirm();
  31553. e.preventDefault();
  31554. return false;
  31555. }
  31556. });
  31557. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleTnputText", function (e) {
  31558. _this.setState({
  31559. text: e.currentTarget.value
  31560. });
  31561. });
  31562. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleInputLink", function (e) {
  31563. _this.setState({
  31564. href: e.currentTarget.value
  31565. });
  31566. });
  31567. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "setTarget", function () {
  31568. _this.setState({
  31569. target: _this.state.target === '_blank' ? '' : '_blank'
  31570. });
  31571. });
  31572. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleCancel", function () {
  31573. _this.dropDownInstance.hide();
  31574. });
  31575. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleUnlink", function () {
  31576. _this.dropDownInstance.hide();
  31577. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionLink(_this.props.editorState, false));
  31578. });
  31579. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleConfirm", function () {
  31580. var _this$state = _this.state,
  31581. text = _this$state.text,
  31582. href = _this$state.href,
  31583. target = _this$state.target,
  31584. textSelected = _this$state.textSelected;
  31585. var hookReturns = _this.props.hooks('toggle-link', {
  31586. href: href,
  31587. target: target
  31588. })({
  31589. href: href,
  31590. target: target
  31591. });
  31592. _this.dropDownInstance.hide();
  31593. _this.props.editor.requestFocus();
  31594. if (hookReturns === false) {
  31595. return false;
  31596. }
  31597. if (hookReturns) {
  31598. typeof hookReturns.href === 'string' && (href = hookReturns.href);
  31599. typeof hookReturns.target === 'string' && (target = hookReturns.target);
  31600. }
  31601. if (textSelected) {
  31602. if (href) {
  31603. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionLink(_this.props.editorState, href, target));
  31604. } else {
  31605. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionLink(_this.props.editorState, false));
  31606. }
  31607. } else {
  31608. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].insertText(_this.props.editorState, text || href, null, {
  31609. type: 'LINK',
  31610. data: {
  31611. href: href,
  31612. target: target
  31613. }
  31614. }));
  31615. }
  31616. });
  31617. _this.state = {
  31618. text: '',
  31619. href: '',
  31620. target: props.defaultLinkTarget || '',
  31621. textSelected: false
  31622. };
  31623. return _this;
  31624. }
  31625. createClass_default()(LinkEditor, [{
  31626. key: "componentWillReceiveProps",
  31627. value: function componentWillReceiveProps(nextProps) {
  31628. var _ContentUtils$getSele = external_braft_utils_["ContentUtils"].getSelectionEntityData(nextProps.editorState, 'LINK'),
  31629. href = _ContentUtils$getSele.href,
  31630. target = _ContentUtils$getSele.target;
  31631. var textSelected = !external_braft_utils_["ContentUtils"].isSelectionCollapsed(this.props.editorState) && external_braft_utils_["ContentUtils"].getSelectionBlockType(this.props.editorState) !== 'atomic';
  31632. var selectedText = '';
  31633. if (textSelected) {
  31634. selectedText = external_braft_utils_["ContentUtils"].getSelectionText(this.props.editorState);
  31635. }
  31636. this.setState({
  31637. textSelected: textSelected,
  31638. text: selectedText,
  31639. href: href || '',
  31640. target: typeof target === 'undefined' ? nextProps.defaultLinkTarget || '' : target || ''
  31641. });
  31642. }
  31643. }, {
  31644. key: "render",
  31645. value: function render() {
  31646. var _this2 = this;
  31647. var allowInsertLinkText = this.props.allowInsertLinkText;
  31648. var _this$state2 = this.state,
  31649. text = _this$state2.text,
  31650. href = _this$state2.href,
  31651. target = _this$state2.target,
  31652. textSelected = _this$state2.textSelected;
  31653. var caption = external_react_default.a.createElement("i", {
  31654. className: "bfi-link"
  31655. });
  31656. return external_react_default.a.createElement(ControlGroup, null, external_react_default.a.createElement(DropDown_DropDown, {
  31657. key: 0,
  31658. caption: caption,
  31659. title: this.props.language.controls.link,
  31660. autoHide: true,
  31661. getContainerNode: this.props.getContainerNode,
  31662. showArrow: false,
  31663. ref: function ref(instance) {
  31664. return _this2.dropDownInstance = instance;
  31665. },
  31666. className: 'control-item dropdown link-editor-dropdown'
  31667. }, external_react_default.a.createElement("div", {
  31668. className: "bf-link-editor"
  31669. }, allowInsertLinkText ? external_react_default.a.createElement("div", {
  31670. className: "input-group"
  31671. }, external_react_default.a.createElement("input", {
  31672. type: "text",
  31673. value: text,
  31674. spellCheck: false,
  31675. disabled: textSelected,
  31676. placeholder: this.props.language.linkEditor.textInputPlaceHolder,
  31677. onKeyDown: this.handeKeyDown,
  31678. onChange: this.handleTnputText
  31679. })) : null, external_react_default.a.createElement("div", {
  31680. className: "input-group"
  31681. }, external_react_default.a.createElement("input", {
  31682. type: "text",
  31683. value: href,
  31684. spellCheck: false,
  31685. placeholder: this.props.language.linkEditor.linkInputPlaceHolder,
  31686. onKeyDown: this.handeKeyDown,
  31687. onChange: this.handleInputLink
  31688. })), external_react_default.a.createElement("div", {
  31689. className: "switch-group"
  31690. }, external_react_default.a.createElement(Switch, {
  31691. active: target === '_blank',
  31692. onClick: this.setTarget
  31693. }), external_react_default.a.createElement("label", null, this.props.language.linkEditor.openInNewWindow)), external_react_default.a.createElement("div", {
  31694. className: "buttons"
  31695. }, external_react_default.a.createElement("a", {
  31696. onClick: this.handleUnlink,
  31697. className: "primary button-remove-link pull-left"
  31698. }, external_react_default.a.createElement("i", {
  31699. className: "bfi-close"
  31700. }), external_react_default.a.createElement("span", null, this.props.language.linkEditor.removeLink)), external_react_default.a.createElement("button", {
  31701. type: "button",
  31702. onClick: this.handleConfirm,
  31703. className: "primary pull-right"
  31704. }, this.props.language.base.confirm), external_react_default.a.createElement("button", {
  31705. type: "button",
  31706. onClick: this.handleCancel,
  31707. className: "default pull-right"
  31708. }, this.props.language.base.cancel)))), external_react_default.a.createElement("button", {
  31709. key: 1,
  31710. type: "button",
  31711. "data-title": this.props.language.controls.unlink,
  31712. className: "control-item button",
  31713. onClick: this.handleUnlink,
  31714. disabled: !textSelected || !href
  31715. }, external_react_default.a.createElement("i", {
  31716. className: "bfi-link-off"
  31717. })));
  31718. }
  31719. }]);
  31720. return LinkEditor;
  31721. }(external_react_default.a.Component);
  31722. // EXTERNAL MODULE: ./components/business/Headings/style.scss
  31723. var Headings_style = __webpack_require__(56);
  31724. // CONCATENATED MODULE: ./configs/maps.js
  31725. var maps_getHeadings = function getHeadings(lang) {
  31726. return [{
  31727. key: 'header-one',
  31728. title: lang.controls.header + ' 1',
  31729. text: external_react_default.a.createElement("h1", null, lang.controls.header, " 1"),
  31730. type: 'block-type',
  31731. command: 'header-one'
  31732. }, {
  31733. key: 'header-two',
  31734. title: lang.controls.header + ' 2',
  31735. text: external_react_default.a.createElement("h2", null, lang.controls.header, " 2"),
  31736. type: 'block-type',
  31737. command: 'header-two'
  31738. }, {
  31739. key: 'header-three',
  31740. title: lang.controls.header + ' 3',
  31741. text: external_react_default.a.createElement("h3", null, lang.controls.header, " 3"),
  31742. type: 'block-type',
  31743. command: 'header-three'
  31744. }, {
  31745. key: 'header-four',
  31746. title: lang.controls.header + ' 4',
  31747. text: external_react_default.a.createElement("h4", null, lang.controls.header, " 4"),
  31748. type: 'block-type',
  31749. command: 'header-four'
  31750. }, {
  31751. key: 'header-five',
  31752. title: lang.controls.header + ' 5',
  31753. text: external_react_default.a.createElement("h5", null, lang.controls.header, " 5"),
  31754. type: 'block-type',
  31755. command: 'header-five'
  31756. }, {
  31757. key: 'header-six',
  31758. title: lang.controls.header + ' 6',
  31759. text: external_react_default.a.createElement("h6", null, lang.controls.header, " 6"),
  31760. type: 'block-type',
  31761. command: 'header-six'
  31762. }, {
  31763. key: 'unstyled',
  31764. title: lang.controls.normal,
  31765. text: lang.controls.normal,
  31766. type: 'block-type',
  31767. command: 'unstyled'
  31768. }];
  31769. };
  31770. // CONCATENATED MODULE: ./components/business/Headings/index.jsx
  31771. /* harmony default export */ var Headings = (function (props) {
  31772. var dropDownInstance = null;
  31773. var headings = maps_getHeadings(props.language).filter(function (item) {
  31774. return props.headings.indexOf(item.key) !== -1;
  31775. });
  31776. var currentHeadingIndex = headings.findIndex(function (item) {
  31777. return item.command === props.current;
  31778. });
  31779. var caption = headings[currentHeadingIndex] ? headings[currentHeadingIndex].title : props.language.controls.normal;
  31780. return external_react_default.a.createElement(DropDown_DropDown, {
  31781. caption: caption,
  31782. autoHide: true,
  31783. getContainerNode: props.getContainerNode,
  31784. title: props.language.controls.headings,
  31785. arrowActive: currentHeadingIndex === 0,
  31786. ref: function ref(instance) {
  31787. return dropDownInstance = instance;
  31788. },
  31789. className: 'control-item dropdown headings-dropdown'
  31790. }, external_react_default.a.createElement("ul", {
  31791. className: "menu"
  31792. }, headings.map(function (item, index) {
  31793. var isActive = props.current === item.command;
  31794. return external_react_default.a.createElement("li", {
  31795. key: index,
  31796. className: 'menu-item' + (isActive ? ' active' : ''),
  31797. onClick: function onClick() {
  31798. props.onChange(item.command, item.type), dropDownInstance.hide();
  31799. }
  31800. }, item.text);
  31801. })));
  31802. });
  31803. // EXTERNAL MODULE: ./components/business/TextColor/style.scss
  31804. var TextColor_style = __webpack_require__(57);
  31805. // EXTERNAL MODULE: ./components/common/ColorPicker/style.scss
  31806. var ColorPicker_style = __webpack_require__(58);
  31807. // CONCATENATED MODULE: ./components/common/ColorPicker/index.jsx
  31808. /* harmony default export */ var common_ColorPicker = (function (props) {
  31809. return external_react_default.a.createElement("div", {
  31810. className: "bf-colors-wrap"
  31811. }, external_react_default.a.createElement("ul", {
  31812. className: "bf-colors"
  31813. }, props.presetColors.map(function (item, index) {
  31814. var className = props.color && item.toLowerCase() === props.color.toLowerCase() ? 'color-item active' : 'color-item';
  31815. return external_react_default.a.createElement("li", {
  31816. key: index,
  31817. title: item,
  31818. className: className,
  31819. style: {
  31820. color: item
  31821. },
  31822. "data-color": item.replace('#', ''),
  31823. onClick: function onClick(e) {
  31824. props.onChange(e.currentTarget.dataset.color, true);
  31825. }
  31826. });
  31827. })));
  31828. });
  31829. // CONCATENATED MODULE: ./components/business/TextColor/index.jsx
  31830. var TextColor_TextColor =
  31831. /*#__PURE__*/
  31832. function (_React$Component) {
  31833. inherits_default()(TextColor, _React$Component);
  31834. function TextColor() {
  31835. var _getPrototypeOf2;
  31836. var _this;
  31837. classCallCheck_default()(this, TextColor);
  31838. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  31839. args[_key] = arguments[_key];
  31840. }
  31841. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(TextColor)).call.apply(_getPrototypeOf2, [this].concat(args)));
  31842. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "state", {
  31843. colorType: 'color'
  31844. });
  31845. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "switchColorType", function (_ref) {
  31846. var currentTarget = _ref.currentTarget;
  31847. _this.setState({
  31848. colorType: currentTarget.dataset.type
  31849. });
  31850. });
  31851. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "toggleColor", function (color, closePicker) {
  31852. if (color) {
  31853. var hookReturns = _this.props.hooks("toggle-text-".concat(_this.state.colorType), color)(color);
  31854. if (hookReturns === false) {
  31855. return false;
  31856. }
  31857. if (typeof hookReturns === 'string') {
  31858. color = hookReturns;
  31859. }
  31860. if (_this.state.colorType === 'color') {
  31861. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionColor(_this.props.editorState, color));
  31862. } else {
  31863. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionBackgroundColor(_this.props.editorState, color));
  31864. }
  31865. }
  31866. if (closePicker) {
  31867. _this.dropDownInstance.hide();
  31868. _this.props.editor.requestFocus();
  31869. }
  31870. });
  31871. return _this;
  31872. }
  31873. createClass_default()(TextColor, [{
  31874. key: "render",
  31875. value: function render() {
  31876. var _this2 = this;
  31877. var captionStyle = {};
  31878. var currentColor = null;
  31879. var colorType = this.state.colorType;
  31880. var selectionStyles = this.props.editorState.getCurrentInlineStyle().toJS();
  31881. selectionStyles.forEach(function (style) {
  31882. if (style.indexOf('COLOR-') === 0) {
  31883. captionStyle.color = '#' + style.split('-')[1];
  31884. colorType === 'color' && (currentColor = captionStyle.color);
  31885. }
  31886. if (style.indexOf('BGCOLOR-') === 0) {
  31887. captionStyle.backgroundColor = '#' + style.split('-')[1];
  31888. colorType === 'background-color' && (currentColor = captionStyle.backgroundColor);
  31889. }
  31890. });
  31891. var caption = external_react_default.a.createElement("i", {
  31892. style: captionStyle,
  31893. className: "bfi-text-color"
  31894. }, external_react_default.a.createElement("span", {
  31895. className: "path1"
  31896. }), external_react_default.a.createElement("span", {
  31897. className: "path2"
  31898. }));
  31899. var ColorPicker = this.props.colorPicker || common_ColorPicker;
  31900. return external_react_default.a.createElement(DropDown_DropDown, {
  31901. caption: caption,
  31902. title: this.props.language.controls.color,
  31903. showArrow: false,
  31904. autoHide: this.props.autoHide,
  31905. theme: this.props.theme,
  31906. getContainerNode: this.props.getContainerNode,
  31907. ref: function ref(instance) {
  31908. return _this2.dropDownInstance = instance;
  31909. },
  31910. className: 'control-item dropdown text-color-dropdown'
  31911. }, external_react_default.a.createElement("div", {
  31912. className: "bf-text-color-picker-wrap"
  31913. }, external_react_default.a.createElement("div", {
  31914. className: "bf-color-switch-buttons",
  31915. style: this.props.enableBackgroundColor ? {} : {
  31916. display: 'none'
  31917. }
  31918. }, external_react_default.a.createElement("button", {
  31919. type: "button",
  31920. "data-type": "color",
  31921. className: colorType === 'color' ? 'active' : '',
  31922. onClick: this.switchColorType
  31923. }, this.props.language.controls.textColor), external_react_default.a.createElement("button", {
  31924. type: "button",
  31925. "data-type": "background-color",
  31926. className: colorType === 'background-color' ? 'active' : '',
  31927. onClick: this.switchColorType
  31928. }, this.props.language.controls.backgroundColor)), external_react_default.a.createElement(ColorPicker, {
  31929. width: 200,
  31930. color: currentColor,
  31931. disableAlpha: true,
  31932. presetColors: this.props.colors,
  31933. onChange: this.toggleColor
  31934. })));
  31935. }
  31936. }]);
  31937. return TextColor;
  31938. }(external_react_default.a.Component);
  31939. // EXTERNAL MODULE: ./components/business/FontSize/style.scss
  31940. var FontSize_style = __webpack_require__(59);
  31941. // CONCATENATED MODULE: ./components/business/FontSize/index.jsx
  31942. var FontSize_toggleFontSize = function toggleFontSize(event, props) {
  31943. var fontSize = event.currentTarget.dataset.size;
  31944. var hookReturns = props.hooks('toggle-font-size', fontSize)(fontSize);
  31945. if (hookReturns === false) {
  31946. return false;
  31947. }
  31948. if (!isNaN(fontSize)) {
  31949. fontSize = hookReturns;
  31950. }
  31951. props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionFontSize(props.editorState, fontSize));
  31952. props.editor.requestFocus();
  31953. };
  31954. /* harmony default export */ var FontSize = (function (props) {
  31955. var caption = null;
  31956. var currentFontSize = null;
  31957. var dropDownInstance = null;
  31958. props.fontSizes.find(function (item) {
  31959. if (external_braft_utils_["ContentUtils"].selectionHasInlineStyle(props.editorState, 'FONTSIZE-' + item)) {
  31960. caption = item;
  31961. currentFontSize = item;
  31962. return true;
  31963. }
  31964. return false;
  31965. });
  31966. return external_react_default.a.createElement(DropDown_DropDown, {
  31967. autoHide: true,
  31968. caption: caption || props.defaultCaption,
  31969. getContainerNode: props.getContainerNode,
  31970. title: props.language.controls.fontSize,
  31971. ref: function ref(instance) {
  31972. return dropDownInstance = instance;
  31973. },
  31974. className: 'control-item dropdown bf-font-size-dropdown'
  31975. }, external_react_default.a.createElement("ul", {
  31976. className: "bf-font-sizes"
  31977. }, props.fontSizes.map(function (item, index) {
  31978. return external_react_default.a.createElement("li", {
  31979. key: index,
  31980. className: item === currentFontSize ? 'active' : null,
  31981. "data-size": item,
  31982. onClick: function onClick(event) {
  31983. FontSize_toggleFontSize(event, props), dropDownInstance.hide();
  31984. }
  31985. }, item);
  31986. })));
  31987. });
  31988. // EXTERNAL MODULE: ./components/business/LineHeight/style.scss
  31989. var LineHeight_style = __webpack_require__(60);
  31990. // CONCATENATED MODULE: ./components/business/LineHeight/index.jsx
  31991. var LineHeight_toggleLineHeight = function toggleLineHeight(event, props) {
  31992. var lineHeight = event.currentTarget.dataset.size;
  31993. var hookReturns = props.hooks('toggle-line-height', lineHeight)(lineHeight);
  31994. if (hookReturns === false) {
  31995. return false;
  31996. }
  31997. if (!isNaN(hookReturns)) {
  31998. lineHeight = hookReturns;
  31999. }
  32000. props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionLineHeight(props.editorState, lineHeight));
  32001. props.editor.requestFocus();
  32002. };
  32003. /* harmony default export */ var LineHeight = (function (props) {
  32004. var caption = null;
  32005. var currentLineHeight = null;
  32006. var dropDownInstance = null;
  32007. props.lineHeights.find(function (item) {
  32008. if (external_braft_utils_["ContentUtils"].selectionHasInlineStyle(props.editorState, 'LINEHEIGHT-' + item)) {
  32009. caption = item;
  32010. currentLineHeight = item;
  32011. return true;
  32012. }
  32013. return false;
  32014. });
  32015. return external_react_default.a.createElement(DropDown_DropDown, {
  32016. autoHide: true,
  32017. caption: caption || props.defaultCaption,
  32018. getContainerNode: props.getContainerNode,
  32019. title: props.language.controls.lineHeight,
  32020. ref: function ref(instance) {
  32021. return dropDownInstance = instance;
  32022. },
  32023. className: 'control-item dropdown bf-line-height-dropdown'
  32024. }, external_react_default.a.createElement("ul", {
  32025. className: "bf-line-heights"
  32026. }, props.lineHeights.map(function (item, index) {
  32027. return external_react_default.a.createElement("li", {
  32028. key: index,
  32029. className: item === currentLineHeight ? 'active' : null,
  32030. "data-size": item,
  32031. onClick: function onClick(event) {
  32032. LineHeight_toggleLineHeight(event, props), dropDownInstance.hide();
  32033. }
  32034. }, item);
  32035. })));
  32036. });
  32037. // EXTERNAL MODULE: ./components/business/FontFamily/style.scss
  32038. var FontFamily_style = __webpack_require__(61);
  32039. // CONCATENATED MODULE: ./components/business/FontFamily/index.jsx
  32040. var FontFamily_toggleFontFamily = function toggleFontFamily(event, props) {
  32041. var fontFamilyName = event.currentTarget.dataset.name;
  32042. var hookReturns = props.hooks('toggle-font-family', fontFamilyName)(fontFamilyName, props.fontFamilies);
  32043. if (hookReturns === false) {
  32044. return false;
  32045. }
  32046. if (typeof hookReturns === 'string') {
  32047. fontFamilyName = hookReturns;
  32048. }
  32049. props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionFontFamily(props.editorState, fontFamilyName));
  32050. props.editor.requestFocus();
  32051. };
  32052. /* harmony default export */ var FontFamily = (function (props) {
  32053. var caption = null;
  32054. var currentIndex = null;
  32055. var dropDownInstance = null;
  32056. props.fontFamilies.find(function (item, index) {
  32057. if (external_braft_utils_["ContentUtils"].selectionHasInlineStyle(props.editorState, 'FONTFAMILY-' + item.name)) {
  32058. caption = item.name;
  32059. currentIndex = index;
  32060. return true;
  32061. }
  32062. return false;
  32063. });
  32064. return external_react_default.a.createElement(DropDown_DropDown, {
  32065. caption: caption || props.defaultCaption,
  32066. getContainerNode: props.getContainerNode,
  32067. title: props.language.controls.fontFamily,
  32068. autoHide: true,
  32069. arrowActive: currentIndex === 0,
  32070. ref: function ref(instance) {
  32071. return dropDownInstance = instance;
  32072. },
  32073. className: 'control-item dropdown font-family-dropdown'
  32074. }, external_react_default.a.createElement("ul", {
  32075. className: "menu"
  32076. }, props.fontFamilies.map(function (item, index) {
  32077. return external_react_default.a.createElement("li", {
  32078. key: index,
  32079. className: 'menu-item ' + (index === currentIndex ? 'active' : ''),
  32080. "data-name": item.name,
  32081. onClick: function onClick(event) {
  32082. FontFamily_toggleFontFamily(event, props), dropDownInstance.hide();
  32083. }
  32084. }, external_react_default.a.createElement("span", {
  32085. style: {
  32086. fontFamily: item.family
  32087. }
  32088. }, item.name));
  32089. })));
  32090. });
  32091. // CONCATENATED MODULE: ./components/business/TextAlign/index.jsx
  32092. var TextAlign_TextAlign =
  32093. /*#__PURE__*/
  32094. function (_React$Component) {
  32095. inherits_default()(TextAlign, _React$Component);
  32096. function TextAlign() {
  32097. var _getPrototypeOf2;
  32098. var _this;
  32099. classCallCheck_default()(this, TextAlign);
  32100. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  32101. args[_key] = arguments[_key];
  32102. }
  32103. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(TextAlign)).call.apply(_getPrototypeOf2, [this].concat(args)));
  32104. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "state", {
  32105. currentAlignment: undefined
  32106. });
  32107. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "setAlignment", function (event) {
  32108. var alignment = event.currentTarget.dataset.alignment;
  32109. var hookReturns = _this.props.hooks('toggle-text-alignment', alignment)(alignment);
  32110. if (_this.props.textAligns.indexOf(hookReturns) > -1) {
  32111. alignment = hookReturns;
  32112. }
  32113. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionAlignment(_this.props.editorState, alignment));
  32114. _this.props.editor.requestFocus();
  32115. });
  32116. return _this;
  32117. }
  32118. createClass_default()(TextAlign, [{
  32119. key: "componentWillReceiveProps",
  32120. value: function componentWillReceiveProps(next) {
  32121. this.setState({
  32122. currentAlignment: external_braft_utils_["ContentUtils"].getSelectionBlockData(next.editorState, 'textAlign')
  32123. });
  32124. }
  32125. }, {
  32126. key: "render",
  32127. value: function render() {
  32128. var _this2 = this;
  32129. var textAlignmentTitles = [this.props.language.controls.alignLeft, this.props.language.controls.alignCenter, this.props.language.controls.alignRight, this.props.language.controls.alignJustify];
  32130. return external_react_default.a.createElement(ControlGroup, null, this.props.textAligns.map(function (item, index) {
  32131. return external_react_default.a.createElement("button", {
  32132. type: "button",
  32133. key: index,
  32134. "data-title": textAlignmentTitles[index],
  32135. "data-alignment": item,
  32136. className: 'control-item button ' + (item === _this2.state.currentAlignment ? 'active' : null),
  32137. onClick: _this2.setAlignment
  32138. }, external_react_default.a.createElement("i", {
  32139. className: 'bfi-align-' + item
  32140. }));
  32141. }));
  32142. }
  32143. }]);
  32144. return TextAlign;
  32145. }(external_react_default.a.Component);
  32146. // EXTERNAL MODULE: ./components/business/EmojiPicker/style.scss
  32147. var EmojiPicker_style = __webpack_require__(62);
  32148. // CONCATENATED MODULE: ./components/business/EmojiPicker/index.jsx
  32149. var EmojiPicker_insertEmoji = function insertEmoji(event, props) {
  32150. var emoji = event.currentTarget.dataset.emoji;
  32151. var hookReturns = props.hooks('insert-emoji', emoji)(emoji);
  32152. if (hookReturns === false) {
  32153. return false;
  32154. }
  32155. if (typeof hookReturns === 'string') {
  32156. emoji = hookReturns;
  32157. }
  32158. props.editor.setValue(external_braft_utils_["ContentUtils"].insertText(props.editorState, emoji));
  32159. props.editor.requestFocus();
  32160. };
  32161. /* harmony default export */ var EmojiPicker = (function (props) {
  32162. return external_react_default.a.createElement(DropDown_DropDown, {
  32163. caption: props.defaultCaption,
  32164. autoHide: true,
  32165. showArrow: false,
  32166. getContainerNode: props.getContainerNode,
  32167. title: props.language.controls.emoji,
  32168. className: 'control-item dropdown bf-emoji-dropdown'
  32169. }, external_react_default.a.createElement("div", {
  32170. className: "bf-emojis-wrap"
  32171. }, external_react_default.a.createElement("ul", {
  32172. className: "bf-emojis"
  32173. }, props.emojis.map(function (item, index) {
  32174. return external_react_default.a.createElement("li", {
  32175. key: index,
  32176. "data-emoji": item,
  32177. onClick: function onClick(event) {
  32178. return EmojiPicker_insertEmoji(event, props);
  32179. }
  32180. }, item);
  32181. }))));
  32182. });
  32183. // EXTERNAL MODULE: ./components/business/LetterSpacing/style.scss
  32184. var LetterSpacing_style = __webpack_require__(63);
  32185. // CONCATENATED MODULE: ./components/business/LetterSpacing/index.jsx
  32186. var LetterSpacing_toggleLetterSpacing = function toggleLetterSpacing(event, props) {
  32187. var letterSpacing = event.currentTarget.dataset.size;
  32188. var hookReturns = props.hooks('toggle-letter-spacing', letterSpacing)(letterSpacing);
  32189. if (hookReturns === false) {
  32190. return false;
  32191. }
  32192. if (!isNaN(hookReturns)) {
  32193. letterSpacing = hookReturns;
  32194. }
  32195. props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionLetterSpacing(props.editorState, letterSpacing));
  32196. props.editor.requestFocus();
  32197. };
  32198. /* harmony default export */ var LetterSpacing = (function (props) {
  32199. var caption = null;
  32200. var currentLetterSpacing = null;
  32201. var dropDownInstance = null;
  32202. props.letterSpacings.find(function (item) {
  32203. if (external_braft_utils_["ContentUtils"].selectionHasInlineStyle(props.editorState, 'LETTERSPACING-' + item)) {
  32204. caption = item;
  32205. currentLetterSpacing = item;
  32206. return true;
  32207. }
  32208. return false;
  32209. });
  32210. return external_react_default.a.createElement(DropDown_DropDown, {
  32211. autoHide: true,
  32212. caption: caption || props.defaultCaption,
  32213. getContainerNode: props.getContainerNode,
  32214. title: props.language.controls.letterSpacing,
  32215. ref: function ref(instance) {
  32216. return dropDownInstance = instance;
  32217. },
  32218. className: 'control-item dropdown bf-letter-spacing-dropdown'
  32219. }, external_react_default.a.createElement("ul", {
  32220. className: "bf-letter-spacings"
  32221. }, props.letterSpacings.map(function (item, index) {
  32222. return external_react_default.a.createElement("li", {
  32223. key: index,
  32224. className: item === currentLetterSpacing ? 'active' : null,
  32225. "data-size": item,
  32226. onClick: function onClick(event) {
  32227. LetterSpacing_toggleLetterSpacing(event, props), dropDownInstance.hide();
  32228. }
  32229. }, item);
  32230. })));
  32231. });
  32232. // CONCATENATED MODULE: ./components/business/TextIndent/index.jsx
  32233. var TextIndent_TextAlign =
  32234. /*#__PURE__*/
  32235. function (_React$Component) {
  32236. inherits_default()(TextAlign, _React$Component);
  32237. function TextAlign() {
  32238. var _getPrototypeOf2;
  32239. var _this;
  32240. classCallCheck_default()(this, TextAlign);
  32241. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  32242. args[_key] = arguments[_key];
  32243. }
  32244. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(TextAlign)).call.apply(_getPrototypeOf2, [this].concat(args)));
  32245. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "state", {
  32246. currentIndent: 0
  32247. });
  32248. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "increaseIndent", function () {
  32249. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].increaseSelectionIndent(_this.props.editorState));
  32250. _this.props.editor.requestFocus();
  32251. });
  32252. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "decreaseIndent", function () {
  32253. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].decreaseSelectionIndent(_this.props.editorState));
  32254. _this.props.editor.requestFocus();
  32255. });
  32256. return _this;
  32257. }
  32258. createClass_default()(TextAlign, [{
  32259. key: "componentWillReceiveProps",
  32260. value: function componentWillReceiveProps(nextProps) {
  32261. this.setState({
  32262. currentIndent: external_braft_utils_["ContentUtils"].getSelectionBlockData(nextProps.editorState, 'textIndent') || 0
  32263. });
  32264. }
  32265. }, {
  32266. key: "render",
  32267. value: function render() {
  32268. var currentIndent = this.state.currentIndent;
  32269. var language = this.props.language;
  32270. return external_react_default.a.createElement(ControlGroup, null, external_react_default.a.createElement("button", {
  32271. key: 0,
  32272. type: "button",
  32273. "data-title": language.controls.increaseIndent,
  32274. disabled: currentIndent >= 6,
  32275. className: "control-item button button-indent-increase".concat(currentIndent > 0 && currentIndent < 6 ? ' active' : ''),
  32276. onClick: this.increaseIndent
  32277. }, external_react_default.a.createElement("i", {
  32278. className: 'bfi-indent-increase'
  32279. })), external_react_default.a.createElement("button", {
  32280. key: 1,
  32281. type: "button",
  32282. "data-title": language.controls.decreaseIndent,
  32283. disabled: currentIndent <= 0,
  32284. className: "control-item button button-indent-decrease",
  32285. onClick: this.decreaseIndent
  32286. }, external_react_default.a.createElement("i", {
  32287. className: 'bfi-indent-decrease'
  32288. })));
  32289. }
  32290. }]);
  32291. return TextAlign;
  32292. }(external_react_default.a.Component);
  32293. // CONCATENATED MODULE: ./components/business/ControlBar/index.jsx
  32294. var commandHookMap = {
  32295. 'inline-style': 'toggle-inline-style',
  32296. 'block-type': 'change-block-type',
  32297. 'editor-method': 'exec-editor-command'
  32298. };
  32299. var exclusiveInlineStyles = {
  32300. 'superscript': 'subscript',
  32301. 'subscript': 'superscript'
  32302. };
  32303. var mergeControls = function mergeControls(commonProps, builtControls, extensionControls, extendControls) {
  32304. extensionControls = extensionControls.map(function (item) {
  32305. return typeof item === 'function' ? item(commonProps) : item;
  32306. });
  32307. extendControls = extendControls.map(function (item) {
  32308. return typeof item === 'function' ? item(commonProps) : item;
  32309. });
  32310. if (extensionControls.length === 0 && extendControls.length === 0) {
  32311. return builtControls;
  32312. }
  32313. return builtControls.map(function (item) {
  32314. return extendControls.find(function (subItem) {
  32315. return subItem.replace === (item.key || item);
  32316. }) || extensionControls.find(function (subItem) {
  32317. return subItem.replace === (item.key || item);
  32318. }) || item;
  32319. }).concat(extensionControls.length ? 'separator' : '').concat(extensionControls.filter(function (item) {
  32320. return !item.replace;
  32321. })).concat(extendControls.filter(function (item) {
  32322. return typeof item === 'string' || !item.replace;
  32323. }));
  32324. };
  32325. var ControlBar_ControlBar =
  32326. /*#__PURE__*/
  32327. function (_React$Component) {
  32328. inherits_default()(ControlBar, _React$Component);
  32329. function ControlBar() {
  32330. var _getPrototypeOf2;
  32331. var _this;
  32332. classCallCheck_default()(this, ControlBar);
  32333. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  32334. args[_key] = arguments[_key];
  32335. }
  32336. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(ControlBar)).call.apply(_getPrototypeOf2, [this].concat(args)));
  32337. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "allControls", []);
  32338. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "mediaLibiraryModal", null);
  32339. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "extendedModals", {});
  32340. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "openBraftFinder", function () {
  32341. if (!_this.props.braftFinder || !_this.props.braftFinder.ReactComponent) {
  32342. return false;
  32343. }
  32344. if (_this.props.hooks('open-braft-finder')() === false) {
  32345. return false;
  32346. }
  32347. var mediaProps = _this.props.media;
  32348. var MediaLibrary = _this.props.braftFinder.ReactComponent;
  32349. _this.mediaLibiraryModal = Modal_showModal({
  32350. title: _this.props.language.controls.mediaLibirary,
  32351. language: _this.props.language,
  32352. width: 640,
  32353. showFooter: false,
  32354. component: external_react_default.a.createElement(MediaLibrary, {
  32355. accepts: mediaProps.accepts,
  32356. onCancel: _this.closeBraftFinder,
  32357. onInsert: _this.insertMedias,
  32358. onChange: mediaProps.onChange,
  32359. externals: mediaProps.externals,
  32360. onBeforeSelect: _this.bindBraftFinderHook('select-medias'),
  32361. onBeforeDeselect: _this.bindBraftFinderHook('deselect-medias'),
  32362. onBeforeRemove: _this.bindBraftFinderHook('remove-medias'),
  32363. onBeforeInsert: _this.bindBraftFinderHook('insert-medias'),
  32364. onFileSelect: _this.bindBraftFinderHook('select-files')
  32365. })
  32366. });
  32367. });
  32368. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "bindBraftFinderHook", function (hookName) {
  32369. return function () {
  32370. return _this.props.hooks(hookName, arguments.length <= 0 ? undefined : arguments[0]).apply(void 0, arguments);
  32371. };
  32372. });
  32373. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "insertMedias", function (medias) {
  32374. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].insertMedias(_this.props.editorState, medias));
  32375. _this.props.editor.requestFocus();
  32376. _this.props.media.onInsert && _this.props.media.onInsert(medias);
  32377. _this.closeBraftFinder();
  32378. });
  32379. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "closeBraftFinder", function () {
  32380. _this.props.media.onCancel && _this.props.media.onCancel();
  32381. _this.mediaLibiraryModal && _this.mediaLibiraryModal.close();
  32382. });
  32383. return _this;
  32384. }
  32385. createClass_default()(ControlBar, [{
  32386. key: "componentDidUpdate",
  32387. value: function componentDidUpdate() {
  32388. var _this2 = this;
  32389. var language = this.props.language;
  32390. this.allControls.forEach(function (item) {
  32391. if (item.type === 'modal') {
  32392. if (item.modal && item.modal.id && _this2.extendedModals[item.modal.id]) {
  32393. _this2.extendedModals[item.modal.id].update(objectSpread_default()({}, item.modal, {
  32394. language: language
  32395. }));
  32396. }
  32397. }
  32398. });
  32399. }
  32400. }, {
  32401. key: "getControlItemClassName",
  32402. value: function getControlItemClassName(data) {
  32403. var className = 'control-item button';
  32404. var type = data.type,
  32405. command = data.command;
  32406. if (type === 'inline-style' && external_braft_utils_["ContentUtils"].selectionHasInlineStyle(this.props.editorState, command)) {
  32407. className += ' active';
  32408. } else if (type === 'block-type' && external_braft_utils_["ContentUtils"].getSelectionBlockType(this.props.editorState) === command) {
  32409. className += ' active';
  32410. } else if (type === 'entity' && external_braft_utils_["ContentUtils"].getSelectionEntityType(this.props.editorState) === command) {
  32411. className += ' active';
  32412. }
  32413. return className;
  32414. }
  32415. }, {
  32416. key: "applyControl",
  32417. value: function applyControl(command, type) {
  32418. var data = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  32419. var hookReturns = this.props.hooks(commandHookMap[type] || type, command)(command);
  32420. var editorState = this.props.editorState;
  32421. if (hookReturns === false) {
  32422. return false;
  32423. }
  32424. if (typeof hookReturns === 'string') {
  32425. command = hookReturns;
  32426. }
  32427. if (type === 'inline-style') {
  32428. var exclusiveInlineStyle = exclusiveInlineStyles[command];
  32429. if (exclusiveInlineStyle && external_braft_utils_["ContentUtils"].selectionHasInlineStyle(editorState, exclusiveInlineStyle)) {
  32430. editorState = external_braft_utils_["ContentUtils"].toggleSelectionInlineStyle(editorState, exclusiveInlineStyle);
  32431. }
  32432. this.props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionInlineStyle(editorState, command));
  32433. } else if (type === 'block-type') {
  32434. this.props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionBlockType(editorState, command));
  32435. } else if (type === 'entity') {
  32436. this.props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionEntity(editorState, {
  32437. type: command,
  32438. mutability: data.mutability || 'MUTABLE',
  32439. data: data.data || {}
  32440. }));
  32441. } else if (type === 'editor-method') {
  32442. this.props.editor[command] && this.props.editor[command]();
  32443. }
  32444. }
  32445. }, {
  32446. key: "render",
  32447. value: function render() {
  32448. var _this3 = this;
  32449. var _this$props = this.props,
  32450. editor = _this$props.editor,
  32451. editorId = _this$props.editorId,
  32452. editorState = _this$props.editorState,
  32453. className = _this$props.className,
  32454. style = _this$props.style,
  32455. controls = _this$props.controls,
  32456. media = _this$props.media,
  32457. extendControls = _this$props.extendControls,
  32458. language = _this$props.language,
  32459. hooks = _this$props.hooks,
  32460. colors = _this$props.colors,
  32461. colorPicker = _this$props.colorPicker,
  32462. colorPickerTheme = _this$props.colorPickerTheme,
  32463. colorPickerAutoHide = _this$props.colorPickerAutoHide,
  32464. headings = _this$props.headings,
  32465. fontSizes = _this$props.fontSizes,
  32466. fontFamilies = _this$props.fontFamilies,
  32467. emojis = _this$props.emojis,
  32468. getContainerNode = _this$props.getContainerNode,
  32469. lineHeights = _this$props.lineHeights,
  32470. letterSpacings = _this$props.letterSpacings,
  32471. textAligns = _this$props.textAligns,
  32472. textBackgroundColor = _this$props.textBackgroundColor,
  32473. allowInsertLinkText = _this$props.allowInsertLinkText,
  32474. defaultLinkTarget = _this$props.defaultLinkTarget;
  32475. var currentBlockType = external_braft_utils_["ContentUtils"].getSelectionBlockType(editorState);
  32476. var commonProps = {
  32477. editor: editor,
  32478. editorId: editorId,
  32479. editorState: editorState,
  32480. language: language,
  32481. getContainerNode: getContainerNode,
  32482. hooks: hooks
  32483. };
  32484. var renderedControls = [];
  32485. var editorControls = configs_controls(language, editor);
  32486. var extensionControls = getExtensionControls(editorId);
  32487. var allControls = mergeControls(commonProps, controls, extensionControls, extendControls);
  32488. this.allControls = allControls;
  32489. return external_react_default.a.createElement("div", {
  32490. className: "bf-controlbar ".concat(className || ''),
  32491. style: style,
  32492. onMouseDown: this.preventDefault
  32493. }, allControls.map(function (item, index) {
  32494. var itemKey = typeof item === 'string' ? item : item.key;
  32495. if (typeof itemKey !== 'string') {
  32496. return null;
  32497. }
  32498. if (renderedControls.indexOf(itemKey) > -1) {
  32499. return null;
  32500. }
  32501. if (itemKey.toLowerCase() === 'separator') {
  32502. return external_react_default.a.createElement("span", {
  32503. key: index,
  32504. className: "separator-line"
  32505. });
  32506. }
  32507. var controlItem = editorControls.find(function (subItem) {
  32508. return subItem.key.toLowerCase() === itemKey.toLowerCase();
  32509. });
  32510. if (typeof item !== 'string') {
  32511. controlItem = objectSpread_default()({}, controlItem, item);
  32512. }
  32513. if (!controlItem) {
  32514. return null;
  32515. }
  32516. renderedControls.push(itemKey);
  32517. if (controlItem.type === 'headings') {
  32518. return external_react_default.a.createElement(Headings, extends_default()({
  32519. key: index,
  32520. headings: headings,
  32521. current: currentBlockType,
  32522. onChange: function onChange(command) {
  32523. return _this3.applyControl(command, 'block-type');
  32524. }
  32525. }, commonProps));
  32526. } else if (controlItem.type === 'text-color') {
  32527. return external_react_default.a.createElement(TextColor_TextColor, extends_default()({
  32528. key: index,
  32529. colors: colors,
  32530. colorPicker: colorPicker,
  32531. theme: colorPickerTheme,
  32532. autoHide: colorPickerAutoHide,
  32533. enableBackgroundColor: textBackgroundColor
  32534. }, commonProps));
  32535. } else if (controlItem.type === 'font-size') {
  32536. return external_react_default.a.createElement(FontSize, extends_default()({
  32537. key: index,
  32538. fontSizes: fontSizes,
  32539. defaultCaption: controlItem.title
  32540. }, commonProps));
  32541. } else if (controlItem.type === 'line-height') {
  32542. return external_react_default.a.createElement(LineHeight, extends_default()({
  32543. key: index,
  32544. lineHeights: lineHeights,
  32545. defaultCaption: controlItem.title
  32546. }, commonProps));
  32547. } else if (controlItem.type === 'letter-spacing') {
  32548. return external_react_default.a.createElement(LetterSpacing, extends_default()({
  32549. key: index,
  32550. letterSpacings: letterSpacings,
  32551. defaultCaption: controlItem.title
  32552. }, commonProps));
  32553. } else if (controlItem.type === 'text-indent') {
  32554. return external_react_default.a.createElement(TextIndent_TextAlign, extends_default()({
  32555. key: index,
  32556. defaultCaption: controlItem.title
  32557. }, commonProps));
  32558. } else if (controlItem.type === 'font-family') {
  32559. return external_react_default.a.createElement(FontFamily, extends_default()({
  32560. key: index,
  32561. fontFamilies: fontFamilies,
  32562. defaultCaption: controlItem.title
  32563. }, commonProps));
  32564. } else if (controlItem.type === 'emoji') {
  32565. return external_react_default.a.createElement(EmojiPicker, extends_default()({
  32566. key: index,
  32567. emojis: emojis,
  32568. defaultCaption: controlItem.text
  32569. }, commonProps));
  32570. } else if (controlItem.type === 'link') {
  32571. return external_react_default.a.createElement(LinkEditor_LinkEditor, extends_default()({
  32572. key: index,
  32573. defaultLinkTarget: defaultLinkTarget,
  32574. allowInsertLinkText: allowInsertLinkText
  32575. }, commonProps));
  32576. } else if (controlItem.type === 'text-align') {
  32577. return external_react_default.a.createElement(TextAlign_TextAlign, extends_default()({
  32578. key: index,
  32579. textAligns: textAligns
  32580. }, commonProps));
  32581. } else if (controlItem.type === 'media') {
  32582. if (!media.image && !media.video && !media.audio) {
  32583. return null;
  32584. }
  32585. return external_react_default.a.createElement("button", {
  32586. type: "button",
  32587. key: index,
  32588. "data-title": controlItem.title,
  32589. disabled: controlItem.disabled,
  32590. className: "control-item media button",
  32591. onClick: _this3.openBraftFinder
  32592. }, controlItem.text);
  32593. } else if (controlItem.type === 'dropdown') {
  32594. return external_react_default.a.createElement(DropDown_DropDown, extends_default()({
  32595. key: index,
  32596. className: "control-item extend-control-item dropdown ".concat(controlItem.className || ''),
  32597. caption: controlItem.text,
  32598. htmlCaption: controlItem.html,
  32599. showArrow: controlItem.showArrow,
  32600. title: controlItem.title,
  32601. arrowActive: controlItem.arrowActive,
  32602. theme: controlItem.theme,
  32603. autoHide: controlItem.autoHide,
  32604. disabled: controlItem.disabled,
  32605. ref: controlItem.ref
  32606. }, commonProps), controlItem.component);
  32607. } else if (controlItem.type === 'modal') {
  32608. return external_react_default.a.createElement("button", {
  32609. type: "button",
  32610. key: index,
  32611. "data-title": controlItem.title,
  32612. disabled: controlItem.disabled,
  32613. className: "control-item extend-control-item button ".concat(controlItem.className || ''),
  32614. dangerouslySetInnerHTML: controlItem.html ? {
  32615. __html: controlItem.html
  32616. } : null,
  32617. onClick: function onClick(event) {
  32618. if (controlItem.modal && controlItem.modal.id) {
  32619. if (_this3.extendedModals[controlItem.modal.id]) {
  32620. _this3.extendedModals[controlItem.modal.id].active = true;
  32621. _this3.extendedModals[controlItem.modal.id].update(objectSpread_default()({}, controlItem.modal, {
  32622. language: language
  32623. }));
  32624. } else {
  32625. _this3.extendedModals[controlItem.modal.id] = Modal_showModal(objectSpread_default()({}, controlItem.modal, {
  32626. language: language
  32627. }));
  32628. controlItem.modal.onCreate && controlItem.modal.onCreate(_this3.extendedModals[controlItem.modal.id]);
  32629. }
  32630. }
  32631. controlItem.onClick && controlItem.onClick(event);
  32632. }
  32633. }, !controlItem.html ? controlItem.text : null);
  32634. } else if (controlItem.type === 'component') {
  32635. return external_react_default.a.createElement("div", {
  32636. key: index,
  32637. className: "component-wrapper ".concat(controlItem.className || '')
  32638. }, controlItem.component);
  32639. } else if (controlItem.type === 'button') {
  32640. return external_react_default.a.createElement("button", {
  32641. type: "button",
  32642. key: index,
  32643. "data-title": controlItem.title,
  32644. disabled: controlItem.disabled,
  32645. className: "control-item button ".concat(controlItem.className || ''),
  32646. dangerouslySetInnerHTML: controlItem.html ? {
  32647. __html: controlItem.html
  32648. } : null,
  32649. onClick: function onClick(event) {
  32650. return controlItem.onClick && controlItem.onClick(event);
  32651. }
  32652. }, !controlItem.html ? controlItem.text : null);
  32653. } else if (controlItem) {
  32654. var disabled = false;
  32655. if (controlItem.command === 'undo') {
  32656. disabled = editorState.getUndoStack().size === 0;
  32657. } else if (controlItem.command === 'redo') {
  32658. disabled = editorState.getRedoStack().size === 0;
  32659. }
  32660. return external_react_default.a.createElement("button", {
  32661. type: "button",
  32662. key: index,
  32663. disabled: disabled,
  32664. "data-title": controlItem.title,
  32665. className: _this3.getControlItemClassName({
  32666. type: controlItem.type,
  32667. command: controlItem.command
  32668. }),
  32669. onClick: function onClick() {
  32670. return _this3.applyControl(controlItem.command, controlItem.type, controlItem.data);
  32671. }
  32672. }, controlItem.text);
  32673. }
  32674. }));
  32675. }
  32676. }, {
  32677. key: "preventDefault",
  32678. value: function preventDefault(event) {
  32679. var tagName = event.target.tagName.toLowerCase();
  32680. if (tagName === 'input' || tagName === 'label') ; else {
  32681. event.preventDefault();
  32682. }
  32683. }
  32684. }]);
  32685. return ControlBar;
  32686. }(external_react_default.a.Component);
  32687. // CONCATENATED MODULE: ./editor/index.jsx
  32688. var buildHooks = function buildHooks(hooks) {
  32689. return function (hookName) {
  32690. var defaultReturns = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  32691. return hooks[hookName] || function () {
  32692. return defaultReturns;
  32693. };
  32694. };
  32695. };
  32696. var filterColors = function filterColors(colors, colors2) {
  32697. return colors.filter(function (item) {
  32698. return !colors2.find(function (color) {
  32699. return color.toLowerCase() === item.toLowerCase();
  32700. });
  32701. }).filter(function (item, index, array) {
  32702. return array.indexOf(item) === index;
  32703. });
  32704. };
  32705. var editor_isControlEnabled = function isControlEnabled(props, controlName) {
  32706. return toConsumableArray_default()(props.controls).concat(toConsumableArray_default()(props.extendControls)).find(function (item) {
  32707. return item === controlName || item.key === controlName;
  32708. }) && props.excludeControls.indexOf(controlName) === -1;
  32709. };
  32710. var editor_getConvertOptions = function getConvertOptions(props) {
  32711. var editorId = props.editorId || props.id;
  32712. var convertOptions = objectSpread_default()({}, configs_props.converts, props.converts, {
  32713. fontFamilies: props.fontFamilies
  32714. });
  32715. convertOptions.styleImportFn = compositeStyleImportFn(convertOptions.styleImportFn, editorId);
  32716. convertOptions.styleExportFn = compositeStyleExportFn(convertOptions.styleExportFn, editorId);
  32717. convertOptions.entityImportFn = compositeEntityImportFn(convertOptions.entityImportFn, editorId);
  32718. convertOptions.entityExportFn = compositeEntityExportFn(convertOptions.entityExportFn, editorId);
  32719. convertOptions.blockImportFn = compositeBlockImportFn(convertOptions.blockImportFn, editorId);
  32720. convertOptions.blockExportFn = compositeBlockExportFn(convertOptions.blockExportFn, editorId);
  32721. return convertOptions;
  32722. };
  32723. var editor_BraftEditor =
  32724. /*#__PURE__*/
  32725. function (_React$Component) {
  32726. inherits_default()(BraftEditor, _React$Component);
  32727. function BraftEditor(props) {
  32728. var _this;
  32729. classCallCheck_default()(this, BraftEditor);
  32730. _this = possibleConstructorReturn_default()(this, getPrototypeOf_default()(BraftEditor).call(this, props));
  32731. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "onChange", function (editorState, callback) {
  32732. if (!(editorState instanceof external_draft_js_["EditorState"])) {
  32733. editorState = external_draft_js_["EditorState"].set(editorState, {
  32734. decorator: _this.editorDecorators
  32735. });
  32736. }
  32737. if (!editorState.convertOptions) {
  32738. editorState.setConvertOptions(editor_getConvertOptions(_this.editorProps));
  32739. }
  32740. _this.setState({
  32741. editorState: editorState
  32742. }, function () {
  32743. _this.props.onChange && _this.props.onChange(editorState);
  32744. callback && callback(editorState);
  32745. });
  32746. });
  32747. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "getDraftInstance", function () {
  32748. return _this.draftInstance;
  32749. });
  32750. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "getFinderInstance", function () {
  32751. return _this.braftFinder;
  32752. });
  32753. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "getValue", function () {
  32754. return _this.state.editorState;
  32755. });
  32756. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "setValue", function (editorState, callback) {
  32757. return _this.onChange(editorState, callback);
  32758. });
  32759. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "forceRender", function () {
  32760. var selectionState = _this.state.editorState.getSelection();
  32761. _this.setValue(external_draft_js_["EditorState"].set(_this.state.editorState, {
  32762. decorator: _this.editorDecorators
  32763. }), function () {
  32764. _this.setValue(external_draft_js_["EditorState"].forceSelection(_this.state.editorState, selectionState));
  32765. });
  32766. });
  32767. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "onTab", function (event) {
  32768. if (handlers_keyCommandHandlers('tab', _this.state.editorState, assertThisInitialized_default()(assertThisInitialized_default()(_this))) === 'handled') {
  32769. event.preventDefault();
  32770. }
  32771. _this.editorProps.onTab && _this.editorProps.onTab(event);
  32772. });
  32773. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "onFocus", function () {
  32774. _this.isFocused = true;
  32775. _this.editorProps.onFocus && _this.editorProps.onFocus(_this.state.editorState);
  32776. });
  32777. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "onBlur", function () {
  32778. _this.isFocused = false;
  32779. _this.editorProps.onBlur && _this.editorProps.onBlur(_this.state.editorState);
  32780. });
  32781. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "requestFocus", function () {
  32782. setTimeout(function () {
  32783. return _this.draftInstance.focus();
  32784. }, 0);
  32785. });
  32786. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleKeyCommand", function (command, editorState) {
  32787. return handlers_keyCommandHandlers(command, editorState, assertThisInitialized_default()(assertThisInitialized_default()(_this)));
  32788. });
  32789. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleReturn", function (event, editorState) {
  32790. return handlers_returnHandlers(event, editorState, assertThisInitialized_default()(assertThisInitialized_default()(_this)));
  32791. });
  32792. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleBeforeInput", function (chars, editorState) {
  32793. return beforeInputHandlers(chars, editorState, assertThisInitialized_default()(assertThisInitialized_default()(_this)));
  32794. });
  32795. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleDrop", function (selectionState, dataTransfer) {
  32796. return handlers_dropHandlers(selectionState, dataTransfer, assertThisInitialized_default()(assertThisInitialized_default()(_this)));
  32797. });
  32798. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleDroppedFiles", function (selectionState, files) {
  32799. return droppedFilesHandlers(selectionState, files, assertThisInitialized_default()(assertThisInitialized_default()(_this)));
  32800. });
  32801. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handlePastedFiles", function (files) {
  32802. return pastedFilesHandlers(files, assertThisInitialized_default()(assertThisInitialized_default()(_this)));
  32803. });
  32804. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleCopyContent", function (event) {
  32805. return handlers_copyHandlers(event, assertThisInitialized_default()(assertThisInitialized_default()(_this)));
  32806. });
  32807. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handlePastedText", function (text, html, editorState) {
  32808. return handlers_pastedTextHandlers(text, html, editorState, assertThisInitialized_default()(assertThisInitialized_default()(_this)));
  32809. });
  32810. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleCompositionStart", function (event) {
  32811. return handlers_compositionStartHandler(event, assertThisInitialized_default()(assertThisInitialized_default()(_this)));
  32812. });
  32813. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "undo", function () {
  32814. _this.setValue(external_braft_utils_["ContentUtils"].undo(_this.state.editorState));
  32815. });
  32816. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "redo", function () {
  32817. _this.setValue(external_braft_utils_["ContentUtils"].redo(_this.state.editorState));
  32818. });
  32819. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "removeSelectionInlineStyles", function () {
  32820. _this.setValue(external_braft_utils_["ContentUtils"].removeSelectionInlineStyles(_this.state.editorState));
  32821. });
  32822. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "insertHorizontalLine", function () {
  32823. _this.setValue(external_braft_utils_["ContentUtils"].insertHorizontalLine(_this.state.editorState));
  32824. });
  32825. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "clearEditorContent", function () {
  32826. _this.setValue(external_braft_utils_["ContentUtils"].clear(_this.state.editorState), function (editorState) {
  32827. _this.setValue(external_braft_utils_["ContentUtils"].toggleSelectionIndent(editorState, 0));
  32828. });
  32829. });
  32830. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "toggleFullscreen", function (fullscreen) {
  32831. _this.setState({
  32832. isFullscreen: typeof fullscreen !== 'undefined' ? fullscreen : !_this.state.isFullscreen
  32833. }, function () {
  32834. _this.editorProps.onFullscreen && _this.editorProps.onFullscreen(_this.state.isFullscreen);
  32835. });
  32836. });
  32837. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "setEditorContainerNode", function (containerNode) {
  32838. _this.containerNode = containerNode;
  32839. });
  32840. _this.editorProps = _this.getEditorProps(props);
  32841. _this.editorDecorators = getDecorators(_this.editorProps.editorId || _this.editorProps.id);
  32842. _this.isFocused = false;
  32843. _this.isLiving = false;
  32844. _this.braftFinder = null;
  32845. _this.valueInitialized = !!(_this.props.defaultValue || _this.props.value);
  32846. 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);
  32847. defaultEditorState.setConvertOptions(editor_getConvertOptions(_this.editorProps));
  32848. var tempColors = [];
  32849. if (external_braft_utils_["ContentUtils"].isEditorState(defaultEditorState)) {
  32850. var colors = external_braft_utils_["ColorUtils"].detectColorsFromDraftState(defaultEditorState.toRAW(true));
  32851. defaultEditorState.setConvertOptions(editor_getConvertOptions(_this.editorProps));
  32852. tempColors = filterColors(colors, _this.editorProps.colors);
  32853. }
  32854. _this.state = {
  32855. tempColors: tempColors,
  32856. editorState: defaultEditorState,
  32857. isFullscreen: false,
  32858. draftProps: {}
  32859. };
  32860. _this.containerNode = null;
  32861. return _this;
  32862. }
  32863. createClass_default()(BraftEditor, [{
  32864. key: "getEditorProps",
  32865. value: function getEditorProps(props) {
  32866. var _this2 = this;
  32867. props = props || this.props;
  32868. var _props = props,
  32869. value = _props.value,
  32870. defaultValue = _props.defaultValue,
  32871. onChange = _props.onChange,
  32872. restProps = objectWithoutProperties_default()(_props, ["value", "defaultValue", "onChange"]); // eslint-disable-line no-unused-vars
  32873. var propInterceptors = getPropInterceptors(restProps.editorId || restProps.id);
  32874. if (propInterceptors.length === 0) {
  32875. return restProps;
  32876. }
  32877. var porpsMap = Object(external_immutable_["Map"])(restProps);
  32878. propInterceptors.forEach(function (interceptor) {
  32879. porpsMap = porpsMap.merge(Object(external_immutable_["Map"])(interceptor(porpsMap.toJS(), _this2) || {}));
  32880. });
  32881. return porpsMap.toJS();
  32882. }
  32883. }, {
  32884. key: "componentWillMount",
  32885. value: function componentWillMount() {
  32886. if (editor_isControlEnabled(this.editorProps, 'media')) {
  32887. var _this$editorProps = this.editorProps,
  32888. language = _this$editorProps.language,
  32889. media = _this$editorProps.media;
  32890. var _defaultProps$media$m = objectSpread_default()({}, configs_props.media, media),
  32891. uploadFn = _defaultProps$media$m.uploadFn,
  32892. validateFn = _defaultProps$media$m.validateFn,
  32893. items = _defaultProps$media$m.items;
  32894. this.braftFinder = new external_braft_finder_default.a({
  32895. items: items,
  32896. language: language,
  32897. uploader: uploadFn,
  32898. validator: validateFn
  32899. });
  32900. this.forceUpdate();
  32901. }
  32902. }
  32903. }, {
  32904. key: "componentDidMount",
  32905. value: function componentDidMount() {
  32906. this.isLiving = true;
  32907. }
  32908. }, {
  32909. key: "componentDidUpdate",
  32910. value: function componentDidUpdate(_, prevState) {
  32911. if (prevState.editorState !== this.state.editorState) {
  32912. this.state.editorState.setConvertOptions(editor_getConvertOptions(this.editorProps));
  32913. }
  32914. }
  32915. }, {
  32916. key: "componentWillReceiveProps",
  32917. value: function componentWillReceiveProps(props) {
  32918. var _this3 = this;
  32919. this.editorProps = this.getEditorProps(props);
  32920. var editorState = props.value;
  32921. var _this$editorProps2 = this.editorProps,
  32922. media = _this$editorProps2.media,
  32923. language = _this$editorProps2.language;
  32924. var currentProps = this.getEditorProps();
  32925. if (!editor_isControlEnabled(currentProps, 'media') && editor_isControlEnabled(this.editorProps, 'media') && !this.braftFinder) {
  32926. var _defaultProps$media$m2 = objectSpread_default()({}, configs_props.media, media),
  32927. uploadFn = _defaultProps$media$m2.uploadFn,
  32928. validateFn = _defaultProps$media$m2.validateFn,
  32929. items = _defaultProps$media$m2.items;
  32930. this.braftFinder = new external_braft_finder_default.a({
  32931. items: items,
  32932. language: language,
  32933. uploader: uploadFn,
  32934. validator: validateFn
  32935. });
  32936. this.forceUpdate();
  32937. }
  32938. if (media && media.items && this.braftFinder) {
  32939. this.braftFinder.setItems(media.items);
  32940. }
  32941. var nextEditorState;
  32942. if (!this.valueInitialized && typeof this.props.defaultValue === 'undefined' && external_braft_utils_["ContentUtils"].isEditorState(props.defaultValue)) {
  32943. nextEditorState = props.defaultValue;
  32944. } else if (external_braft_utils_["ContentUtils"].isEditorState(editorState)) {
  32945. nextEditorState = editorState;
  32946. }
  32947. if (nextEditorState) {
  32948. if (nextEditorState && nextEditorState !== this.state.editorState) {
  32949. var tempColors = external_braft_utils_["ColorUtils"].detectColorsFromDraftState(nextEditorState.toRAW(true));
  32950. nextEditorState.setConvertOptions(editor_getConvertOptions(this.editorProps));
  32951. this.setState({
  32952. tempColors: filterColors(toConsumableArray_default()(this.state.tempColors).concat(toConsumableArray_default()(tempColors)), currentProps.colors),
  32953. editorState: nextEditorState
  32954. }, function () {
  32955. _this3.props.onChange && _this3.props.onChange(nextEditorState);
  32956. });
  32957. } else {
  32958. this.setState({
  32959. editorState: nextEditorState
  32960. });
  32961. }
  32962. }
  32963. }
  32964. }, {
  32965. key: "componentWillUnmount",
  32966. value: function componentWillUnmount() {
  32967. this.isLiving = false;
  32968. this.controlBarInstance && this.controlBarInstance.closeBraftFinder();
  32969. }
  32970. }, {
  32971. key: "lockOrUnlockEditor",
  32972. value: function lockOrUnlockEditor(editorLocked) {
  32973. this.setState({
  32974. editorLocked: editorLocked
  32975. });
  32976. }
  32977. }, {
  32978. key: "render",
  32979. value: function render() {
  32980. var _this4 = this;
  32981. var _this$editorProps3 = this.editorProps,
  32982. id = _this$editorProps3.id,
  32983. editorId = _this$editorProps3.editorId,
  32984. controls = _this$editorProps3.controls,
  32985. excludeControls = _this$editorProps3.excludeControls,
  32986. extendControls = _this$editorProps3.extendControls,
  32987. readOnly = _this$editorProps3.readOnly,
  32988. disabled = _this$editorProps3.disabled,
  32989. media = _this$editorProps3.media,
  32990. language = _this$editorProps3.language,
  32991. colors = _this$editorProps3.colors,
  32992. colorPicker = _this$editorProps3.colorPicker,
  32993. colorPickerTheme = _this$editorProps3.colorPickerTheme,
  32994. colorPickerAutoHide = _this$editorProps3.colorPickerAutoHide,
  32995. hooks = _this$editorProps3.hooks,
  32996. fontSizes = _this$editorProps3.fontSizes,
  32997. fontFamilies = _this$editorProps3.fontFamilies,
  32998. emojis = _this$editorProps3.emojis,
  32999. placeholder = _this$editorProps3.placeholder,
  33000. fixPlaceholder = _this$editorProps3.fixPlaceholder,
  33001. headings = _this$editorProps3.headings,
  33002. imageControls = _this$editorProps3.imageControls,
  33003. imageResizable = _this$editorProps3.imageResizable,
  33004. lineHeights = _this$editorProps3.lineHeights,
  33005. letterSpacings = _this$editorProps3.letterSpacings,
  33006. textAligns = _this$editorProps3.textAligns,
  33007. textBackgroundColor = _this$editorProps3.textBackgroundColor,
  33008. allowInsertLinkText = _this$editorProps3.allowInsertLinkText,
  33009. defaultLinkTarget = _this$editorProps3.defaultLinkTarget,
  33010. extendAtomics = _this$editorProps3.extendAtomics,
  33011. className = _this$editorProps3.className,
  33012. style = _this$editorProps3.style,
  33013. controlBarClassName = _this$editorProps3.controlBarClassName,
  33014. controlBarStyle = _this$editorProps3.controlBarStyle,
  33015. contentClassName = _this$editorProps3.contentClassName,
  33016. contentStyle = _this$editorProps3.contentStyle,
  33017. stripPastedStyles = _this$editorProps3.stripPastedStyles,
  33018. componentBelowControlBar = _this$editorProps3.componentBelowControlBar;
  33019. var _this$state = this.state,
  33020. isFullscreen = _this$state.isFullscreen,
  33021. editorState = _this$state.editorState;
  33022. editorId = editorId || id;
  33023. hooks = buildHooks(hooks);
  33024. controls = controls.filter(function (item) {
  33025. return excludeControls.indexOf(item) === -1;
  33026. });
  33027. language = (typeof language === 'function' ? language(languages, 'braft-editor') : languages[language]) || languages[configs_props.language];
  33028. var externalMedias = media && media.externals ? objectSpread_default()({}, configs_props.media.externals, media.externals) : configs_props.media.externals;
  33029. var accepts = media && media.accepts ? objectSpread_default()({}, configs_props.media.accepts, media.accepts) : configs_props.media.accepts;
  33030. media = objectSpread_default()({}, configs_props.media, media, {
  33031. externalMedias: externalMedias,
  33032. accepts: accepts
  33033. });
  33034. if (!media.uploadFn) {
  33035. media.video = false;
  33036. media.audio = false;
  33037. }
  33038. var controlBarProps = {
  33039. editor: this,
  33040. editorState: editorState,
  33041. braftFinder: this.braftFinder,
  33042. ref: function ref(instance) {
  33043. return _this4.controlBarInstance = instance;
  33044. },
  33045. getContainerNode: function getContainerNode() {
  33046. return _this4.containerNode;
  33047. },
  33048. className: controlBarClassName,
  33049. style: controlBarStyle,
  33050. colors: toConsumableArray_default()(colors).concat(toConsumableArray_default()(this.state.tempColors)),
  33051. colorPicker: colorPicker,
  33052. colorPickerTheme: colorPickerTheme,
  33053. colorPickerAutoHide: colorPickerAutoHide,
  33054. hooks: hooks,
  33055. editorId: editorId,
  33056. media: media,
  33057. controls: controls,
  33058. language: language,
  33059. extendControls: extendControls,
  33060. headings: headings,
  33061. fontSizes: fontSizes,
  33062. fontFamilies: fontFamilies,
  33063. emojis: emojis,
  33064. lineHeights: lineHeights,
  33065. letterSpacings: letterSpacings,
  33066. textAligns: textAligns,
  33067. textBackgroundColor: textBackgroundColor,
  33068. allowInsertLinkText: allowInsertLinkText,
  33069. defaultLinkTarget: defaultLinkTarget
  33070. };
  33071. var unitExportFn = editorState.convertOptions.unitExportFn;
  33072. var commonProps = {
  33073. editor: this,
  33074. editorId: editorId,
  33075. hooks: hooks,
  33076. editorState: editorState,
  33077. containerNode: this.containerNode,
  33078. imageControls: imageControls,
  33079. imageResizable: imageResizable,
  33080. language: language,
  33081. extendAtomics: extendAtomics
  33082. };
  33083. var blockRendererFn = getBlockRendererFn(commonProps, this.editorProps.blockRendererFn);
  33084. var blockRenderMap = getBlockRenderMap(commonProps, this.editorProps.blockRenderMap);
  33085. var blockStyleFn = getBlockStyleFn(this.editorProps.blockStyleFn);
  33086. var customStyleMap = getCustomStyleMap(commonProps, this.editorProps.customStyleMap);
  33087. var customStyleFn = getCustomStyleFn(commonProps, {
  33088. fontFamilies: fontFamilies,
  33089. unitExportFn: unitExportFn,
  33090. customStyleFn: this.editorProps.customStyleFn
  33091. });
  33092. var keyBindingFn = keybindings(this.editorProps.keyBindingFn);
  33093. var mixedProps = {};
  33094. if (this.state.editorLocked || this.editorProps.disabled || this.editorProps.readOnly || this.editorProps.draftProps.readOnly) {
  33095. mixedProps.readOnly = true;
  33096. }
  33097. if (placeholder && fixPlaceholder && editorState.isEmpty() && editorState.getCurrentContent().getFirstBlock().getType() !== 'unstyled') {
  33098. placeholder = '';
  33099. }
  33100. var draftProps = objectSpread_default()({
  33101. ref: function ref(instance) {
  33102. _this4.draftInstance = instance;
  33103. },
  33104. editorState: editorState,
  33105. handleKeyCommand: this.handleKeyCommand,
  33106. handleReturn: this.handleReturn,
  33107. handleBeforeInput: this.handleBeforeInput,
  33108. handleDrop: this.handleDrop,
  33109. handleDroppedFiles: this.handleDroppedFiles,
  33110. handlePastedText: this.handlePastedText,
  33111. handlePastedFiles: this.handlePastedFiles,
  33112. onChange: this.onChange,
  33113. onTab: this.onTab,
  33114. onFocus: this.onFocus,
  33115. onBlur: this.onBlur,
  33116. blockRenderMap: blockRenderMap,
  33117. blockRendererFn: blockRendererFn,
  33118. blockStyleFn: blockStyleFn,
  33119. customStyleMap: customStyleMap,
  33120. customStyleFn: customStyleFn,
  33121. keyBindingFn: keyBindingFn,
  33122. placeholder: placeholder,
  33123. stripPastedStyles: stripPastedStyles
  33124. }, this.editorProps.draftProps, mixedProps);
  33125. return external_react_default.a.createElement("div", {
  33126. style: style,
  33127. ref: this.setEditorContainerNode,
  33128. className: "bf-container ".concat(className).concat(disabled ? ' disabled' : '').concat(readOnly ? ' read-only' : '').concat(isFullscreen ? ' fullscreen' : '')
  33129. }, external_react_default.a.createElement(ControlBar_ControlBar, controlBarProps), componentBelowControlBar, external_react_default.a.createElement("div", {
  33130. onCompositionStart: this.handleCompositionStart,
  33131. className: "bf-content ".concat(contentClassName),
  33132. onCopy: this.handleCopyContent,
  33133. style: contentStyle
  33134. }, external_react_default.a.createElement(external_draft_js_["Editor"], draftProps)));
  33135. }
  33136. }]);
  33137. return BraftEditor;
  33138. }(external_react_default.a.Component);
  33139. defineProperty_default()(editor_BraftEditor, "defaultProps", configs_props);
  33140. // EXTERNAL MODULE: external "braft-convert"
  33141. var external_braft_convert_ = __webpack_require__(14);
  33142. // CONCATENATED MODULE: ./index.jsx
  33143. /* concated harmony reexport EditorState */__webpack_require__.d(__webpack_exports__, "EditorState", function() { return external_draft_js_["EditorState"]; });
  33144. /* concated harmony reexport getDecorators */__webpack_require__.d(__webpack_exports__, "getDecorators", function() { return getDecorators; });
  33145. external_draft_js_["EditorState"].prototype.setConvertOptions = function () {
  33146. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  33147. this.convertOptions = options;
  33148. };
  33149. external_draft_js_["EditorState"].prototype.toHTML = function () {
  33150. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  33151. var convertOptions = this.convertOptions || {};
  33152. return Object(external_braft_convert_["convertEditorStateToHTML"])(this, objectSpread_default()({}, convertOptions, options));
  33153. };
  33154. external_draft_js_["EditorState"].prototype.toRAW = function (noStringify) {
  33155. return noStringify ? Object(external_braft_convert_["convertEditorStateToRaw"])(this) : JSON.stringify(Object(external_braft_convert_["convertEditorStateToRaw"])(this));
  33156. };
  33157. external_draft_js_["EditorState"].prototype.toText = function () {
  33158. return this.getCurrentContent().getPlainText();
  33159. };
  33160. external_draft_js_["EditorState"].prototype.isEmpty = function () {
  33161. return !this.getCurrentContent().hasText();
  33162. };
  33163. editor_BraftEditor.createEditorState = external_draft_js_["EditorState"].createFrom = function (content) {
  33164. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  33165. options.unitExportFn = options.unitExportFn || editor_BraftEditor.defaultProps.converts.unitExportFn;
  33166. options.styleImportFn = compositeStyleImportFn(options.styleImportFn, options.editorId);
  33167. options.entityImportFn = compositeEntityImportFn(options.entityImportFn, options.editorId);
  33168. options.blockImportFn = compositeBlockImportFn(options.blockImportFn, options.editorId);
  33169. var editorState = null;
  33170. if (content instanceof external_draft_js_["EditorState"]) {
  33171. editorState = content;
  33172. } else if (typeof_default()(content) === 'object' && content && content.blocks && content.entityMap) {
  33173. editorState = Object(external_braft_convert_["convertRawToEditorState"])(content, getDecorators(options.editorId));
  33174. } else if (typeof content === 'string') {
  33175. try {
  33176. if (/^(-)?\d+$/.test(content)) {
  33177. editorState = Object(external_braft_convert_["convertHTMLToEditorState"])(content, getDecorators(options.editorId), options, 'create');
  33178. } else {
  33179. editorState = external_draft_js_["EditorState"].createFrom(JSON.parse(content), options);
  33180. }
  33181. } catch (error) {
  33182. editorState = Object(external_braft_convert_["convertHTMLToEditorState"])(content, getDecorators(options.editorId), options, 'create');
  33183. }
  33184. } else if (typeof content === 'number') {
  33185. editorState = Object(external_braft_convert_["convertHTMLToEditorState"])(content.toLocaleString().replace(/,/g, ''), getDecorators(options.editorId), options, 'create');
  33186. } else {
  33187. editorState = external_draft_js_["EditorState"].createEmpty(getDecorators(options.editorId));
  33188. }
  33189. options.styleExportFn = compositeStyleExportFn(options.styleExportFn, options.editorId);
  33190. options.entityExportFn = compositeEntityExportFn(options.entityExportFn, options.editorId);
  33191. options.blockExportFn = compositeBlockExportFn(options.blockExportFn, options.editorId);
  33192. editorState.setConvertOptions(options);
  33193. return editorState;
  33194. };
  33195. /* harmony default export */ var index_0 = __webpack_exports__["default"] = (createExtensibleEditor(editor_BraftEditor));
  33196. // 2.1版本开发计划
  33197. // [ ]优化选中多行文字是插入链接报错的问题
  33198. // [ ]新增编辑器内图片删除hook
  33199. // 2.2版本开发计划
  33200. // [ ]表格功能
  33201. // [ ]美化UI,包括图标和界面风格
  33202. // 2.3版本开发计划
  33203. // [ ]初级md快捷输入支持
  33204. // [ ]图片裁切等简单的编辑功能
  33205. // [ ]允许自定义快捷键
  33206. /***/ }),
  33207. /* 40 */
  33208. /***/ (function(module, exports) {
  33209. // removed by extract-text-webpack-plugin
  33210. /***/ }),
  33211. /* 41 */,
  33212. /* 42 */
  33213. /***/ (function(module, exports) {
  33214. // removed by extract-text-webpack-plugin
  33215. /***/ }),
  33216. /* 43 */,
  33217. /* 44 */,
  33218. /* 45 */
  33219. /***/ (function(module, exports) {
  33220. // removed by extract-text-webpack-plugin
  33221. /***/ }),
  33222. /* 46 */
  33223. /***/ (function(module, exports) {
  33224. // removed by extract-text-webpack-plugin
  33225. /***/ }),
  33226. /* 47 */
  33227. /***/ (function(module, exports) {
  33228. // removed by extract-text-webpack-plugin
  33229. /***/ }),
  33230. /* 48 */
  33231. /***/ (function(module, exports) {
  33232. // removed by extract-text-webpack-plugin
  33233. /***/ }),
  33234. /* 49 */
  33235. /***/ (function(module, exports) {
  33236. // removed by extract-text-webpack-plugin
  33237. /***/ }),
  33238. /* 50 */
  33239. /***/ (function(module, exports) {
  33240. // removed by extract-text-webpack-plugin
  33241. /***/ }),
  33242. /* 51 */
  33243. /***/ (function(module, exports) {
  33244. // removed by extract-text-webpack-plugin
  33245. /***/ }),
  33246. /* 52 */
  33247. /***/ (function(module, exports) {
  33248. // removed by extract-text-webpack-plugin
  33249. /***/ }),
  33250. /* 53 */
  33251. /***/ (function(module, exports) {
  33252. // removed by extract-text-webpack-plugin
  33253. /***/ }),
  33254. /* 54 */
  33255. /***/ (function(module, exports) {
  33256. // removed by extract-text-webpack-plugin
  33257. /***/ }),
  33258. /* 55 */
  33259. /***/ (function(module, exports) {
  33260. // removed by extract-text-webpack-plugin
  33261. /***/ }),
  33262. /* 56 */
  33263. /***/ (function(module, exports) {
  33264. // removed by extract-text-webpack-plugin
  33265. /***/ }),
  33266. /* 57 */
  33267. /***/ (function(module, exports) {
  33268. // removed by extract-text-webpack-plugin
  33269. /***/ }),
  33270. /* 58 */
  33271. /***/ (function(module, exports) {
  33272. // removed by extract-text-webpack-plugin
  33273. /***/ }),
  33274. /* 59 */
  33275. /***/ (function(module, exports) {
  33276. // removed by extract-text-webpack-plugin
  33277. /***/ }),
  33278. /* 60 */
  33279. /***/ (function(module, exports) {
  33280. // removed by extract-text-webpack-plugin
  33281. /***/ }),
  33282. /* 61 */
  33283. /***/ (function(module, exports) {
  33284. // removed by extract-text-webpack-plugin
  33285. /***/ }),
  33286. /* 62 */
  33287. /***/ (function(module, exports) {
  33288. // removed by extract-text-webpack-plugin
  33289. /***/ }),
  33290. /* 63 */
  33291. /***/ (function(module, exports) {
  33292. // removed by extract-text-webpack-plugin
  33293. /***/ })
  33294. /******/ ]);
  33295. });
  33296. });
  33297. var BraftEditor = unwrapExports(dist$3);
  33298. 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)}";
  33299. styleInject(css);
  33300. 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}";
  33301. styleInject(css$1);
  33302. var immutable$3 = createCommonjsModule(function (module, exports) {
  33303. /**
  33304. * Copyright (c) 2014-present, Facebook, Inc.
  33305. *
  33306. * This source code is licensed under the MIT license found in the
  33307. * LICENSE file in the root directory of this source tree.
  33308. */
  33309. (function (global, factory) {
  33310. factory(exports) ;
  33311. }(commonjsGlobal, (function (exports) {
  33312. // Used for setting prototype methods that IE8 chokes on.
  33313. var DELETE = 'delete';
  33314. // Constants describing the size of trie nodes.
  33315. var SHIFT = 5; // Resulted in best performance after ______?
  33316. var SIZE = 1 << SHIFT;
  33317. var MASK = SIZE - 1;
  33318. // A consistent shared value representing "not set" which equals nothing other
  33319. // than itself, and nothing that could be provided externally.
  33320. var NOT_SET = {};
  33321. // Boolean references, Rough equivalent of `bool &`.
  33322. function MakeRef() {
  33323. return { value: false };
  33324. }
  33325. function SetRef(ref) {
  33326. if (ref) {
  33327. ref.value = true;
  33328. }
  33329. }
  33330. // A function which returns a value representing an "owner" for transient writes
  33331. // to tries. The return value will only ever equal itself, and will not equal
  33332. // the return of any subsequent call of this function.
  33333. function OwnerID() {}
  33334. function ensureSize(iter) {
  33335. if (iter.size === undefined) {
  33336. iter.size = iter.__iterate(returnTrue);
  33337. }
  33338. return iter.size;
  33339. }
  33340. function wrapIndex(iter, index) {
  33341. // This implements "is array index" which the ECMAString spec defines as:
  33342. //
  33343. // A String property name P is an array index if and only if
  33344. // ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal
  33345. // to 2^32−1.
  33346. //
  33347. // http://www.ecma-international.org/ecma-262/6.0/#sec-array-exotic-objects
  33348. if (typeof index !== 'number') {
  33349. var uint32Index = index >>> 0; // N >>> 0 is shorthand for ToUint32
  33350. if ('' + uint32Index !== index || uint32Index === 4294967295) {
  33351. return NaN;
  33352. }
  33353. index = uint32Index;
  33354. }
  33355. return index < 0 ? ensureSize(iter) + index : index;
  33356. }
  33357. function returnTrue() {
  33358. return true;
  33359. }
  33360. function wholeSlice(begin, end, size) {
  33361. return (
  33362. ((begin === 0 && !isNeg(begin)) ||
  33363. (size !== undefined && begin <= -size)) &&
  33364. (end === undefined || (size !== undefined && end >= size))
  33365. );
  33366. }
  33367. function resolveBegin(begin, size) {
  33368. return resolveIndex(begin, size, 0);
  33369. }
  33370. function resolveEnd(end, size) {
  33371. return resolveIndex(end, size, size);
  33372. }
  33373. function resolveIndex(index, size, defaultIndex) {
  33374. // Sanitize indices using this shorthand for ToInt32(argument)
  33375. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  33376. return index === undefined
  33377. ? defaultIndex
  33378. : isNeg(index)
  33379. ? size === Infinity
  33380. ? size
  33381. : Math.max(0, size + index) | 0
  33382. : size === undefined || size === index
  33383. ? index
  33384. : Math.min(size, index) | 0;
  33385. }
  33386. function isNeg(value) {
  33387. // Account for -0 which is negative, but not less than 0.
  33388. return value < 0 || (value === 0 && 1 / value === -Infinity);
  33389. }
  33390. // Note: value is unchanged to not break immutable-devtools.
  33391. var IS_COLLECTION_SYMBOL = '@@__IMMUTABLE_ITERABLE__@@';
  33392. function isCollection(maybeCollection) {
  33393. return Boolean(maybeCollection && maybeCollection[IS_COLLECTION_SYMBOL]);
  33394. }
  33395. var IS_KEYED_SYMBOL = '@@__IMMUTABLE_KEYED__@@';
  33396. function isKeyed(maybeKeyed) {
  33397. return Boolean(maybeKeyed && maybeKeyed[IS_KEYED_SYMBOL]);
  33398. }
  33399. var IS_INDEXED_SYMBOL = '@@__IMMUTABLE_INDEXED__@@';
  33400. function isIndexed(maybeIndexed) {
  33401. return Boolean(maybeIndexed && maybeIndexed[IS_INDEXED_SYMBOL]);
  33402. }
  33403. function isAssociative(maybeAssociative) {
  33404. return isKeyed(maybeAssociative) || isIndexed(maybeAssociative);
  33405. }
  33406. var Collection = function Collection(value) {
  33407. return isCollection(value) ? value : Seq(value);
  33408. };
  33409. var KeyedCollection = /*@__PURE__*/(function (Collection) {
  33410. function KeyedCollection(value) {
  33411. return isKeyed(value) ? value : KeyedSeq(value);
  33412. }
  33413. if ( Collection ) KeyedCollection.__proto__ = Collection;
  33414. KeyedCollection.prototype = Object.create( Collection && Collection.prototype );
  33415. KeyedCollection.prototype.constructor = KeyedCollection;
  33416. return KeyedCollection;
  33417. }(Collection));
  33418. var IndexedCollection = /*@__PURE__*/(function (Collection) {
  33419. function IndexedCollection(value) {
  33420. return isIndexed(value) ? value : IndexedSeq(value);
  33421. }
  33422. if ( Collection ) IndexedCollection.__proto__ = Collection;
  33423. IndexedCollection.prototype = Object.create( Collection && Collection.prototype );
  33424. IndexedCollection.prototype.constructor = IndexedCollection;
  33425. return IndexedCollection;
  33426. }(Collection));
  33427. var SetCollection = /*@__PURE__*/(function (Collection) {
  33428. function SetCollection(value) {
  33429. return isCollection(value) && !isAssociative(value) ? value : SetSeq(value);
  33430. }
  33431. if ( Collection ) SetCollection.__proto__ = Collection;
  33432. SetCollection.prototype = Object.create( Collection && Collection.prototype );
  33433. SetCollection.prototype.constructor = SetCollection;
  33434. return SetCollection;
  33435. }(Collection));
  33436. Collection.Keyed = KeyedCollection;
  33437. Collection.Indexed = IndexedCollection;
  33438. Collection.Set = SetCollection;
  33439. var IS_SEQ_SYMBOL = '@@__IMMUTABLE_SEQ__@@';
  33440. function isSeq(maybeSeq) {
  33441. return Boolean(maybeSeq && maybeSeq[IS_SEQ_SYMBOL]);
  33442. }
  33443. var IS_RECORD_SYMBOL = '@@__IMMUTABLE_RECORD__@@';
  33444. function isRecord(maybeRecord) {
  33445. return Boolean(maybeRecord && maybeRecord[IS_RECORD_SYMBOL]);
  33446. }
  33447. function isImmutable(maybeImmutable) {
  33448. return isCollection(maybeImmutable) || isRecord(maybeImmutable);
  33449. }
  33450. var IS_ORDERED_SYMBOL = '@@__IMMUTABLE_ORDERED__@@';
  33451. function isOrdered(maybeOrdered) {
  33452. return Boolean(maybeOrdered && maybeOrdered[IS_ORDERED_SYMBOL]);
  33453. }
  33454. var ITERATE_KEYS = 0;
  33455. var ITERATE_VALUES = 1;
  33456. var ITERATE_ENTRIES = 2;
  33457. var REAL_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
  33458. var FAUX_ITERATOR_SYMBOL = '@@iterator';
  33459. var ITERATOR_SYMBOL = REAL_ITERATOR_SYMBOL || FAUX_ITERATOR_SYMBOL;
  33460. var Iterator = function Iterator(next) {
  33461. this.next = next;
  33462. };
  33463. Iterator.prototype.toString = function toString () {
  33464. return '[Iterator]';
  33465. };
  33466. Iterator.KEYS = ITERATE_KEYS;
  33467. Iterator.VALUES = ITERATE_VALUES;
  33468. Iterator.ENTRIES = ITERATE_ENTRIES;
  33469. Iterator.prototype.inspect = Iterator.prototype.toSource = function() {
  33470. return this.toString();
  33471. };
  33472. Iterator.prototype[ITERATOR_SYMBOL] = function() {
  33473. return this;
  33474. };
  33475. function iteratorValue(type, k, v, iteratorResult) {
  33476. var value = type === 0 ? k : type === 1 ? v : [k, v];
  33477. iteratorResult
  33478. ? (iteratorResult.value = value)
  33479. : (iteratorResult = {
  33480. value: value,
  33481. done: false,
  33482. });
  33483. return iteratorResult;
  33484. }
  33485. function iteratorDone() {
  33486. return { value: undefined, done: true };
  33487. }
  33488. function hasIterator(maybeIterable) {
  33489. return !!getIteratorFn(maybeIterable);
  33490. }
  33491. function isIterator(maybeIterator) {
  33492. return maybeIterator && typeof maybeIterator.next === 'function';
  33493. }
  33494. function getIterator(iterable) {
  33495. var iteratorFn = getIteratorFn(iterable);
  33496. return iteratorFn && iteratorFn.call(iterable);
  33497. }
  33498. function getIteratorFn(iterable) {
  33499. var iteratorFn =
  33500. iterable &&
  33501. ((REAL_ITERATOR_SYMBOL && iterable[REAL_ITERATOR_SYMBOL]) ||
  33502. iterable[FAUX_ITERATOR_SYMBOL]);
  33503. if (typeof iteratorFn === 'function') {
  33504. return iteratorFn;
  33505. }
  33506. }
  33507. var hasOwnProperty = Object.prototype.hasOwnProperty;
  33508. function isArrayLike(value) {
  33509. if (Array.isArray(value) || typeof value === 'string') {
  33510. return true;
  33511. }
  33512. return (
  33513. value &&
  33514. typeof value === 'object' &&
  33515. Number.isInteger(value.length) &&
  33516. value.length >= 0 &&
  33517. (value.length === 0
  33518. ? // Only {length: 0} is considered Array-like.
  33519. Object.keys(value).length === 1
  33520. : // An object is only Array-like if it has a property where the last value
  33521. // in the array-like may be found (which could be undefined).
  33522. value.hasOwnProperty(value.length - 1))
  33523. );
  33524. }
  33525. var Seq = /*@__PURE__*/(function (Collection$$1) {
  33526. function Seq(value) {
  33527. return value === null || value === undefined
  33528. ? emptySequence()
  33529. : isImmutable(value)
  33530. ? value.toSeq()
  33531. : seqFromValue(value);
  33532. }
  33533. if ( Collection$$1 ) Seq.__proto__ = Collection$$1;
  33534. Seq.prototype = Object.create( Collection$$1 && Collection$$1.prototype );
  33535. Seq.prototype.constructor = Seq;
  33536. Seq.prototype.toSeq = function toSeq () {
  33537. return this;
  33538. };
  33539. Seq.prototype.toString = function toString () {
  33540. return this.__toString('Seq {', '}');
  33541. };
  33542. Seq.prototype.cacheResult = function cacheResult () {
  33543. if (!this._cache && this.__iterateUncached) {
  33544. this._cache = this.entrySeq().toArray();
  33545. this.size = this._cache.length;
  33546. }
  33547. return this;
  33548. };
  33549. // abstract __iterateUncached(fn, reverse)
  33550. Seq.prototype.__iterate = function __iterate (fn, reverse) {
  33551. var cache = this._cache;
  33552. if (cache) {
  33553. var size = cache.length;
  33554. var i = 0;
  33555. while (i !== size) {
  33556. var entry = cache[reverse ? size - ++i : i++];
  33557. if (fn(entry[1], entry[0], this) === false) {
  33558. break;
  33559. }
  33560. }
  33561. return i;
  33562. }
  33563. return this.__iterateUncached(fn, reverse);
  33564. };
  33565. // abstract __iteratorUncached(type, reverse)
  33566. Seq.prototype.__iterator = function __iterator (type, reverse) {
  33567. var cache = this._cache;
  33568. if (cache) {
  33569. var size = cache.length;
  33570. var i = 0;
  33571. return new Iterator(function () {
  33572. if (i === size) {
  33573. return iteratorDone();
  33574. }
  33575. var entry = cache[reverse ? size - ++i : i++];
  33576. return iteratorValue(type, entry[0], entry[1]);
  33577. });
  33578. }
  33579. return this.__iteratorUncached(type, reverse);
  33580. };
  33581. return Seq;
  33582. }(Collection));
  33583. var KeyedSeq = /*@__PURE__*/(function (Seq) {
  33584. function KeyedSeq(value) {
  33585. return value === null || value === undefined
  33586. ? emptySequence().toKeyedSeq()
  33587. : isCollection(value)
  33588. ? isKeyed(value)
  33589. ? value.toSeq()
  33590. : value.fromEntrySeq()
  33591. : isRecord(value)
  33592. ? value.toSeq()
  33593. : keyedSeqFromValue(value);
  33594. }
  33595. if ( Seq ) KeyedSeq.__proto__ = Seq;
  33596. KeyedSeq.prototype = Object.create( Seq && Seq.prototype );
  33597. KeyedSeq.prototype.constructor = KeyedSeq;
  33598. KeyedSeq.prototype.toKeyedSeq = function toKeyedSeq () {
  33599. return this;
  33600. };
  33601. return KeyedSeq;
  33602. }(Seq));
  33603. var IndexedSeq = /*@__PURE__*/(function (Seq) {
  33604. function IndexedSeq(value) {
  33605. return value === null || value === undefined
  33606. ? emptySequence()
  33607. : isCollection(value)
  33608. ? isKeyed(value)
  33609. ? value.entrySeq()
  33610. : value.toIndexedSeq()
  33611. : isRecord(value)
  33612. ? value.toSeq().entrySeq()
  33613. : indexedSeqFromValue(value);
  33614. }
  33615. if ( Seq ) IndexedSeq.__proto__ = Seq;
  33616. IndexedSeq.prototype = Object.create( Seq && Seq.prototype );
  33617. IndexedSeq.prototype.constructor = IndexedSeq;
  33618. IndexedSeq.of = function of (/*...values*/) {
  33619. return IndexedSeq(arguments);
  33620. };
  33621. IndexedSeq.prototype.toIndexedSeq = function toIndexedSeq () {
  33622. return this;
  33623. };
  33624. IndexedSeq.prototype.toString = function toString () {
  33625. return this.__toString('Seq [', ']');
  33626. };
  33627. return IndexedSeq;
  33628. }(Seq));
  33629. var SetSeq = /*@__PURE__*/(function (Seq) {
  33630. function SetSeq(value) {
  33631. return (isCollection(value) && !isAssociative(value)
  33632. ? value
  33633. : IndexedSeq(value)
  33634. ).toSetSeq();
  33635. }
  33636. if ( Seq ) SetSeq.__proto__ = Seq;
  33637. SetSeq.prototype = Object.create( Seq && Seq.prototype );
  33638. SetSeq.prototype.constructor = SetSeq;
  33639. SetSeq.of = function of (/*...values*/) {
  33640. return SetSeq(arguments);
  33641. };
  33642. SetSeq.prototype.toSetSeq = function toSetSeq () {
  33643. return this;
  33644. };
  33645. return SetSeq;
  33646. }(Seq));
  33647. Seq.isSeq = isSeq;
  33648. Seq.Keyed = KeyedSeq;
  33649. Seq.Set = SetSeq;
  33650. Seq.Indexed = IndexedSeq;
  33651. Seq.prototype[IS_SEQ_SYMBOL] = true;
  33652. // #pragma Root Sequences
  33653. var ArraySeq = /*@__PURE__*/(function (IndexedSeq) {
  33654. function ArraySeq(array) {
  33655. this._array = array;
  33656. this.size = array.length;
  33657. }
  33658. if ( IndexedSeq ) ArraySeq.__proto__ = IndexedSeq;
  33659. ArraySeq.prototype = Object.create( IndexedSeq && IndexedSeq.prototype );
  33660. ArraySeq.prototype.constructor = ArraySeq;
  33661. ArraySeq.prototype.get = function get (index, notSetValue) {
  33662. return this.has(index) ? this._array[wrapIndex(this, index)] : notSetValue;
  33663. };
  33664. ArraySeq.prototype.__iterate = function __iterate (fn, reverse) {
  33665. var array = this._array;
  33666. var size = array.length;
  33667. var i = 0;
  33668. while (i !== size) {
  33669. var ii = reverse ? size - ++i : i++;
  33670. if (fn(array[ii], ii, this) === false) {
  33671. break;
  33672. }
  33673. }
  33674. return i;
  33675. };
  33676. ArraySeq.prototype.__iterator = function __iterator (type, reverse) {
  33677. var array = this._array;
  33678. var size = array.length;
  33679. var i = 0;
  33680. return new Iterator(function () {
  33681. if (i === size) {
  33682. return iteratorDone();
  33683. }
  33684. var ii = reverse ? size - ++i : i++;
  33685. return iteratorValue(type, ii, array[ii]);
  33686. });
  33687. };
  33688. return ArraySeq;
  33689. }(IndexedSeq));
  33690. var ObjectSeq = /*@__PURE__*/(function (KeyedSeq) {
  33691. function ObjectSeq(object) {
  33692. var keys = Object.keys(object);
  33693. this._object = object;
  33694. this._keys = keys;
  33695. this.size = keys.length;
  33696. }
  33697. if ( KeyedSeq ) ObjectSeq.__proto__ = KeyedSeq;
  33698. ObjectSeq.prototype = Object.create( KeyedSeq && KeyedSeq.prototype );
  33699. ObjectSeq.prototype.constructor = ObjectSeq;
  33700. ObjectSeq.prototype.get = function get (key, notSetValue) {
  33701. if (notSetValue !== undefined && !this.has(key)) {
  33702. return notSetValue;
  33703. }
  33704. return this._object[key];
  33705. };
  33706. ObjectSeq.prototype.has = function has (key) {
  33707. return hasOwnProperty.call(this._object, key);
  33708. };
  33709. ObjectSeq.prototype.__iterate = function __iterate (fn, reverse) {
  33710. var object = this._object;
  33711. var keys = this._keys;
  33712. var size = keys.length;
  33713. var i = 0;
  33714. while (i !== size) {
  33715. var key = keys[reverse ? size - ++i : i++];
  33716. if (fn(object[key], key, this) === false) {
  33717. break;
  33718. }
  33719. }
  33720. return i;
  33721. };
  33722. ObjectSeq.prototype.__iterator = function __iterator (type, reverse) {
  33723. var object = this._object;
  33724. var keys = this._keys;
  33725. var size = keys.length;
  33726. var i = 0;
  33727. return new Iterator(function () {
  33728. if (i === size) {
  33729. return iteratorDone();
  33730. }
  33731. var key = keys[reverse ? size - ++i : i++];
  33732. return iteratorValue(type, key, object[key]);
  33733. });
  33734. };
  33735. return ObjectSeq;
  33736. }(KeyedSeq));
  33737. ObjectSeq.prototype[IS_ORDERED_SYMBOL] = true;
  33738. var CollectionSeq = /*@__PURE__*/(function (IndexedSeq) {
  33739. function CollectionSeq(collection) {
  33740. this._collection = collection;
  33741. this.size = collection.length || collection.size;
  33742. }
  33743. if ( IndexedSeq ) CollectionSeq.__proto__ = IndexedSeq;
  33744. CollectionSeq.prototype = Object.create( IndexedSeq && IndexedSeq.prototype );
  33745. CollectionSeq.prototype.constructor = CollectionSeq;
  33746. CollectionSeq.prototype.__iterateUncached = function __iterateUncached (fn, reverse) {
  33747. if (reverse) {
  33748. return this.cacheResult().__iterate(fn, reverse);
  33749. }
  33750. var collection = this._collection;
  33751. var iterator = getIterator(collection);
  33752. var iterations = 0;
  33753. if (isIterator(iterator)) {
  33754. var step;
  33755. while (!(step = iterator.next()).done) {
  33756. if (fn(step.value, iterations++, this) === false) {
  33757. break;
  33758. }
  33759. }
  33760. }
  33761. return iterations;
  33762. };
  33763. CollectionSeq.prototype.__iteratorUncached = function __iteratorUncached (type, reverse) {
  33764. if (reverse) {
  33765. return this.cacheResult().__iterator(type, reverse);
  33766. }
  33767. var collection = this._collection;
  33768. var iterator = getIterator(collection);
  33769. if (!isIterator(iterator)) {
  33770. return new Iterator(iteratorDone);
  33771. }
  33772. var iterations = 0;
  33773. return new Iterator(function () {
  33774. var step = iterator.next();
  33775. return step.done ? step : iteratorValue(type, iterations++, step.value);
  33776. });
  33777. };
  33778. return CollectionSeq;
  33779. }(IndexedSeq));
  33780. // # pragma Helper functions
  33781. var EMPTY_SEQ;
  33782. function emptySequence() {
  33783. return EMPTY_SEQ || (EMPTY_SEQ = new ArraySeq([]));
  33784. }
  33785. function keyedSeqFromValue(value) {
  33786. var seq = Array.isArray(value)
  33787. ? new ArraySeq(value)
  33788. : hasIterator(value)
  33789. ? new CollectionSeq(value)
  33790. : undefined;
  33791. if (seq) {
  33792. return seq.fromEntrySeq();
  33793. }
  33794. if (typeof value === 'object') {
  33795. return new ObjectSeq(value);
  33796. }
  33797. throw new TypeError(
  33798. 'Expected Array or collection object of [k, v] entries, or keyed object: ' +
  33799. value
  33800. );
  33801. }
  33802. function indexedSeqFromValue(value) {
  33803. var seq = maybeIndexedSeqFromValue(value);
  33804. if (seq) {
  33805. return seq;
  33806. }
  33807. throw new TypeError(
  33808. 'Expected Array or collection object of values: ' + value
  33809. );
  33810. }
  33811. function seqFromValue(value) {
  33812. var seq = maybeIndexedSeqFromValue(value);
  33813. if (seq) {
  33814. return seq;
  33815. }
  33816. if (typeof value === 'object') {
  33817. return new ObjectSeq(value);
  33818. }
  33819. throw new TypeError(
  33820. 'Expected Array or collection object of values, or keyed object: ' + value
  33821. );
  33822. }
  33823. function maybeIndexedSeqFromValue(value) {
  33824. return isArrayLike(value)
  33825. ? new ArraySeq(value)
  33826. : hasIterator(value)
  33827. ? new CollectionSeq(value)
  33828. : undefined;
  33829. }
  33830. var IS_MAP_SYMBOL = '@@__IMMUTABLE_MAP__@@';
  33831. function isMap(maybeMap) {
  33832. return Boolean(maybeMap && maybeMap[IS_MAP_SYMBOL]);
  33833. }
  33834. function isOrderedMap(maybeOrderedMap) {
  33835. return isMap(maybeOrderedMap) && isOrdered(maybeOrderedMap);
  33836. }
  33837. function isValueObject(maybeValue) {
  33838. return Boolean(
  33839. maybeValue &&
  33840. typeof maybeValue.equals === 'function' &&
  33841. typeof maybeValue.hashCode === 'function'
  33842. );
  33843. }
  33844. /**
  33845. * An extension of the "same-value" algorithm as [described for use by ES6 Map
  33846. * and Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map#Key_equality)
  33847. *
  33848. * NaN is considered the same as NaN, however -0 and 0 are considered the same
  33849. * value, which is different from the algorithm described by
  33850. * [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is).
  33851. *
  33852. * This is extended further to allow Objects to describe the values they
  33853. * represent, by way of `valueOf` or `equals` (and `hashCode`).
  33854. *
  33855. * Note: because of this extension, the key equality of Immutable.Map and the
  33856. * value equality of Immutable.Set will differ from ES6 Map and Set.
  33857. *
  33858. * ### Defining custom values
  33859. *
  33860. * The easiest way to describe the value an object represents is by implementing
  33861. * `valueOf`. For example, `Date` represents a value by returning a unix
  33862. * timestamp for `valueOf`:
  33863. *
  33864. * var date1 = new Date(1234567890000); // Fri Feb 13 2009 ...
  33865. * var date2 = new Date(1234567890000);
  33866. * date1.valueOf(); // 1234567890000
  33867. * assert( date1 !== date2 );
  33868. * assert( Immutable.is( date1, date2 ) );
  33869. *
  33870. * Note: overriding `valueOf` may have other implications if you use this object
  33871. * where JavaScript expects a primitive, such as implicit string coercion.
  33872. *
  33873. * For more complex types, especially collections, implementing `valueOf` may
  33874. * not be performant. An alternative is to implement `equals` and `hashCode`.
  33875. *
  33876. * `equals` takes another object, presumably of similar type, and returns true
  33877. * if it is equal. Equality is symmetrical, so the same result should be
  33878. * returned if this and the argument are flipped.
  33879. *
  33880. * assert( a.equals(b) === b.equals(a) );
  33881. *
  33882. * `hashCode` returns a 32bit integer number representing the object which will
  33883. * be used to determine how to store the value object in a Map or Set. You must
  33884. * provide both or neither methods, one must not exist without the other.
  33885. *
  33886. * Also, an important relationship between these methods must be upheld: if two
  33887. * values are equal, they *must* return the same hashCode. If the values are not
  33888. * equal, they might have the same hashCode; this is called a hash collision,
  33889. * and while undesirable for performance reasons, it is acceptable.
  33890. *
  33891. * if (a.equals(b)) {
  33892. * assert( a.hashCode() === b.hashCode() );
  33893. * }
  33894. *
  33895. * All Immutable collections are Value Objects: they implement `equals()`
  33896. * and `hashCode()`.
  33897. */
  33898. function is(valueA, valueB) {
  33899. if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
  33900. return true;
  33901. }
  33902. if (!valueA || !valueB) {
  33903. return false;
  33904. }
  33905. if (
  33906. typeof valueA.valueOf === 'function' &&
  33907. typeof valueB.valueOf === 'function'
  33908. ) {
  33909. valueA = valueA.valueOf();
  33910. valueB = valueB.valueOf();
  33911. if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
  33912. return true;
  33913. }
  33914. if (!valueA || !valueB) {
  33915. return false;
  33916. }
  33917. }
  33918. return !!(
  33919. isValueObject(valueA) &&
  33920. isValueObject(valueB) &&
  33921. valueA.equals(valueB)
  33922. );
  33923. }
  33924. var imul =
  33925. typeof Math.imul === 'function' && Math.imul(0xffffffff, 2) === -2
  33926. ? Math.imul
  33927. : function imul(a, b) {
  33928. a |= 0; // int
  33929. b |= 0; // int
  33930. var c = a & 0xffff;
  33931. var d = b & 0xffff;
  33932. // Shift by 0 fixes the sign on the high part.
  33933. return (c * d + ((((a >>> 16) * d + c * (b >>> 16)) << 16) >>> 0)) | 0; // int
  33934. };
  33935. // v8 has an optimization for storing 31-bit signed numbers.
  33936. // Values which have either 00 or 11 as the high order bits qualify.
  33937. // This function drops the highest order bit in a signed number, maintaining
  33938. // the sign bit.
  33939. function smi(i32) {
  33940. return ((i32 >>> 1) & 0x40000000) | (i32 & 0xbfffffff);
  33941. }
  33942. var defaultValueOf = Object.prototype.valueOf;
  33943. function hash(o) {
  33944. switch (typeof o) {
  33945. case 'boolean':
  33946. // The hash values for built-in constants are a 1 value for each 5-byte
  33947. // shift region expect for the first, which encodes the value. This
  33948. // reduces the odds of a hash collision for these common values.
  33949. return o ? 0x42108421 : 0x42108420;
  33950. case 'number':
  33951. return hashNumber(o);
  33952. case 'string':
  33953. return o.length > STRING_HASH_CACHE_MIN_STRLEN
  33954. ? cachedHashString(o)
  33955. : hashString(o);
  33956. case 'object':
  33957. case 'function':
  33958. if (o === null) {
  33959. return 0x42108422;
  33960. }
  33961. if (typeof o.hashCode === 'function') {
  33962. // Drop any high bits from accidentally long hash codes.
  33963. return smi(o.hashCode(o));
  33964. }
  33965. if (o.valueOf !== defaultValueOf && typeof o.valueOf === 'function') {
  33966. o = o.valueOf(o);
  33967. }
  33968. return hashJSObj(o);
  33969. case 'undefined':
  33970. return 0x42108423;
  33971. default:
  33972. if (typeof o.toString === 'function') {
  33973. return hashString(o.toString());
  33974. }
  33975. throw new Error('Value type ' + typeof o + ' cannot be hashed.');
  33976. }
  33977. }
  33978. // Compress arbitrarily large numbers into smi hashes.
  33979. function hashNumber(n) {
  33980. if (n !== n || n === Infinity) {
  33981. return 0;
  33982. }
  33983. var hash = n | 0;
  33984. if (hash !== n) {
  33985. hash ^= n * 0xffffffff;
  33986. }
  33987. while (n > 0xffffffff) {
  33988. n /= 0xffffffff;
  33989. hash ^= n;
  33990. }
  33991. return smi(hash);
  33992. }
  33993. function cachedHashString(string) {
  33994. var hashed = stringHashCache[string];
  33995. if (hashed === undefined) {
  33996. hashed = hashString(string);
  33997. if (STRING_HASH_CACHE_SIZE === STRING_HASH_CACHE_MAX_SIZE) {
  33998. STRING_HASH_CACHE_SIZE = 0;
  33999. stringHashCache = {};
  34000. }
  34001. STRING_HASH_CACHE_SIZE++;
  34002. stringHashCache[string] = hashed;
  34003. }
  34004. return hashed;
  34005. }
  34006. // http://jsperf.com/hashing-strings
  34007. function hashString(string) {
  34008. // This is the hash from JVM
  34009. // The hash code for a string is computed as
  34010. // s[0] * 31 ^ (n - 1) + s[1] * 31 ^ (n - 2) + ... + s[n - 1],
  34011. // where s[i] is the ith character of the string and n is the length of
  34012. // the string. We "mod" the result to make it between 0 (inclusive) and 2^31
  34013. // (exclusive) by dropping high bits.
  34014. var hashed = 0;
  34015. for (var ii = 0; ii < string.length; ii++) {
  34016. hashed = (31 * hashed + string.charCodeAt(ii)) | 0;
  34017. }
  34018. return smi(hashed);
  34019. }
  34020. function hashJSObj(obj) {
  34021. var hashed;
  34022. if (usingWeakMap) {
  34023. hashed = weakMap.get(obj);
  34024. if (hashed !== undefined) {
  34025. return hashed;
  34026. }
  34027. }
  34028. hashed = obj[UID_HASH_KEY];
  34029. if (hashed !== undefined) {
  34030. return hashed;
  34031. }
  34032. if (!canDefineProperty) {
  34033. hashed = obj.propertyIsEnumerable && obj.propertyIsEnumerable[UID_HASH_KEY];
  34034. if (hashed !== undefined) {
  34035. return hashed;
  34036. }
  34037. hashed = getIENodeHash(obj);
  34038. if (hashed !== undefined) {
  34039. return hashed;
  34040. }
  34041. }
  34042. hashed = ++objHashUID;
  34043. if (objHashUID & 0x40000000) {
  34044. objHashUID = 0;
  34045. }
  34046. if (usingWeakMap) {
  34047. weakMap.set(obj, hashed);
  34048. } else if (isExtensible !== undefined && isExtensible(obj) === false) {
  34049. throw new Error('Non-extensible objects are not allowed as keys.');
  34050. } else if (canDefineProperty) {
  34051. Object.defineProperty(obj, UID_HASH_KEY, {
  34052. enumerable: false,
  34053. configurable: false,
  34054. writable: false,
  34055. value: hashed,
  34056. });
  34057. } else if (
  34058. obj.propertyIsEnumerable !== undefined &&
  34059. obj.propertyIsEnumerable === obj.constructor.prototype.propertyIsEnumerable
  34060. ) {
  34061. // Since we can't define a non-enumerable property on the object
  34062. // we'll hijack one of the less-used non-enumerable properties to
  34063. // save our hash on it. Since this is a function it will not show up in
  34064. // `JSON.stringify` which is what we want.
  34065. obj.propertyIsEnumerable = function() {
  34066. return this.constructor.prototype.propertyIsEnumerable.apply(
  34067. this,
  34068. arguments
  34069. );
  34070. };
  34071. obj.propertyIsEnumerable[UID_HASH_KEY] = hashed;
  34072. } else if (obj.nodeType !== undefined) {
  34073. // At this point we couldn't get the IE `uniqueID` to use as a hash
  34074. // and we couldn't use a non-enumerable property to exploit the
  34075. // dontEnum bug so we simply add the `UID_HASH_KEY` on the node
  34076. // itself.
  34077. obj[UID_HASH_KEY] = hashed;
  34078. } else {
  34079. throw new Error('Unable to set a non-enumerable property on object.');
  34080. }
  34081. return hashed;
  34082. }
  34083. // Get references to ES5 object methods.
  34084. var isExtensible = Object.isExtensible;
  34085. // True if Object.defineProperty works as expected. IE8 fails this test.
  34086. var canDefineProperty = (function() {
  34087. try {
  34088. Object.defineProperty({}, '@', {});
  34089. return true;
  34090. } catch (e) {
  34091. return false;
  34092. }
  34093. })();
  34094. // IE has a `uniqueID` property on DOM nodes. We can construct the hash from it
  34095. // and avoid memory leaks from the IE cloneNode bug.
  34096. function getIENodeHash(node) {
  34097. if (node && node.nodeType > 0) {
  34098. switch (node.nodeType) {
  34099. case 1: // Element
  34100. return node.uniqueID;
  34101. case 9: // Document
  34102. return node.documentElement && node.documentElement.uniqueID;
  34103. }
  34104. }
  34105. }
  34106. // If possible, use a WeakMap.
  34107. var usingWeakMap = typeof WeakMap === 'function';
  34108. var weakMap;
  34109. if (usingWeakMap) {
  34110. weakMap = new WeakMap();
  34111. }
  34112. var objHashUID = 0;
  34113. var UID_HASH_KEY = '__immutablehash__';
  34114. if (typeof Symbol === 'function') {
  34115. UID_HASH_KEY = Symbol(UID_HASH_KEY);
  34116. }
  34117. var STRING_HASH_CACHE_MIN_STRLEN = 16;
  34118. var STRING_HASH_CACHE_MAX_SIZE = 255;
  34119. var STRING_HASH_CACHE_SIZE = 0;
  34120. var stringHashCache = {};
  34121. var ToKeyedSequence = /*@__PURE__*/(function (KeyedSeq$$1) {
  34122. function ToKeyedSequence(indexed, useKeys) {
  34123. this._iter = indexed;
  34124. this._useKeys = useKeys;
  34125. this.size = indexed.size;
  34126. }
  34127. if ( KeyedSeq$$1 ) ToKeyedSequence.__proto__ = KeyedSeq$$1;
  34128. ToKeyedSequence.prototype = Object.create( KeyedSeq$$1 && KeyedSeq$$1.prototype );
  34129. ToKeyedSequence.prototype.constructor = ToKeyedSequence;
  34130. ToKeyedSequence.prototype.get = function get (key, notSetValue) {
  34131. return this._iter.get(key, notSetValue);
  34132. };
  34133. ToKeyedSequence.prototype.has = function has (key) {
  34134. return this._iter.has(key);
  34135. };
  34136. ToKeyedSequence.prototype.valueSeq = function valueSeq () {
  34137. return this._iter.valueSeq();
  34138. };
  34139. ToKeyedSequence.prototype.reverse = function reverse () {
  34140. var this$1 = this;
  34141. var reversedSequence = reverseFactory(this, true);
  34142. if (!this._useKeys) {
  34143. reversedSequence.valueSeq = function () { return this$1._iter.toSeq().reverse(); };
  34144. }
  34145. return reversedSequence;
  34146. };
  34147. ToKeyedSequence.prototype.map = function map (mapper, context) {
  34148. var this$1 = this;
  34149. var mappedSequence = mapFactory(this, mapper, context);
  34150. if (!this._useKeys) {
  34151. mappedSequence.valueSeq = function () { return this$1._iter.toSeq().map(mapper, context); };
  34152. }
  34153. return mappedSequence;
  34154. };
  34155. ToKeyedSequence.prototype.__iterate = function __iterate (fn, reverse) {
  34156. var this$1 = this;
  34157. return this._iter.__iterate(function (v, k) { return fn(v, k, this$1); }, reverse);
  34158. };
  34159. ToKeyedSequence.prototype.__iterator = function __iterator (type, reverse) {
  34160. return this._iter.__iterator(type, reverse);
  34161. };
  34162. return ToKeyedSequence;
  34163. }(KeyedSeq));
  34164. ToKeyedSequence.prototype[IS_ORDERED_SYMBOL] = true;
  34165. var ToIndexedSequence = /*@__PURE__*/(function (IndexedSeq$$1) {
  34166. function ToIndexedSequence(iter) {
  34167. this._iter = iter;
  34168. this.size = iter.size;
  34169. }
  34170. if ( IndexedSeq$$1 ) ToIndexedSequence.__proto__ = IndexedSeq$$1;
  34171. ToIndexedSequence.prototype = Object.create( IndexedSeq$$1 && IndexedSeq$$1.prototype );
  34172. ToIndexedSequence.prototype.constructor = ToIndexedSequence;
  34173. ToIndexedSequence.prototype.includes = function includes (value) {
  34174. return this._iter.includes(value);
  34175. };
  34176. ToIndexedSequence.prototype.__iterate = function __iterate (fn, reverse) {
  34177. var this$1 = this;
  34178. var i = 0;
  34179. reverse && ensureSize(this);
  34180. return this._iter.__iterate(
  34181. function (v) { return fn(v, reverse ? this$1.size - ++i : i++, this$1); },
  34182. reverse
  34183. );
  34184. };
  34185. ToIndexedSequence.prototype.__iterator = function __iterator (type, reverse) {
  34186. var this$1 = this;
  34187. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  34188. var i = 0;
  34189. reverse && ensureSize(this);
  34190. return new Iterator(function () {
  34191. var step = iterator.next();
  34192. return step.done
  34193. ? step
  34194. : iteratorValue(
  34195. type,
  34196. reverse ? this$1.size - ++i : i++,
  34197. step.value,
  34198. step
  34199. );
  34200. });
  34201. };
  34202. return ToIndexedSequence;
  34203. }(IndexedSeq));
  34204. var ToSetSequence = /*@__PURE__*/(function (SetSeq$$1) {
  34205. function ToSetSequence(iter) {
  34206. this._iter = iter;
  34207. this.size = iter.size;
  34208. }
  34209. if ( SetSeq$$1 ) ToSetSequence.__proto__ = SetSeq$$1;
  34210. ToSetSequence.prototype = Object.create( SetSeq$$1 && SetSeq$$1.prototype );
  34211. ToSetSequence.prototype.constructor = ToSetSequence;
  34212. ToSetSequence.prototype.has = function has (key) {
  34213. return this._iter.includes(key);
  34214. };
  34215. ToSetSequence.prototype.__iterate = function __iterate (fn, reverse) {
  34216. var this$1 = this;
  34217. return this._iter.__iterate(function (v) { return fn(v, v, this$1); }, reverse);
  34218. };
  34219. ToSetSequence.prototype.__iterator = function __iterator (type, reverse) {
  34220. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  34221. return new Iterator(function () {
  34222. var step = iterator.next();
  34223. return step.done
  34224. ? step
  34225. : iteratorValue(type, step.value, step.value, step);
  34226. });
  34227. };
  34228. return ToSetSequence;
  34229. }(SetSeq));
  34230. var FromEntriesSequence = /*@__PURE__*/(function (KeyedSeq$$1) {
  34231. function FromEntriesSequence(entries) {
  34232. this._iter = entries;
  34233. this.size = entries.size;
  34234. }
  34235. if ( KeyedSeq$$1 ) FromEntriesSequence.__proto__ = KeyedSeq$$1;
  34236. FromEntriesSequence.prototype = Object.create( KeyedSeq$$1 && KeyedSeq$$1.prototype );
  34237. FromEntriesSequence.prototype.constructor = FromEntriesSequence;
  34238. FromEntriesSequence.prototype.entrySeq = function entrySeq () {
  34239. return this._iter.toSeq();
  34240. };
  34241. FromEntriesSequence.prototype.__iterate = function __iterate (fn, reverse) {
  34242. var this$1 = this;
  34243. return this._iter.__iterate(function (entry) {
  34244. // Check if entry exists first so array access doesn't throw for holes
  34245. // in the parent iteration.
  34246. if (entry) {
  34247. validateEntry(entry);
  34248. var indexedCollection = isCollection(entry);
  34249. return fn(
  34250. indexedCollection ? entry.get(1) : entry[1],
  34251. indexedCollection ? entry.get(0) : entry[0],
  34252. this$1
  34253. );
  34254. }
  34255. }, reverse);
  34256. };
  34257. FromEntriesSequence.prototype.__iterator = function __iterator (type, reverse) {
  34258. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  34259. return new Iterator(function () {
  34260. while (true) {
  34261. var step = iterator.next();
  34262. if (step.done) {
  34263. return step;
  34264. }
  34265. var entry = step.value;
  34266. // Check if entry exists first so array access doesn't throw for holes
  34267. // in the parent iteration.
  34268. if (entry) {
  34269. validateEntry(entry);
  34270. var indexedCollection = isCollection(entry);
  34271. return iteratorValue(
  34272. type,
  34273. indexedCollection ? entry.get(0) : entry[0],
  34274. indexedCollection ? entry.get(1) : entry[1],
  34275. step
  34276. );
  34277. }
  34278. }
  34279. });
  34280. };
  34281. return FromEntriesSequence;
  34282. }(KeyedSeq));
  34283. ToIndexedSequence.prototype.cacheResult = ToKeyedSequence.prototype.cacheResult = ToSetSequence.prototype.cacheResult = FromEntriesSequence.prototype.cacheResult = cacheResultThrough;
  34284. function flipFactory(collection) {
  34285. var flipSequence = makeSequence(collection);
  34286. flipSequence._iter = collection;
  34287. flipSequence.size = collection.size;
  34288. flipSequence.flip = function () { return collection; };
  34289. flipSequence.reverse = function() {
  34290. var reversedSequence = collection.reverse.apply(this); // super.reverse()
  34291. reversedSequence.flip = function () { return collection.reverse(); };
  34292. return reversedSequence;
  34293. };
  34294. flipSequence.has = function (key) { return collection.includes(key); };
  34295. flipSequence.includes = function (key) { return collection.has(key); };
  34296. flipSequence.cacheResult = cacheResultThrough;
  34297. flipSequence.__iterateUncached = function(fn, reverse) {
  34298. var this$1 = this;
  34299. return collection.__iterate(function (v, k) { return fn(k, v, this$1) !== false; }, reverse);
  34300. };
  34301. flipSequence.__iteratorUncached = function(type, reverse) {
  34302. if (type === ITERATE_ENTRIES) {
  34303. var iterator = collection.__iterator(type, reverse);
  34304. return new Iterator(function () {
  34305. var step = iterator.next();
  34306. if (!step.done) {
  34307. var k = step.value[0];
  34308. step.value[0] = step.value[1];
  34309. step.value[1] = k;
  34310. }
  34311. return step;
  34312. });
  34313. }
  34314. return collection.__iterator(
  34315. type === ITERATE_VALUES ? ITERATE_KEYS : ITERATE_VALUES,
  34316. reverse
  34317. );
  34318. };
  34319. return flipSequence;
  34320. }
  34321. function mapFactory(collection, mapper, context) {
  34322. var mappedSequence = makeSequence(collection);
  34323. mappedSequence.size = collection.size;
  34324. mappedSequence.has = function (key) { return collection.has(key); };
  34325. mappedSequence.get = function (key, notSetValue) {
  34326. var v = collection.get(key, NOT_SET);
  34327. return v === NOT_SET
  34328. ? notSetValue
  34329. : mapper.call(context, v, key, collection);
  34330. };
  34331. mappedSequence.__iterateUncached = function(fn, reverse) {
  34332. var this$1 = this;
  34333. return collection.__iterate(
  34334. function (v, k, c) { return fn(mapper.call(context, v, k, c), k, this$1) !== false; },
  34335. reverse
  34336. );
  34337. };
  34338. mappedSequence.__iteratorUncached = function(type, reverse) {
  34339. var iterator = collection.__iterator(ITERATE_ENTRIES, reverse);
  34340. return new Iterator(function () {
  34341. var step = iterator.next();
  34342. if (step.done) {
  34343. return step;
  34344. }
  34345. var entry = step.value;
  34346. var key = entry[0];
  34347. return iteratorValue(
  34348. type,
  34349. key,
  34350. mapper.call(context, entry[1], key, collection),
  34351. step
  34352. );
  34353. });
  34354. };
  34355. return mappedSequence;
  34356. }
  34357. function reverseFactory(collection, useKeys) {
  34358. var this$1 = this;
  34359. var reversedSequence = makeSequence(collection);
  34360. reversedSequence._iter = collection;
  34361. reversedSequence.size = collection.size;
  34362. reversedSequence.reverse = function () { return collection; };
  34363. if (collection.flip) {
  34364. reversedSequence.flip = function() {
  34365. var flipSequence = flipFactory(collection);
  34366. flipSequence.reverse = function () { return collection.flip(); };
  34367. return flipSequence;
  34368. };
  34369. }
  34370. reversedSequence.get = function (key, notSetValue) { return collection.get(useKeys ? key : -1 - key, notSetValue); };
  34371. reversedSequence.has = function (key) { return collection.has(useKeys ? key : -1 - key); };
  34372. reversedSequence.includes = function (value) { return collection.includes(value); };
  34373. reversedSequence.cacheResult = cacheResultThrough;
  34374. reversedSequence.__iterate = function(fn, reverse) {
  34375. var this$1 = this;
  34376. var i = 0;
  34377. reverse && ensureSize(collection);
  34378. return collection.__iterate(
  34379. function (v, k) { return fn(v, useKeys ? k : reverse ? this$1.size - ++i : i++, this$1); },
  34380. !reverse
  34381. );
  34382. };
  34383. reversedSequence.__iterator = function (type, reverse) {
  34384. var i = 0;
  34385. reverse && ensureSize(collection);
  34386. var iterator = collection.__iterator(ITERATE_ENTRIES, !reverse);
  34387. return new Iterator(function () {
  34388. var step = iterator.next();
  34389. if (step.done) {
  34390. return step;
  34391. }
  34392. var entry = step.value;
  34393. return iteratorValue(
  34394. type,
  34395. useKeys ? entry[0] : reverse ? this$1.size - ++i : i++,
  34396. entry[1],
  34397. step
  34398. );
  34399. });
  34400. };
  34401. return reversedSequence;
  34402. }
  34403. function filterFactory(collection, predicate, context, useKeys) {
  34404. var filterSequence = makeSequence(collection);
  34405. if (useKeys) {
  34406. filterSequence.has = function (key) {
  34407. var v = collection.get(key, NOT_SET);
  34408. return v !== NOT_SET && !!predicate.call(context, v, key, collection);
  34409. };
  34410. filterSequence.get = function (key, notSetValue) {
  34411. var v = collection.get(key, NOT_SET);
  34412. return v !== NOT_SET && predicate.call(context, v, key, collection)
  34413. ? v
  34414. : notSetValue;
  34415. };
  34416. }
  34417. filterSequence.__iterateUncached = function(fn, reverse) {
  34418. var this$1 = this;
  34419. var iterations = 0;
  34420. collection.__iterate(function (v, k, c) {
  34421. if (predicate.call(context, v, k, c)) {
  34422. iterations++;
  34423. return fn(v, useKeys ? k : iterations - 1, this$1);
  34424. }
  34425. }, reverse);
  34426. return iterations;
  34427. };
  34428. filterSequence.__iteratorUncached = function(type, reverse) {
  34429. var iterator = collection.__iterator(ITERATE_ENTRIES, reverse);
  34430. var iterations = 0;
  34431. return new Iterator(function () {
  34432. while (true) {
  34433. var step = iterator.next();
  34434. if (step.done) {
  34435. return step;
  34436. }
  34437. var entry = step.value;
  34438. var key = entry[0];
  34439. var value = entry[1];
  34440. if (predicate.call(context, value, key, collection)) {
  34441. return iteratorValue(type, useKeys ? key : iterations++, value, step);
  34442. }
  34443. }
  34444. });
  34445. };
  34446. return filterSequence;
  34447. }
  34448. function countByFactory(collection, grouper, context) {
  34449. var groups = Map().asMutable();
  34450. collection.__iterate(function (v, k) {
  34451. groups.update(grouper.call(context, v, k, collection), 0, function (a) { return a + 1; });
  34452. });
  34453. return groups.asImmutable();
  34454. }
  34455. function groupByFactory(collection, grouper, context) {
  34456. var isKeyedIter = isKeyed(collection);
  34457. var groups = (isOrdered(collection) ? OrderedMap() : Map()).asMutable();
  34458. collection.__iterate(function (v, k) {
  34459. groups.update(
  34460. grouper.call(context, v, k, collection),
  34461. function (a) { return ((a = a || []), a.push(isKeyedIter ? [k, v] : v), a); }
  34462. );
  34463. });
  34464. var coerce = collectionClass(collection);
  34465. return groups.map(function (arr) { return reify(collection, coerce(arr)); }).asImmutable();
  34466. }
  34467. function sliceFactory(collection, begin, end, useKeys) {
  34468. var originalSize = collection.size;
  34469. if (wholeSlice(begin, end, originalSize)) {
  34470. return collection;
  34471. }
  34472. var resolvedBegin = resolveBegin(begin, originalSize);
  34473. var resolvedEnd = resolveEnd(end, originalSize);
  34474. // begin or end will be NaN if they were provided as negative numbers and
  34475. // this collection's size is unknown. In that case, cache first so there is
  34476. // a known size and these do not resolve to NaN.
  34477. if (resolvedBegin !== resolvedBegin || resolvedEnd !== resolvedEnd) {
  34478. return sliceFactory(collection.toSeq().cacheResult(), begin, end, useKeys);
  34479. }
  34480. // Note: resolvedEnd is undefined when the original sequence's length is
  34481. // unknown and this slice did not supply an end and should contain all
  34482. // elements after resolvedBegin.
  34483. // In that case, resolvedSize will be NaN and sliceSize will remain undefined.
  34484. var resolvedSize = resolvedEnd - resolvedBegin;
  34485. var sliceSize;
  34486. if (resolvedSize === resolvedSize) {
  34487. sliceSize = resolvedSize < 0 ? 0 : resolvedSize;
  34488. }
  34489. var sliceSeq = makeSequence(collection);
  34490. // If collection.size is undefined, the size of the realized sliceSeq is
  34491. // unknown at this point unless the number of items to slice is 0
  34492. sliceSeq.size =
  34493. sliceSize === 0 ? sliceSize : (collection.size && sliceSize) || undefined;
  34494. if (!useKeys && isSeq(collection) && sliceSize >= 0) {
  34495. sliceSeq.get = function(index, notSetValue) {
  34496. index = wrapIndex(this, index);
  34497. return index >= 0 && index < sliceSize
  34498. ? collection.get(index + resolvedBegin, notSetValue)
  34499. : notSetValue;
  34500. };
  34501. }
  34502. sliceSeq.__iterateUncached = function(fn, reverse) {
  34503. var this$1 = this;
  34504. if (sliceSize === 0) {
  34505. return 0;
  34506. }
  34507. if (reverse) {
  34508. return this.cacheResult().__iterate(fn, reverse);
  34509. }
  34510. var skipped = 0;
  34511. var isSkipping = true;
  34512. var iterations = 0;
  34513. collection.__iterate(function (v, k) {
  34514. if (!(isSkipping && (isSkipping = skipped++ < resolvedBegin))) {
  34515. iterations++;
  34516. return (
  34517. fn(v, useKeys ? k : iterations - 1, this$1) !== false &&
  34518. iterations !== sliceSize
  34519. );
  34520. }
  34521. });
  34522. return iterations;
  34523. };
  34524. sliceSeq.__iteratorUncached = function(type, reverse) {
  34525. if (sliceSize !== 0 && reverse) {
  34526. return this.cacheResult().__iterator(type, reverse);
  34527. }
  34528. // Don't bother instantiating parent iterator if taking 0.
  34529. if (sliceSize === 0) {
  34530. return new Iterator(iteratorDone);
  34531. }
  34532. var iterator = collection.__iterator(type, reverse);
  34533. var skipped = 0;
  34534. var iterations = 0;
  34535. return new Iterator(function () {
  34536. while (skipped++ < resolvedBegin) {
  34537. iterator.next();
  34538. }
  34539. if (++iterations > sliceSize) {
  34540. return iteratorDone();
  34541. }
  34542. var step = iterator.next();
  34543. if (useKeys || type === ITERATE_VALUES || step.done) {
  34544. return step;
  34545. }
  34546. if (type === ITERATE_KEYS) {
  34547. return iteratorValue(type, iterations - 1, undefined, step);
  34548. }
  34549. return iteratorValue(type, iterations - 1, step.value[1], step);
  34550. });
  34551. };
  34552. return sliceSeq;
  34553. }
  34554. function takeWhileFactory(collection, predicate, context) {
  34555. var takeSequence = makeSequence(collection);
  34556. takeSequence.__iterateUncached = function(fn, reverse) {
  34557. var this$1 = this;
  34558. if (reverse) {
  34559. return this.cacheResult().__iterate(fn, reverse);
  34560. }
  34561. var iterations = 0;
  34562. collection.__iterate(
  34563. function (v, k, c) { return predicate.call(context, v, k, c) && ++iterations && fn(v, k, this$1); }
  34564. );
  34565. return iterations;
  34566. };
  34567. takeSequence.__iteratorUncached = function(type, reverse) {
  34568. var this$1 = this;
  34569. if (reverse) {
  34570. return this.cacheResult().__iterator(type, reverse);
  34571. }
  34572. var iterator = collection.__iterator(ITERATE_ENTRIES, reverse);
  34573. var iterating = true;
  34574. return new Iterator(function () {
  34575. if (!iterating) {
  34576. return iteratorDone();
  34577. }
  34578. var step = iterator.next();
  34579. if (step.done) {
  34580. return step;
  34581. }
  34582. var entry = step.value;
  34583. var k = entry[0];
  34584. var v = entry[1];
  34585. if (!predicate.call(context, v, k, this$1)) {
  34586. iterating = false;
  34587. return iteratorDone();
  34588. }
  34589. return type === ITERATE_ENTRIES ? step : iteratorValue(type, k, v, step);
  34590. });
  34591. };
  34592. return takeSequence;
  34593. }
  34594. function skipWhileFactory(collection, predicate, context, useKeys) {
  34595. var skipSequence = makeSequence(collection);
  34596. skipSequence.__iterateUncached = function(fn, reverse) {
  34597. var this$1 = this;
  34598. if (reverse) {
  34599. return this.cacheResult().__iterate(fn, reverse);
  34600. }
  34601. var isSkipping = true;
  34602. var iterations = 0;
  34603. collection.__iterate(function (v, k, c) {
  34604. if (!(isSkipping && (isSkipping = predicate.call(context, v, k, c)))) {
  34605. iterations++;
  34606. return fn(v, useKeys ? k : iterations - 1, this$1);
  34607. }
  34608. });
  34609. return iterations;
  34610. };
  34611. skipSequence.__iteratorUncached = function(type, reverse) {
  34612. var this$1 = this;
  34613. if (reverse) {
  34614. return this.cacheResult().__iterator(type, reverse);
  34615. }
  34616. var iterator = collection.__iterator(ITERATE_ENTRIES, reverse);
  34617. var skipping = true;
  34618. var iterations = 0;
  34619. return new Iterator(function () {
  34620. var step;
  34621. var k;
  34622. var v;
  34623. do {
  34624. step = iterator.next();
  34625. if (step.done) {
  34626. if (useKeys || type === ITERATE_VALUES) {
  34627. return step;
  34628. }
  34629. if (type === ITERATE_KEYS) {
  34630. return iteratorValue(type, iterations++, undefined, step);
  34631. }
  34632. return iteratorValue(type, iterations++, step.value[1], step);
  34633. }
  34634. var entry = step.value;
  34635. k = entry[0];
  34636. v = entry[1];
  34637. skipping && (skipping = predicate.call(context, v, k, this$1));
  34638. } while (skipping);
  34639. return type === ITERATE_ENTRIES ? step : iteratorValue(type, k, v, step);
  34640. });
  34641. };
  34642. return skipSequence;
  34643. }
  34644. function concatFactory(collection, values) {
  34645. var isKeyedCollection = isKeyed(collection);
  34646. var iters = [collection]
  34647. .concat(values)
  34648. .map(function (v) {
  34649. if (!isCollection(v)) {
  34650. v = isKeyedCollection
  34651. ? keyedSeqFromValue(v)
  34652. : indexedSeqFromValue(Array.isArray(v) ? v : [v]);
  34653. } else if (isKeyedCollection) {
  34654. v = KeyedCollection(v);
  34655. }
  34656. return v;
  34657. })
  34658. .filter(function (v) { return v.size !== 0; });
  34659. if (iters.length === 0) {
  34660. return collection;
  34661. }
  34662. if (iters.length === 1) {
  34663. var singleton = iters[0];
  34664. if (
  34665. singleton === collection ||
  34666. (isKeyedCollection && isKeyed(singleton)) ||
  34667. (isIndexed(collection) && isIndexed(singleton))
  34668. ) {
  34669. return singleton;
  34670. }
  34671. }
  34672. var concatSeq = new ArraySeq(iters);
  34673. if (isKeyedCollection) {
  34674. concatSeq = concatSeq.toKeyedSeq();
  34675. } else if (!isIndexed(collection)) {
  34676. concatSeq = concatSeq.toSetSeq();
  34677. }
  34678. concatSeq = concatSeq.flatten(true);
  34679. concatSeq.size = iters.reduce(function (sum, seq) {
  34680. if (sum !== undefined) {
  34681. var size = seq.size;
  34682. if (size !== undefined) {
  34683. return sum + size;
  34684. }
  34685. }
  34686. }, 0);
  34687. return concatSeq;
  34688. }
  34689. function flattenFactory(collection, depth, useKeys) {
  34690. var flatSequence = makeSequence(collection);
  34691. flatSequence.__iterateUncached = function(fn, reverse) {
  34692. if (reverse) {
  34693. return this.cacheResult().__iterate(fn, reverse);
  34694. }
  34695. var iterations = 0;
  34696. var stopped = false;
  34697. function flatDeep(iter, currentDepth) {
  34698. iter.__iterate(function (v, k) {
  34699. if ((!depth || currentDepth < depth) && isCollection(v)) {
  34700. flatDeep(v, currentDepth + 1);
  34701. } else {
  34702. iterations++;
  34703. if (fn(v, useKeys ? k : iterations - 1, flatSequence) === false) {
  34704. stopped = true;
  34705. }
  34706. }
  34707. return !stopped;
  34708. }, reverse);
  34709. }
  34710. flatDeep(collection, 0);
  34711. return iterations;
  34712. };
  34713. flatSequence.__iteratorUncached = function(type, reverse) {
  34714. if (reverse) {
  34715. return this.cacheResult().__iterator(type, reverse);
  34716. }
  34717. var iterator = collection.__iterator(type, reverse);
  34718. var stack = [];
  34719. var iterations = 0;
  34720. return new Iterator(function () {
  34721. while (iterator) {
  34722. var step = iterator.next();
  34723. if (step.done !== false) {
  34724. iterator = stack.pop();
  34725. continue;
  34726. }
  34727. var v = step.value;
  34728. if (type === ITERATE_ENTRIES) {
  34729. v = v[1];
  34730. }
  34731. if ((!depth || stack.length < depth) && isCollection(v)) {
  34732. stack.push(iterator);
  34733. iterator = v.__iterator(type, reverse);
  34734. } else {
  34735. return useKeys ? step : iteratorValue(type, iterations++, v, step);
  34736. }
  34737. }
  34738. return iteratorDone();
  34739. });
  34740. };
  34741. return flatSequence;
  34742. }
  34743. function flatMapFactory(collection, mapper, context) {
  34744. var coerce = collectionClass(collection);
  34745. return collection
  34746. .toSeq()
  34747. .map(function (v, k) { return coerce(mapper.call(context, v, k, collection)); })
  34748. .flatten(true);
  34749. }
  34750. function interposeFactory(collection, separator) {
  34751. var interposedSequence = makeSequence(collection);
  34752. interposedSequence.size = collection.size && collection.size * 2 - 1;
  34753. interposedSequence.__iterateUncached = function(fn, reverse) {
  34754. var this$1 = this;
  34755. var iterations = 0;
  34756. collection.__iterate(
  34757. function (v) { return (!iterations || fn(separator, iterations++, this$1) !== false) &&
  34758. fn(v, iterations++, this$1) !== false; },
  34759. reverse
  34760. );
  34761. return iterations;
  34762. };
  34763. interposedSequence.__iteratorUncached = function(type, reverse) {
  34764. var iterator = collection.__iterator(ITERATE_VALUES, reverse);
  34765. var iterations = 0;
  34766. var step;
  34767. return new Iterator(function () {
  34768. if (!step || iterations % 2) {
  34769. step = iterator.next();
  34770. if (step.done) {
  34771. return step;
  34772. }
  34773. }
  34774. return iterations % 2
  34775. ? iteratorValue(type, iterations++, separator)
  34776. : iteratorValue(type, iterations++, step.value, step);
  34777. });
  34778. };
  34779. return interposedSequence;
  34780. }
  34781. function sortFactory(collection, comparator, mapper) {
  34782. if (!comparator) {
  34783. comparator = defaultComparator;
  34784. }
  34785. var isKeyedCollection = isKeyed(collection);
  34786. var index = 0;
  34787. var entries = collection
  34788. .toSeq()
  34789. .map(function (v, k) { return [k, v, index++, mapper ? mapper(v, k, collection) : v]; })
  34790. .valueSeq()
  34791. .toArray();
  34792. entries.sort(function (a, b) { return comparator(a[3], b[3]) || a[2] - b[2]; }).forEach(
  34793. isKeyedCollection
  34794. ? function (v, i) {
  34795. entries[i].length = 2;
  34796. }
  34797. : function (v, i) {
  34798. entries[i] = v[1];
  34799. }
  34800. );
  34801. return isKeyedCollection
  34802. ? KeyedSeq(entries)
  34803. : isIndexed(collection)
  34804. ? IndexedSeq(entries)
  34805. : SetSeq(entries);
  34806. }
  34807. function maxFactory(collection, comparator, mapper) {
  34808. if (!comparator) {
  34809. comparator = defaultComparator;
  34810. }
  34811. if (mapper) {
  34812. var entry = collection
  34813. .toSeq()
  34814. .map(function (v, k) { return [v, mapper(v, k, collection)]; })
  34815. .reduce(function (a, b) { return (maxCompare(comparator, a[1], b[1]) ? b : a); });
  34816. return entry && entry[0];
  34817. }
  34818. return collection.reduce(function (a, b) { return (maxCompare(comparator, a, b) ? b : a); });
  34819. }
  34820. function maxCompare(comparator, a, b) {
  34821. var comp = comparator(b, a);
  34822. // b is considered the new max if the comparator declares them equal, but
  34823. // they are not equal and b is in fact a nullish value.
  34824. return (
  34825. (comp === 0 && b !== a && (b === undefined || b === null || b !== b)) ||
  34826. comp > 0
  34827. );
  34828. }
  34829. function zipWithFactory(keyIter, zipper, iters, zipAll) {
  34830. var zipSequence = makeSequence(keyIter);
  34831. var sizes = new ArraySeq(iters).map(function (i) { return i.size; });
  34832. zipSequence.size = zipAll ? sizes.max() : sizes.min();
  34833. // Note: this a generic base implementation of __iterate in terms of
  34834. // __iterator which may be more generically useful in the future.
  34835. zipSequence.__iterate = function(fn, reverse) {
  34836. /* generic:
  34837. var iterator = this.__iterator(ITERATE_ENTRIES, reverse);
  34838. var step;
  34839. var iterations = 0;
  34840. while (!(step = iterator.next()).done) {
  34841. iterations++;
  34842. if (fn(step.value[1], step.value[0], this) === false) {
  34843. break;
  34844. }
  34845. }
  34846. return iterations;
  34847. */
  34848. // indexed:
  34849. var iterator = this.__iterator(ITERATE_VALUES, reverse);
  34850. var step;
  34851. var iterations = 0;
  34852. while (!(step = iterator.next()).done) {
  34853. if (fn(step.value, iterations++, this) === false) {
  34854. break;
  34855. }
  34856. }
  34857. return iterations;
  34858. };
  34859. zipSequence.__iteratorUncached = function(type, reverse) {
  34860. var iterators = iters.map(
  34861. function (i) { return ((i = Collection(i)), getIterator(reverse ? i.reverse() : i)); }
  34862. );
  34863. var iterations = 0;
  34864. var isDone = false;
  34865. return new Iterator(function () {
  34866. var steps;
  34867. if (!isDone) {
  34868. steps = iterators.map(function (i) { return i.next(); });
  34869. isDone = zipAll ? steps.every(function (s) { return s.done; }) : steps.some(function (s) { return s.done; });
  34870. }
  34871. if (isDone) {
  34872. return iteratorDone();
  34873. }
  34874. return iteratorValue(
  34875. type,
  34876. iterations++,
  34877. zipper.apply(null, steps.map(function (s) { return s.value; }))
  34878. );
  34879. });
  34880. };
  34881. return zipSequence;
  34882. }
  34883. // #pragma Helper Functions
  34884. function reify(iter, seq) {
  34885. return iter === seq ? iter : isSeq(iter) ? seq : iter.constructor(seq);
  34886. }
  34887. function validateEntry(entry) {
  34888. if (entry !== Object(entry)) {
  34889. throw new TypeError('Expected [K, V] tuple: ' + entry);
  34890. }
  34891. }
  34892. function collectionClass(collection) {
  34893. return isKeyed(collection)
  34894. ? KeyedCollection
  34895. : isIndexed(collection)
  34896. ? IndexedCollection
  34897. : SetCollection;
  34898. }
  34899. function makeSequence(collection) {
  34900. return Object.create(
  34901. (isKeyed(collection)
  34902. ? KeyedSeq
  34903. : isIndexed(collection)
  34904. ? IndexedSeq
  34905. : SetSeq
  34906. ).prototype
  34907. );
  34908. }
  34909. function cacheResultThrough() {
  34910. if (this._iter.cacheResult) {
  34911. this._iter.cacheResult();
  34912. this.size = this._iter.size;
  34913. return this;
  34914. }
  34915. return Seq.prototype.cacheResult.call(this);
  34916. }
  34917. function defaultComparator(a, b) {
  34918. if (a === undefined && b === undefined) {
  34919. return 0;
  34920. }
  34921. if (a === undefined) {
  34922. return 1;
  34923. }
  34924. if (b === undefined) {
  34925. return -1;
  34926. }
  34927. return a > b ? 1 : a < b ? -1 : 0;
  34928. }
  34929. // http://jsperf.com/copy-array-inline
  34930. function arrCopy(arr, offset) {
  34931. offset = offset || 0;
  34932. var len = Math.max(0, arr.length - offset);
  34933. var newArr = new Array(len);
  34934. for (var ii = 0; ii < len; ii++) {
  34935. newArr[ii] = arr[ii + offset];
  34936. }
  34937. return newArr;
  34938. }
  34939. function invariant(condition, error) {
  34940. if (!condition) { throw new Error(error); }
  34941. }
  34942. function assertNotInfinite(size) {
  34943. invariant(
  34944. size !== Infinity,
  34945. 'Cannot perform this action with an infinite size.'
  34946. );
  34947. }
  34948. function coerceKeyPath(keyPath) {
  34949. if (isArrayLike(keyPath) && typeof keyPath !== 'string') {
  34950. return keyPath;
  34951. }
  34952. if (isOrdered(keyPath)) {
  34953. return keyPath.toArray();
  34954. }
  34955. throw new TypeError(
  34956. 'Invalid keyPath: expected Ordered Collection or Array: ' + keyPath
  34957. );
  34958. }
  34959. function isPlainObj(value) {
  34960. return (
  34961. value &&
  34962. (typeof value.constructor !== 'function' ||
  34963. value.constructor.name === 'Object')
  34964. );
  34965. }
  34966. /**
  34967. * Returns true if the value is a potentially-persistent data structure, either
  34968. * provided by Immutable.js or a plain Array or Object.
  34969. */
  34970. function isDataStructure(value) {
  34971. return (
  34972. typeof value === 'object' &&
  34973. (isImmutable(value) || Array.isArray(value) || isPlainObj(value))
  34974. );
  34975. }
  34976. /**
  34977. * Converts a value to a string, adding quotes if a string was provided.
  34978. */
  34979. function quoteString(value) {
  34980. try {
  34981. return typeof value === 'string' ? JSON.stringify(value) : String(value);
  34982. } catch (_ignoreError) {
  34983. return JSON.stringify(value);
  34984. }
  34985. }
  34986. function has(collection, key) {
  34987. return isImmutable(collection)
  34988. ? collection.has(key)
  34989. : isDataStructure(collection) && hasOwnProperty.call(collection, key);
  34990. }
  34991. function get(collection, key, notSetValue) {
  34992. return isImmutable(collection)
  34993. ? collection.get(key, notSetValue)
  34994. : !has(collection, key)
  34995. ? notSetValue
  34996. : typeof collection.get === 'function'
  34997. ? collection.get(key)
  34998. : collection[key];
  34999. }
  35000. function shallowCopy(from) {
  35001. if (Array.isArray(from)) {
  35002. return arrCopy(from);
  35003. }
  35004. var to = {};
  35005. for (var key in from) {
  35006. if (hasOwnProperty.call(from, key)) {
  35007. to[key] = from[key];
  35008. }
  35009. }
  35010. return to;
  35011. }
  35012. function remove(collection, key) {
  35013. if (!isDataStructure(collection)) {
  35014. throw new TypeError(
  35015. 'Cannot update non-data-structure value: ' + collection
  35016. );
  35017. }
  35018. if (isImmutable(collection)) {
  35019. if (!collection.remove) {
  35020. throw new TypeError(
  35021. 'Cannot update immutable value without .remove() method: ' + collection
  35022. );
  35023. }
  35024. return collection.remove(key);
  35025. }
  35026. if (!hasOwnProperty.call(collection, key)) {
  35027. return collection;
  35028. }
  35029. var collectionCopy = shallowCopy(collection);
  35030. if (Array.isArray(collectionCopy)) {
  35031. collectionCopy.splice(key, 1);
  35032. } else {
  35033. delete collectionCopy[key];
  35034. }
  35035. return collectionCopy;
  35036. }
  35037. function set(collection, key, value) {
  35038. if (!isDataStructure(collection)) {
  35039. throw new TypeError(
  35040. 'Cannot update non-data-structure value: ' + collection
  35041. );
  35042. }
  35043. if (isImmutable(collection)) {
  35044. if (!collection.set) {
  35045. throw new TypeError(
  35046. 'Cannot update immutable value without .set() method: ' + collection
  35047. );
  35048. }
  35049. return collection.set(key, value);
  35050. }
  35051. if (hasOwnProperty.call(collection, key) && value === collection[key]) {
  35052. return collection;
  35053. }
  35054. var collectionCopy = shallowCopy(collection);
  35055. collectionCopy[key] = value;
  35056. return collectionCopy;
  35057. }
  35058. function updateIn(collection, keyPath, notSetValue, updater) {
  35059. if (!updater) {
  35060. updater = notSetValue;
  35061. notSetValue = undefined;
  35062. }
  35063. var updatedValue = updateInDeeply(
  35064. isImmutable(collection),
  35065. collection,
  35066. coerceKeyPath(keyPath),
  35067. 0,
  35068. notSetValue,
  35069. updater
  35070. );
  35071. return updatedValue === NOT_SET ? notSetValue : updatedValue;
  35072. }
  35073. function updateInDeeply(
  35074. inImmutable,
  35075. existing,
  35076. keyPath,
  35077. i,
  35078. notSetValue,
  35079. updater
  35080. ) {
  35081. var wasNotSet = existing === NOT_SET;
  35082. if (i === keyPath.length) {
  35083. var existingValue = wasNotSet ? notSetValue : existing;
  35084. var newValue = updater(existingValue);
  35085. return newValue === existingValue ? existing : newValue;
  35086. }
  35087. if (!wasNotSet && !isDataStructure(existing)) {
  35088. throw new TypeError(
  35089. 'Cannot update within non-data-structure value in path [' +
  35090. keyPath.slice(0, i).map(quoteString) +
  35091. ']: ' +
  35092. existing
  35093. );
  35094. }
  35095. var key = keyPath[i];
  35096. var nextExisting = wasNotSet ? NOT_SET : get(existing, key, NOT_SET);
  35097. var nextUpdated = updateInDeeply(
  35098. nextExisting === NOT_SET ? inImmutable : isImmutable(nextExisting),
  35099. nextExisting,
  35100. keyPath,
  35101. i + 1,
  35102. notSetValue,
  35103. updater
  35104. );
  35105. return nextUpdated === nextExisting
  35106. ? existing
  35107. : nextUpdated === NOT_SET
  35108. ? remove(existing, key)
  35109. : set(
  35110. wasNotSet ? (inImmutable ? emptyMap() : {}) : existing,
  35111. key,
  35112. nextUpdated
  35113. );
  35114. }
  35115. function setIn(collection, keyPath, value) {
  35116. return updateIn(collection, keyPath, NOT_SET, function () { return value; });
  35117. }
  35118. function setIn$1(keyPath, v) {
  35119. return setIn(this, keyPath, v);
  35120. }
  35121. function removeIn(collection, keyPath) {
  35122. return updateIn(collection, keyPath, function () { return NOT_SET; });
  35123. }
  35124. function deleteIn(keyPath) {
  35125. return removeIn(this, keyPath);
  35126. }
  35127. function update(collection, key, notSetValue, updater) {
  35128. return updateIn(collection, [key], notSetValue, updater);
  35129. }
  35130. function update$1(key, notSetValue, updater) {
  35131. return arguments.length === 1
  35132. ? key(this)
  35133. : update(this, key, notSetValue, updater);
  35134. }
  35135. function updateIn$1(keyPath, notSetValue, updater) {
  35136. return updateIn(this, keyPath, notSetValue, updater);
  35137. }
  35138. function merge() {
  35139. var iters = [], len = arguments.length;
  35140. while ( len-- ) iters[ len ] = arguments[ len ];
  35141. return mergeIntoKeyedWith(this, iters);
  35142. }
  35143. function mergeWith(merger) {
  35144. var iters = [], len = arguments.length - 1;
  35145. while ( len-- > 0 ) iters[ len ] = arguments[ len + 1 ];
  35146. if (typeof merger !== 'function') {
  35147. throw new TypeError('Invalid merger function: ' + merger);
  35148. }
  35149. return mergeIntoKeyedWith(this, iters, merger);
  35150. }
  35151. function mergeIntoKeyedWith(collection, collections, merger) {
  35152. var iters = [];
  35153. for (var ii = 0; ii < collections.length; ii++) {
  35154. var collection$1 = KeyedCollection(collections[ii]);
  35155. if (collection$1.size !== 0) {
  35156. iters.push(collection$1);
  35157. }
  35158. }
  35159. if (iters.length === 0) {
  35160. return collection;
  35161. }
  35162. if (
  35163. collection.toSeq().size === 0 &&
  35164. !collection.__ownerID &&
  35165. iters.length === 1
  35166. ) {
  35167. return collection.constructor(iters[0]);
  35168. }
  35169. return collection.withMutations(function (collection) {
  35170. var mergeIntoCollection = merger
  35171. ? function (value, key) {
  35172. update(
  35173. collection,
  35174. key,
  35175. NOT_SET,
  35176. function (oldVal) { return (oldVal === NOT_SET ? value : merger(oldVal, value, key)); }
  35177. );
  35178. }
  35179. : function (value, key) {
  35180. collection.set(key, value);
  35181. };
  35182. for (var ii = 0; ii < iters.length; ii++) {
  35183. iters[ii].forEach(mergeIntoCollection);
  35184. }
  35185. });
  35186. }
  35187. function merge$1(collection) {
  35188. var sources = [], len = arguments.length - 1;
  35189. while ( len-- > 0 ) sources[ len ] = arguments[ len + 1 ];
  35190. return mergeWithSources(collection, sources);
  35191. }
  35192. function mergeWith$1(merger, collection) {
  35193. var sources = [], len = arguments.length - 2;
  35194. while ( len-- > 0 ) sources[ len ] = arguments[ len + 2 ];
  35195. return mergeWithSources(collection, sources, merger);
  35196. }
  35197. function mergeDeep(collection) {
  35198. var sources = [], len = arguments.length - 1;
  35199. while ( len-- > 0 ) sources[ len ] = arguments[ len + 1 ];
  35200. return mergeDeepWithSources(collection, sources);
  35201. }
  35202. function mergeDeepWith(merger, collection) {
  35203. var sources = [], len = arguments.length - 2;
  35204. while ( len-- > 0 ) sources[ len ] = arguments[ len + 2 ];
  35205. return mergeDeepWithSources(collection, sources, merger);
  35206. }
  35207. function mergeDeepWithSources(collection, sources, merger) {
  35208. return mergeWithSources(collection, sources, deepMergerWith(merger));
  35209. }
  35210. function mergeWithSources(collection, sources, merger) {
  35211. if (!isDataStructure(collection)) {
  35212. throw new TypeError(
  35213. 'Cannot merge into non-data-structure value: ' + collection
  35214. );
  35215. }
  35216. if (isImmutable(collection)) {
  35217. return typeof merger === 'function' && collection.mergeWith
  35218. ? collection.mergeWith.apply(collection, [ merger ].concat( sources ))
  35219. : collection.merge
  35220. ? collection.merge.apply(collection, sources)
  35221. : collection.concat.apply(collection, sources);
  35222. }
  35223. var isArray = Array.isArray(collection);
  35224. var merged = collection;
  35225. var Collection$$1 = isArray ? IndexedCollection : KeyedCollection;
  35226. var mergeItem = isArray
  35227. ? function (value) {
  35228. // Copy on write
  35229. if (merged === collection) {
  35230. merged = shallowCopy(merged);
  35231. }
  35232. merged.push(value);
  35233. }
  35234. : function (value, key) {
  35235. var hasVal = hasOwnProperty.call(merged, key);
  35236. var nextVal =
  35237. hasVal && merger ? merger(merged[key], value, key) : value;
  35238. if (!hasVal || nextVal !== merged[key]) {
  35239. // Copy on write
  35240. if (merged === collection) {
  35241. merged = shallowCopy(merged);
  35242. }
  35243. merged[key] = nextVal;
  35244. }
  35245. };
  35246. for (var i = 0; i < sources.length; i++) {
  35247. Collection$$1(sources[i]).forEach(mergeItem);
  35248. }
  35249. return merged;
  35250. }
  35251. function deepMergerWith(merger) {
  35252. function deepMerger(oldValue, newValue, key) {
  35253. return isDataStructure(oldValue) && isDataStructure(newValue)
  35254. ? mergeWithSources(oldValue, [newValue], deepMerger)
  35255. : merger
  35256. ? merger(oldValue, newValue, key)
  35257. : newValue;
  35258. }
  35259. return deepMerger;
  35260. }
  35261. function mergeDeep$1() {
  35262. var iters = [], len = arguments.length;
  35263. while ( len-- ) iters[ len ] = arguments[ len ];
  35264. return mergeDeepWithSources(this, iters);
  35265. }
  35266. function mergeDeepWith$1(merger) {
  35267. var iters = [], len = arguments.length - 1;
  35268. while ( len-- > 0 ) iters[ len ] = arguments[ len + 1 ];
  35269. return mergeDeepWithSources(this, iters, merger);
  35270. }
  35271. function mergeIn(keyPath) {
  35272. var iters = [], len = arguments.length - 1;
  35273. while ( len-- > 0 ) iters[ len ] = arguments[ len + 1 ];
  35274. return updateIn(this, keyPath, emptyMap(), function (m) { return mergeWithSources(m, iters); });
  35275. }
  35276. function mergeDeepIn(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 mergeDeepWithSources(m, iters); }
  35280. );
  35281. }
  35282. function withMutations(fn) {
  35283. var mutable = this.asMutable();
  35284. fn(mutable);
  35285. return mutable.wasAltered() ? mutable.__ensureOwner(this.__ownerID) : this;
  35286. }
  35287. function asMutable() {
  35288. return this.__ownerID ? this : this.__ensureOwner(new OwnerID());
  35289. }
  35290. function asImmutable() {
  35291. return this.__ensureOwner();
  35292. }
  35293. function wasAltered() {
  35294. return this.__altered;
  35295. }
  35296. var Map = /*@__PURE__*/(function (KeyedCollection$$1) {
  35297. function Map(value) {
  35298. return value === null || value === undefined
  35299. ? emptyMap()
  35300. : isMap(value) && !isOrdered(value)
  35301. ? value
  35302. : emptyMap().withMutations(function (map) {
  35303. var iter = KeyedCollection$$1(value);
  35304. assertNotInfinite(iter.size);
  35305. iter.forEach(function (v, k) { return map.set(k, v); });
  35306. });
  35307. }
  35308. if ( KeyedCollection$$1 ) Map.__proto__ = KeyedCollection$$1;
  35309. Map.prototype = Object.create( KeyedCollection$$1 && KeyedCollection$$1.prototype );
  35310. Map.prototype.constructor = Map;
  35311. Map.of = function of () {
  35312. var keyValues = [], len = arguments.length;
  35313. while ( len-- ) keyValues[ len ] = arguments[ len ];
  35314. return emptyMap().withMutations(function (map) {
  35315. for (var i = 0; i < keyValues.length; i += 2) {
  35316. if (i + 1 >= keyValues.length) {
  35317. throw new Error('Missing value for key: ' + keyValues[i]);
  35318. }
  35319. map.set(keyValues[i], keyValues[i + 1]);
  35320. }
  35321. });
  35322. };
  35323. Map.prototype.toString = function toString () {
  35324. return this.__toString('Map {', '}');
  35325. };
  35326. // @pragma Access
  35327. Map.prototype.get = function get (k, notSetValue) {
  35328. return this._root
  35329. ? this._root.get(0, undefined, k, notSetValue)
  35330. : notSetValue;
  35331. };
  35332. // @pragma Modification
  35333. Map.prototype.set = function set (k, v) {
  35334. return updateMap(this, k, v);
  35335. };
  35336. Map.prototype.remove = function remove (k) {
  35337. return updateMap(this, k, NOT_SET);
  35338. };
  35339. Map.prototype.deleteAll = function deleteAll (keys) {
  35340. var collection = Collection(keys);
  35341. if (collection.size === 0) {
  35342. return this;
  35343. }
  35344. return this.withMutations(function (map) {
  35345. collection.forEach(function (key) { return map.remove(key); });
  35346. });
  35347. };
  35348. Map.prototype.clear = function clear () {
  35349. if (this.size === 0) {
  35350. return this;
  35351. }
  35352. if (this.__ownerID) {
  35353. this.size = 0;
  35354. this._root = null;
  35355. this.__hash = undefined;
  35356. this.__altered = true;
  35357. return this;
  35358. }
  35359. return emptyMap();
  35360. };
  35361. // @pragma Composition
  35362. Map.prototype.sort = function sort (comparator) {
  35363. // Late binding
  35364. return OrderedMap(sortFactory(this, comparator));
  35365. };
  35366. Map.prototype.sortBy = function sortBy (mapper, comparator) {
  35367. // Late binding
  35368. return OrderedMap(sortFactory(this, comparator, mapper));
  35369. };
  35370. Map.prototype.map = function map (mapper, context) {
  35371. return this.withMutations(function (map) {
  35372. map.forEach(function (value, key) {
  35373. map.set(key, mapper.call(context, value, key, map));
  35374. });
  35375. });
  35376. };
  35377. // @pragma Mutability
  35378. Map.prototype.__iterator = function __iterator (type, reverse) {
  35379. return new MapIterator(this, type, reverse);
  35380. };
  35381. Map.prototype.__iterate = function __iterate (fn, reverse) {
  35382. var this$1 = this;
  35383. var iterations = 0;
  35384. this._root &&
  35385. this._root.iterate(function (entry) {
  35386. iterations++;
  35387. return fn(entry[1], entry[0], this$1);
  35388. }, reverse);
  35389. return iterations;
  35390. };
  35391. Map.prototype.__ensureOwner = function __ensureOwner (ownerID) {
  35392. if (ownerID === this.__ownerID) {
  35393. return this;
  35394. }
  35395. if (!ownerID) {
  35396. if (this.size === 0) {
  35397. return emptyMap();
  35398. }
  35399. this.__ownerID = ownerID;
  35400. this.__altered = false;
  35401. return this;
  35402. }
  35403. return makeMap(this.size, this._root, ownerID, this.__hash);
  35404. };
  35405. return Map;
  35406. }(KeyedCollection));
  35407. Map.isMap = isMap;
  35408. var MapPrototype = Map.prototype;
  35409. MapPrototype[IS_MAP_SYMBOL] = true;
  35410. MapPrototype[DELETE] = MapPrototype.remove;
  35411. MapPrototype.removeAll = MapPrototype.deleteAll;
  35412. MapPrototype.setIn = setIn$1;
  35413. MapPrototype.removeIn = MapPrototype.deleteIn = deleteIn;
  35414. MapPrototype.update = update$1;
  35415. MapPrototype.updateIn = updateIn$1;
  35416. MapPrototype.merge = MapPrototype.concat = merge;
  35417. MapPrototype.mergeWith = mergeWith;
  35418. MapPrototype.mergeDeep = mergeDeep$1;
  35419. MapPrototype.mergeDeepWith = mergeDeepWith$1;
  35420. MapPrototype.mergeIn = mergeIn;
  35421. MapPrototype.mergeDeepIn = mergeDeepIn;
  35422. MapPrototype.withMutations = withMutations;
  35423. MapPrototype.wasAltered = wasAltered;
  35424. MapPrototype.asImmutable = asImmutable;
  35425. MapPrototype['@@transducer/init'] = MapPrototype.asMutable = asMutable;
  35426. MapPrototype['@@transducer/step'] = function(result, arr) {
  35427. return result.set(arr[0], arr[1]);
  35428. };
  35429. MapPrototype['@@transducer/result'] = function(obj) {
  35430. return obj.asImmutable();
  35431. };
  35432. // #pragma Trie Nodes
  35433. var ArrayMapNode = function ArrayMapNode(ownerID, entries) {
  35434. this.ownerID = ownerID;
  35435. this.entries = entries;
  35436. };
  35437. ArrayMapNode.prototype.get = function get (shift, keyHash, key, notSetValue) {
  35438. var entries = this.entries;
  35439. for (var ii = 0, len = entries.length; ii < len; ii++) {
  35440. if (is(key, entries[ii][0])) {
  35441. return entries[ii][1];
  35442. }
  35443. }
  35444. return notSetValue;
  35445. };
  35446. ArrayMapNode.prototype.update = function update (ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  35447. var removed = value === NOT_SET;
  35448. var entries = this.entries;
  35449. var idx = 0;
  35450. var len = entries.length;
  35451. for (; idx < len; idx++) {
  35452. if (is(key, entries[idx][0])) {
  35453. break;
  35454. }
  35455. }
  35456. var exists = idx < len;
  35457. if (exists ? entries[idx][1] === value : removed) {
  35458. return this;
  35459. }
  35460. SetRef(didAlter);
  35461. (removed || !exists) && SetRef(didChangeSize);
  35462. if (removed && entries.length === 1) {
  35463. return; // undefined
  35464. }
  35465. if (!exists && !removed && entries.length >= MAX_ARRAY_MAP_SIZE) {
  35466. return createNodes(ownerID, entries, key, value);
  35467. }
  35468. var isEditable = ownerID && ownerID === this.ownerID;
  35469. var newEntries = isEditable ? entries : arrCopy(entries);
  35470. if (exists) {
  35471. if (removed) {
  35472. idx === len - 1
  35473. ? newEntries.pop()
  35474. : (newEntries[idx] = newEntries.pop());
  35475. } else {
  35476. newEntries[idx] = [key, value];
  35477. }
  35478. } else {
  35479. newEntries.push([key, value]);
  35480. }
  35481. if (isEditable) {
  35482. this.entries = newEntries;
  35483. return this;
  35484. }
  35485. return new ArrayMapNode(ownerID, newEntries);
  35486. };
  35487. var BitmapIndexedNode = function BitmapIndexedNode(ownerID, bitmap, nodes) {
  35488. this.ownerID = ownerID;
  35489. this.bitmap = bitmap;
  35490. this.nodes = nodes;
  35491. };
  35492. BitmapIndexedNode.prototype.get = function get (shift, keyHash, key, notSetValue) {
  35493. if (keyHash === undefined) {
  35494. keyHash = hash(key);
  35495. }
  35496. var bit = 1 << ((shift === 0 ? keyHash : keyHash >>> shift) & MASK);
  35497. var bitmap = this.bitmap;
  35498. return (bitmap & bit) === 0
  35499. ? notSetValue
  35500. : this.nodes[popCount(bitmap & (bit - 1))].get(
  35501. shift + SHIFT,
  35502. keyHash,
  35503. key,
  35504. notSetValue
  35505. );
  35506. };
  35507. BitmapIndexedNode.prototype.update = function update (ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  35508. if (keyHash === undefined) {
  35509. keyHash = hash(key);
  35510. }
  35511. var keyHashFrag = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  35512. var bit = 1 << keyHashFrag;
  35513. var bitmap = this.bitmap;
  35514. var exists = (bitmap & bit) !== 0;
  35515. if (!exists && value === NOT_SET) {
  35516. return this;
  35517. }
  35518. var idx = popCount(bitmap & (bit - 1));
  35519. var nodes = this.nodes;
  35520. var node = exists ? nodes[idx] : undefined;
  35521. var newNode = updateNode(
  35522. node,
  35523. ownerID,
  35524. shift + SHIFT,
  35525. keyHash,
  35526. key,
  35527. value,
  35528. didChangeSize,
  35529. didAlter
  35530. );
  35531. if (newNode === node) {
  35532. return this;
  35533. }
  35534. if (!exists && newNode && nodes.length >= MAX_BITMAP_INDEXED_SIZE) {
  35535. return expandNodes(ownerID, nodes, bitmap, keyHashFrag, newNode);
  35536. }
  35537. if (
  35538. exists &&
  35539. !newNode &&
  35540. nodes.length === 2 &&
  35541. isLeafNode(nodes[idx ^ 1])
  35542. ) {
  35543. return nodes[idx ^ 1];
  35544. }
  35545. if (exists && newNode && nodes.length === 1 && isLeafNode(newNode)) {
  35546. return newNode;
  35547. }
  35548. var isEditable = ownerID && ownerID === this.ownerID;
  35549. var newBitmap = exists ? (newNode ? bitmap : bitmap ^ bit) : bitmap | bit;
  35550. var newNodes = exists
  35551. ? newNode
  35552. ? setAt(nodes, idx, newNode, isEditable)
  35553. : spliceOut(nodes, idx, isEditable)
  35554. : spliceIn(nodes, idx, newNode, isEditable);
  35555. if (isEditable) {
  35556. this.bitmap = newBitmap;
  35557. this.nodes = newNodes;
  35558. return this;
  35559. }
  35560. return new BitmapIndexedNode(ownerID, newBitmap, newNodes);
  35561. };
  35562. var HashArrayMapNode = function HashArrayMapNode(ownerID, count, nodes) {
  35563. this.ownerID = ownerID;
  35564. this.count = count;
  35565. this.nodes = nodes;
  35566. };
  35567. HashArrayMapNode.prototype.get = function get (shift, keyHash, key, notSetValue) {
  35568. if (keyHash === undefined) {
  35569. keyHash = hash(key);
  35570. }
  35571. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  35572. var node = this.nodes[idx];
  35573. return node
  35574. ? node.get(shift + SHIFT, keyHash, key, notSetValue)
  35575. : notSetValue;
  35576. };
  35577. HashArrayMapNode.prototype.update = function update (ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  35578. if (keyHash === undefined) {
  35579. keyHash = hash(key);
  35580. }
  35581. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  35582. var removed = value === NOT_SET;
  35583. var nodes = this.nodes;
  35584. var node = nodes[idx];
  35585. if (removed && !node) {
  35586. return this;
  35587. }
  35588. var newNode = updateNode(
  35589. node,
  35590. ownerID,
  35591. shift + SHIFT,
  35592. keyHash,
  35593. key,
  35594. value,
  35595. didChangeSize,
  35596. didAlter
  35597. );
  35598. if (newNode === node) {
  35599. return this;
  35600. }
  35601. var newCount = this.count;
  35602. if (!node) {
  35603. newCount++;
  35604. } else if (!newNode) {
  35605. newCount--;
  35606. if (newCount < MIN_HASH_ARRAY_MAP_SIZE) {
  35607. return packNodes(ownerID, nodes, newCount, idx);
  35608. }
  35609. }
  35610. var isEditable = ownerID && ownerID === this.ownerID;
  35611. var newNodes = setAt(nodes, idx, newNode, isEditable);
  35612. if (isEditable) {
  35613. this.count = newCount;
  35614. this.nodes = newNodes;
  35615. return this;
  35616. }
  35617. return new HashArrayMapNode(ownerID, newCount, newNodes);
  35618. };
  35619. var HashCollisionNode = function HashCollisionNode(ownerID, keyHash, entries) {
  35620. this.ownerID = ownerID;
  35621. this.keyHash = keyHash;
  35622. this.entries = entries;
  35623. };
  35624. HashCollisionNode.prototype.get = function get (shift, keyHash, key, notSetValue) {
  35625. var entries = this.entries;
  35626. for (var ii = 0, len = entries.length; ii < len; ii++) {
  35627. if (is(key, entries[ii][0])) {
  35628. return entries[ii][1];
  35629. }
  35630. }
  35631. return notSetValue;
  35632. };
  35633. HashCollisionNode.prototype.update = function update (ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  35634. if (keyHash === undefined) {
  35635. keyHash = hash(key);
  35636. }
  35637. var removed = value === NOT_SET;
  35638. if (keyHash !== this.keyHash) {
  35639. if (removed) {
  35640. return this;
  35641. }
  35642. SetRef(didAlter);
  35643. SetRef(didChangeSize);
  35644. return mergeIntoNode(this, ownerID, shift, keyHash, [key, value]);
  35645. }
  35646. var entries = this.entries;
  35647. var idx = 0;
  35648. var len = entries.length;
  35649. for (; idx < len; idx++) {
  35650. if (is(key, entries[idx][0])) {
  35651. break;
  35652. }
  35653. }
  35654. var exists = idx < len;
  35655. if (exists ? entries[idx][1] === value : removed) {
  35656. return this;
  35657. }
  35658. SetRef(didAlter);
  35659. (removed || !exists) && SetRef(didChangeSize);
  35660. if (removed && len === 2) {
  35661. return new ValueNode(ownerID, this.keyHash, entries[idx ^ 1]);
  35662. }
  35663. var isEditable = ownerID && ownerID === this.ownerID;
  35664. var newEntries = isEditable ? entries : arrCopy(entries);
  35665. if (exists) {
  35666. if (removed) {
  35667. idx === len - 1
  35668. ? newEntries.pop()
  35669. : (newEntries[idx] = newEntries.pop());
  35670. } else {
  35671. newEntries[idx] = [key, value];
  35672. }
  35673. } else {
  35674. newEntries.push([key, value]);
  35675. }
  35676. if (isEditable) {
  35677. this.entries = newEntries;
  35678. return this;
  35679. }
  35680. return new HashCollisionNode(ownerID, this.keyHash, newEntries);
  35681. };
  35682. var ValueNode = function ValueNode(ownerID, keyHash, entry) {
  35683. this.ownerID = ownerID;
  35684. this.keyHash = keyHash;
  35685. this.entry = entry;
  35686. };
  35687. ValueNode.prototype.get = function get (shift, keyHash, key, notSetValue) {
  35688. return is(key, this.entry[0]) ? this.entry[1] : notSetValue;
  35689. };
  35690. ValueNode.prototype.update = function update (ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  35691. var removed = value === NOT_SET;
  35692. var keyMatch = is(key, this.entry[0]);
  35693. if (keyMatch ? value === this.entry[1] : removed) {
  35694. return this;
  35695. }
  35696. SetRef(didAlter);
  35697. if (removed) {
  35698. SetRef(didChangeSize);
  35699. return; // undefined
  35700. }
  35701. if (keyMatch) {
  35702. if (ownerID && ownerID === this.ownerID) {
  35703. this.entry[1] = value;
  35704. return this;
  35705. }
  35706. return new ValueNode(ownerID, this.keyHash, [key, value]);
  35707. }
  35708. SetRef(didChangeSize);
  35709. return mergeIntoNode(this, ownerID, shift, hash(key), [key, value]);
  35710. };
  35711. // #pragma Iterators
  35712. ArrayMapNode.prototype.iterate = HashCollisionNode.prototype.iterate = function(
  35713. fn,
  35714. reverse
  35715. ) {
  35716. var entries = this.entries;
  35717. for (var ii = 0, maxIndex = entries.length - 1; ii <= maxIndex; ii++) {
  35718. if (fn(entries[reverse ? maxIndex - ii : ii]) === false) {
  35719. return false;
  35720. }
  35721. }
  35722. };
  35723. BitmapIndexedNode.prototype.iterate = HashArrayMapNode.prototype.iterate = function(
  35724. fn,
  35725. reverse
  35726. ) {
  35727. var nodes = this.nodes;
  35728. for (var ii = 0, maxIndex = nodes.length - 1; ii <= maxIndex; ii++) {
  35729. var node = nodes[reverse ? maxIndex - ii : ii];
  35730. if (node && node.iterate(fn, reverse) === false) {
  35731. return false;
  35732. }
  35733. }
  35734. };
  35735. // eslint-disable-next-line no-unused-vars
  35736. ValueNode.prototype.iterate = function(fn, reverse) {
  35737. return fn(this.entry);
  35738. };
  35739. var MapIterator = /*@__PURE__*/(function (Iterator$$1) {
  35740. function MapIterator(map, type, reverse) {
  35741. this._type = type;
  35742. this._reverse = reverse;
  35743. this._stack = map._root && mapIteratorFrame(map._root);
  35744. }
  35745. if ( Iterator$$1 ) MapIterator.__proto__ = Iterator$$1;
  35746. MapIterator.prototype = Object.create( Iterator$$1 && Iterator$$1.prototype );
  35747. MapIterator.prototype.constructor = MapIterator;
  35748. MapIterator.prototype.next = function next () {
  35749. var type = this._type;
  35750. var stack = this._stack;
  35751. while (stack) {
  35752. var node = stack.node;
  35753. var index = stack.index++;
  35754. var maxIndex = (void 0);
  35755. if (node.entry) {
  35756. if (index === 0) {
  35757. return mapIteratorValue(type, node.entry);
  35758. }
  35759. } else if (node.entries) {
  35760. maxIndex = node.entries.length - 1;
  35761. if (index <= maxIndex) {
  35762. return mapIteratorValue(
  35763. type,
  35764. node.entries[this._reverse ? maxIndex - index : index]
  35765. );
  35766. }
  35767. } else {
  35768. maxIndex = node.nodes.length - 1;
  35769. if (index <= maxIndex) {
  35770. var subNode = node.nodes[this._reverse ? maxIndex - index : index];
  35771. if (subNode) {
  35772. if (subNode.entry) {
  35773. return mapIteratorValue(type, subNode.entry);
  35774. }
  35775. stack = this._stack = mapIteratorFrame(subNode, stack);
  35776. }
  35777. continue;
  35778. }
  35779. }
  35780. stack = this._stack = this._stack.__prev;
  35781. }
  35782. return iteratorDone();
  35783. };
  35784. return MapIterator;
  35785. }(Iterator));
  35786. function mapIteratorValue(type, entry) {
  35787. return iteratorValue(type, entry[0], entry[1]);
  35788. }
  35789. function mapIteratorFrame(node, prev) {
  35790. return {
  35791. node: node,
  35792. index: 0,
  35793. __prev: prev,
  35794. };
  35795. }
  35796. function makeMap(size, root, ownerID, hash$$1) {
  35797. var map = Object.create(MapPrototype);
  35798. map.size = size;
  35799. map._root = root;
  35800. map.__ownerID = ownerID;
  35801. map.__hash = hash$$1;
  35802. map.__altered = false;
  35803. return map;
  35804. }
  35805. var EMPTY_MAP;
  35806. function emptyMap() {
  35807. return EMPTY_MAP || (EMPTY_MAP = makeMap(0));
  35808. }
  35809. function updateMap(map, k, v) {
  35810. var newRoot;
  35811. var newSize;
  35812. if (!map._root) {
  35813. if (v === NOT_SET) {
  35814. return map;
  35815. }
  35816. newSize = 1;
  35817. newRoot = new ArrayMapNode(map.__ownerID, [[k, v]]);
  35818. } else {
  35819. var didChangeSize = MakeRef();
  35820. var didAlter = MakeRef();
  35821. newRoot = updateNode(
  35822. map._root,
  35823. map.__ownerID,
  35824. 0,
  35825. undefined,
  35826. k,
  35827. v,
  35828. didChangeSize,
  35829. didAlter
  35830. );
  35831. if (!didAlter.value) {
  35832. return map;
  35833. }
  35834. newSize = map.size + (didChangeSize.value ? (v === NOT_SET ? -1 : 1) : 0);
  35835. }
  35836. if (map.__ownerID) {
  35837. map.size = newSize;
  35838. map._root = newRoot;
  35839. map.__hash = undefined;
  35840. map.__altered = true;
  35841. return map;
  35842. }
  35843. return newRoot ? makeMap(newSize, newRoot) : emptyMap();
  35844. }
  35845. function updateNode(
  35846. node,
  35847. ownerID,
  35848. shift,
  35849. keyHash,
  35850. key,
  35851. value,
  35852. didChangeSize,
  35853. didAlter
  35854. ) {
  35855. if (!node) {
  35856. if (value === NOT_SET) {
  35857. return node;
  35858. }
  35859. SetRef(didAlter);
  35860. SetRef(didChangeSize);
  35861. return new ValueNode(ownerID, keyHash, [key, value]);
  35862. }
  35863. return node.update(
  35864. ownerID,
  35865. shift,
  35866. keyHash,
  35867. key,
  35868. value,
  35869. didChangeSize,
  35870. didAlter
  35871. );
  35872. }
  35873. function isLeafNode(node) {
  35874. return (
  35875. node.constructor === ValueNode || node.constructor === HashCollisionNode
  35876. );
  35877. }
  35878. function mergeIntoNode(node, ownerID, shift, keyHash, entry) {
  35879. if (node.keyHash === keyHash) {
  35880. return new HashCollisionNode(ownerID, keyHash, [node.entry, entry]);
  35881. }
  35882. var idx1 = (shift === 0 ? node.keyHash : node.keyHash >>> shift) & MASK;
  35883. var idx2 = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  35884. var newNode;
  35885. var nodes =
  35886. idx1 === idx2
  35887. ? [mergeIntoNode(node, ownerID, shift + SHIFT, keyHash, entry)]
  35888. : ((newNode = new ValueNode(ownerID, keyHash, entry)),
  35889. idx1 < idx2 ? [node, newNode] : [newNode, node]);
  35890. return new BitmapIndexedNode(ownerID, (1 << idx1) | (1 << idx2), nodes);
  35891. }
  35892. function createNodes(ownerID, entries, key, value) {
  35893. if (!ownerID) {
  35894. ownerID = new OwnerID();
  35895. }
  35896. var node = new ValueNode(ownerID, hash(key), [key, value]);
  35897. for (var ii = 0; ii < entries.length; ii++) {
  35898. var entry = entries[ii];
  35899. node = node.update(ownerID, 0, undefined, entry[0], entry[1]);
  35900. }
  35901. return node;
  35902. }
  35903. function packNodes(ownerID, nodes, count, excluding) {
  35904. var bitmap = 0;
  35905. var packedII = 0;
  35906. var packedNodes = new Array(count);
  35907. for (var ii = 0, bit = 1, len = nodes.length; ii < len; ii++, bit <<= 1) {
  35908. var node = nodes[ii];
  35909. if (node !== undefined && ii !== excluding) {
  35910. bitmap |= bit;
  35911. packedNodes[packedII++] = node;
  35912. }
  35913. }
  35914. return new BitmapIndexedNode(ownerID, bitmap, packedNodes);
  35915. }
  35916. function expandNodes(ownerID, nodes, bitmap, including, node) {
  35917. var count = 0;
  35918. var expandedNodes = new Array(SIZE);
  35919. for (var ii = 0; bitmap !== 0; ii++, bitmap >>>= 1) {
  35920. expandedNodes[ii] = bitmap & 1 ? nodes[count++] : undefined;
  35921. }
  35922. expandedNodes[including] = node;
  35923. return new HashArrayMapNode(ownerID, count + 1, expandedNodes);
  35924. }
  35925. function popCount(x) {
  35926. x -= (x >> 1) & 0x55555555;
  35927. x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
  35928. x = (x + (x >> 4)) & 0x0f0f0f0f;
  35929. x += x >> 8;
  35930. x += x >> 16;
  35931. return x & 0x7f;
  35932. }
  35933. function setAt(array, idx, val, canEdit) {
  35934. var newArray = canEdit ? array : arrCopy(array);
  35935. newArray[idx] = val;
  35936. return newArray;
  35937. }
  35938. function spliceIn(array, idx, val, canEdit) {
  35939. var newLen = array.length + 1;
  35940. if (canEdit && idx + 1 === newLen) {
  35941. array[idx] = val;
  35942. return array;
  35943. }
  35944. var newArray = new Array(newLen);
  35945. var after = 0;
  35946. for (var ii = 0; ii < newLen; ii++) {
  35947. if (ii === idx) {
  35948. newArray[ii] = val;
  35949. after = -1;
  35950. } else {
  35951. newArray[ii] = array[ii + after];
  35952. }
  35953. }
  35954. return newArray;
  35955. }
  35956. function spliceOut(array, idx, canEdit) {
  35957. var newLen = array.length - 1;
  35958. if (canEdit && idx === newLen) {
  35959. array.pop();
  35960. return array;
  35961. }
  35962. var newArray = new Array(newLen);
  35963. var after = 0;
  35964. for (var ii = 0; ii < newLen; ii++) {
  35965. if (ii === idx) {
  35966. after = 1;
  35967. }
  35968. newArray[ii] = array[ii + after];
  35969. }
  35970. return newArray;
  35971. }
  35972. var MAX_ARRAY_MAP_SIZE = SIZE / 4;
  35973. var MAX_BITMAP_INDEXED_SIZE = SIZE / 2;
  35974. var MIN_HASH_ARRAY_MAP_SIZE = SIZE / 4;
  35975. var IS_LIST_SYMBOL = '@@__IMMUTABLE_LIST__@@';
  35976. function isList(maybeList) {
  35977. return Boolean(maybeList && maybeList[IS_LIST_SYMBOL]);
  35978. }
  35979. var List = /*@__PURE__*/(function (IndexedCollection$$1) {
  35980. function List(value) {
  35981. var empty = emptyList();
  35982. if (value === null || value === undefined) {
  35983. return empty;
  35984. }
  35985. if (isList(value)) {
  35986. return value;
  35987. }
  35988. var iter = IndexedCollection$$1(value);
  35989. var size = iter.size;
  35990. if (size === 0) {
  35991. return empty;
  35992. }
  35993. assertNotInfinite(size);
  35994. if (size > 0 && size < SIZE) {
  35995. return makeList(0, size, SHIFT, null, new VNode(iter.toArray()));
  35996. }
  35997. return empty.withMutations(function (list) {
  35998. list.setSize(size);
  35999. iter.forEach(function (v, i) { return list.set(i, v); });
  36000. });
  36001. }
  36002. if ( IndexedCollection$$1 ) List.__proto__ = IndexedCollection$$1;
  36003. List.prototype = Object.create( IndexedCollection$$1 && IndexedCollection$$1.prototype );
  36004. List.prototype.constructor = List;
  36005. List.of = function of (/*...values*/) {
  36006. return this(arguments);
  36007. };
  36008. List.prototype.toString = function toString () {
  36009. return this.__toString('List [', ']');
  36010. };
  36011. // @pragma Access
  36012. List.prototype.get = function get (index, notSetValue) {
  36013. index = wrapIndex(this, index);
  36014. if (index >= 0 && index < this.size) {
  36015. index += this._origin;
  36016. var node = listNodeFor(this, index);
  36017. return node && node.array[index & MASK];
  36018. }
  36019. return notSetValue;
  36020. };
  36021. // @pragma Modification
  36022. List.prototype.set = function set (index, value) {
  36023. return updateList(this, index, value);
  36024. };
  36025. List.prototype.remove = function remove (index) {
  36026. return !this.has(index)
  36027. ? this
  36028. : index === 0
  36029. ? this.shift()
  36030. : index === this.size - 1
  36031. ? this.pop()
  36032. : this.splice(index, 1);
  36033. };
  36034. List.prototype.insert = function insert (index, value) {
  36035. return this.splice(index, 0, value);
  36036. };
  36037. List.prototype.clear = function clear () {
  36038. if (this.size === 0) {
  36039. return this;
  36040. }
  36041. if (this.__ownerID) {
  36042. this.size = this._origin = this._capacity = 0;
  36043. this._level = SHIFT;
  36044. this._root = this._tail = null;
  36045. this.__hash = undefined;
  36046. this.__altered = true;
  36047. return this;
  36048. }
  36049. return emptyList();
  36050. };
  36051. List.prototype.push = function push (/*...values*/) {
  36052. var values = arguments;
  36053. var oldSize = this.size;
  36054. return this.withMutations(function (list) {
  36055. setListBounds(list, 0, oldSize + values.length);
  36056. for (var ii = 0; ii < values.length; ii++) {
  36057. list.set(oldSize + ii, values[ii]);
  36058. }
  36059. });
  36060. };
  36061. List.prototype.pop = function pop () {
  36062. return setListBounds(this, 0, -1);
  36063. };
  36064. List.prototype.unshift = function unshift (/*...values*/) {
  36065. var values = arguments;
  36066. return this.withMutations(function (list) {
  36067. setListBounds(list, -values.length);
  36068. for (var ii = 0; ii < values.length; ii++) {
  36069. list.set(ii, values[ii]);
  36070. }
  36071. });
  36072. };
  36073. List.prototype.shift = function shift () {
  36074. return setListBounds(this, 1);
  36075. };
  36076. // @pragma Composition
  36077. List.prototype.concat = function concat (/*...collections*/) {
  36078. var arguments$1 = arguments;
  36079. var seqs = [];
  36080. for (var i = 0; i < arguments.length; i++) {
  36081. var argument = arguments$1[i];
  36082. var seq = IndexedCollection$$1(
  36083. typeof argument !== 'string' && hasIterator(argument)
  36084. ? argument
  36085. : [argument]
  36086. );
  36087. if (seq.size !== 0) {
  36088. seqs.push(seq);
  36089. }
  36090. }
  36091. if (seqs.length === 0) {
  36092. return this;
  36093. }
  36094. if (this.size === 0 && !this.__ownerID && seqs.length === 1) {
  36095. return this.constructor(seqs[0]);
  36096. }
  36097. return this.withMutations(function (list) {
  36098. seqs.forEach(function (seq) { return seq.forEach(function (value) { return list.push(value); }); });
  36099. });
  36100. };
  36101. List.prototype.setSize = function setSize (size) {
  36102. return setListBounds(this, 0, size);
  36103. };
  36104. List.prototype.map = function map (mapper, context) {
  36105. var this$1 = this;
  36106. return this.withMutations(function (list) {
  36107. for (var i = 0; i < this$1.size; i++) {
  36108. list.set(i, mapper.call(context, list.get(i), i, list));
  36109. }
  36110. });
  36111. };
  36112. // @pragma Iteration
  36113. List.prototype.slice = function slice (begin, end) {
  36114. var size = this.size;
  36115. if (wholeSlice(begin, end, size)) {
  36116. return this;
  36117. }
  36118. return setListBounds(
  36119. this,
  36120. resolveBegin(begin, size),
  36121. resolveEnd(end, size)
  36122. );
  36123. };
  36124. List.prototype.__iterator = function __iterator (type, reverse) {
  36125. var index = reverse ? this.size : 0;
  36126. var values = iterateList(this, reverse);
  36127. return new Iterator(function () {
  36128. var value = values();
  36129. return value === DONE
  36130. ? iteratorDone()
  36131. : iteratorValue(type, reverse ? --index : index++, value);
  36132. });
  36133. };
  36134. List.prototype.__iterate = function __iterate (fn, reverse) {
  36135. var index = reverse ? this.size : 0;
  36136. var values = iterateList(this, reverse);
  36137. var value;
  36138. while ((value = values()) !== DONE) {
  36139. if (fn(value, reverse ? --index : index++, this) === false) {
  36140. break;
  36141. }
  36142. }
  36143. return index;
  36144. };
  36145. List.prototype.__ensureOwner = function __ensureOwner (ownerID) {
  36146. if (ownerID === this.__ownerID) {
  36147. return this;
  36148. }
  36149. if (!ownerID) {
  36150. if (this.size === 0) {
  36151. return emptyList();
  36152. }
  36153. this.__ownerID = ownerID;
  36154. this.__altered = false;
  36155. return this;
  36156. }
  36157. return makeList(
  36158. this._origin,
  36159. this._capacity,
  36160. this._level,
  36161. this._root,
  36162. this._tail,
  36163. ownerID,
  36164. this.__hash
  36165. );
  36166. };
  36167. return List;
  36168. }(IndexedCollection));
  36169. List.isList = isList;
  36170. var ListPrototype = List.prototype;
  36171. ListPrototype[IS_LIST_SYMBOL] = true;
  36172. ListPrototype[DELETE] = ListPrototype.remove;
  36173. ListPrototype.merge = ListPrototype.concat;
  36174. ListPrototype.setIn = setIn$1;
  36175. ListPrototype.deleteIn = ListPrototype.removeIn = deleteIn;
  36176. ListPrototype.update = update$1;
  36177. ListPrototype.updateIn = updateIn$1;
  36178. ListPrototype.mergeIn = mergeIn;
  36179. ListPrototype.mergeDeepIn = mergeDeepIn;
  36180. ListPrototype.withMutations = withMutations;
  36181. ListPrototype.wasAltered = wasAltered;
  36182. ListPrototype.asImmutable = asImmutable;
  36183. ListPrototype['@@transducer/init'] = ListPrototype.asMutable = asMutable;
  36184. ListPrototype['@@transducer/step'] = function(result, arr) {
  36185. return result.push(arr);
  36186. };
  36187. ListPrototype['@@transducer/result'] = function(obj) {
  36188. return obj.asImmutable();
  36189. };
  36190. var VNode = function VNode(array, ownerID) {
  36191. this.array = array;
  36192. this.ownerID = ownerID;
  36193. };
  36194. // TODO: seems like these methods are very similar
  36195. VNode.prototype.removeBefore = function removeBefore (ownerID, level, index) {
  36196. if (index === level ? 1 << level : this.array.length === 0) {
  36197. return this;
  36198. }
  36199. var originIndex = (index >>> level) & MASK;
  36200. if (originIndex >= this.array.length) {
  36201. return new VNode([], ownerID);
  36202. }
  36203. var removingFirst = originIndex === 0;
  36204. var newChild;
  36205. if (level > 0) {
  36206. var oldChild = this.array[originIndex];
  36207. newChild =
  36208. oldChild && oldChild.removeBefore(ownerID, level - SHIFT, index);
  36209. if (newChild === oldChild && removingFirst) {
  36210. return this;
  36211. }
  36212. }
  36213. if (removingFirst && !newChild) {
  36214. return this;
  36215. }
  36216. var editable = editableVNode(this, ownerID);
  36217. if (!removingFirst) {
  36218. for (var ii = 0; ii < originIndex; ii++) {
  36219. editable.array[ii] = undefined;
  36220. }
  36221. }
  36222. if (newChild) {
  36223. editable.array[originIndex] = newChild;
  36224. }
  36225. return editable;
  36226. };
  36227. VNode.prototype.removeAfter = function removeAfter (ownerID, level, index) {
  36228. if (index === (level ? 1 << level : 0) || this.array.length === 0) {
  36229. return this;
  36230. }
  36231. var sizeIndex = ((index - 1) >>> level) & MASK;
  36232. if (sizeIndex >= this.array.length) {
  36233. return this;
  36234. }
  36235. var newChild;
  36236. if (level > 0) {
  36237. var oldChild = this.array[sizeIndex];
  36238. newChild =
  36239. oldChild && oldChild.removeAfter(ownerID, level - SHIFT, index);
  36240. if (newChild === oldChild && sizeIndex === this.array.length - 1) {
  36241. return this;
  36242. }
  36243. }
  36244. var editable = editableVNode(this, ownerID);
  36245. editable.array.splice(sizeIndex + 1);
  36246. if (newChild) {
  36247. editable.array[sizeIndex] = newChild;
  36248. }
  36249. return editable;
  36250. };
  36251. var DONE = {};
  36252. function iterateList(list, reverse) {
  36253. var left = list._origin;
  36254. var right = list._capacity;
  36255. var tailPos = getTailOffset(right);
  36256. var tail = list._tail;
  36257. return iterateNodeOrLeaf(list._root, list._level, 0);
  36258. function iterateNodeOrLeaf(node, level, offset) {
  36259. return level === 0
  36260. ? iterateLeaf(node, offset)
  36261. : iterateNode(node, level, offset);
  36262. }
  36263. function iterateLeaf(node, offset) {
  36264. var array = offset === tailPos ? tail && tail.array : node && node.array;
  36265. var from = offset > left ? 0 : left - offset;
  36266. var to = right - offset;
  36267. if (to > SIZE) {
  36268. to = SIZE;
  36269. }
  36270. return function () {
  36271. if (from === to) {
  36272. return DONE;
  36273. }
  36274. var idx = reverse ? --to : from++;
  36275. return array && array[idx];
  36276. };
  36277. }
  36278. function iterateNode(node, level, offset) {
  36279. var values;
  36280. var array = node && node.array;
  36281. var from = offset > left ? 0 : (left - offset) >> level;
  36282. var to = ((right - offset) >> level) + 1;
  36283. if (to > SIZE) {
  36284. to = SIZE;
  36285. }
  36286. return function () {
  36287. while (true) {
  36288. if (values) {
  36289. var value = values();
  36290. if (value !== DONE) {
  36291. return value;
  36292. }
  36293. values = null;
  36294. }
  36295. if (from === to) {
  36296. return DONE;
  36297. }
  36298. var idx = reverse ? --to : from++;
  36299. values = iterateNodeOrLeaf(
  36300. array && array[idx],
  36301. level - SHIFT,
  36302. offset + (idx << level)
  36303. );
  36304. }
  36305. };
  36306. }
  36307. }
  36308. function makeList(origin, capacity, level, root, tail, ownerID, hash) {
  36309. var list = Object.create(ListPrototype);
  36310. list.size = capacity - origin;
  36311. list._origin = origin;
  36312. list._capacity = capacity;
  36313. list._level = level;
  36314. list._root = root;
  36315. list._tail = tail;
  36316. list.__ownerID = ownerID;
  36317. list.__hash = hash;
  36318. list.__altered = false;
  36319. return list;
  36320. }
  36321. var EMPTY_LIST;
  36322. function emptyList() {
  36323. return EMPTY_LIST || (EMPTY_LIST = makeList(0, 0, SHIFT));
  36324. }
  36325. function updateList(list, index, value) {
  36326. index = wrapIndex(list, index);
  36327. if (index !== index) {
  36328. return list;
  36329. }
  36330. if (index >= list.size || index < 0) {
  36331. return list.withMutations(function (list) {
  36332. index < 0
  36333. ? setListBounds(list, index).set(0, value)
  36334. : setListBounds(list, 0, index + 1).set(index, value);
  36335. });
  36336. }
  36337. index += list._origin;
  36338. var newTail = list._tail;
  36339. var newRoot = list._root;
  36340. var didAlter = MakeRef();
  36341. if (index >= getTailOffset(list._capacity)) {
  36342. newTail = updateVNode(newTail, list.__ownerID, 0, index, value, didAlter);
  36343. } else {
  36344. newRoot = updateVNode(
  36345. newRoot,
  36346. list.__ownerID,
  36347. list._level,
  36348. index,
  36349. value,
  36350. didAlter
  36351. );
  36352. }
  36353. if (!didAlter.value) {
  36354. return list;
  36355. }
  36356. if (list.__ownerID) {
  36357. list._root = newRoot;
  36358. list._tail = newTail;
  36359. list.__hash = undefined;
  36360. list.__altered = true;
  36361. return list;
  36362. }
  36363. return makeList(list._origin, list._capacity, list._level, newRoot, newTail);
  36364. }
  36365. function updateVNode(node, ownerID, level, index, value, didAlter) {
  36366. var idx = (index >>> level) & MASK;
  36367. var nodeHas = node && idx < node.array.length;
  36368. if (!nodeHas && value === undefined) {
  36369. return node;
  36370. }
  36371. var newNode;
  36372. if (level > 0) {
  36373. var lowerNode = node && node.array[idx];
  36374. var newLowerNode = updateVNode(
  36375. lowerNode,
  36376. ownerID,
  36377. level - SHIFT,
  36378. index,
  36379. value,
  36380. didAlter
  36381. );
  36382. if (newLowerNode === lowerNode) {
  36383. return node;
  36384. }
  36385. newNode = editableVNode(node, ownerID);
  36386. newNode.array[idx] = newLowerNode;
  36387. return newNode;
  36388. }
  36389. if (nodeHas && node.array[idx] === value) {
  36390. return node;
  36391. }
  36392. if (didAlter) {
  36393. SetRef(didAlter);
  36394. }
  36395. newNode = editableVNode(node, ownerID);
  36396. if (value === undefined && idx === newNode.array.length - 1) {
  36397. newNode.array.pop();
  36398. } else {
  36399. newNode.array[idx] = value;
  36400. }
  36401. return newNode;
  36402. }
  36403. function editableVNode(node, ownerID) {
  36404. if (ownerID && node && ownerID === node.ownerID) {
  36405. return node;
  36406. }
  36407. return new VNode(node ? node.array.slice() : [], ownerID);
  36408. }
  36409. function listNodeFor(list, rawIndex) {
  36410. if (rawIndex >= getTailOffset(list._capacity)) {
  36411. return list._tail;
  36412. }
  36413. if (rawIndex < 1 << (list._level + SHIFT)) {
  36414. var node = list._root;
  36415. var level = list._level;
  36416. while (node && level > 0) {
  36417. node = node.array[(rawIndex >>> level) & MASK];
  36418. level -= SHIFT;
  36419. }
  36420. return node;
  36421. }
  36422. }
  36423. function setListBounds(list, begin, end) {
  36424. // Sanitize begin & end using this shorthand for ToInt32(argument)
  36425. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  36426. if (begin !== undefined) {
  36427. begin |= 0;
  36428. }
  36429. if (end !== undefined) {
  36430. end |= 0;
  36431. }
  36432. var owner = list.__ownerID || new OwnerID();
  36433. var oldOrigin = list._origin;
  36434. var oldCapacity = list._capacity;
  36435. var newOrigin = oldOrigin + begin;
  36436. var newCapacity =
  36437. end === undefined
  36438. ? oldCapacity
  36439. : end < 0
  36440. ? oldCapacity + end
  36441. : oldOrigin + end;
  36442. if (newOrigin === oldOrigin && newCapacity === oldCapacity) {
  36443. return list;
  36444. }
  36445. // If it's going to end after it starts, it's empty.
  36446. if (newOrigin >= newCapacity) {
  36447. return list.clear();
  36448. }
  36449. var newLevel = list._level;
  36450. var newRoot = list._root;
  36451. // New origin might need creating a higher root.
  36452. var offsetShift = 0;
  36453. while (newOrigin + offsetShift < 0) {
  36454. newRoot = new VNode(
  36455. newRoot && newRoot.array.length ? [undefined, newRoot] : [],
  36456. owner
  36457. );
  36458. newLevel += SHIFT;
  36459. offsetShift += 1 << newLevel;
  36460. }
  36461. if (offsetShift) {
  36462. newOrigin += offsetShift;
  36463. oldOrigin += offsetShift;
  36464. newCapacity += offsetShift;
  36465. oldCapacity += offsetShift;
  36466. }
  36467. var oldTailOffset = getTailOffset(oldCapacity);
  36468. var newTailOffset = getTailOffset(newCapacity);
  36469. // New size might need creating a higher root.
  36470. while (newTailOffset >= 1 << (newLevel + SHIFT)) {
  36471. newRoot = new VNode(
  36472. newRoot && newRoot.array.length ? [newRoot] : [],
  36473. owner
  36474. );
  36475. newLevel += SHIFT;
  36476. }
  36477. // Locate or create the new tail.
  36478. var oldTail = list._tail;
  36479. var newTail =
  36480. newTailOffset < oldTailOffset
  36481. ? listNodeFor(list, newCapacity - 1)
  36482. : newTailOffset > oldTailOffset
  36483. ? new VNode([], owner)
  36484. : oldTail;
  36485. // Merge Tail into tree.
  36486. if (
  36487. oldTail &&
  36488. newTailOffset > oldTailOffset &&
  36489. newOrigin < oldCapacity &&
  36490. oldTail.array.length
  36491. ) {
  36492. newRoot = editableVNode(newRoot, owner);
  36493. var node = newRoot;
  36494. for (var level = newLevel; level > SHIFT; level -= SHIFT) {
  36495. var idx = (oldTailOffset >>> level) & MASK;
  36496. node = node.array[idx] = editableVNode(node.array[idx], owner);
  36497. }
  36498. node.array[(oldTailOffset >>> SHIFT) & MASK] = oldTail;
  36499. }
  36500. // If the size has been reduced, there's a chance the tail needs to be trimmed.
  36501. if (newCapacity < oldCapacity) {
  36502. newTail = newTail && newTail.removeAfter(owner, 0, newCapacity);
  36503. }
  36504. // If the new origin is within the tail, then we do not need a root.
  36505. if (newOrigin >= newTailOffset) {
  36506. newOrigin -= newTailOffset;
  36507. newCapacity -= newTailOffset;
  36508. newLevel = SHIFT;
  36509. newRoot = null;
  36510. newTail = newTail && newTail.removeBefore(owner, 0, newOrigin);
  36511. // Otherwise, if the root has been trimmed, garbage collect.
  36512. } else if (newOrigin > oldOrigin || newTailOffset < oldTailOffset) {
  36513. offsetShift = 0;
  36514. // Identify the new top root node of the subtree of the old root.
  36515. while (newRoot) {
  36516. var beginIndex = (newOrigin >>> newLevel) & MASK;
  36517. if ((beginIndex !== newTailOffset >>> newLevel) & MASK) {
  36518. break;
  36519. }
  36520. if (beginIndex) {
  36521. offsetShift += (1 << newLevel) * beginIndex;
  36522. }
  36523. newLevel -= SHIFT;
  36524. newRoot = newRoot.array[beginIndex];
  36525. }
  36526. // Trim the new sides of the new root.
  36527. if (newRoot && newOrigin > oldOrigin) {
  36528. newRoot = newRoot.removeBefore(owner, newLevel, newOrigin - offsetShift);
  36529. }
  36530. if (newRoot && newTailOffset < oldTailOffset) {
  36531. newRoot = newRoot.removeAfter(
  36532. owner,
  36533. newLevel,
  36534. newTailOffset - offsetShift
  36535. );
  36536. }
  36537. if (offsetShift) {
  36538. newOrigin -= offsetShift;
  36539. newCapacity -= offsetShift;
  36540. }
  36541. }
  36542. if (list.__ownerID) {
  36543. list.size = newCapacity - newOrigin;
  36544. list._origin = newOrigin;
  36545. list._capacity = newCapacity;
  36546. list._level = newLevel;
  36547. list._root = newRoot;
  36548. list._tail = newTail;
  36549. list.__hash = undefined;
  36550. list.__altered = true;
  36551. return list;
  36552. }
  36553. return makeList(newOrigin, newCapacity, newLevel, newRoot, newTail);
  36554. }
  36555. function getTailOffset(size) {
  36556. return size < SIZE ? 0 : ((size - 1) >>> SHIFT) << SHIFT;
  36557. }
  36558. var OrderedMap = /*@__PURE__*/(function (Map$$1) {
  36559. function OrderedMap(value) {
  36560. return value === null || value === undefined
  36561. ? emptyOrderedMap()
  36562. : isOrderedMap(value)
  36563. ? value
  36564. : emptyOrderedMap().withMutations(function (map) {
  36565. var iter = KeyedCollection(value);
  36566. assertNotInfinite(iter.size);
  36567. iter.forEach(function (v, k) { return map.set(k, v); });
  36568. });
  36569. }
  36570. if ( Map$$1 ) OrderedMap.__proto__ = Map$$1;
  36571. OrderedMap.prototype = Object.create( Map$$1 && Map$$1.prototype );
  36572. OrderedMap.prototype.constructor = OrderedMap;
  36573. OrderedMap.of = function of (/*...values*/) {
  36574. return this(arguments);
  36575. };
  36576. OrderedMap.prototype.toString = function toString () {
  36577. return this.__toString('OrderedMap {', '}');
  36578. };
  36579. // @pragma Access
  36580. OrderedMap.prototype.get = function get (k, notSetValue) {
  36581. var index = this._map.get(k);
  36582. return index !== undefined ? this._list.get(index)[1] : notSetValue;
  36583. };
  36584. // @pragma Modification
  36585. OrderedMap.prototype.clear = function clear () {
  36586. if (this.size === 0) {
  36587. return this;
  36588. }
  36589. if (this.__ownerID) {
  36590. this.size = 0;
  36591. this._map.clear();
  36592. this._list.clear();
  36593. return this;
  36594. }
  36595. return emptyOrderedMap();
  36596. };
  36597. OrderedMap.prototype.set = function set (k, v) {
  36598. return updateOrderedMap(this, k, v);
  36599. };
  36600. OrderedMap.prototype.remove = function remove (k) {
  36601. return updateOrderedMap(this, k, NOT_SET);
  36602. };
  36603. OrderedMap.prototype.wasAltered = function wasAltered () {
  36604. return this._map.wasAltered() || this._list.wasAltered();
  36605. };
  36606. OrderedMap.prototype.__iterate = function __iterate (fn, reverse) {
  36607. var this$1 = this;
  36608. return this._list.__iterate(
  36609. function (entry) { return entry && fn(entry[1], entry[0], this$1); },
  36610. reverse
  36611. );
  36612. };
  36613. OrderedMap.prototype.__iterator = function __iterator (type, reverse) {
  36614. return this._list.fromEntrySeq().__iterator(type, reverse);
  36615. };
  36616. OrderedMap.prototype.__ensureOwner = function __ensureOwner (ownerID) {
  36617. if (ownerID === this.__ownerID) {
  36618. return this;
  36619. }
  36620. var newMap = this._map.__ensureOwner(ownerID);
  36621. var newList = this._list.__ensureOwner(ownerID);
  36622. if (!ownerID) {
  36623. if (this.size === 0) {
  36624. return emptyOrderedMap();
  36625. }
  36626. this.__ownerID = ownerID;
  36627. this._map = newMap;
  36628. this._list = newList;
  36629. return this;
  36630. }
  36631. return makeOrderedMap(newMap, newList, ownerID, this.__hash);
  36632. };
  36633. return OrderedMap;
  36634. }(Map));
  36635. OrderedMap.isOrderedMap = isOrderedMap;
  36636. OrderedMap.prototype[IS_ORDERED_SYMBOL] = true;
  36637. OrderedMap.prototype[DELETE] = OrderedMap.prototype.remove;
  36638. function makeOrderedMap(map, list, ownerID, hash) {
  36639. var omap = Object.create(OrderedMap.prototype);
  36640. omap.size = map ? map.size : 0;
  36641. omap._map = map;
  36642. omap._list = list;
  36643. omap.__ownerID = ownerID;
  36644. omap.__hash = hash;
  36645. return omap;
  36646. }
  36647. var EMPTY_ORDERED_MAP;
  36648. function emptyOrderedMap() {
  36649. return (
  36650. EMPTY_ORDERED_MAP ||
  36651. (EMPTY_ORDERED_MAP = makeOrderedMap(emptyMap(), emptyList()))
  36652. );
  36653. }
  36654. function updateOrderedMap(omap, k, v) {
  36655. var map = omap._map;
  36656. var list = omap._list;
  36657. var i = map.get(k);
  36658. var has = i !== undefined;
  36659. var newMap;
  36660. var newList;
  36661. if (v === NOT_SET) {
  36662. // removed
  36663. if (!has) {
  36664. return omap;
  36665. }
  36666. if (list.size >= SIZE && list.size >= map.size * 2) {
  36667. newList = list.filter(function (entry, idx) { return entry !== undefined && i !== idx; });
  36668. newMap = newList
  36669. .toKeyedSeq()
  36670. .map(function (entry) { return entry[0]; })
  36671. .flip()
  36672. .toMap();
  36673. if (omap.__ownerID) {
  36674. newMap.__ownerID = newList.__ownerID = omap.__ownerID;
  36675. }
  36676. } else {
  36677. newMap = map.remove(k);
  36678. newList = i === list.size - 1 ? list.pop() : list.set(i, undefined);
  36679. }
  36680. } else if (has) {
  36681. if (v === list.get(i)[1]) {
  36682. return omap;
  36683. }
  36684. newMap = map;
  36685. newList = list.set(i, [k, v]);
  36686. } else {
  36687. newMap = map.set(k, list.size);
  36688. newList = list.set(list.size, [k, v]);
  36689. }
  36690. if (omap.__ownerID) {
  36691. omap.size = newMap.size;
  36692. omap._map = newMap;
  36693. omap._list = newList;
  36694. omap.__hash = undefined;
  36695. return omap;
  36696. }
  36697. return makeOrderedMap(newMap, newList);
  36698. }
  36699. var IS_STACK_SYMBOL = '@@__IMMUTABLE_STACK__@@';
  36700. function isStack(maybeStack) {
  36701. return Boolean(maybeStack && maybeStack[IS_STACK_SYMBOL]);
  36702. }
  36703. var Stack = /*@__PURE__*/(function (IndexedCollection$$1) {
  36704. function Stack(value) {
  36705. return value === null || value === undefined
  36706. ? emptyStack()
  36707. : isStack(value)
  36708. ? value
  36709. : emptyStack().pushAll(value);
  36710. }
  36711. if ( IndexedCollection$$1 ) Stack.__proto__ = IndexedCollection$$1;
  36712. Stack.prototype = Object.create( IndexedCollection$$1 && IndexedCollection$$1.prototype );
  36713. Stack.prototype.constructor = Stack;
  36714. Stack.of = function of (/*...values*/) {
  36715. return this(arguments);
  36716. };
  36717. Stack.prototype.toString = function toString () {
  36718. return this.__toString('Stack [', ']');
  36719. };
  36720. // @pragma Access
  36721. Stack.prototype.get = function get (index, notSetValue) {
  36722. var head = this._head;
  36723. index = wrapIndex(this, index);
  36724. while (head && index--) {
  36725. head = head.next;
  36726. }
  36727. return head ? head.value : notSetValue;
  36728. };
  36729. Stack.prototype.peek = function peek () {
  36730. return this._head && this._head.value;
  36731. };
  36732. // @pragma Modification
  36733. Stack.prototype.push = function push (/*...values*/) {
  36734. var arguments$1 = arguments;
  36735. if (arguments.length === 0) {
  36736. return this;
  36737. }
  36738. var newSize = this.size + arguments.length;
  36739. var head = this._head;
  36740. for (var ii = arguments.length - 1; ii >= 0; ii--) {
  36741. head = {
  36742. value: arguments$1[ii],
  36743. next: head,
  36744. };
  36745. }
  36746. if (this.__ownerID) {
  36747. this.size = newSize;
  36748. this._head = head;
  36749. this.__hash = undefined;
  36750. this.__altered = true;
  36751. return this;
  36752. }
  36753. return makeStack(newSize, head);
  36754. };
  36755. Stack.prototype.pushAll = function pushAll (iter) {
  36756. iter = IndexedCollection$$1(iter);
  36757. if (iter.size === 0) {
  36758. return this;
  36759. }
  36760. if (this.size === 0 && isStack(iter)) {
  36761. return iter;
  36762. }
  36763. assertNotInfinite(iter.size);
  36764. var newSize = this.size;
  36765. var head = this._head;
  36766. iter.__iterate(function (value) {
  36767. newSize++;
  36768. head = {
  36769. value: value,
  36770. next: head,
  36771. };
  36772. }, /* reverse */ true);
  36773. if (this.__ownerID) {
  36774. this.size = newSize;
  36775. this._head = head;
  36776. this.__hash = undefined;
  36777. this.__altered = true;
  36778. return this;
  36779. }
  36780. return makeStack(newSize, head);
  36781. };
  36782. Stack.prototype.pop = function pop () {
  36783. return this.slice(1);
  36784. };
  36785. Stack.prototype.clear = function clear () {
  36786. if (this.size === 0) {
  36787. return this;
  36788. }
  36789. if (this.__ownerID) {
  36790. this.size = 0;
  36791. this._head = undefined;
  36792. this.__hash = undefined;
  36793. this.__altered = true;
  36794. return this;
  36795. }
  36796. return emptyStack();
  36797. };
  36798. Stack.prototype.slice = function slice (begin, end) {
  36799. if (wholeSlice(begin, end, this.size)) {
  36800. return this;
  36801. }
  36802. var resolvedBegin = resolveBegin(begin, this.size);
  36803. var resolvedEnd = resolveEnd(end, this.size);
  36804. if (resolvedEnd !== this.size) {
  36805. // super.slice(begin, end);
  36806. return IndexedCollection$$1.prototype.slice.call(this, begin, end);
  36807. }
  36808. var newSize = this.size - resolvedBegin;
  36809. var head = this._head;
  36810. while (resolvedBegin--) {
  36811. head = head.next;
  36812. }
  36813. if (this.__ownerID) {
  36814. this.size = newSize;
  36815. this._head = head;
  36816. this.__hash = undefined;
  36817. this.__altered = true;
  36818. return this;
  36819. }
  36820. return makeStack(newSize, head);
  36821. };
  36822. // @pragma Mutability
  36823. Stack.prototype.__ensureOwner = function __ensureOwner (ownerID) {
  36824. if (ownerID === this.__ownerID) {
  36825. return this;
  36826. }
  36827. if (!ownerID) {
  36828. if (this.size === 0) {
  36829. return emptyStack();
  36830. }
  36831. this.__ownerID = ownerID;
  36832. this.__altered = false;
  36833. return this;
  36834. }
  36835. return makeStack(this.size, this._head, ownerID, this.__hash);
  36836. };
  36837. // @pragma Iteration
  36838. Stack.prototype.__iterate = function __iterate (fn, reverse) {
  36839. var this$1 = this;
  36840. if (reverse) {
  36841. return new ArraySeq(this.toArray()).__iterate(
  36842. function (v, k) { return fn(v, k, this$1); },
  36843. reverse
  36844. );
  36845. }
  36846. var iterations = 0;
  36847. var node = this._head;
  36848. while (node) {
  36849. if (fn(node.value, iterations++, this) === false) {
  36850. break;
  36851. }
  36852. node = node.next;
  36853. }
  36854. return iterations;
  36855. };
  36856. Stack.prototype.__iterator = function __iterator (type, reverse) {
  36857. if (reverse) {
  36858. return new ArraySeq(this.toArray()).__iterator(type, reverse);
  36859. }
  36860. var iterations = 0;
  36861. var node = this._head;
  36862. return new Iterator(function () {
  36863. if (node) {
  36864. var value = node.value;
  36865. node = node.next;
  36866. return iteratorValue(type, iterations++, value);
  36867. }
  36868. return iteratorDone();
  36869. });
  36870. };
  36871. return Stack;
  36872. }(IndexedCollection));
  36873. Stack.isStack = isStack;
  36874. var StackPrototype = Stack.prototype;
  36875. StackPrototype[IS_STACK_SYMBOL] = true;
  36876. StackPrototype.shift = StackPrototype.pop;
  36877. StackPrototype.unshift = StackPrototype.push;
  36878. StackPrototype.unshiftAll = StackPrototype.pushAll;
  36879. StackPrototype.withMutations = withMutations;
  36880. StackPrototype.wasAltered = wasAltered;
  36881. StackPrototype.asImmutable = asImmutable;
  36882. StackPrototype['@@transducer/init'] = StackPrototype.asMutable = asMutable;
  36883. StackPrototype['@@transducer/step'] = function(result, arr) {
  36884. return result.unshift(arr);
  36885. };
  36886. StackPrototype['@@transducer/result'] = function(obj) {
  36887. return obj.asImmutable();
  36888. };
  36889. function makeStack(size, head, ownerID, hash) {
  36890. var map = Object.create(StackPrototype);
  36891. map.size = size;
  36892. map._head = head;
  36893. map.__ownerID = ownerID;
  36894. map.__hash = hash;
  36895. map.__altered = false;
  36896. return map;
  36897. }
  36898. var EMPTY_STACK;
  36899. function emptyStack() {
  36900. return EMPTY_STACK || (EMPTY_STACK = makeStack(0));
  36901. }
  36902. var IS_SET_SYMBOL = '@@__IMMUTABLE_SET__@@';
  36903. function isSet(maybeSet) {
  36904. return Boolean(maybeSet && maybeSet[IS_SET_SYMBOL]);
  36905. }
  36906. function isOrderedSet(maybeOrderedSet) {
  36907. return isSet(maybeOrderedSet) && isOrdered(maybeOrderedSet);
  36908. }
  36909. function deepEqual(a, b) {
  36910. if (a === b) {
  36911. return true;
  36912. }
  36913. if (
  36914. !isCollection(b) ||
  36915. (a.size !== undefined && b.size !== undefined && a.size !== b.size) ||
  36916. (a.__hash !== undefined &&
  36917. b.__hash !== undefined &&
  36918. a.__hash !== b.__hash) ||
  36919. isKeyed(a) !== isKeyed(b) ||
  36920. isIndexed(a) !== isIndexed(b) ||
  36921. isOrdered(a) !== isOrdered(b)
  36922. ) {
  36923. return false;
  36924. }
  36925. if (a.size === 0 && b.size === 0) {
  36926. return true;
  36927. }
  36928. var notAssociative = !isAssociative(a);
  36929. if (isOrdered(a)) {
  36930. var entries = a.entries();
  36931. return (
  36932. b.every(function (v, k) {
  36933. var entry = entries.next().value;
  36934. return entry && is(entry[1], v) && (notAssociative || is(entry[0], k));
  36935. }) && entries.next().done
  36936. );
  36937. }
  36938. var flipped = false;
  36939. if (a.size === undefined) {
  36940. if (b.size === undefined) {
  36941. if (typeof a.cacheResult === 'function') {
  36942. a.cacheResult();
  36943. }
  36944. } else {
  36945. flipped = true;
  36946. var _ = a;
  36947. a = b;
  36948. b = _;
  36949. }
  36950. }
  36951. var allEqual = true;
  36952. var bSize = b.__iterate(function (v, k) {
  36953. if (
  36954. notAssociative
  36955. ? !a.has(v)
  36956. : flipped
  36957. ? !is(v, a.get(k, NOT_SET))
  36958. : !is(a.get(k, NOT_SET), v)
  36959. ) {
  36960. allEqual = false;
  36961. return false;
  36962. }
  36963. });
  36964. return allEqual && a.size === bSize;
  36965. }
  36966. /**
  36967. * Contributes additional methods to a constructor
  36968. */
  36969. function mixin(ctor, methods) {
  36970. var keyCopier = function (key) {
  36971. ctor.prototype[key] = methods[key];
  36972. };
  36973. Object.keys(methods).forEach(keyCopier);
  36974. Object.getOwnPropertySymbols &&
  36975. Object.getOwnPropertySymbols(methods).forEach(keyCopier);
  36976. return ctor;
  36977. }
  36978. function toJS(value) {
  36979. if (!value || typeof value !== 'object') {
  36980. return value;
  36981. }
  36982. if (!isCollection(value)) {
  36983. if (!isDataStructure(value)) {
  36984. return value;
  36985. }
  36986. value = Seq(value);
  36987. }
  36988. if (isKeyed(value)) {
  36989. var result$1 = {};
  36990. value.__iterate(function (v, k) {
  36991. result$1[k] = toJS(v);
  36992. });
  36993. return result$1;
  36994. }
  36995. var result = [];
  36996. value.__iterate(function (v) {
  36997. result.push(toJS(v));
  36998. });
  36999. return result;
  37000. }
  37001. var Set = /*@__PURE__*/(function (SetCollection$$1) {
  37002. function Set(value) {
  37003. return value === null || value === undefined
  37004. ? emptySet()
  37005. : isSet(value) && !isOrdered(value)
  37006. ? value
  37007. : emptySet().withMutations(function (set) {
  37008. var iter = SetCollection$$1(value);
  37009. assertNotInfinite(iter.size);
  37010. iter.forEach(function (v) { return set.add(v); });
  37011. });
  37012. }
  37013. if ( SetCollection$$1 ) Set.__proto__ = SetCollection$$1;
  37014. Set.prototype = Object.create( SetCollection$$1 && SetCollection$$1.prototype );
  37015. Set.prototype.constructor = Set;
  37016. Set.of = function of (/*...values*/) {
  37017. return this(arguments);
  37018. };
  37019. Set.fromKeys = function fromKeys (value) {
  37020. return this(KeyedCollection(value).keySeq());
  37021. };
  37022. Set.intersect = function intersect (sets) {
  37023. sets = Collection(sets).toArray();
  37024. return sets.length
  37025. ? SetPrototype.intersect.apply(Set(sets.pop()), sets)
  37026. : emptySet();
  37027. };
  37028. Set.union = function union (sets) {
  37029. sets = Collection(sets).toArray();
  37030. return sets.length
  37031. ? SetPrototype.union.apply(Set(sets.pop()), sets)
  37032. : emptySet();
  37033. };
  37034. Set.prototype.toString = function toString () {
  37035. return this.__toString('Set {', '}');
  37036. };
  37037. // @pragma Access
  37038. Set.prototype.has = function has (value) {
  37039. return this._map.has(value);
  37040. };
  37041. // @pragma Modification
  37042. Set.prototype.add = function add (value) {
  37043. return updateSet(this, this._map.set(value, value));
  37044. };
  37045. Set.prototype.remove = function remove (value) {
  37046. return updateSet(this, this._map.remove(value));
  37047. };
  37048. Set.prototype.clear = function clear () {
  37049. return updateSet(this, this._map.clear());
  37050. };
  37051. // @pragma Composition
  37052. Set.prototype.map = function map (mapper, context) {
  37053. var this$1 = this;
  37054. var removes = [];
  37055. var adds = [];
  37056. this.forEach(function (value) {
  37057. var mapped = mapper.call(context, value, value, this$1);
  37058. if (mapped !== value) {
  37059. removes.push(value);
  37060. adds.push(mapped);
  37061. }
  37062. });
  37063. return this.withMutations(function (set) {
  37064. removes.forEach(function (value) { return set.remove(value); });
  37065. adds.forEach(function (value) { return set.add(value); });
  37066. });
  37067. };
  37068. Set.prototype.union = function union () {
  37069. var iters = [], len = arguments.length;
  37070. while ( len-- ) iters[ len ] = arguments[ len ];
  37071. iters = iters.filter(function (x) { return x.size !== 0; });
  37072. if (iters.length === 0) {
  37073. return this;
  37074. }
  37075. if (this.size === 0 && !this.__ownerID && iters.length === 1) {
  37076. return this.constructor(iters[0]);
  37077. }
  37078. return this.withMutations(function (set) {
  37079. for (var ii = 0; ii < iters.length; ii++) {
  37080. SetCollection$$1(iters[ii]).forEach(function (value) { return set.add(value); });
  37081. }
  37082. });
  37083. };
  37084. Set.prototype.intersect = function intersect () {
  37085. var iters = [], len = arguments.length;
  37086. while ( len-- ) iters[ len ] = arguments[ len ];
  37087. if (iters.length === 0) {
  37088. return this;
  37089. }
  37090. iters = iters.map(function (iter) { return SetCollection$$1(iter); });
  37091. var toRemove = [];
  37092. this.forEach(function (value) {
  37093. if (!iters.every(function (iter) { return iter.includes(value); })) {
  37094. toRemove.push(value);
  37095. }
  37096. });
  37097. return this.withMutations(function (set) {
  37098. toRemove.forEach(function (value) {
  37099. set.remove(value);
  37100. });
  37101. });
  37102. };
  37103. Set.prototype.subtract = function subtract () {
  37104. var iters = [], len = arguments.length;
  37105. while ( len-- ) iters[ len ] = arguments[ len ];
  37106. if (iters.length === 0) {
  37107. return this;
  37108. }
  37109. iters = iters.map(function (iter) { return SetCollection$$1(iter); });
  37110. var toRemove = [];
  37111. this.forEach(function (value) {
  37112. if (iters.some(function (iter) { return iter.includes(value); })) {
  37113. toRemove.push(value);
  37114. }
  37115. });
  37116. return this.withMutations(function (set) {
  37117. toRemove.forEach(function (value) {
  37118. set.remove(value);
  37119. });
  37120. });
  37121. };
  37122. Set.prototype.sort = function sort (comparator) {
  37123. // Late binding
  37124. return OrderedSet(sortFactory(this, comparator));
  37125. };
  37126. Set.prototype.sortBy = function sortBy (mapper, comparator) {
  37127. // Late binding
  37128. return OrderedSet(sortFactory(this, comparator, mapper));
  37129. };
  37130. Set.prototype.wasAltered = function wasAltered () {
  37131. return this._map.wasAltered();
  37132. };
  37133. Set.prototype.__iterate = function __iterate (fn, reverse) {
  37134. var this$1 = this;
  37135. return this._map.__iterate(function (k) { return fn(k, k, this$1); }, reverse);
  37136. };
  37137. Set.prototype.__iterator = function __iterator (type, reverse) {
  37138. return this._map.__iterator(type, reverse);
  37139. };
  37140. Set.prototype.__ensureOwner = function __ensureOwner (ownerID) {
  37141. if (ownerID === this.__ownerID) {
  37142. return this;
  37143. }
  37144. var newMap = this._map.__ensureOwner(ownerID);
  37145. if (!ownerID) {
  37146. if (this.size === 0) {
  37147. return this.__empty();
  37148. }
  37149. this.__ownerID = ownerID;
  37150. this._map = newMap;
  37151. return this;
  37152. }
  37153. return this.__make(newMap, ownerID);
  37154. };
  37155. return Set;
  37156. }(SetCollection));
  37157. Set.isSet = isSet;
  37158. var SetPrototype = Set.prototype;
  37159. SetPrototype[IS_SET_SYMBOL] = true;
  37160. SetPrototype[DELETE] = SetPrototype.remove;
  37161. SetPrototype.merge = SetPrototype.concat = SetPrototype.union;
  37162. SetPrototype.withMutations = withMutations;
  37163. SetPrototype.asImmutable = asImmutable;
  37164. SetPrototype['@@transducer/init'] = SetPrototype.asMutable = asMutable;
  37165. SetPrototype['@@transducer/step'] = function(result, arr) {
  37166. return result.add(arr);
  37167. };
  37168. SetPrototype['@@transducer/result'] = function(obj) {
  37169. return obj.asImmutable();
  37170. };
  37171. SetPrototype.__empty = emptySet;
  37172. SetPrototype.__make = makeSet;
  37173. function updateSet(set, newMap) {
  37174. if (set.__ownerID) {
  37175. set.size = newMap.size;
  37176. set._map = newMap;
  37177. return set;
  37178. }
  37179. return newMap === set._map
  37180. ? set
  37181. : newMap.size === 0
  37182. ? set.__empty()
  37183. : set.__make(newMap);
  37184. }
  37185. function makeSet(map, ownerID) {
  37186. var set = Object.create(SetPrototype);
  37187. set.size = map ? map.size : 0;
  37188. set._map = map;
  37189. set.__ownerID = ownerID;
  37190. return set;
  37191. }
  37192. var EMPTY_SET;
  37193. function emptySet() {
  37194. return EMPTY_SET || (EMPTY_SET = makeSet(emptyMap()));
  37195. }
  37196. /**
  37197. * Returns a lazy seq of nums from start (inclusive) to end
  37198. * (exclusive), by step, where start defaults to 0, step to 1, and end to
  37199. * infinity. When start is equal to end, returns empty list.
  37200. */
  37201. var Range = /*@__PURE__*/(function (IndexedSeq$$1) {
  37202. function Range(start, end, step) {
  37203. if (!(this instanceof Range)) {
  37204. return new Range(start, end, step);
  37205. }
  37206. invariant(step !== 0, 'Cannot step a Range by 0');
  37207. start = start || 0;
  37208. if (end === undefined) {
  37209. end = Infinity;
  37210. }
  37211. step = step === undefined ? 1 : Math.abs(step);
  37212. if (end < start) {
  37213. step = -step;
  37214. }
  37215. this._start = start;
  37216. this._end = end;
  37217. this._step = step;
  37218. this.size = Math.max(0, Math.ceil((end - start) / step - 1) + 1);
  37219. if (this.size === 0) {
  37220. if (EMPTY_RANGE) {
  37221. return EMPTY_RANGE;
  37222. }
  37223. EMPTY_RANGE = this;
  37224. }
  37225. }
  37226. if ( IndexedSeq$$1 ) Range.__proto__ = IndexedSeq$$1;
  37227. Range.prototype = Object.create( IndexedSeq$$1 && IndexedSeq$$1.prototype );
  37228. Range.prototype.constructor = Range;
  37229. Range.prototype.toString = function toString () {
  37230. if (this.size === 0) {
  37231. return 'Range []';
  37232. }
  37233. return (
  37234. 'Range [ ' +
  37235. this._start +
  37236. '...' +
  37237. this._end +
  37238. (this._step !== 1 ? ' by ' + this._step : '') +
  37239. ' ]'
  37240. );
  37241. };
  37242. Range.prototype.get = function get (index, notSetValue) {
  37243. return this.has(index)
  37244. ? this._start + wrapIndex(this, index) * this._step
  37245. : notSetValue;
  37246. };
  37247. Range.prototype.includes = function includes (searchValue) {
  37248. var possibleIndex = (searchValue - this._start) / this._step;
  37249. return (
  37250. possibleIndex >= 0 &&
  37251. possibleIndex < this.size &&
  37252. possibleIndex === Math.floor(possibleIndex)
  37253. );
  37254. };
  37255. Range.prototype.slice = function slice (begin, end) {
  37256. if (wholeSlice(begin, end, this.size)) {
  37257. return this;
  37258. }
  37259. begin = resolveBegin(begin, this.size);
  37260. end = resolveEnd(end, this.size);
  37261. if (end <= begin) {
  37262. return new Range(0, 0);
  37263. }
  37264. return new Range(
  37265. this.get(begin, this._end),
  37266. this.get(end, this._end),
  37267. this._step
  37268. );
  37269. };
  37270. Range.prototype.indexOf = function indexOf (searchValue) {
  37271. var offsetValue = searchValue - this._start;
  37272. if (offsetValue % this._step === 0) {
  37273. var index = offsetValue / this._step;
  37274. if (index >= 0 && index < this.size) {
  37275. return index;
  37276. }
  37277. }
  37278. return -1;
  37279. };
  37280. Range.prototype.lastIndexOf = function lastIndexOf (searchValue) {
  37281. return this.indexOf(searchValue);
  37282. };
  37283. Range.prototype.__iterate = function __iterate (fn, reverse) {
  37284. var size = this.size;
  37285. var step = this._step;
  37286. var value = reverse ? this._start + (size - 1) * step : this._start;
  37287. var i = 0;
  37288. while (i !== size) {
  37289. if (fn(value, reverse ? size - ++i : i++, this) === false) {
  37290. break;
  37291. }
  37292. value += reverse ? -step : step;
  37293. }
  37294. return i;
  37295. };
  37296. Range.prototype.__iterator = function __iterator (type, reverse) {
  37297. var size = this.size;
  37298. var step = this._step;
  37299. var value = reverse ? this._start + (size - 1) * step : this._start;
  37300. var i = 0;
  37301. return new Iterator(function () {
  37302. if (i === size) {
  37303. return iteratorDone();
  37304. }
  37305. var v = value;
  37306. value += reverse ? -step : step;
  37307. return iteratorValue(type, reverse ? size - ++i : i++, v);
  37308. });
  37309. };
  37310. Range.prototype.equals = function equals (other) {
  37311. return other instanceof Range
  37312. ? this._start === other._start &&
  37313. this._end === other._end &&
  37314. this._step === other._step
  37315. : deepEqual(this, other);
  37316. };
  37317. return Range;
  37318. }(IndexedSeq));
  37319. var EMPTY_RANGE;
  37320. function getIn(collection, searchKeyPath, notSetValue) {
  37321. var keyPath = coerceKeyPath(searchKeyPath);
  37322. var i = 0;
  37323. while (i !== keyPath.length) {
  37324. collection = get(collection, keyPath[i++], NOT_SET);
  37325. if (collection === NOT_SET) {
  37326. return notSetValue;
  37327. }
  37328. }
  37329. return collection;
  37330. }
  37331. function getIn$1(searchKeyPath, notSetValue) {
  37332. return getIn(this, searchKeyPath, notSetValue);
  37333. }
  37334. function hasIn(collection, keyPath) {
  37335. return getIn(collection, keyPath, NOT_SET) !== NOT_SET;
  37336. }
  37337. function hasIn$1(searchKeyPath) {
  37338. return hasIn(this, searchKeyPath);
  37339. }
  37340. function toObject() {
  37341. assertNotInfinite(this.size);
  37342. var object = {};
  37343. this.__iterate(function (v, k) {
  37344. object[k] = v;
  37345. });
  37346. return object;
  37347. }
  37348. // Note: all of these methods are deprecated.
  37349. Collection.isIterable = isCollection;
  37350. Collection.isKeyed = isKeyed;
  37351. Collection.isIndexed = isIndexed;
  37352. Collection.isAssociative = isAssociative;
  37353. Collection.isOrdered = isOrdered;
  37354. Collection.Iterator = Iterator;
  37355. mixin(Collection, {
  37356. // ### Conversion to other types
  37357. toArray: function toArray() {
  37358. assertNotInfinite(this.size);
  37359. var array = new Array(this.size || 0);
  37360. var useTuples = isKeyed(this);
  37361. var i = 0;
  37362. this.__iterate(function (v, k) {
  37363. // Keyed collections produce an array of tuples.
  37364. array[i++] = useTuples ? [k, v] : v;
  37365. });
  37366. return array;
  37367. },
  37368. toIndexedSeq: function toIndexedSeq() {
  37369. return new ToIndexedSequence(this);
  37370. },
  37371. toJS: function toJS$1() {
  37372. return toJS(this);
  37373. },
  37374. toKeyedSeq: function toKeyedSeq() {
  37375. return new ToKeyedSequence(this, true);
  37376. },
  37377. toMap: function toMap() {
  37378. // Use Late Binding here to solve the circular dependency.
  37379. return Map(this.toKeyedSeq());
  37380. },
  37381. toObject: toObject,
  37382. toOrderedMap: function toOrderedMap() {
  37383. // Use Late Binding here to solve the circular dependency.
  37384. return OrderedMap(this.toKeyedSeq());
  37385. },
  37386. toOrderedSet: function toOrderedSet() {
  37387. // Use Late Binding here to solve the circular dependency.
  37388. return OrderedSet(isKeyed(this) ? this.valueSeq() : this);
  37389. },
  37390. toSet: function toSet() {
  37391. // Use Late Binding here to solve the circular dependency.
  37392. return Set(isKeyed(this) ? this.valueSeq() : this);
  37393. },
  37394. toSetSeq: function toSetSeq() {
  37395. return new ToSetSequence(this);
  37396. },
  37397. toSeq: function toSeq() {
  37398. return isIndexed(this)
  37399. ? this.toIndexedSeq()
  37400. : isKeyed(this)
  37401. ? this.toKeyedSeq()
  37402. : this.toSetSeq();
  37403. },
  37404. toStack: function toStack() {
  37405. // Use Late Binding here to solve the circular dependency.
  37406. return Stack(isKeyed(this) ? this.valueSeq() : this);
  37407. },
  37408. toList: function toList() {
  37409. // Use Late Binding here to solve the circular dependency.
  37410. return List(isKeyed(this) ? this.valueSeq() : this);
  37411. },
  37412. // ### Common JavaScript methods and properties
  37413. toString: function toString() {
  37414. return '[Collection]';
  37415. },
  37416. __toString: function __toString(head, tail) {
  37417. if (this.size === 0) {
  37418. return head + tail;
  37419. }
  37420. return (
  37421. head +
  37422. ' ' +
  37423. this.toSeq()
  37424. .map(this.__toStringMapper)
  37425. .join(', ') +
  37426. ' ' +
  37427. tail
  37428. );
  37429. },
  37430. // ### ES6 Collection methods (ES6 Array and Map)
  37431. concat: function concat() {
  37432. var values = [], len = arguments.length;
  37433. while ( len-- ) values[ len ] = arguments[ len ];
  37434. return reify(this, concatFactory(this, values));
  37435. },
  37436. includes: function includes(searchValue) {
  37437. return this.some(function (value) { return is(value, searchValue); });
  37438. },
  37439. entries: function entries() {
  37440. return this.__iterator(ITERATE_ENTRIES);
  37441. },
  37442. every: function every(predicate, context) {
  37443. assertNotInfinite(this.size);
  37444. var returnValue = true;
  37445. this.__iterate(function (v, k, c) {
  37446. if (!predicate.call(context, v, k, c)) {
  37447. returnValue = false;
  37448. return false;
  37449. }
  37450. });
  37451. return returnValue;
  37452. },
  37453. filter: function filter(predicate, context) {
  37454. return reify(this, filterFactory(this, predicate, context, true));
  37455. },
  37456. find: function find(predicate, context, notSetValue) {
  37457. var entry = this.findEntry(predicate, context);
  37458. return entry ? entry[1] : notSetValue;
  37459. },
  37460. forEach: function forEach(sideEffect, context) {
  37461. assertNotInfinite(this.size);
  37462. return this.__iterate(context ? sideEffect.bind(context) : sideEffect);
  37463. },
  37464. join: function join(separator) {
  37465. assertNotInfinite(this.size);
  37466. separator = separator !== undefined ? '' + separator : ',';
  37467. var joined = '';
  37468. var isFirst = true;
  37469. this.__iterate(function (v) {
  37470. isFirst ? (isFirst = false) : (joined += separator);
  37471. joined += v !== null && v !== undefined ? v.toString() : '';
  37472. });
  37473. return joined;
  37474. },
  37475. keys: function keys() {
  37476. return this.__iterator(ITERATE_KEYS);
  37477. },
  37478. map: function map(mapper, context) {
  37479. return reify(this, mapFactory(this, mapper, context));
  37480. },
  37481. reduce: function reduce$1(reducer, initialReduction, context) {
  37482. return reduce(
  37483. this,
  37484. reducer,
  37485. initialReduction,
  37486. context,
  37487. arguments.length < 2,
  37488. false
  37489. );
  37490. },
  37491. reduceRight: function reduceRight(reducer, initialReduction, context) {
  37492. return reduce(
  37493. this,
  37494. reducer,
  37495. initialReduction,
  37496. context,
  37497. arguments.length < 2,
  37498. true
  37499. );
  37500. },
  37501. reverse: function reverse() {
  37502. return reify(this, reverseFactory(this, true));
  37503. },
  37504. slice: function slice(begin, end) {
  37505. return reify(this, sliceFactory(this, begin, end, true));
  37506. },
  37507. some: function some(predicate, context) {
  37508. return !this.every(not(predicate), context);
  37509. },
  37510. sort: function sort(comparator) {
  37511. return reify(this, sortFactory(this, comparator));
  37512. },
  37513. values: function values() {
  37514. return this.__iterator(ITERATE_VALUES);
  37515. },
  37516. // ### More sequential methods
  37517. butLast: function butLast() {
  37518. return this.slice(0, -1);
  37519. },
  37520. isEmpty: function isEmpty() {
  37521. return this.size !== undefined ? this.size === 0 : !this.some(function () { return true; });
  37522. },
  37523. count: function count(predicate, context) {
  37524. return ensureSize(
  37525. predicate ? this.toSeq().filter(predicate, context) : this
  37526. );
  37527. },
  37528. countBy: function countBy(grouper, context) {
  37529. return countByFactory(this, grouper, context);
  37530. },
  37531. equals: function equals(other) {
  37532. return deepEqual(this, other);
  37533. },
  37534. entrySeq: function entrySeq() {
  37535. var collection = this;
  37536. if (collection._cache) {
  37537. // We cache as an entries array, so we can just return the cache!
  37538. return new ArraySeq(collection._cache);
  37539. }
  37540. var entriesSequence = collection
  37541. .toSeq()
  37542. .map(entryMapper)
  37543. .toIndexedSeq();
  37544. entriesSequence.fromEntrySeq = function () { return collection.toSeq(); };
  37545. return entriesSequence;
  37546. },
  37547. filterNot: function filterNot(predicate, context) {
  37548. return this.filter(not(predicate), context);
  37549. },
  37550. findEntry: function findEntry(predicate, context, notSetValue) {
  37551. var found = notSetValue;
  37552. this.__iterate(function (v, k, c) {
  37553. if (predicate.call(context, v, k, c)) {
  37554. found = [k, v];
  37555. return false;
  37556. }
  37557. });
  37558. return found;
  37559. },
  37560. findKey: function findKey(predicate, context) {
  37561. var entry = this.findEntry(predicate, context);
  37562. return entry && entry[0];
  37563. },
  37564. findLast: function findLast(predicate, context, notSetValue) {
  37565. return this.toKeyedSeq()
  37566. .reverse()
  37567. .find(predicate, context, notSetValue);
  37568. },
  37569. findLastEntry: function findLastEntry(predicate, context, notSetValue) {
  37570. return this.toKeyedSeq()
  37571. .reverse()
  37572. .findEntry(predicate, context, notSetValue);
  37573. },
  37574. findLastKey: function findLastKey(predicate, context) {
  37575. return this.toKeyedSeq()
  37576. .reverse()
  37577. .findKey(predicate, context);
  37578. },
  37579. first: function first(notSetValue) {
  37580. return this.find(returnTrue, null, notSetValue);
  37581. },
  37582. flatMap: function flatMap(mapper, context) {
  37583. return reify(this, flatMapFactory(this, mapper, context));
  37584. },
  37585. flatten: function flatten(depth) {
  37586. return reify(this, flattenFactory(this, depth, true));
  37587. },
  37588. fromEntrySeq: function fromEntrySeq() {
  37589. return new FromEntriesSequence(this);
  37590. },
  37591. get: function get(searchKey, notSetValue) {
  37592. return this.find(function (_, key) { return is(key, searchKey); }, undefined, notSetValue);
  37593. },
  37594. getIn: getIn$1,
  37595. groupBy: function groupBy(grouper, context) {
  37596. return groupByFactory(this, grouper, context);
  37597. },
  37598. has: function has(searchKey) {
  37599. return this.get(searchKey, NOT_SET) !== NOT_SET;
  37600. },
  37601. hasIn: hasIn$1,
  37602. isSubset: function isSubset(iter) {
  37603. iter = typeof iter.includes === 'function' ? iter : Collection(iter);
  37604. return this.every(function (value) { return iter.includes(value); });
  37605. },
  37606. isSuperset: function isSuperset(iter) {
  37607. iter = typeof iter.isSubset === 'function' ? iter : Collection(iter);
  37608. return iter.isSubset(this);
  37609. },
  37610. keyOf: function keyOf(searchValue) {
  37611. return this.findKey(function (value) { return is(value, searchValue); });
  37612. },
  37613. keySeq: function keySeq() {
  37614. return this.toSeq()
  37615. .map(keyMapper)
  37616. .toIndexedSeq();
  37617. },
  37618. last: function last(notSetValue) {
  37619. return this.toSeq()
  37620. .reverse()
  37621. .first(notSetValue);
  37622. },
  37623. lastKeyOf: function lastKeyOf(searchValue) {
  37624. return this.toKeyedSeq()
  37625. .reverse()
  37626. .keyOf(searchValue);
  37627. },
  37628. max: function max(comparator) {
  37629. return maxFactory(this, comparator);
  37630. },
  37631. maxBy: function maxBy(mapper, comparator) {
  37632. return maxFactory(this, comparator, mapper);
  37633. },
  37634. min: function min(comparator) {
  37635. return maxFactory(
  37636. this,
  37637. comparator ? neg(comparator) : defaultNegComparator
  37638. );
  37639. },
  37640. minBy: function minBy(mapper, comparator) {
  37641. return maxFactory(
  37642. this,
  37643. comparator ? neg(comparator) : defaultNegComparator,
  37644. mapper
  37645. );
  37646. },
  37647. rest: function rest() {
  37648. return this.slice(1);
  37649. },
  37650. skip: function skip(amount) {
  37651. return amount === 0 ? this : this.slice(Math.max(0, amount));
  37652. },
  37653. skipLast: function skipLast(amount) {
  37654. return amount === 0 ? this : this.slice(0, -Math.max(0, amount));
  37655. },
  37656. skipWhile: function skipWhile(predicate, context) {
  37657. return reify(this, skipWhileFactory(this, predicate, context, true));
  37658. },
  37659. skipUntil: function skipUntil(predicate, context) {
  37660. return this.skipWhile(not(predicate), context);
  37661. },
  37662. sortBy: function sortBy(mapper, comparator) {
  37663. return reify(this, sortFactory(this, comparator, mapper));
  37664. },
  37665. take: function take(amount) {
  37666. return this.slice(0, Math.max(0, amount));
  37667. },
  37668. takeLast: function takeLast(amount) {
  37669. return this.slice(-Math.max(0, amount));
  37670. },
  37671. takeWhile: function takeWhile(predicate, context) {
  37672. return reify(this, takeWhileFactory(this, predicate, context));
  37673. },
  37674. takeUntil: function takeUntil(predicate, context) {
  37675. return this.takeWhile(not(predicate), context);
  37676. },
  37677. update: function update(fn) {
  37678. return fn(this);
  37679. },
  37680. valueSeq: function valueSeq() {
  37681. return this.toIndexedSeq();
  37682. },
  37683. // ### Hashable Object
  37684. hashCode: function hashCode() {
  37685. return this.__hash || (this.__hash = hashCollection(this));
  37686. },
  37687. // ### Internal
  37688. // abstract __iterate(fn, reverse)
  37689. // abstract __iterator(type, reverse)
  37690. });
  37691. var CollectionPrototype = Collection.prototype;
  37692. CollectionPrototype[IS_COLLECTION_SYMBOL] = true;
  37693. CollectionPrototype[ITERATOR_SYMBOL] = CollectionPrototype.values;
  37694. CollectionPrototype.toJSON = CollectionPrototype.toArray;
  37695. CollectionPrototype.__toStringMapper = quoteString;
  37696. CollectionPrototype.inspect = CollectionPrototype.toSource = function() {
  37697. return this.toString();
  37698. };
  37699. CollectionPrototype.chain = CollectionPrototype.flatMap;
  37700. CollectionPrototype.contains = CollectionPrototype.includes;
  37701. mixin(KeyedCollection, {
  37702. // ### More sequential methods
  37703. flip: function flip() {
  37704. return reify(this, flipFactory(this));
  37705. },
  37706. mapEntries: function mapEntries(mapper, context) {
  37707. var this$1 = this;
  37708. var iterations = 0;
  37709. return reify(
  37710. this,
  37711. this.toSeq()
  37712. .map(function (v, k) { return mapper.call(context, [k, v], iterations++, this$1); })
  37713. .fromEntrySeq()
  37714. );
  37715. },
  37716. mapKeys: function mapKeys(mapper, context) {
  37717. var this$1 = this;
  37718. return reify(
  37719. this,
  37720. this.toSeq()
  37721. .flip()
  37722. .map(function (k, v) { return mapper.call(context, k, v, this$1); })
  37723. .flip()
  37724. );
  37725. },
  37726. });
  37727. var KeyedCollectionPrototype = KeyedCollection.prototype;
  37728. KeyedCollectionPrototype[IS_KEYED_SYMBOL] = true;
  37729. KeyedCollectionPrototype[ITERATOR_SYMBOL] = CollectionPrototype.entries;
  37730. KeyedCollectionPrototype.toJSON = toObject;
  37731. KeyedCollectionPrototype.__toStringMapper = function (v, k) { return quoteString(k) + ': ' + quoteString(v); };
  37732. mixin(IndexedCollection, {
  37733. // ### Conversion to other types
  37734. toKeyedSeq: function toKeyedSeq() {
  37735. return new ToKeyedSequence(this, false);
  37736. },
  37737. // ### ES6 Collection methods (ES6 Array and Map)
  37738. filter: function filter(predicate, context) {
  37739. return reify(this, filterFactory(this, predicate, context, false));
  37740. },
  37741. findIndex: function findIndex(predicate, context) {
  37742. var entry = this.findEntry(predicate, context);
  37743. return entry ? entry[0] : -1;
  37744. },
  37745. indexOf: function indexOf(searchValue) {
  37746. var key = this.keyOf(searchValue);
  37747. return key === undefined ? -1 : key;
  37748. },
  37749. lastIndexOf: function lastIndexOf(searchValue) {
  37750. var key = this.lastKeyOf(searchValue);
  37751. return key === undefined ? -1 : key;
  37752. },
  37753. reverse: function reverse() {
  37754. return reify(this, reverseFactory(this, false));
  37755. },
  37756. slice: function slice(begin, end) {
  37757. return reify(this, sliceFactory(this, begin, end, false));
  37758. },
  37759. splice: function splice(index, removeNum /*, ...values*/) {
  37760. var numArgs = arguments.length;
  37761. removeNum = Math.max(removeNum || 0, 0);
  37762. if (numArgs === 0 || (numArgs === 2 && !removeNum)) {
  37763. return this;
  37764. }
  37765. // If index is negative, it should resolve relative to the size of the
  37766. // collection. However size may be expensive to compute if not cached, so
  37767. // only call count() if the number is in fact negative.
  37768. index = resolveBegin(index, index < 0 ? this.count() : this.size);
  37769. var spliced = this.slice(0, index);
  37770. return reify(
  37771. this,
  37772. numArgs === 1
  37773. ? spliced
  37774. : spliced.concat(arrCopy(arguments, 2), this.slice(index + removeNum))
  37775. );
  37776. },
  37777. // ### More collection methods
  37778. findLastIndex: function findLastIndex(predicate, context) {
  37779. var entry = this.findLastEntry(predicate, context);
  37780. return entry ? entry[0] : -1;
  37781. },
  37782. first: function first(notSetValue) {
  37783. return this.get(0, notSetValue);
  37784. },
  37785. flatten: function flatten(depth) {
  37786. return reify(this, flattenFactory(this, depth, false));
  37787. },
  37788. get: function get(index, notSetValue) {
  37789. index = wrapIndex(this, index);
  37790. return index < 0 ||
  37791. (this.size === Infinity || (this.size !== undefined && index > this.size))
  37792. ? notSetValue
  37793. : this.find(function (_, key) { return key === index; }, undefined, notSetValue);
  37794. },
  37795. has: function has(index) {
  37796. index = wrapIndex(this, index);
  37797. return (
  37798. index >= 0 &&
  37799. (this.size !== undefined
  37800. ? this.size === Infinity || index < this.size
  37801. : this.indexOf(index) !== -1)
  37802. );
  37803. },
  37804. interpose: function interpose(separator) {
  37805. return reify(this, interposeFactory(this, separator));
  37806. },
  37807. interleave: function interleave(/*...collections*/) {
  37808. var collections = [this].concat(arrCopy(arguments));
  37809. var zipped = zipWithFactory(this.toSeq(), IndexedSeq.of, collections);
  37810. var interleaved = zipped.flatten(true);
  37811. if (zipped.size) {
  37812. interleaved.size = zipped.size * collections.length;
  37813. }
  37814. return reify(this, interleaved);
  37815. },
  37816. keySeq: function keySeq() {
  37817. return Range(0, this.size);
  37818. },
  37819. last: function last(notSetValue) {
  37820. return this.get(-1, notSetValue);
  37821. },
  37822. skipWhile: function skipWhile(predicate, context) {
  37823. return reify(this, skipWhileFactory(this, predicate, context, false));
  37824. },
  37825. zip: function zip(/*, ...collections */) {
  37826. var collections = [this].concat(arrCopy(arguments));
  37827. return reify(this, zipWithFactory(this, defaultZipper, collections));
  37828. },
  37829. zipAll: function zipAll(/*, ...collections */) {
  37830. var collections = [this].concat(arrCopy(arguments));
  37831. return reify(this, zipWithFactory(this, defaultZipper, collections, true));
  37832. },
  37833. zipWith: function zipWith(zipper /*, ...collections */) {
  37834. var collections = arrCopy(arguments);
  37835. collections[0] = this;
  37836. return reify(this, zipWithFactory(this, zipper, collections));
  37837. },
  37838. });
  37839. var IndexedCollectionPrototype = IndexedCollection.prototype;
  37840. IndexedCollectionPrototype[IS_INDEXED_SYMBOL] = true;
  37841. IndexedCollectionPrototype[IS_ORDERED_SYMBOL] = true;
  37842. mixin(SetCollection, {
  37843. // ### ES6 Collection methods (ES6 Array and Map)
  37844. get: function get(value, notSetValue) {
  37845. return this.has(value) ? value : notSetValue;
  37846. },
  37847. includes: function includes(value) {
  37848. return this.has(value);
  37849. },
  37850. // ### More sequential methods
  37851. keySeq: function keySeq() {
  37852. return this.valueSeq();
  37853. },
  37854. });
  37855. SetCollection.prototype.has = CollectionPrototype.includes;
  37856. SetCollection.prototype.contains = SetCollection.prototype.includes;
  37857. // Mixin subclasses
  37858. mixin(KeyedSeq, KeyedCollection.prototype);
  37859. mixin(IndexedSeq, IndexedCollection.prototype);
  37860. mixin(SetSeq, SetCollection.prototype);
  37861. // #pragma Helper functions
  37862. function reduce(collection, reducer, reduction, context, useFirst, reverse) {
  37863. assertNotInfinite(collection.size);
  37864. collection.__iterate(function (v, k, c) {
  37865. if (useFirst) {
  37866. useFirst = false;
  37867. reduction = v;
  37868. } else {
  37869. reduction = reducer.call(context, reduction, v, k, c);
  37870. }
  37871. }, reverse);
  37872. return reduction;
  37873. }
  37874. function keyMapper(v, k) {
  37875. return k;
  37876. }
  37877. function entryMapper(v, k) {
  37878. return [k, v];
  37879. }
  37880. function not(predicate) {
  37881. return function() {
  37882. return !predicate.apply(this, arguments);
  37883. };
  37884. }
  37885. function neg(predicate) {
  37886. return function() {
  37887. return -predicate.apply(this, arguments);
  37888. };
  37889. }
  37890. function defaultZipper() {
  37891. return arrCopy(arguments);
  37892. }
  37893. function defaultNegComparator(a, b) {
  37894. return a < b ? 1 : a > b ? -1 : 0;
  37895. }
  37896. function hashCollection(collection) {
  37897. if (collection.size === Infinity) {
  37898. return 0;
  37899. }
  37900. var ordered = isOrdered(collection);
  37901. var keyed = isKeyed(collection);
  37902. var h = ordered ? 1 : 0;
  37903. var size = collection.__iterate(
  37904. keyed
  37905. ? ordered
  37906. ? function (v, k) {
  37907. h = (31 * h + hashMerge(hash(v), hash(k))) | 0;
  37908. }
  37909. : function (v, k) {
  37910. h = (h + hashMerge(hash(v), hash(k))) | 0;
  37911. }
  37912. : ordered
  37913. ? function (v) {
  37914. h = (31 * h + hash(v)) | 0;
  37915. }
  37916. : function (v) {
  37917. h = (h + hash(v)) | 0;
  37918. }
  37919. );
  37920. return murmurHashOfSize(size, h);
  37921. }
  37922. function murmurHashOfSize(size, h) {
  37923. h = imul(h, 0xcc9e2d51);
  37924. h = imul((h << 15) | (h >>> -15), 0x1b873593);
  37925. h = imul((h << 13) | (h >>> -13), 5);
  37926. h = ((h + 0xe6546b64) | 0) ^ size;
  37927. h = imul(h ^ (h >>> 16), 0x85ebca6b);
  37928. h = imul(h ^ (h >>> 13), 0xc2b2ae35);
  37929. h = smi(h ^ (h >>> 16));
  37930. return h;
  37931. }
  37932. function hashMerge(a, b) {
  37933. return (a ^ (b + 0x9e3779b9 + (a << 6) + (a >> 2))) | 0; // int
  37934. }
  37935. var OrderedSet = /*@__PURE__*/(function (Set$$1) {
  37936. function OrderedSet(value) {
  37937. return value === null || value === undefined
  37938. ? emptyOrderedSet()
  37939. : isOrderedSet(value)
  37940. ? value
  37941. : emptyOrderedSet().withMutations(function (set) {
  37942. var iter = SetCollection(value);
  37943. assertNotInfinite(iter.size);
  37944. iter.forEach(function (v) { return set.add(v); });
  37945. });
  37946. }
  37947. if ( Set$$1 ) OrderedSet.__proto__ = Set$$1;
  37948. OrderedSet.prototype = Object.create( Set$$1 && Set$$1.prototype );
  37949. OrderedSet.prototype.constructor = OrderedSet;
  37950. OrderedSet.of = function of (/*...values*/) {
  37951. return this(arguments);
  37952. };
  37953. OrderedSet.fromKeys = function fromKeys (value) {
  37954. return this(KeyedCollection(value).keySeq());
  37955. };
  37956. OrderedSet.prototype.toString = function toString () {
  37957. return this.__toString('OrderedSet {', '}');
  37958. };
  37959. return OrderedSet;
  37960. }(Set));
  37961. OrderedSet.isOrderedSet = isOrderedSet;
  37962. var OrderedSetPrototype = OrderedSet.prototype;
  37963. OrderedSetPrototype[IS_ORDERED_SYMBOL] = true;
  37964. OrderedSetPrototype.zip = IndexedCollectionPrototype.zip;
  37965. OrderedSetPrototype.zipWith = IndexedCollectionPrototype.zipWith;
  37966. OrderedSetPrototype.__empty = emptyOrderedSet;
  37967. OrderedSetPrototype.__make = makeOrderedSet;
  37968. function makeOrderedSet(map, ownerID) {
  37969. var set = Object.create(OrderedSetPrototype);
  37970. set.size = map ? map.size : 0;
  37971. set._map = map;
  37972. set.__ownerID = ownerID;
  37973. return set;
  37974. }
  37975. var EMPTY_ORDERED_SET;
  37976. function emptyOrderedSet() {
  37977. return (
  37978. EMPTY_ORDERED_SET || (EMPTY_ORDERED_SET = makeOrderedSet(emptyOrderedMap()))
  37979. );
  37980. }
  37981. var Record = function Record(defaultValues, name) {
  37982. var hasInitialized;
  37983. var RecordType = function Record(values) {
  37984. var this$1 = this;
  37985. if (values instanceof RecordType) {
  37986. return values;
  37987. }
  37988. if (!(this instanceof RecordType)) {
  37989. return new RecordType(values);
  37990. }
  37991. if (!hasInitialized) {
  37992. hasInitialized = true;
  37993. var keys = Object.keys(defaultValues);
  37994. var indices = (RecordTypePrototype._indices = {});
  37995. // Deprecated: left to attempt not to break any external code which
  37996. // relies on a ._name property existing on record instances.
  37997. // Use Record.getDescriptiveName() instead
  37998. RecordTypePrototype._name = name;
  37999. RecordTypePrototype._keys = keys;
  38000. RecordTypePrototype._defaultValues = defaultValues;
  38001. for (var i = 0; i < keys.length; i++) {
  38002. var propName = keys[i];
  38003. indices[propName] = i;
  38004. if (RecordTypePrototype[propName]) {
  38005. /* eslint-disable no-console */
  38006. typeof console === 'object' &&
  38007. console.warn &&
  38008. console.warn(
  38009. 'Cannot define ' +
  38010. recordName(this) +
  38011. ' with property "' +
  38012. propName +
  38013. '" since that property name is part of the Record API.'
  38014. );
  38015. /* eslint-enable no-console */
  38016. } else {
  38017. setProp(RecordTypePrototype, propName);
  38018. }
  38019. }
  38020. }
  38021. this.__ownerID = undefined;
  38022. this._values = List().withMutations(function (l) {
  38023. l.setSize(this$1._keys.length);
  38024. KeyedCollection(values).forEach(function (v, k) {
  38025. l.set(this$1._indices[k], v === this$1._defaultValues[k] ? undefined : v);
  38026. });
  38027. });
  38028. };
  38029. var RecordTypePrototype = (RecordType.prototype = Object.create(
  38030. RecordPrototype
  38031. ));
  38032. RecordTypePrototype.constructor = RecordType;
  38033. if (name) {
  38034. RecordType.displayName = name;
  38035. }
  38036. return RecordType;
  38037. };
  38038. Record.prototype.toString = function toString () {
  38039. var str = recordName(this) + ' { ';
  38040. var keys = this._keys;
  38041. var k;
  38042. for (var i = 0, l = keys.length; i !== l; i++) {
  38043. k = keys[i];
  38044. str += (i ? ', ' : '') + k + ': ' + quoteString(this.get(k));
  38045. }
  38046. return str + ' }';
  38047. };
  38048. Record.prototype.equals = function equals (other) {
  38049. return (
  38050. this === other ||
  38051. (other &&
  38052. this._keys === other._keys &&
  38053. recordSeq(this).equals(recordSeq(other)))
  38054. );
  38055. };
  38056. Record.prototype.hashCode = function hashCode () {
  38057. return recordSeq(this).hashCode();
  38058. };
  38059. // @pragma Access
  38060. Record.prototype.has = function has (k) {
  38061. return this._indices.hasOwnProperty(k);
  38062. };
  38063. Record.prototype.get = function get (k, notSetValue) {
  38064. if (!this.has(k)) {
  38065. return notSetValue;
  38066. }
  38067. var index = this._indices[k];
  38068. var value = this._values.get(index);
  38069. return value === undefined ? this._defaultValues[k] : value;
  38070. };
  38071. // @pragma Modification
  38072. Record.prototype.set = function set (k, v) {
  38073. if (this.has(k)) {
  38074. var newValues = this._values.set(
  38075. this._indices[k],
  38076. v === this._defaultValues[k] ? undefined : v
  38077. );
  38078. if (newValues !== this._values && !this.__ownerID) {
  38079. return makeRecord(this, newValues);
  38080. }
  38081. }
  38082. return this;
  38083. };
  38084. Record.prototype.remove = function remove (k) {
  38085. return this.set(k);
  38086. };
  38087. Record.prototype.clear = function clear () {
  38088. var newValues = this._values.clear().setSize(this._keys.length);
  38089. return this.__ownerID ? this : makeRecord(this, newValues);
  38090. };
  38091. Record.prototype.wasAltered = function wasAltered () {
  38092. return this._values.wasAltered();
  38093. };
  38094. Record.prototype.toSeq = function toSeq () {
  38095. return recordSeq(this);
  38096. };
  38097. Record.prototype.toJS = function toJS$1 () {
  38098. return toJS(this);
  38099. };
  38100. Record.prototype.entries = function entries () {
  38101. return this.__iterator(ITERATE_ENTRIES);
  38102. };
  38103. Record.prototype.__iterator = function __iterator (type, reverse) {
  38104. return recordSeq(this).__iterator(type, reverse);
  38105. };
  38106. Record.prototype.__iterate = function __iterate (fn, reverse) {
  38107. return recordSeq(this).__iterate(fn, reverse);
  38108. };
  38109. Record.prototype.__ensureOwner = function __ensureOwner (ownerID) {
  38110. if (ownerID === this.__ownerID) {
  38111. return this;
  38112. }
  38113. var newValues = this._values.__ensureOwner(ownerID);
  38114. if (!ownerID) {
  38115. this.__ownerID = ownerID;
  38116. this._values = newValues;
  38117. return this;
  38118. }
  38119. return makeRecord(this, newValues, ownerID);
  38120. };
  38121. Record.isRecord = isRecord;
  38122. Record.getDescriptiveName = recordName;
  38123. var RecordPrototype = Record.prototype;
  38124. RecordPrototype[IS_RECORD_SYMBOL] = true;
  38125. RecordPrototype[DELETE] = RecordPrototype.remove;
  38126. RecordPrototype.deleteIn = RecordPrototype.removeIn = deleteIn;
  38127. RecordPrototype.getIn = getIn$1;
  38128. RecordPrototype.hasIn = CollectionPrototype.hasIn;
  38129. RecordPrototype.merge = merge;
  38130. RecordPrototype.mergeWith = mergeWith;
  38131. RecordPrototype.mergeIn = mergeIn;
  38132. RecordPrototype.mergeDeep = mergeDeep$1;
  38133. RecordPrototype.mergeDeepWith = mergeDeepWith$1;
  38134. RecordPrototype.mergeDeepIn = mergeDeepIn;
  38135. RecordPrototype.setIn = setIn$1;
  38136. RecordPrototype.update = update$1;
  38137. RecordPrototype.updateIn = updateIn$1;
  38138. RecordPrototype.withMutations = withMutations;
  38139. RecordPrototype.asMutable = asMutable;
  38140. RecordPrototype.asImmutable = asImmutable;
  38141. RecordPrototype[ITERATOR_SYMBOL] = RecordPrototype.entries;
  38142. RecordPrototype.toJSON = RecordPrototype.toObject =
  38143. CollectionPrototype.toObject;
  38144. RecordPrototype.inspect = RecordPrototype.toSource = function() {
  38145. return this.toString();
  38146. };
  38147. function makeRecord(likeRecord, values, ownerID) {
  38148. var record = Object.create(Object.getPrototypeOf(likeRecord));
  38149. record._values = values;
  38150. record.__ownerID = ownerID;
  38151. return record;
  38152. }
  38153. function recordName(record) {
  38154. return record.constructor.displayName || record.constructor.name || 'Record';
  38155. }
  38156. function recordSeq(record) {
  38157. return keyedSeqFromValue(record._keys.map(function (k) { return [k, record.get(k)]; }));
  38158. }
  38159. function setProp(prototype, name) {
  38160. try {
  38161. Object.defineProperty(prototype, name, {
  38162. get: function() {
  38163. return this.get(name);
  38164. },
  38165. set: function(value) {
  38166. invariant(this.__ownerID, 'Cannot set on an immutable record.');
  38167. this.set(name, value);
  38168. },
  38169. });
  38170. } catch (error) {
  38171. // Object.defineProperty failed. Probably IE8.
  38172. }
  38173. }
  38174. /**
  38175. * Returns a lazy Seq of `value` repeated `times` times. When `times` is
  38176. * undefined, returns an infinite sequence of `value`.
  38177. */
  38178. var Repeat = /*@__PURE__*/(function (IndexedSeq$$1) {
  38179. function Repeat(value, times) {
  38180. if (!(this instanceof Repeat)) {
  38181. return new Repeat(value, times);
  38182. }
  38183. this._value = value;
  38184. this.size = times === undefined ? Infinity : Math.max(0, times);
  38185. if (this.size === 0) {
  38186. if (EMPTY_REPEAT) {
  38187. return EMPTY_REPEAT;
  38188. }
  38189. EMPTY_REPEAT = this;
  38190. }
  38191. }
  38192. if ( IndexedSeq$$1 ) Repeat.__proto__ = IndexedSeq$$1;
  38193. Repeat.prototype = Object.create( IndexedSeq$$1 && IndexedSeq$$1.prototype );
  38194. Repeat.prototype.constructor = Repeat;
  38195. Repeat.prototype.toString = function toString () {
  38196. if (this.size === 0) {
  38197. return 'Repeat []';
  38198. }
  38199. return 'Repeat [ ' + this._value + ' ' + this.size + ' times ]';
  38200. };
  38201. Repeat.prototype.get = function get (index, notSetValue) {
  38202. return this.has(index) ? this._value : notSetValue;
  38203. };
  38204. Repeat.prototype.includes = function includes (searchValue) {
  38205. return is(this._value, searchValue);
  38206. };
  38207. Repeat.prototype.slice = function slice (begin, end) {
  38208. var size = this.size;
  38209. return wholeSlice(begin, end, size)
  38210. ? this
  38211. : new Repeat(
  38212. this._value,
  38213. resolveEnd(end, size) - resolveBegin(begin, size)
  38214. );
  38215. };
  38216. Repeat.prototype.reverse = function reverse () {
  38217. return this;
  38218. };
  38219. Repeat.prototype.indexOf = function indexOf (searchValue) {
  38220. if (is(this._value, searchValue)) {
  38221. return 0;
  38222. }
  38223. return -1;
  38224. };
  38225. Repeat.prototype.lastIndexOf = function lastIndexOf (searchValue) {
  38226. if (is(this._value, searchValue)) {
  38227. return this.size;
  38228. }
  38229. return -1;
  38230. };
  38231. Repeat.prototype.__iterate = function __iterate (fn, reverse) {
  38232. var size = this.size;
  38233. var i = 0;
  38234. while (i !== size) {
  38235. if (fn(this._value, reverse ? size - ++i : i++, this) === false) {
  38236. break;
  38237. }
  38238. }
  38239. return i;
  38240. };
  38241. Repeat.prototype.__iterator = function __iterator (type, reverse) {
  38242. var this$1 = this;
  38243. var size = this.size;
  38244. var i = 0;
  38245. return new Iterator(
  38246. function () { return i === size
  38247. ? iteratorDone()
  38248. : iteratorValue(type, reverse ? size - ++i : i++, this$1._value); }
  38249. );
  38250. };
  38251. Repeat.prototype.equals = function equals (other) {
  38252. return other instanceof Repeat
  38253. ? is(this._value, other._value)
  38254. : deepEqual(other);
  38255. };
  38256. return Repeat;
  38257. }(IndexedSeq));
  38258. var EMPTY_REPEAT;
  38259. function fromJS(value, converter) {
  38260. return fromJSWith(
  38261. [],
  38262. converter || defaultConverter,
  38263. value,
  38264. '',
  38265. converter && converter.length > 2 ? [] : undefined,
  38266. { '': value }
  38267. );
  38268. }
  38269. function fromJSWith(stack, converter, value, key, keyPath, parentValue) {
  38270. var toSeq = Array.isArray(value)
  38271. ? IndexedSeq
  38272. : isPlainObj(value)
  38273. ? KeyedSeq
  38274. : null;
  38275. if (toSeq) {
  38276. if (~stack.indexOf(value)) {
  38277. throw new TypeError('Cannot convert circular structure to Immutable');
  38278. }
  38279. stack.push(value);
  38280. keyPath && key !== '' && keyPath.push(key);
  38281. var converted = converter.call(
  38282. parentValue,
  38283. key,
  38284. toSeq(value).map(function (v, k) { return fromJSWith(stack, converter, v, k, keyPath, value); }
  38285. ),
  38286. keyPath && keyPath.slice()
  38287. );
  38288. stack.pop();
  38289. keyPath && keyPath.pop();
  38290. return converted;
  38291. }
  38292. return value;
  38293. }
  38294. function defaultConverter(k, v) {
  38295. return isKeyed(v) ? v.toMap() : v.toList();
  38296. }
  38297. var version = "4.0.0-rc.11";
  38298. var Immutable = {
  38299. version: version,
  38300. Collection: Collection,
  38301. // Note: Iterable is deprecated
  38302. Iterable: Collection,
  38303. Seq: Seq,
  38304. Map: Map,
  38305. OrderedMap: OrderedMap,
  38306. List: List,
  38307. Stack: Stack,
  38308. Set: Set,
  38309. OrderedSet: OrderedSet,
  38310. Record: Record,
  38311. Range: Range,
  38312. Repeat: Repeat,
  38313. is: is,
  38314. fromJS: fromJS,
  38315. hash: hash,
  38316. isImmutable: isImmutable,
  38317. isCollection: isCollection,
  38318. isKeyed: isKeyed,
  38319. isIndexed: isIndexed,
  38320. isAssociative: isAssociative,
  38321. isOrdered: isOrdered,
  38322. isValueObject: isValueObject,
  38323. isSeq: isSeq,
  38324. isList: isList,
  38325. isMap: isMap,
  38326. isOrderedMap: isOrderedMap,
  38327. isStack: isStack,
  38328. isSet: isSet,
  38329. isOrderedSet: isOrderedSet,
  38330. isRecord: isRecord,
  38331. get: get,
  38332. getIn: getIn,
  38333. has: has,
  38334. hasIn: hasIn,
  38335. merge: merge$1,
  38336. mergeDeep: mergeDeep,
  38337. mergeWith: mergeWith$1,
  38338. mergeDeepWith: mergeDeepWith,
  38339. remove: remove,
  38340. removeIn: removeIn,
  38341. set: set,
  38342. setIn: setIn,
  38343. update: update,
  38344. updateIn: updateIn,
  38345. };
  38346. // Note: Iterable is deprecated
  38347. var Iterable = Collection;
  38348. exports.default = Immutable;
  38349. exports.version = version;
  38350. exports.Collection = Collection;
  38351. exports.Iterable = Iterable;
  38352. exports.Seq = Seq;
  38353. exports.Map = Map;
  38354. exports.OrderedMap = OrderedMap;
  38355. exports.List = List;
  38356. exports.Stack = Stack;
  38357. exports.Set = Set;
  38358. exports.OrderedSet = OrderedSet;
  38359. exports.Record = Record;
  38360. exports.Range = Range;
  38361. exports.Repeat = Repeat;
  38362. exports.is = is;
  38363. exports.fromJS = fromJS;
  38364. exports.hash = hash;
  38365. exports.isImmutable = isImmutable;
  38366. exports.isCollection = isCollection;
  38367. exports.isKeyed = isKeyed;
  38368. exports.isIndexed = isIndexed;
  38369. exports.isAssociative = isAssociative;
  38370. exports.isOrdered = isOrdered;
  38371. exports.isValueObject = isValueObject;
  38372. exports.get = get;
  38373. exports.getIn = getIn;
  38374. exports.has = has;
  38375. exports.hasIn = hasIn;
  38376. exports.merge = merge$1;
  38377. exports.mergeDeep = mergeDeep;
  38378. exports.mergeWith = mergeWith$1;
  38379. exports.mergeDeepWith = mergeDeepWith;
  38380. exports.remove = remove;
  38381. exports.removeIn = removeIn;
  38382. exports.set = set;
  38383. exports.setIn = setIn;
  38384. exports.update = update;
  38385. exports.updateIn = updateIn;
  38386. Object.defineProperty(exports, '__esModule', { value: true });
  38387. })));
  38388. });
  38389. unwrapExports(immutable$3);
  38390. var draftjsUtils$1 = createCommonjsModule(function (module, exports) {
  38391. !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;});
  38392. });
  38393. unwrapExports(draftjsUtils$1);
  38394. var draftjsUtils_1$1 = draftjsUtils$1.draftjsUtils;
  38395. var content$1 = createCommonjsModule(function (module, exports) {
  38396. Object.defineProperty(exports, "__esModule", {
  38397. value: true
  38398. });
  38399. 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;
  38400. var _immutable2 = _interopRequireDefault(immutable$3);
  38401. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  38402. var strictBlockTypes = ['atomic'];
  38403. var registerStrictBlockType = exports.registerStrictBlockType = function registerStrictBlockType(blockType) {
  38404. strictBlockTypes.indexOf(blockType) === -1 && strictBlockTypes.push(blockType);
  38405. };
  38406. var isEditorState = exports.isEditorState = function isEditorState(editorState) {
  38407. return editorState instanceof Draft.EditorState;
  38408. };
  38409. var createEmptyEditorState = exports.createEmptyEditorState = function createEmptyEditorState(editorDecorators) {
  38410. return Draft.EditorState.createEmpty(editorDecorators);
  38411. };
  38412. var createEditorState = exports.createEditorState = function createEditorState(contentState, editorDecorators) {
  38413. return Draft.EditorState.createWithContent(contentState, editorDecorators);
  38414. };
  38415. var isSelectionCollapsed = exports.isSelectionCollapsed = function isSelectionCollapsed(editorState) {
  38416. return editorState.getSelection().isCollapsed();
  38417. };
  38418. var selectionContainsBlockType = exports.selectionContainsBlockType = function selectionContainsBlockType(editorState, blockType) {
  38419. return getSelectedBlocks(editorState).find(function (block) {
  38420. return block.getType() === blockType;
  38421. });
  38422. };
  38423. var selectionContainsStrictBlock = exports.selectionContainsStrictBlock = function selectionContainsStrictBlock(editorState) {
  38424. return getSelectedBlocks(editorState).find(function (block) {
  38425. return ~strictBlockTypes.indexOf(block.getType());
  38426. });
  38427. };
  38428. var selectBlock = exports.selectBlock = function selectBlock(editorState, block) {
  38429. var blockKey = block.getKey();
  38430. return Draft.EditorState.forceSelection(editorState, new Draft.SelectionState({
  38431. anchorKey: blockKey,
  38432. anchorOffset: 0,
  38433. focusKey: blockKey,
  38434. focusOffset: block.getLength()
  38435. }));
  38436. };
  38437. var selectNextBlock = exports.selectNextBlock = function selectNextBlock(editorState, block) {
  38438. var nextBlock = editorState.getCurrentContent().getBlockAfter(block.getKey());
  38439. return nextBlock ? selectBlock(editorState, nextBlock) : editorState;
  38440. };
  38441. var removeBlock = exports.removeBlock = function removeBlock(editorState, block) {
  38442. var lastSelection = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  38443. var nextContentState = void 0,
  38444. nextEditorState = void 0;
  38445. var blockKey = block.getKey();
  38446. nextContentState = Draft.Modifier.removeRange(editorState.getCurrentContent(), new Draft.SelectionState({
  38447. anchorKey: blockKey,
  38448. anchorOffset: 0,
  38449. focusKey: blockKey,
  38450. focusOffset: block.getLength()
  38451. }), 'backward');
  38452. nextContentState = Draft.Modifier.setBlockType(nextContentState, nextContentState.getSelectionAfter(), 'unstyled');
  38453. nextEditorState = Draft.EditorState.push(editorState, nextContentState, 'remove-range');
  38454. return Draft.EditorState.forceSelection(nextEditorState, lastSelection || nextContentState.getSelectionAfter());
  38455. };
  38456. var getSelectionBlock = exports.getSelectionBlock = function getSelectionBlock(editorState) {
  38457. return editorState.getCurrentContent().getBlockForKey(editorState.getSelection().getAnchorKey());
  38458. };
  38459. var updateEachCharacterOfSelection = exports.updateEachCharacterOfSelection = function updateEachCharacterOfSelection(editorState, callback) {
  38460. var selectionState = editorState.getSelection();
  38461. var contentState = editorState.getCurrentContent();
  38462. var contentBlocks = contentState.getBlockMap();
  38463. var selectedBlocks = getSelectedBlocks(editorState);
  38464. if (selectedBlocks.length === 0) {
  38465. return editorState;
  38466. }
  38467. var startKey = selectionState.getStartKey();
  38468. var startOffset = selectionState.getStartOffset();
  38469. var endKey = selectionState.getEndKey();
  38470. var endOffset = selectionState.getEndOffset();
  38471. var nextContentBlocks = contentBlocks.map(function (block) {
  38472. if (selectedBlocks.indexOf(block) === -1) {
  38473. return block;
  38474. }
  38475. var blockKey = block.getKey();
  38476. var charactersList = block.getCharacterList();
  38477. var nextCharactersList = null;
  38478. if (blockKey === startKey && blockKey === endKey) {
  38479. nextCharactersList = charactersList.map(function (character, index) {
  38480. if (index >= startOffset && index < endOffset) {
  38481. return callback(character);
  38482. }
  38483. return character;
  38484. });
  38485. } else if (blockKey === startKey) {
  38486. nextCharactersList = charactersList.map(function (character, index) {
  38487. if (index >= startOffset) {
  38488. return callback(character);
  38489. }
  38490. return character;
  38491. });
  38492. } else if (blockKey === endKey) {
  38493. nextCharactersList = charactersList.map(function (character, index) {
  38494. if (index < endOffset) {
  38495. return callback(character);
  38496. }
  38497. return character;
  38498. });
  38499. } else {
  38500. nextCharactersList = charactersList.map(function (character) {
  38501. return callback(character);
  38502. });
  38503. }
  38504. return block.merge({
  38505. 'characterList': nextCharactersList
  38506. });
  38507. });
  38508. return Draft.EditorState.push(editorState, contentState.merge({
  38509. blockMap: nextContentBlocks,
  38510. selectionBefore: selectionState,
  38511. selectionAfter: selectionState
  38512. }), 'update-selection-character-list');
  38513. };
  38514. var getSelectedBlocks = exports.getSelectedBlocks = function getSelectedBlocks(editorState) {
  38515. var selectionState = editorState.getSelection();
  38516. var contentState = editorState.getCurrentContent();
  38517. var startKey = selectionState.getStartKey();
  38518. var endKey = selectionState.getEndKey();
  38519. var isSameBlock = startKey === endKey;
  38520. var startingBlock = contentState.getBlockForKey(startKey);
  38521. var selectedBlocks = [startingBlock];
  38522. if (!isSameBlock) {
  38523. var blockKey = startKey;
  38524. while (blockKey !== endKey) {
  38525. var nextBlock = contentState.getBlockAfter(blockKey);
  38526. selectedBlocks.push(nextBlock);
  38527. blockKey = nextBlock.getKey();
  38528. }
  38529. }
  38530. return selectedBlocks;
  38531. };
  38532. var setSelectionBlockData = exports.setSelectionBlockData = function setSelectionBlockData(editorState, blockData, override) {
  38533. var newBlockData = override ? blockData : Object.assign({}, getSelectionBlockData(editorState).toJS(), blockData);
  38534. Object.keys(newBlockData).forEach(function (key) {
  38535. if (newBlockData.hasOwnProperty(key) && newBlockData[key] === undefined) {
  38536. delete newBlockData[key];
  38537. }
  38538. });
  38539. return (0, draftjsUtils$1.setBlockData)(editorState, newBlockData);
  38540. };
  38541. var getSelectionBlockData = exports.getSelectionBlockData = function getSelectionBlockData(editorState, name) {
  38542. var blockData = getSelectionBlock(editorState).getData();
  38543. return name ? blockData.get(name) : blockData;
  38544. };
  38545. var getSelectionBlockType = exports.getSelectionBlockType = function getSelectionBlockType(editorState) {
  38546. return getSelectionBlock(editorState).getType();
  38547. };
  38548. var getSelectionText = exports.getSelectionText = function getSelectionText(editorState) {
  38549. var selectionState = editorState.getSelection();
  38550. var contentState = editorState.getCurrentContent();
  38551. if (selectionState.isCollapsed() || getSelectionBlockType(editorState) === 'atomic') {
  38552. return '';
  38553. }
  38554. var anchorKey = selectionState.getAnchorKey();
  38555. var currentContentBlock = contentState.getBlockForKey(anchorKey);
  38556. var start = selectionState.getStartOffset();
  38557. var end = selectionState.getEndOffset();
  38558. return currentContentBlock.getText().slice(start, end);
  38559. };
  38560. var toggleSelectionBlockType = exports.toggleSelectionBlockType = function toggleSelectionBlockType(editorState, blockType) {
  38561. if (selectionContainsStrictBlock(editorState)) {
  38562. return editorState;
  38563. }
  38564. return Draft.RichUtils.toggleBlockType(editorState, blockType);
  38565. };
  38566. var getSelectionEntityType = exports.getSelectionEntityType = function getSelectionEntityType(editorState) {
  38567. var entityKey = (0, draftjsUtils$1.getSelectionEntity)(editorState);
  38568. if (entityKey) {
  38569. var entity = editorState.getCurrentContent().getEntity(entityKey);
  38570. return entity ? entity.get('type') : null;
  38571. }
  38572. return null;
  38573. };
  38574. var getSelectionEntityData = exports.getSelectionEntityData = function getSelectionEntityData(editorState, type) {
  38575. var entityKey = (0, draftjsUtils$1.getSelectionEntity)(editorState);
  38576. if (entityKey) {
  38577. var entity = editorState.getCurrentContent().getEntity(entityKey);
  38578. if (entity && entity.get('type') === type) {
  38579. return entity.getData();
  38580. } else {
  38581. return {};
  38582. }
  38583. } else {
  38584. return {};
  38585. }
  38586. };
  38587. var toggleSelectionEntity = exports.toggleSelectionEntity = function toggleSelectionEntity(editorState, entity) {
  38588. var contentState = editorState.getCurrentContent();
  38589. var selectionState = editorState.getSelection();
  38590. if (selectionState.isCollapsed() || getSelectionBlockType(editorState) === 'atomic') {
  38591. return editorState;
  38592. }
  38593. if (!entity || !entity.type || getSelectionEntityType(editorState) === entity.type) {
  38594. return Draft.EditorState.push(editorState, Draft.Modifier.applyEntity(contentState, selectionState, null), 'apply-entity');
  38595. }
  38596. try {
  38597. var nextContentState = contentState.createEntity(entity.type, entity.mutability, entity.data);
  38598. var entityKey = nextContentState.getLastCreatedEntityKey();
  38599. var nextEditorState = Draft.EditorState.set(editorState, {
  38600. currentContent: nextContentState
  38601. });
  38602. return Draft.EditorState.push(nextEditorState, Draft.Modifier.applyEntity(nextContentState, selectionState, entityKey), 'apply-entity');
  38603. } catch (error) {
  38604. console.warn(error);
  38605. return editorState;
  38606. }
  38607. };
  38608. var toggleSelectionLink = exports.toggleSelectionLink = function toggleSelectionLink(editorState, href, target) {
  38609. var contentState = editorState.getCurrentContent();
  38610. var selectionState = editorState.getSelection();
  38611. var entityData = { href: href, target: target };
  38612. if (selectionState.isCollapsed() || getSelectionBlockType(editorState) === 'atomic') {
  38613. return editorState;
  38614. }
  38615. if (href === false) {
  38616. return Draft.RichUtils.toggleLink(editorState, selectionState, null);
  38617. }
  38618. if (href === null) {
  38619. delete entityData.href;
  38620. }
  38621. try {
  38622. var nextContentState = contentState.createEntity('LINK', 'MUTABLE', entityData);
  38623. var entityKey = nextContentState.getLastCreatedEntityKey();
  38624. var nextEditorState = Draft.EditorState.set(editorState, {
  38625. currentContent: nextContentState
  38626. });
  38627. nextEditorState = Draft.RichUtils.toggleLink(nextEditorState, selectionState, entityKey);
  38628. nextEditorState = Draft.EditorState.forceSelection(nextEditorState, selectionState.merge({
  38629. anchorOffset: selectionState.getEndOffset(),
  38630. focusOffset: selectionState.getEndOffset()
  38631. }));
  38632. nextEditorState = Draft.EditorState.push(nextEditorState, Draft.Modifier.insertText(nextEditorState.getCurrentContent(), nextEditorState.getSelection(), ''), 'insert-text');
  38633. return nextEditorState;
  38634. } catch (error) {
  38635. console.warn(error);
  38636. return editorState;
  38637. }
  38638. };
  38639. var getSelectionInlineStyle = exports.getSelectionInlineStyle = function getSelectionInlineStyle(editorState) {
  38640. return editorState.getCurrentInlineStyle();
  38641. };
  38642. var selectionHasInlineStyle = exports.selectionHasInlineStyle = function selectionHasInlineStyle(editorState, style) {
  38643. return getSelectionInlineStyle(editorState).has(style.toUpperCase());
  38644. };
  38645. var toggleSelectionInlineStyle = exports.toggleSelectionInlineStyle = function toggleSelectionInlineStyle(editorState, style) {
  38646. var prefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
  38647. var nextEditorState = editorState;
  38648. style = prefix + style.toUpperCase();
  38649. if (prefix) {
  38650. nextEditorState = updateEachCharacterOfSelection(nextEditorState, function (characterMetadata) {
  38651. return characterMetadata.toJS().style.reduce(function (characterMetadata, characterStyle) {
  38652. if (characterStyle.indexOf(prefix) === 0 && style !== characterStyle) {
  38653. return Draft.CharacterMetadata.removeStyle(characterMetadata, characterStyle);
  38654. } else {
  38655. return characterMetadata;
  38656. }
  38657. }, characterMetadata);
  38658. });
  38659. }
  38660. return Draft.RichUtils.toggleInlineStyle(nextEditorState, style);
  38661. };
  38662. var removeSelectionInlineStyles = exports.removeSelectionInlineStyles = function removeSelectionInlineStyles(editorState) {
  38663. return updateEachCharacterOfSelection(editorState, function (characterMetadata) {
  38664. return characterMetadata.merge({
  38665. style: _immutable2.default.OrderedSet([])
  38666. });
  38667. });
  38668. };
  38669. var toggleSelectionAlignment = exports.toggleSelectionAlignment = function toggleSelectionAlignment(editorState, alignment) {
  38670. return setSelectionBlockData(editorState, {
  38671. textAlign: getSelectionBlockData(editorState, 'textAlign') !== alignment ? alignment : undefined
  38672. });
  38673. };
  38674. var toggleSelectionIndent = exports.toggleSelectionIndent = function toggleSelectionIndent(editorState, textIndent) {
  38675. var maxIndent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 6;
  38676. return textIndent < 0 || textIndent > maxIndent || isNaN(textIndent) ? editorState : setSelectionBlockData(editorState, {
  38677. textIndent: textIndent || undefined
  38678. });
  38679. };
  38680. var increaseSelectionIndent = exports.increaseSelectionIndent = function increaseSelectionIndent(editorState) {
  38681. var maxIndent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 6;
  38682. var currentIndent = getSelectionBlockData(editorState, 'textIndent') || 0;
  38683. return toggleSelectionIndent(editorState, currentIndent + 1, maxIndent);
  38684. };
  38685. var decreaseSelectionIndent = exports.decreaseSelectionIndent = function decreaseSelectionIndent(editorState) {
  38686. var currentIndent = getSelectionBlockData(editorState, 'textIndent') || 0;
  38687. return toggleSelectionIndent(editorState, currentIndent - 1);
  38688. };
  38689. var toggleSelectionColor = exports.toggleSelectionColor = function toggleSelectionColor(editorState, color) {
  38690. return toggleSelectionInlineStyle(editorState, color.replace('#', ''), 'COLOR-');
  38691. };
  38692. var toggleSelectionBackgroundColor = exports.toggleSelectionBackgroundColor = function toggleSelectionBackgroundColor(editorState, color) {
  38693. return toggleSelectionInlineStyle(editorState, color.replace('#', ''), 'BGCOLOR-');
  38694. };
  38695. var toggleSelectionFontSize = exports.toggleSelectionFontSize = function toggleSelectionFontSize(editorState, fontSize) {
  38696. return toggleSelectionInlineStyle(editorState, fontSize, 'FONTSIZE-');
  38697. };
  38698. var toggleSelectionLineHeight = exports.toggleSelectionLineHeight = function toggleSelectionLineHeight(editorState, lineHeight) {
  38699. return toggleSelectionInlineStyle(editorState, lineHeight, 'LINEHEIGHT-');
  38700. };
  38701. var toggleSelectionFontFamily = exports.toggleSelectionFontFamily = function toggleSelectionFontFamily(editorState, fontFamily) {
  38702. return toggleSelectionInlineStyle(editorState, fontFamily, 'FONTFAMILY-');
  38703. };
  38704. var toggleSelectionLetterSpacing = exports.toggleSelectionLetterSpacing = function toggleSelectionLetterSpacing(editorState, letterSpacing) {
  38705. return toggleSelectionInlineStyle(editorState, letterSpacing, 'LETTERSPACING-');
  38706. };
  38707. var insertText = exports.insertText = function insertText(editorState, text, inlineStyle, entity) {
  38708. var selectionState = editorState.getSelection();
  38709. var currentSelectedBlockType = getSelectionBlockType(editorState);
  38710. if (currentSelectedBlockType === 'atomic') {
  38711. return editorState;
  38712. }
  38713. var entityKey = void 0;
  38714. var contentState = editorState.getCurrentContent();
  38715. if (entity && entity.type) {
  38716. contentState = contentState.createEntity(entity.type, entity.mutability || 'MUTABLE', entity.data || entityData);
  38717. entityKey = contentState.getLastCreatedEntityKey();
  38718. }
  38719. if (!selectionState.isCollapsed()) {
  38720. return Draft.EditorState.push(editorState, Draft.Modifier.replaceText(contentState, selectionState, text, inlineStyle, entityKey), 'replace-text');
  38721. } else {
  38722. return Draft.EditorState.push(editorState, Draft.Modifier.insertText(contentState, selectionState, text, inlineStyle, entityKey), 'insert-text');
  38723. }
  38724. };
  38725. var insertHTML = exports.insertHTML = function insertHTML(editorState, htmlString, source) {
  38726. if (!htmlString) {
  38727. return editorState;
  38728. }
  38729. var selectionState = editorState.getSelection();
  38730. var contentState = editorState.getCurrentContent();
  38731. var options = editorState.convertOptions || {};
  38732. try {
  38733. var _convertFromRaw = (0, Draft.convertFromRaw)((0, dist.convertHTMLToRaw)(htmlString, options, source)),
  38734. blockMap = _convertFromRaw.blockMap;
  38735. return Draft.EditorState.push(editorState, Draft.Modifier.replaceWithFragment(contentState, selectionState, blockMap), 'insert-fragment');
  38736. } catch (error) {
  38737. console.warn(error);
  38738. return editorState;
  38739. }
  38740. };
  38741. var insertAtomicBlock = exports.insertAtomicBlock = function insertAtomicBlock(editorState, type) {
  38742. var immutable = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
  38743. var data = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
  38744. if (selectionContainsStrictBlock(editorState)) {
  38745. return insertAtomicBlock(selectNextBlock(editorState, getSelectionBlock(editorState)), type, immutable, data);
  38746. }
  38747. var selectionState = editorState.getSelection();
  38748. var contentState = editorState.getCurrentContent();
  38749. if (!selectionState.isCollapsed() || getSelectionBlockType(editorState) === 'atomic') {
  38750. return editorState;
  38751. }
  38752. var contentStateWithEntity = contentState.createEntity(type, immutable ? 'IMMUTABLE' : 'MUTABLE', data);
  38753. var entityKey = contentStateWithEntity.getLastCreatedEntityKey();
  38754. var newEditorState = Draft.AtomicBlockUtils.insertAtomicBlock(editorState, entityKey, ' ');
  38755. return newEditorState;
  38756. };
  38757. var insertHorizontalLine = exports.insertHorizontalLine = function insertHorizontalLine(editorState) {
  38758. return insertAtomicBlock(editorState, 'HR');
  38759. };
  38760. var insertMedias = exports.insertMedias = function insertMedias(editorState) {
  38761. var medias = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  38762. if (!medias.length) {
  38763. return editorState;
  38764. }
  38765. return medias.reduce(function (editorState, media) {
  38766. var url = media.url,
  38767. link = media.link,
  38768. link_target = media.link_target,
  38769. name = media.name,
  38770. type = media.type,
  38771. width = media.width,
  38772. height = media.height,
  38773. meta = media.meta;
  38774. return insertAtomicBlock(editorState, type, true, { url: url, link: link, link_target: link_target, name: name, type: type, width: width, height: height, meta: meta });
  38775. }, editorState);
  38776. };
  38777. var setMediaData = exports.setMediaData = function setMediaData(editorState, entityKey, data) {
  38778. return Draft.EditorState.push(editorState, editorState.getCurrentContent().mergeEntityData(entityKey, data), 'change-block-data');
  38779. };
  38780. var removeMedia = exports.removeMedia = function removeMedia(editorState, mediaBlock) {
  38781. return removeBlock(editorState, mediaBlock);
  38782. };
  38783. var setMediaPosition = exports.setMediaPosition = function setMediaPosition(editorState, mediaBlock, position) {
  38784. var newPosition = {};
  38785. var float = position.float,
  38786. alignment = position.alignment;
  38787. if (typeof float !== 'undefined') {
  38788. newPosition.float = mediaBlock.getData().get('float') === float ? null : float;
  38789. }
  38790. if (typeof alignment !== 'undefined') {
  38791. newPosition.alignment = mediaBlock.getData().get('alignment') === alignment ? null : alignment;
  38792. }
  38793. return setSelectionBlockData(selectBlock(editorState, mediaBlock), newPosition);
  38794. };
  38795. var clear = exports.clear = function clear(editorState) {
  38796. var contentState = editorState.getCurrentContent();
  38797. var firstBlock = contentState.getFirstBlock();
  38798. var lastBlock = contentState.getLastBlock();
  38799. var allSelected = new Draft.SelectionState({
  38800. anchorKey: firstBlock.getKey(),
  38801. anchorOffset: 0,
  38802. focusKey: lastBlock.getKey(),
  38803. focusOffset: lastBlock.getLength(),
  38804. hasFocus: true
  38805. });
  38806. return Draft.RichUtils.toggleBlockType(Draft.EditorState.push(editorState, Draft.Modifier.removeRange(contentState, allSelected, 'backward'), 'remove-range'), 'unstyled');
  38807. };
  38808. var handleKeyCommand = exports.handleKeyCommand = function handleKeyCommand(editorState, command) {
  38809. return Draft.RichUtils.handleKeyCommand(editorState, command);
  38810. };
  38811. var undo = exports.undo = function undo(editorState) {
  38812. return Draft.EditorState.undo(editorState);
  38813. };
  38814. var redo = exports.redo = function redo(editorState) {
  38815. return Draft.EditorState.redo(editorState);
  38816. };
  38817. });
  38818. unwrapExports(content$1);
  38819. var content_1$1 = content$1.redo;
  38820. var content_2$1 = content$1.undo;
  38821. var content_3$1 = content$1.handleKeyCommand;
  38822. var content_4$1 = content$1.clear;
  38823. var content_5$1 = content$1.setMediaPosition;
  38824. var content_6$1 = content$1.removeMedia;
  38825. var content_7$1 = content$1.setMediaData;
  38826. var content_8$1 = content$1.insertMedias;
  38827. var content_9$1 = content$1.insertHorizontalLine;
  38828. var content_10$1 = content$1.insertAtomicBlock;
  38829. var content_11$1 = content$1.insertHTML;
  38830. var content_12$1 = content$1.insertText;
  38831. var content_13$1 = content$1.toggleSelectionLetterSpacing;
  38832. var content_14$1 = content$1.toggleSelectionFontFamily;
  38833. var content_15$1 = content$1.toggleSelectionLineHeight;
  38834. var content_16$1 = content$1.toggleSelectionFontSize;
  38835. var content_17$1 = content$1.toggleSelectionBackgroundColor;
  38836. var content_18$1 = content$1.toggleSelectionColor;
  38837. var content_19$1 = content$1.decreaseSelectionIndent;
  38838. var content_20$1 = content$1.increaseSelectionIndent;
  38839. var content_21$1 = content$1.toggleSelectionIndent;
  38840. var content_22$1 = content$1.toggleSelectionAlignment;
  38841. var content_23$1 = content$1.removeSelectionInlineStyles;
  38842. var content_24$1 = content$1.toggleSelectionInlineStyle;
  38843. var content_25$1 = content$1.selectionHasInlineStyle;
  38844. var content_26$1 = content$1.getSelectionInlineStyle;
  38845. var content_27$1 = content$1.toggleSelectionLink;
  38846. var content_28$1 = content$1.toggleSelectionEntity;
  38847. var content_29$1 = content$1.getSelectionEntityData;
  38848. var content_30$1 = content$1.getSelectionEntityType;
  38849. var content_31$1 = content$1.toggleSelectionBlockType;
  38850. var content_32$1 = content$1.getSelectionText;
  38851. var content_33$1 = content$1.getSelectionBlockType;
  38852. var content_34$1 = content$1.getSelectionBlockData;
  38853. var content_35$1 = content$1.setSelectionBlockData;
  38854. var content_36$1 = content$1.getSelectedBlocks;
  38855. var content_37$1 = content$1.updateEachCharacterOfSelection;
  38856. var content_38$1 = content$1.getSelectionBlock;
  38857. var content_39$1 = content$1.removeBlock;
  38858. var content_40$1 = content$1.selectNextBlock;
  38859. var content_41$1 = content$1.selectBlock;
  38860. var content_42$1 = content$1.selectionContainsStrictBlock;
  38861. var content_43$1 = content$1.selectionContainsBlockType;
  38862. var content_44$1 = content$1.isSelectionCollapsed;
  38863. var content_45$1 = content$1.createEditorState;
  38864. var content_46$1 = content$1.createEmptyEditorState;
  38865. var content_47$1 = content$1.isEditorState;
  38866. var content_48$1 = content$1.registerStrictBlockType;
  38867. var base$1 = createCommonjsModule(function (module, exports) {
  38868. Object.defineProperty(exports, "__esModule", {
  38869. value: true
  38870. });
  38871. var braftUniqueIndex = 0;
  38872. var UniqueIndex = exports.UniqueIndex = function UniqueIndex() {
  38873. return braftUniqueIndex += 1;
  38874. };
  38875. });
  38876. unwrapExports(base$1);
  38877. var base_1$1 = base$1.UniqueIndex;
  38878. var color$1 = createCommonjsModule(function (module, exports) {
  38879. Object.defineProperty(exports, "__esModule", {
  38880. value: true
  38881. });
  38882. var _namedColors = {
  38883. "aliceblue": "#f0f8ff",
  38884. "antiquewhite": "#faebd7",
  38885. "aqua": "#00ffff",
  38886. "aquamarine": "#7fffd4",
  38887. "azure": "#f0ffff",
  38888. "beige": "#f5f5dc",
  38889. "bisque": "#ffe4c4",
  38890. "black": "#000000",
  38891. "blanchedalmond": "#ffebcd",
  38892. "blue": "#0000ff",
  38893. "blueviolet": "#8a2be2",
  38894. "brown": "#a52a2a",
  38895. "burlywood": "#deb887",
  38896. "cadetblue": "#5f9ea0",
  38897. "chartreuse": "#7fff00",
  38898. "chocolate": "#d2691e",
  38899. "coral": "#ff7f50",
  38900. "cornflowerblue": "#6495ed",
  38901. "cornsilk": "#fff8dc",
  38902. "crimson": "#dc143c",
  38903. "cyan": "#00ffff",
  38904. "darkblue": "#00008b",
  38905. "darkcyan": "#008b8b",
  38906. "darkgoldenrod": "#b8860b",
  38907. "darkgray": "#a9a9a9",
  38908. "darkgreen": "#006400",
  38909. "darkkhaki": "#bdb76b",
  38910. "darkmagenta": "#8b008b",
  38911. "darkolivegreen": "#556b2f",
  38912. "darkorange": "#ff8c00",
  38913. "darkorchid": "#9932cc",
  38914. "darkred": "#8b0000",
  38915. "darksalmon": "#e9967a",
  38916. "darkseagreen": "#8fbc8f",
  38917. "darkslateblue": "#483d8b",
  38918. "darkslategray": "#2f4f4f",
  38919. "darkturquoise": "#00ced1",
  38920. "darkviolet": "#9400d3",
  38921. "deeppink": "#ff1493",
  38922. "deepskyblue": "#00bfff",
  38923. "dimgray": "#696969",
  38924. "dodgerblue": "#1e90ff",
  38925. "firebrick": "#b22222",
  38926. "floralwhite": "#fffaf0",
  38927. "forestgreen": "#228b22",
  38928. "fuchsia": "#ff00ff",
  38929. "gainsboro": "#dcdcdc",
  38930. "ghostwhite": "#f8f8ff",
  38931. "gold": "#ffd700",
  38932. "goldenrod": "#daa520",
  38933. "gray": "#808080",
  38934. "green": "#008000",
  38935. "greenyellow": "#adff2f",
  38936. "honeydew": "#f0fff0",
  38937. "hotpink": "#ff69b4",
  38938. "indianred ": "#cd5c5c",
  38939. "indigo": "#4b0082",
  38940. "ivory": "#fffff0",
  38941. "khaki": "#f0e68c",
  38942. "lavender": "#e6e6fa",
  38943. "lavenderblush": "#fff0f5",
  38944. "lawngreen": "#7cfc00",
  38945. "lemonchiffon": "#fffacd",
  38946. "lightblue": "#add8e6",
  38947. "lightcoral": "#f08080",
  38948. "lightcyan": "#e0ffff",
  38949. "lightgoldenrodyellow": "#fafad2",
  38950. "lightgrey": "#d3d3d3",
  38951. "lightgreen": "#90ee90",
  38952. "lightpink": "#ffb6c1",
  38953. "lightsalmon": "#ffa07a",
  38954. "lightseagreen": "#20b2aa",
  38955. "lightskyblue": "#87cefa",
  38956. "lightslategray": "#778899",
  38957. "lightsteelblue": "#b0c4de",
  38958. "lightyellow": "#ffffe0",
  38959. "lime": "#00ff00",
  38960. "limegreen": "#32cd32",
  38961. "linen": "#faf0e6",
  38962. "magenta": "#ff00ff",
  38963. "maroon": "#800000",
  38964. "mediumaquamarine": "#66cdaa",
  38965. "mediumblue": "#0000cd",
  38966. "mediumorchid": "#ba55d3",
  38967. "mediumpurple": "#9370d8",
  38968. "mediumseagreen": "#3cb371",
  38969. "mediumslateblue": "#7b68ee",
  38970. "mediumspringgreen": "#00fa9a",
  38971. "mediumturquoise": "#48d1cc",
  38972. "mediumvioletred": "#c71585",
  38973. "midnightblue": "#191970",
  38974. "mintcream": "#f5fffa",
  38975. "mistyrose": "#ffe4e1",
  38976. "moccasin": "#ffe4b5",
  38977. "navajowhite": "#ffdead",
  38978. "navy": "#000080",
  38979. "oldlace": "#fdf5e6",
  38980. "olive": "#808000",
  38981. "olivedrab": "#6b8e23",
  38982. "orange": "#ffa500",
  38983. "orangered": "#ff4500",
  38984. "orchid": "#da70d6",
  38985. "palegoldenrod": "#eee8aa",
  38986. "palegreen": "#98fb98",
  38987. "paleturquoise": "#afeeee",
  38988. "palevioletred": "#d87093",
  38989. "papayawhip": "#ffefd5",
  38990. "peachpuff": "#ffdab9",
  38991. "peru": "#cd853f",
  38992. "pink": "#ffc0cb",
  38993. "plum": "#dda0dd",
  38994. "powderblue": "#b0e0e6",
  38995. "purple": "#800080",
  38996. "rebeccapurple": "#663399",
  38997. "red": "#ff0000",
  38998. "rosybrown": "#bc8f8f",
  38999. "royalblue": "#4169e1",
  39000. "saddlebrown": "#8b4513",
  39001. "salmon": "#fa8072",
  39002. "sandybrown": "#f4a460",
  39003. "seagreen": "#2e8b57",
  39004. "seashell": "#fff5ee",
  39005. "sienna": "#a0522d",
  39006. "silver": "#c0c0c0",
  39007. "skyblue": "#87ceeb",
  39008. "slateblue": "#6a5acd",
  39009. "slategray": "#708090",
  39010. "snow": "#fffafa",
  39011. "springgreen": "#00ff7f",
  39012. "steelblue": "#4682b4",
  39013. "tan": "#d2b48c",
  39014. "teal": "#008080",
  39015. "thistle": "#d8bfd8",
  39016. "tomato": "#ff6347",
  39017. "turquoise": "#40e0d0",
  39018. "violet": "#ee82ee",
  39019. "wheat": "#f5deb3",
  39020. "white": "#ffffff",
  39021. "whitesmoke": "#f5f5f5",
  39022. "yellow": "#ffff00",
  39023. "yellowgreen": "#9acd32"
  39024. };
  39025. var _getHexColor = function _getHexColor(color) {
  39026. color = color.replace('color:', '').replace(';', '').replace(' ', '');
  39027. if (/^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/.test(color)) {
  39028. return color;
  39029. } else if (namedColors[color]) {
  39030. return namedColors[color];
  39031. } else if (color.indexOf('rgb') === 0) {
  39032. var rgbArray = color.split(',');
  39033. var convertedColor = rgbArray.length < 3 ? null : '#' + [rgbArray[0], rgbArray[1], rgbArray[2]].map(function (x) {
  39034. var hex = parseInt(x.replace(/\D/g, ''), 10).toString(16);
  39035. return hex.length === 1 ? '0' + hex : hex;
  39036. }).join('');
  39037. return (/^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/.test(convertedColor) ? convertedColor : null
  39038. );
  39039. } else {
  39040. return null;
  39041. }
  39042. };
  39043. var namedColors = exports.namedColors = _namedColors;
  39044. var getHexColor = exports.getHexColor = _getHexColor;
  39045. var detectColorsFromHTMLString = exports.detectColorsFromHTMLString = function detectColorsFromHTMLString(html) {
  39046. return typeof html !== 'string' ? [] : (html.match(/color:[^;]{3,24};/g) || []).map(getHexColor).filter(function (color) {
  39047. return color;
  39048. });
  39049. };
  39050. var detectColorsFromDraftState = exports.detectColorsFromDraftState = function detectColorsFromDraftState(draftState) {
  39051. var result = [];
  39052. if (!draftState || !draftState.blocks || !draftState.blocks.length) {
  39053. return result;
  39054. }
  39055. draftState.blocks.forEach(function (block) {
  39056. if (block && block.inlineStyleRanges && block.inlineStyleRanges.length) {
  39057. block.inlineStyleRanges.forEach(function (inlineStyle) {
  39058. if (inlineStyle.style && inlineStyle.style.indexOf('COLOR-') >= 0) {
  39059. result.push('#' + inlineStyle.style.split('COLOR-')[1]);
  39060. }
  39061. });
  39062. }
  39063. });
  39064. return result.filter(function (color) {
  39065. return color;
  39066. });
  39067. };
  39068. });
  39069. unwrapExports(color$1);
  39070. var color_1$1 = color$1.namedColors;
  39071. var color_2$1 = color$1.getHexColor;
  39072. var color_3$1 = color$1.detectColorsFromHTMLString;
  39073. var color_4$1 = color$1.detectColorsFromDraftState;
  39074. var dist$4 = createCommonjsModule(function (module, exports) {
  39075. Object.defineProperty(exports, "__esModule", {
  39076. value: true
  39077. });
  39078. exports.ColorUtils = exports.BaseUtils = exports.ContentUtils = undefined;
  39079. var _ContentUtils = _interopRequireWildcard(content$1);
  39080. var _BaseUtils = _interopRequireWildcard(base$1);
  39081. var _ColorUtils = _interopRequireWildcard(color$1);
  39082. 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; } }
  39083. var ContentUtils = exports.ContentUtils = _ContentUtils;
  39084. var BaseUtils = exports.BaseUtils = _BaseUtils;
  39085. var ColorUtils = exports.ColorUtils = _ColorUtils;
  39086. });
  39087. unwrapExports(dist$4);
  39088. var dist_1$2 = dist$4.ColorUtils;
  39089. var dist_2$2 = dist$4.BaseUtils;
  39090. var dist_3$2 = dist$4.ContentUtils;
  39091. var emoticon = createCommonjsModule(function (module, exports) {
  39092. (function webpackUniversalModuleDefinition(root, factory) {
  39093. module.exports = factory(React, dist$4);
  39094. })(window, function(__WEBPACK_EXTERNAL_MODULE__1__, __WEBPACK_EXTERNAL_MODULE__6__) {
  39095. return /******/ (function(modules) { // webpackBootstrap
  39096. /******/ // The module cache
  39097. /******/ var installedModules = {};
  39098. /******/
  39099. /******/ // The require function
  39100. /******/ function __webpack_require__(moduleId) {
  39101. /******/
  39102. /******/ // Check if module is in cache
  39103. /******/ if(installedModules[moduleId]) {
  39104. /******/ return installedModules[moduleId].exports;
  39105. /******/ }
  39106. /******/ // Create a new module (and put it into the cache)
  39107. /******/ var module = installedModules[moduleId] = {
  39108. /******/ i: moduleId,
  39109. /******/ l: false,
  39110. /******/ exports: {}
  39111. /******/ };
  39112. /******/
  39113. /******/ // Execute the module function
  39114. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  39115. /******/
  39116. /******/ // Flag the module as loaded
  39117. /******/ module.l = true;
  39118. /******/
  39119. /******/ // Return the exports of the module
  39120. /******/ return module.exports;
  39121. /******/ }
  39122. /******/
  39123. /******/
  39124. /******/ // expose the modules object (__webpack_modules__)
  39125. /******/ __webpack_require__.m = modules;
  39126. /******/
  39127. /******/ // expose the module cache
  39128. /******/ __webpack_require__.c = installedModules;
  39129. /******/
  39130. /******/ // define getter function for harmony exports
  39131. /******/ __webpack_require__.d = function(exports, name, getter) {
  39132. /******/ if(!__webpack_require__.o(exports, name)) {
  39133. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  39134. /******/ }
  39135. /******/ };
  39136. /******/
  39137. /******/ // define __esModule on exports
  39138. /******/ __webpack_require__.r = function(exports) {
  39139. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  39140. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  39141. /******/ }
  39142. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  39143. /******/ };
  39144. /******/
  39145. /******/ // create a fake namespace object
  39146. /******/ // mode & 1: value is a module id, require it
  39147. /******/ // mode & 2: merge all properties of value into the ns
  39148. /******/ // mode & 4: return value when already ns object
  39149. /******/ // mode & 8|1: behave like require
  39150. /******/ __webpack_require__.t = function(value, mode) {
  39151. /******/ if(mode & 1) value = __webpack_require__(value);
  39152. /******/ if(mode & 8) return value;
  39153. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  39154. /******/ var ns = Object.create(null);
  39155. /******/ __webpack_require__.r(ns);
  39156. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  39157. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  39158. /******/ return ns;
  39159. /******/ };
  39160. /******/
  39161. /******/ // getDefaultExport function for compatibility with non-harmony modules
  39162. /******/ __webpack_require__.n = function(module) {
  39163. /******/ var getter = module && module.__esModule ?
  39164. /******/ function getDefault() { return module['default']; } :
  39165. /******/ function getModuleExports() { return module; };
  39166. /******/ __webpack_require__.d(getter, 'a', getter);
  39167. /******/ return getter;
  39168. /******/ };
  39169. /******/
  39170. /******/ // Object.prototype.hasOwnProperty.call
  39171. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  39172. /******/
  39173. /******/ // __webpack_public_path__
  39174. /******/ __webpack_require__.p = "/";
  39175. /******/
  39176. /******/
  39177. /******/ // Load entry module and return exports
  39178. /******/ return __webpack_require__(__webpack_require__.s = 33);
  39179. /******/ })
  39180. /************************************************************************/
  39181. /******/ ({
  39182. /***/ 1:
  39183. /***/ (function(module, exports) {
  39184. module.exports = __WEBPACK_EXTERNAL_MODULE__1__;
  39185. /***/ }),
  39186. /***/ 2:
  39187. /***/ (function(module, exports) {
  39188. function _defineProperty(obj, key, value) {
  39189. if (key in obj) {
  39190. Object.defineProperty(obj, key, {
  39191. value: value,
  39192. enumerable: true,
  39193. configurable: true,
  39194. writable: true
  39195. });
  39196. } else {
  39197. obj[key] = value;
  39198. }
  39199. return obj;
  39200. }
  39201. module.exports = _defineProperty;
  39202. /***/ }),
  39203. /***/ 33:
  39204. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  39205. __webpack_require__.r(__webpack_exports__);
  39206. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "defaultEmoticons", function() { return defaultEmoticons; });
  39207. /* harmony import */ var _babel_runtime_helpers_objectSpread__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(5);
  39208. /* harmony import */ var _babel_runtime_helpers_objectSpread__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_objectSpread__WEBPACK_IMPORTED_MODULE_0__);
  39209. /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1);
  39210. /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_1__);
  39211. /* harmony import */ var braft_utils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6);
  39212. /* harmony import */ var _styles_scss__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(48);
  39213. // https://www.iconfinder.com/iconsets/emoji-18
  39214. 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) {
  39215. return "".concat(item, ".png");
  39216. });
  39217. var insertEmoticon = function insertEmoticon(editor, editorState, src) {
  39218. editor.setValue(braft_utils__WEBPACK_IMPORTED_MODULE_2__["ContentUtils"].insertText(editorState, ' ', null, {
  39219. type: 'EMOTICON',
  39220. mutability: 'IMMUTABLE',
  39221. data: {
  39222. src: src
  39223. }
  39224. }));
  39225. };
  39226. var controlRef = null;
  39227. var bindControlRef = function bindControlRef(ref) {
  39228. return controlRef = ref;
  39229. };
  39230. /* harmony default export */ __webpack_exports__["default"] = (function (options) {
  39231. options = _babel_runtime_helpers_objectSpread__WEBPACK_IMPORTED_MODULE_0___default()({
  39232. emoticons: [],
  39233. closeOnSelect: false,
  39234. closeOnBlur: false
  39235. }, options);
  39236. var _options = options,
  39237. emoticons = _options.emoticons,
  39238. closeOnSelect = _options.closeOnSelect,
  39239. closeOnBlur = _options.closeOnBlur,
  39240. includeEditors = _options.includeEditors,
  39241. excludeEditors = _options.excludeEditors;
  39242. return {
  39243. type: 'entity',
  39244. includeEditors: includeEditors,
  39245. excludeEditors: excludeEditors,
  39246. name: 'EMOTICON',
  39247. control: function control(props) {
  39248. return {
  39249. key: 'EMOTICON',
  39250. replace: 'emoji',
  39251. type: 'dropdown',
  39252. text: react__WEBPACK_IMPORTED_MODULE_1___default.a.createElement("i", {
  39253. className: "bfi-emoji"
  39254. }),
  39255. showArrow: false,
  39256. ref: bindControlRef,
  39257. autoHide: closeOnBlur,
  39258. component: react__WEBPACK_IMPORTED_MODULE_1___default.a.createElement("div", {
  39259. className: "braft-emoticon-picker"
  39260. }, react__WEBPACK_IMPORTED_MODULE_1___default.a.createElement("div", {
  39261. className: "braft-emoticons-list"
  39262. }, emoticons.map(function (item, index) {
  39263. return react__WEBPACK_IMPORTED_MODULE_1___default.a.createElement("img", {
  39264. onClick: function onClick() {
  39265. insertEmoticon(props.editor, props.editorState, item);
  39266. closeOnSelect && controlRef && controlRef.hide();
  39267. },
  39268. key: index,
  39269. src: item
  39270. });
  39271. })))
  39272. };
  39273. },
  39274. mutability: 'IMMUTABLE',
  39275. component: function component(props) {
  39276. var entity = props.contentState.getEntity(props.entityKey);
  39277. var _entity$getData = entity.getData(),
  39278. src = _entity$getData.src;
  39279. return react__WEBPACK_IMPORTED_MODULE_1___default.a.createElement("span", {
  39280. className: "braft-emoticon-in-editor"
  39281. }, react__WEBPACK_IMPORTED_MODULE_1___default.a.createElement("img", {
  39282. src: src
  39283. }), props.children);
  39284. },
  39285. importer: function importer(nodeName, node) {
  39286. if (nodeName.toLowerCase() === 'span' && node.classList && node.classList.contains('braft-emoticon-wrap')) {
  39287. var imgNode = node.querySelector('img');
  39288. var src = imgNode.getAttribute('src'); // 移除img节点以避免生成atomic block
  39289. node.removeChild(imgNode);
  39290. return {
  39291. mutability: 'IMMUTABLE',
  39292. data: {
  39293. src: src
  39294. }
  39295. };
  39296. }
  39297. },
  39298. exporter: function exporter(entityObject, initialText) {
  39299. var src = entityObject.data.src;
  39300. return react__WEBPACK_IMPORTED_MODULE_1___default.a.createElement("span", {
  39301. className: "braft-emoticon-wrap"
  39302. }, react__WEBPACK_IMPORTED_MODULE_1___default.a.createElement("img", {
  39303. src: src
  39304. }), initialText);
  39305. }
  39306. };
  39307. });
  39308. /***/ }),
  39309. /***/ 48:
  39310. /***/ (function(module, exports) {
  39311. // removed by extract-text-webpack-plugin
  39312. /***/ }),
  39313. /***/ 5:
  39314. /***/ (function(module, exports, __webpack_require__) {
  39315. var defineProperty = __webpack_require__(2);
  39316. function _objectSpread(target) {
  39317. for (var i = 1; i < arguments.length; i++) {
  39318. var source = arguments[i] != null ? arguments[i] : {};
  39319. var ownKeys = Object.keys(source);
  39320. if (typeof Object.getOwnPropertySymbols === 'function') {
  39321. ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
  39322. return Object.getOwnPropertyDescriptor(source, sym).enumerable;
  39323. }));
  39324. }
  39325. ownKeys.forEach(function (key) {
  39326. defineProperty(target, key, source[key]);
  39327. });
  39328. }
  39329. return target;
  39330. }
  39331. module.exports = _objectSpread;
  39332. /***/ }),
  39333. /***/ 6:
  39334. /***/ (function(module, exports) {
  39335. module.exports = __WEBPACK_EXTERNAL_MODULE__6__;
  39336. /***/ })
  39337. /******/ });
  39338. });
  39339. });
  39340. var Emoticon = unwrapExports(emoticon);
  39341. var emoticon_1 = emoticon.defaultEmoticons;
  39342. var maxLength = createCommonjsModule(function (module, exports) {
  39343. (function webpackUniversalModuleDefinition(root, factory) {
  39344. module.exports = factory();
  39345. })(window, function() {
  39346. return /******/ (function(modules) { // webpackBootstrap
  39347. /******/ // The module cache
  39348. /******/ var installedModules = {};
  39349. /******/
  39350. /******/ // The require function
  39351. /******/ function __webpack_require__(moduleId) {
  39352. /******/
  39353. /******/ // Check if module is in cache
  39354. /******/ if(installedModules[moduleId]) {
  39355. /******/ return installedModules[moduleId].exports;
  39356. /******/ }
  39357. /******/ // Create a new module (and put it into the cache)
  39358. /******/ var module = installedModules[moduleId] = {
  39359. /******/ i: moduleId,
  39360. /******/ l: false,
  39361. /******/ exports: {}
  39362. /******/ };
  39363. /******/
  39364. /******/ // Execute the module function
  39365. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  39366. /******/
  39367. /******/ // Flag the module as loaded
  39368. /******/ module.l = true;
  39369. /******/
  39370. /******/ // Return the exports of the module
  39371. /******/ return module.exports;
  39372. /******/ }
  39373. /******/
  39374. /******/
  39375. /******/ // expose the modules object (__webpack_modules__)
  39376. /******/ __webpack_require__.m = modules;
  39377. /******/
  39378. /******/ // expose the module cache
  39379. /******/ __webpack_require__.c = installedModules;
  39380. /******/
  39381. /******/ // define getter function for harmony exports
  39382. /******/ __webpack_require__.d = function(exports, name, getter) {
  39383. /******/ if(!__webpack_require__.o(exports, name)) {
  39384. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  39385. /******/ }
  39386. /******/ };
  39387. /******/
  39388. /******/ // define __esModule on exports
  39389. /******/ __webpack_require__.r = function(exports) {
  39390. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  39391. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  39392. /******/ }
  39393. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  39394. /******/ };
  39395. /******/
  39396. /******/ // create a fake namespace object
  39397. /******/ // mode & 1: value is a module id, require it
  39398. /******/ // mode & 2: merge all properties of value into the ns
  39399. /******/ // mode & 4: return value when already ns object
  39400. /******/ // mode & 8|1: behave like require
  39401. /******/ __webpack_require__.t = function(value, mode) {
  39402. /******/ if(mode & 1) value = __webpack_require__(value);
  39403. /******/ if(mode & 8) return value;
  39404. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  39405. /******/ var ns = Object.create(null);
  39406. /******/ __webpack_require__.r(ns);
  39407. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  39408. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  39409. /******/ return ns;
  39410. /******/ };
  39411. /******/
  39412. /******/ // getDefaultExport function for compatibility with non-harmony modules
  39413. /******/ __webpack_require__.n = function(module) {
  39414. /******/ var getter = module && module.__esModule ?
  39415. /******/ function getDefault() { return module['default']; } :
  39416. /******/ function getModuleExports() { return module; };
  39417. /******/ __webpack_require__.d(getter, 'a', getter);
  39418. /******/ return getter;
  39419. /******/ };
  39420. /******/
  39421. /******/ // Object.prototype.hasOwnProperty.call
  39422. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  39423. /******/
  39424. /******/ // __webpack_public_path__
  39425. /******/ __webpack_require__.p = "/";
  39426. /******/
  39427. /******/
  39428. /******/ // Load entry module and return exports
  39429. /******/ return __webpack_require__(__webpack_require__.s = 34);
  39430. /******/ })
  39431. /************************************************************************/
  39432. /******/ ({
  39433. /***/ 2:
  39434. /***/ (function(module, exports) {
  39435. function _defineProperty(obj, key, value) {
  39436. if (key in obj) {
  39437. Object.defineProperty(obj, key, {
  39438. value: value,
  39439. enumerable: true,
  39440. configurable: true,
  39441. writable: true
  39442. });
  39443. } else {
  39444. obj[key] = value;
  39445. }
  39446. return obj;
  39447. }
  39448. module.exports = _defineProperty;
  39449. /***/ }),
  39450. /***/ 34:
  39451. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  39452. __webpack_require__.r(__webpack_exports__);
  39453. /* harmony import */ var _babel_runtime_helpers_objectSpread__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(5);
  39454. /* harmony import */ var _babel_runtime_helpers_objectSpread__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_objectSpread__WEBPACK_IMPORTED_MODULE_0__);
  39455. var getSelectedTextLength = function getSelectedTextLength(editorState) {
  39456. var currentSelection = editorState.getSelection();
  39457. var isCollapsed = currentSelection.isCollapsed();
  39458. var length = 0;
  39459. if (!isCollapsed) {
  39460. var currentContent = editorState.getCurrentContent();
  39461. var startKey = currentSelection.getStartKey();
  39462. var endKey = currentSelection.getEndKey();
  39463. var startBlock = currentContent.getBlockForKey(startKey);
  39464. var isStartAndEndBlockAreTheSame = startKey === endKey;
  39465. var startBlockTextLength = startBlock.getLength();
  39466. var startSelectedTextLength = startBlockTextLength - currentSelection.getStartOffset();
  39467. var endSelectedTextLength = currentSelection.getEndOffset();
  39468. var keyAfterEnd = currentContent.getKeyAfter(endKey);
  39469. if (isStartAndEndBlockAreTheSame) {
  39470. length += currentSelection.getEndOffset() - currentSelection.getStartOffset();
  39471. } else {
  39472. var currentKey = startKey;
  39473. while (currentKey && currentKey !== keyAfterEnd) {
  39474. if (currentKey === startKey) {
  39475. length += startSelectedTextLength + 1;
  39476. } else if (currentKey === endKey) {
  39477. length += endSelectedTextLength;
  39478. } else {
  39479. length += currentContent.getBlockForKey(currentKey).getLength() + 1;
  39480. }
  39481. currentKey = currentContent.getKeyAfter(currentKey);
  39482. }
  39483. }
  39484. }
  39485. return length;
  39486. };
  39487. /* harmony default export */ __webpack_exports__["default"] = (function (options) {
  39488. options = _babel_runtime_helpers_objectSpread__WEBPACK_IMPORTED_MODULE_0___default()({
  39489. defaultValue: Infinity
  39490. }, options);
  39491. var _options = options,
  39492. includeEditors = _options.includeEditors,
  39493. excludeEditors = _options.excludeEditors,
  39494. defaultValue = _options.defaultValue;
  39495. return {
  39496. type: 'prop-interception',
  39497. includeEditors: includeEditors,
  39498. excludeEditors: excludeEditors,
  39499. interceptor: function interceptor(editorProps) {
  39500. var maxLength = editorProps.maxLength || defaultValue;
  39501. editorProps.handleBeforeInput = function (_, editorState) {
  39502. if (maxLength === Infinity) {
  39503. return 'not-handled';
  39504. }
  39505. var currentContentLength = editorState.toText().length;
  39506. var selectedTextLength = getSelectedTextLength(editorState);
  39507. if (currentContentLength - selectedTextLength > maxLength - 1) {
  39508. editorProps.onReachMaxLength && editorProps.onReachMaxLength(maxLength);
  39509. return 'handled';
  39510. }
  39511. };
  39512. editorProps.handlePastedText = function (pastedText, _, editorState) {
  39513. if (maxLength === Infinity) {
  39514. return 'not-handled';
  39515. }
  39516. var currentContentLength = editorState.toText().length;
  39517. var selectedTextLength = getSelectedTextLength(editorState);
  39518. if (currentContentLength + pastedText.length - selectedTextLength > maxLength) {
  39519. editorProps.onReachMaxLength && editorProps.onReachMaxLength(maxLength);
  39520. return 'handled';
  39521. }
  39522. };
  39523. return editorProps;
  39524. }
  39525. };
  39526. });
  39527. /***/ }),
  39528. /***/ 5:
  39529. /***/ (function(module, exports, __webpack_require__) {
  39530. var defineProperty = __webpack_require__(2);
  39531. function _objectSpread(target) {
  39532. for (var i = 1; i < arguments.length; i++) {
  39533. var source = arguments[i] != null ? arguments[i] : {};
  39534. var ownKeys = Object.keys(source);
  39535. if (typeof Object.getOwnPropertySymbols === 'function') {
  39536. ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
  39537. return Object.getOwnPropertyDescriptor(source, sym).enumerable;
  39538. }));
  39539. }
  39540. ownKeys.forEach(function (key) {
  39541. defineProperty(target, key, source[key]);
  39542. });
  39543. }
  39544. return target;
  39545. }
  39546. module.exports = _objectSpread;
  39547. /***/ })
  39548. /******/ });
  39549. });
  39550. });
  39551. var MaxLength = unwrapExports(maxLength);
  39552. var lengthOptions = {
  39553. defaultValue: 100
  39554. };
  39555. BraftEditor.use(MaxLength(lengthOptions));
  39556. var emoticons = emoticon_1.map(function (item) {
  39557. return require("braft-extensions/dist/assets/".concat(item));
  39558. });
  39559. var emotionOptions = {
  39560. emoticons: emoticons,
  39561. closeOnBlur: true,
  39562. closeOnSelect: false
  39563. };
  39564. BraftEditor.use(Emoticon(emotionOptions));
  39565. var BarftEditorPage = function BarftEditorPage(_ref) {
  39566. var value = _ref.value;
  39567. var controls = ["bold", "italic", "underline", "separator", "link", "emoji", "separator", "media"];
  39568. var _useState = useState(BraftEditor.createEditorState(value || "<p>Hello <b>World!</b></p>")),
  39569. _useState2 = _slicedToArray(_useState, 2),
  39570. editorState = _useState2[0],
  39571. setEditorState = _useState2[1];
  39572. return React.createElement("div", {
  39573. className: "editor-wrapper"
  39574. }, React.createElement(BraftEditor, {
  39575. value: editorState,
  39576. onChange: setEditorState,
  39577. controls: controls,
  39578. contentStyle: {
  39579. boxShadow: "inset 0 1px 3px rgba(0,0,0,.1)"
  39580. }
  39581. }));
  39582. };
  39583. export default BarftEditorPage;
  39584. export { BarftEditorPage };
  39585. //# sourceMappingURL=index.js.map