Nessuna descrizione

index.js 1.5MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737
  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 { _ as _defineProperty$1 } from '../defineProperty-18999f8e.js';
  5. import { a as createCommonjsModule, b as commonjsGlobal, u as unwrapExports, c as classnames } from '../index-b8d80d39.js';
  6. import { _ as _slicedToArray } from '../slicedToArray-4cd9e6d3.js';
  7. import server from 'react-dom/server';
  8. /*
  9. object-assign
  10. (c) Sindre Sorhus
  11. @license MIT
  12. */
  13. /* eslint-disable no-unused-vars */
  14. var getOwnPropertySymbols = Object.getOwnPropertySymbols;
  15. var hasOwnProperty = Object.prototype.hasOwnProperty;
  16. var propIsEnumerable = Object.prototype.propertyIsEnumerable;
  17. function toObject(val) {
  18. if (val === null || val === undefined) {
  19. throw new TypeError('Object.assign cannot be called with null or undefined');
  20. }
  21. return Object(val);
  22. }
  23. function shouldUseNative() {
  24. try {
  25. if (!Object.assign) {
  26. return false;
  27. }
  28. // Detect buggy property enumeration order in older V8 versions.
  29. // https://bugs.chromium.org/p/v8/issues/detail?id=4118
  30. var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
  31. test1[5] = 'de';
  32. if (Object.getOwnPropertyNames(test1)[0] === '5') {
  33. return false;
  34. }
  35. // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  36. var test2 = {};
  37. for (var i = 0; i < 10; i++) {
  38. test2['_' + String.fromCharCode(i)] = i;
  39. }
  40. var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
  41. return test2[n];
  42. });
  43. if (order2.join('') !== '0123456789') {
  44. return false;
  45. }
  46. // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  47. var test3 = {};
  48. 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
  49. test3[letter] = letter;
  50. });
  51. if (Object.keys(Object.assign({}, test3)).join('') !==
  52. 'abcdefghijklmnopqrst') {
  53. return false;
  54. }
  55. return true;
  56. } catch (err) {
  57. // We don't expect any of the above to throw, but better to be safe.
  58. return false;
  59. }
  60. }
  61. var objectAssign = shouldUseNative() ? Object.assign : function (target, source) {
  62. var from;
  63. var to = toObject(target);
  64. var symbols;
  65. for (var s = 1; s < arguments.length; s++) {
  66. from = Object(arguments[s]);
  67. for (var key in from) {
  68. if (hasOwnProperty.call(from, key)) {
  69. to[key] = from[key];
  70. }
  71. }
  72. if (getOwnPropertySymbols) {
  73. symbols = getOwnPropertySymbols(from);
  74. for (var i = 0; i < symbols.length; i++) {
  75. if (propIsEnumerable.call(from, symbols[i])) {
  76. to[symbols[i]] = from[symbols[i]];
  77. }
  78. }
  79. }
  80. }
  81. return to;
  82. };
  83. var immutable = createCommonjsModule(function (module, exports) {
  84. /**
  85. * Copyright (c) 2014-2015, Facebook, Inc.
  86. * All rights reserved.
  87. *
  88. * This source code is licensed under the BSD-style license found in the
  89. * LICENSE file in the root directory of this source tree. An additional grant
  90. * of patent rights can be found in the PATENTS file in the same directory.
  91. */
  92. (function (global, factory) {
  93. module.exports = factory() ;
  94. }(commonjsGlobal, function () {var SLICE$0 = Array.prototype.slice;
  95. function createClass(ctor, superClass) {
  96. if (superClass) {
  97. ctor.prototype = Object.create(superClass.prototype);
  98. }
  99. ctor.prototype.constructor = ctor;
  100. }
  101. function Iterable(value) {
  102. return isIterable(value) ? value : Seq(value);
  103. }
  104. createClass(KeyedIterable, Iterable);
  105. function KeyedIterable(value) {
  106. return isKeyed(value) ? value : KeyedSeq(value);
  107. }
  108. createClass(IndexedIterable, Iterable);
  109. function IndexedIterable(value) {
  110. return isIndexed(value) ? value : IndexedSeq(value);
  111. }
  112. createClass(SetIterable, Iterable);
  113. function SetIterable(value) {
  114. return isIterable(value) && !isAssociative(value) ? value : SetSeq(value);
  115. }
  116. function isIterable(maybeIterable) {
  117. return !!(maybeIterable && maybeIterable[IS_ITERABLE_SENTINEL]);
  118. }
  119. function isKeyed(maybeKeyed) {
  120. return !!(maybeKeyed && maybeKeyed[IS_KEYED_SENTINEL]);
  121. }
  122. function isIndexed(maybeIndexed) {
  123. return !!(maybeIndexed && maybeIndexed[IS_INDEXED_SENTINEL]);
  124. }
  125. function isAssociative(maybeAssociative) {
  126. return isKeyed(maybeAssociative) || isIndexed(maybeAssociative);
  127. }
  128. function isOrdered(maybeOrdered) {
  129. return !!(maybeOrdered && maybeOrdered[IS_ORDERED_SENTINEL]);
  130. }
  131. Iterable.isIterable = isIterable;
  132. Iterable.isKeyed = isKeyed;
  133. Iterable.isIndexed = isIndexed;
  134. Iterable.isAssociative = isAssociative;
  135. Iterable.isOrdered = isOrdered;
  136. Iterable.Keyed = KeyedIterable;
  137. Iterable.Indexed = IndexedIterable;
  138. Iterable.Set = SetIterable;
  139. var IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
  140. var IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
  141. var IS_INDEXED_SENTINEL = '@@__IMMUTABLE_INDEXED__@@';
  142. var IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
  143. // Used for setting prototype methods that IE8 chokes on.
  144. var DELETE = 'delete';
  145. // Constants describing the size of trie nodes.
  146. var SHIFT = 5; // Resulted in best performance after ______?
  147. var SIZE = 1 << SHIFT;
  148. var MASK = SIZE - 1;
  149. // A consistent shared value representing "not set" which equals nothing other
  150. // than itself, and nothing that could be provided externally.
  151. var NOT_SET = {};
  152. // Boolean references, Rough equivalent of `bool &`.
  153. var CHANGE_LENGTH = { value: false };
  154. var DID_ALTER = { value: false };
  155. function MakeRef(ref) {
  156. ref.value = false;
  157. return ref;
  158. }
  159. function SetRef(ref) {
  160. ref && (ref.value = true);
  161. }
  162. // A function which returns a value representing an "owner" for transient writes
  163. // to tries. The return value will only ever equal itself, and will not equal
  164. // the return of any subsequent call of this function.
  165. function OwnerID() {}
  166. // http://jsperf.com/copy-array-inline
  167. function arrCopy(arr, offset) {
  168. offset = offset || 0;
  169. var len = Math.max(0, arr.length - offset);
  170. var newArr = new Array(len);
  171. for (var ii = 0; ii < len; ii++) {
  172. newArr[ii] = arr[ii + offset];
  173. }
  174. return newArr;
  175. }
  176. function ensureSize(iter) {
  177. if (iter.size === undefined) {
  178. iter.size = iter.__iterate(returnTrue);
  179. }
  180. return iter.size;
  181. }
  182. function wrapIndex(iter, index) {
  183. // This implements "is array index" which the ECMAString spec defines as:
  184. //
  185. // A String property name P is an array index if and only if
  186. // ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal
  187. // to 2^32−1.
  188. //
  189. // http://www.ecma-international.org/ecma-262/6.0/#sec-array-exotic-objects
  190. if (typeof index !== 'number') {
  191. var uint32Index = index >>> 0; // N >>> 0 is shorthand for ToUint32
  192. if ('' + uint32Index !== index || uint32Index === 4294967295) {
  193. return NaN;
  194. }
  195. index = uint32Index;
  196. }
  197. return index < 0 ? ensureSize(iter) + index : index;
  198. }
  199. function returnTrue() {
  200. return true;
  201. }
  202. function wholeSlice(begin, end, size) {
  203. return (begin === 0 || (size !== undefined && begin <= -size)) &&
  204. (end === undefined || (size !== undefined && end >= size));
  205. }
  206. function resolveBegin(begin, size) {
  207. return resolveIndex(begin, size, 0);
  208. }
  209. function resolveEnd(end, size) {
  210. return resolveIndex(end, size, size);
  211. }
  212. function resolveIndex(index, size, defaultIndex) {
  213. return index === undefined ?
  214. defaultIndex :
  215. index < 0 ?
  216. Math.max(0, size + index) :
  217. size === undefined ?
  218. index :
  219. Math.min(size, index);
  220. }
  221. /* global Symbol */
  222. var ITERATE_KEYS = 0;
  223. var ITERATE_VALUES = 1;
  224. var ITERATE_ENTRIES = 2;
  225. var REAL_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
  226. var FAUX_ITERATOR_SYMBOL = '@@iterator';
  227. var ITERATOR_SYMBOL = REAL_ITERATOR_SYMBOL || FAUX_ITERATOR_SYMBOL;
  228. function Iterator(next) {
  229. this.next = next;
  230. }
  231. Iterator.prototype.toString = function() {
  232. return '[Iterator]';
  233. };
  234. Iterator.KEYS = ITERATE_KEYS;
  235. Iterator.VALUES = ITERATE_VALUES;
  236. Iterator.ENTRIES = ITERATE_ENTRIES;
  237. Iterator.prototype.inspect =
  238. Iterator.prototype.toSource = function () { return this.toString(); };
  239. Iterator.prototype[ITERATOR_SYMBOL] = function () {
  240. return this;
  241. };
  242. function iteratorValue(type, k, v, iteratorResult) {
  243. var value = type === 0 ? k : type === 1 ? v : [k, v];
  244. iteratorResult ? (iteratorResult.value = value) : (iteratorResult = {
  245. value: value, done: false
  246. });
  247. return iteratorResult;
  248. }
  249. function iteratorDone() {
  250. return { value: undefined, done: true };
  251. }
  252. function hasIterator(maybeIterable) {
  253. return !!getIteratorFn(maybeIterable);
  254. }
  255. function isIterator(maybeIterator) {
  256. return maybeIterator && typeof maybeIterator.next === 'function';
  257. }
  258. function getIterator(iterable) {
  259. var iteratorFn = getIteratorFn(iterable);
  260. return iteratorFn && iteratorFn.call(iterable);
  261. }
  262. function getIteratorFn(iterable) {
  263. var iteratorFn = iterable && (
  264. (REAL_ITERATOR_SYMBOL && iterable[REAL_ITERATOR_SYMBOL]) ||
  265. iterable[FAUX_ITERATOR_SYMBOL]
  266. );
  267. if (typeof iteratorFn === 'function') {
  268. return iteratorFn;
  269. }
  270. }
  271. function isArrayLike(value) {
  272. return value && typeof value.length === 'number';
  273. }
  274. createClass(Seq, Iterable);
  275. function Seq(value) {
  276. return value === null || value === undefined ? emptySequence() :
  277. isIterable(value) ? value.toSeq() : seqFromValue(value);
  278. }
  279. Seq.of = function(/*...values*/) {
  280. return Seq(arguments);
  281. };
  282. Seq.prototype.toSeq = function() {
  283. return this;
  284. };
  285. Seq.prototype.toString = function() {
  286. return this.__toString('Seq {', '}');
  287. };
  288. Seq.prototype.cacheResult = function() {
  289. if (!this._cache && this.__iterateUncached) {
  290. this._cache = this.entrySeq().toArray();
  291. this.size = this._cache.length;
  292. }
  293. return this;
  294. };
  295. // abstract __iterateUncached(fn, reverse)
  296. Seq.prototype.__iterate = function(fn, reverse) {
  297. return seqIterate(this, fn, reverse, true);
  298. };
  299. // abstract __iteratorUncached(type, reverse)
  300. Seq.prototype.__iterator = function(type, reverse) {
  301. return seqIterator(this, type, reverse, true);
  302. };
  303. createClass(KeyedSeq, Seq);
  304. function KeyedSeq(value) {
  305. return value === null || value === undefined ?
  306. emptySequence().toKeyedSeq() :
  307. isIterable(value) ?
  308. (isKeyed(value) ? value.toSeq() : value.fromEntrySeq()) :
  309. keyedSeqFromValue(value);
  310. }
  311. KeyedSeq.prototype.toKeyedSeq = function() {
  312. return this;
  313. };
  314. createClass(IndexedSeq, Seq);
  315. function IndexedSeq(value) {
  316. return value === null || value === undefined ? emptySequence() :
  317. !isIterable(value) ? indexedSeqFromValue(value) :
  318. isKeyed(value) ? value.entrySeq() : value.toIndexedSeq();
  319. }
  320. IndexedSeq.of = function(/*...values*/) {
  321. return IndexedSeq(arguments);
  322. };
  323. IndexedSeq.prototype.toIndexedSeq = function() {
  324. return this;
  325. };
  326. IndexedSeq.prototype.toString = function() {
  327. return this.__toString('Seq [', ']');
  328. };
  329. IndexedSeq.prototype.__iterate = function(fn, reverse) {
  330. return seqIterate(this, fn, reverse, false);
  331. };
  332. IndexedSeq.prototype.__iterator = function(type, reverse) {
  333. return seqIterator(this, type, reverse, false);
  334. };
  335. createClass(SetSeq, Seq);
  336. function SetSeq(value) {
  337. return (
  338. value === null || value === undefined ? emptySequence() :
  339. !isIterable(value) ? indexedSeqFromValue(value) :
  340. isKeyed(value) ? value.entrySeq() : value
  341. ).toSetSeq();
  342. }
  343. SetSeq.of = function(/*...values*/) {
  344. return SetSeq(arguments);
  345. };
  346. SetSeq.prototype.toSetSeq = function() {
  347. return this;
  348. };
  349. Seq.isSeq = isSeq;
  350. Seq.Keyed = KeyedSeq;
  351. Seq.Set = SetSeq;
  352. Seq.Indexed = IndexedSeq;
  353. var IS_SEQ_SENTINEL = '@@__IMMUTABLE_SEQ__@@';
  354. Seq.prototype[IS_SEQ_SENTINEL] = true;
  355. createClass(ArraySeq, IndexedSeq);
  356. function ArraySeq(array) {
  357. this._array = array;
  358. this.size = array.length;
  359. }
  360. ArraySeq.prototype.get = function(index, notSetValue) {
  361. return this.has(index) ? this._array[wrapIndex(this, index)] : notSetValue;
  362. };
  363. ArraySeq.prototype.__iterate = function(fn, reverse) {
  364. var array = this._array;
  365. var maxIndex = array.length - 1;
  366. for (var ii = 0; ii <= maxIndex; ii++) {
  367. if (fn(array[reverse ? maxIndex - ii : ii], ii, this) === false) {
  368. return ii + 1;
  369. }
  370. }
  371. return ii;
  372. };
  373. ArraySeq.prototype.__iterator = function(type, reverse) {
  374. var array = this._array;
  375. var maxIndex = array.length - 1;
  376. var ii = 0;
  377. return new Iterator(function()
  378. {return ii > maxIndex ?
  379. iteratorDone() :
  380. iteratorValue(type, ii, array[reverse ? maxIndex - ii++ : ii++])}
  381. );
  382. };
  383. createClass(ObjectSeq, KeyedSeq);
  384. function ObjectSeq(object) {
  385. var keys = Object.keys(object);
  386. this._object = object;
  387. this._keys = keys;
  388. this.size = keys.length;
  389. }
  390. ObjectSeq.prototype.get = function(key, notSetValue) {
  391. if (notSetValue !== undefined && !this.has(key)) {
  392. return notSetValue;
  393. }
  394. return this._object[key];
  395. };
  396. ObjectSeq.prototype.has = function(key) {
  397. return this._object.hasOwnProperty(key);
  398. };
  399. ObjectSeq.prototype.__iterate = function(fn, reverse) {
  400. var object = this._object;
  401. var keys = this._keys;
  402. var maxIndex = keys.length - 1;
  403. for (var ii = 0; ii <= maxIndex; ii++) {
  404. var key = keys[reverse ? maxIndex - ii : ii];
  405. if (fn(object[key], key, this) === false) {
  406. return ii + 1;
  407. }
  408. }
  409. return ii;
  410. };
  411. ObjectSeq.prototype.__iterator = function(type, reverse) {
  412. var object = this._object;
  413. var keys = this._keys;
  414. var maxIndex = keys.length - 1;
  415. var ii = 0;
  416. return new Iterator(function() {
  417. var key = keys[reverse ? maxIndex - ii : ii];
  418. return ii++ > maxIndex ?
  419. iteratorDone() :
  420. iteratorValue(type, key, object[key]);
  421. });
  422. };
  423. ObjectSeq.prototype[IS_ORDERED_SENTINEL] = true;
  424. createClass(IterableSeq, IndexedSeq);
  425. function IterableSeq(iterable) {
  426. this._iterable = iterable;
  427. this.size = iterable.length || iterable.size;
  428. }
  429. IterableSeq.prototype.__iterateUncached = function(fn, reverse) {
  430. if (reverse) {
  431. return this.cacheResult().__iterate(fn, reverse);
  432. }
  433. var iterable = this._iterable;
  434. var iterator = getIterator(iterable);
  435. var iterations = 0;
  436. if (isIterator(iterator)) {
  437. var step;
  438. while (!(step = iterator.next()).done) {
  439. if (fn(step.value, iterations++, this) === false) {
  440. break;
  441. }
  442. }
  443. }
  444. return iterations;
  445. };
  446. IterableSeq.prototype.__iteratorUncached = function(type, reverse) {
  447. if (reverse) {
  448. return this.cacheResult().__iterator(type, reverse);
  449. }
  450. var iterable = this._iterable;
  451. var iterator = getIterator(iterable);
  452. if (!isIterator(iterator)) {
  453. return new Iterator(iteratorDone);
  454. }
  455. var iterations = 0;
  456. return new Iterator(function() {
  457. var step = iterator.next();
  458. return step.done ? step : iteratorValue(type, iterations++, step.value);
  459. });
  460. };
  461. createClass(IteratorSeq, IndexedSeq);
  462. function IteratorSeq(iterator) {
  463. this._iterator = iterator;
  464. this._iteratorCache = [];
  465. }
  466. IteratorSeq.prototype.__iterateUncached = function(fn, reverse) {
  467. if (reverse) {
  468. return this.cacheResult().__iterate(fn, reverse);
  469. }
  470. var iterator = this._iterator;
  471. var cache = this._iteratorCache;
  472. var iterations = 0;
  473. while (iterations < cache.length) {
  474. if (fn(cache[iterations], iterations++, this) === false) {
  475. return iterations;
  476. }
  477. }
  478. var step;
  479. while (!(step = iterator.next()).done) {
  480. var val = step.value;
  481. cache[iterations] = val;
  482. if (fn(val, iterations++, this) === false) {
  483. break;
  484. }
  485. }
  486. return iterations;
  487. };
  488. IteratorSeq.prototype.__iteratorUncached = function(type, reverse) {
  489. if (reverse) {
  490. return this.cacheResult().__iterator(type, reverse);
  491. }
  492. var iterator = this._iterator;
  493. var cache = this._iteratorCache;
  494. var iterations = 0;
  495. return new Iterator(function() {
  496. if (iterations >= cache.length) {
  497. var step = iterator.next();
  498. if (step.done) {
  499. return step;
  500. }
  501. cache[iterations] = step.value;
  502. }
  503. return iteratorValue(type, iterations, cache[iterations++]);
  504. });
  505. };
  506. // # pragma Helper functions
  507. function isSeq(maybeSeq) {
  508. return !!(maybeSeq && maybeSeq[IS_SEQ_SENTINEL]);
  509. }
  510. var EMPTY_SEQ;
  511. function emptySequence() {
  512. return EMPTY_SEQ || (EMPTY_SEQ = new ArraySeq([]));
  513. }
  514. function keyedSeqFromValue(value) {
  515. var seq =
  516. Array.isArray(value) ? new ArraySeq(value).fromEntrySeq() :
  517. isIterator(value) ? new IteratorSeq(value).fromEntrySeq() :
  518. hasIterator(value) ? new IterableSeq(value).fromEntrySeq() :
  519. typeof value === 'object' ? new ObjectSeq(value) :
  520. undefined;
  521. if (!seq) {
  522. throw new TypeError(
  523. 'Expected Array or iterable object of [k, v] entries, '+
  524. 'or keyed object: ' + value
  525. );
  526. }
  527. return seq;
  528. }
  529. function indexedSeqFromValue(value) {
  530. var seq = maybeIndexedSeqFromValue(value);
  531. if (!seq) {
  532. throw new TypeError(
  533. 'Expected Array or iterable object of values: ' + value
  534. );
  535. }
  536. return seq;
  537. }
  538. function seqFromValue(value) {
  539. var seq = maybeIndexedSeqFromValue(value) ||
  540. (typeof value === 'object' && new ObjectSeq(value));
  541. if (!seq) {
  542. throw new TypeError(
  543. 'Expected Array or iterable object of values, or keyed object: ' + value
  544. );
  545. }
  546. return seq;
  547. }
  548. function maybeIndexedSeqFromValue(value) {
  549. return (
  550. isArrayLike(value) ? new ArraySeq(value) :
  551. isIterator(value) ? new IteratorSeq(value) :
  552. hasIterator(value) ? new IterableSeq(value) :
  553. undefined
  554. );
  555. }
  556. function seqIterate(seq, fn, reverse, useKeys) {
  557. var cache = seq._cache;
  558. if (cache) {
  559. var maxIndex = cache.length - 1;
  560. for (var ii = 0; ii <= maxIndex; ii++) {
  561. var entry = cache[reverse ? maxIndex - ii : ii];
  562. if (fn(entry[1], useKeys ? entry[0] : ii, seq) === false) {
  563. return ii + 1;
  564. }
  565. }
  566. return ii;
  567. }
  568. return seq.__iterateUncached(fn, reverse);
  569. }
  570. function seqIterator(seq, type, reverse, useKeys) {
  571. var cache = seq._cache;
  572. if (cache) {
  573. var maxIndex = cache.length - 1;
  574. var ii = 0;
  575. return new Iterator(function() {
  576. var entry = cache[reverse ? maxIndex - ii : ii];
  577. return ii++ > maxIndex ?
  578. iteratorDone() :
  579. iteratorValue(type, useKeys ? entry[0] : ii - 1, entry[1]);
  580. });
  581. }
  582. return seq.__iteratorUncached(type, reverse);
  583. }
  584. function fromJS(json, converter) {
  585. return converter ?
  586. fromJSWith(converter, json, '', {'': json}) :
  587. fromJSDefault(json);
  588. }
  589. function fromJSWith(converter, json, key, parentJSON) {
  590. if (Array.isArray(json)) {
  591. return converter.call(parentJSON, key, IndexedSeq(json).map(function(v, k) {return fromJSWith(converter, v, k, json)}));
  592. }
  593. if (isPlainObj(json)) {
  594. return converter.call(parentJSON, key, KeyedSeq(json).map(function(v, k) {return fromJSWith(converter, v, k, json)}));
  595. }
  596. return json;
  597. }
  598. function fromJSDefault(json) {
  599. if (Array.isArray(json)) {
  600. return IndexedSeq(json).map(fromJSDefault).toList();
  601. }
  602. if (isPlainObj(json)) {
  603. return KeyedSeq(json).map(fromJSDefault).toMap();
  604. }
  605. return json;
  606. }
  607. function isPlainObj(value) {
  608. return value && (value.constructor === Object || value.constructor === undefined);
  609. }
  610. /**
  611. * An extension of the "same-value" algorithm as [described for use by ES6 Map
  612. * and Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map#Key_equality)
  613. *
  614. * NaN is considered the same as NaN, however -0 and 0 are considered the same
  615. * value, which is different from the algorithm described by
  616. * [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is).
  617. *
  618. * This is extended further to allow Objects to describe the values they
  619. * represent, by way of `valueOf` or `equals` (and `hashCode`).
  620. *
  621. * Note: because of this extension, the key equality of Immutable.Map and the
  622. * value equality of Immutable.Set will differ from ES6 Map and Set.
  623. *
  624. * ### Defining custom values
  625. *
  626. * The easiest way to describe the value an object represents is by implementing
  627. * `valueOf`. For example, `Date` represents a value by returning a unix
  628. * timestamp for `valueOf`:
  629. *
  630. * var date1 = new Date(1234567890000); // Fri Feb 13 2009 ...
  631. * var date2 = new Date(1234567890000);
  632. * date1.valueOf(); // 1234567890000
  633. * assert( date1 !== date2 );
  634. * assert( Immutable.is( date1, date2 ) );
  635. *
  636. * Note: overriding `valueOf` may have other implications if you use this object
  637. * where JavaScript expects a primitive, such as implicit string coercion.
  638. *
  639. * For more complex types, especially collections, implementing `valueOf` may
  640. * not be performant. An alternative is to implement `equals` and `hashCode`.
  641. *
  642. * `equals` takes another object, presumably of similar type, and returns true
  643. * if the it is equal. Equality is symmetrical, so the same result should be
  644. * returned if this and the argument are flipped.
  645. *
  646. * assert( a.equals(b) === b.equals(a) );
  647. *
  648. * `hashCode` returns a 32bit integer number representing the object which will
  649. * be used to determine how to store the value object in a Map or Set. You must
  650. * provide both or neither methods, one must not exist without the other.
  651. *
  652. * Also, an important relationship between these methods must be upheld: if two
  653. * values are equal, they *must* return the same hashCode. If the values are not
  654. * equal, they might have the same hashCode; this is called a hash collision,
  655. * and while undesirable for performance reasons, it is acceptable.
  656. *
  657. * if (a.equals(b)) {
  658. * assert( a.hashCode() === b.hashCode() );
  659. * }
  660. *
  661. * All Immutable collections implement `equals` and `hashCode`.
  662. *
  663. */
  664. function is(valueA, valueB) {
  665. if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
  666. return true;
  667. }
  668. if (!valueA || !valueB) {
  669. return false;
  670. }
  671. if (typeof valueA.valueOf === 'function' &&
  672. typeof valueB.valueOf === 'function') {
  673. valueA = valueA.valueOf();
  674. valueB = valueB.valueOf();
  675. if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
  676. return true;
  677. }
  678. if (!valueA || !valueB) {
  679. return false;
  680. }
  681. }
  682. if (typeof valueA.equals === 'function' &&
  683. typeof valueB.equals === 'function' &&
  684. valueA.equals(valueB)) {
  685. return true;
  686. }
  687. return false;
  688. }
  689. function deepEqual(a, b) {
  690. if (a === b) {
  691. return true;
  692. }
  693. if (
  694. !isIterable(b) ||
  695. a.size !== undefined && b.size !== undefined && a.size !== b.size ||
  696. a.__hash !== undefined && b.__hash !== undefined && a.__hash !== b.__hash ||
  697. isKeyed(a) !== isKeyed(b) ||
  698. isIndexed(a) !== isIndexed(b) ||
  699. isOrdered(a) !== isOrdered(b)
  700. ) {
  701. return false;
  702. }
  703. if (a.size === 0 && b.size === 0) {
  704. return true;
  705. }
  706. var notAssociative = !isAssociative(a);
  707. if (isOrdered(a)) {
  708. var entries = a.entries();
  709. return b.every(function(v, k) {
  710. var entry = entries.next().value;
  711. return entry && is(entry[1], v) && (notAssociative || is(entry[0], k));
  712. }) && entries.next().done;
  713. }
  714. var flipped = false;
  715. if (a.size === undefined) {
  716. if (b.size === undefined) {
  717. if (typeof a.cacheResult === 'function') {
  718. a.cacheResult();
  719. }
  720. } else {
  721. flipped = true;
  722. var _ = a;
  723. a = b;
  724. b = _;
  725. }
  726. }
  727. var allEqual = true;
  728. var bSize = b.__iterate(function(v, k) {
  729. if (notAssociative ? !a.has(v) :
  730. flipped ? !is(v, a.get(k, NOT_SET)) : !is(a.get(k, NOT_SET), v)) {
  731. allEqual = false;
  732. return false;
  733. }
  734. });
  735. return allEqual && a.size === bSize;
  736. }
  737. createClass(Repeat, IndexedSeq);
  738. function Repeat(value, times) {
  739. if (!(this instanceof Repeat)) {
  740. return new Repeat(value, times);
  741. }
  742. this._value = value;
  743. this.size = times === undefined ? Infinity : Math.max(0, times);
  744. if (this.size === 0) {
  745. if (EMPTY_REPEAT) {
  746. return EMPTY_REPEAT;
  747. }
  748. EMPTY_REPEAT = this;
  749. }
  750. }
  751. Repeat.prototype.toString = function() {
  752. if (this.size === 0) {
  753. return 'Repeat []';
  754. }
  755. return 'Repeat [ ' + this._value + ' ' + this.size + ' times ]';
  756. };
  757. Repeat.prototype.get = function(index, notSetValue) {
  758. return this.has(index) ? this._value : notSetValue;
  759. };
  760. Repeat.prototype.includes = function(searchValue) {
  761. return is(this._value, searchValue);
  762. };
  763. Repeat.prototype.slice = function(begin, end) {
  764. var size = this.size;
  765. return wholeSlice(begin, end, size) ? this :
  766. new Repeat(this._value, resolveEnd(end, size) - resolveBegin(begin, size));
  767. };
  768. Repeat.prototype.reverse = function() {
  769. return this;
  770. };
  771. Repeat.prototype.indexOf = function(searchValue) {
  772. if (is(this._value, searchValue)) {
  773. return 0;
  774. }
  775. return -1;
  776. };
  777. Repeat.prototype.lastIndexOf = function(searchValue) {
  778. if (is(this._value, searchValue)) {
  779. return this.size;
  780. }
  781. return -1;
  782. };
  783. Repeat.prototype.__iterate = function(fn, reverse) {
  784. for (var ii = 0; ii < this.size; ii++) {
  785. if (fn(this._value, ii, this) === false) {
  786. return ii + 1;
  787. }
  788. }
  789. return ii;
  790. };
  791. Repeat.prototype.__iterator = function(type, reverse) {var this$0 = this;
  792. var ii = 0;
  793. return new Iterator(function()
  794. {return ii < this$0.size ? iteratorValue(type, ii++, this$0._value) : iteratorDone()}
  795. );
  796. };
  797. Repeat.prototype.equals = function(other) {
  798. return other instanceof Repeat ?
  799. is(this._value, other._value) :
  800. deepEqual(other);
  801. };
  802. var EMPTY_REPEAT;
  803. function invariant(condition, error) {
  804. if (!condition) throw new Error(error);
  805. }
  806. createClass(Range, IndexedSeq);
  807. function Range(start, end, step) {
  808. if (!(this instanceof Range)) {
  809. return new Range(start, end, step);
  810. }
  811. invariant(step !== 0, 'Cannot step a Range by 0');
  812. start = start || 0;
  813. if (end === undefined) {
  814. end = Infinity;
  815. }
  816. step = step === undefined ? 1 : Math.abs(step);
  817. if (end < start) {
  818. step = -step;
  819. }
  820. this._start = start;
  821. this._end = end;
  822. this._step = step;
  823. this.size = Math.max(0, Math.ceil((end - start) / step - 1) + 1);
  824. if (this.size === 0) {
  825. if (EMPTY_RANGE) {
  826. return EMPTY_RANGE;
  827. }
  828. EMPTY_RANGE = this;
  829. }
  830. }
  831. Range.prototype.toString = function() {
  832. if (this.size === 0) {
  833. return 'Range []';
  834. }
  835. return 'Range [ ' +
  836. this._start + '...' + this._end +
  837. (this._step > 1 ? ' by ' + this._step : '') +
  838. ' ]';
  839. };
  840. Range.prototype.get = function(index, notSetValue) {
  841. return this.has(index) ?
  842. this._start + wrapIndex(this, index) * this._step :
  843. notSetValue;
  844. };
  845. Range.prototype.includes = function(searchValue) {
  846. var possibleIndex = (searchValue - this._start) / this._step;
  847. return possibleIndex >= 0 &&
  848. possibleIndex < this.size &&
  849. possibleIndex === Math.floor(possibleIndex);
  850. };
  851. Range.prototype.slice = function(begin, end) {
  852. if (wholeSlice(begin, end, this.size)) {
  853. return this;
  854. }
  855. begin = resolveBegin(begin, this.size);
  856. end = resolveEnd(end, this.size);
  857. if (end <= begin) {
  858. return new Range(0, 0);
  859. }
  860. return new Range(this.get(begin, this._end), this.get(end, this._end), this._step);
  861. };
  862. Range.prototype.indexOf = function(searchValue) {
  863. var offsetValue = searchValue - this._start;
  864. if (offsetValue % this._step === 0) {
  865. var index = offsetValue / this._step;
  866. if (index >= 0 && index < this.size) {
  867. return index
  868. }
  869. }
  870. return -1;
  871. };
  872. Range.prototype.lastIndexOf = function(searchValue) {
  873. return this.indexOf(searchValue);
  874. };
  875. Range.prototype.__iterate = function(fn, reverse) {
  876. var maxIndex = this.size - 1;
  877. var step = this._step;
  878. var value = reverse ? this._start + maxIndex * step : this._start;
  879. for (var ii = 0; ii <= maxIndex; ii++) {
  880. if (fn(value, ii, this) === false) {
  881. return ii + 1;
  882. }
  883. value += reverse ? -step : step;
  884. }
  885. return ii;
  886. };
  887. Range.prototype.__iterator = function(type, reverse) {
  888. var maxIndex = this.size - 1;
  889. var step = this._step;
  890. var value = reverse ? this._start + maxIndex * step : this._start;
  891. var ii = 0;
  892. return new Iterator(function() {
  893. var v = value;
  894. value += reverse ? -step : step;
  895. return ii > maxIndex ? iteratorDone() : iteratorValue(type, ii++, v);
  896. });
  897. };
  898. Range.prototype.equals = function(other) {
  899. return other instanceof Range ?
  900. this._start === other._start &&
  901. this._end === other._end &&
  902. this._step === other._step :
  903. deepEqual(this, other);
  904. };
  905. var EMPTY_RANGE;
  906. createClass(Collection, Iterable);
  907. function Collection() {
  908. throw TypeError('Abstract');
  909. }
  910. createClass(KeyedCollection, Collection);function KeyedCollection() {}
  911. createClass(IndexedCollection, Collection);function IndexedCollection() {}
  912. createClass(SetCollection, Collection);function SetCollection() {}
  913. Collection.Keyed = KeyedCollection;
  914. Collection.Indexed = IndexedCollection;
  915. Collection.Set = SetCollection;
  916. var imul =
  917. typeof Math.imul === 'function' && Math.imul(0xffffffff, 2) === -2 ?
  918. Math.imul :
  919. function imul(a, b) {
  920. a = a | 0; // int
  921. b = b | 0; // int
  922. var c = a & 0xffff;
  923. var d = b & 0xffff;
  924. // Shift by 0 fixes the sign on the high part.
  925. return (c * d) + ((((a >>> 16) * d + c * (b >>> 16)) << 16) >>> 0) | 0; // int
  926. };
  927. // v8 has an optimization for storing 31-bit signed numbers.
  928. // Values which have either 00 or 11 as the high order bits qualify.
  929. // This function drops the highest order bit in a signed number, maintaining
  930. // the sign bit.
  931. function smi(i32) {
  932. return ((i32 >>> 1) & 0x40000000) | (i32 & 0xBFFFFFFF);
  933. }
  934. function hash(o) {
  935. if (o === false || o === null || o === undefined) {
  936. return 0;
  937. }
  938. if (typeof o.valueOf === 'function') {
  939. o = o.valueOf();
  940. if (o === false || o === null || o === undefined) {
  941. return 0;
  942. }
  943. }
  944. if (o === true) {
  945. return 1;
  946. }
  947. var type = typeof o;
  948. if (type === 'number') {
  949. var h = o | 0;
  950. if (h !== o) {
  951. h ^= o * 0xFFFFFFFF;
  952. }
  953. while (o > 0xFFFFFFFF) {
  954. o /= 0xFFFFFFFF;
  955. h ^= o;
  956. }
  957. return smi(h);
  958. }
  959. if (type === 'string') {
  960. return o.length > STRING_HASH_CACHE_MIN_STRLEN ? cachedHashString(o) : hashString(o);
  961. }
  962. if (typeof o.hashCode === 'function') {
  963. return o.hashCode();
  964. }
  965. if (type === 'object') {
  966. return hashJSObj(o);
  967. }
  968. if (typeof o.toString === 'function') {
  969. return hashString(o.toString());
  970. }
  971. throw new Error('Value type ' + type + ' cannot be hashed.');
  972. }
  973. function cachedHashString(string) {
  974. var hash = stringHashCache[string];
  975. if (hash === undefined) {
  976. hash = hashString(string);
  977. if (STRING_HASH_CACHE_SIZE === STRING_HASH_CACHE_MAX_SIZE) {
  978. STRING_HASH_CACHE_SIZE = 0;
  979. stringHashCache = {};
  980. }
  981. STRING_HASH_CACHE_SIZE++;
  982. stringHashCache[string] = hash;
  983. }
  984. return hash;
  985. }
  986. // http://jsperf.com/hashing-strings
  987. function hashString(string) {
  988. // This is the hash from JVM
  989. // The hash code for a string is computed as
  990. // s[0] * 31 ^ (n - 1) + s[1] * 31 ^ (n - 2) + ... + s[n - 1],
  991. // where s[i] is the ith character of the string and n is the length of
  992. // the string. We "mod" the result to make it between 0 (inclusive) and 2^31
  993. // (exclusive) by dropping high bits.
  994. var hash = 0;
  995. for (var ii = 0; ii < string.length; ii++) {
  996. hash = 31 * hash + string.charCodeAt(ii) | 0;
  997. }
  998. return smi(hash);
  999. }
  1000. function hashJSObj(obj) {
  1001. var hash;
  1002. if (usingWeakMap) {
  1003. hash = weakMap.get(obj);
  1004. if (hash !== undefined) {
  1005. return hash;
  1006. }
  1007. }
  1008. hash = obj[UID_HASH_KEY];
  1009. if (hash !== undefined) {
  1010. return hash;
  1011. }
  1012. if (!canDefineProperty) {
  1013. hash = obj.propertyIsEnumerable && obj.propertyIsEnumerable[UID_HASH_KEY];
  1014. if (hash !== undefined) {
  1015. return hash;
  1016. }
  1017. hash = getIENodeHash(obj);
  1018. if (hash !== undefined) {
  1019. return hash;
  1020. }
  1021. }
  1022. hash = ++objHashUID;
  1023. if (objHashUID & 0x40000000) {
  1024. objHashUID = 0;
  1025. }
  1026. if (usingWeakMap) {
  1027. weakMap.set(obj, hash);
  1028. } else if (isExtensible !== undefined && isExtensible(obj) === false) {
  1029. throw new Error('Non-extensible objects are not allowed as keys.');
  1030. } else if (canDefineProperty) {
  1031. Object.defineProperty(obj, UID_HASH_KEY, {
  1032. 'enumerable': false,
  1033. 'configurable': false,
  1034. 'writable': false,
  1035. 'value': hash
  1036. });
  1037. } else if (obj.propertyIsEnumerable !== undefined &&
  1038. obj.propertyIsEnumerable === obj.constructor.prototype.propertyIsEnumerable) {
  1039. // Since we can't define a non-enumerable property on the object
  1040. // we'll hijack one of the less-used non-enumerable properties to
  1041. // save our hash on it. Since this is a function it will not show up in
  1042. // `JSON.stringify` which is what we want.
  1043. obj.propertyIsEnumerable = function() {
  1044. return this.constructor.prototype.propertyIsEnumerable.apply(this, arguments);
  1045. };
  1046. obj.propertyIsEnumerable[UID_HASH_KEY] = hash;
  1047. } else if (obj.nodeType !== undefined) {
  1048. // At this point we couldn't get the IE `uniqueID` to use as a hash
  1049. // and we couldn't use a non-enumerable property to exploit the
  1050. // dontEnum bug so we simply add the `UID_HASH_KEY` on the node
  1051. // itself.
  1052. obj[UID_HASH_KEY] = hash;
  1053. } else {
  1054. throw new Error('Unable to set a non-enumerable property on object.');
  1055. }
  1056. return hash;
  1057. }
  1058. // Get references to ES5 object methods.
  1059. var isExtensible = Object.isExtensible;
  1060. // True if Object.defineProperty works as expected. IE8 fails this test.
  1061. var canDefineProperty = (function() {
  1062. try {
  1063. Object.defineProperty({}, '@', {});
  1064. return true;
  1065. } catch (e) {
  1066. return false;
  1067. }
  1068. }());
  1069. // IE has a `uniqueID` property on DOM nodes. We can construct the hash from it
  1070. // and avoid memory leaks from the IE cloneNode bug.
  1071. function getIENodeHash(node) {
  1072. if (node && node.nodeType > 0) {
  1073. switch (node.nodeType) {
  1074. case 1: // Element
  1075. return node.uniqueID;
  1076. case 9: // Document
  1077. return node.documentElement && node.documentElement.uniqueID;
  1078. }
  1079. }
  1080. }
  1081. // If possible, use a WeakMap.
  1082. var usingWeakMap = typeof WeakMap === 'function';
  1083. var weakMap;
  1084. if (usingWeakMap) {
  1085. weakMap = new WeakMap();
  1086. }
  1087. var objHashUID = 0;
  1088. var UID_HASH_KEY = '__immutablehash__';
  1089. if (typeof Symbol === 'function') {
  1090. UID_HASH_KEY = Symbol(UID_HASH_KEY);
  1091. }
  1092. var STRING_HASH_CACHE_MIN_STRLEN = 16;
  1093. var STRING_HASH_CACHE_MAX_SIZE = 255;
  1094. var STRING_HASH_CACHE_SIZE = 0;
  1095. var stringHashCache = {};
  1096. function assertNotInfinite(size) {
  1097. invariant(
  1098. size !== Infinity,
  1099. 'Cannot perform this action with an infinite size.'
  1100. );
  1101. }
  1102. createClass(Map, KeyedCollection);
  1103. // @pragma Construction
  1104. function Map(value) {
  1105. return value === null || value === undefined ? emptyMap() :
  1106. isMap(value) && !isOrdered(value) ? value :
  1107. emptyMap().withMutations(function(map ) {
  1108. var iter = KeyedIterable(value);
  1109. assertNotInfinite(iter.size);
  1110. iter.forEach(function(v, k) {return map.set(k, v)});
  1111. });
  1112. }
  1113. Map.prototype.toString = function() {
  1114. return this.__toString('Map {', '}');
  1115. };
  1116. // @pragma Access
  1117. Map.prototype.get = function(k, notSetValue) {
  1118. return this._root ?
  1119. this._root.get(0, undefined, k, notSetValue) :
  1120. notSetValue;
  1121. };
  1122. // @pragma Modification
  1123. Map.prototype.set = function(k, v) {
  1124. return updateMap(this, k, v);
  1125. };
  1126. Map.prototype.setIn = function(keyPath, v) {
  1127. return this.updateIn(keyPath, NOT_SET, function() {return v});
  1128. };
  1129. Map.prototype.remove = function(k) {
  1130. return updateMap(this, k, NOT_SET);
  1131. };
  1132. Map.prototype.deleteIn = function(keyPath) {
  1133. return this.updateIn(keyPath, function() {return NOT_SET});
  1134. };
  1135. Map.prototype.update = function(k, notSetValue, updater) {
  1136. return arguments.length === 1 ?
  1137. k(this) :
  1138. this.updateIn([k], notSetValue, updater);
  1139. };
  1140. Map.prototype.updateIn = function(keyPath, notSetValue, updater) {
  1141. if (!updater) {
  1142. updater = notSetValue;
  1143. notSetValue = undefined;
  1144. }
  1145. var updatedValue = updateInDeepMap(
  1146. this,
  1147. forceIterator(keyPath),
  1148. notSetValue,
  1149. updater
  1150. );
  1151. return updatedValue === NOT_SET ? undefined : updatedValue;
  1152. };
  1153. Map.prototype.clear = function() {
  1154. if (this.size === 0) {
  1155. return this;
  1156. }
  1157. if (this.__ownerID) {
  1158. this.size = 0;
  1159. this._root = null;
  1160. this.__hash = undefined;
  1161. this.__altered = true;
  1162. return this;
  1163. }
  1164. return emptyMap();
  1165. };
  1166. // @pragma Composition
  1167. Map.prototype.merge = function(/*...iters*/) {
  1168. return mergeIntoMapWith(this, undefined, arguments);
  1169. };
  1170. Map.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  1171. return mergeIntoMapWith(this, merger, iters);
  1172. };
  1173. Map.prototype.mergeIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1);
  1174. return this.updateIn(
  1175. keyPath,
  1176. emptyMap(),
  1177. function(m ) {return typeof m.merge === 'function' ?
  1178. m.merge.apply(m, iters) :
  1179. iters[iters.length - 1]}
  1180. );
  1181. };
  1182. Map.prototype.mergeDeep = function(/*...iters*/) {
  1183. return mergeIntoMapWith(this, deepMerger, arguments);
  1184. };
  1185. Map.prototype.mergeDeepWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  1186. return mergeIntoMapWith(this, deepMergerWith(merger), iters);
  1187. };
  1188. Map.prototype.mergeDeepIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1);
  1189. return this.updateIn(
  1190. keyPath,
  1191. emptyMap(),
  1192. function(m ) {return typeof m.mergeDeep === 'function' ?
  1193. m.mergeDeep.apply(m, iters) :
  1194. iters[iters.length - 1]}
  1195. );
  1196. };
  1197. Map.prototype.sort = function(comparator) {
  1198. // Late binding
  1199. return OrderedMap(sortFactory(this, comparator));
  1200. };
  1201. Map.prototype.sortBy = function(mapper, comparator) {
  1202. // Late binding
  1203. return OrderedMap(sortFactory(this, comparator, mapper));
  1204. };
  1205. // @pragma Mutability
  1206. Map.prototype.withMutations = function(fn) {
  1207. var mutable = this.asMutable();
  1208. fn(mutable);
  1209. return mutable.wasAltered() ? mutable.__ensureOwner(this.__ownerID) : this;
  1210. };
  1211. Map.prototype.asMutable = function() {
  1212. return this.__ownerID ? this : this.__ensureOwner(new OwnerID());
  1213. };
  1214. Map.prototype.asImmutable = function() {
  1215. return this.__ensureOwner();
  1216. };
  1217. Map.prototype.wasAltered = function() {
  1218. return this.__altered;
  1219. };
  1220. Map.prototype.__iterator = function(type, reverse) {
  1221. return new MapIterator(this, type, reverse);
  1222. };
  1223. Map.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  1224. var iterations = 0;
  1225. this._root && this._root.iterate(function(entry ) {
  1226. iterations++;
  1227. return fn(entry[1], entry[0], this$0);
  1228. }, reverse);
  1229. return iterations;
  1230. };
  1231. Map.prototype.__ensureOwner = function(ownerID) {
  1232. if (ownerID === this.__ownerID) {
  1233. return this;
  1234. }
  1235. if (!ownerID) {
  1236. this.__ownerID = ownerID;
  1237. this.__altered = false;
  1238. return this;
  1239. }
  1240. return makeMap(this.size, this._root, ownerID, this.__hash);
  1241. };
  1242. function isMap(maybeMap) {
  1243. return !!(maybeMap && maybeMap[IS_MAP_SENTINEL]);
  1244. }
  1245. Map.isMap = isMap;
  1246. var IS_MAP_SENTINEL = '@@__IMMUTABLE_MAP__@@';
  1247. var MapPrototype = Map.prototype;
  1248. MapPrototype[IS_MAP_SENTINEL] = true;
  1249. MapPrototype[DELETE] = MapPrototype.remove;
  1250. MapPrototype.removeIn = MapPrototype.deleteIn;
  1251. // #pragma Trie Nodes
  1252. function ArrayMapNode(ownerID, entries) {
  1253. this.ownerID = ownerID;
  1254. this.entries = entries;
  1255. }
  1256. ArrayMapNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  1257. var entries = this.entries;
  1258. for (var ii = 0, len = entries.length; ii < len; ii++) {
  1259. if (is(key, entries[ii][0])) {
  1260. return entries[ii][1];
  1261. }
  1262. }
  1263. return notSetValue;
  1264. };
  1265. ArrayMapNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  1266. var removed = value === NOT_SET;
  1267. var entries = this.entries;
  1268. var idx = 0;
  1269. for (var len = entries.length; idx < len; idx++) {
  1270. if (is(key, entries[idx][0])) {
  1271. break;
  1272. }
  1273. }
  1274. var exists = idx < len;
  1275. if (exists ? entries[idx][1] === value : removed) {
  1276. return this;
  1277. }
  1278. SetRef(didAlter);
  1279. (removed || !exists) && SetRef(didChangeSize);
  1280. if (removed && entries.length === 1) {
  1281. return; // undefined
  1282. }
  1283. if (!exists && !removed && entries.length >= MAX_ARRAY_MAP_SIZE) {
  1284. return createNodes(ownerID, entries, key, value);
  1285. }
  1286. var isEditable = ownerID && ownerID === this.ownerID;
  1287. var newEntries = isEditable ? entries : arrCopy(entries);
  1288. if (exists) {
  1289. if (removed) {
  1290. idx === len - 1 ? newEntries.pop() : (newEntries[idx] = newEntries.pop());
  1291. } else {
  1292. newEntries[idx] = [key, value];
  1293. }
  1294. } else {
  1295. newEntries.push([key, value]);
  1296. }
  1297. if (isEditable) {
  1298. this.entries = newEntries;
  1299. return this;
  1300. }
  1301. return new ArrayMapNode(ownerID, newEntries);
  1302. };
  1303. function BitmapIndexedNode(ownerID, bitmap, nodes) {
  1304. this.ownerID = ownerID;
  1305. this.bitmap = bitmap;
  1306. this.nodes = nodes;
  1307. }
  1308. BitmapIndexedNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  1309. if (keyHash === undefined) {
  1310. keyHash = hash(key);
  1311. }
  1312. var bit = (1 << ((shift === 0 ? keyHash : keyHash >>> shift) & MASK));
  1313. var bitmap = this.bitmap;
  1314. return (bitmap & bit) === 0 ? notSetValue :
  1315. this.nodes[popCount(bitmap & (bit - 1))].get(shift + SHIFT, keyHash, key, notSetValue);
  1316. };
  1317. BitmapIndexedNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  1318. if (keyHash === undefined) {
  1319. keyHash = hash(key);
  1320. }
  1321. var keyHashFrag = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  1322. var bit = 1 << keyHashFrag;
  1323. var bitmap = this.bitmap;
  1324. var exists = (bitmap & bit) !== 0;
  1325. if (!exists && value === NOT_SET) {
  1326. return this;
  1327. }
  1328. var idx = popCount(bitmap & (bit - 1));
  1329. var nodes = this.nodes;
  1330. var node = exists ? nodes[idx] : undefined;
  1331. var newNode = updateNode(node, ownerID, shift + SHIFT, keyHash, key, value, didChangeSize, didAlter);
  1332. if (newNode === node) {
  1333. return this;
  1334. }
  1335. if (!exists && newNode && nodes.length >= MAX_BITMAP_INDEXED_SIZE) {
  1336. return expandNodes(ownerID, nodes, bitmap, keyHashFrag, newNode);
  1337. }
  1338. if (exists && !newNode && nodes.length === 2 && isLeafNode(nodes[idx ^ 1])) {
  1339. return nodes[idx ^ 1];
  1340. }
  1341. if (exists && newNode && nodes.length === 1 && isLeafNode(newNode)) {
  1342. return newNode;
  1343. }
  1344. var isEditable = ownerID && ownerID === this.ownerID;
  1345. var newBitmap = exists ? newNode ? bitmap : bitmap ^ bit : bitmap | bit;
  1346. var newNodes = exists ? newNode ?
  1347. setIn(nodes, idx, newNode, isEditable) :
  1348. spliceOut(nodes, idx, isEditable) :
  1349. spliceIn(nodes, idx, newNode, isEditable);
  1350. if (isEditable) {
  1351. this.bitmap = newBitmap;
  1352. this.nodes = newNodes;
  1353. return this;
  1354. }
  1355. return new BitmapIndexedNode(ownerID, newBitmap, newNodes);
  1356. };
  1357. function HashArrayMapNode(ownerID, count, nodes) {
  1358. this.ownerID = ownerID;
  1359. this.count = count;
  1360. this.nodes = nodes;
  1361. }
  1362. HashArrayMapNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  1363. if (keyHash === undefined) {
  1364. keyHash = hash(key);
  1365. }
  1366. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  1367. var node = this.nodes[idx];
  1368. return node ? node.get(shift + SHIFT, keyHash, key, notSetValue) : notSetValue;
  1369. };
  1370. HashArrayMapNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  1371. if (keyHash === undefined) {
  1372. keyHash = hash(key);
  1373. }
  1374. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  1375. var removed = value === NOT_SET;
  1376. var nodes = this.nodes;
  1377. var node = nodes[idx];
  1378. if (removed && !node) {
  1379. return this;
  1380. }
  1381. var newNode = updateNode(node, ownerID, shift + SHIFT, keyHash, key, value, didChangeSize, didAlter);
  1382. if (newNode === node) {
  1383. return this;
  1384. }
  1385. var newCount = this.count;
  1386. if (!node) {
  1387. newCount++;
  1388. } else if (!newNode) {
  1389. newCount--;
  1390. if (newCount < MIN_HASH_ARRAY_MAP_SIZE) {
  1391. return packNodes(ownerID, nodes, newCount, idx);
  1392. }
  1393. }
  1394. var isEditable = ownerID && ownerID === this.ownerID;
  1395. var newNodes = setIn(nodes, idx, newNode, isEditable);
  1396. if (isEditable) {
  1397. this.count = newCount;
  1398. this.nodes = newNodes;
  1399. return this;
  1400. }
  1401. return new HashArrayMapNode(ownerID, newCount, newNodes);
  1402. };
  1403. function HashCollisionNode(ownerID, keyHash, entries) {
  1404. this.ownerID = ownerID;
  1405. this.keyHash = keyHash;
  1406. this.entries = entries;
  1407. }
  1408. HashCollisionNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  1409. var entries = this.entries;
  1410. for (var ii = 0, len = entries.length; ii < len; ii++) {
  1411. if (is(key, entries[ii][0])) {
  1412. return entries[ii][1];
  1413. }
  1414. }
  1415. return notSetValue;
  1416. };
  1417. HashCollisionNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  1418. if (keyHash === undefined) {
  1419. keyHash = hash(key);
  1420. }
  1421. var removed = value === NOT_SET;
  1422. if (keyHash !== this.keyHash) {
  1423. if (removed) {
  1424. return this;
  1425. }
  1426. SetRef(didAlter);
  1427. SetRef(didChangeSize);
  1428. return mergeIntoNode(this, ownerID, shift, keyHash, [key, value]);
  1429. }
  1430. var entries = this.entries;
  1431. var idx = 0;
  1432. for (var len = entries.length; idx < len; idx++) {
  1433. if (is(key, entries[idx][0])) {
  1434. break;
  1435. }
  1436. }
  1437. var exists = idx < len;
  1438. if (exists ? entries[idx][1] === value : removed) {
  1439. return this;
  1440. }
  1441. SetRef(didAlter);
  1442. (removed || !exists) && SetRef(didChangeSize);
  1443. if (removed && len === 2) {
  1444. return new ValueNode(ownerID, this.keyHash, entries[idx ^ 1]);
  1445. }
  1446. var isEditable = ownerID && ownerID === this.ownerID;
  1447. var newEntries = isEditable ? entries : arrCopy(entries);
  1448. if (exists) {
  1449. if (removed) {
  1450. idx === len - 1 ? newEntries.pop() : (newEntries[idx] = newEntries.pop());
  1451. } else {
  1452. newEntries[idx] = [key, value];
  1453. }
  1454. } else {
  1455. newEntries.push([key, value]);
  1456. }
  1457. if (isEditable) {
  1458. this.entries = newEntries;
  1459. return this;
  1460. }
  1461. return new HashCollisionNode(ownerID, this.keyHash, newEntries);
  1462. };
  1463. function ValueNode(ownerID, keyHash, entry) {
  1464. this.ownerID = ownerID;
  1465. this.keyHash = keyHash;
  1466. this.entry = entry;
  1467. }
  1468. ValueNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  1469. return is(key, this.entry[0]) ? this.entry[1] : notSetValue;
  1470. };
  1471. ValueNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  1472. var removed = value === NOT_SET;
  1473. var keyMatch = is(key, this.entry[0]);
  1474. if (keyMatch ? value === this.entry[1] : removed) {
  1475. return this;
  1476. }
  1477. SetRef(didAlter);
  1478. if (removed) {
  1479. SetRef(didChangeSize);
  1480. return; // undefined
  1481. }
  1482. if (keyMatch) {
  1483. if (ownerID && ownerID === this.ownerID) {
  1484. this.entry[1] = value;
  1485. return this;
  1486. }
  1487. return new ValueNode(ownerID, this.keyHash, [key, value]);
  1488. }
  1489. SetRef(didChangeSize);
  1490. return mergeIntoNode(this, ownerID, shift, hash(key), [key, value]);
  1491. };
  1492. // #pragma Iterators
  1493. ArrayMapNode.prototype.iterate =
  1494. HashCollisionNode.prototype.iterate = function (fn, reverse) {
  1495. var entries = this.entries;
  1496. for (var ii = 0, maxIndex = entries.length - 1; ii <= maxIndex; ii++) {
  1497. if (fn(entries[reverse ? maxIndex - ii : ii]) === false) {
  1498. return false;
  1499. }
  1500. }
  1501. };
  1502. BitmapIndexedNode.prototype.iterate =
  1503. HashArrayMapNode.prototype.iterate = function (fn, reverse) {
  1504. var nodes = this.nodes;
  1505. for (var ii = 0, maxIndex = nodes.length - 1; ii <= maxIndex; ii++) {
  1506. var node = nodes[reverse ? maxIndex - ii : ii];
  1507. if (node && node.iterate(fn, reverse) === false) {
  1508. return false;
  1509. }
  1510. }
  1511. };
  1512. ValueNode.prototype.iterate = function (fn, reverse) {
  1513. return fn(this.entry);
  1514. };
  1515. createClass(MapIterator, Iterator);
  1516. function MapIterator(map, type, reverse) {
  1517. this._type = type;
  1518. this._reverse = reverse;
  1519. this._stack = map._root && mapIteratorFrame(map._root);
  1520. }
  1521. MapIterator.prototype.next = function() {
  1522. var type = this._type;
  1523. var stack = this._stack;
  1524. while (stack) {
  1525. var node = stack.node;
  1526. var index = stack.index++;
  1527. var maxIndex;
  1528. if (node.entry) {
  1529. if (index === 0) {
  1530. return mapIteratorValue(type, node.entry);
  1531. }
  1532. } else if (node.entries) {
  1533. maxIndex = node.entries.length - 1;
  1534. if (index <= maxIndex) {
  1535. return mapIteratorValue(type, node.entries[this._reverse ? maxIndex - index : index]);
  1536. }
  1537. } else {
  1538. maxIndex = node.nodes.length - 1;
  1539. if (index <= maxIndex) {
  1540. var subNode = node.nodes[this._reverse ? maxIndex - index : index];
  1541. if (subNode) {
  1542. if (subNode.entry) {
  1543. return mapIteratorValue(type, subNode.entry);
  1544. }
  1545. stack = this._stack = mapIteratorFrame(subNode, stack);
  1546. }
  1547. continue;
  1548. }
  1549. }
  1550. stack = this._stack = this._stack.__prev;
  1551. }
  1552. return iteratorDone();
  1553. };
  1554. function mapIteratorValue(type, entry) {
  1555. return iteratorValue(type, entry[0], entry[1]);
  1556. }
  1557. function mapIteratorFrame(node, prev) {
  1558. return {
  1559. node: node,
  1560. index: 0,
  1561. __prev: prev
  1562. };
  1563. }
  1564. function makeMap(size, root, ownerID, hash) {
  1565. var map = Object.create(MapPrototype);
  1566. map.size = size;
  1567. map._root = root;
  1568. map.__ownerID = ownerID;
  1569. map.__hash = hash;
  1570. map.__altered = false;
  1571. return map;
  1572. }
  1573. var EMPTY_MAP;
  1574. function emptyMap() {
  1575. return EMPTY_MAP || (EMPTY_MAP = makeMap(0));
  1576. }
  1577. function updateMap(map, k, v) {
  1578. var newRoot;
  1579. var newSize;
  1580. if (!map._root) {
  1581. if (v === NOT_SET) {
  1582. return map;
  1583. }
  1584. newSize = 1;
  1585. newRoot = new ArrayMapNode(map.__ownerID, [[k, v]]);
  1586. } else {
  1587. var didChangeSize = MakeRef(CHANGE_LENGTH);
  1588. var didAlter = MakeRef(DID_ALTER);
  1589. newRoot = updateNode(map._root, map.__ownerID, 0, undefined, k, v, didChangeSize, didAlter);
  1590. if (!didAlter.value) {
  1591. return map;
  1592. }
  1593. newSize = map.size + (didChangeSize.value ? v === NOT_SET ? -1 : 1 : 0);
  1594. }
  1595. if (map.__ownerID) {
  1596. map.size = newSize;
  1597. map._root = newRoot;
  1598. map.__hash = undefined;
  1599. map.__altered = true;
  1600. return map;
  1601. }
  1602. return newRoot ? makeMap(newSize, newRoot) : emptyMap();
  1603. }
  1604. function updateNode(node, ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  1605. if (!node) {
  1606. if (value === NOT_SET) {
  1607. return node;
  1608. }
  1609. SetRef(didAlter);
  1610. SetRef(didChangeSize);
  1611. return new ValueNode(ownerID, keyHash, [key, value]);
  1612. }
  1613. return node.update(ownerID, shift, keyHash, key, value, didChangeSize, didAlter);
  1614. }
  1615. function isLeafNode(node) {
  1616. return node.constructor === ValueNode || node.constructor === HashCollisionNode;
  1617. }
  1618. function mergeIntoNode(node, ownerID, shift, keyHash, entry) {
  1619. if (node.keyHash === keyHash) {
  1620. return new HashCollisionNode(ownerID, keyHash, [node.entry, entry]);
  1621. }
  1622. var idx1 = (shift === 0 ? node.keyHash : node.keyHash >>> shift) & MASK;
  1623. var idx2 = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  1624. var newNode;
  1625. var nodes = idx1 === idx2 ?
  1626. [mergeIntoNode(node, ownerID, shift + SHIFT, keyHash, entry)] :
  1627. ((newNode = new ValueNode(ownerID, keyHash, entry)), idx1 < idx2 ? [node, newNode] : [newNode, node]);
  1628. return new BitmapIndexedNode(ownerID, (1 << idx1) | (1 << idx2), nodes);
  1629. }
  1630. function createNodes(ownerID, entries, key, value) {
  1631. if (!ownerID) {
  1632. ownerID = new OwnerID();
  1633. }
  1634. var node = new ValueNode(ownerID, hash(key), [key, value]);
  1635. for (var ii = 0; ii < entries.length; ii++) {
  1636. var entry = entries[ii];
  1637. node = node.update(ownerID, 0, undefined, entry[0], entry[1]);
  1638. }
  1639. return node;
  1640. }
  1641. function packNodes(ownerID, nodes, count, excluding) {
  1642. var bitmap = 0;
  1643. var packedII = 0;
  1644. var packedNodes = new Array(count);
  1645. for (var ii = 0, bit = 1, len = nodes.length; ii < len; ii++, bit <<= 1) {
  1646. var node = nodes[ii];
  1647. if (node !== undefined && ii !== excluding) {
  1648. bitmap |= bit;
  1649. packedNodes[packedII++] = node;
  1650. }
  1651. }
  1652. return new BitmapIndexedNode(ownerID, bitmap, packedNodes);
  1653. }
  1654. function expandNodes(ownerID, nodes, bitmap, including, node) {
  1655. var count = 0;
  1656. var expandedNodes = new Array(SIZE);
  1657. for (var ii = 0; bitmap !== 0; ii++, bitmap >>>= 1) {
  1658. expandedNodes[ii] = bitmap & 1 ? nodes[count++] : undefined;
  1659. }
  1660. expandedNodes[including] = node;
  1661. return new HashArrayMapNode(ownerID, count + 1, expandedNodes);
  1662. }
  1663. function mergeIntoMapWith(map, merger, iterables) {
  1664. var iters = [];
  1665. for (var ii = 0; ii < iterables.length; ii++) {
  1666. var value = iterables[ii];
  1667. var iter = KeyedIterable(value);
  1668. if (!isIterable(value)) {
  1669. iter = iter.map(function(v ) {return fromJS(v)});
  1670. }
  1671. iters.push(iter);
  1672. }
  1673. return mergeIntoCollectionWith(map, merger, iters);
  1674. }
  1675. function deepMerger(existing, value, key) {
  1676. return existing && existing.mergeDeep && isIterable(value) ?
  1677. existing.mergeDeep(value) :
  1678. is(existing, value) ? existing : value;
  1679. }
  1680. function deepMergerWith(merger) {
  1681. return function(existing, value, key) {
  1682. if (existing && existing.mergeDeepWith && isIterable(value)) {
  1683. return existing.mergeDeepWith(merger, value);
  1684. }
  1685. var nextValue = merger(existing, value, key);
  1686. return is(existing, nextValue) ? existing : nextValue;
  1687. };
  1688. }
  1689. function mergeIntoCollectionWith(collection, merger, iters) {
  1690. iters = iters.filter(function(x ) {return x.size !== 0});
  1691. if (iters.length === 0) {
  1692. return collection;
  1693. }
  1694. if (collection.size === 0 && !collection.__ownerID && iters.length === 1) {
  1695. return collection.constructor(iters[0]);
  1696. }
  1697. return collection.withMutations(function(collection ) {
  1698. var mergeIntoMap = merger ?
  1699. function(value, key) {
  1700. collection.update(key, NOT_SET, function(existing )
  1701. {return existing === NOT_SET ? value : merger(existing, value, key)}
  1702. );
  1703. } :
  1704. function(value, key) {
  1705. collection.set(key, value);
  1706. };
  1707. for (var ii = 0; ii < iters.length; ii++) {
  1708. iters[ii].forEach(mergeIntoMap);
  1709. }
  1710. });
  1711. }
  1712. function updateInDeepMap(existing, keyPathIter, notSetValue, updater) {
  1713. var isNotSet = existing === NOT_SET;
  1714. var step = keyPathIter.next();
  1715. if (step.done) {
  1716. var existingValue = isNotSet ? notSetValue : existing;
  1717. var newValue = updater(existingValue);
  1718. return newValue === existingValue ? existing : newValue;
  1719. }
  1720. invariant(
  1721. isNotSet || (existing && existing.set),
  1722. 'invalid keyPath'
  1723. );
  1724. var key = step.value;
  1725. var nextExisting = isNotSet ? NOT_SET : existing.get(key, NOT_SET);
  1726. var nextUpdated = updateInDeepMap(
  1727. nextExisting,
  1728. keyPathIter,
  1729. notSetValue,
  1730. updater
  1731. );
  1732. return nextUpdated === nextExisting ? existing :
  1733. nextUpdated === NOT_SET ? existing.remove(key) :
  1734. (isNotSet ? emptyMap() : existing).set(key, nextUpdated);
  1735. }
  1736. function popCount(x) {
  1737. x = x - ((x >> 1) & 0x55555555);
  1738. x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
  1739. x = (x + (x >> 4)) & 0x0f0f0f0f;
  1740. x = x + (x >> 8);
  1741. x = x + (x >> 16);
  1742. return x & 0x7f;
  1743. }
  1744. function setIn(array, idx, val, canEdit) {
  1745. var newArray = canEdit ? array : arrCopy(array);
  1746. newArray[idx] = val;
  1747. return newArray;
  1748. }
  1749. function spliceIn(array, idx, val, canEdit) {
  1750. var newLen = array.length + 1;
  1751. if (canEdit && idx + 1 === newLen) {
  1752. array[idx] = val;
  1753. return array;
  1754. }
  1755. var newArray = new Array(newLen);
  1756. var after = 0;
  1757. for (var ii = 0; ii < newLen; ii++) {
  1758. if (ii === idx) {
  1759. newArray[ii] = val;
  1760. after = -1;
  1761. } else {
  1762. newArray[ii] = array[ii + after];
  1763. }
  1764. }
  1765. return newArray;
  1766. }
  1767. function spliceOut(array, idx, canEdit) {
  1768. var newLen = array.length - 1;
  1769. if (canEdit && idx === newLen) {
  1770. array.pop();
  1771. return array;
  1772. }
  1773. var newArray = new Array(newLen);
  1774. var after = 0;
  1775. for (var ii = 0; ii < newLen; ii++) {
  1776. if (ii === idx) {
  1777. after = 1;
  1778. }
  1779. newArray[ii] = array[ii + after];
  1780. }
  1781. return newArray;
  1782. }
  1783. var MAX_ARRAY_MAP_SIZE = SIZE / 4;
  1784. var MAX_BITMAP_INDEXED_SIZE = SIZE / 2;
  1785. var MIN_HASH_ARRAY_MAP_SIZE = SIZE / 4;
  1786. createClass(List, IndexedCollection);
  1787. // @pragma Construction
  1788. function List(value) {
  1789. var empty = emptyList();
  1790. if (value === null || value === undefined) {
  1791. return empty;
  1792. }
  1793. if (isList(value)) {
  1794. return value;
  1795. }
  1796. var iter = IndexedIterable(value);
  1797. var size = iter.size;
  1798. if (size === 0) {
  1799. return empty;
  1800. }
  1801. assertNotInfinite(size);
  1802. if (size > 0 && size < SIZE) {
  1803. return makeList(0, size, SHIFT, null, new VNode(iter.toArray()));
  1804. }
  1805. return empty.withMutations(function(list ) {
  1806. list.setSize(size);
  1807. iter.forEach(function(v, i) {return list.set(i, v)});
  1808. });
  1809. }
  1810. List.of = function(/*...values*/) {
  1811. return this(arguments);
  1812. };
  1813. List.prototype.toString = function() {
  1814. return this.__toString('List [', ']');
  1815. };
  1816. // @pragma Access
  1817. List.prototype.get = function(index, notSetValue) {
  1818. index = wrapIndex(this, index);
  1819. if (index >= 0 && index < this.size) {
  1820. index += this._origin;
  1821. var node = listNodeFor(this, index);
  1822. return node && node.array[index & MASK];
  1823. }
  1824. return notSetValue;
  1825. };
  1826. // @pragma Modification
  1827. List.prototype.set = function(index, value) {
  1828. return updateList(this, index, value);
  1829. };
  1830. List.prototype.remove = function(index) {
  1831. return !this.has(index) ? this :
  1832. index === 0 ? this.shift() :
  1833. index === this.size - 1 ? this.pop() :
  1834. this.splice(index, 1);
  1835. };
  1836. List.prototype.insert = function(index, value) {
  1837. return this.splice(index, 0, value);
  1838. };
  1839. List.prototype.clear = function() {
  1840. if (this.size === 0) {
  1841. return this;
  1842. }
  1843. if (this.__ownerID) {
  1844. this.size = this._origin = this._capacity = 0;
  1845. this._level = SHIFT;
  1846. this._root = this._tail = null;
  1847. this.__hash = undefined;
  1848. this.__altered = true;
  1849. return this;
  1850. }
  1851. return emptyList();
  1852. };
  1853. List.prototype.push = function(/*...values*/) {
  1854. var values = arguments;
  1855. var oldSize = this.size;
  1856. return this.withMutations(function(list ) {
  1857. setListBounds(list, 0, oldSize + values.length);
  1858. for (var ii = 0; ii < values.length; ii++) {
  1859. list.set(oldSize + ii, values[ii]);
  1860. }
  1861. });
  1862. };
  1863. List.prototype.pop = function() {
  1864. return setListBounds(this, 0, -1);
  1865. };
  1866. List.prototype.unshift = function(/*...values*/) {
  1867. var values = arguments;
  1868. return this.withMutations(function(list ) {
  1869. setListBounds(list, -values.length);
  1870. for (var ii = 0; ii < values.length; ii++) {
  1871. list.set(ii, values[ii]);
  1872. }
  1873. });
  1874. };
  1875. List.prototype.shift = function() {
  1876. return setListBounds(this, 1);
  1877. };
  1878. // @pragma Composition
  1879. List.prototype.merge = function(/*...iters*/) {
  1880. return mergeIntoListWith(this, undefined, arguments);
  1881. };
  1882. List.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  1883. return mergeIntoListWith(this, merger, iters);
  1884. };
  1885. List.prototype.mergeDeep = function(/*...iters*/) {
  1886. return mergeIntoListWith(this, deepMerger, arguments);
  1887. };
  1888. List.prototype.mergeDeepWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  1889. return mergeIntoListWith(this, deepMergerWith(merger), iters);
  1890. };
  1891. List.prototype.setSize = function(size) {
  1892. return setListBounds(this, 0, size);
  1893. };
  1894. // @pragma Iteration
  1895. List.prototype.slice = function(begin, end) {
  1896. var size = this.size;
  1897. if (wholeSlice(begin, end, size)) {
  1898. return this;
  1899. }
  1900. return setListBounds(
  1901. this,
  1902. resolveBegin(begin, size),
  1903. resolveEnd(end, size)
  1904. );
  1905. };
  1906. List.prototype.__iterator = function(type, reverse) {
  1907. var index = 0;
  1908. var values = iterateList(this, reverse);
  1909. return new Iterator(function() {
  1910. var value = values();
  1911. return value === DONE ?
  1912. iteratorDone() :
  1913. iteratorValue(type, index++, value);
  1914. });
  1915. };
  1916. List.prototype.__iterate = function(fn, reverse) {
  1917. var index = 0;
  1918. var values = iterateList(this, reverse);
  1919. var value;
  1920. while ((value = values()) !== DONE) {
  1921. if (fn(value, index++, this) === false) {
  1922. break;
  1923. }
  1924. }
  1925. return index;
  1926. };
  1927. List.prototype.__ensureOwner = function(ownerID) {
  1928. if (ownerID === this.__ownerID) {
  1929. return this;
  1930. }
  1931. if (!ownerID) {
  1932. this.__ownerID = ownerID;
  1933. return this;
  1934. }
  1935. return makeList(this._origin, this._capacity, this._level, this._root, this._tail, ownerID, this.__hash);
  1936. };
  1937. function isList(maybeList) {
  1938. return !!(maybeList && maybeList[IS_LIST_SENTINEL]);
  1939. }
  1940. List.isList = isList;
  1941. var IS_LIST_SENTINEL = '@@__IMMUTABLE_LIST__@@';
  1942. var ListPrototype = List.prototype;
  1943. ListPrototype[IS_LIST_SENTINEL] = true;
  1944. ListPrototype[DELETE] = ListPrototype.remove;
  1945. ListPrototype.setIn = MapPrototype.setIn;
  1946. ListPrototype.deleteIn =
  1947. ListPrototype.removeIn = MapPrototype.removeIn;
  1948. ListPrototype.update = MapPrototype.update;
  1949. ListPrototype.updateIn = MapPrototype.updateIn;
  1950. ListPrototype.mergeIn = MapPrototype.mergeIn;
  1951. ListPrototype.mergeDeepIn = MapPrototype.mergeDeepIn;
  1952. ListPrototype.withMutations = MapPrototype.withMutations;
  1953. ListPrototype.asMutable = MapPrototype.asMutable;
  1954. ListPrototype.asImmutable = MapPrototype.asImmutable;
  1955. ListPrototype.wasAltered = MapPrototype.wasAltered;
  1956. function VNode(array, ownerID) {
  1957. this.array = array;
  1958. this.ownerID = ownerID;
  1959. }
  1960. // TODO: seems like these methods are very similar
  1961. VNode.prototype.removeBefore = function(ownerID, level, index) {
  1962. if (index === level ? 1 << level : this.array.length === 0) {
  1963. return this;
  1964. }
  1965. var originIndex = (index >>> level) & MASK;
  1966. if (originIndex >= this.array.length) {
  1967. return new VNode([], ownerID);
  1968. }
  1969. var removingFirst = originIndex === 0;
  1970. var newChild;
  1971. if (level > 0) {
  1972. var oldChild = this.array[originIndex];
  1973. newChild = oldChild && oldChild.removeBefore(ownerID, level - SHIFT, index);
  1974. if (newChild === oldChild && removingFirst) {
  1975. return this;
  1976. }
  1977. }
  1978. if (removingFirst && !newChild) {
  1979. return this;
  1980. }
  1981. var editable = editableVNode(this, ownerID);
  1982. if (!removingFirst) {
  1983. for (var ii = 0; ii < originIndex; ii++) {
  1984. editable.array[ii] = undefined;
  1985. }
  1986. }
  1987. if (newChild) {
  1988. editable.array[originIndex] = newChild;
  1989. }
  1990. return editable;
  1991. };
  1992. VNode.prototype.removeAfter = function(ownerID, level, index) {
  1993. if (index === (level ? 1 << level : 0) || this.array.length === 0) {
  1994. return this;
  1995. }
  1996. var sizeIndex = ((index - 1) >>> level) & MASK;
  1997. if (sizeIndex >= this.array.length) {
  1998. return this;
  1999. }
  2000. var newChild;
  2001. if (level > 0) {
  2002. var oldChild = this.array[sizeIndex];
  2003. newChild = oldChild && oldChild.removeAfter(ownerID, level - SHIFT, index);
  2004. if (newChild === oldChild && sizeIndex === this.array.length - 1) {
  2005. return this;
  2006. }
  2007. }
  2008. var editable = editableVNode(this, ownerID);
  2009. editable.array.splice(sizeIndex + 1);
  2010. if (newChild) {
  2011. editable.array[sizeIndex] = newChild;
  2012. }
  2013. return editable;
  2014. };
  2015. var DONE = {};
  2016. function iterateList(list, reverse) {
  2017. var left = list._origin;
  2018. var right = list._capacity;
  2019. var tailPos = getTailOffset(right);
  2020. var tail = list._tail;
  2021. return iterateNodeOrLeaf(list._root, list._level, 0);
  2022. function iterateNodeOrLeaf(node, level, offset) {
  2023. return level === 0 ?
  2024. iterateLeaf(node, offset) :
  2025. iterateNode(node, level, offset);
  2026. }
  2027. function iterateLeaf(node, offset) {
  2028. var array = offset === tailPos ? tail && tail.array : node && node.array;
  2029. var from = offset > left ? 0 : left - offset;
  2030. var to = right - offset;
  2031. if (to > SIZE) {
  2032. to = SIZE;
  2033. }
  2034. return function() {
  2035. if (from === to) {
  2036. return DONE;
  2037. }
  2038. var idx = reverse ? --to : from++;
  2039. return array && array[idx];
  2040. };
  2041. }
  2042. function iterateNode(node, level, offset) {
  2043. var values;
  2044. var array = node && node.array;
  2045. var from = offset > left ? 0 : (left - offset) >> level;
  2046. var to = ((right - offset) >> level) + 1;
  2047. if (to > SIZE) {
  2048. to = SIZE;
  2049. }
  2050. return function() {
  2051. do {
  2052. if (values) {
  2053. var value = values();
  2054. if (value !== DONE) {
  2055. return value;
  2056. }
  2057. values = null;
  2058. }
  2059. if (from === to) {
  2060. return DONE;
  2061. }
  2062. var idx = reverse ? --to : from++;
  2063. values = iterateNodeOrLeaf(
  2064. array && array[idx], level - SHIFT, offset + (idx << level)
  2065. );
  2066. } while (true);
  2067. };
  2068. }
  2069. }
  2070. function makeList(origin, capacity, level, root, tail, ownerID, hash) {
  2071. var list = Object.create(ListPrototype);
  2072. list.size = capacity - origin;
  2073. list._origin = origin;
  2074. list._capacity = capacity;
  2075. list._level = level;
  2076. list._root = root;
  2077. list._tail = tail;
  2078. list.__ownerID = ownerID;
  2079. list.__hash = hash;
  2080. list.__altered = false;
  2081. return list;
  2082. }
  2083. var EMPTY_LIST;
  2084. function emptyList() {
  2085. return EMPTY_LIST || (EMPTY_LIST = makeList(0, 0, SHIFT));
  2086. }
  2087. function updateList(list, index, value) {
  2088. index = wrapIndex(list, index);
  2089. if (index !== index) {
  2090. return list;
  2091. }
  2092. if (index >= list.size || index < 0) {
  2093. return list.withMutations(function(list ) {
  2094. index < 0 ?
  2095. setListBounds(list, index).set(0, value) :
  2096. setListBounds(list, 0, index + 1).set(index, value);
  2097. });
  2098. }
  2099. index += list._origin;
  2100. var newTail = list._tail;
  2101. var newRoot = list._root;
  2102. var didAlter = MakeRef(DID_ALTER);
  2103. if (index >= getTailOffset(list._capacity)) {
  2104. newTail = updateVNode(newTail, list.__ownerID, 0, index, value, didAlter);
  2105. } else {
  2106. newRoot = updateVNode(newRoot, list.__ownerID, list._level, index, value, didAlter);
  2107. }
  2108. if (!didAlter.value) {
  2109. return list;
  2110. }
  2111. if (list.__ownerID) {
  2112. list._root = newRoot;
  2113. list._tail = newTail;
  2114. list.__hash = undefined;
  2115. list.__altered = true;
  2116. return list;
  2117. }
  2118. return makeList(list._origin, list._capacity, list._level, newRoot, newTail);
  2119. }
  2120. function updateVNode(node, ownerID, level, index, value, didAlter) {
  2121. var idx = (index >>> level) & MASK;
  2122. var nodeHas = node && idx < node.array.length;
  2123. if (!nodeHas && value === undefined) {
  2124. return node;
  2125. }
  2126. var newNode;
  2127. if (level > 0) {
  2128. var lowerNode = node && node.array[idx];
  2129. var newLowerNode = updateVNode(lowerNode, ownerID, level - SHIFT, index, value, didAlter);
  2130. if (newLowerNode === lowerNode) {
  2131. return node;
  2132. }
  2133. newNode = editableVNode(node, ownerID);
  2134. newNode.array[idx] = newLowerNode;
  2135. return newNode;
  2136. }
  2137. if (nodeHas && node.array[idx] === value) {
  2138. return node;
  2139. }
  2140. SetRef(didAlter);
  2141. newNode = editableVNode(node, ownerID);
  2142. if (value === undefined && idx === newNode.array.length - 1) {
  2143. newNode.array.pop();
  2144. } else {
  2145. newNode.array[idx] = value;
  2146. }
  2147. return newNode;
  2148. }
  2149. function editableVNode(node, ownerID) {
  2150. if (ownerID && node && ownerID === node.ownerID) {
  2151. return node;
  2152. }
  2153. return new VNode(node ? node.array.slice() : [], ownerID);
  2154. }
  2155. function listNodeFor(list, rawIndex) {
  2156. if (rawIndex >= getTailOffset(list._capacity)) {
  2157. return list._tail;
  2158. }
  2159. if (rawIndex < 1 << (list._level + SHIFT)) {
  2160. var node = list._root;
  2161. var level = list._level;
  2162. while (node && level > 0) {
  2163. node = node.array[(rawIndex >>> level) & MASK];
  2164. level -= SHIFT;
  2165. }
  2166. return node;
  2167. }
  2168. }
  2169. function setListBounds(list, begin, end) {
  2170. // Sanitize begin & end using this shorthand for ToInt32(argument)
  2171. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  2172. if (begin !== undefined) {
  2173. begin = begin | 0;
  2174. }
  2175. if (end !== undefined) {
  2176. end = end | 0;
  2177. }
  2178. var owner = list.__ownerID || new OwnerID();
  2179. var oldOrigin = list._origin;
  2180. var oldCapacity = list._capacity;
  2181. var newOrigin = oldOrigin + begin;
  2182. var newCapacity = end === undefined ? oldCapacity : end < 0 ? oldCapacity + end : oldOrigin + end;
  2183. if (newOrigin === oldOrigin && newCapacity === oldCapacity) {
  2184. return list;
  2185. }
  2186. // If it's going to end after it starts, it's empty.
  2187. if (newOrigin >= newCapacity) {
  2188. return list.clear();
  2189. }
  2190. var newLevel = list._level;
  2191. var newRoot = list._root;
  2192. // New origin might need creating a higher root.
  2193. var offsetShift = 0;
  2194. while (newOrigin + offsetShift < 0) {
  2195. newRoot = new VNode(newRoot && newRoot.array.length ? [undefined, newRoot] : [], owner);
  2196. newLevel += SHIFT;
  2197. offsetShift += 1 << newLevel;
  2198. }
  2199. if (offsetShift) {
  2200. newOrigin += offsetShift;
  2201. oldOrigin += offsetShift;
  2202. newCapacity += offsetShift;
  2203. oldCapacity += offsetShift;
  2204. }
  2205. var oldTailOffset = getTailOffset(oldCapacity);
  2206. var newTailOffset = getTailOffset(newCapacity);
  2207. // New size might need creating a higher root.
  2208. while (newTailOffset >= 1 << (newLevel + SHIFT)) {
  2209. newRoot = new VNode(newRoot && newRoot.array.length ? [newRoot] : [], owner);
  2210. newLevel += SHIFT;
  2211. }
  2212. // Locate or create the new tail.
  2213. var oldTail = list._tail;
  2214. var newTail = newTailOffset < oldTailOffset ?
  2215. listNodeFor(list, newCapacity - 1) :
  2216. newTailOffset > oldTailOffset ? new VNode([], owner) : oldTail;
  2217. // Merge Tail into tree.
  2218. if (oldTail && newTailOffset > oldTailOffset && newOrigin < oldCapacity && oldTail.array.length) {
  2219. newRoot = editableVNode(newRoot, owner);
  2220. var node = newRoot;
  2221. for (var level = newLevel; level > SHIFT; level -= SHIFT) {
  2222. var idx = (oldTailOffset >>> level) & MASK;
  2223. node = node.array[idx] = editableVNode(node.array[idx], owner);
  2224. }
  2225. node.array[(oldTailOffset >>> SHIFT) & MASK] = oldTail;
  2226. }
  2227. // If the size has been reduced, there's a chance the tail needs to be trimmed.
  2228. if (newCapacity < oldCapacity) {
  2229. newTail = newTail && newTail.removeAfter(owner, 0, newCapacity);
  2230. }
  2231. // If the new origin is within the tail, then we do not need a root.
  2232. if (newOrigin >= newTailOffset) {
  2233. newOrigin -= newTailOffset;
  2234. newCapacity -= newTailOffset;
  2235. newLevel = SHIFT;
  2236. newRoot = null;
  2237. newTail = newTail && newTail.removeBefore(owner, 0, newOrigin);
  2238. // Otherwise, if the root has been trimmed, garbage collect.
  2239. } else if (newOrigin > oldOrigin || newTailOffset < oldTailOffset) {
  2240. offsetShift = 0;
  2241. // Identify the new top root node of the subtree of the old root.
  2242. while (newRoot) {
  2243. var beginIndex = (newOrigin >>> newLevel) & MASK;
  2244. if (beginIndex !== (newTailOffset >>> newLevel) & MASK) {
  2245. break;
  2246. }
  2247. if (beginIndex) {
  2248. offsetShift += (1 << newLevel) * beginIndex;
  2249. }
  2250. newLevel -= SHIFT;
  2251. newRoot = newRoot.array[beginIndex];
  2252. }
  2253. // Trim the new sides of the new root.
  2254. if (newRoot && newOrigin > oldOrigin) {
  2255. newRoot = newRoot.removeBefore(owner, newLevel, newOrigin - offsetShift);
  2256. }
  2257. if (newRoot && newTailOffset < oldTailOffset) {
  2258. newRoot = newRoot.removeAfter(owner, newLevel, newTailOffset - offsetShift);
  2259. }
  2260. if (offsetShift) {
  2261. newOrigin -= offsetShift;
  2262. newCapacity -= offsetShift;
  2263. }
  2264. }
  2265. if (list.__ownerID) {
  2266. list.size = newCapacity - newOrigin;
  2267. list._origin = newOrigin;
  2268. list._capacity = newCapacity;
  2269. list._level = newLevel;
  2270. list._root = newRoot;
  2271. list._tail = newTail;
  2272. list.__hash = undefined;
  2273. list.__altered = true;
  2274. return list;
  2275. }
  2276. return makeList(newOrigin, newCapacity, newLevel, newRoot, newTail);
  2277. }
  2278. function mergeIntoListWith(list, merger, iterables) {
  2279. var iters = [];
  2280. var maxSize = 0;
  2281. for (var ii = 0; ii < iterables.length; ii++) {
  2282. var value = iterables[ii];
  2283. var iter = IndexedIterable(value);
  2284. if (iter.size > maxSize) {
  2285. maxSize = iter.size;
  2286. }
  2287. if (!isIterable(value)) {
  2288. iter = iter.map(function(v ) {return fromJS(v)});
  2289. }
  2290. iters.push(iter);
  2291. }
  2292. if (maxSize > list.size) {
  2293. list = list.setSize(maxSize);
  2294. }
  2295. return mergeIntoCollectionWith(list, merger, iters);
  2296. }
  2297. function getTailOffset(size) {
  2298. return size < SIZE ? 0 : (((size - 1) >>> SHIFT) << SHIFT);
  2299. }
  2300. createClass(OrderedMap, Map);
  2301. // @pragma Construction
  2302. function OrderedMap(value) {
  2303. return value === null || value === undefined ? emptyOrderedMap() :
  2304. isOrderedMap(value) ? value :
  2305. emptyOrderedMap().withMutations(function(map ) {
  2306. var iter = KeyedIterable(value);
  2307. assertNotInfinite(iter.size);
  2308. iter.forEach(function(v, k) {return map.set(k, v)});
  2309. });
  2310. }
  2311. OrderedMap.of = function(/*...values*/) {
  2312. return this(arguments);
  2313. };
  2314. OrderedMap.prototype.toString = function() {
  2315. return this.__toString('OrderedMap {', '}');
  2316. };
  2317. // @pragma Access
  2318. OrderedMap.prototype.get = function(k, notSetValue) {
  2319. var index = this._map.get(k);
  2320. return index !== undefined ? this._list.get(index)[1] : notSetValue;
  2321. };
  2322. // @pragma Modification
  2323. OrderedMap.prototype.clear = function() {
  2324. if (this.size === 0) {
  2325. return this;
  2326. }
  2327. if (this.__ownerID) {
  2328. this.size = 0;
  2329. this._map.clear();
  2330. this._list.clear();
  2331. return this;
  2332. }
  2333. return emptyOrderedMap();
  2334. };
  2335. OrderedMap.prototype.set = function(k, v) {
  2336. return updateOrderedMap(this, k, v);
  2337. };
  2338. OrderedMap.prototype.remove = function(k) {
  2339. return updateOrderedMap(this, k, NOT_SET);
  2340. };
  2341. OrderedMap.prototype.wasAltered = function() {
  2342. return this._map.wasAltered() || this._list.wasAltered();
  2343. };
  2344. OrderedMap.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  2345. return this._list.__iterate(
  2346. function(entry ) {return entry && fn(entry[1], entry[0], this$0)},
  2347. reverse
  2348. );
  2349. };
  2350. OrderedMap.prototype.__iterator = function(type, reverse) {
  2351. return this._list.fromEntrySeq().__iterator(type, reverse);
  2352. };
  2353. OrderedMap.prototype.__ensureOwner = function(ownerID) {
  2354. if (ownerID === this.__ownerID) {
  2355. return this;
  2356. }
  2357. var newMap = this._map.__ensureOwner(ownerID);
  2358. var newList = this._list.__ensureOwner(ownerID);
  2359. if (!ownerID) {
  2360. this.__ownerID = ownerID;
  2361. this._map = newMap;
  2362. this._list = newList;
  2363. return this;
  2364. }
  2365. return makeOrderedMap(newMap, newList, ownerID, this.__hash);
  2366. };
  2367. function isOrderedMap(maybeOrderedMap) {
  2368. return isMap(maybeOrderedMap) && isOrdered(maybeOrderedMap);
  2369. }
  2370. OrderedMap.isOrderedMap = isOrderedMap;
  2371. OrderedMap.prototype[IS_ORDERED_SENTINEL] = true;
  2372. OrderedMap.prototype[DELETE] = OrderedMap.prototype.remove;
  2373. function makeOrderedMap(map, list, ownerID, hash) {
  2374. var omap = Object.create(OrderedMap.prototype);
  2375. omap.size = map ? map.size : 0;
  2376. omap._map = map;
  2377. omap._list = list;
  2378. omap.__ownerID = ownerID;
  2379. omap.__hash = hash;
  2380. return omap;
  2381. }
  2382. var EMPTY_ORDERED_MAP;
  2383. function emptyOrderedMap() {
  2384. return EMPTY_ORDERED_MAP || (EMPTY_ORDERED_MAP = makeOrderedMap(emptyMap(), emptyList()));
  2385. }
  2386. function updateOrderedMap(omap, k, v) {
  2387. var map = omap._map;
  2388. var list = omap._list;
  2389. var i = map.get(k);
  2390. var has = i !== undefined;
  2391. var newMap;
  2392. var newList;
  2393. if (v === NOT_SET) { // removed
  2394. if (!has) {
  2395. return omap;
  2396. }
  2397. if (list.size >= SIZE && list.size >= map.size * 2) {
  2398. newList = list.filter(function(entry, idx) {return entry !== undefined && i !== idx});
  2399. newMap = newList.toKeyedSeq().map(function(entry ) {return entry[0]}).flip().toMap();
  2400. if (omap.__ownerID) {
  2401. newMap.__ownerID = newList.__ownerID = omap.__ownerID;
  2402. }
  2403. } else {
  2404. newMap = map.remove(k);
  2405. newList = i === list.size - 1 ? list.pop() : list.set(i, undefined);
  2406. }
  2407. } else {
  2408. if (has) {
  2409. if (v === list.get(i)[1]) {
  2410. return omap;
  2411. }
  2412. newMap = map;
  2413. newList = list.set(i, [k, v]);
  2414. } else {
  2415. newMap = map.set(k, list.size);
  2416. newList = list.set(list.size, [k, v]);
  2417. }
  2418. }
  2419. if (omap.__ownerID) {
  2420. omap.size = newMap.size;
  2421. omap._map = newMap;
  2422. omap._list = newList;
  2423. omap.__hash = undefined;
  2424. return omap;
  2425. }
  2426. return makeOrderedMap(newMap, newList);
  2427. }
  2428. createClass(ToKeyedSequence, KeyedSeq);
  2429. function ToKeyedSequence(indexed, useKeys) {
  2430. this._iter = indexed;
  2431. this._useKeys = useKeys;
  2432. this.size = indexed.size;
  2433. }
  2434. ToKeyedSequence.prototype.get = function(key, notSetValue) {
  2435. return this._iter.get(key, notSetValue);
  2436. };
  2437. ToKeyedSequence.prototype.has = function(key) {
  2438. return this._iter.has(key);
  2439. };
  2440. ToKeyedSequence.prototype.valueSeq = function() {
  2441. return this._iter.valueSeq();
  2442. };
  2443. ToKeyedSequence.prototype.reverse = function() {var this$0 = this;
  2444. var reversedSequence = reverseFactory(this, true);
  2445. if (!this._useKeys) {
  2446. reversedSequence.valueSeq = function() {return this$0._iter.toSeq().reverse()};
  2447. }
  2448. return reversedSequence;
  2449. };
  2450. ToKeyedSequence.prototype.map = function(mapper, context) {var this$0 = this;
  2451. var mappedSequence = mapFactory(this, mapper, context);
  2452. if (!this._useKeys) {
  2453. mappedSequence.valueSeq = function() {return this$0._iter.toSeq().map(mapper, context)};
  2454. }
  2455. return mappedSequence;
  2456. };
  2457. ToKeyedSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  2458. var ii;
  2459. return this._iter.__iterate(
  2460. this._useKeys ?
  2461. function(v, k) {return fn(v, k, this$0)} :
  2462. ((ii = reverse ? resolveSize(this) : 0),
  2463. function(v ) {return fn(v, reverse ? --ii : ii++, this$0)}),
  2464. reverse
  2465. );
  2466. };
  2467. ToKeyedSequence.prototype.__iterator = function(type, reverse) {
  2468. if (this._useKeys) {
  2469. return this._iter.__iterator(type, reverse);
  2470. }
  2471. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  2472. var ii = reverse ? resolveSize(this) : 0;
  2473. return new Iterator(function() {
  2474. var step = iterator.next();
  2475. return step.done ? step :
  2476. iteratorValue(type, reverse ? --ii : ii++, step.value, step);
  2477. });
  2478. };
  2479. ToKeyedSequence.prototype[IS_ORDERED_SENTINEL] = true;
  2480. createClass(ToIndexedSequence, IndexedSeq);
  2481. function ToIndexedSequence(iter) {
  2482. this._iter = iter;
  2483. this.size = iter.size;
  2484. }
  2485. ToIndexedSequence.prototype.includes = function(value) {
  2486. return this._iter.includes(value);
  2487. };
  2488. ToIndexedSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  2489. var iterations = 0;
  2490. return this._iter.__iterate(function(v ) {return fn(v, iterations++, this$0)}, reverse);
  2491. };
  2492. ToIndexedSequence.prototype.__iterator = function(type, reverse) {
  2493. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  2494. var iterations = 0;
  2495. return new Iterator(function() {
  2496. var step = iterator.next();
  2497. return step.done ? step :
  2498. iteratorValue(type, iterations++, step.value, step)
  2499. });
  2500. };
  2501. createClass(ToSetSequence, SetSeq);
  2502. function ToSetSequence(iter) {
  2503. this._iter = iter;
  2504. this.size = iter.size;
  2505. }
  2506. ToSetSequence.prototype.has = function(key) {
  2507. return this._iter.includes(key);
  2508. };
  2509. ToSetSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  2510. return this._iter.__iterate(function(v ) {return fn(v, v, this$0)}, reverse);
  2511. };
  2512. ToSetSequence.prototype.__iterator = function(type, reverse) {
  2513. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  2514. return new Iterator(function() {
  2515. var step = iterator.next();
  2516. return step.done ? step :
  2517. iteratorValue(type, step.value, step.value, step);
  2518. });
  2519. };
  2520. createClass(FromEntriesSequence, KeyedSeq);
  2521. function FromEntriesSequence(entries) {
  2522. this._iter = entries;
  2523. this.size = entries.size;
  2524. }
  2525. FromEntriesSequence.prototype.entrySeq = function() {
  2526. return this._iter.toSeq();
  2527. };
  2528. FromEntriesSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  2529. return this._iter.__iterate(function(entry ) {
  2530. // Check if entry exists first so array access doesn't throw for holes
  2531. // in the parent iteration.
  2532. if (entry) {
  2533. validateEntry(entry);
  2534. var indexedIterable = isIterable(entry);
  2535. return fn(
  2536. indexedIterable ? entry.get(1) : entry[1],
  2537. indexedIterable ? entry.get(0) : entry[0],
  2538. this$0
  2539. );
  2540. }
  2541. }, reverse);
  2542. };
  2543. FromEntriesSequence.prototype.__iterator = function(type, reverse) {
  2544. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  2545. return new Iterator(function() {
  2546. while (true) {
  2547. var step = iterator.next();
  2548. if (step.done) {
  2549. return step;
  2550. }
  2551. var entry = step.value;
  2552. // Check if entry exists first so array access doesn't throw for holes
  2553. // in the parent iteration.
  2554. if (entry) {
  2555. validateEntry(entry);
  2556. var indexedIterable = isIterable(entry);
  2557. return iteratorValue(
  2558. type,
  2559. indexedIterable ? entry.get(0) : entry[0],
  2560. indexedIterable ? entry.get(1) : entry[1],
  2561. step
  2562. );
  2563. }
  2564. }
  2565. });
  2566. };
  2567. ToIndexedSequence.prototype.cacheResult =
  2568. ToKeyedSequence.prototype.cacheResult =
  2569. ToSetSequence.prototype.cacheResult =
  2570. FromEntriesSequence.prototype.cacheResult =
  2571. cacheResultThrough;
  2572. function flipFactory(iterable) {
  2573. var flipSequence = makeSequence(iterable);
  2574. flipSequence._iter = iterable;
  2575. flipSequence.size = iterable.size;
  2576. flipSequence.flip = function() {return iterable};
  2577. flipSequence.reverse = function () {
  2578. var reversedSequence = iterable.reverse.apply(this); // super.reverse()
  2579. reversedSequence.flip = function() {return iterable.reverse()};
  2580. return reversedSequence;
  2581. };
  2582. flipSequence.has = function(key ) {return iterable.includes(key)};
  2583. flipSequence.includes = function(key ) {return iterable.has(key)};
  2584. flipSequence.cacheResult = cacheResultThrough;
  2585. flipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  2586. return iterable.__iterate(function(v, k) {return fn(k, v, this$0) !== false}, reverse);
  2587. };
  2588. flipSequence.__iteratorUncached = function(type, reverse) {
  2589. if (type === ITERATE_ENTRIES) {
  2590. var iterator = iterable.__iterator(type, reverse);
  2591. return new Iterator(function() {
  2592. var step = iterator.next();
  2593. if (!step.done) {
  2594. var k = step.value[0];
  2595. step.value[0] = step.value[1];
  2596. step.value[1] = k;
  2597. }
  2598. return step;
  2599. });
  2600. }
  2601. return iterable.__iterator(
  2602. type === ITERATE_VALUES ? ITERATE_KEYS : ITERATE_VALUES,
  2603. reverse
  2604. );
  2605. };
  2606. return flipSequence;
  2607. }
  2608. function mapFactory(iterable, mapper, context) {
  2609. var mappedSequence = makeSequence(iterable);
  2610. mappedSequence.size = iterable.size;
  2611. mappedSequence.has = function(key ) {return iterable.has(key)};
  2612. mappedSequence.get = function(key, notSetValue) {
  2613. var v = iterable.get(key, NOT_SET);
  2614. return v === NOT_SET ?
  2615. notSetValue :
  2616. mapper.call(context, v, key, iterable);
  2617. };
  2618. mappedSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  2619. return iterable.__iterate(
  2620. function(v, k, c) {return fn(mapper.call(context, v, k, c), k, this$0) !== false},
  2621. reverse
  2622. );
  2623. };
  2624. mappedSequence.__iteratorUncached = function (type, reverse) {
  2625. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  2626. return new Iterator(function() {
  2627. var step = iterator.next();
  2628. if (step.done) {
  2629. return step;
  2630. }
  2631. var entry = step.value;
  2632. var key = entry[0];
  2633. return iteratorValue(
  2634. type,
  2635. key,
  2636. mapper.call(context, entry[1], key, iterable),
  2637. step
  2638. );
  2639. });
  2640. };
  2641. return mappedSequence;
  2642. }
  2643. function reverseFactory(iterable, useKeys) {
  2644. var reversedSequence = makeSequence(iterable);
  2645. reversedSequence._iter = iterable;
  2646. reversedSequence.size = iterable.size;
  2647. reversedSequence.reverse = function() {return iterable};
  2648. if (iterable.flip) {
  2649. reversedSequence.flip = function () {
  2650. var flipSequence = flipFactory(iterable);
  2651. flipSequence.reverse = function() {return iterable.flip()};
  2652. return flipSequence;
  2653. };
  2654. }
  2655. reversedSequence.get = function(key, notSetValue)
  2656. {return iterable.get(useKeys ? key : -1 - key, notSetValue)};
  2657. reversedSequence.has = function(key )
  2658. {return iterable.has(useKeys ? key : -1 - key)};
  2659. reversedSequence.includes = function(value ) {return iterable.includes(value)};
  2660. reversedSequence.cacheResult = cacheResultThrough;
  2661. reversedSequence.__iterate = function (fn, reverse) {var this$0 = this;
  2662. return iterable.__iterate(function(v, k) {return fn(v, k, this$0)}, !reverse);
  2663. };
  2664. reversedSequence.__iterator =
  2665. function(type, reverse) {return iterable.__iterator(type, !reverse)};
  2666. return reversedSequence;
  2667. }
  2668. function filterFactory(iterable, predicate, context, useKeys) {
  2669. var filterSequence = makeSequence(iterable);
  2670. if (useKeys) {
  2671. filterSequence.has = function(key ) {
  2672. var v = iterable.get(key, NOT_SET);
  2673. return v !== NOT_SET && !!predicate.call(context, v, key, iterable);
  2674. };
  2675. filterSequence.get = function(key, notSetValue) {
  2676. var v = iterable.get(key, NOT_SET);
  2677. return v !== NOT_SET && predicate.call(context, v, key, iterable) ?
  2678. v : notSetValue;
  2679. };
  2680. }
  2681. filterSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  2682. var iterations = 0;
  2683. iterable.__iterate(function(v, k, c) {
  2684. if (predicate.call(context, v, k, c)) {
  2685. iterations++;
  2686. return fn(v, useKeys ? k : iterations - 1, this$0);
  2687. }
  2688. }, reverse);
  2689. return iterations;
  2690. };
  2691. filterSequence.__iteratorUncached = function (type, reverse) {
  2692. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  2693. var iterations = 0;
  2694. return new Iterator(function() {
  2695. while (true) {
  2696. var step = iterator.next();
  2697. if (step.done) {
  2698. return step;
  2699. }
  2700. var entry = step.value;
  2701. var key = entry[0];
  2702. var value = entry[1];
  2703. if (predicate.call(context, value, key, iterable)) {
  2704. return iteratorValue(type, useKeys ? key : iterations++, value, step);
  2705. }
  2706. }
  2707. });
  2708. };
  2709. return filterSequence;
  2710. }
  2711. function countByFactory(iterable, grouper, context) {
  2712. var groups = Map().asMutable();
  2713. iterable.__iterate(function(v, k) {
  2714. groups.update(
  2715. grouper.call(context, v, k, iterable),
  2716. 0,
  2717. function(a ) {return a + 1}
  2718. );
  2719. });
  2720. return groups.asImmutable();
  2721. }
  2722. function groupByFactory(iterable, grouper, context) {
  2723. var isKeyedIter = isKeyed(iterable);
  2724. var groups = (isOrdered(iterable) ? OrderedMap() : Map()).asMutable();
  2725. iterable.__iterate(function(v, k) {
  2726. groups.update(
  2727. grouper.call(context, v, k, iterable),
  2728. function(a ) {return (a = a || [], a.push(isKeyedIter ? [k, v] : v), a)}
  2729. );
  2730. });
  2731. var coerce = iterableClass(iterable);
  2732. return groups.map(function(arr ) {return reify(iterable, coerce(arr))});
  2733. }
  2734. function sliceFactory(iterable, begin, end, useKeys) {
  2735. var originalSize = iterable.size;
  2736. // Sanitize begin & end using this shorthand for ToInt32(argument)
  2737. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  2738. if (begin !== undefined) {
  2739. begin = begin | 0;
  2740. }
  2741. if (end !== undefined) {
  2742. end = end | 0;
  2743. }
  2744. if (wholeSlice(begin, end, originalSize)) {
  2745. return iterable;
  2746. }
  2747. var resolvedBegin = resolveBegin(begin, originalSize);
  2748. var resolvedEnd = resolveEnd(end, originalSize);
  2749. // begin or end will be NaN if they were provided as negative numbers and
  2750. // this iterable's size is unknown. In that case, cache first so there is
  2751. // a known size and these do not resolve to NaN.
  2752. if (resolvedBegin !== resolvedBegin || resolvedEnd !== resolvedEnd) {
  2753. return sliceFactory(iterable.toSeq().cacheResult(), begin, end, useKeys);
  2754. }
  2755. // Note: resolvedEnd is undefined when the original sequence's length is
  2756. // unknown and this slice did not supply an end and should contain all
  2757. // elements after resolvedBegin.
  2758. // In that case, resolvedSize will be NaN and sliceSize will remain undefined.
  2759. var resolvedSize = resolvedEnd - resolvedBegin;
  2760. var sliceSize;
  2761. if (resolvedSize === resolvedSize) {
  2762. sliceSize = resolvedSize < 0 ? 0 : resolvedSize;
  2763. }
  2764. var sliceSeq = makeSequence(iterable);
  2765. // If iterable.size is undefined, the size of the realized sliceSeq is
  2766. // unknown at this point unless the number of items to slice is 0
  2767. sliceSeq.size = sliceSize === 0 ? sliceSize : iterable.size && sliceSize || undefined;
  2768. if (!useKeys && isSeq(iterable) && sliceSize >= 0) {
  2769. sliceSeq.get = function (index, notSetValue) {
  2770. index = wrapIndex(this, index);
  2771. return index >= 0 && index < sliceSize ?
  2772. iterable.get(index + resolvedBegin, notSetValue) :
  2773. notSetValue;
  2774. };
  2775. }
  2776. sliceSeq.__iterateUncached = function(fn, reverse) {var this$0 = this;
  2777. if (sliceSize === 0) {
  2778. return 0;
  2779. }
  2780. if (reverse) {
  2781. return this.cacheResult().__iterate(fn, reverse);
  2782. }
  2783. var skipped = 0;
  2784. var isSkipping = true;
  2785. var iterations = 0;
  2786. iterable.__iterate(function(v, k) {
  2787. if (!(isSkipping && (isSkipping = skipped++ < resolvedBegin))) {
  2788. iterations++;
  2789. return fn(v, useKeys ? k : iterations - 1, this$0) !== false &&
  2790. iterations !== sliceSize;
  2791. }
  2792. });
  2793. return iterations;
  2794. };
  2795. sliceSeq.__iteratorUncached = function(type, reverse) {
  2796. if (sliceSize !== 0 && reverse) {
  2797. return this.cacheResult().__iterator(type, reverse);
  2798. }
  2799. // Don't bother instantiating parent iterator if taking 0.
  2800. var iterator = sliceSize !== 0 && iterable.__iterator(type, reverse);
  2801. var skipped = 0;
  2802. var iterations = 0;
  2803. return new Iterator(function() {
  2804. while (skipped++ < resolvedBegin) {
  2805. iterator.next();
  2806. }
  2807. if (++iterations > sliceSize) {
  2808. return iteratorDone();
  2809. }
  2810. var step = iterator.next();
  2811. if (useKeys || type === ITERATE_VALUES) {
  2812. return step;
  2813. } else if (type === ITERATE_KEYS) {
  2814. return iteratorValue(type, iterations - 1, undefined, step);
  2815. } else {
  2816. return iteratorValue(type, iterations - 1, step.value[1], step);
  2817. }
  2818. });
  2819. };
  2820. return sliceSeq;
  2821. }
  2822. function takeWhileFactory(iterable, predicate, context) {
  2823. var takeSequence = makeSequence(iterable);
  2824. takeSequence.__iterateUncached = function(fn, reverse) {var this$0 = this;
  2825. if (reverse) {
  2826. return this.cacheResult().__iterate(fn, reverse);
  2827. }
  2828. var iterations = 0;
  2829. iterable.__iterate(function(v, k, c)
  2830. {return predicate.call(context, v, k, c) && ++iterations && fn(v, k, this$0)}
  2831. );
  2832. return iterations;
  2833. };
  2834. takeSequence.__iteratorUncached = function(type, reverse) {var this$0 = this;
  2835. if (reverse) {
  2836. return this.cacheResult().__iterator(type, reverse);
  2837. }
  2838. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  2839. var iterating = true;
  2840. return new Iterator(function() {
  2841. if (!iterating) {
  2842. return iteratorDone();
  2843. }
  2844. var step = iterator.next();
  2845. if (step.done) {
  2846. return step;
  2847. }
  2848. var entry = step.value;
  2849. var k = entry[0];
  2850. var v = entry[1];
  2851. if (!predicate.call(context, v, k, this$0)) {
  2852. iterating = false;
  2853. return iteratorDone();
  2854. }
  2855. return type === ITERATE_ENTRIES ? step :
  2856. iteratorValue(type, k, v, step);
  2857. });
  2858. };
  2859. return takeSequence;
  2860. }
  2861. function skipWhileFactory(iterable, predicate, context, useKeys) {
  2862. var skipSequence = makeSequence(iterable);
  2863. skipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  2864. if (reverse) {
  2865. return this.cacheResult().__iterate(fn, reverse);
  2866. }
  2867. var isSkipping = true;
  2868. var iterations = 0;
  2869. iterable.__iterate(function(v, k, c) {
  2870. if (!(isSkipping && (isSkipping = predicate.call(context, v, k, c)))) {
  2871. iterations++;
  2872. return fn(v, useKeys ? k : iterations - 1, this$0);
  2873. }
  2874. });
  2875. return iterations;
  2876. };
  2877. skipSequence.__iteratorUncached = function(type, reverse) {var this$0 = this;
  2878. if (reverse) {
  2879. return this.cacheResult().__iterator(type, reverse);
  2880. }
  2881. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  2882. var skipping = true;
  2883. var iterations = 0;
  2884. return new Iterator(function() {
  2885. var step, k, v;
  2886. do {
  2887. step = iterator.next();
  2888. if (step.done) {
  2889. if (useKeys || type === ITERATE_VALUES) {
  2890. return step;
  2891. } else if (type === ITERATE_KEYS) {
  2892. return iteratorValue(type, iterations++, undefined, step);
  2893. } else {
  2894. return iteratorValue(type, iterations++, step.value[1], step);
  2895. }
  2896. }
  2897. var entry = step.value;
  2898. k = entry[0];
  2899. v = entry[1];
  2900. skipping && (skipping = predicate.call(context, v, k, this$0));
  2901. } while (skipping);
  2902. return type === ITERATE_ENTRIES ? step :
  2903. iteratorValue(type, k, v, step);
  2904. });
  2905. };
  2906. return skipSequence;
  2907. }
  2908. function concatFactory(iterable, values) {
  2909. var isKeyedIterable = isKeyed(iterable);
  2910. var iters = [iterable].concat(values).map(function(v ) {
  2911. if (!isIterable(v)) {
  2912. v = isKeyedIterable ?
  2913. keyedSeqFromValue(v) :
  2914. indexedSeqFromValue(Array.isArray(v) ? v : [v]);
  2915. } else if (isKeyedIterable) {
  2916. v = KeyedIterable(v);
  2917. }
  2918. return v;
  2919. }).filter(function(v ) {return v.size !== 0});
  2920. if (iters.length === 0) {
  2921. return iterable;
  2922. }
  2923. if (iters.length === 1) {
  2924. var singleton = iters[0];
  2925. if (singleton === iterable ||
  2926. isKeyedIterable && isKeyed(singleton) ||
  2927. isIndexed(iterable) && isIndexed(singleton)) {
  2928. return singleton;
  2929. }
  2930. }
  2931. var concatSeq = new ArraySeq(iters);
  2932. if (isKeyedIterable) {
  2933. concatSeq = concatSeq.toKeyedSeq();
  2934. } else if (!isIndexed(iterable)) {
  2935. concatSeq = concatSeq.toSetSeq();
  2936. }
  2937. concatSeq = concatSeq.flatten(true);
  2938. concatSeq.size = iters.reduce(
  2939. function(sum, seq) {
  2940. if (sum !== undefined) {
  2941. var size = seq.size;
  2942. if (size !== undefined) {
  2943. return sum + size;
  2944. }
  2945. }
  2946. },
  2947. 0
  2948. );
  2949. return concatSeq;
  2950. }
  2951. function flattenFactory(iterable, depth, useKeys) {
  2952. var flatSequence = makeSequence(iterable);
  2953. flatSequence.__iterateUncached = function(fn, reverse) {
  2954. var iterations = 0;
  2955. var stopped = false;
  2956. function flatDeep(iter, currentDepth) {var this$0 = this;
  2957. iter.__iterate(function(v, k) {
  2958. if ((!depth || currentDepth < depth) && isIterable(v)) {
  2959. flatDeep(v, currentDepth + 1);
  2960. } else if (fn(v, useKeys ? k : iterations++, this$0) === false) {
  2961. stopped = true;
  2962. }
  2963. return !stopped;
  2964. }, reverse);
  2965. }
  2966. flatDeep(iterable, 0);
  2967. return iterations;
  2968. };
  2969. flatSequence.__iteratorUncached = function(type, reverse) {
  2970. var iterator = iterable.__iterator(type, reverse);
  2971. var stack = [];
  2972. var iterations = 0;
  2973. return new Iterator(function() {
  2974. while (iterator) {
  2975. var step = iterator.next();
  2976. if (step.done !== false) {
  2977. iterator = stack.pop();
  2978. continue;
  2979. }
  2980. var v = step.value;
  2981. if (type === ITERATE_ENTRIES) {
  2982. v = v[1];
  2983. }
  2984. if ((!depth || stack.length < depth) && isIterable(v)) {
  2985. stack.push(iterator);
  2986. iterator = v.__iterator(type, reverse);
  2987. } else {
  2988. return useKeys ? step : iteratorValue(type, iterations++, v, step);
  2989. }
  2990. }
  2991. return iteratorDone();
  2992. });
  2993. };
  2994. return flatSequence;
  2995. }
  2996. function flatMapFactory(iterable, mapper, context) {
  2997. var coerce = iterableClass(iterable);
  2998. return iterable.toSeq().map(
  2999. function(v, k) {return coerce(mapper.call(context, v, k, iterable))}
  3000. ).flatten(true);
  3001. }
  3002. function interposeFactory(iterable, separator) {
  3003. var interposedSequence = makeSequence(iterable);
  3004. interposedSequence.size = iterable.size && iterable.size * 2 -1;
  3005. interposedSequence.__iterateUncached = function(fn, reverse) {var this$0 = this;
  3006. var iterations = 0;
  3007. iterable.__iterate(function(v, k)
  3008. {return (!iterations || fn(separator, iterations++, this$0) !== false) &&
  3009. fn(v, iterations++, this$0) !== false},
  3010. reverse
  3011. );
  3012. return iterations;
  3013. };
  3014. interposedSequence.__iteratorUncached = function(type, reverse) {
  3015. var iterator = iterable.__iterator(ITERATE_VALUES, reverse);
  3016. var iterations = 0;
  3017. var step;
  3018. return new Iterator(function() {
  3019. if (!step || iterations % 2) {
  3020. step = iterator.next();
  3021. if (step.done) {
  3022. return step;
  3023. }
  3024. }
  3025. return iterations % 2 ?
  3026. iteratorValue(type, iterations++, separator) :
  3027. iteratorValue(type, iterations++, step.value, step);
  3028. });
  3029. };
  3030. return interposedSequence;
  3031. }
  3032. function sortFactory(iterable, comparator, mapper) {
  3033. if (!comparator) {
  3034. comparator = defaultComparator;
  3035. }
  3036. var isKeyedIterable = isKeyed(iterable);
  3037. var index = 0;
  3038. var entries = iterable.toSeq().map(
  3039. function(v, k) {return [k, v, index++, mapper ? mapper(v, k, iterable) : v]}
  3040. ).toArray();
  3041. entries.sort(function(a, b) {return comparator(a[3], b[3]) || a[2] - b[2]}).forEach(
  3042. isKeyedIterable ?
  3043. function(v, i) { entries[i].length = 2; } :
  3044. function(v, i) { entries[i] = v[1]; }
  3045. );
  3046. return isKeyedIterable ? KeyedSeq(entries) :
  3047. isIndexed(iterable) ? IndexedSeq(entries) :
  3048. SetSeq(entries);
  3049. }
  3050. function maxFactory(iterable, comparator, mapper) {
  3051. if (!comparator) {
  3052. comparator = defaultComparator;
  3053. }
  3054. if (mapper) {
  3055. var entry = iterable.toSeq()
  3056. .map(function(v, k) {return [v, mapper(v, k, iterable)]})
  3057. .reduce(function(a, b) {return maxCompare(comparator, a[1], b[1]) ? b : a});
  3058. return entry && entry[0];
  3059. } else {
  3060. return iterable.reduce(function(a, b) {return maxCompare(comparator, a, b) ? b : a});
  3061. }
  3062. }
  3063. function maxCompare(comparator, a, b) {
  3064. var comp = comparator(b, a);
  3065. // b is considered the new max if the comparator declares them equal, but
  3066. // they are not equal and b is in fact a nullish value.
  3067. return (comp === 0 && b !== a && (b === undefined || b === null || b !== b)) || comp > 0;
  3068. }
  3069. function zipWithFactory(keyIter, zipper, iters) {
  3070. var zipSequence = makeSequence(keyIter);
  3071. zipSequence.size = new ArraySeq(iters).map(function(i ) {return i.size}).min();
  3072. // Note: this a generic base implementation of __iterate in terms of
  3073. // __iterator which may be more generically useful in the future.
  3074. zipSequence.__iterate = function(fn, reverse) {
  3075. /* generic:
  3076. var iterator = this.__iterator(ITERATE_ENTRIES, reverse);
  3077. var step;
  3078. var iterations = 0;
  3079. while (!(step = iterator.next()).done) {
  3080. iterations++;
  3081. if (fn(step.value[1], step.value[0], this) === false) {
  3082. break;
  3083. }
  3084. }
  3085. return iterations;
  3086. */
  3087. // indexed:
  3088. var iterator = this.__iterator(ITERATE_VALUES, reverse);
  3089. var step;
  3090. var iterations = 0;
  3091. while (!(step = iterator.next()).done) {
  3092. if (fn(step.value, iterations++, this) === false) {
  3093. break;
  3094. }
  3095. }
  3096. return iterations;
  3097. };
  3098. zipSequence.__iteratorUncached = function(type, reverse) {
  3099. var iterators = iters.map(function(i )
  3100. {return (i = Iterable(i), getIterator(reverse ? i.reverse() : i))}
  3101. );
  3102. var iterations = 0;
  3103. var isDone = false;
  3104. return new Iterator(function() {
  3105. var steps;
  3106. if (!isDone) {
  3107. steps = iterators.map(function(i ) {return i.next()});
  3108. isDone = steps.some(function(s ) {return s.done});
  3109. }
  3110. if (isDone) {
  3111. return iteratorDone();
  3112. }
  3113. return iteratorValue(
  3114. type,
  3115. iterations++,
  3116. zipper.apply(null, steps.map(function(s ) {return s.value}))
  3117. );
  3118. });
  3119. };
  3120. return zipSequence
  3121. }
  3122. // #pragma Helper Functions
  3123. function reify(iter, seq) {
  3124. return isSeq(iter) ? seq : iter.constructor(seq);
  3125. }
  3126. function validateEntry(entry) {
  3127. if (entry !== Object(entry)) {
  3128. throw new TypeError('Expected [K, V] tuple: ' + entry);
  3129. }
  3130. }
  3131. function resolveSize(iter) {
  3132. assertNotInfinite(iter.size);
  3133. return ensureSize(iter);
  3134. }
  3135. function iterableClass(iterable) {
  3136. return isKeyed(iterable) ? KeyedIterable :
  3137. isIndexed(iterable) ? IndexedIterable :
  3138. SetIterable;
  3139. }
  3140. function makeSequence(iterable) {
  3141. return Object.create(
  3142. (
  3143. isKeyed(iterable) ? KeyedSeq :
  3144. isIndexed(iterable) ? IndexedSeq :
  3145. SetSeq
  3146. ).prototype
  3147. );
  3148. }
  3149. function cacheResultThrough() {
  3150. if (this._iter.cacheResult) {
  3151. this._iter.cacheResult();
  3152. this.size = this._iter.size;
  3153. return this;
  3154. } else {
  3155. return Seq.prototype.cacheResult.call(this);
  3156. }
  3157. }
  3158. function defaultComparator(a, b) {
  3159. return a > b ? 1 : a < b ? -1 : 0;
  3160. }
  3161. function forceIterator(keyPath) {
  3162. var iter = getIterator(keyPath);
  3163. if (!iter) {
  3164. // Array might not be iterable in this environment, so we need a fallback
  3165. // to our wrapped type.
  3166. if (!isArrayLike(keyPath)) {
  3167. throw new TypeError('Expected iterable or array-like: ' + keyPath);
  3168. }
  3169. iter = getIterator(Iterable(keyPath));
  3170. }
  3171. return iter;
  3172. }
  3173. createClass(Record, KeyedCollection);
  3174. function Record(defaultValues, name) {
  3175. var hasInitialized;
  3176. var RecordType = function Record(values) {
  3177. if (values instanceof RecordType) {
  3178. return values;
  3179. }
  3180. if (!(this instanceof RecordType)) {
  3181. return new RecordType(values);
  3182. }
  3183. if (!hasInitialized) {
  3184. hasInitialized = true;
  3185. var keys = Object.keys(defaultValues);
  3186. setProps(RecordTypePrototype, keys);
  3187. RecordTypePrototype.size = keys.length;
  3188. RecordTypePrototype._name = name;
  3189. RecordTypePrototype._keys = keys;
  3190. RecordTypePrototype._defaultValues = defaultValues;
  3191. }
  3192. this._map = Map(values);
  3193. };
  3194. var RecordTypePrototype = RecordType.prototype = Object.create(RecordPrototype);
  3195. RecordTypePrototype.constructor = RecordType;
  3196. return RecordType;
  3197. }
  3198. Record.prototype.toString = function() {
  3199. return this.__toString(recordName(this) + ' {', '}');
  3200. };
  3201. // @pragma Access
  3202. Record.prototype.has = function(k) {
  3203. return this._defaultValues.hasOwnProperty(k);
  3204. };
  3205. Record.prototype.get = function(k, notSetValue) {
  3206. if (!this.has(k)) {
  3207. return notSetValue;
  3208. }
  3209. var defaultVal = this._defaultValues[k];
  3210. return this._map ? this._map.get(k, defaultVal) : defaultVal;
  3211. };
  3212. // @pragma Modification
  3213. Record.prototype.clear = function() {
  3214. if (this.__ownerID) {
  3215. this._map && this._map.clear();
  3216. return this;
  3217. }
  3218. var RecordType = this.constructor;
  3219. return RecordType._empty || (RecordType._empty = makeRecord(this, emptyMap()));
  3220. };
  3221. Record.prototype.set = function(k, v) {
  3222. if (!this.has(k)) {
  3223. throw new Error('Cannot set unknown key "' + k + '" on ' + recordName(this));
  3224. }
  3225. var newMap = this._map && this._map.set(k, v);
  3226. if (this.__ownerID || newMap === this._map) {
  3227. return this;
  3228. }
  3229. return makeRecord(this, newMap);
  3230. };
  3231. Record.prototype.remove = function(k) {
  3232. if (!this.has(k)) {
  3233. return this;
  3234. }
  3235. var newMap = this._map && this._map.remove(k);
  3236. if (this.__ownerID || newMap === this._map) {
  3237. return this;
  3238. }
  3239. return makeRecord(this, newMap);
  3240. };
  3241. Record.prototype.wasAltered = function() {
  3242. return this._map.wasAltered();
  3243. };
  3244. Record.prototype.__iterator = function(type, reverse) {var this$0 = this;
  3245. return KeyedIterable(this._defaultValues).map(function(_, k) {return this$0.get(k)}).__iterator(type, reverse);
  3246. };
  3247. Record.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  3248. return KeyedIterable(this._defaultValues).map(function(_, k) {return this$0.get(k)}).__iterate(fn, reverse);
  3249. };
  3250. Record.prototype.__ensureOwner = function(ownerID) {
  3251. if (ownerID === this.__ownerID) {
  3252. return this;
  3253. }
  3254. var newMap = this._map && this._map.__ensureOwner(ownerID);
  3255. if (!ownerID) {
  3256. this.__ownerID = ownerID;
  3257. this._map = newMap;
  3258. return this;
  3259. }
  3260. return makeRecord(this, newMap, ownerID);
  3261. };
  3262. var RecordPrototype = Record.prototype;
  3263. RecordPrototype[DELETE] = RecordPrototype.remove;
  3264. RecordPrototype.deleteIn =
  3265. RecordPrototype.removeIn = MapPrototype.removeIn;
  3266. RecordPrototype.merge = MapPrototype.merge;
  3267. RecordPrototype.mergeWith = MapPrototype.mergeWith;
  3268. RecordPrototype.mergeIn = MapPrototype.mergeIn;
  3269. RecordPrototype.mergeDeep = MapPrototype.mergeDeep;
  3270. RecordPrototype.mergeDeepWith = MapPrototype.mergeDeepWith;
  3271. RecordPrototype.mergeDeepIn = MapPrototype.mergeDeepIn;
  3272. RecordPrototype.setIn = MapPrototype.setIn;
  3273. RecordPrototype.update = MapPrototype.update;
  3274. RecordPrototype.updateIn = MapPrototype.updateIn;
  3275. RecordPrototype.withMutations = MapPrototype.withMutations;
  3276. RecordPrototype.asMutable = MapPrototype.asMutable;
  3277. RecordPrototype.asImmutable = MapPrototype.asImmutable;
  3278. function makeRecord(likeRecord, map, ownerID) {
  3279. var record = Object.create(Object.getPrototypeOf(likeRecord));
  3280. record._map = map;
  3281. record.__ownerID = ownerID;
  3282. return record;
  3283. }
  3284. function recordName(record) {
  3285. return record._name || record.constructor.name || 'Record';
  3286. }
  3287. function setProps(prototype, names) {
  3288. try {
  3289. names.forEach(setProp.bind(undefined, prototype));
  3290. } catch (error) {
  3291. // Object.defineProperty failed. Probably IE8.
  3292. }
  3293. }
  3294. function setProp(prototype, name) {
  3295. Object.defineProperty(prototype, name, {
  3296. get: function() {
  3297. return this.get(name);
  3298. },
  3299. set: function(value) {
  3300. invariant(this.__ownerID, 'Cannot set on an immutable record.');
  3301. this.set(name, value);
  3302. }
  3303. });
  3304. }
  3305. createClass(Set, SetCollection);
  3306. // @pragma Construction
  3307. function Set(value) {
  3308. return value === null || value === undefined ? emptySet() :
  3309. isSet(value) && !isOrdered(value) ? value :
  3310. emptySet().withMutations(function(set ) {
  3311. var iter = SetIterable(value);
  3312. assertNotInfinite(iter.size);
  3313. iter.forEach(function(v ) {return set.add(v)});
  3314. });
  3315. }
  3316. Set.of = function(/*...values*/) {
  3317. return this(arguments);
  3318. };
  3319. Set.fromKeys = function(value) {
  3320. return this(KeyedIterable(value).keySeq());
  3321. };
  3322. Set.prototype.toString = function() {
  3323. return this.__toString('Set {', '}');
  3324. };
  3325. // @pragma Access
  3326. Set.prototype.has = function(value) {
  3327. return this._map.has(value);
  3328. };
  3329. // @pragma Modification
  3330. Set.prototype.add = function(value) {
  3331. return updateSet(this, this._map.set(value, true));
  3332. };
  3333. Set.prototype.remove = function(value) {
  3334. return updateSet(this, this._map.remove(value));
  3335. };
  3336. Set.prototype.clear = function() {
  3337. return updateSet(this, this._map.clear());
  3338. };
  3339. // @pragma Composition
  3340. Set.prototype.union = function() {var iters = SLICE$0.call(arguments, 0);
  3341. iters = iters.filter(function(x ) {return x.size !== 0});
  3342. if (iters.length === 0) {
  3343. return this;
  3344. }
  3345. if (this.size === 0 && !this.__ownerID && iters.length === 1) {
  3346. return this.constructor(iters[0]);
  3347. }
  3348. return this.withMutations(function(set ) {
  3349. for (var ii = 0; ii < iters.length; ii++) {
  3350. SetIterable(iters[ii]).forEach(function(value ) {return set.add(value)});
  3351. }
  3352. });
  3353. };
  3354. Set.prototype.intersect = function() {var iters = SLICE$0.call(arguments, 0);
  3355. if (iters.length === 0) {
  3356. return this;
  3357. }
  3358. iters = iters.map(function(iter ) {return SetIterable(iter)});
  3359. var originalSet = this;
  3360. return this.withMutations(function(set ) {
  3361. originalSet.forEach(function(value ) {
  3362. if (!iters.every(function(iter ) {return iter.includes(value)})) {
  3363. set.remove(value);
  3364. }
  3365. });
  3366. });
  3367. };
  3368. Set.prototype.subtract = function() {var iters = SLICE$0.call(arguments, 0);
  3369. if (iters.length === 0) {
  3370. return this;
  3371. }
  3372. iters = iters.map(function(iter ) {return SetIterable(iter)});
  3373. var originalSet = this;
  3374. return this.withMutations(function(set ) {
  3375. originalSet.forEach(function(value ) {
  3376. if (iters.some(function(iter ) {return iter.includes(value)})) {
  3377. set.remove(value);
  3378. }
  3379. });
  3380. });
  3381. };
  3382. Set.prototype.merge = function() {
  3383. return this.union.apply(this, arguments);
  3384. };
  3385. Set.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  3386. return this.union.apply(this, iters);
  3387. };
  3388. Set.prototype.sort = function(comparator) {
  3389. // Late binding
  3390. return OrderedSet(sortFactory(this, comparator));
  3391. };
  3392. Set.prototype.sortBy = function(mapper, comparator) {
  3393. // Late binding
  3394. return OrderedSet(sortFactory(this, comparator, mapper));
  3395. };
  3396. Set.prototype.wasAltered = function() {
  3397. return this._map.wasAltered();
  3398. };
  3399. Set.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  3400. return this._map.__iterate(function(_, k) {return fn(k, k, this$0)}, reverse);
  3401. };
  3402. Set.prototype.__iterator = function(type, reverse) {
  3403. return this._map.map(function(_, k) {return k}).__iterator(type, reverse);
  3404. };
  3405. Set.prototype.__ensureOwner = function(ownerID) {
  3406. if (ownerID === this.__ownerID) {
  3407. return this;
  3408. }
  3409. var newMap = this._map.__ensureOwner(ownerID);
  3410. if (!ownerID) {
  3411. this.__ownerID = ownerID;
  3412. this._map = newMap;
  3413. return this;
  3414. }
  3415. return this.__make(newMap, ownerID);
  3416. };
  3417. function isSet(maybeSet) {
  3418. return !!(maybeSet && maybeSet[IS_SET_SENTINEL]);
  3419. }
  3420. Set.isSet = isSet;
  3421. var IS_SET_SENTINEL = '@@__IMMUTABLE_SET__@@';
  3422. var SetPrototype = Set.prototype;
  3423. SetPrototype[IS_SET_SENTINEL] = true;
  3424. SetPrototype[DELETE] = SetPrototype.remove;
  3425. SetPrototype.mergeDeep = SetPrototype.merge;
  3426. SetPrototype.mergeDeepWith = SetPrototype.mergeWith;
  3427. SetPrototype.withMutations = MapPrototype.withMutations;
  3428. SetPrototype.asMutable = MapPrototype.asMutable;
  3429. SetPrototype.asImmutable = MapPrototype.asImmutable;
  3430. SetPrototype.__empty = emptySet;
  3431. SetPrototype.__make = makeSet;
  3432. function updateSet(set, newMap) {
  3433. if (set.__ownerID) {
  3434. set.size = newMap.size;
  3435. set._map = newMap;
  3436. return set;
  3437. }
  3438. return newMap === set._map ? set :
  3439. newMap.size === 0 ? set.__empty() :
  3440. set.__make(newMap);
  3441. }
  3442. function makeSet(map, ownerID) {
  3443. var set = Object.create(SetPrototype);
  3444. set.size = map ? map.size : 0;
  3445. set._map = map;
  3446. set.__ownerID = ownerID;
  3447. return set;
  3448. }
  3449. var EMPTY_SET;
  3450. function emptySet() {
  3451. return EMPTY_SET || (EMPTY_SET = makeSet(emptyMap()));
  3452. }
  3453. createClass(OrderedSet, Set);
  3454. // @pragma Construction
  3455. function OrderedSet(value) {
  3456. return value === null || value === undefined ? emptyOrderedSet() :
  3457. isOrderedSet(value) ? value :
  3458. emptyOrderedSet().withMutations(function(set ) {
  3459. var iter = SetIterable(value);
  3460. assertNotInfinite(iter.size);
  3461. iter.forEach(function(v ) {return set.add(v)});
  3462. });
  3463. }
  3464. OrderedSet.of = function(/*...values*/) {
  3465. return this(arguments);
  3466. };
  3467. OrderedSet.fromKeys = function(value) {
  3468. return this(KeyedIterable(value).keySeq());
  3469. };
  3470. OrderedSet.prototype.toString = function() {
  3471. return this.__toString('OrderedSet {', '}');
  3472. };
  3473. function isOrderedSet(maybeOrderedSet) {
  3474. return isSet(maybeOrderedSet) && isOrdered(maybeOrderedSet);
  3475. }
  3476. OrderedSet.isOrderedSet = isOrderedSet;
  3477. var OrderedSetPrototype = OrderedSet.prototype;
  3478. OrderedSetPrototype[IS_ORDERED_SENTINEL] = true;
  3479. OrderedSetPrototype.__empty = emptyOrderedSet;
  3480. OrderedSetPrototype.__make = makeOrderedSet;
  3481. function makeOrderedSet(map, ownerID) {
  3482. var set = Object.create(OrderedSetPrototype);
  3483. set.size = map ? map.size : 0;
  3484. set._map = map;
  3485. set.__ownerID = ownerID;
  3486. return set;
  3487. }
  3488. var EMPTY_ORDERED_SET;
  3489. function emptyOrderedSet() {
  3490. return EMPTY_ORDERED_SET || (EMPTY_ORDERED_SET = makeOrderedSet(emptyOrderedMap()));
  3491. }
  3492. createClass(Stack, IndexedCollection);
  3493. // @pragma Construction
  3494. function Stack(value) {
  3495. return value === null || value === undefined ? emptyStack() :
  3496. isStack(value) ? value :
  3497. emptyStack().unshiftAll(value);
  3498. }
  3499. Stack.of = function(/*...values*/) {
  3500. return this(arguments);
  3501. };
  3502. Stack.prototype.toString = function() {
  3503. return this.__toString('Stack [', ']');
  3504. };
  3505. // @pragma Access
  3506. Stack.prototype.get = function(index, notSetValue) {
  3507. var head = this._head;
  3508. index = wrapIndex(this, index);
  3509. while (head && index--) {
  3510. head = head.next;
  3511. }
  3512. return head ? head.value : notSetValue;
  3513. };
  3514. Stack.prototype.peek = function() {
  3515. return this._head && this._head.value;
  3516. };
  3517. // @pragma Modification
  3518. Stack.prototype.push = function(/*...values*/) {
  3519. if (arguments.length === 0) {
  3520. return this;
  3521. }
  3522. var newSize = this.size + arguments.length;
  3523. var head = this._head;
  3524. for (var ii = arguments.length - 1; ii >= 0; ii--) {
  3525. head = {
  3526. value: arguments[ii],
  3527. next: head
  3528. };
  3529. }
  3530. if (this.__ownerID) {
  3531. this.size = newSize;
  3532. this._head = head;
  3533. this.__hash = undefined;
  3534. this.__altered = true;
  3535. return this;
  3536. }
  3537. return makeStack(newSize, head);
  3538. };
  3539. Stack.prototype.pushAll = function(iter) {
  3540. iter = IndexedIterable(iter);
  3541. if (iter.size === 0) {
  3542. return this;
  3543. }
  3544. assertNotInfinite(iter.size);
  3545. var newSize = this.size;
  3546. var head = this._head;
  3547. iter.reverse().forEach(function(value ) {
  3548. newSize++;
  3549. head = {
  3550. value: value,
  3551. next: head
  3552. };
  3553. });
  3554. if (this.__ownerID) {
  3555. this.size = newSize;
  3556. this._head = head;
  3557. this.__hash = undefined;
  3558. this.__altered = true;
  3559. return this;
  3560. }
  3561. return makeStack(newSize, head);
  3562. };
  3563. Stack.prototype.pop = function() {
  3564. return this.slice(1);
  3565. };
  3566. Stack.prototype.unshift = function(/*...values*/) {
  3567. return this.push.apply(this, arguments);
  3568. };
  3569. Stack.prototype.unshiftAll = function(iter) {
  3570. return this.pushAll(iter);
  3571. };
  3572. Stack.prototype.shift = function() {
  3573. return this.pop.apply(this, arguments);
  3574. };
  3575. Stack.prototype.clear = function() {
  3576. if (this.size === 0) {
  3577. return this;
  3578. }
  3579. if (this.__ownerID) {
  3580. this.size = 0;
  3581. this._head = undefined;
  3582. this.__hash = undefined;
  3583. this.__altered = true;
  3584. return this;
  3585. }
  3586. return emptyStack();
  3587. };
  3588. Stack.prototype.slice = function(begin, end) {
  3589. if (wholeSlice(begin, end, this.size)) {
  3590. return this;
  3591. }
  3592. var resolvedBegin = resolveBegin(begin, this.size);
  3593. var resolvedEnd = resolveEnd(end, this.size);
  3594. if (resolvedEnd !== this.size) {
  3595. // super.slice(begin, end);
  3596. return IndexedCollection.prototype.slice.call(this, begin, end);
  3597. }
  3598. var newSize = this.size - resolvedBegin;
  3599. var head = this._head;
  3600. while (resolvedBegin--) {
  3601. head = head.next;
  3602. }
  3603. if (this.__ownerID) {
  3604. this.size = newSize;
  3605. this._head = head;
  3606. this.__hash = undefined;
  3607. this.__altered = true;
  3608. return this;
  3609. }
  3610. return makeStack(newSize, head);
  3611. };
  3612. // @pragma Mutability
  3613. Stack.prototype.__ensureOwner = function(ownerID) {
  3614. if (ownerID === this.__ownerID) {
  3615. return this;
  3616. }
  3617. if (!ownerID) {
  3618. this.__ownerID = ownerID;
  3619. this.__altered = false;
  3620. return this;
  3621. }
  3622. return makeStack(this.size, this._head, ownerID, this.__hash);
  3623. };
  3624. // @pragma Iteration
  3625. Stack.prototype.__iterate = function(fn, reverse) {
  3626. if (reverse) {
  3627. return this.reverse().__iterate(fn);
  3628. }
  3629. var iterations = 0;
  3630. var node = this._head;
  3631. while (node) {
  3632. if (fn(node.value, iterations++, this) === false) {
  3633. break;
  3634. }
  3635. node = node.next;
  3636. }
  3637. return iterations;
  3638. };
  3639. Stack.prototype.__iterator = function(type, reverse) {
  3640. if (reverse) {
  3641. return this.reverse().__iterator(type);
  3642. }
  3643. var iterations = 0;
  3644. var node = this._head;
  3645. return new Iterator(function() {
  3646. if (node) {
  3647. var value = node.value;
  3648. node = node.next;
  3649. return iteratorValue(type, iterations++, value);
  3650. }
  3651. return iteratorDone();
  3652. });
  3653. };
  3654. function isStack(maybeStack) {
  3655. return !!(maybeStack && maybeStack[IS_STACK_SENTINEL]);
  3656. }
  3657. Stack.isStack = isStack;
  3658. var IS_STACK_SENTINEL = '@@__IMMUTABLE_STACK__@@';
  3659. var StackPrototype = Stack.prototype;
  3660. StackPrototype[IS_STACK_SENTINEL] = true;
  3661. StackPrototype.withMutations = MapPrototype.withMutations;
  3662. StackPrototype.asMutable = MapPrototype.asMutable;
  3663. StackPrototype.asImmutable = MapPrototype.asImmutable;
  3664. StackPrototype.wasAltered = MapPrototype.wasAltered;
  3665. function makeStack(size, head, ownerID, hash) {
  3666. var map = Object.create(StackPrototype);
  3667. map.size = size;
  3668. map._head = head;
  3669. map.__ownerID = ownerID;
  3670. map.__hash = hash;
  3671. map.__altered = false;
  3672. return map;
  3673. }
  3674. var EMPTY_STACK;
  3675. function emptyStack() {
  3676. return EMPTY_STACK || (EMPTY_STACK = makeStack(0));
  3677. }
  3678. /**
  3679. * Contributes additional methods to a constructor
  3680. */
  3681. function mixin(ctor, methods) {
  3682. var keyCopier = function(key ) { ctor.prototype[key] = methods[key]; };
  3683. Object.keys(methods).forEach(keyCopier);
  3684. Object.getOwnPropertySymbols &&
  3685. Object.getOwnPropertySymbols(methods).forEach(keyCopier);
  3686. return ctor;
  3687. }
  3688. Iterable.Iterator = Iterator;
  3689. mixin(Iterable, {
  3690. // ### Conversion to other types
  3691. toArray: function() {
  3692. assertNotInfinite(this.size);
  3693. var array = new Array(this.size || 0);
  3694. this.valueSeq().__iterate(function(v, i) { array[i] = v; });
  3695. return array;
  3696. },
  3697. toIndexedSeq: function() {
  3698. return new ToIndexedSequence(this);
  3699. },
  3700. toJS: function() {
  3701. return this.toSeq().map(
  3702. function(value ) {return value && typeof value.toJS === 'function' ? value.toJS() : value}
  3703. ).__toJS();
  3704. },
  3705. toJSON: function() {
  3706. return this.toSeq().map(
  3707. function(value ) {return value && typeof value.toJSON === 'function' ? value.toJSON() : value}
  3708. ).__toJS();
  3709. },
  3710. toKeyedSeq: function() {
  3711. return new ToKeyedSequence(this, true);
  3712. },
  3713. toMap: function() {
  3714. // Use Late Binding here to solve the circular dependency.
  3715. return Map(this.toKeyedSeq());
  3716. },
  3717. toObject: function() {
  3718. assertNotInfinite(this.size);
  3719. var object = {};
  3720. this.__iterate(function(v, k) { object[k] = v; });
  3721. return object;
  3722. },
  3723. toOrderedMap: function() {
  3724. // Use Late Binding here to solve the circular dependency.
  3725. return OrderedMap(this.toKeyedSeq());
  3726. },
  3727. toOrderedSet: function() {
  3728. // Use Late Binding here to solve the circular dependency.
  3729. return OrderedSet(isKeyed(this) ? this.valueSeq() : this);
  3730. },
  3731. toSet: function() {
  3732. // Use Late Binding here to solve the circular dependency.
  3733. return Set(isKeyed(this) ? this.valueSeq() : this);
  3734. },
  3735. toSetSeq: function() {
  3736. return new ToSetSequence(this);
  3737. },
  3738. toSeq: function() {
  3739. return isIndexed(this) ? this.toIndexedSeq() :
  3740. isKeyed(this) ? this.toKeyedSeq() :
  3741. this.toSetSeq();
  3742. },
  3743. toStack: function() {
  3744. // Use Late Binding here to solve the circular dependency.
  3745. return Stack(isKeyed(this) ? this.valueSeq() : this);
  3746. },
  3747. toList: function() {
  3748. // Use Late Binding here to solve the circular dependency.
  3749. return List(isKeyed(this) ? this.valueSeq() : this);
  3750. },
  3751. // ### Common JavaScript methods and properties
  3752. toString: function() {
  3753. return '[Iterable]';
  3754. },
  3755. __toString: function(head, tail) {
  3756. if (this.size === 0) {
  3757. return head + tail;
  3758. }
  3759. return head + ' ' + this.toSeq().map(this.__toStringMapper).join(', ') + ' ' + tail;
  3760. },
  3761. // ### ES6 Collection methods (ES6 Array and Map)
  3762. concat: function() {var values = SLICE$0.call(arguments, 0);
  3763. return reify(this, concatFactory(this, values));
  3764. },
  3765. includes: function(searchValue) {
  3766. return this.some(function(value ) {return is(value, searchValue)});
  3767. },
  3768. entries: function() {
  3769. return this.__iterator(ITERATE_ENTRIES);
  3770. },
  3771. every: function(predicate, context) {
  3772. assertNotInfinite(this.size);
  3773. var returnValue = true;
  3774. this.__iterate(function(v, k, c) {
  3775. if (!predicate.call(context, v, k, c)) {
  3776. returnValue = false;
  3777. return false;
  3778. }
  3779. });
  3780. return returnValue;
  3781. },
  3782. filter: function(predicate, context) {
  3783. return reify(this, filterFactory(this, predicate, context, true));
  3784. },
  3785. find: function(predicate, context, notSetValue) {
  3786. var entry = this.findEntry(predicate, context);
  3787. return entry ? entry[1] : notSetValue;
  3788. },
  3789. findEntry: function(predicate, context) {
  3790. var found;
  3791. this.__iterate(function(v, k, c) {
  3792. if (predicate.call(context, v, k, c)) {
  3793. found = [k, v];
  3794. return false;
  3795. }
  3796. });
  3797. return found;
  3798. },
  3799. findLastEntry: function(predicate, context) {
  3800. return this.toSeq().reverse().findEntry(predicate, context);
  3801. },
  3802. forEach: function(sideEffect, context) {
  3803. assertNotInfinite(this.size);
  3804. return this.__iterate(context ? sideEffect.bind(context) : sideEffect);
  3805. },
  3806. join: function(separator) {
  3807. assertNotInfinite(this.size);
  3808. separator = separator !== undefined ? '' + separator : ',';
  3809. var joined = '';
  3810. var isFirst = true;
  3811. this.__iterate(function(v ) {
  3812. isFirst ? (isFirst = false) : (joined += separator);
  3813. joined += v !== null && v !== undefined ? v.toString() : '';
  3814. });
  3815. return joined;
  3816. },
  3817. keys: function() {
  3818. return this.__iterator(ITERATE_KEYS);
  3819. },
  3820. map: function(mapper, context) {
  3821. return reify(this, mapFactory(this, mapper, context));
  3822. },
  3823. reduce: function(reducer, initialReduction, context) {
  3824. assertNotInfinite(this.size);
  3825. var reduction;
  3826. var useFirst;
  3827. if (arguments.length < 2) {
  3828. useFirst = true;
  3829. } else {
  3830. reduction = initialReduction;
  3831. }
  3832. this.__iterate(function(v, k, c) {
  3833. if (useFirst) {
  3834. useFirst = false;
  3835. reduction = v;
  3836. } else {
  3837. reduction = reducer.call(context, reduction, v, k, c);
  3838. }
  3839. });
  3840. return reduction;
  3841. },
  3842. reduceRight: function(reducer, initialReduction, context) {
  3843. var reversed = this.toKeyedSeq().reverse();
  3844. return reversed.reduce.apply(reversed, arguments);
  3845. },
  3846. reverse: function() {
  3847. return reify(this, reverseFactory(this, true));
  3848. },
  3849. slice: function(begin, end) {
  3850. return reify(this, sliceFactory(this, begin, end, true));
  3851. },
  3852. some: function(predicate, context) {
  3853. return !this.every(not(predicate), context);
  3854. },
  3855. sort: function(comparator) {
  3856. return reify(this, sortFactory(this, comparator));
  3857. },
  3858. values: function() {
  3859. return this.__iterator(ITERATE_VALUES);
  3860. },
  3861. // ### More sequential methods
  3862. butLast: function() {
  3863. return this.slice(0, -1);
  3864. },
  3865. isEmpty: function() {
  3866. return this.size !== undefined ? this.size === 0 : !this.some(function() {return true});
  3867. },
  3868. count: function(predicate, context) {
  3869. return ensureSize(
  3870. predicate ? this.toSeq().filter(predicate, context) : this
  3871. );
  3872. },
  3873. countBy: function(grouper, context) {
  3874. return countByFactory(this, grouper, context);
  3875. },
  3876. equals: function(other) {
  3877. return deepEqual(this, other);
  3878. },
  3879. entrySeq: function() {
  3880. var iterable = this;
  3881. if (iterable._cache) {
  3882. // We cache as an entries array, so we can just return the cache!
  3883. return new ArraySeq(iterable._cache);
  3884. }
  3885. var entriesSequence = iterable.toSeq().map(entryMapper).toIndexedSeq();
  3886. entriesSequence.fromEntrySeq = function() {return iterable.toSeq()};
  3887. return entriesSequence;
  3888. },
  3889. filterNot: function(predicate, context) {
  3890. return this.filter(not(predicate), context);
  3891. },
  3892. findLast: function(predicate, context, notSetValue) {
  3893. return this.toKeyedSeq().reverse().find(predicate, context, notSetValue);
  3894. },
  3895. first: function() {
  3896. return this.find(returnTrue);
  3897. },
  3898. flatMap: function(mapper, context) {
  3899. return reify(this, flatMapFactory(this, mapper, context));
  3900. },
  3901. flatten: function(depth) {
  3902. return reify(this, flattenFactory(this, depth, true));
  3903. },
  3904. fromEntrySeq: function() {
  3905. return new FromEntriesSequence(this);
  3906. },
  3907. get: function(searchKey, notSetValue) {
  3908. return this.find(function(_, key) {return is(key, searchKey)}, undefined, notSetValue);
  3909. },
  3910. getIn: function(searchKeyPath, notSetValue) {
  3911. var nested = this;
  3912. // Note: in an ES6 environment, we would prefer:
  3913. // for (var key of searchKeyPath) {
  3914. var iter = forceIterator(searchKeyPath);
  3915. var step;
  3916. while (!(step = iter.next()).done) {
  3917. var key = step.value;
  3918. nested = nested && nested.get ? nested.get(key, NOT_SET) : NOT_SET;
  3919. if (nested === NOT_SET) {
  3920. return notSetValue;
  3921. }
  3922. }
  3923. return nested;
  3924. },
  3925. groupBy: function(grouper, context) {
  3926. return groupByFactory(this, grouper, context);
  3927. },
  3928. has: function(searchKey) {
  3929. return this.get(searchKey, NOT_SET) !== NOT_SET;
  3930. },
  3931. hasIn: function(searchKeyPath) {
  3932. return this.getIn(searchKeyPath, NOT_SET) !== NOT_SET;
  3933. },
  3934. isSubset: function(iter) {
  3935. iter = typeof iter.includes === 'function' ? iter : Iterable(iter);
  3936. return this.every(function(value ) {return iter.includes(value)});
  3937. },
  3938. isSuperset: function(iter) {
  3939. iter = typeof iter.isSubset === 'function' ? iter : Iterable(iter);
  3940. return iter.isSubset(this);
  3941. },
  3942. keySeq: function() {
  3943. return this.toSeq().map(keyMapper).toIndexedSeq();
  3944. },
  3945. last: function() {
  3946. return this.toSeq().reverse().first();
  3947. },
  3948. max: function(comparator) {
  3949. return maxFactory(this, comparator);
  3950. },
  3951. maxBy: function(mapper, comparator) {
  3952. return maxFactory(this, comparator, mapper);
  3953. },
  3954. min: function(comparator) {
  3955. return maxFactory(this, comparator ? neg(comparator) : defaultNegComparator);
  3956. },
  3957. minBy: function(mapper, comparator) {
  3958. return maxFactory(this, comparator ? neg(comparator) : defaultNegComparator, mapper);
  3959. },
  3960. rest: function() {
  3961. return this.slice(1);
  3962. },
  3963. skip: function(amount) {
  3964. return this.slice(Math.max(0, amount));
  3965. },
  3966. skipLast: function(amount) {
  3967. return reify(this, this.toSeq().reverse().skip(amount).reverse());
  3968. },
  3969. skipWhile: function(predicate, context) {
  3970. return reify(this, skipWhileFactory(this, predicate, context, true));
  3971. },
  3972. skipUntil: function(predicate, context) {
  3973. return this.skipWhile(not(predicate), context);
  3974. },
  3975. sortBy: function(mapper, comparator) {
  3976. return reify(this, sortFactory(this, comparator, mapper));
  3977. },
  3978. take: function(amount) {
  3979. return this.slice(0, Math.max(0, amount));
  3980. },
  3981. takeLast: function(amount) {
  3982. return reify(this, this.toSeq().reverse().take(amount).reverse());
  3983. },
  3984. takeWhile: function(predicate, context) {
  3985. return reify(this, takeWhileFactory(this, predicate, context));
  3986. },
  3987. takeUntil: function(predicate, context) {
  3988. return this.takeWhile(not(predicate), context);
  3989. },
  3990. valueSeq: function() {
  3991. return this.toIndexedSeq();
  3992. },
  3993. // ### Hashable Object
  3994. hashCode: function() {
  3995. return this.__hash || (this.__hash = hashIterable(this));
  3996. }
  3997. // ### Internal
  3998. // abstract __iterate(fn, reverse)
  3999. // abstract __iterator(type, reverse)
  4000. });
  4001. // var IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
  4002. // var IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
  4003. // var IS_INDEXED_SENTINEL = '@@__IMMUTABLE_INDEXED__@@';
  4004. // var IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
  4005. var IterablePrototype = Iterable.prototype;
  4006. IterablePrototype[IS_ITERABLE_SENTINEL] = true;
  4007. IterablePrototype[ITERATOR_SYMBOL] = IterablePrototype.values;
  4008. IterablePrototype.__toJS = IterablePrototype.toArray;
  4009. IterablePrototype.__toStringMapper = quoteString;
  4010. IterablePrototype.inspect =
  4011. IterablePrototype.toSource = function() { return this.toString(); };
  4012. IterablePrototype.chain = IterablePrototype.flatMap;
  4013. IterablePrototype.contains = IterablePrototype.includes;
  4014. // Temporary warning about using length
  4015. (function () {
  4016. try {
  4017. Object.defineProperty(IterablePrototype, 'length', {
  4018. get: function () {
  4019. if (!Iterable.noLengthWarning) {
  4020. var stack;
  4021. try {
  4022. throw new Error();
  4023. } catch (error) {
  4024. stack = error.stack;
  4025. }
  4026. if (stack.indexOf('_wrapObject') === -1) {
  4027. console && console.warn && console.warn(
  4028. 'iterable.length has been deprecated, '+
  4029. 'use iterable.size or iterable.count(). '+
  4030. 'This warning will become a silent error in a future version. ' +
  4031. stack
  4032. );
  4033. return this.size;
  4034. }
  4035. }
  4036. }
  4037. });
  4038. } catch (e) {}
  4039. })();
  4040. mixin(KeyedIterable, {
  4041. // ### More sequential methods
  4042. flip: function() {
  4043. return reify(this, flipFactory(this));
  4044. },
  4045. findKey: function(predicate, context) {
  4046. var entry = this.findEntry(predicate, context);
  4047. return entry && entry[0];
  4048. },
  4049. findLastKey: function(predicate, context) {
  4050. return this.toSeq().reverse().findKey(predicate, context);
  4051. },
  4052. keyOf: function(searchValue) {
  4053. return this.findKey(function(value ) {return is(value, searchValue)});
  4054. },
  4055. lastKeyOf: function(searchValue) {
  4056. return this.findLastKey(function(value ) {return is(value, searchValue)});
  4057. },
  4058. mapEntries: function(mapper, context) {var this$0 = this;
  4059. var iterations = 0;
  4060. return reify(this,
  4061. this.toSeq().map(
  4062. function(v, k) {return mapper.call(context, [k, v], iterations++, this$0)}
  4063. ).fromEntrySeq()
  4064. );
  4065. },
  4066. mapKeys: function(mapper, context) {var this$0 = this;
  4067. return reify(this,
  4068. this.toSeq().flip().map(
  4069. function(k, v) {return mapper.call(context, k, v, this$0)}
  4070. ).flip()
  4071. );
  4072. }
  4073. });
  4074. var KeyedIterablePrototype = KeyedIterable.prototype;
  4075. KeyedIterablePrototype[IS_KEYED_SENTINEL] = true;
  4076. KeyedIterablePrototype[ITERATOR_SYMBOL] = IterablePrototype.entries;
  4077. KeyedIterablePrototype.__toJS = IterablePrototype.toObject;
  4078. KeyedIterablePrototype.__toStringMapper = function(v, k) {return JSON.stringify(k) + ': ' + quoteString(v)};
  4079. mixin(IndexedIterable, {
  4080. // ### Conversion to other types
  4081. toKeyedSeq: function() {
  4082. return new ToKeyedSequence(this, false);
  4083. },
  4084. // ### ES6 Collection methods (ES6 Array and Map)
  4085. filter: function(predicate, context) {
  4086. return reify(this, filterFactory(this, predicate, context, false));
  4087. },
  4088. findIndex: function(predicate, context) {
  4089. var entry = this.findEntry(predicate, context);
  4090. return entry ? entry[0] : -1;
  4091. },
  4092. indexOf: function(searchValue) {
  4093. var key = this.toKeyedSeq().keyOf(searchValue);
  4094. return key === undefined ? -1 : key;
  4095. },
  4096. lastIndexOf: function(searchValue) {
  4097. var key = this.toKeyedSeq().reverse().keyOf(searchValue);
  4098. return key === undefined ? -1 : key;
  4099. // var index =
  4100. // return this.toSeq().reverse().indexOf(searchValue);
  4101. },
  4102. reverse: function() {
  4103. return reify(this, reverseFactory(this, false));
  4104. },
  4105. slice: function(begin, end) {
  4106. return reify(this, sliceFactory(this, begin, end, false));
  4107. },
  4108. splice: function(index, removeNum /*, ...values*/) {
  4109. var numArgs = arguments.length;
  4110. removeNum = Math.max(removeNum | 0, 0);
  4111. if (numArgs === 0 || (numArgs === 2 && !removeNum)) {
  4112. return this;
  4113. }
  4114. // If index is negative, it should resolve relative to the size of the
  4115. // collection. However size may be expensive to compute if not cached, so
  4116. // only call count() if the number is in fact negative.
  4117. index = resolveBegin(index, index < 0 ? this.count() : this.size);
  4118. var spliced = this.slice(0, index);
  4119. return reify(
  4120. this,
  4121. numArgs === 1 ?
  4122. spliced :
  4123. spliced.concat(arrCopy(arguments, 2), this.slice(index + removeNum))
  4124. );
  4125. },
  4126. // ### More collection methods
  4127. findLastIndex: function(predicate, context) {
  4128. var key = this.toKeyedSeq().findLastKey(predicate, context);
  4129. return key === undefined ? -1 : key;
  4130. },
  4131. first: function() {
  4132. return this.get(0);
  4133. },
  4134. flatten: function(depth) {
  4135. return reify(this, flattenFactory(this, depth, false));
  4136. },
  4137. get: function(index, notSetValue) {
  4138. index = wrapIndex(this, index);
  4139. return (index < 0 || (this.size === Infinity ||
  4140. (this.size !== undefined && index > this.size))) ?
  4141. notSetValue :
  4142. this.find(function(_, key) {return key === index}, undefined, notSetValue);
  4143. },
  4144. has: function(index) {
  4145. index = wrapIndex(this, index);
  4146. return index >= 0 && (this.size !== undefined ?
  4147. this.size === Infinity || index < this.size :
  4148. this.indexOf(index) !== -1
  4149. );
  4150. },
  4151. interpose: function(separator) {
  4152. return reify(this, interposeFactory(this, separator));
  4153. },
  4154. interleave: function(/*...iterables*/) {
  4155. var iterables = [this].concat(arrCopy(arguments));
  4156. var zipped = zipWithFactory(this.toSeq(), IndexedSeq.of, iterables);
  4157. var interleaved = zipped.flatten(true);
  4158. if (zipped.size) {
  4159. interleaved.size = zipped.size * iterables.length;
  4160. }
  4161. return reify(this, interleaved);
  4162. },
  4163. last: function() {
  4164. return this.get(-1);
  4165. },
  4166. skipWhile: function(predicate, context) {
  4167. return reify(this, skipWhileFactory(this, predicate, context, false));
  4168. },
  4169. zip: function(/*, ...iterables */) {
  4170. var iterables = [this].concat(arrCopy(arguments));
  4171. return reify(this, zipWithFactory(this, defaultZipper, iterables));
  4172. },
  4173. zipWith: function(zipper/*, ...iterables */) {
  4174. var iterables = arrCopy(arguments);
  4175. iterables[0] = this;
  4176. return reify(this, zipWithFactory(this, zipper, iterables));
  4177. }
  4178. });
  4179. IndexedIterable.prototype[IS_INDEXED_SENTINEL] = true;
  4180. IndexedIterable.prototype[IS_ORDERED_SENTINEL] = true;
  4181. mixin(SetIterable, {
  4182. // ### ES6 Collection methods (ES6 Array and Map)
  4183. get: function(value, notSetValue) {
  4184. return this.has(value) ? value : notSetValue;
  4185. },
  4186. includes: function(value) {
  4187. return this.has(value);
  4188. },
  4189. // ### More sequential methods
  4190. keySeq: function() {
  4191. return this.valueSeq();
  4192. }
  4193. });
  4194. SetIterable.prototype.has = IterablePrototype.includes;
  4195. // Mixin subclasses
  4196. mixin(KeyedSeq, KeyedIterable.prototype);
  4197. mixin(IndexedSeq, IndexedIterable.prototype);
  4198. mixin(SetSeq, SetIterable.prototype);
  4199. mixin(KeyedCollection, KeyedIterable.prototype);
  4200. mixin(IndexedCollection, IndexedIterable.prototype);
  4201. mixin(SetCollection, SetIterable.prototype);
  4202. // #pragma Helper functions
  4203. function keyMapper(v, k) {
  4204. return k;
  4205. }
  4206. function entryMapper(v, k) {
  4207. return [k, v];
  4208. }
  4209. function not(predicate) {
  4210. return function() {
  4211. return !predicate.apply(this, arguments);
  4212. }
  4213. }
  4214. function neg(predicate) {
  4215. return function() {
  4216. return -predicate.apply(this, arguments);
  4217. }
  4218. }
  4219. function quoteString(value) {
  4220. return typeof value === 'string' ? JSON.stringify(value) : value;
  4221. }
  4222. function defaultZipper() {
  4223. return arrCopy(arguments);
  4224. }
  4225. function defaultNegComparator(a, b) {
  4226. return a < b ? 1 : a > b ? -1 : 0;
  4227. }
  4228. function hashIterable(iterable) {
  4229. if (iterable.size === Infinity) {
  4230. return 0;
  4231. }
  4232. var ordered = isOrdered(iterable);
  4233. var keyed = isKeyed(iterable);
  4234. var h = ordered ? 1 : 0;
  4235. var size = iterable.__iterate(
  4236. keyed ?
  4237. ordered ?
  4238. function(v, k) { h = 31 * h + hashMerge(hash(v), hash(k)) | 0; } :
  4239. function(v, k) { h = h + hashMerge(hash(v), hash(k)) | 0; } :
  4240. ordered ?
  4241. function(v ) { h = 31 * h + hash(v) | 0; } :
  4242. function(v ) { h = h + hash(v) | 0; }
  4243. );
  4244. return murmurHashOfSize(size, h);
  4245. }
  4246. function murmurHashOfSize(size, h) {
  4247. h = imul(h, 0xCC9E2D51);
  4248. h = imul(h << 15 | h >>> -15, 0x1B873593);
  4249. h = imul(h << 13 | h >>> -13, 5);
  4250. h = (h + 0xE6546B64 | 0) ^ size;
  4251. h = imul(h ^ h >>> 16, 0x85EBCA6B);
  4252. h = imul(h ^ h >>> 13, 0xC2B2AE35);
  4253. h = smi(h ^ h >>> 16);
  4254. return h;
  4255. }
  4256. function hashMerge(a, b) {
  4257. return a ^ b + 0x9E3779B9 + (a << 6) + (a >> 2) | 0; // int
  4258. }
  4259. var Immutable = {
  4260. Iterable: Iterable,
  4261. Seq: Seq,
  4262. Collection: Collection,
  4263. Map: Map,
  4264. OrderedMap: OrderedMap,
  4265. List: List,
  4266. Stack: Stack,
  4267. Set: Set,
  4268. OrderedSet: OrderedSet,
  4269. Record: Record,
  4270. Range: Range,
  4271. Repeat: Repeat,
  4272. is: is,
  4273. fromJS: fromJS
  4274. };
  4275. return Immutable;
  4276. }));
  4277. });
  4278. var OrderedMap = immutable.OrderedMap;
  4279. var BlockMapBuilder = {
  4280. createFromArray: function createFromArray(blocks) {
  4281. return OrderedMap(blocks.map(function (block) {
  4282. return [block.getKey(), block];
  4283. }));
  4284. }
  4285. };
  4286. var BlockMapBuilder_1 = BlockMapBuilder;
  4287. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4288. 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; }
  4289. 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; }
  4290. var Map = immutable.Map,
  4291. OrderedSet = immutable.OrderedSet,
  4292. Record = immutable.Record;
  4293. // Immutable.map is typed such that the value for every key in the map
  4294. // must be the same type
  4295. var EMPTY_SET = OrderedSet();
  4296. var defaultRecord = {
  4297. style: EMPTY_SET,
  4298. entity: null
  4299. };
  4300. var CharacterMetadataRecord = Record(defaultRecord);
  4301. var CharacterMetadata = function (_CharacterMetadataRec) {
  4302. _inherits(CharacterMetadata, _CharacterMetadataRec);
  4303. function CharacterMetadata() {
  4304. _classCallCheck(this, CharacterMetadata);
  4305. return _possibleConstructorReturn(this, _CharacterMetadataRec.apply(this, arguments));
  4306. }
  4307. CharacterMetadata.prototype.getStyle = function getStyle() {
  4308. return this.get('style');
  4309. };
  4310. CharacterMetadata.prototype.getEntity = function getEntity() {
  4311. return this.get('entity');
  4312. };
  4313. CharacterMetadata.prototype.hasStyle = function hasStyle(style) {
  4314. return this.getStyle().includes(style);
  4315. };
  4316. CharacterMetadata.applyStyle = function applyStyle(record, style) {
  4317. var withStyle = record.set('style', record.getStyle().add(style));
  4318. return CharacterMetadata.create(withStyle);
  4319. };
  4320. CharacterMetadata.removeStyle = function removeStyle(record, style) {
  4321. var withoutStyle = record.set('style', record.getStyle().remove(style));
  4322. return CharacterMetadata.create(withoutStyle);
  4323. };
  4324. CharacterMetadata.applyEntity = function applyEntity(record, entityKey) {
  4325. var withEntity = record.getEntity() === entityKey ? record : record.set('entity', entityKey);
  4326. return CharacterMetadata.create(withEntity);
  4327. };
  4328. /**
  4329. * Use this function instead of the `CharacterMetadata` constructor.
  4330. * Since most content generally uses only a very small number of
  4331. * style/entity permutations, we can reuse these objects as often as
  4332. * possible.
  4333. */
  4334. CharacterMetadata.create = function create(config) {
  4335. if (!config) {
  4336. return EMPTY;
  4337. }
  4338. var defaultConfig = {
  4339. style: EMPTY_SET,
  4340. entity: null
  4341. };
  4342. // Fill in unspecified properties, if necessary.
  4343. var configMap = Map(defaultConfig).merge(config);
  4344. var existing = pool.get(configMap);
  4345. if (existing) {
  4346. return existing;
  4347. }
  4348. var newCharacter = new CharacterMetadata(configMap);
  4349. pool = pool.set(configMap, newCharacter);
  4350. return newCharacter;
  4351. };
  4352. return CharacterMetadata;
  4353. }(CharacterMetadataRecord);
  4354. var EMPTY = new CharacterMetadata();
  4355. var pool = Map([[Map(defaultRecord), EMPTY]]);
  4356. CharacterMetadata.EMPTY = EMPTY;
  4357. var CharacterMetadata_1 = CharacterMetadata;
  4358. /**
  4359. * Copyright (c) 2013-present, Facebook, Inc.
  4360. * All rights reserved.
  4361. *
  4362. * This source code is licensed under the BSD-style license found in the
  4363. * LICENSE file in the root directory of this source tree. An additional grant
  4364. * of patent rights can be found in the PATENTS file in the same directory.
  4365. *
  4366. * @providesModule findRangesImmutable
  4367. * @format
  4368. *
  4369. */
  4370. /**
  4371. * Search through an array to find contiguous stretches of elements that
  4372. * match a specified filter function.
  4373. *
  4374. * When ranges are found, execute a specified `found` function to supply
  4375. * the values to the caller.
  4376. */
  4377. function findRangesImmutable(haystack, areEqualFn, filterFn, foundFn) {
  4378. if (!haystack.size) {
  4379. return;
  4380. }
  4381. var cursor = 0;
  4382. haystack.reduce(function (value, nextValue, nextIndex) {
  4383. if (!areEqualFn(value, nextValue)) {
  4384. if (filterFn(value)) {
  4385. foundFn(cursor, nextIndex);
  4386. }
  4387. cursor = nextIndex;
  4388. }
  4389. return nextValue;
  4390. });
  4391. filterFn(haystack.last()) && foundFn(cursor, haystack.count());
  4392. }
  4393. var findRangesImmutable_1 = findRangesImmutable;
  4394. function _classCallCheck$1(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4395. 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; }
  4396. 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; }
  4397. var List = immutable.List,
  4398. Map$1 = immutable.Map,
  4399. OrderedSet$1 = immutable.OrderedSet,
  4400. Record$1 = immutable.Record,
  4401. Repeat = immutable.Repeat;
  4402. var EMPTY_SET$1 = OrderedSet$1();
  4403. var defaultRecord$1 = {
  4404. key: '',
  4405. type: 'unstyled',
  4406. text: '',
  4407. characterList: List(),
  4408. depth: 0,
  4409. data: Map$1()
  4410. };
  4411. var ContentBlockRecord = Record$1(defaultRecord$1);
  4412. var decorateCharacterList = function decorateCharacterList(config) {
  4413. if (!config) {
  4414. return config;
  4415. }
  4416. var characterList = config.characterList,
  4417. text = config.text;
  4418. if (text && !characterList) {
  4419. config.characterList = List(Repeat(CharacterMetadata_1.EMPTY, text.length));
  4420. }
  4421. return config;
  4422. };
  4423. var ContentBlock = function (_ContentBlockRecord) {
  4424. _inherits$1(ContentBlock, _ContentBlockRecord);
  4425. function ContentBlock(config) {
  4426. _classCallCheck$1(this, ContentBlock);
  4427. return _possibleConstructorReturn$1(this, _ContentBlockRecord.call(this, decorateCharacterList(config)));
  4428. }
  4429. ContentBlock.prototype.getKey = function getKey() {
  4430. return this.get('key');
  4431. };
  4432. ContentBlock.prototype.getType = function getType() {
  4433. return this.get('type');
  4434. };
  4435. ContentBlock.prototype.getText = function getText() {
  4436. return this.get('text');
  4437. };
  4438. ContentBlock.prototype.getCharacterList = function getCharacterList() {
  4439. return this.get('characterList');
  4440. };
  4441. ContentBlock.prototype.getLength = function getLength() {
  4442. return this.getText().length;
  4443. };
  4444. ContentBlock.prototype.getDepth = function getDepth() {
  4445. return this.get('depth');
  4446. };
  4447. ContentBlock.prototype.getData = function getData() {
  4448. return this.get('data');
  4449. };
  4450. ContentBlock.prototype.getInlineStyleAt = function getInlineStyleAt(offset) {
  4451. var character = this.getCharacterList().get(offset);
  4452. return character ? character.getStyle() : EMPTY_SET$1;
  4453. };
  4454. ContentBlock.prototype.getEntityAt = function getEntityAt(offset) {
  4455. var character = this.getCharacterList().get(offset);
  4456. return character ? character.getEntity() : null;
  4457. };
  4458. /**
  4459. * Execute a callback for every contiguous range of styles within the block.
  4460. */
  4461. ContentBlock.prototype.findStyleRanges = function findStyleRanges(filterFn, callback) {
  4462. findRangesImmutable_1(this.getCharacterList(), haveEqualStyle, filterFn, callback);
  4463. };
  4464. /**
  4465. * Execute a callback for every contiguous range of entities within the block.
  4466. */
  4467. ContentBlock.prototype.findEntityRanges = function findEntityRanges(filterFn, callback) {
  4468. findRangesImmutable_1(this.getCharacterList(), haveEqualEntity, filterFn, callback);
  4469. };
  4470. return ContentBlock;
  4471. }(ContentBlockRecord);
  4472. function haveEqualStyle(charA, charB) {
  4473. return charA.getStyle() === charB.getStyle();
  4474. }
  4475. function haveEqualEntity(charA, charB) {
  4476. return charA.getEntity() === charB.getEntity();
  4477. }
  4478. var ContentBlock_1 = ContentBlock;
  4479. function _classCallCheck$2(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4480. 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; }
  4481. 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; }
  4482. var List$1 = immutable.List,
  4483. Map$2 = immutable.Map,
  4484. OrderedSet$2 = immutable.OrderedSet,
  4485. Record$2 = immutable.Record,
  4486. Repeat$1 = immutable.Repeat;
  4487. var EMPTY_SET$2 = OrderedSet$2();
  4488. var defaultRecord$2 = {
  4489. parent: null,
  4490. characterList: List$1(),
  4491. data: Map$2(),
  4492. depth: 0,
  4493. key: '',
  4494. text: '',
  4495. type: 'unstyled',
  4496. children: List$1(),
  4497. prevSibling: null,
  4498. nextSibling: null
  4499. };
  4500. var haveEqualStyle$1 = function haveEqualStyle(charA, charB) {
  4501. return charA.getStyle() === charB.getStyle();
  4502. };
  4503. var haveEqualEntity$1 = function haveEqualEntity(charA, charB) {
  4504. return charA.getEntity() === charB.getEntity();
  4505. };
  4506. var decorateCharacterList$1 = function decorateCharacterList(config) {
  4507. if (!config) {
  4508. return config;
  4509. }
  4510. var characterList = config.characterList,
  4511. text = config.text;
  4512. if (text && !characterList) {
  4513. config.characterList = List$1(Repeat$1(CharacterMetadata_1.EMPTY, text.length));
  4514. }
  4515. return config;
  4516. };
  4517. var ContentBlockNode = function (_Record) {
  4518. _inherits$2(ContentBlockNode, _Record);
  4519. function ContentBlockNode() {
  4520. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultRecord$2;
  4521. _classCallCheck$2(this, ContentBlockNode);
  4522. return _possibleConstructorReturn$2(this, _Record.call(this, decorateCharacterList$1(props)));
  4523. }
  4524. ContentBlockNode.prototype.getKey = function getKey() {
  4525. return this.get('key');
  4526. };
  4527. ContentBlockNode.prototype.getType = function getType() {
  4528. return this.get('type');
  4529. };
  4530. ContentBlockNode.prototype.getText = function getText() {
  4531. return this.get('text');
  4532. };
  4533. ContentBlockNode.prototype.getCharacterList = function getCharacterList() {
  4534. return this.get('characterList');
  4535. };
  4536. ContentBlockNode.prototype.getLength = function getLength() {
  4537. return this.getText().length;
  4538. };
  4539. ContentBlockNode.prototype.getDepth = function getDepth() {
  4540. return this.get('depth');
  4541. };
  4542. ContentBlockNode.prototype.getData = function getData() {
  4543. return this.get('data');
  4544. };
  4545. ContentBlockNode.prototype.getInlineStyleAt = function getInlineStyleAt(offset) {
  4546. var character = this.getCharacterList().get(offset);
  4547. return character ? character.getStyle() : EMPTY_SET$2;
  4548. };
  4549. ContentBlockNode.prototype.getEntityAt = function getEntityAt(offset) {
  4550. var character = this.getCharacterList().get(offset);
  4551. return character ? character.getEntity() : null;
  4552. };
  4553. ContentBlockNode.prototype.getChildKeys = function getChildKeys() {
  4554. return this.get('children');
  4555. };
  4556. ContentBlockNode.prototype.getParentKey = function getParentKey() {
  4557. return this.get('parent');
  4558. };
  4559. ContentBlockNode.prototype.getPrevSiblingKey = function getPrevSiblingKey() {
  4560. return this.get('prevSibling');
  4561. };
  4562. ContentBlockNode.prototype.getNextSiblingKey = function getNextSiblingKey() {
  4563. return this.get('nextSibling');
  4564. };
  4565. ContentBlockNode.prototype.findStyleRanges = function findStyleRanges(filterFn, callback) {
  4566. findRangesImmutable_1(this.getCharacterList(), haveEqualStyle$1, filterFn, callback);
  4567. };
  4568. ContentBlockNode.prototype.findEntityRanges = function findEntityRanges(filterFn, callback) {
  4569. findRangesImmutable_1(this.getCharacterList(), haveEqualEntity$1, filterFn, callback);
  4570. };
  4571. return ContentBlockNode;
  4572. }(Record$2(defaultRecord$2));
  4573. var ContentBlockNode_1 = ContentBlockNode;
  4574. /**
  4575. * Copyright 2013-present, Facebook, Inc.
  4576. * All rights reserved.
  4577. *
  4578. * This source code is licensed under the BSD-style license found in the
  4579. * LICENSE file in the root directory of this source tree. An additional grant
  4580. * of patent rights can be found in the PATENTS file in the same directory.
  4581. *
  4582. * @providesModule DraftFeatureFlags-core
  4583. * @format
  4584. *
  4585. */
  4586. var DraftFeatureFlags = {
  4587. draft_killswitch_allow_nontextnodes: false,
  4588. draft_segmented_entities_behavior: false,
  4589. draft_handlebeforeinput_composed_text: false,
  4590. draft_tree_data_support: false
  4591. };
  4592. var DraftFeatureFlagsCore = DraftFeatureFlags;
  4593. var DraftFeatureFlags_1 = DraftFeatureFlagsCore;
  4594. var Map$3 = immutable.Map;
  4595. var ContentStateInlineStyle = {
  4596. add: function add(contentState, selectionState, inlineStyle) {
  4597. return modifyInlineStyle(contentState, selectionState, inlineStyle, true);
  4598. },
  4599. remove: function remove(contentState, selectionState, inlineStyle) {
  4600. return modifyInlineStyle(contentState, selectionState, inlineStyle, false);
  4601. }
  4602. };
  4603. function modifyInlineStyle(contentState, selectionState, inlineStyle, addOrRemove) {
  4604. var blockMap = contentState.getBlockMap();
  4605. var startKey = selectionState.getStartKey();
  4606. var startOffset = selectionState.getStartOffset();
  4607. var endKey = selectionState.getEndKey();
  4608. var endOffset = selectionState.getEndOffset();
  4609. var newBlocks = blockMap.skipUntil(function (_, k) {
  4610. return k === startKey;
  4611. }).takeUntil(function (_, k) {
  4612. return k === endKey;
  4613. }).concat(Map$3([[endKey, blockMap.get(endKey)]])).map(function (block, blockKey) {
  4614. var sliceStart;
  4615. var sliceEnd;
  4616. if (startKey === endKey) {
  4617. sliceStart = startOffset;
  4618. sliceEnd = endOffset;
  4619. } else {
  4620. sliceStart = blockKey === startKey ? startOffset : 0;
  4621. sliceEnd = blockKey === endKey ? endOffset : block.getLength();
  4622. }
  4623. var chars = block.getCharacterList();
  4624. var current;
  4625. while (sliceStart < sliceEnd) {
  4626. current = chars.get(sliceStart);
  4627. chars = chars.set(sliceStart, addOrRemove ? CharacterMetadata_1.applyStyle(current, inlineStyle) : CharacterMetadata_1.removeStyle(current, inlineStyle));
  4628. sliceStart++;
  4629. }
  4630. return block.set('characterList', chars);
  4631. });
  4632. return contentState.merge({
  4633. blockMap: blockMap.merge(newBlocks),
  4634. selectionBefore: selectionState,
  4635. selectionAfter: selectionState
  4636. });
  4637. }
  4638. var ContentStateInlineStyle_1 = ContentStateInlineStyle;
  4639. function applyEntityToContentBlock(contentBlock, start, end, entityKey) {
  4640. var characterList = contentBlock.getCharacterList();
  4641. while (start < end) {
  4642. characterList = characterList.set(start, CharacterMetadata_1.applyEntity(characterList.get(start), entityKey));
  4643. start++;
  4644. }
  4645. return contentBlock.set('characterList', characterList);
  4646. }
  4647. var applyEntityToContentBlock_1 = applyEntityToContentBlock;
  4648. function applyEntityToContentState(contentState, selectionState, entityKey) {
  4649. var blockMap = contentState.getBlockMap();
  4650. var startKey = selectionState.getStartKey();
  4651. var startOffset = selectionState.getStartOffset();
  4652. var endKey = selectionState.getEndKey();
  4653. var endOffset = selectionState.getEndOffset();
  4654. var newBlocks = blockMap.skipUntil(function (_, k) {
  4655. return k === startKey;
  4656. }).takeUntil(function (_, k) {
  4657. return k === endKey;
  4658. }).toOrderedMap().merge(immutable.OrderedMap([[endKey, blockMap.get(endKey)]])).map(function (block, blockKey) {
  4659. var sliceStart = blockKey === startKey ? startOffset : 0;
  4660. var sliceEnd = blockKey === endKey ? endOffset : block.getLength();
  4661. return applyEntityToContentBlock_1(block, sliceStart, sliceEnd, entityKey);
  4662. });
  4663. return contentState.merge({
  4664. blockMap: blockMap.merge(newBlocks),
  4665. selectionBefore: selectionState,
  4666. selectionAfter: selectionState
  4667. });
  4668. }
  4669. var applyEntityToContentState_1 = applyEntityToContentState;
  4670. /**
  4671. * Copyright (c) 2013-present, Facebook, Inc.
  4672. * All rights reserved.
  4673. *
  4674. * This source code is licensed under the BSD-style license found in the
  4675. * LICENSE file in the root directory of this source tree. An additional grant
  4676. * of patent rights can be found in the PATENTS file in the same directory.
  4677. *
  4678. * @providesModule DraftEntitySegments
  4679. * @format
  4680. *
  4681. */
  4682. /**
  4683. * Identify the range to delete from a segmented entity.
  4684. *
  4685. * Rules:
  4686. *
  4687. * Example: 'John F. Kennedy'
  4688. *
  4689. * - Deletion from within any non-whitespace (i.e. ['John', 'F.', 'Kennedy'])
  4690. * will return the range of that text.
  4691. *
  4692. * 'John F. Kennedy' -> 'John F.'
  4693. * ^
  4694. *
  4695. * - Forward deletion of whitespace will remove the following section:
  4696. *
  4697. * 'John F. Kennedy' -> 'John Kennedy'
  4698. * ^
  4699. *
  4700. * - Backward deletion of whitespace will remove the previous section:
  4701. *
  4702. * 'John F. Kennedy' -> 'F. Kennedy'
  4703. * ^
  4704. */
  4705. var DraftEntitySegments = {
  4706. getRemovalRange: function getRemovalRange(selectionStart, selectionEnd, text, entityStart, direction) {
  4707. var segments = text.split(' ');
  4708. segments = segments.map(function ( /*string*/segment, /*number*/ii) {
  4709. if (direction === 'forward') {
  4710. if (ii > 0) {
  4711. return ' ' + segment;
  4712. }
  4713. } else if (ii < segments.length - 1) {
  4714. return segment + ' ';
  4715. }
  4716. return segment;
  4717. });
  4718. var segmentStart = entityStart;
  4719. var segmentEnd;
  4720. var segment;
  4721. var removalStart = null;
  4722. var removalEnd = null;
  4723. for (var jj = 0; jj < segments.length; jj++) {
  4724. segment = segments[jj];
  4725. segmentEnd = segmentStart + segment.length;
  4726. // Our selection overlaps this segment.
  4727. if (selectionStart < segmentEnd && segmentStart < selectionEnd) {
  4728. if (removalStart !== null) {
  4729. removalEnd = segmentEnd;
  4730. } else {
  4731. removalStart = segmentStart;
  4732. removalEnd = segmentEnd;
  4733. }
  4734. } else if (removalStart !== null) {
  4735. break;
  4736. }
  4737. segmentStart = segmentEnd;
  4738. }
  4739. var entityEnd = entityStart + text.length;
  4740. var atStart = removalStart === entityStart;
  4741. var atEnd = removalEnd === entityEnd;
  4742. if (!atStart && atEnd || atStart && !atEnd) {
  4743. if (direction === 'forward') {
  4744. if (removalEnd !== entityEnd) {
  4745. removalEnd++;
  4746. }
  4747. } else if (removalStart !== entityStart) {
  4748. removalStart--;
  4749. }
  4750. }
  4751. return {
  4752. start: removalStart,
  4753. end: removalEnd
  4754. };
  4755. }
  4756. };
  4757. var DraftEntitySegments_1 = DraftEntitySegments;
  4758. /**
  4759. * Copyright (c) 2013-present, Facebook, Inc.
  4760. *
  4761. * This source code is licensed under the MIT license found in the
  4762. * LICENSE file in the root directory of this source tree.
  4763. *
  4764. */
  4765. /**
  4766. * Use invariant() to assert state which your program assumes to be true.
  4767. *
  4768. * Provide sprintf-style format (only %s is supported) and arguments
  4769. * to provide information about what broke and what you were
  4770. * expecting.
  4771. *
  4772. * The invariant message will be stripped in production, but the invariant
  4773. * will remain to ensure logic does not differ in production.
  4774. */
  4775. var validateFormat = function validateFormat(format) {};
  4776. if (process.env.NODE_ENV !== 'production') {
  4777. validateFormat = function validateFormat(format) {
  4778. if (format === undefined) {
  4779. throw new Error('invariant requires an error message argument');
  4780. }
  4781. };
  4782. }
  4783. function invariant(condition, format, a, b, c, d, e, f) {
  4784. validateFormat(format);
  4785. if (!condition) {
  4786. var error;
  4787. if (format === undefined) {
  4788. error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
  4789. } else {
  4790. var args = [a, b, c, d, e, f];
  4791. var argIndex = 0;
  4792. error = new Error(format.replace(/%s/g, function () {
  4793. return args[argIndex++];
  4794. }));
  4795. error.name = 'Invariant Violation';
  4796. }
  4797. error.framesToPop = 1; // we don't care about invariant's own frame
  4798. throw error;
  4799. }
  4800. }
  4801. var invariant_1 = invariant;
  4802. /**
  4803. * Obtain the start and end positions of the range that has the
  4804. * specified entity applied to it.
  4805. *
  4806. * Entity keys are applied only to contiguous stretches of text, so this
  4807. * method searches for the first instance of the entity key and returns
  4808. * the subsequent range.
  4809. */
  4810. function getRangesForDraftEntity(block, key) {
  4811. var ranges = [];
  4812. block.findEntityRanges(function (c) {
  4813. return c.getEntity() === key;
  4814. }, function (start, end) {
  4815. ranges.push({ start: start, end: end });
  4816. });
  4817. !!!ranges.length ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Entity key not found in this range.') : invariant_1(false) : void 0;
  4818. return ranges;
  4819. }
  4820. var getRangesForDraftEntity_1 = getRangesForDraftEntity;
  4821. /**
  4822. * Given a SelectionState and a removal direction, determine the entire range
  4823. * that should be removed from a ContentState. This is based on any entities
  4824. * within the target, with their `mutability` values taken into account.
  4825. *
  4826. * For instance, if we are attempting to remove part of an "immutable" entity
  4827. * range, the entire entity must be removed. The returned `SelectionState`
  4828. * will be adjusted accordingly.
  4829. */
  4830. function getCharacterRemovalRange(entityMap, startBlock, endBlock, selectionState, direction) {
  4831. var start = selectionState.getStartOffset();
  4832. var end = selectionState.getEndOffset();
  4833. var startEntityKey = startBlock.getEntityAt(start);
  4834. var endEntityKey = endBlock.getEntityAt(end - 1);
  4835. if (!startEntityKey && !endEntityKey) {
  4836. return selectionState;
  4837. }
  4838. var newSelectionState = selectionState;
  4839. if (startEntityKey && startEntityKey === endEntityKey) {
  4840. newSelectionState = getEntityRemovalRange(entityMap, startBlock, newSelectionState, direction, startEntityKey, true, true);
  4841. } else if (startEntityKey && endEntityKey) {
  4842. var startSelectionState = getEntityRemovalRange(entityMap, startBlock, newSelectionState, direction, startEntityKey, false, true);
  4843. var endSelectionState = getEntityRemovalRange(entityMap, endBlock, newSelectionState, direction, endEntityKey, false, false);
  4844. newSelectionState = newSelectionState.merge({
  4845. anchorOffset: startSelectionState.getAnchorOffset(),
  4846. focusOffset: endSelectionState.getFocusOffset(),
  4847. isBackward: false
  4848. });
  4849. } else if (startEntityKey) {
  4850. var _startSelectionState = getEntityRemovalRange(entityMap, startBlock, newSelectionState, direction, startEntityKey, false, true);
  4851. newSelectionState = newSelectionState.merge({
  4852. anchorOffset: _startSelectionState.getStartOffset(),
  4853. isBackward: false
  4854. });
  4855. } else if (endEntityKey) {
  4856. var _endSelectionState = getEntityRemovalRange(entityMap, endBlock, newSelectionState, direction, endEntityKey, false, false);
  4857. newSelectionState = newSelectionState.merge({
  4858. focusOffset: _endSelectionState.getEndOffset(),
  4859. isBackward: false
  4860. });
  4861. }
  4862. return newSelectionState;
  4863. }
  4864. function getEntityRemovalRange(entityMap, block, selectionState, direction, entityKey, isEntireSelectionWithinEntity, isEntityAtStart) {
  4865. var start = selectionState.getStartOffset();
  4866. var end = selectionState.getEndOffset();
  4867. var entity = entityMap.__get(entityKey);
  4868. var mutability = entity.getMutability();
  4869. var sideToConsider = isEntityAtStart ? start : end;
  4870. // `MUTABLE` entities can just have the specified range of text removed
  4871. // directly. No adjustments are needed.
  4872. if (mutability === 'MUTABLE') {
  4873. return selectionState;
  4874. }
  4875. // Find the entity range that overlaps with our removal range.
  4876. var entityRanges = getRangesForDraftEntity_1(block, entityKey).filter(function (range) {
  4877. return sideToConsider <= range.end && sideToConsider >= range.start;
  4878. });
  4879. !(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;
  4880. var entityRange = entityRanges[0];
  4881. // For `IMMUTABLE` entity types, we will remove the entire entity range.
  4882. if (mutability === 'IMMUTABLE') {
  4883. return selectionState.merge({
  4884. anchorOffset: entityRange.start,
  4885. focusOffset: entityRange.end,
  4886. isBackward: false
  4887. });
  4888. }
  4889. // For `SEGMENTED` entity types, determine the appropriate segment to
  4890. // remove.
  4891. if (!isEntireSelectionWithinEntity) {
  4892. if (isEntityAtStart) {
  4893. end = entityRange.end;
  4894. } else {
  4895. start = entityRange.start;
  4896. }
  4897. }
  4898. var removalRange = DraftEntitySegments_1.getRemovalRange(start, end, block.getText().slice(entityRange.start, entityRange.end), entityRange.start, direction);
  4899. return selectionState.merge({
  4900. anchorOffset: removalRange.start,
  4901. focusOffset: removalRange.end,
  4902. isBackward: false
  4903. });
  4904. }
  4905. var getCharacterRemovalRange_1 = getCharacterRemovalRange;
  4906. /**
  4907. * Copyright (c) 2013-present, Facebook, Inc.
  4908. * All rights reserved.
  4909. *
  4910. * This source code is licensed under the BSD-style license found in the
  4911. * LICENSE file in the root directory of this source tree. An additional grant
  4912. * of patent rights can be found in the PATENTS file in the same directory.
  4913. *
  4914. * @providesModule generateRandomKey
  4915. * @format
  4916. *
  4917. */
  4918. var seenKeys = {};
  4919. var MULTIPLIER = Math.pow(2, 24);
  4920. function generateRandomKey() {
  4921. var key = void 0;
  4922. while (key === undefined || seenKeys.hasOwnProperty(key) || !isNaN(+key)) {
  4923. key = Math.floor(Math.random() * MULTIPLIER).toString(32);
  4924. }
  4925. seenKeys[key] = true;
  4926. return key;
  4927. }
  4928. var generateRandomKey_1 = generateRandomKey;
  4929. var OrderedMap$1 = immutable.OrderedMap;
  4930. var randomizeContentBlockNodeKeys = function randomizeContentBlockNodeKeys(blockMap) {
  4931. var newKeysRef = {};
  4932. // we keep track of root blocks in order to update subsequent sibling links
  4933. var lastRootBlock = void 0;
  4934. return OrderedMap$1(blockMap.withMutations(function (blockMapState) {
  4935. blockMapState.forEach(function (block, index) {
  4936. var oldKey = block.getKey();
  4937. var nextKey = block.getNextSiblingKey();
  4938. var prevKey = block.getPrevSiblingKey();
  4939. var childrenKeys = block.getChildKeys();
  4940. var parentKey = block.getParentKey();
  4941. // new key that we will use to build linking
  4942. var key = generateRandomKey_1();
  4943. // we will add it here to re-use it later
  4944. newKeysRef[oldKey] = key;
  4945. if (nextKey) {
  4946. var nextBlock = blockMapState.get(nextKey);
  4947. if (nextBlock) {
  4948. blockMapState.setIn([nextKey, 'prevSibling'], key);
  4949. } else {
  4950. // this can happen when generating random keys for fragments
  4951. blockMapState.setIn([oldKey, 'nextSibling'], null);
  4952. }
  4953. }
  4954. if (prevKey) {
  4955. var prevBlock = blockMapState.get(prevKey);
  4956. if (prevBlock) {
  4957. blockMapState.setIn([prevKey, 'nextSibling'], key);
  4958. } else {
  4959. // this can happen when generating random keys for fragments
  4960. blockMapState.setIn([oldKey, 'prevSibling'], null);
  4961. }
  4962. }
  4963. if (parentKey && blockMapState.get(parentKey)) {
  4964. var parentBlock = blockMapState.get(parentKey);
  4965. var parentChildrenList = parentBlock.getChildKeys();
  4966. blockMapState.setIn([parentKey, 'children'], parentChildrenList.set(parentChildrenList.indexOf(block.getKey()), key));
  4967. } else {
  4968. // blocks will then be treated as root block nodes
  4969. blockMapState.setIn([oldKey, 'parent'], null);
  4970. if (lastRootBlock) {
  4971. blockMapState.setIn([lastRootBlock.getKey(), 'nextSibling'], key);
  4972. blockMapState.setIn([oldKey, 'prevSibling'], newKeysRef[lastRootBlock.getKey()]);
  4973. }
  4974. lastRootBlock = blockMapState.get(oldKey);
  4975. }
  4976. childrenKeys.forEach(function (childKey) {
  4977. var childBlock = blockMapState.get(childKey);
  4978. if (childBlock) {
  4979. blockMapState.setIn([childKey, 'parent'], key);
  4980. } else {
  4981. blockMapState.setIn([oldKey, 'children'], block.getChildKeys().filter(function (child) {
  4982. return child !== childKey;
  4983. }));
  4984. }
  4985. });
  4986. });
  4987. }).toArray().map(function (block) {
  4988. return [newKeysRef[block.getKey()], block.set('key', newKeysRef[block.getKey()])];
  4989. }));
  4990. };
  4991. var randomizeContentBlockKeys = function randomizeContentBlockKeys(blockMap) {
  4992. return OrderedMap$1(blockMap.toArray().map(function (block) {
  4993. var key = generateRandomKey_1();
  4994. return [key, block.set('key', key)];
  4995. }));
  4996. };
  4997. var randomizeBlockMapKeys = function randomizeBlockMapKeys(blockMap) {
  4998. var isTreeBasedBlockMap = blockMap.first() instanceof ContentBlockNode_1;
  4999. if (!isTreeBasedBlockMap) {
  5000. return randomizeContentBlockKeys(blockMap);
  5001. }
  5002. return randomizeContentBlockNodeKeys(blockMap);
  5003. };
  5004. var randomizeBlockMapKeys_1 = randomizeBlockMapKeys;
  5005. function removeEntitiesAtEdges(contentState, selectionState) {
  5006. var blockMap = contentState.getBlockMap();
  5007. var entityMap = contentState.getEntityMap();
  5008. var updatedBlocks = {};
  5009. var startKey = selectionState.getStartKey();
  5010. var startOffset = selectionState.getStartOffset();
  5011. var startBlock = blockMap.get(startKey);
  5012. var updatedStart = removeForBlock(entityMap, startBlock, startOffset);
  5013. if (updatedStart !== startBlock) {
  5014. updatedBlocks[startKey] = updatedStart;
  5015. }
  5016. var endKey = selectionState.getEndKey();
  5017. var endOffset = selectionState.getEndOffset();
  5018. var endBlock = blockMap.get(endKey);
  5019. if (startKey === endKey) {
  5020. endBlock = updatedStart;
  5021. }
  5022. var updatedEnd = removeForBlock(entityMap, endBlock, endOffset);
  5023. if (updatedEnd !== endBlock) {
  5024. updatedBlocks[endKey] = updatedEnd;
  5025. }
  5026. if (!Object.keys(updatedBlocks).length) {
  5027. return contentState.set('selectionAfter', selectionState);
  5028. }
  5029. return contentState.merge({
  5030. blockMap: blockMap.merge(updatedBlocks),
  5031. selectionAfter: selectionState
  5032. });
  5033. }
  5034. function getRemovalRange(characters, key, offset) {
  5035. var removalRange;
  5036. findRangesImmutable_1(characters, function (a, b) {
  5037. return a.getEntity() === b.getEntity();
  5038. }, function (element) {
  5039. return element.getEntity() === key;
  5040. }, function (start, end) {
  5041. if (start <= offset && end >= offset) {
  5042. removalRange = { start: start, end: end };
  5043. }
  5044. });
  5045. !(typeof removalRange === 'object') ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Removal range must exist within character list.') : invariant_1(false) : void 0;
  5046. return removalRange;
  5047. }
  5048. function removeForBlock(entityMap, block, offset) {
  5049. var chars = block.getCharacterList();
  5050. var charBefore = offset > 0 ? chars.get(offset - 1) : undefined;
  5051. var charAfter = offset < chars.count() ? chars.get(offset) : undefined;
  5052. var entityBeforeCursor = charBefore ? charBefore.getEntity() : undefined;
  5053. var entityAfterCursor = charAfter ? charAfter.getEntity() : undefined;
  5054. if (entityAfterCursor && entityAfterCursor === entityBeforeCursor) {
  5055. var entity = entityMap.__get(entityAfterCursor);
  5056. if (entity.getMutability() !== 'MUTABLE') {
  5057. var _getRemovalRange = getRemovalRange(chars, entityAfterCursor, offset),
  5058. start = _getRemovalRange.start,
  5059. end = _getRemovalRange.end;
  5060. var current;
  5061. while (start < end) {
  5062. current = chars.get(start);
  5063. chars = chars.set(start, CharacterMetadata_1.applyEntity(current, null));
  5064. start++;
  5065. }
  5066. return block.set('characterList', chars);
  5067. }
  5068. }
  5069. return block;
  5070. }
  5071. var removeEntitiesAtEdges_1 = removeEntitiesAtEdges;
  5072. var getContentStateFragment = function getContentStateFragment(contentState, selectionState) {
  5073. var startKey = selectionState.getStartKey();
  5074. var startOffset = selectionState.getStartOffset();
  5075. var endKey = selectionState.getEndKey();
  5076. var endOffset = selectionState.getEndOffset();
  5077. // Edge entities should be stripped to ensure that we don't preserve
  5078. // invalid partial entities when the fragment is reused. We do, however,
  5079. // preserve entities that are entirely within the selection range.
  5080. var contentWithoutEdgeEntities = removeEntitiesAtEdges_1(contentState, selectionState);
  5081. var blockMap = contentWithoutEdgeEntities.getBlockMap();
  5082. var blockKeys = blockMap.keySeq();
  5083. var startIndex = blockKeys.indexOf(startKey);
  5084. var endIndex = blockKeys.indexOf(endKey) + 1;
  5085. return randomizeBlockMapKeys_1(blockMap.slice(startIndex, endIndex).map(function (block, blockKey) {
  5086. var text = block.getText();
  5087. var chars = block.getCharacterList();
  5088. if (startKey === endKey) {
  5089. return block.merge({
  5090. text: text.slice(startOffset, endOffset),
  5091. characterList: chars.slice(startOffset, endOffset)
  5092. });
  5093. }
  5094. if (blockKey === startKey) {
  5095. return block.merge({
  5096. text: text.slice(startOffset),
  5097. characterList: chars.slice(startOffset)
  5098. });
  5099. }
  5100. if (blockKey === endKey) {
  5101. return block.merge({
  5102. text: text.slice(0, endOffset),
  5103. characterList: chars.slice(0, endOffset)
  5104. });
  5105. }
  5106. return block;
  5107. }));
  5108. };
  5109. var getContentStateFragment_1 = getContentStateFragment;
  5110. /**
  5111. * Copyright (c) 2013-present, Facebook, Inc.
  5112. * All rights reserved.
  5113. *
  5114. * This source code is licensed under the BSD-style license found in the
  5115. * LICENSE file in the root directory of this source tree. An additional grant
  5116. * of patent rights can be found in the PATENTS file in the same directory.
  5117. *
  5118. * @providesModule insertIntoList
  5119. * @format
  5120. *
  5121. */
  5122. /**
  5123. * Maintain persistence for target list when appending and prepending.
  5124. */
  5125. function insertIntoList(targetList, toInsert, offset) {
  5126. if (offset === targetList.count()) {
  5127. toInsert.forEach(function (c) {
  5128. targetList = targetList.push(c);
  5129. });
  5130. } else if (offset === 0) {
  5131. toInsert.reverse().forEach(function (c) {
  5132. targetList = targetList.unshift(c);
  5133. });
  5134. } else {
  5135. var head = targetList.slice(0, offset);
  5136. var tail = targetList.slice(offset);
  5137. targetList = head.concat(toInsert, tail).toList();
  5138. }
  5139. return targetList;
  5140. }
  5141. var insertIntoList_1 = insertIntoList;
  5142. var List$2 = immutable.List;
  5143. var updateExistingBlock = function updateExistingBlock(contentState, selectionState, blockMap, fragmentBlock, targetKey, targetOffset) {
  5144. var targetBlock = blockMap.get(targetKey);
  5145. var text = targetBlock.getText();
  5146. var chars = targetBlock.getCharacterList();
  5147. var finalKey = targetKey;
  5148. var finalOffset = targetOffset + fragmentBlock.getText().length;
  5149. var newBlock = targetBlock.merge({
  5150. text: text.slice(0, targetOffset) + fragmentBlock.getText() + text.slice(targetOffset),
  5151. characterList: insertIntoList_1(chars, fragmentBlock.getCharacterList(), targetOffset),
  5152. data: fragmentBlock.getData()
  5153. });
  5154. return contentState.merge({
  5155. blockMap: blockMap.set(targetKey, newBlock),
  5156. selectionBefore: selectionState,
  5157. selectionAfter: selectionState.merge({
  5158. anchorKey: finalKey,
  5159. anchorOffset: finalOffset,
  5160. focusKey: finalKey,
  5161. focusOffset: finalOffset,
  5162. isBackward: false
  5163. })
  5164. });
  5165. };
  5166. /**
  5167. * Appends text/characterList from the fragment first block to
  5168. * target block.
  5169. */
  5170. var updateHead = function updateHead(block, targetOffset, fragment) {
  5171. var text = block.getText();
  5172. var chars = block.getCharacterList();
  5173. // Modify head portion of block.
  5174. var headText = text.slice(0, targetOffset);
  5175. var headCharacters = chars.slice(0, targetOffset);
  5176. var appendToHead = fragment.first();
  5177. return block.merge({
  5178. text: headText + appendToHead.getText(),
  5179. characterList: headCharacters.concat(appendToHead.getCharacterList()),
  5180. type: headText ? block.getType() : appendToHead.getType(),
  5181. data: appendToHead.getData()
  5182. });
  5183. };
  5184. /**
  5185. * Appends offset text/characterList from the target block to the last
  5186. * fragment block.
  5187. */
  5188. var updateTail = function updateTail(block, targetOffset, fragment) {
  5189. // Modify tail portion of block.
  5190. var text = block.getText();
  5191. var chars = block.getCharacterList();
  5192. // Modify head portion of block.
  5193. var blockSize = text.length;
  5194. var tailText = text.slice(targetOffset, blockSize);
  5195. var tailCharacters = chars.slice(targetOffset, blockSize);
  5196. var prependToTail = fragment.last();
  5197. return prependToTail.merge({
  5198. text: prependToTail.getText() + tailText,
  5199. characterList: prependToTail.getCharacterList().concat(tailCharacters),
  5200. data: prependToTail.getData()
  5201. });
  5202. };
  5203. var getRootBlocks = function getRootBlocks(block, blockMap) {
  5204. var headKey = block.getKey();
  5205. var rootBlock = block;
  5206. var rootBlocks = [];
  5207. // sometimes the fragment head block will not be part of the blockMap itself this can happen when
  5208. // the fragment head is used to update the target block, however when this does not happen we need
  5209. // to make sure that we include it on the rootBlocks since the first block of a fragment is always a
  5210. // fragment root block
  5211. if (blockMap.get(headKey)) {
  5212. rootBlocks.push(headKey);
  5213. }
  5214. while (rootBlock && rootBlock.getNextSiblingKey()) {
  5215. var lastSiblingKey = rootBlock.getNextSiblingKey();
  5216. if (!lastSiblingKey) {
  5217. break;
  5218. }
  5219. rootBlocks.push(lastSiblingKey);
  5220. rootBlock = blockMap.get(lastSiblingKey);
  5221. }
  5222. return rootBlocks;
  5223. };
  5224. var updateBlockMapLinks = function updateBlockMapLinks(blockMap, originalBlockMap, targetBlock, fragmentHeadBlock) {
  5225. return blockMap.withMutations(function (blockMapState) {
  5226. var targetKey = targetBlock.getKey();
  5227. var headKey = fragmentHeadBlock.getKey();
  5228. var targetNextKey = targetBlock.getNextSiblingKey();
  5229. var targetParentKey = targetBlock.getParentKey();
  5230. var fragmentRootBlocks = getRootBlocks(fragmentHeadBlock, blockMap);
  5231. var lastRootFragmentBlockKey = fragmentRootBlocks[fragmentRootBlocks.length - 1];
  5232. if (blockMapState.get(headKey)) {
  5233. // update the fragment head when it is part of the blockMap otherwise
  5234. blockMapState.setIn([targetKey, 'nextSibling'], headKey);
  5235. blockMapState.setIn([headKey, 'prevSibling'], targetKey);
  5236. } else {
  5237. // update the target block that had the fragment head contents merged into it
  5238. blockMapState.setIn([targetKey, 'nextSibling'], fragmentHeadBlock.getNextSiblingKey());
  5239. blockMapState.setIn([fragmentHeadBlock.getNextSiblingKey(), 'prevSibling'], targetKey);
  5240. }
  5241. // update the last root block fragment
  5242. blockMapState.setIn([lastRootFragmentBlockKey, 'nextSibling'], targetNextKey);
  5243. // update the original target next block
  5244. if (targetNextKey) {
  5245. blockMapState.setIn([targetNextKey, 'prevSibling'], lastRootFragmentBlockKey);
  5246. }
  5247. // update fragment parent links
  5248. fragmentRootBlocks.forEach(function (blockKey) {
  5249. return blockMapState.setIn([blockKey, 'parent'], targetParentKey);
  5250. });
  5251. // update targetBlock parent child links
  5252. if (targetParentKey) {
  5253. var targetParent = blockMap.get(targetParentKey);
  5254. var originalTargetParentChildKeys = targetParent.getChildKeys();
  5255. var targetBlockIndex = originalTargetParentChildKeys.indexOf(targetKey);
  5256. var insertionIndex = targetBlockIndex + 1;
  5257. var newChildrenKeysArray = originalTargetParentChildKeys.toArray();
  5258. // insert fragment children
  5259. newChildrenKeysArray.splice.apply(newChildrenKeysArray, [insertionIndex, 0].concat(fragmentRootBlocks));
  5260. blockMapState.setIn([targetParentKey, 'children'], List$2(newChildrenKeysArray));
  5261. }
  5262. });
  5263. };
  5264. var insertFragment = function insertFragment(contentState, selectionState, blockMap, fragment, targetKey, targetOffset) {
  5265. var isTreeBasedBlockMap = blockMap.first() instanceof ContentBlockNode_1;
  5266. var newBlockArr = [];
  5267. var fragmentSize = fragment.size;
  5268. var target = blockMap.get(targetKey);
  5269. var head = fragment.first();
  5270. var tail = fragment.last();
  5271. var finalOffset = tail.getLength();
  5272. var finalKey = tail.getKey();
  5273. var shouldNotUpdateFromFragmentBlock = isTreeBasedBlockMap && (!target.getChildKeys().isEmpty() || !head.getChildKeys().isEmpty());
  5274. blockMap.forEach(function (block, blockKey) {
  5275. if (blockKey !== targetKey) {
  5276. newBlockArr.push(block);
  5277. return;
  5278. }
  5279. if (shouldNotUpdateFromFragmentBlock) {
  5280. newBlockArr.push(block);
  5281. } else {
  5282. newBlockArr.push(updateHead(block, targetOffset, fragment));
  5283. }
  5284. // Insert fragment blocks after the head and before the tail.
  5285. fragment
  5286. // when we are updating the target block with the head fragment block we skip the first fragment
  5287. // head since its contents have already been merged with the target block otherwise we include
  5288. // the whole fragment
  5289. .slice(shouldNotUpdateFromFragmentBlock ? 0 : 1, fragmentSize - 1).forEach(function (fragmentBlock) {
  5290. return newBlockArr.push(fragmentBlock);
  5291. });
  5292. // update tail
  5293. newBlockArr.push(updateTail(block, targetOffset, fragment));
  5294. });
  5295. var updatedBlockMap = BlockMapBuilder_1.createFromArray(newBlockArr);
  5296. if (isTreeBasedBlockMap) {
  5297. updatedBlockMap = updateBlockMapLinks(updatedBlockMap, blockMap, target, head);
  5298. }
  5299. return contentState.merge({
  5300. blockMap: updatedBlockMap,
  5301. selectionBefore: selectionState,
  5302. selectionAfter: selectionState.merge({
  5303. anchorKey: finalKey,
  5304. anchorOffset: finalOffset,
  5305. focusKey: finalKey,
  5306. focusOffset: finalOffset,
  5307. isBackward: false
  5308. })
  5309. });
  5310. };
  5311. var insertFragmentIntoContentState = function insertFragmentIntoContentState(contentState, selectionState, fragmentBlockMap) {
  5312. !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;
  5313. var blockMap = contentState.getBlockMap();
  5314. var fragment = randomizeBlockMapKeys_1(fragmentBlockMap);
  5315. var targetKey = selectionState.getStartKey();
  5316. var targetOffset = selectionState.getStartOffset();
  5317. var targetBlock = blockMap.get(targetKey);
  5318. if (targetBlock instanceof ContentBlockNode_1) {
  5319. !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;
  5320. }
  5321. // When we insert a fragment with a single block we simply update the target block
  5322. // with the contents of the inserted fragment block
  5323. if (fragment.size === 1) {
  5324. return updateExistingBlock(contentState, selectionState, blockMap, fragment.first(), targetKey, targetOffset);
  5325. }
  5326. return insertFragment(contentState, selectionState, blockMap, fragment, targetKey, targetOffset);
  5327. };
  5328. var insertFragmentIntoContentState_1 = insertFragmentIntoContentState;
  5329. var Repeat$2 = immutable.Repeat;
  5330. function insertTextIntoContentState(contentState, selectionState, text, characterMetadata) {
  5331. !selectionState.isCollapsed() ? process.env.NODE_ENV !== 'production' ? invariant_1(false, '`insertText` should only be called with a collapsed range.') : invariant_1(false) : void 0;
  5332. var len = text.length;
  5333. if (!len) {
  5334. return contentState;
  5335. }
  5336. var blockMap = contentState.getBlockMap();
  5337. var key = selectionState.getStartKey();
  5338. var offset = selectionState.getStartOffset();
  5339. var block = blockMap.get(key);
  5340. var blockText = block.getText();
  5341. var newBlock = block.merge({
  5342. text: blockText.slice(0, offset) + text + blockText.slice(offset, block.getLength()),
  5343. characterList: insertIntoList_1(block.getCharacterList(), Repeat$2(characterMetadata, len).toList(), offset)
  5344. });
  5345. var newOffset = offset + len;
  5346. return contentState.merge({
  5347. blockMap: blockMap.set(key, newBlock),
  5348. selectionAfter: selectionState.merge({
  5349. anchorOffset: newOffset,
  5350. focusOffset: newOffset
  5351. })
  5352. });
  5353. }
  5354. var insertTextIntoContentState_1 = insertTextIntoContentState;
  5355. var Map$4 = immutable.Map;
  5356. function modifyBlockForContentState(contentState, selectionState, operation) {
  5357. var startKey = selectionState.getStartKey();
  5358. var endKey = selectionState.getEndKey();
  5359. var blockMap = contentState.getBlockMap();
  5360. var newBlocks = blockMap.toSeq().skipUntil(function (_, k) {
  5361. return k === startKey;
  5362. }).takeUntil(function (_, k) {
  5363. return k === endKey;
  5364. }).concat(Map$4([[endKey, blockMap.get(endKey)]])).map(operation);
  5365. return contentState.merge({
  5366. blockMap: blockMap.merge(newBlocks),
  5367. selectionBefore: selectionState,
  5368. selectionAfter: selectionState
  5369. });
  5370. }
  5371. var modifyBlockForContentState_1 = modifyBlockForContentState;
  5372. /**
  5373. * Copyright (c) 2013-present, Facebook, Inc.
  5374. * All rights reserved.
  5375. *
  5376. * This source code is licensed under the BSD-style license found in the
  5377. * LICENSE file in the root directory of this source tree. An additional grant
  5378. * of patent rights can be found in the PATENTS file in the same directory.
  5379. *
  5380. * @providesModule getNextDelimiterBlockKey
  5381. * @format
  5382. *
  5383. *
  5384. * This is unstable and not part of the public API and should not be used by
  5385. * production systems. This file may be update/removed without notice.
  5386. */
  5387. var getNextDelimiterBlockKey = function getNextDelimiterBlockKey(block, blockMap) {
  5388. var isExperimentalTreeBlock = block instanceof ContentBlockNode_1;
  5389. if (!isExperimentalTreeBlock) {
  5390. return null;
  5391. }
  5392. var nextSiblingKey = block.getNextSiblingKey();
  5393. if (nextSiblingKey) {
  5394. return nextSiblingKey;
  5395. }
  5396. var parent = block.getParentKey();
  5397. if (!parent) {
  5398. return null;
  5399. }
  5400. var nextNonDescendantBlock = blockMap.get(parent);
  5401. while (nextNonDescendantBlock && !nextNonDescendantBlock.getNextSiblingKey()) {
  5402. var parentKey = nextNonDescendantBlock.getParentKey();
  5403. nextNonDescendantBlock = parentKey ? blockMap.get(parentKey) : null;
  5404. }
  5405. if (!nextNonDescendantBlock) {
  5406. return null;
  5407. }
  5408. return nextNonDescendantBlock.getNextSiblingKey();
  5409. };
  5410. var getNextDelimiterBlockKey_1 = getNextDelimiterBlockKey;
  5411. var List$3 = immutable.List,
  5412. Map$5 = immutable.Map;
  5413. var transformBlock = function transformBlock(key, blockMap, func) {
  5414. if (!key) {
  5415. return;
  5416. }
  5417. var block = blockMap.get(key);
  5418. if (!block) {
  5419. return;
  5420. }
  5421. blockMap.set(key, func(block));
  5422. };
  5423. /**
  5424. * Ancestors needs to be preserved when there are non selected
  5425. * children to make sure we do not leave any orphans behind
  5426. */
  5427. var getAncestorsKeys = function getAncestorsKeys(blockKey, blockMap) {
  5428. var parents = [];
  5429. if (!blockKey) {
  5430. return parents;
  5431. }
  5432. var blockNode = blockMap.get(blockKey);
  5433. while (blockNode && blockNode.getParentKey()) {
  5434. var parentKey = blockNode.getParentKey();
  5435. if (parentKey) {
  5436. parents.push(parentKey);
  5437. }
  5438. blockNode = parentKey ? blockMap.get(parentKey) : null;
  5439. }
  5440. return parents;
  5441. };
  5442. /**
  5443. * Get all next delimiter keys until we hit a root delimiter and return
  5444. * an array of key references
  5445. */
  5446. var getNextDelimitersBlockKeys = function getNextDelimitersBlockKeys(block, blockMap) {
  5447. var nextDelimiters = [];
  5448. if (!block) {
  5449. return nextDelimiters;
  5450. }
  5451. var nextDelimiter = getNextDelimiterBlockKey_1(block, blockMap);
  5452. while (nextDelimiter && blockMap.get(nextDelimiter)) {
  5453. var _block = blockMap.get(nextDelimiter);
  5454. nextDelimiters.push(nextDelimiter);
  5455. // we do not need to keep checking all root node siblings, just the first occurance
  5456. nextDelimiter = _block.getParentKey() ? getNextDelimiterBlockKey_1(_block, blockMap) : null;
  5457. }
  5458. return nextDelimiters;
  5459. };
  5460. var getNextValidSibling = function getNextValidSibling(block, blockMap, originalBlockMap) {
  5461. if (!block) {
  5462. return null;
  5463. }
  5464. // note that we need to make sure we refer to the original block since this
  5465. // function is called within a withMutations
  5466. var nextValidSiblingKey = originalBlockMap.get(block.getKey()).getNextSiblingKey();
  5467. while (nextValidSiblingKey && !blockMap.get(nextValidSiblingKey)) {
  5468. nextValidSiblingKey = originalBlockMap.get(nextValidSiblingKey).getNextSiblingKey() || null;
  5469. }
  5470. return nextValidSiblingKey;
  5471. };
  5472. var getPrevValidSibling = function getPrevValidSibling(block, blockMap, originalBlockMap) {
  5473. if (!block) {
  5474. return null;
  5475. }
  5476. // note that we need to make sure we refer to the original block since this
  5477. // function is called within a withMutations
  5478. var prevValidSiblingKey = originalBlockMap.get(block.getKey()).getPrevSiblingKey();
  5479. while (prevValidSiblingKey && !blockMap.get(prevValidSiblingKey)) {
  5480. prevValidSiblingKey = originalBlockMap.get(prevValidSiblingKey).getPrevSiblingKey() || null;
  5481. }
  5482. return prevValidSiblingKey;
  5483. };
  5484. var updateBlockMapLinks$1 = function updateBlockMapLinks(blockMap, startBlock, endBlock, originalBlockMap) {
  5485. return blockMap.withMutations(function (blocks) {
  5486. // update start block if its retained
  5487. transformBlock(startBlock.getKey(), blocks, function (block) {
  5488. return block.merge({
  5489. nextSibling: getNextValidSibling(startBlock, blocks, originalBlockMap),
  5490. prevSibling: getPrevValidSibling(startBlock, blocks, originalBlockMap)
  5491. });
  5492. });
  5493. // update endblock if its retained
  5494. transformBlock(endBlock.getKey(), blocks, function (block) {
  5495. return block.merge({
  5496. nextSibling: getNextValidSibling(endBlock, blocks, originalBlockMap),
  5497. prevSibling: getPrevValidSibling(endBlock, blocks, originalBlockMap)
  5498. });
  5499. });
  5500. // update start block parent ancestors
  5501. getAncestorsKeys(startBlock.getKey(), originalBlockMap).forEach(function (parentKey) {
  5502. return transformBlock(parentKey, blocks, function (block) {
  5503. return block.merge({
  5504. children: block.getChildKeys().filter(function (key) {
  5505. return blocks.get(key);
  5506. }),
  5507. nextSibling: getNextValidSibling(block, blocks, originalBlockMap),
  5508. prevSibling: getPrevValidSibling(block, blocks, originalBlockMap)
  5509. });
  5510. });
  5511. });
  5512. // update start block next - can only happen if startBlock == endBlock
  5513. transformBlock(startBlock.getNextSiblingKey(), blocks, function (block) {
  5514. return block.merge({
  5515. prevSibling: startBlock.getPrevSiblingKey()
  5516. });
  5517. });
  5518. // update start block prev
  5519. transformBlock(startBlock.getPrevSiblingKey(), blocks, function (block) {
  5520. return block.merge({
  5521. nextSibling: getNextValidSibling(startBlock, blocks, originalBlockMap)
  5522. });
  5523. });
  5524. // update end block next
  5525. transformBlock(endBlock.getNextSiblingKey(), blocks, function (block) {
  5526. return block.merge({
  5527. prevSibling: getPrevValidSibling(endBlock, blocks, originalBlockMap)
  5528. });
  5529. });
  5530. // update end block prev
  5531. transformBlock(endBlock.getPrevSiblingKey(), blocks, function (block) {
  5532. return block.merge({
  5533. nextSibling: endBlock.getNextSiblingKey()
  5534. });
  5535. });
  5536. // update end block parent ancestors
  5537. getAncestorsKeys(endBlock.getKey(), originalBlockMap).forEach(function (parentKey) {
  5538. transformBlock(parentKey, blocks, function (block) {
  5539. return block.merge({
  5540. children: block.getChildKeys().filter(function (key) {
  5541. return blocks.get(key);
  5542. }),
  5543. nextSibling: getNextValidSibling(block, blocks, originalBlockMap),
  5544. prevSibling: getPrevValidSibling(block, blocks, originalBlockMap)
  5545. });
  5546. });
  5547. });
  5548. // update next delimiters all the way to a root delimiter
  5549. getNextDelimitersBlockKeys(endBlock, originalBlockMap).forEach(function (delimiterKey) {
  5550. return transformBlock(delimiterKey, blocks, function (block) {
  5551. return block.merge({
  5552. nextSibling: getNextValidSibling(block, blocks, originalBlockMap),
  5553. prevSibling: getPrevValidSibling(block, blocks, originalBlockMap)
  5554. });
  5555. });
  5556. });
  5557. });
  5558. };
  5559. var removeRangeFromContentState = function removeRangeFromContentState(contentState, selectionState) {
  5560. if (selectionState.isCollapsed()) {
  5561. return contentState;
  5562. }
  5563. var blockMap = contentState.getBlockMap();
  5564. var startKey = selectionState.getStartKey();
  5565. var startOffset = selectionState.getStartOffset();
  5566. var endKey = selectionState.getEndKey();
  5567. var endOffset = selectionState.getEndOffset();
  5568. var startBlock = blockMap.get(startKey);
  5569. var endBlock = blockMap.get(endKey);
  5570. // we assume that ContentBlockNode and ContentBlocks are not mixed together
  5571. var isExperimentalTreeBlock = startBlock instanceof ContentBlockNode_1;
  5572. // used to retain blocks that should not be deleted to avoid orphan children
  5573. var parentAncestors = [];
  5574. if (isExperimentalTreeBlock) {
  5575. var endBlockchildrenKeys = endBlock.getChildKeys();
  5576. var endBlockAncestors = getAncestorsKeys(endKey, blockMap);
  5577. // endBlock has unselected sibblings so we can not remove its ancestors parents
  5578. if (endBlock.getNextSiblingKey()) {
  5579. parentAncestors = parentAncestors.concat(endBlockAncestors);
  5580. }
  5581. // endBlock has children so can not remove this block or any of its ancestors
  5582. if (!endBlockchildrenKeys.isEmpty()) {
  5583. parentAncestors = parentAncestors.concat(endBlockAncestors.concat([endKey]));
  5584. }
  5585. // we need to retain all ancestors of the next delimiter block
  5586. parentAncestors = parentAncestors.concat(getAncestorsKeys(getNextDelimiterBlockKey_1(endBlock, blockMap), blockMap));
  5587. }
  5588. var characterList = void 0;
  5589. if (startBlock === endBlock) {
  5590. characterList = removeFromList(startBlock.getCharacterList(), startOffset, endOffset);
  5591. } else {
  5592. characterList = startBlock.getCharacterList().slice(0, startOffset).concat(endBlock.getCharacterList().slice(endOffset));
  5593. }
  5594. var modifiedStart = startBlock.merge({
  5595. text: startBlock.getText().slice(0, startOffset) + endBlock.getText().slice(endOffset),
  5596. characterList: characterList
  5597. });
  5598. var newBlocks = blockMap.toSeq().skipUntil(function (_, k) {
  5599. return k === startKey;
  5600. }).takeUntil(function (_, k) {
  5601. return k === endKey;
  5602. }).filter(function (_, k) {
  5603. return parentAncestors.indexOf(k) === -1;
  5604. }).concat(Map$5([[endKey, null]])).map(function (_, k) {
  5605. return k === startKey ? modifiedStart : null;
  5606. });
  5607. var updatedBlockMap = blockMap.merge(newBlocks).filter(function (block) {
  5608. return !!block;
  5609. });
  5610. if (isExperimentalTreeBlock) {
  5611. updatedBlockMap = updateBlockMapLinks$1(updatedBlockMap, startBlock, endBlock, blockMap);
  5612. }
  5613. return contentState.merge({
  5614. blockMap: updatedBlockMap,
  5615. selectionBefore: selectionState,
  5616. selectionAfter: selectionState.merge({
  5617. anchorKey: startKey,
  5618. anchorOffset: startOffset,
  5619. focusKey: startKey,
  5620. focusOffset: startOffset,
  5621. isBackward: false
  5622. })
  5623. });
  5624. };
  5625. /**
  5626. * Maintain persistence for target list when removing characters on the
  5627. * head and tail of the character list.
  5628. */
  5629. var removeFromList = function removeFromList(targetList, startOffset, endOffset) {
  5630. if (startOffset === 0) {
  5631. while (startOffset < endOffset) {
  5632. targetList = targetList.shift();
  5633. startOffset++;
  5634. }
  5635. } else if (endOffset === targetList.count()) {
  5636. while (endOffset > startOffset) {
  5637. targetList = targetList.pop();
  5638. endOffset--;
  5639. }
  5640. } else {
  5641. var head = targetList.slice(0, startOffset);
  5642. var tail = targetList.slice(endOffset);
  5643. targetList = head.concat(tail).toList();
  5644. }
  5645. return targetList;
  5646. };
  5647. var removeRangeFromContentState_1 = removeRangeFromContentState;
  5648. var List$4 = immutable.List,
  5649. Map$6 = immutable.Map;
  5650. var transformBlock$1 = function transformBlock(key, blockMap, func) {
  5651. if (!key) {
  5652. return;
  5653. }
  5654. var block = blockMap.get(key);
  5655. if (!block) {
  5656. return;
  5657. }
  5658. blockMap.set(key, func(block));
  5659. };
  5660. var updateBlockMapLinks$2 = function updateBlockMapLinks(blockMap, originalBlock, belowBlock) {
  5661. return blockMap.withMutations(function (blocks) {
  5662. var originalBlockKey = originalBlock.getKey();
  5663. var belowBlockKey = belowBlock.getKey();
  5664. // update block parent
  5665. transformBlock$1(originalBlock.getParentKey(), blocks, function (block) {
  5666. var parentChildrenList = block.getChildKeys();
  5667. var insertionIndex = parentChildrenList.indexOf(originalBlockKey) + 1;
  5668. var newChildrenArray = parentChildrenList.toArray();
  5669. newChildrenArray.splice(insertionIndex, 0, belowBlockKey);
  5670. return block.merge({
  5671. children: List$4(newChildrenArray)
  5672. });
  5673. });
  5674. // update original next block
  5675. transformBlock$1(originalBlock.getNextSiblingKey(), blocks, function (block) {
  5676. return block.merge({
  5677. prevSibling: belowBlockKey
  5678. });
  5679. });
  5680. // update original block
  5681. transformBlock$1(originalBlockKey, blocks, function (block) {
  5682. return block.merge({
  5683. nextSibling: belowBlockKey
  5684. });
  5685. });
  5686. // update below block
  5687. transformBlock$1(belowBlockKey, blocks, function (block) {
  5688. return block.merge({
  5689. prevSibling: originalBlockKey
  5690. });
  5691. });
  5692. });
  5693. };
  5694. var splitBlockInContentState = function splitBlockInContentState(contentState, selectionState) {
  5695. !selectionState.isCollapsed() ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Selection range must be collapsed.') : invariant_1(false) : void 0;
  5696. var key = selectionState.getAnchorKey();
  5697. var offset = selectionState.getAnchorOffset();
  5698. var blockMap = contentState.getBlockMap();
  5699. var blockToSplit = blockMap.get(key);
  5700. var text = blockToSplit.getText();
  5701. var chars = blockToSplit.getCharacterList();
  5702. var keyBelow = generateRandomKey_1();
  5703. var isExperimentalTreeBlock = blockToSplit instanceof ContentBlockNode_1;
  5704. var blockAbove = blockToSplit.merge({
  5705. text: text.slice(0, offset),
  5706. characterList: chars.slice(0, offset)
  5707. });
  5708. var blockBelow = blockAbove.merge({
  5709. key: keyBelow,
  5710. text: text.slice(offset),
  5711. characterList: chars.slice(offset),
  5712. data: Map$6()
  5713. });
  5714. var blocksBefore = blockMap.toSeq().takeUntil(function (v) {
  5715. return v === blockToSplit;
  5716. });
  5717. var blocksAfter = blockMap.toSeq().skipUntil(function (v) {
  5718. return v === blockToSplit;
  5719. }).rest();
  5720. var newBlocks = blocksBefore.concat([[key, blockAbove], [keyBelow, blockBelow]], blocksAfter).toOrderedMap();
  5721. if (isExperimentalTreeBlock) {
  5722. !blockToSplit.getChildKeys().isEmpty() ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'ContentBlockNode must not have children') : invariant_1(false) : void 0;
  5723. newBlocks = updateBlockMapLinks$2(newBlocks, blockAbove, blockBelow);
  5724. }
  5725. return contentState.merge({
  5726. blockMap: newBlocks,
  5727. selectionBefore: selectionState,
  5728. selectionAfter: selectionState.merge({
  5729. anchorKey: keyBelow,
  5730. anchorOffset: 0,
  5731. focusKey: keyBelow,
  5732. focusOffset: 0,
  5733. isBackward: false
  5734. })
  5735. });
  5736. };
  5737. var splitBlockInContentState_1 = splitBlockInContentState;
  5738. var OrderedSet$3 = immutable.OrderedSet;
  5739. /**
  5740. * `DraftModifier` provides a set of convenience methods that apply
  5741. * modifications to a `ContentState` object based on a target `SelectionState`.
  5742. *
  5743. * Any change to a `ContentState` should be decomposable into a series of
  5744. * transaction functions that apply the required changes and return output
  5745. * `ContentState` objects.
  5746. *
  5747. * These functions encapsulate some of the most common transaction sequences.
  5748. */
  5749. var DraftModifier = {
  5750. replaceText: function replaceText(contentState, rangeToReplace, text, inlineStyle, entityKey) {
  5751. var withoutEntities = removeEntitiesAtEdges_1(contentState, rangeToReplace);
  5752. var withoutText = removeRangeFromContentState_1(withoutEntities, rangeToReplace);
  5753. var character = CharacterMetadata_1.create({
  5754. style: inlineStyle || OrderedSet$3(),
  5755. entity: entityKey || null
  5756. });
  5757. return insertTextIntoContentState_1(withoutText, withoutText.getSelectionAfter(), text, character);
  5758. },
  5759. insertText: function insertText(contentState, targetRange, text, inlineStyle, entityKey) {
  5760. !targetRange.isCollapsed() ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Target range must be collapsed for `insertText`.') : invariant_1(false) : void 0;
  5761. return DraftModifier.replaceText(contentState, targetRange, text, inlineStyle, entityKey);
  5762. },
  5763. moveText: function moveText(contentState, removalRange, targetRange) {
  5764. var movedFragment = getContentStateFragment_1(contentState, removalRange);
  5765. var afterRemoval = DraftModifier.removeRange(contentState, removalRange, 'backward');
  5766. return DraftModifier.replaceWithFragment(afterRemoval, targetRange, movedFragment);
  5767. },
  5768. replaceWithFragment: function replaceWithFragment(contentState, targetRange, fragment) {
  5769. var withoutEntities = removeEntitiesAtEdges_1(contentState, targetRange);
  5770. var withoutText = removeRangeFromContentState_1(withoutEntities, targetRange);
  5771. return insertFragmentIntoContentState_1(withoutText, withoutText.getSelectionAfter(), fragment);
  5772. },
  5773. removeRange: function removeRange(contentState, rangeToRemove, removalDirection) {
  5774. var startKey = void 0,
  5775. endKey = void 0,
  5776. startBlock = void 0,
  5777. endBlock = void 0;
  5778. if (rangeToRemove.getIsBackward()) {
  5779. rangeToRemove = rangeToRemove.merge({
  5780. anchorKey: rangeToRemove.getFocusKey(),
  5781. anchorOffset: rangeToRemove.getFocusOffset(),
  5782. focusKey: rangeToRemove.getAnchorKey(),
  5783. focusOffset: rangeToRemove.getAnchorOffset(),
  5784. isBackward: false
  5785. });
  5786. }
  5787. startKey = rangeToRemove.getAnchorKey();
  5788. endKey = rangeToRemove.getFocusKey();
  5789. startBlock = contentState.getBlockForKey(startKey);
  5790. endBlock = contentState.getBlockForKey(endKey);
  5791. var startOffset = rangeToRemove.getStartOffset();
  5792. var endOffset = rangeToRemove.getEndOffset();
  5793. var startEntityKey = startBlock.getEntityAt(startOffset);
  5794. var endEntityKey = endBlock.getEntityAt(endOffset - 1);
  5795. // Check whether the selection state overlaps with a single entity.
  5796. // If so, try to remove the appropriate substring of the entity text.
  5797. if (startKey === endKey) {
  5798. if (startEntityKey && startEntityKey === endEntityKey) {
  5799. var _adjustedRemovalRange = getCharacterRemovalRange_1(contentState.getEntityMap(), startBlock, endBlock, rangeToRemove, removalDirection);
  5800. return removeRangeFromContentState_1(contentState, _adjustedRemovalRange);
  5801. }
  5802. }
  5803. var adjustedRemovalRange = rangeToRemove;
  5804. var withoutEntities = removeEntitiesAtEdges_1(contentState, adjustedRemovalRange);
  5805. return removeRangeFromContentState_1(withoutEntities, adjustedRemovalRange);
  5806. },
  5807. splitBlock: function splitBlock(contentState, selectionState) {
  5808. var withoutEntities = removeEntitiesAtEdges_1(contentState, selectionState);
  5809. var withoutText = removeRangeFromContentState_1(withoutEntities, selectionState);
  5810. return splitBlockInContentState_1(withoutText, withoutText.getSelectionAfter());
  5811. },
  5812. applyInlineStyle: function applyInlineStyle(contentState, selectionState, inlineStyle) {
  5813. return ContentStateInlineStyle_1.add(contentState, selectionState, inlineStyle);
  5814. },
  5815. removeInlineStyle: function removeInlineStyle(contentState, selectionState, inlineStyle) {
  5816. return ContentStateInlineStyle_1.remove(contentState, selectionState, inlineStyle);
  5817. },
  5818. setBlockType: function setBlockType(contentState, selectionState, blockType) {
  5819. return modifyBlockForContentState_1(contentState, selectionState, function (block) {
  5820. return block.merge({ type: blockType, depth: 0 });
  5821. });
  5822. },
  5823. setBlockData: function setBlockData(contentState, selectionState, blockData) {
  5824. return modifyBlockForContentState_1(contentState, selectionState, function (block) {
  5825. return block.merge({ data: blockData });
  5826. });
  5827. },
  5828. mergeBlockData: function mergeBlockData(contentState, selectionState, blockData) {
  5829. return modifyBlockForContentState_1(contentState, selectionState, function (block) {
  5830. return block.merge({ data: block.getData().merge(blockData) });
  5831. });
  5832. },
  5833. applyEntity: function applyEntity(contentState, selectionState, entityKey) {
  5834. var withoutEntities = removeEntitiesAtEdges_1(contentState, selectionState);
  5835. return applyEntityToContentState_1(withoutEntities, selectionState, entityKey);
  5836. }
  5837. };
  5838. var DraftModifier_1 = DraftModifier;
  5839. /**
  5840. * Copyright (c) 2013-present, Facebook, Inc.
  5841. *
  5842. * This source code is licensed under the MIT license found in the
  5843. * LICENSE file in the root directory of this source tree.
  5844. *
  5845. *
  5846. */
  5847. function makeEmptyFunction(arg) {
  5848. return function () {
  5849. return arg;
  5850. };
  5851. }
  5852. /**
  5853. * This function accepts and discards inputs; it has no side effects. This is
  5854. * primarily useful idiomatically for overridable function endpoints which
  5855. * always need to be callable, since JS lacks a null-call idiom ala Cocoa.
  5856. */
  5857. var emptyFunction = function emptyFunction() {};
  5858. emptyFunction.thatReturns = makeEmptyFunction;
  5859. emptyFunction.thatReturnsFalse = makeEmptyFunction(false);
  5860. emptyFunction.thatReturnsTrue = makeEmptyFunction(true);
  5861. emptyFunction.thatReturnsNull = makeEmptyFunction(null);
  5862. emptyFunction.thatReturnsThis = function () {
  5863. return this;
  5864. };
  5865. emptyFunction.thatReturnsArgument = function (arg) {
  5866. return arg;
  5867. };
  5868. var emptyFunction_1 = emptyFunction;
  5869. var List$5 = immutable.List,
  5870. Repeat$3 = immutable.Repeat,
  5871. Record$3 = immutable.Record;
  5872. var returnTrue = emptyFunction_1.thatReturnsTrue;
  5873. var FINGERPRINT_DELIMITER = '-';
  5874. var defaultLeafRange = {
  5875. start: null,
  5876. end: null
  5877. };
  5878. var LeafRange = Record$3(defaultLeafRange);
  5879. var defaultDecoratorRange = {
  5880. start: null,
  5881. end: null,
  5882. decoratorKey: null,
  5883. leaves: null
  5884. };
  5885. var DecoratorRange = Record$3(defaultDecoratorRange);
  5886. var BlockTree = {
  5887. /**
  5888. * Generate a block tree for a given ContentBlock/decorator pair.
  5889. */
  5890. generate: function generate(contentState, block, decorator) {
  5891. var textLength = block.getLength();
  5892. if (!textLength) {
  5893. return List$5.of(new DecoratorRange({
  5894. start: 0,
  5895. end: 0,
  5896. decoratorKey: null,
  5897. leaves: List$5.of(new LeafRange({ start: 0, end: 0 }))
  5898. }));
  5899. }
  5900. var leafSets = [];
  5901. var decorations = decorator ? decorator.getDecorations(block, contentState) : List$5(Repeat$3(null, textLength));
  5902. var chars = block.getCharacterList();
  5903. findRangesImmutable_1(decorations, areEqual, returnTrue, function (start, end) {
  5904. leafSets.push(new DecoratorRange({
  5905. start: start,
  5906. end: end,
  5907. decoratorKey: decorations.get(start),
  5908. leaves: generateLeaves(chars.slice(start, end).toList(), start)
  5909. }));
  5910. });
  5911. return List$5(leafSets);
  5912. },
  5913. /**
  5914. * Create a string representation of the given tree map. This allows us
  5915. * to rapidly determine whether a tree has undergone a significant
  5916. * structural change.
  5917. */
  5918. getFingerprint: function getFingerprint(tree) {
  5919. return tree.map(function (leafSet) {
  5920. var decoratorKey = leafSet.get('decoratorKey');
  5921. var fingerprintString = decoratorKey !== null ? decoratorKey + '.' + (leafSet.get('end') - leafSet.get('start')) : '';
  5922. return '' + fingerprintString + '.' + leafSet.get('leaves').size;
  5923. }).join(FINGERPRINT_DELIMITER);
  5924. }
  5925. };
  5926. /**
  5927. * Generate LeafRange records for a given character list.
  5928. */
  5929. function generateLeaves(characters, offset) {
  5930. var leaves = [];
  5931. var inlineStyles = characters.map(function (c) {
  5932. return c.getStyle();
  5933. }).toList();
  5934. findRangesImmutable_1(inlineStyles, areEqual, returnTrue, function (start, end) {
  5935. leaves.push(new LeafRange({
  5936. start: start + offset,
  5937. end: end + offset
  5938. }));
  5939. });
  5940. return List$5(leaves);
  5941. }
  5942. function areEqual(a, b) {
  5943. return a === b;
  5944. }
  5945. var BlockTree_1 = BlockTree;
  5946. function _classCallCheck$3(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5947. 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; }
  5948. 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; }
  5949. var Record$4 = immutable.Record;
  5950. var DraftEntityInstanceRecord = Record$4({
  5951. type: 'TOKEN',
  5952. mutability: 'IMMUTABLE',
  5953. data: Object
  5954. });
  5955. /**
  5956. * An instance of a document entity, consisting of a `type` and relevant
  5957. * `data`, metadata about the entity.
  5958. *
  5959. * For instance, a "link" entity might provide a URI, and a "mention"
  5960. * entity might provide the mentioned user's ID. These pieces of data
  5961. * may be used when rendering the entity as part of a ContentBlock DOM
  5962. * representation. For a link, the data would be used as an href for
  5963. * the rendered anchor. For a mention, the ID could be used to retrieve
  5964. * a hovercard.
  5965. */
  5966. var DraftEntityInstance = function (_DraftEntityInstanceR) {
  5967. _inherits$3(DraftEntityInstance, _DraftEntityInstanceR);
  5968. function DraftEntityInstance() {
  5969. _classCallCheck$3(this, DraftEntityInstance);
  5970. return _possibleConstructorReturn$3(this, _DraftEntityInstanceR.apply(this, arguments));
  5971. }
  5972. DraftEntityInstance.prototype.getType = function getType() {
  5973. return this.get('type');
  5974. };
  5975. DraftEntityInstance.prototype.getMutability = function getMutability() {
  5976. return this.get('mutability');
  5977. };
  5978. DraftEntityInstance.prototype.getData = function getData() {
  5979. return this.get('data');
  5980. };
  5981. return DraftEntityInstance;
  5982. }(DraftEntityInstanceRecord);
  5983. var DraftEntityInstance_1 = DraftEntityInstance;
  5984. 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; };
  5985. /**
  5986. * Copyright (c) 2013-present, Facebook, Inc.
  5987. * All rights reserved.
  5988. *
  5989. * This source code is licensed under the BSD-style license found in the
  5990. * LICENSE file in the root directory of this source tree. An additional grant
  5991. * of patent rights can be found in the PATENTS file in the same directory.
  5992. *
  5993. * @providesModule DraftEntity
  5994. * @format
  5995. *
  5996. */
  5997. var Map$7 = immutable.Map;
  5998. var instances = Map$7();
  5999. var instanceKey = 0;
  6000. /**
  6001. * Temporary utility for generating the warnings
  6002. */
  6003. function logWarning(oldMethodCall, newMethodCall) {
  6004. console.warn('WARNING: ' + oldMethodCall + ' will be deprecated soon!\nPlease use "' + newMethodCall + '" instead.');
  6005. }
  6006. /**
  6007. * A "document entity" is an object containing metadata associated with a
  6008. * piece of text in a ContentBlock.
  6009. *
  6010. * For example, a `link` entity might include a `uri` property. When a
  6011. * ContentBlock is rendered in the browser, text that refers to that link
  6012. * entity may be rendered as an anchor, with the `uri` as the href value.
  6013. *
  6014. * In a ContentBlock, every position in the text may correspond to zero
  6015. * or one entities. This correspondence is tracked using a key string,
  6016. * generated via DraftEntity.create() and used to obtain entity metadata
  6017. * via DraftEntity.get().
  6018. */
  6019. var DraftEntity = {
  6020. /**
  6021. * WARNING: This method will be deprecated soon!
  6022. * Please use 'contentState.getLastCreatedEntityKey' instead.
  6023. * ---
  6024. * Get the random key string from whatever entity was last created.
  6025. * We need this to support the new API, as part of transitioning to put Entity
  6026. * storage in contentState.
  6027. */
  6028. getLastCreatedEntityKey: function getLastCreatedEntityKey() {
  6029. logWarning('DraftEntity.getLastCreatedEntityKey', 'contentState.getLastCreatedEntityKey');
  6030. return DraftEntity.__getLastCreatedEntityKey();
  6031. },
  6032. /**
  6033. * WARNING: This method will be deprecated soon!
  6034. * Please use 'contentState.createEntity' instead.
  6035. * ---
  6036. * Create a DraftEntityInstance and store it for later retrieval.
  6037. *
  6038. * A random key string will be generated and returned. This key may
  6039. * be used to track the entity's usage in a ContentBlock, and for
  6040. * retrieving data about the entity at render time.
  6041. */
  6042. create: function create(type, mutability, data) {
  6043. logWarning('DraftEntity.create', 'contentState.createEntity');
  6044. return DraftEntity.__create(type, mutability, data);
  6045. },
  6046. /**
  6047. * WARNING: This method will be deprecated soon!
  6048. * Please use 'contentState.addEntity' instead.
  6049. * ---
  6050. * Add an existing DraftEntityInstance to the DraftEntity map. This is
  6051. * useful when restoring instances from the server.
  6052. */
  6053. add: function add(instance) {
  6054. logWarning('DraftEntity.add', 'contentState.addEntity');
  6055. return DraftEntity.__add(instance);
  6056. },
  6057. /**
  6058. * WARNING: This method will be deprecated soon!
  6059. * Please use 'contentState.getEntity' instead.
  6060. * ---
  6061. * Retrieve the entity corresponding to the supplied key string.
  6062. */
  6063. get: function get(key) {
  6064. logWarning('DraftEntity.get', 'contentState.getEntity');
  6065. return DraftEntity.__get(key);
  6066. },
  6067. /**
  6068. * WARNING: This method will be deprecated soon!
  6069. * Please use 'contentState.mergeEntityData' instead.
  6070. * ---
  6071. * Entity instances are immutable. If you need to update the data for an
  6072. * instance, this method will merge your data updates and return a new
  6073. * instance.
  6074. */
  6075. mergeData: function mergeData(key, toMerge) {
  6076. logWarning('DraftEntity.mergeData', 'contentState.mergeEntityData');
  6077. return DraftEntity.__mergeData(key, toMerge);
  6078. },
  6079. /**
  6080. * WARNING: This method will be deprecated soon!
  6081. * Please use 'contentState.replaceEntityData' instead.
  6082. * ---
  6083. * Completely replace the data for a given instance.
  6084. */
  6085. replaceData: function replaceData(key, newData) {
  6086. logWarning('DraftEntity.replaceData', 'contentState.replaceEntityData');
  6087. return DraftEntity.__replaceData(key, newData);
  6088. },
  6089. // ***********************************WARNING******************************
  6090. // --- the above public API will be deprecated in the next version of Draft!
  6091. // The methods below this line are private - don't call them directly.
  6092. /**
  6093. * Get the random key string from whatever entity was last created.
  6094. * We need this to support the new API, as part of transitioning to put Entity
  6095. * storage in contentState.
  6096. */
  6097. __getLastCreatedEntityKey: function __getLastCreatedEntityKey() {
  6098. return '' + instanceKey;
  6099. },
  6100. /**
  6101. * Create a DraftEntityInstance and store it for later retrieval.
  6102. *
  6103. * A random key string will be generated and returned. This key may
  6104. * be used to track the entity's usage in a ContentBlock, and for
  6105. * retrieving data about the entity at render time.
  6106. */
  6107. __create: function __create(type, mutability, data) {
  6108. return DraftEntity.__add(new DraftEntityInstance_1({ type: type, mutability: mutability, data: data || {} }));
  6109. },
  6110. /**
  6111. * Add an existing DraftEntityInstance to the DraftEntity map. This is
  6112. * useful when restoring instances from the server.
  6113. */
  6114. __add: function __add(instance) {
  6115. var key = '' + ++instanceKey;
  6116. instances = instances.set(key, instance);
  6117. return key;
  6118. },
  6119. /**
  6120. * Retrieve the entity corresponding to the supplied key string.
  6121. */
  6122. __get: function __get(key) {
  6123. var instance = instances.get(key);
  6124. !!!instance ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Unknown DraftEntity key: %s.', key) : invariant_1(false) : void 0;
  6125. return instance;
  6126. },
  6127. /**
  6128. * Entity instances are immutable. If you need to update the data for an
  6129. * instance, this method will merge your data updates and return a new
  6130. * instance.
  6131. */
  6132. __mergeData: function __mergeData(key, toMerge) {
  6133. var instance = DraftEntity.__get(key);
  6134. var newData = _extends({}, instance.getData(), toMerge);
  6135. var newInstance = instance.set('data', newData);
  6136. instances = instances.set(key, newInstance);
  6137. return newInstance;
  6138. },
  6139. /**
  6140. * Completely replace the data for a given instance.
  6141. */
  6142. __replaceData: function __replaceData(key, newData) {
  6143. var instance = DraftEntity.__get(key);
  6144. var newInstance = instance.set('data', newData);
  6145. instances = instances.set(key, newInstance);
  6146. return newInstance;
  6147. }
  6148. };
  6149. var DraftEntity_1 = DraftEntity;
  6150. function _classCallCheck$4(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6151. 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; }
  6152. 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; }
  6153. var Record$5 = immutable.Record;
  6154. var defaultRecord$3 = {
  6155. anchorKey: '',
  6156. anchorOffset: 0,
  6157. focusKey: '',
  6158. focusOffset: 0,
  6159. isBackward: false,
  6160. hasFocus: false
  6161. };
  6162. var SelectionStateRecord = Record$5(defaultRecord$3);
  6163. var SelectionState = function (_SelectionStateRecord) {
  6164. _inherits$4(SelectionState, _SelectionStateRecord);
  6165. function SelectionState() {
  6166. _classCallCheck$4(this, SelectionState);
  6167. return _possibleConstructorReturn$4(this, _SelectionStateRecord.apply(this, arguments));
  6168. }
  6169. SelectionState.prototype.serialize = function serialize() {
  6170. return 'Anchor: ' + this.getAnchorKey() + ':' + this.getAnchorOffset() + ', ' + 'Focus: ' + this.getFocusKey() + ':' + this.getFocusOffset() + ', ' + 'Is Backward: ' + String(this.getIsBackward()) + ', ' + 'Has Focus: ' + String(this.getHasFocus());
  6171. };
  6172. SelectionState.prototype.getAnchorKey = function getAnchorKey() {
  6173. return this.get('anchorKey');
  6174. };
  6175. SelectionState.prototype.getAnchorOffset = function getAnchorOffset() {
  6176. return this.get('anchorOffset');
  6177. };
  6178. SelectionState.prototype.getFocusKey = function getFocusKey() {
  6179. return this.get('focusKey');
  6180. };
  6181. SelectionState.prototype.getFocusOffset = function getFocusOffset() {
  6182. return this.get('focusOffset');
  6183. };
  6184. SelectionState.prototype.getIsBackward = function getIsBackward() {
  6185. return this.get('isBackward');
  6186. };
  6187. SelectionState.prototype.getHasFocus = function getHasFocus() {
  6188. return this.get('hasFocus');
  6189. };
  6190. /**
  6191. * Return whether the specified range overlaps with an edge of the
  6192. * SelectionState.
  6193. */
  6194. SelectionState.prototype.hasEdgeWithin = function hasEdgeWithin(blockKey, start, end) {
  6195. var anchorKey = this.getAnchorKey();
  6196. var focusKey = this.getFocusKey();
  6197. if (anchorKey === focusKey && anchorKey === blockKey) {
  6198. var selectionStart = this.getStartOffset();
  6199. var selectionEnd = this.getEndOffset();
  6200. return start <= selectionEnd && selectionStart <= end;
  6201. }
  6202. if (blockKey !== anchorKey && blockKey !== focusKey) {
  6203. return false;
  6204. }
  6205. var offsetToCheck = blockKey === anchorKey ? this.getAnchorOffset() : this.getFocusOffset();
  6206. return start <= offsetToCheck && end >= offsetToCheck;
  6207. };
  6208. SelectionState.prototype.isCollapsed = function isCollapsed() {
  6209. return this.getAnchorKey() === this.getFocusKey() && this.getAnchorOffset() === this.getFocusOffset();
  6210. };
  6211. SelectionState.prototype.getStartKey = function getStartKey() {
  6212. return this.getIsBackward() ? this.getFocusKey() : this.getAnchorKey();
  6213. };
  6214. SelectionState.prototype.getStartOffset = function getStartOffset() {
  6215. return this.getIsBackward() ? this.getFocusOffset() : this.getAnchorOffset();
  6216. };
  6217. SelectionState.prototype.getEndKey = function getEndKey() {
  6218. return this.getIsBackward() ? this.getAnchorKey() : this.getFocusKey();
  6219. };
  6220. SelectionState.prototype.getEndOffset = function getEndOffset() {
  6221. return this.getIsBackward() ? this.getAnchorOffset() : this.getFocusOffset();
  6222. };
  6223. SelectionState.createEmpty = function createEmpty(key) {
  6224. return new SelectionState({
  6225. anchorKey: key,
  6226. anchorOffset: 0,
  6227. focusKey: key,
  6228. focusOffset: 0,
  6229. isBackward: false,
  6230. hasFocus: false
  6231. });
  6232. };
  6233. return SelectionState;
  6234. }(SelectionStateRecord);
  6235. var SelectionState_1 = SelectionState;
  6236. /**
  6237. * Copyright (c) 2013-present, Facebook, Inc.
  6238. * All rights reserved.
  6239. *
  6240. * This source code is licensed under the BSD-style license found in the
  6241. * LICENSE file in the root directory of this source tree. An additional grant
  6242. * of patent rights can be found in the PATENTS file in the same directory.
  6243. *
  6244. * @providesModule sanitizeDraftText
  6245. * @format
  6246. *
  6247. */
  6248. var REGEX_BLOCK_DELIMITER = new RegExp('\r', 'g');
  6249. function sanitizeDraftText(input) {
  6250. return input.replace(REGEX_BLOCK_DELIMITER, '');
  6251. }
  6252. var sanitizeDraftText_1 = sanitizeDraftText;
  6253. function _classCallCheck$5(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6254. 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; }
  6255. 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; }
  6256. var List$6 = immutable.List,
  6257. Record$6 = immutable.Record,
  6258. Repeat$4 = immutable.Repeat;
  6259. var defaultRecord$4 = {
  6260. entityMap: null,
  6261. blockMap: null,
  6262. selectionBefore: null,
  6263. selectionAfter: null
  6264. };
  6265. var ContentBlockNodeRecord = ContentBlock_1;
  6266. var ContentStateRecord = Record$6(defaultRecord$4);
  6267. var ContentState = function (_ContentStateRecord) {
  6268. _inherits$5(ContentState, _ContentStateRecord);
  6269. function ContentState() {
  6270. _classCallCheck$5(this, ContentState);
  6271. return _possibleConstructorReturn$5(this, _ContentStateRecord.apply(this, arguments));
  6272. }
  6273. ContentState.prototype.getEntityMap = function getEntityMap() {
  6274. // TODO: update this when we fully remove DraftEntity
  6275. return DraftEntity_1;
  6276. };
  6277. ContentState.prototype.getBlockMap = function getBlockMap() {
  6278. return this.get('blockMap');
  6279. };
  6280. ContentState.prototype.getSelectionBefore = function getSelectionBefore() {
  6281. return this.get('selectionBefore');
  6282. };
  6283. ContentState.prototype.getSelectionAfter = function getSelectionAfter() {
  6284. return this.get('selectionAfter');
  6285. };
  6286. ContentState.prototype.getBlockForKey = function getBlockForKey(key) {
  6287. var block = this.getBlockMap().get(key);
  6288. return block;
  6289. };
  6290. ContentState.prototype.getKeyBefore = function getKeyBefore(key) {
  6291. return this.getBlockMap().reverse().keySeq().skipUntil(function (v) {
  6292. return v === key;
  6293. }).skip(1).first();
  6294. };
  6295. ContentState.prototype.getKeyAfter = function getKeyAfter(key) {
  6296. return this.getBlockMap().keySeq().skipUntil(function (v) {
  6297. return v === key;
  6298. }).skip(1).first();
  6299. };
  6300. ContentState.prototype.getBlockAfter = function getBlockAfter(key) {
  6301. return this.getBlockMap().skipUntil(function (_, k) {
  6302. return k === key;
  6303. }).skip(1).first();
  6304. };
  6305. ContentState.prototype.getBlockBefore = function getBlockBefore(key) {
  6306. return this.getBlockMap().reverse().skipUntil(function (_, k) {
  6307. return k === key;
  6308. }).skip(1).first();
  6309. };
  6310. ContentState.prototype.getBlocksAsArray = function getBlocksAsArray() {
  6311. return this.getBlockMap().toArray();
  6312. };
  6313. ContentState.prototype.getFirstBlock = function getFirstBlock() {
  6314. return this.getBlockMap().first();
  6315. };
  6316. ContentState.prototype.getLastBlock = function getLastBlock() {
  6317. return this.getBlockMap().last();
  6318. };
  6319. ContentState.prototype.getPlainText = function getPlainText(delimiter) {
  6320. return this.getBlockMap().map(function (block) {
  6321. return block ? block.getText() : '';
  6322. }).join(delimiter || '\n');
  6323. };
  6324. ContentState.prototype.getLastCreatedEntityKey = function getLastCreatedEntityKey() {
  6325. // TODO: update this when we fully remove DraftEntity
  6326. return DraftEntity_1.__getLastCreatedEntityKey();
  6327. };
  6328. ContentState.prototype.hasText = function hasText() {
  6329. var blockMap = this.getBlockMap();
  6330. return blockMap.size > 1 || blockMap.first().getLength() > 0;
  6331. };
  6332. ContentState.prototype.createEntity = function createEntity(type, mutability, data) {
  6333. // TODO: update this when we fully remove DraftEntity
  6334. DraftEntity_1.__create(type, mutability, data);
  6335. return this;
  6336. };
  6337. ContentState.prototype.mergeEntityData = function mergeEntityData(key, toMerge) {
  6338. // TODO: update this when we fully remove DraftEntity
  6339. DraftEntity_1.__mergeData(key, toMerge);
  6340. return this;
  6341. };
  6342. ContentState.prototype.replaceEntityData = function replaceEntityData(key, newData) {
  6343. // TODO: update this when we fully remove DraftEntity
  6344. DraftEntity_1.__replaceData(key, newData);
  6345. return this;
  6346. };
  6347. ContentState.prototype.addEntity = function addEntity(instance) {
  6348. // TODO: update this when we fully remove DraftEntity
  6349. DraftEntity_1.__add(instance);
  6350. return this;
  6351. };
  6352. ContentState.prototype.getEntity = function getEntity(key) {
  6353. // TODO: update this when we fully remove DraftEntity
  6354. return DraftEntity_1.__get(key);
  6355. };
  6356. ContentState.createFromBlockArray = function createFromBlockArray(
  6357. // TODO: update flow type when we completely deprecate the old entity API
  6358. blocks, entityMap) {
  6359. // TODO: remove this when we completely deprecate the old entity API
  6360. var theBlocks = Array.isArray(blocks) ? blocks : blocks.contentBlocks;
  6361. var blockMap = BlockMapBuilder_1.createFromArray(theBlocks);
  6362. var selectionState = blockMap.isEmpty() ? new SelectionState_1() : SelectionState_1.createEmpty(blockMap.first().getKey());
  6363. return new ContentState({
  6364. blockMap: blockMap,
  6365. entityMap: entityMap || DraftEntity_1,
  6366. selectionBefore: selectionState,
  6367. selectionAfter: selectionState
  6368. });
  6369. };
  6370. ContentState.createFromText = function createFromText(text) {
  6371. var delimiter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : /\r\n?|\n/g;
  6372. var strings = text.split(delimiter);
  6373. var blocks = strings.map(function (block) {
  6374. block = sanitizeDraftText_1(block);
  6375. return new ContentBlockNodeRecord({
  6376. key: generateRandomKey_1(),
  6377. text: block,
  6378. type: 'unstyled',
  6379. characterList: List$6(Repeat$4(CharacterMetadata_1.EMPTY, block.length))
  6380. });
  6381. });
  6382. return ContentState.createFromBlockArray(blocks);
  6383. };
  6384. return ContentState;
  6385. }(ContentStateRecord);
  6386. var ContentState_1 = ContentState;
  6387. var NEUTRAL = 'NEUTRAL'; // No strong direction
  6388. var LTR = 'LTR'; // Left-to-Right direction
  6389. var RTL = 'RTL'; // Right-to-Left direction
  6390. var globalDir = null;
  6391. // == Helpers ==
  6392. /**
  6393. * Check if a directionality value is a Strong one
  6394. */
  6395. function isStrong(dir) {
  6396. return dir === LTR || dir === RTL;
  6397. }
  6398. /**
  6399. * Get string value to be used for `dir` HTML attribute or `direction` CSS
  6400. * property.
  6401. */
  6402. function getHTMLDir(dir) {
  6403. !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;
  6404. return dir === LTR ? 'ltr' : 'rtl';
  6405. }
  6406. /**
  6407. * Get string value to be used for `dir` HTML attribute or `direction` CSS
  6408. * property, but returns null if `dir` has same value as `otherDir`.
  6409. * `null`.
  6410. */
  6411. function getHTMLDirIfDifferent(dir, otherDir) {
  6412. !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;
  6413. !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;
  6414. return dir === otherDir ? null : getHTMLDir(dir);
  6415. }
  6416. // == Global Direction ==
  6417. /**
  6418. * Set the global direction.
  6419. */
  6420. function setGlobalDir(dir) {
  6421. globalDir = dir;
  6422. }
  6423. /**
  6424. * Initialize the global direction
  6425. */
  6426. function initGlobalDir() {
  6427. setGlobalDir(LTR);
  6428. }
  6429. /**
  6430. * Get the global direction
  6431. */
  6432. function getGlobalDir() {
  6433. if (!globalDir) {
  6434. this.initGlobalDir();
  6435. }
  6436. !globalDir ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Global direction not set.') : invariant_1(false) : void 0;
  6437. return globalDir;
  6438. }
  6439. var UnicodeBidiDirection = {
  6440. // Values
  6441. NEUTRAL: NEUTRAL,
  6442. LTR: LTR,
  6443. RTL: RTL,
  6444. // Helpers
  6445. isStrong: isStrong,
  6446. getHTMLDir: getHTMLDir,
  6447. getHTMLDirIfDifferent: getHTMLDirIfDifferent,
  6448. // Global Direction
  6449. setGlobalDir: setGlobalDir,
  6450. initGlobalDir: initGlobalDir,
  6451. getGlobalDir: getGlobalDir
  6452. };
  6453. var UnicodeBidiDirection_1 = UnicodeBidiDirection;
  6454. /**
  6455. * RegExp ranges of characters with a *Strong* Bidi_Class value.
  6456. *
  6457. * Data is based on DerivedBidiClass.txt in UCD version 7.0.0.
  6458. *
  6459. * NOTE: For performance reasons, we only support Unicode's
  6460. * Basic Multilingual Plane (BMP) for now.
  6461. */
  6462. var RANGE_BY_BIDI_TYPE = {
  6463. 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',
  6464. 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',
  6465. 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'
  6466. };
  6467. var REGEX_STRONG = new RegExp('[' + RANGE_BY_BIDI_TYPE.L + RANGE_BY_BIDI_TYPE.R + RANGE_BY_BIDI_TYPE.AL + ']');
  6468. var REGEX_RTL = new RegExp('[' + RANGE_BY_BIDI_TYPE.R + RANGE_BY_BIDI_TYPE.AL + ']');
  6469. /**
  6470. * Returns the first strong character (has Bidi_Class value of L, R, or AL).
  6471. *
  6472. * @param str A text block; e.g. paragraph, table cell, tag
  6473. * @return A character with strong bidi direction, or null if not found
  6474. */
  6475. function firstStrongChar(str) {
  6476. var match = REGEX_STRONG.exec(str);
  6477. return match == null ? null : match[0];
  6478. }
  6479. /**
  6480. * Returns the direction of a block of text, based on the direction of its
  6481. * first strong character (has Bidi_Class value of L, R, or AL).
  6482. *
  6483. * @param str A text block; e.g. paragraph, table cell, tag
  6484. * @return The resolved direction
  6485. */
  6486. function firstStrongCharDir(str) {
  6487. var strongChar = firstStrongChar(str);
  6488. if (strongChar == null) {
  6489. return UnicodeBidiDirection_1.NEUTRAL;
  6490. }
  6491. return REGEX_RTL.exec(strongChar) ? UnicodeBidiDirection_1.RTL : UnicodeBidiDirection_1.LTR;
  6492. }
  6493. /**
  6494. * Returns the direction of a block of text, based on the direction of its
  6495. * first strong character (has Bidi_Class value of L, R, or AL), or a fallback
  6496. * direction, if no strong character is found.
  6497. *
  6498. * This function is supposed to be used in respect to Higher-Level Protocol
  6499. * rule HL1. (http://www.unicode.org/reports/tr9/#HL1)
  6500. *
  6501. * @param str A text block; e.g. paragraph, table cell, tag
  6502. * @param fallback Fallback direction, used if no strong direction detected
  6503. * for the block (default = NEUTRAL)
  6504. * @return The resolved direction
  6505. */
  6506. function resolveBlockDir(str, fallback) {
  6507. fallback = fallback || UnicodeBidiDirection_1.NEUTRAL;
  6508. if (!str.length) {
  6509. return fallback;
  6510. }
  6511. var blockDir = firstStrongCharDir(str);
  6512. return blockDir === UnicodeBidiDirection_1.NEUTRAL ? fallback : blockDir;
  6513. }
  6514. /**
  6515. * Returns the direction of a block of text, based on the direction of its
  6516. * first strong character (has Bidi_Class value of L, R, or AL), or a fallback
  6517. * direction, if no strong character is found.
  6518. *
  6519. * NOTE: This function is similar to resolveBlockDir(), but uses the global
  6520. * direction as the fallback, so it *always* returns a Strong direction,
  6521. * making it useful for integration in places that you need to make the final
  6522. * decision, like setting some CSS class.
  6523. *
  6524. * This function is supposed to be used in respect to Higher-Level Protocol
  6525. * rule HL1. (http://www.unicode.org/reports/tr9/#HL1)
  6526. *
  6527. * @param str A text block; e.g. paragraph, table cell
  6528. * @param strongFallback Fallback direction, used if no strong direction
  6529. * detected for the block (default = global direction)
  6530. * @return The resolved Strong direction
  6531. */
  6532. function getDirection(str, strongFallback) {
  6533. if (!strongFallback) {
  6534. strongFallback = UnicodeBidiDirection_1.getGlobalDir();
  6535. }
  6536. !UnicodeBidiDirection_1.isStrong(strongFallback) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Fallback direction must be a strong direction') : invariant_1(false) : void 0;
  6537. return resolveBlockDir(str, strongFallback);
  6538. }
  6539. /**
  6540. * Returns true if getDirection(arguments...) returns LTR.
  6541. *
  6542. * @param str A text block; e.g. paragraph, table cell
  6543. * @param strongFallback Fallback direction, used if no strong direction
  6544. * detected for the block (default = global direction)
  6545. * @return True if the resolved direction is LTR
  6546. */
  6547. function isDirectionLTR(str, strongFallback) {
  6548. return getDirection(str, strongFallback) === UnicodeBidiDirection_1.LTR;
  6549. }
  6550. /**
  6551. * Returns true if getDirection(arguments...) returns RTL.
  6552. *
  6553. * @param str A text block; e.g. paragraph, table cell
  6554. * @param strongFallback Fallback direction, used if no strong direction
  6555. * detected for the block (default = global direction)
  6556. * @return True if the resolved direction is RTL
  6557. */
  6558. function isDirectionRTL(str, strongFallback) {
  6559. return getDirection(str, strongFallback) === UnicodeBidiDirection_1.RTL;
  6560. }
  6561. var UnicodeBidi = {
  6562. firstStrongChar: firstStrongChar,
  6563. firstStrongCharDir: firstStrongCharDir,
  6564. resolveBlockDir: resolveBlockDir,
  6565. getDirection: getDirection,
  6566. isDirectionLTR: isDirectionLTR,
  6567. isDirectionRTL: isDirectionRTL
  6568. };
  6569. var UnicodeBidi_1 = UnicodeBidi;
  6570. function _classCallCheck$6(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6571. var UnicodeBidiService = function () {
  6572. /**
  6573. * Stateful class for paragraph direction detection
  6574. *
  6575. * @param defaultDir Default direction of the service
  6576. */
  6577. function UnicodeBidiService(defaultDir) {
  6578. _classCallCheck$6(this, UnicodeBidiService);
  6579. if (!defaultDir) {
  6580. defaultDir = UnicodeBidiDirection_1.getGlobalDir();
  6581. } else {
  6582. !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;
  6583. }
  6584. this._defaultDir = defaultDir;
  6585. this.reset();
  6586. }
  6587. /**
  6588. * Reset the internal state
  6589. *
  6590. * Instead of creating a new instance, you can just reset() your instance
  6591. * everytime you start a new loop.
  6592. */
  6593. UnicodeBidiService.prototype.reset = function reset() {
  6594. this._lastDir = this._defaultDir;
  6595. };
  6596. /**
  6597. * Returns the direction of a block of text, and remembers it as the
  6598. * fall-back direction for the next paragraph.
  6599. *
  6600. * @param str A text block, e.g. paragraph, table cell, tag
  6601. * @return The resolved direction
  6602. */
  6603. UnicodeBidiService.prototype.getDirection = function getDirection(str) {
  6604. this._lastDir = UnicodeBidi_1.getDirection(str, this._lastDir);
  6605. return this._lastDir;
  6606. };
  6607. return UnicodeBidiService;
  6608. }();
  6609. var UnicodeBidiService_1 = UnicodeBidiService;
  6610. /**
  6611. * Copyright (c) 2013-present, Facebook, Inc.
  6612. *
  6613. * This source code is licensed under the MIT license found in the
  6614. * LICENSE file in the root directory of this source tree.
  6615. *
  6616. *
  6617. */
  6618. var nullthrows = function nullthrows(x) {
  6619. if (x != null) {
  6620. return x;
  6621. }
  6622. throw new Error("Got unexpected null or undefined");
  6623. };
  6624. var nullthrows_1 = nullthrows;
  6625. var OrderedMap$2 = immutable.OrderedMap;
  6626. var bidiService;
  6627. var EditorBidiService = {
  6628. getDirectionMap: function getDirectionMap(content, prevBidiMap) {
  6629. if (!bidiService) {
  6630. bidiService = new UnicodeBidiService_1();
  6631. } else {
  6632. bidiService.reset();
  6633. }
  6634. var blockMap = content.getBlockMap();
  6635. var nextBidi = blockMap.valueSeq().map(function (block) {
  6636. return nullthrows_1(bidiService).getDirection(block.getText());
  6637. });
  6638. var bidiMap = OrderedMap$2(blockMap.keySeq().zip(nextBidi));
  6639. if (prevBidiMap != null && immutable.is(prevBidiMap, bidiMap)) {
  6640. return prevBidiMap;
  6641. }
  6642. return bidiMap;
  6643. }
  6644. };
  6645. var EditorBidiService_1 = EditorBidiService;
  6646. 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; };
  6647. function _classCallCheck$7(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6648. var OrderedSet$4 = immutable.OrderedSet,
  6649. Record$7 = immutable.Record,
  6650. Stack = immutable.Stack;
  6651. var defaultRecord$5 = {
  6652. allowUndo: true,
  6653. currentContent: null,
  6654. decorator: null,
  6655. directionMap: null,
  6656. forceSelection: false,
  6657. inCompositionMode: false,
  6658. inlineStyleOverride: null,
  6659. lastChangeType: null,
  6660. nativelyRenderedContent: null,
  6661. redoStack: Stack(),
  6662. selection: null,
  6663. treeMap: null,
  6664. undoStack: Stack()
  6665. };
  6666. var EditorStateRecord = Record$7(defaultRecord$5);
  6667. var EditorState = function () {
  6668. EditorState.createEmpty = function createEmpty(decorator) {
  6669. return EditorState.createWithContent(ContentState_1.createFromText(''), decorator);
  6670. };
  6671. EditorState.createWithContent = function createWithContent(contentState, decorator) {
  6672. var firstKey = contentState.getBlockMap().first().getKey();
  6673. return EditorState.create({
  6674. currentContent: contentState,
  6675. undoStack: Stack(),
  6676. redoStack: Stack(),
  6677. decorator: decorator || null,
  6678. selection: SelectionState_1.createEmpty(firstKey)
  6679. });
  6680. };
  6681. EditorState.create = function create(config) {
  6682. var currentContent = config.currentContent,
  6683. decorator = config.decorator;
  6684. var recordConfig = _extends$1({}, config, {
  6685. treeMap: generateNewTreeMap(currentContent, decorator),
  6686. directionMap: EditorBidiService_1.getDirectionMap(currentContent)
  6687. });
  6688. return new EditorState(new EditorStateRecord(recordConfig));
  6689. };
  6690. EditorState.set = function set(editorState, put) {
  6691. var map = editorState.getImmutable().withMutations(function (state) {
  6692. var existingDecorator = state.get('decorator');
  6693. var decorator = existingDecorator;
  6694. if (put.decorator === null) {
  6695. decorator = null;
  6696. } else if (put.decorator) {
  6697. decorator = put.decorator;
  6698. }
  6699. var newContent = put.currentContent || editorState.getCurrentContent();
  6700. if (decorator !== existingDecorator) {
  6701. var treeMap = state.get('treeMap');
  6702. var newTreeMap;
  6703. if (decorator && existingDecorator) {
  6704. newTreeMap = regenerateTreeForNewDecorator(newContent, newContent.getBlockMap(), treeMap, decorator, existingDecorator);
  6705. } else {
  6706. newTreeMap = generateNewTreeMap(newContent, decorator);
  6707. }
  6708. state.merge({
  6709. decorator: decorator,
  6710. treeMap: newTreeMap,
  6711. nativelyRenderedContent: null
  6712. });
  6713. return;
  6714. }
  6715. var existingContent = editorState.getCurrentContent();
  6716. if (newContent !== existingContent) {
  6717. state.set('treeMap', regenerateTreeForNewBlocks(editorState, newContent.getBlockMap(), newContent.getEntityMap(), decorator));
  6718. }
  6719. state.merge(put);
  6720. });
  6721. return new EditorState(map);
  6722. };
  6723. EditorState.prototype.toJS = function toJS() {
  6724. return this.getImmutable().toJS();
  6725. };
  6726. EditorState.prototype.getAllowUndo = function getAllowUndo() {
  6727. return this.getImmutable().get('allowUndo');
  6728. };
  6729. EditorState.prototype.getCurrentContent = function getCurrentContent() {
  6730. return this.getImmutable().get('currentContent');
  6731. };
  6732. EditorState.prototype.getUndoStack = function getUndoStack() {
  6733. return this.getImmutable().get('undoStack');
  6734. };
  6735. EditorState.prototype.getRedoStack = function getRedoStack() {
  6736. return this.getImmutable().get('redoStack');
  6737. };
  6738. EditorState.prototype.getSelection = function getSelection() {
  6739. return this.getImmutable().get('selection');
  6740. };
  6741. EditorState.prototype.getDecorator = function getDecorator() {
  6742. return this.getImmutable().get('decorator');
  6743. };
  6744. EditorState.prototype.isInCompositionMode = function isInCompositionMode() {
  6745. return this.getImmutable().get('inCompositionMode');
  6746. };
  6747. EditorState.prototype.mustForceSelection = function mustForceSelection() {
  6748. return this.getImmutable().get('forceSelection');
  6749. };
  6750. EditorState.prototype.getNativelyRenderedContent = function getNativelyRenderedContent() {
  6751. return this.getImmutable().get('nativelyRenderedContent');
  6752. };
  6753. EditorState.prototype.getLastChangeType = function getLastChangeType() {
  6754. return this.getImmutable().get('lastChangeType');
  6755. };
  6756. /**
  6757. * While editing, the user may apply inline style commands with a collapsed
  6758. * cursor, intending to type text that adopts the specified style. In this
  6759. * case, we track the specified style as an "override" that takes precedence
  6760. * over the inline style of the text adjacent to the cursor.
  6761. *
  6762. * If null, there is no override in place.
  6763. */
  6764. EditorState.prototype.getInlineStyleOverride = function getInlineStyleOverride() {
  6765. return this.getImmutable().get('inlineStyleOverride');
  6766. };
  6767. EditorState.setInlineStyleOverride = function setInlineStyleOverride(editorState, inlineStyleOverride) {
  6768. return EditorState.set(editorState, { inlineStyleOverride: inlineStyleOverride });
  6769. };
  6770. /**
  6771. * Get the appropriate inline style for the editor state. If an
  6772. * override is in place, use it. Otherwise, the current style is
  6773. * based on the location of the selection state.
  6774. */
  6775. EditorState.prototype.getCurrentInlineStyle = function getCurrentInlineStyle() {
  6776. var override = this.getInlineStyleOverride();
  6777. if (override != null) {
  6778. return override;
  6779. }
  6780. var content = this.getCurrentContent();
  6781. var selection = this.getSelection();
  6782. if (selection.isCollapsed()) {
  6783. return getInlineStyleForCollapsedSelection(content, selection);
  6784. }
  6785. return getInlineStyleForNonCollapsedSelection(content, selection);
  6786. };
  6787. EditorState.prototype.getBlockTree = function getBlockTree(blockKey) {
  6788. return this.getImmutable().getIn(['treeMap', blockKey]);
  6789. };
  6790. EditorState.prototype.isSelectionAtStartOfContent = function isSelectionAtStartOfContent() {
  6791. var firstKey = this.getCurrentContent().getBlockMap().first().getKey();
  6792. return this.getSelection().hasEdgeWithin(firstKey, 0, 0);
  6793. };
  6794. EditorState.prototype.isSelectionAtEndOfContent = function isSelectionAtEndOfContent() {
  6795. var content = this.getCurrentContent();
  6796. var blockMap = content.getBlockMap();
  6797. var last = blockMap.last();
  6798. var end = last.getLength();
  6799. return this.getSelection().hasEdgeWithin(last.getKey(), end, end);
  6800. };
  6801. EditorState.prototype.getDirectionMap = function getDirectionMap() {
  6802. return this.getImmutable().get('directionMap');
  6803. };
  6804. /**
  6805. * Incorporate native DOM selection changes into the EditorState. This
  6806. * method can be used when we simply want to accept whatever the DOM
  6807. * has given us to represent selection, and we do not need to re-render
  6808. * the editor.
  6809. *
  6810. * To forcibly move the DOM selection, see `EditorState.forceSelection`.
  6811. */
  6812. EditorState.acceptSelection = function acceptSelection(editorState, selection) {
  6813. return updateSelection(editorState, selection, false);
  6814. };
  6815. /**
  6816. * At times, we need to force the DOM selection to be where we
  6817. * need it to be. This can occur when the anchor or focus nodes
  6818. * are non-text nodes, for instance. In this case, we want to trigger
  6819. * a re-render of the editor, which in turn forces selection into
  6820. * the correct place in the DOM. The `forceSelection` method
  6821. * accomplishes this.
  6822. *
  6823. * This method should be used in cases where you need to explicitly
  6824. * move the DOM selection from one place to another without a change
  6825. * in ContentState.
  6826. */
  6827. EditorState.forceSelection = function forceSelection(editorState, selection) {
  6828. if (!selection.getHasFocus()) {
  6829. selection = selection.set('hasFocus', true);
  6830. }
  6831. return updateSelection(editorState, selection, true);
  6832. };
  6833. /**
  6834. * Move selection to the end of the editor without forcing focus.
  6835. */
  6836. EditorState.moveSelectionToEnd = function moveSelectionToEnd(editorState) {
  6837. var content = editorState.getCurrentContent();
  6838. var lastBlock = content.getLastBlock();
  6839. var lastKey = lastBlock.getKey();
  6840. var length = lastBlock.getLength();
  6841. return EditorState.acceptSelection(editorState, new SelectionState_1({
  6842. anchorKey: lastKey,
  6843. anchorOffset: length,
  6844. focusKey: lastKey,
  6845. focusOffset: length,
  6846. isBackward: false
  6847. }));
  6848. };
  6849. /**
  6850. * Force focus to the end of the editor. This is useful in scenarios
  6851. * where we want to programmatically focus the input and it makes sense
  6852. * to allow the user to continue working seamlessly.
  6853. */
  6854. EditorState.moveFocusToEnd = function moveFocusToEnd(editorState) {
  6855. var afterSelectionMove = EditorState.moveSelectionToEnd(editorState);
  6856. return EditorState.forceSelection(afterSelectionMove, afterSelectionMove.getSelection());
  6857. };
  6858. /**
  6859. * Push the current ContentState onto the undo stack if it should be
  6860. * considered a boundary state, and set the provided ContentState as the
  6861. * new current content.
  6862. */
  6863. EditorState.push = function push(editorState, contentState, changeType) {
  6864. if (editorState.getCurrentContent() === contentState) {
  6865. return editorState;
  6866. }
  6867. var forceSelection = changeType !== 'insert-characters';
  6868. var directionMap = EditorBidiService_1.getDirectionMap(contentState, editorState.getDirectionMap());
  6869. if (!editorState.getAllowUndo()) {
  6870. return EditorState.set(editorState, {
  6871. currentContent: contentState,
  6872. directionMap: directionMap,
  6873. lastChangeType: changeType,
  6874. selection: contentState.getSelectionAfter(),
  6875. forceSelection: forceSelection,
  6876. inlineStyleOverride: null
  6877. });
  6878. }
  6879. var selection = editorState.getSelection();
  6880. var currentContent = editorState.getCurrentContent();
  6881. var undoStack = editorState.getUndoStack();
  6882. var newContent = contentState;
  6883. if (selection !== currentContent.getSelectionAfter() || mustBecomeBoundary(editorState, changeType)) {
  6884. undoStack = undoStack.push(currentContent);
  6885. newContent = newContent.set('selectionBefore', selection);
  6886. } else if (changeType === 'insert-characters' || changeType === 'backspace-character' || changeType === 'delete-character') {
  6887. // Preserve the previous selection.
  6888. newContent = newContent.set('selectionBefore', currentContent.getSelectionBefore());
  6889. }
  6890. var inlineStyleOverride = editorState.getInlineStyleOverride();
  6891. // Don't discard inline style overrides for the following change types:
  6892. var overrideChangeTypes = ['adjust-depth', 'change-block-type', 'split-block'];
  6893. if (overrideChangeTypes.indexOf(changeType) === -1) {
  6894. inlineStyleOverride = null;
  6895. }
  6896. var editorStateChanges = {
  6897. currentContent: newContent,
  6898. directionMap: directionMap,
  6899. undoStack: undoStack,
  6900. redoStack: Stack(),
  6901. lastChangeType: changeType,
  6902. selection: contentState.getSelectionAfter(),
  6903. forceSelection: forceSelection,
  6904. inlineStyleOverride: inlineStyleOverride
  6905. };
  6906. return EditorState.set(editorState, editorStateChanges);
  6907. };
  6908. /**
  6909. * Make the top ContentState in the undo stack the new current content and
  6910. * push the current content onto the redo stack.
  6911. */
  6912. EditorState.undo = function undo(editorState) {
  6913. if (!editorState.getAllowUndo()) {
  6914. return editorState;
  6915. }
  6916. var undoStack = editorState.getUndoStack();
  6917. var newCurrentContent = undoStack.peek();
  6918. if (!newCurrentContent) {
  6919. return editorState;
  6920. }
  6921. var currentContent = editorState.getCurrentContent();
  6922. var directionMap = EditorBidiService_1.getDirectionMap(newCurrentContent, editorState.getDirectionMap());
  6923. return EditorState.set(editorState, {
  6924. currentContent: newCurrentContent,
  6925. directionMap: directionMap,
  6926. undoStack: undoStack.shift(),
  6927. redoStack: editorState.getRedoStack().push(currentContent),
  6928. forceSelection: true,
  6929. inlineStyleOverride: null,
  6930. lastChangeType: 'undo',
  6931. nativelyRenderedContent: null,
  6932. selection: currentContent.getSelectionBefore()
  6933. });
  6934. };
  6935. /**
  6936. * Make the top ContentState in the redo stack the new current content and
  6937. * push the current content onto the undo stack.
  6938. */
  6939. EditorState.redo = function redo(editorState) {
  6940. if (!editorState.getAllowUndo()) {
  6941. return editorState;
  6942. }
  6943. var redoStack = editorState.getRedoStack();
  6944. var newCurrentContent = redoStack.peek();
  6945. if (!newCurrentContent) {
  6946. return editorState;
  6947. }
  6948. var currentContent = editorState.getCurrentContent();
  6949. var directionMap = EditorBidiService_1.getDirectionMap(newCurrentContent, editorState.getDirectionMap());
  6950. return EditorState.set(editorState, {
  6951. currentContent: newCurrentContent,
  6952. directionMap: directionMap,
  6953. undoStack: editorState.getUndoStack().push(currentContent),
  6954. redoStack: redoStack.shift(),
  6955. forceSelection: true,
  6956. inlineStyleOverride: null,
  6957. lastChangeType: 'redo',
  6958. nativelyRenderedContent: null,
  6959. selection: newCurrentContent.getSelectionAfter()
  6960. });
  6961. };
  6962. /**
  6963. * Not for public consumption.
  6964. */
  6965. function EditorState(immutable) {
  6966. _classCallCheck$7(this, EditorState);
  6967. this._immutable = immutable;
  6968. }
  6969. /**
  6970. * Not for public consumption.
  6971. */
  6972. EditorState.prototype.getImmutable = function getImmutable() {
  6973. return this._immutable;
  6974. };
  6975. return EditorState;
  6976. }();
  6977. /**
  6978. * Set the supplied SelectionState as the new current selection, and set
  6979. * the `force` flag to trigger manual selection placement by the view.
  6980. */
  6981. function updateSelection(editorState, selection, forceSelection) {
  6982. return EditorState.set(editorState, {
  6983. selection: selection,
  6984. forceSelection: forceSelection,
  6985. nativelyRenderedContent: null,
  6986. inlineStyleOverride: null
  6987. });
  6988. }
  6989. /**
  6990. * Regenerate the entire tree map for a given ContentState and decorator.
  6991. * Returns an OrderedMap that maps all available ContentBlock objects.
  6992. */
  6993. function generateNewTreeMap(contentState, decorator) {
  6994. return contentState.getBlockMap().map(function (block) {
  6995. return BlockTree_1.generate(contentState, block, decorator);
  6996. }).toOrderedMap();
  6997. }
  6998. /**
  6999. * Regenerate tree map objects for all ContentBlocks that have changed
  7000. * between the current editorState and newContent. Returns an OrderedMap
  7001. * with only changed regenerated tree map objects.
  7002. */
  7003. function regenerateTreeForNewBlocks(editorState, newBlockMap, newEntityMap, decorator) {
  7004. var contentState = editorState.getCurrentContent().set('entityMap', newEntityMap);
  7005. var prevBlockMap = contentState.getBlockMap();
  7006. var prevTreeMap = editorState.getImmutable().get('treeMap');
  7007. return prevTreeMap.merge(newBlockMap.toSeq().filter(function (block, key) {
  7008. return block !== prevBlockMap.get(key);
  7009. }).map(function (block) {
  7010. return BlockTree_1.generate(contentState, block, decorator);
  7011. }));
  7012. }
  7013. /**
  7014. * Generate tree map objects for a new decorator object, preserving any
  7015. * decorations that are unchanged from the previous decorator.
  7016. *
  7017. * Note that in order for this to perform optimally, decoration Lists for
  7018. * decorators should be preserved when possible to allow for direct immutable
  7019. * List comparison.
  7020. */
  7021. function regenerateTreeForNewDecorator(content, blockMap, previousTreeMap, decorator, existingDecorator) {
  7022. return previousTreeMap.merge(blockMap.toSeq().filter(function (block) {
  7023. return decorator.getDecorations(block, content) !== existingDecorator.getDecorations(block, content);
  7024. }).map(function (block) {
  7025. return BlockTree_1.generate(content, block, decorator);
  7026. }));
  7027. }
  7028. /**
  7029. * Return whether a change should be considered a boundary state, given
  7030. * the previous change type. Allows us to discard potential boundary states
  7031. * during standard typing or deletion behavior.
  7032. */
  7033. function mustBecomeBoundary(editorState, changeType) {
  7034. var lastChangeType = editorState.getLastChangeType();
  7035. return changeType !== lastChangeType || changeType !== 'insert-characters' && changeType !== 'backspace-character' && changeType !== 'delete-character';
  7036. }
  7037. function getInlineStyleForCollapsedSelection(content, selection) {
  7038. var startKey = selection.getStartKey();
  7039. var startOffset = selection.getStartOffset();
  7040. var startBlock = content.getBlockForKey(startKey);
  7041. // If the cursor is not at the start of the block, look backward to
  7042. // preserve the style of the preceding character.
  7043. if (startOffset > 0) {
  7044. return startBlock.getInlineStyleAt(startOffset - 1);
  7045. }
  7046. // The caret is at position zero in this block. If the block has any
  7047. // text at all, use the style of the first character.
  7048. if (startBlock.getLength()) {
  7049. return startBlock.getInlineStyleAt(0);
  7050. }
  7051. // Otherwise, look upward in the document to find the closest character.
  7052. return lookUpwardForInlineStyle(content, startKey);
  7053. }
  7054. function getInlineStyleForNonCollapsedSelection(content, selection) {
  7055. var startKey = selection.getStartKey();
  7056. var startOffset = selection.getStartOffset();
  7057. var startBlock = content.getBlockForKey(startKey);
  7058. // If there is a character just inside the selection, use its style.
  7059. if (startOffset < startBlock.getLength()) {
  7060. return startBlock.getInlineStyleAt(startOffset);
  7061. }
  7062. // Check if the selection at the end of a non-empty block. Use the last
  7063. // style in the block.
  7064. if (startOffset > 0) {
  7065. return startBlock.getInlineStyleAt(startOffset - 1);
  7066. }
  7067. // Otherwise, look upward in the document to find the closest character.
  7068. return lookUpwardForInlineStyle(content, startKey);
  7069. }
  7070. function lookUpwardForInlineStyle(content, fromKey) {
  7071. var lastNonEmpty = content.getBlockMap().reverse().skipUntil(function (_, k) {
  7072. return k === fromKey;
  7073. }).skip(1).skipUntil(function (block, _) {
  7074. return block.getLength();
  7075. }).first();
  7076. if (lastNonEmpty) return lastNonEmpty.getInlineStyleAt(lastNonEmpty.getLength() - 1);
  7077. return OrderedSet$4();
  7078. }
  7079. var EditorState_1 = EditorState;
  7080. var OrderedMap$3 = immutable.OrderedMap,
  7081. List$7 = immutable.List;
  7082. var transformBlock$2 = function transformBlock(key, blockMap, func) {
  7083. if (!key) {
  7084. return;
  7085. }
  7086. var block = blockMap.get(key);
  7087. if (!block) {
  7088. return;
  7089. }
  7090. blockMap.set(key, func(block));
  7091. };
  7092. var updateBlockMapLinks$3 = function updateBlockMapLinks(blockMap, originalBlockToBeMoved, originalTargetBlock, insertionMode, isExperimentalTreeBlock) {
  7093. if (!isExperimentalTreeBlock) {
  7094. return blockMap;
  7095. }
  7096. // possible values of 'insertionMode' are: 'after', 'before'
  7097. var isInsertedAfterTarget = insertionMode === 'after';
  7098. var originalBlockKey = originalBlockToBeMoved.getKey();
  7099. var originalTargetKey = originalTargetBlock.getKey();
  7100. var originalParentKey = originalBlockToBeMoved.getParentKey();
  7101. var originalNextSiblingKey = originalBlockToBeMoved.getNextSiblingKey();
  7102. var originalPrevSiblingKey = originalBlockToBeMoved.getPrevSiblingKey();
  7103. var newParentKey = originalTargetBlock.getParentKey();
  7104. var newNextSiblingKey = isInsertedAfterTarget ? originalTargetBlock.getNextSiblingKey() : originalTargetKey;
  7105. var newPrevSiblingKey = isInsertedAfterTarget ? originalTargetKey : originalTargetBlock.getPrevSiblingKey();
  7106. return blockMap.withMutations(function (blocks) {
  7107. // update old parent
  7108. transformBlock$2(originalParentKey, blocks, function (block) {
  7109. var parentChildrenList = block.getChildKeys();
  7110. return block.merge({
  7111. children: parentChildrenList['delete'](parentChildrenList.indexOf(originalBlockKey))
  7112. });
  7113. });
  7114. // update old prev
  7115. transformBlock$2(originalPrevSiblingKey, blocks, function (block) {
  7116. return block.merge({
  7117. nextSibling: originalNextSiblingKey
  7118. });
  7119. });
  7120. // update old next
  7121. transformBlock$2(originalNextSiblingKey, blocks, function (block) {
  7122. return block.merge({
  7123. prevSibling: originalPrevSiblingKey
  7124. });
  7125. });
  7126. // update new next
  7127. transformBlock$2(newNextSiblingKey, blocks, function (block) {
  7128. return block.merge({
  7129. prevSibling: originalBlockKey
  7130. });
  7131. });
  7132. // update new prev
  7133. transformBlock$2(newPrevSiblingKey, blocks, function (block) {
  7134. return block.merge({
  7135. nextSibling: originalBlockKey
  7136. });
  7137. });
  7138. // update new parent
  7139. transformBlock$2(newParentKey, blocks, function (block) {
  7140. var newParentChildrenList = block.getChildKeys();
  7141. var targetBlockIndex = newParentChildrenList.indexOf(originalTargetKey);
  7142. var insertionIndex = isInsertedAfterTarget ? targetBlockIndex + 1 : targetBlockIndex !== 0 ? targetBlockIndex - 1 : 0;
  7143. var newChildrenArray = newParentChildrenList.toArray();
  7144. newChildrenArray.splice(insertionIndex, 0, originalBlockKey);
  7145. return block.merge({
  7146. children: List$7(newChildrenArray)
  7147. });
  7148. });
  7149. // update block
  7150. transformBlock$2(originalBlockKey, blocks, function (block) {
  7151. return block.merge({
  7152. nextSibling: newNextSiblingKey,
  7153. prevSibling: newPrevSiblingKey,
  7154. parent: newParentKey
  7155. });
  7156. });
  7157. });
  7158. };
  7159. var moveBlockInContentState = function moveBlockInContentState(contentState, blockToBeMoved, targetBlock, insertionMode) {
  7160. !(insertionMode !== 'replace') ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Replacing blocks is not supported.') : invariant_1(false) : void 0;
  7161. var targetKey = targetBlock.getKey();
  7162. var blockKey = blockToBeMoved.getKey();
  7163. !(blockKey !== targetKey) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Block cannot be moved next to itself.') : invariant_1(false) : void 0;
  7164. var blockMap = contentState.getBlockMap();
  7165. var isExperimentalTreeBlock = blockToBeMoved instanceof ContentBlockNode_1;
  7166. var blocksToBeMoved = [blockToBeMoved];
  7167. var blockMapWithoutBlocksToBeMoved = blockMap['delete'](blockKey);
  7168. if (isExperimentalTreeBlock) {
  7169. blocksToBeMoved = [];
  7170. blockMapWithoutBlocksToBeMoved = blockMap.withMutations(function (blocks) {
  7171. var nextSiblingKey = blockToBeMoved.getNextSiblingKey();
  7172. var nextDelimiterBlockKey = getNextDelimiterBlockKey_1(blockToBeMoved, blocks);
  7173. blocks.toSeq().skipUntil(function (block) {
  7174. return block.getKey() === blockKey;
  7175. }).takeWhile(function (block) {
  7176. var key = block.getKey();
  7177. var isBlockToBeMoved = key === blockKey;
  7178. var hasNextSiblingAndIsNotNextSibling = nextSiblingKey && key !== nextSiblingKey;
  7179. var doesNotHaveNextSiblingAndIsNotDelimiter = !nextSiblingKey && block.getParentKey() && (!nextDelimiterBlockKey || key !== nextDelimiterBlockKey);
  7180. return !!(isBlockToBeMoved || hasNextSiblingAndIsNotNextSibling || doesNotHaveNextSiblingAndIsNotDelimiter);
  7181. }).forEach(function (block) {
  7182. blocksToBeMoved.push(block);
  7183. blocks['delete'](block.getKey());
  7184. });
  7185. });
  7186. }
  7187. var blocksBefore = blockMapWithoutBlocksToBeMoved.toSeq().takeUntil(function (v) {
  7188. return v === targetBlock;
  7189. });
  7190. var blocksAfter = blockMapWithoutBlocksToBeMoved.toSeq().skipUntil(function (v) {
  7191. return v === targetBlock;
  7192. }).skip(1);
  7193. var slicedBlocks = blocksToBeMoved.map(function (block) {
  7194. return [block.getKey(), block];
  7195. });
  7196. var newBlocks = OrderedMap$3();
  7197. if (insertionMode === 'before') {
  7198. var blockBefore = contentState.getBlockBefore(targetKey);
  7199. !(!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;
  7200. newBlocks = blocksBefore.concat([].concat(slicedBlocks, [[targetKey, targetBlock]]), blocksAfter).toOrderedMap();
  7201. } else if (insertionMode === 'after') {
  7202. var blockAfter = contentState.getBlockAfter(targetKey);
  7203. !(!blockAfter || blockAfter.getKey() !== blockKey) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Block cannot be moved next to itself.') : invariant_1(false) : void 0;
  7204. newBlocks = blocksBefore.concat([[targetKey, targetBlock]].concat(slicedBlocks), blocksAfter).toOrderedMap();
  7205. }
  7206. return contentState.merge({
  7207. blockMap: updateBlockMapLinks$3(newBlocks, blockToBeMoved, targetBlock, insertionMode, isExperimentalTreeBlock),
  7208. selectionBefore: contentState.getSelectionAfter(),
  7209. selectionAfter: contentState.getSelectionAfter().merge({
  7210. anchorKey: blockKey,
  7211. focusKey: blockKey
  7212. })
  7213. });
  7214. };
  7215. var moveBlockInContentState_1 = moveBlockInContentState;
  7216. var ContentBlockRecord$1 = ContentBlock_1;
  7217. var List$8 = immutable.List,
  7218. Repeat$5 = immutable.Repeat;
  7219. var AtomicBlockUtils = {
  7220. insertAtomicBlock: function insertAtomicBlock(editorState, entityKey, character) {
  7221. var contentState = editorState.getCurrentContent();
  7222. var selectionState = editorState.getSelection();
  7223. var afterRemoval = DraftModifier_1.removeRange(contentState, selectionState, 'backward');
  7224. var targetSelection = afterRemoval.getSelectionAfter();
  7225. var afterSplit = DraftModifier_1.splitBlock(afterRemoval, targetSelection);
  7226. var insertionTarget = afterSplit.getSelectionAfter();
  7227. var asAtomicBlock = DraftModifier_1.setBlockType(afterSplit, insertionTarget, 'atomic');
  7228. var charData = CharacterMetadata_1.create({ entity: entityKey });
  7229. var atomicBlockConfig = {
  7230. key: generateRandomKey_1(),
  7231. type: 'atomic',
  7232. text: character,
  7233. characterList: List$8(Repeat$5(charData, character.length))
  7234. };
  7235. var atomicDividerBlockConfig = {
  7236. key: generateRandomKey_1(),
  7237. type: 'unstyled'
  7238. };
  7239. var fragmentArray = [new ContentBlockRecord$1(atomicBlockConfig), new ContentBlockRecord$1(atomicDividerBlockConfig)];
  7240. var fragment = BlockMapBuilder_1.createFromArray(fragmentArray);
  7241. var withAtomicBlock = DraftModifier_1.replaceWithFragment(asAtomicBlock, insertionTarget, fragment);
  7242. var newContent = withAtomicBlock.merge({
  7243. selectionBefore: selectionState,
  7244. selectionAfter: withAtomicBlock.getSelectionAfter().set('hasFocus', true)
  7245. });
  7246. return EditorState_1.push(editorState, newContent, 'insert-fragment');
  7247. },
  7248. moveAtomicBlock: function moveAtomicBlock(editorState, atomicBlock, targetRange, insertionMode) {
  7249. var contentState = editorState.getCurrentContent();
  7250. var selectionState = editorState.getSelection();
  7251. var withMovedAtomicBlock = void 0;
  7252. if (insertionMode === 'before' || insertionMode === 'after') {
  7253. var targetBlock = contentState.getBlockForKey(insertionMode === 'before' ? targetRange.getStartKey() : targetRange.getEndKey());
  7254. withMovedAtomicBlock = moveBlockInContentState_1(contentState, atomicBlock, targetBlock, insertionMode);
  7255. } else {
  7256. var afterRemoval = DraftModifier_1.removeRange(contentState, targetRange, 'backward');
  7257. var selectionAfterRemoval = afterRemoval.getSelectionAfter();
  7258. var _targetBlock = afterRemoval.getBlockForKey(selectionAfterRemoval.getFocusKey());
  7259. if (selectionAfterRemoval.getStartOffset() === 0) {
  7260. withMovedAtomicBlock = moveBlockInContentState_1(afterRemoval, atomicBlock, _targetBlock, 'before');
  7261. } else if (selectionAfterRemoval.getEndOffset() === _targetBlock.getLength()) {
  7262. withMovedAtomicBlock = moveBlockInContentState_1(afterRemoval, atomicBlock, _targetBlock, 'after');
  7263. } else {
  7264. var afterSplit = DraftModifier_1.splitBlock(afterRemoval, selectionAfterRemoval);
  7265. var selectionAfterSplit = afterSplit.getSelectionAfter();
  7266. var _targetBlock2 = afterSplit.getBlockForKey(selectionAfterSplit.getFocusKey());
  7267. withMovedAtomicBlock = moveBlockInContentState_1(afterSplit, atomicBlock, _targetBlock2, 'before');
  7268. }
  7269. }
  7270. var newContent = withMovedAtomicBlock.merge({
  7271. selectionBefore: selectionState,
  7272. selectionAfter: withMovedAtomicBlock.getSelectionAfter().set('hasFocus', true)
  7273. });
  7274. return EditorState_1.push(editorState, newContent, 'move-block');
  7275. }
  7276. };
  7277. var AtomicBlockUtils_1 = AtomicBlockUtils;
  7278. function _classCallCheck$8(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7279. var List$9 = immutable.List;
  7280. var DELIMITER = '.';
  7281. /**
  7282. * A CompositeDraftDecorator traverses through a list of DraftDecorator
  7283. * instances to identify sections of a ContentBlock that should be rendered
  7284. * in a "decorated" manner. For example, hashtags, mentions, and links may
  7285. * be intended to stand out visually, be rendered as anchors, etc.
  7286. *
  7287. * The list of decorators supplied to the constructor will be used in the
  7288. * order they are provided. This allows the caller to specify a priority for
  7289. * string matching, in case of match collisions among decorators.
  7290. *
  7291. * For instance, I may have a link with a `#` in its text. Though this section
  7292. * of text may match our hashtag decorator, it should not be treated as a
  7293. * hashtag. I should therefore list my link DraftDecorator
  7294. * before my hashtag DraftDecorator when constructing this composite
  7295. * decorator instance.
  7296. *
  7297. * Thus, when a collision like this is encountered, the earlier match is
  7298. * preserved and the new match is discarded.
  7299. */
  7300. var CompositeDraftDecorator = function () {
  7301. function CompositeDraftDecorator(decorators) {
  7302. _classCallCheck$8(this, CompositeDraftDecorator);
  7303. // Copy the decorator array, since we use this array order to determine
  7304. // precedence of decoration matching. If the array is mutated externally,
  7305. // we don't want to be affected here.
  7306. this._decorators = decorators.slice();
  7307. }
  7308. CompositeDraftDecorator.prototype.getDecorations = function getDecorations(block, contentState) {
  7309. var decorations = Array(block.getText().length).fill(null);
  7310. this._decorators.forEach(function ( /*object*/decorator, /*number*/ii) {
  7311. var counter = 0;
  7312. var strategy = decorator.strategy;
  7313. var callback = function callback( /*number*/start, /*number*/end) {
  7314. // Find out if any of our matching range is already occupied
  7315. // by another decorator. If so, discard the match. Otherwise, store
  7316. // the component key for rendering.
  7317. if (canOccupySlice(decorations, start, end)) {
  7318. occupySlice(decorations, start, end, ii + DELIMITER + counter);
  7319. counter++;
  7320. }
  7321. };
  7322. strategy(block, callback, contentState);
  7323. });
  7324. return List$9(decorations);
  7325. };
  7326. CompositeDraftDecorator.prototype.getComponentForKey = function getComponentForKey(key) {
  7327. var componentKey = parseInt(key.split(DELIMITER)[0], 10);
  7328. return this._decorators[componentKey].component;
  7329. };
  7330. CompositeDraftDecorator.prototype.getPropsForKey = function getPropsForKey(key) {
  7331. var componentKey = parseInt(key.split(DELIMITER)[0], 10);
  7332. return this._decorators[componentKey].props;
  7333. };
  7334. return CompositeDraftDecorator;
  7335. }();
  7336. /**
  7337. * Determine whether we can occupy the specified slice of the decorations
  7338. * array.
  7339. */
  7340. function canOccupySlice(decorations, start, end) {
  7341. for (var ii = start; ii < end; ii++) {
  7342. if (decorations[ii] != null) {
  7343. return false;
  7344. }
  7345. }
  7346. return true;
  7347. }
  7348. /**
  7349. * Splice the specified component into our decoration array at the desired
  7350. * range.
  7351. */
  7352. function occupySlice(targetArr, start, end, componentKey) {
  7353. for (var ii = start; ii < end; ii++) {
  7354. targetArr[ii] = componentKey;
  7355. }
  7356. }
  7357. var CompositeDraftDecorator_1 = CompositeDraftDecorator;
  7358. /**
  7359. * Copyright (c) 2013-present, Facebook, Inc.
  7360. *
  7361. * This source code is licensed under the MIT license found in the
  7362. * LICENSE file in the root directory of this source tree.
  7363. *
  7364. */
  7365. /**
  7366. * This function is used to mark string literals representing CSS class names
  7367. * so that they can be transformed statically. This allows for modularization
  7368. * and minification of CSS class names.
  7369. *
  7370. * In static_upstream, this function is actually implemented, but it should
  7371. * eventually be replaced with something more descriptive, and the transform
  7372. * that is used in the main stack should be ported for use elsewhere.
  7373. *
  7374. * @param string|object className to modularize, or an object of key/values.
  7375. * In the object case, the values are conditions that
  7376. * determine if the className keys should be included.
  7377. * @param [string ...] Variable list of classNames in the string case.
  7378. * @return string Renderable space-separated CSS className.
  7379. */
  7380. function cx(classNames) {
  7381. if (typeof classNames == 'object') {
  7382. return Object.keys(classNames).filter(function (className) {
  7383. return classNames[className];
  7384. }).map(replace).join(' ');
  7385. }
  7386. return Array.prototype.map.call(arguments, replace).join(' ');
  7387. }
  7388. function replace(str) {
  7389. return str.replace(/\//g, '-');
  7390. }
  7391. var cx_1 = cx;
  7392. var Map$8 = immutable.Map;
  7393. var UL_WRAP = React.createElement('ul', { className: cx_1('public/DraftStyleDefault/ul') });
  7394. var OL_WRAP = React.createElement('ol', { className: cx_1('public/DraftStyleDefault/ol') });
  7395. var PRE_WRAP = React.createElement('pre', { className: cx_1('public/DraftStyleDefault/pre') });
  7396. var DefaultDraftBlockRenderMap = Map$8({
  7397. 'header-one': {
  7398. element: 'h1'
  7399. },
  7400. 'header-two': {
  7401. element: 'h2'
  7402. },
  7403. 'header-three': {
  7404. element: 'h3'
  7405. },
  7406. 'header-four': {
  7407. element: 'h4'
  7408. },
  7409. 'header-five': {
  7410. element: 'h5'
  7411. },
  7412. 'header-six': {
  7413. element: 'h6'
  7414. },
  7415. 'unordered-list-item': {
  7416. element: 'li',
  7417. wrapper: UL_WRAP
  7418. },
  7419. 'ordered-list-item': {
  7420. element: 'li',
  7421. wrapper: OL_WRAP
  7422. },
  7423. blockquote: {
  7424. element: 'blockquote'
  7425. },
  7426. atomic: {
  7427. element: 'figure'
  7428. },
  7429. 'code-block': {
  7430. element: 'pre',
  7431. wrapper: PRE_WRAP
  7432. },
  7433. unstyled: {
  7434. element: 'div',
  7435. aliasedElements: ['p']
  7436. }
  7437. });
  7438. var DefaultDraftBlockRenderMap_1 = DefaultDraftBlockRenderMap;
  7439. /**
  7440. * Copyright (c) 2013-present, Facebook, Inc.
  7441. * All rights reserved.
  7442. *
  7443. * This source code is licensed under the BSD-style license found in the
  7444. * LICENSE file in the root directory of this source tree. An additional grant
  7445. * of patent rights can be found in the PATENTS file in the same directory.
  7446. *
  7447. * @providesModule DefaultDraftInlineStyle
  7448. * @format
  7449. *
  7450. */
  7451. var DefaultDraftInlineStyle = {
  7452. BOLD: {
  7453. fontWeight: 'bold'
  7454. },
  7455. CODE: {
  7456. fontFamily: 'monospace',
  7457. wordWrap: 'break-word'
  7458. },
  7459. ITALIC: {
  7460. fontStyle: 'italic'
  7461. },
  7462. STRIKETHROUGH: {
  7463. textDecoration: 'line-through'
  7464. },
  7465. UNDERLINE: {
  7466. textDecoration: 'underline'
  7467. }
  7468. };
  7469. /**
  7470. * Copyright (c) 2013-present, Facebook, Inc.
  7471. *
  7472. * This source code is licensed under the MIT license found in the
  7473. * LICENSE file in the root directory of this source tree.
  7474. *
  7475. */
  7476. var Keys = {
  7477. BACKSPACE: 8,
  7478. TAB: 9,
  7479. RETURN: 13,
  7480. ALT: 18,
  7481. ESC: 27,
  7482. SPACE: 32,
  7483. PAGE_UP: 33,
  7484. PAGE_DOWN: 34,
  7485. END: 35,
  7486. HOME: 36,
  7487. LEFT: 37,
  7488. UP: 38,
  7489. RIGHT: 39,
  7490. DOWN: 40,
  7491. DELETE: 46,
  7492. COMMA: 188,
  7493. PERIOD: 190,
  7494. A: 65,
  7495. Z: 90,
  7496. ZERO: 48,
  7497. NUMPAD_0: 96,
  7498. NUMPAD_9: 105
  7499. };
  7500. /**
  7501. * Copyright (c) 2013-present, Facebook, Inc.
  7502. * All rights reserved.
  7503. *
  7504. * This source code is licensed under the BSD-style license found in the
  7505. * LICENSE file in the root directory of this source tree. An additional grant
  7506. * of patent rights can be found in the PATENTS file in the same directory.
  7507. *
  7508. * @providesModule getEntityKeyForSelection
  7509. * @format
  7510. *
  7511. */
  7512. /**
  7513. * Return the entity key that should be used when inserting text for the
  7514. * specified target selection, only if the entity is `MUTABLE`. `IMMUTABLE`
  7515. * and `SEGMENTED` entities should not be used for insertion behavior.
  7516. */
  7517. function getEntityKeyForSelection(contentState, targetSelection) {
  7518. var entityKey;
  7519. if (targetSelection.isCollapsed()) {
  7520. var key = targetSelection.getAnchorKey();
  7521. var offset = targetSelection.getAnchorOffset();
  7522. if (offset > 0) {
  7523. entityKey = contentState.getBlockForKey(key).getEntityAt(offset - 1);
  7524. if (entityKey !== contentState.getBlockForKey(key).getEntityAt(offset)) {
  7525. return null;
  7526. }
  7527. return filterKey(contentState.getEntityMap(), entityKey);
  7528. }
  7529. return null;
  7530. }
  7531. var startKey = targetSelection.getStartKey();
  7532. var startOffset = targetSelection.getStartOffset();
  7533. var startBlock = contentState.getBlockForKey(startKey);
  7534. entityKey = startOffset === startBlock.getLength() ? null : startBlock.getEntityAt(startOffset);
  7535. return filterKey(contentState.getEntityMap(), entityKey);
  7536. }
  7537. /**
  7538. * Determine whether an entity key corresponds to a `MUTABLE` entity. If so,
  7539. * return it. If not, return null.
  7540. */
  7541. function filterKey(entityMap, entityKey) {
  7542. if (entityKey) {
  7543. var entity = entityMap.__get(entityKey);
  7544. return entity.getMutability() === 'MUTABLE' ? entityKey : null;
  7545. }
  7546. return null;
  7547. }
  7548. var getEntityKeyForSelection_1 = getEntityKeyForSelection;
  7549. /**
  7550. * Copyright (c) 2013-present, Facebook, Inc.
  7551. * All rights reserved.
  7552. *
  7553. * This source code is licensed under the BSD-style license found in the
  7554. * LICENSE file in the root directory of this source tree. An additional grant
  7555. * of patent rights can be found in the PATENTS file in the same directory.
  7556. *
  7557. * @providesModule isEventHandled
  7558. * @format
  7559. *
  7560. */
  7561. /**
  7562. * Utility method for determining whether or not the value returned
  7563. * from a handler indicates that it was handled.
  7564. */
  7565. function isEventHandled(value) {
  7566. return value === 'handled' || value === true;
  7567. }
  7568. var isEventHandled_1 = isEventHandled;
  7569. /**
  7570. * Copyright (c) 2013-present, Facebook, Inc.
  7571. * All rights reserved.
  7572. *
  7573. * This source code is licensed under the BSD-style license found in the
  7574. * LICENSE file in the root directory of this source tree. An additional grant
  7575. * of patent rights can be found in the PATENTS file in the same directory.
  7576. *
  7577. * @providesModule isSelectionAtLeafStart
  7578. * @format
  7579. *
  7580. */
  7581. function isSelectionAtLeafStart(editorState) {
  7582. var selection = editorState.getSelection();
  7583. var anchorKey = selection.getAnchorKey();
  7584. var blockTree = editorState.getBlockTree(anchorKey);
  7585. var offset = selection.getStartOffset();
  7586. var isAtStart = false;
  7587. blockTree.some(function (leafSet) {
  7588. if (offset === leafSet.get('start')) {
  7589. isAtStart = true;
  7590. return true;
  7591. }
  7592. if (offset < leafSet.get('end')) {
  7593. return leafSet.get('leaves').some(function (leaf) {
  7594. var leafStart = leaf.get('start');
  7595. if (offset === leafStart) {
  7596. isAtStart = true;
  7597. return true;
  7598. }
  7599. return false;
  7600. });
  7601. }
  7602. return false;
  7603. });
  7604. return isAtStart;
  7605. }
  7606. var isSelectionAtLeafStart_1 = isSelectionAtLeafStart;
  7607. /**
  7608. * Millisecond delay to allow `compositionstart` to fire again upon
  7609. * `compositionend`.
  7610. *
  7611. * This is used for Korean input to ensure that typing can continue without
  7612. * the editor trying to render too quickly. More specifically, Safari 7.1+
  7613. * triggers `compositionstart` a little slower than Chrome/FF, which
  7614. * leads to composed characters being resolved and re-render occurring
  7615. * sooner than we want.
  7616. */
  7617. var RESOLVE_DELAY = 20;
  7618. /**
  7619. * A handful of variables used to track the current composition and its
  7620. * resolution status. These exist at the module level because it is not
  7621. * possible to have compositions occurring in multiple editors simultaneously,
  7622. * and it simplifies state management with respect to the DraftEditor component.
  7623. */
  7624. var resolved = false;
  7625. var stillComposing = false;
  7626. var textInputData = '';
  7627. var DraftEditorCompositionHandler = {
  7628. onBeforeInput: function onBeforeInput(editor, e) {
  7629. textInputData = (textInputData || '') + e.data;
  7630. },
  7631. /**
  7632. * A `compositionstart` event has fired while we're still in composition
  7633. * mode. Continue the current composition session to prevent a re-render.
  7634. */
  7635. onCompositionStart: function onCompositionStart(editor) {
  7636. stillComposing = true;
  7637. },
  7638. /**
  7639. * Attempt to end the current composition session.
  7640. *
  7641. * Defer handling because browser will still insert the chars into active
  7642. * element after `compositionend`. If a `compositionstart` event fires
  7643. * before `resolveComposition` executes, our composition session will
  7644. * continue.
  7645. *
  7646. * The `resolved` flag is useful because certain IME interfaces fire the
  7647. * `compositionend` event multiple times, thus queueing up multiple attempts
  7648. * at handling the composition. Since handling the same composition event
  7649. * twice could break the DOM, we only use the first event. Example: Arabic
  7650. * Google Input Tools on Windows 8.1 fires `compositionend` three times.
  7651. */
  7652. onCompositionEnd: function onCompositionEnd(editor) {
  7653. resolved = false;
  7654. stillComposing = false;
  7655. setTimeout(function () {
  7656. if (!resolved) {
  7657. DraftEditorCompositionHandler.resolveComposition(editor);
  7658. }
  7659. }, RESOLVE_DELAY);
  7660. },
  7661. /**
  7662. * In Safari, keydown events may fire when committing compositions. If
  7663. * the arrow keys are used to commit, prevent default so that the cursor
  7664. * doesn't move, otherwise it will jump back noticeably on re-render.
  7665. */
  7666. onKeyDown: function onKeyDown(editor, e) {
  7667. if (!stillComposing) {
  7668. // If a keydown event is received after compositionend but before the
  7669. // 20ms timer expires (ex: type option-E then backspace, or type A then
  7670. // backspace in 2-Set Korean), we should immediately resolve the
  7671. // composition and reinterpret the key press in edit mode.
  7672. DraftEditorCompositionHandler.resolveComposition(editor);
  7673. editor._onKeyDown(e);
  7674. return;
  7675. }
  7676. if (e.which === Keys.RIGHT || e.which === Keys.LEFT) {
  7677. e.preventDefault();
  7678. }
  7679. },
  7680. /**
  7681. * Keypress events may fire when committing compositions. In Firefox,
  7682. * pressing RETURN commits the composition and inserts extra newline
  7683. * characters that we do not want. `preventDefault` allows the composition
  7684. * to be committed while preventing the extra characters.
  7685. */
  7686. onKeyPress: function onKeyPress(editor, e) {
  7687. if (e.which === Keys.RETURN) {
  7688. e.preventDefault();
  7689. }
  7690. },
  7691. /**
  7692. * Attempt to insert composed characters into the document.
  7693. *
  7694. * If we are still in a composition session, do nothing. Otherwise, insert
  7695. * the characters into the document and terminate the composition session.
  7696. *
  7697. * If no characters were composed -- for instance, the user
  7698. * deleted all composed characters and committed nothing new --
  7699. * force a re-render. We also re-render when the composition occurs
  7700. * at the beginning of a leaf, to ensure that if the browser has
  7701. * created a new text node for the composition, we will discard it.
  7702. *
  7703. * Resetting innerHTML will move focus to the beginning of the editor,
  7704. * so we update to force it back to the correct place.
  7705. */
  7706. resolveComposition: function resolveComposition(editor) {
  7707. if (stillComposing) {
  7708. return;
  7709. }
  7710. resolved = true;
  7711. var composedChars = textInputData;
  7712. textInputData = '';
  7713. var editorState = EditorState_1.set(editor._latestEditorState, {
  7714. inCompositionMode: false
  7715. });
  7716. var currentStyle = editorState.getCurrentInlineStyle();
  7717. var entityKey = getEntityKeyForSelection_1(editorState.getCurrentContent(), editorState.getSelection());
  7718. var mustReset = !composedChars || isSelectionAtLeafStart_1(editorState) || currentStyle.size > 0 || entityKey !== null;
  7719. if (mustReset) {
  7720. editor.restoreEditorDOM();
  7721. }
  7722. editor.exitCurrentMode();
  7723. if (composedChars) {
  7724. // If characters have been composed, re-rendering with the update
  7725. // is sufficient to reset the editor.
  7726. var contentState = DraftModifier_1.replaceText(editorState.getCurrentContent(), editorState.getSelection(), composedChars, currentStyle, entityKey);
  7727. editor.update(EditorState_1.push(editorState, contentState, 'insert-characters'));
  7728. return;
  7729. }
  7730. if (mustReset) {
  7731. editor.update(EditorState_1.set(editorState, {
  7732. nativelyRenderedContent: null,
  7733. forceSelection: true
  7734. }));
  7735. }
  7736. }
  7737. };
  7738. var DraftEditorCompositionHandler_1 = DraftEditorCompositionHandler;
  7739. var uaParser = createCommonjsModule(function (module, exports) {
  7740. /*!
  7741. * UAParser.js v0.7.21
  7742. * Lightweight JavaScript-based User-Agent string parser
  7743. * https://github.com/faisalman/ua-parser-js
  7744. *
  7745. * Copyright © 2012-2019 Faisal Salman <f@faisalman.com>
  7746. * Licensed under MIT License
  7747. */
  7748. (function (window, undefined$1) {
  7749. //////////////
  7750. // Constants
  7751. /////////////
  7752. var LIBVERSION = '0.7.21',
  7753. EMPTY = '',
  7754. UNKNOWN = '?',
  7755. FUNC_TYPE = 'function',
  7756. OBJ_TYPE = 'object',
  7757. STR_TYPE = 'string',
  7758. MAJOR = 'major', // deprecated
  7759. MODEL = 'model',
  7760. NAME = 'name',
  7761. TYPE = 'type',
  7762. VENDOR = 'vendor',
  7763. VERSION = 'version',
  7764. ARCHITECTURE= 'architecture',
  7765. CONSOLE = 'console',
  7766. MOBILE = 'mobile',
  7767. TABLET = 'tablet',
  7768. SMARTTV = 'smarttv',
  7769. WEARABLE = 'wearable',
  7770. EMBEDDED = 'embedded';
  7771. ///////////
  7772. // Helper
  7773. //////////
  7774. var util = {
  7775. extend : function (regexes, extensions) {
  7776. var mergedRegexes = {};
  7777. for (var i in regexes) {
  7778. if (extensions[i] && extensions[i].length % 2 === 0) {
  7779. mergedRegexes[i] = extensions[i].concat(regexes[i]);
  7780. } else {
  7781. mergedRegexes[i] = regexes[i];
  7782. }
  7783. }
  7784. return mergedRegexes;
  7785. },
  7786. has : function (str1, str2) {
  7787. if (typeof str1 === "string") {
  7788. return str2.toLowerCase().indexOf(str1.toLowerCase()) !== -1;
  7789. } else {
  7790. return false;
  7791. }
  7792. },
  7793. lowerize : function (str) {
  7794. return str.toLowerCase();
  7795. },
  7796. major : function (version) {
  7797. return typeof(version) === STR_TYPE ? version.replace(/[^\d\.]/g,'').split(".")[0] : undefined$1;
  7798. },
  7799. trim : function (str) {
  7800. return str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
  7801. }
  7802. };
  7803. ///////////////
  7804. // Map helper
  7805. //////////////
  7806. var mapper = {
  7807. rgx : function (ua, arrays) {
  7808. var i = 0, j, k, p, q, matches, match;
  7809. // loop through all regexes maps
  7810. while (i < arrays.length && !matches) {
  7811. var regex = arrays[i], // even sequence (0,2,4,..)
  7812. props = arrays[i + 1]; // odd sequence (1,3,5,..)
  7813. j = k = 0;
  7814. // try matching uastring with regexes
  7815. while (j < regex.length && !matches) {
  7816. matches = regex[j++].exec(ua);
  7817. if (!!matches) {
  7818. for (p = 0; p < props.length; p++) {
  7819. match = matches[++k];
  7820. q = props[p];
  7821. // check if given property is actually array
  7822. if (typeof q === OBJ_TYPE && q.length > 0) {
  7823. if (q.length == 2) {
  7824. if (typeof q[1] == FUNC_TYPE) {
  7825. // assign modified match
  7826. this[q[0]] = q[1].call(this, match);
  7827. } else {
  7828. // assign given value, ignore regex match
  7829. this[q[0]] = q[1];
  7830. }
  7831. } else if (q.length == 3) {
  7832. // check whether function or regex
  7833. if (typeof q[1] === FUNC_TYPE && !(q[1].exec && q[1].test)) {
  7834. // call function (usually string mapper)
  7835. this[q[0]] = match ? q[1].call(this, match, q[2]) : undefined$1;
  7836. } else {
  7837. // sanitize match using given regex
  7838. this[q[0]] = match ? match.replace(q[1], q[2]) : undefined$1;
  7839. }
  7840. } else if (q.length == 4) {
  7841. this[q[0]] = match ? q[3].call(this, match.replace(q[1], q[2])) : undefined$1;
  7842. }
  7843. } else {
  7844. this[q] = match ? match : undefined$1;
  7845. }
  7846. }
  7847. }
  7848. }
  7849. i += 2;
  7850. }
  7851. },
  7852. str : function (str, map) {
  7853. for (var i in map) {
  7854. // check if array
  7855. if (typeof map[i] === OBJ_TYPE && map[i].length > 0) {
  7856. for (var j = 0; j < map[i].length; j++) {
  7857. if (util.has(map[i][j], str)) {
  7858. return (i === UNKNOWN) ? undefined$1 : i;
  7859. }
  7860. }
  7861. } else if (util.has(map[i], str)) {
  7862. return (i === UNKNOWN) ? undefined$1 : i;
  7863. }
  7864. }
  7865. return str;
  7866. }
  7867. };
  7868. ///////////////
  7869. // String map
  7870. //////////////
  7871. var maps = {
  7872. browser : {
  7873. oldsafari : {
  7874. version : {
  7875. '1.0' : '/8',
  7876. '1.2' : '/1',
  7877. '1.3' : '/3',
  7878. '2.0' : '/412',
  7879. '2.0.2' : '/416',
  7880. '2.0.3' : '/417',
  7881. '2.0.4' : '/419',
  7882. '?' : '/'
  7883. }
  7884. }
  7885. },
  7886. device : {
  7887. amazon : {
  7888. model : {
  7889. 'Fire Phone' : ['SD', 'KF']
  7890. }
  7891. },
  7892. sprint : {
  7893. model : {
  7894. 'Evo Shift 4G' : '7373KT'
  7895. },
  7896. vendor : {
  7897. 'HTC' : 'APA',
  7898. 'Sprint' : 'Sprint'
  7899. }
  7900. }
  7901. },
  7902. os : {
  7903. windows : {
  7904. version : {
  7905. 'ME' : '4.90',
  7906. 'NT 3.11' : 'NT3.51',
  7907. 'NT 4.0' : 'NT4.0',
  7908. '2000' : 'NT 5.0',
  7909. 'XP' : ['NT 5.1', 'NT 5.2'],
  7910. 'Vista' : 'NT 6.0',
  7911. '7' : 'NT 6.1',
  7912. '8' : 'NT 6.2',
  7913. '8.1' : 'NT 6.3',
  7914. '10' : ['NT 6.4', 'NT 10.0'],
  7915. 'RT' : 'ARM'
  7916. }
  7917. }
  7918. }
  7919. };
  7920. //////////////
  7921. // Regex map
  7922. /////////////
  7923. var regexes = {
  7924. browser : [[
  7925. // Presto based
  7926. /(opera\smini)\/([\w\.-]+)/i, // Opera Mini
  7927. /(opera\s[mobiletab]+).+version\/([\w\.-]+)/i, // Opera Mobi/Tablet
  7928. /(opera).+version\/([\w\.]+)/i, // Opera > 9.80
  7929. /(opera)[\/\s]+([\w\.]+)/i // Opera < 9.80
  7930. ], [NAME, VERSION], [
  7931. /(opios)[\/\s]+([\w\.]+)/i // Opera mini on iphone >= 8.0
  7932. ], [[NAME, 'Opera Mini'], VERSION], [
  7933. /\s(opr)\/([\w\.]+)/i // Opera Webkit
  7934. ], [[NAME, 'Opera'], VERSION], [
  7935. // Mixed
  7936. /(kindle)\/([\w\.]+)/i, // Kindle
  7937. /(lunascape|maxthon|netfront|jasmine|blazer)[\/\s]?([\w\.]*)/i,
  7938. // Lunascape/Maxthon/Netfront/Jasmine/Blazer
  7939. // Trident based
  7940. /(avant\s|iemobile|slim)(?:browser)?[\/\s]?([\w\.]*)/i,
  7941. // Avant/IEMobile/SlimBrowser
  7942. /(bidubrowser|baidubrowser)[\/\s]?([\w\.]+)/i, // Baidu Browser
  7943. /(?:ms|\()(ie)\s([\w\.]+)/i, // Internet Explorer
  7944. // Webkit/KHTML based
  7945. /(rekonq)\/([\w\.]*)/i, // Rekonq
  7946. /(chromium|flock|rockmelt|midori|epiphany|silk|skyfire|ovibrowser|bolt|iron|vivaldi|iridium|phantomjs|bowser|quark|qupzilla|falkon)\/([\w\.-]+)/i
  7947. // Chromium/Flock/RockMelt/Midori/Epiphany/Silk/Skyfire/Bolt/Iron/Iridium/PhantomJS/Bowser/QupZilla/Falkon
  7948. ], [NAME, VERSION], [
  7949. /(konqueror)\/([\w\.]+)/i // Konqueror
  7950. ], [[NAME, 'Konqueror'], VERSION], [
  7951. /(trident).+rv[:\s]([\w\.]+).+like\sgecko/i // IE11
  7952. ], [[NAME, 'IE'], VERSION], [
  7953. /(edge|edgios|edga|edg)\/((\d+)?[\w\.]+)/i // Microsoft Edge
  7954. ], [[NAME, 'Edge'], VERSION], [
  7955. /(yabrowser)\/([\w\.]+)/i // Yandex
  7956. ], [[NAME, 'Yandex'], VERSION], [
  7957. /(Avast)\/([\w\.]+)/i // Avast Secure Browser
  7958. ], [[NAME, 'Avast Secure Browser'], VERSION], [
  7959. /(AVG)\/([\w\.]+)/i // AVG Secure Browser
  7960. ], [[NAME, 'AVG Secure Browser'], VERSION], [
  7961. /(puffin)\/([\w\.]+)/i // Puffin
  7962. ], [[NAME, 'Puffin'], VERSION], [
  7963. /(focus)\/([\w\.]+)/i // Firefox Focus
  7964. ], [[NAME, 'Firefox Focus'], VERSION], [
  7965. /(opt)\/([\w\.]+)/i // Opera Touch
  7966. ], [[NAME, 'Opera Touch'], VERSION], [
  7967. /((?:[\s\/])uc?\s?browser|(?:juc.+)ucweb)[\/\s]?([\w\.]+)/i // UCBrowser
  7968. ], [[NAME, 'UCBrowser'], VERSION], [
  7969. /(comodo_dragon)\/([\w\.]+)/i // Comodo Dragon
  7970. ], [[NAME, /_/g, ' '], VERSION], [
  7971. /(windowswechat qbcore)\/([\w\.]+)/i // WeChat Desktop for Windows Built-in Browser
  7972. ], [[NAME, 'WeChat(Win) Desktop'], VERSION], [
  7973. /(micromessenger)\/([\w\.]+)/i // WeChat
  7974. ], [[NAME, 'WeChat'], VERSION], [
  7975. /(brave)\/([\w\.]+)/i // Brave browser
  7976. ], [[NAME, 'Brave'], VERSION], [
  7977. /(qqbrowserlite)\/([\w\.]+)/i // QQBrowserLite
  7978. ], [NAME, VERSION], [
  7979. /(QQ)\/([\d\.]+)/i // QQ, aka ShouQ
  7980. ], [NAME, VERSION], [
  7981. /m?(qqbrowser)[\/\s]?([\w\.]+)/i // QQBrowser
  7982. ], [NAME, VERSION], [
  7983. /(baiduboxapp)[\/\s]?([\w\.]+)/i // Baidu App
  7984. ], [NAME, VERSION], [
  7985. /(2345Explorer)[\/\s]?([\w\.]+)/i // 2345 Browser
  7986. ], [NAME, VERSION], [
  7987. /(MetaSr)[\/\s]?([\w\.]+)/i // SouGouBrowser
  7988. ], [NAME], [
  7989. /(LBBROWSER)/i // LieBao Browser
  7990. ], [NAME], [
  7991. /xiaomi\/miuibrowser\/([\w\.]+)/i // MIUI Browser
  7992. ], [VERSION, [NAME, 'MIUI Browser']], [
  7993. /;fbav\/([\w\.]+);/i // Facebook App for iOS & Android
  7994. ], [VERSION, [NAME, 'Facebook']], [
  7995. /safari\s(line)\/([\w\.]+)/i, // Line App for iOS
  7996. /android.+(line)\/([\w\.]+)\/iab/i // Line App for Android
  7997. ], [NAME, VERSION], [
  7998. /headlesschrome(?:\/([\w\.]+)|\s)/i // Chrome Headless
  7999. ], [VERSION, [NAME, 'Chrome Headless']], [
  8000. /\swv\).+(chrome)\/([\w\.]+)/i // Chrome WebView
  8001. ], [[NAME, /(.+)/, '$1 WebView'], VERSION], [
  8002. /((?:oculus|samsung)browser)\/([\w\.]+)/i
  8003. ], [[NAME, /(.+(?:g|us))(.+)/, '$1 $2'], VERSION], [ // Oculus / Samsung Browser
  8004. /android.+version\/([\w\.]+)\s+(?:mobile\s?safari|safari)*/i // Android Browser
  8005. ], [VERSION, [NAME, 'Android Browser']], [
  8006. /(sailfishbrowser)\/([\w\.]+)/i // Sailfish Browser
  8007. ], [[NAME, 'Sailfish Browser'], VERSION], [
  8008. /(chrome|omniweb|arora|[tizenoka]{5}\s?browser)\/v?([\w\.]+)/i
  8009. // Chrome/OmniWeb/Arora/Tizen/Nokia
  8010. ], [NAME, VERSION], [
  8011. /(dolfin)\/([\w\.]+)/i // Dolphin
  8012. ], [[NAME, 'Dolphin'], VERSION], [
  8013. /(qihu|qhbrowser|qihoobrowser|360browser)/i // 360
  8014. ], [[NAME, '360 Browser']], [
  8015. /((?:android.+)crmo|crios)\/([\w\.]+)/i // Chrome for Android/iOS
  8016. ], [[NAME, 'Chrome'], VERSION], [
  8017. /(coast)\/([\w\.]+)/i // Opera Coast
  8018. ], [[NAME, 'Opera Coast'], VERSION], [
  8019. /fxios\/([\w\.-]+)/i // Firefox for iOS
  8020. ], [VERSION, [NAME, 'Firefox']], [
  8021. /version\/([\w\.]+).+?mobile\/\w+\s(safari)/i // Mobile Safari
  8022. ], [VERSION, [NAME, 'Mobile Safari']], [
  8023. /version\/([\w\.]+).+?(mobile\s?safari|safari)/i // Safari & Safari Mobile
  8024. ], [VERSION, NAME], [
  8025. /webkit.+?(gsa)\/([\w\.]+).+?(mobile\s?safari|safari)(\/[\w\.]+)/i // Google Search Appliance on iOS
  8026. ], [[NAME, 'GSA'], VERSION], [
  8027. /webkit.+?(mobile\s?safari|safari)(\/[\w\.]+)/i // Safari < 3.0
  8028. ], [NAME, [VERSION, mapper.str, maps.browser.oldsafari.version]], [
  8029. /(webkit|khtml)\/([\w\.]+)/i
  8030. ], [NAME, VERSION], [
  8031. // Gecko based
  8032. /(navigator|netscape)\/([\w\.-]+)/i // Netscape
  8033. ], [[NAME, 'Netscape'], VERSION], [
  8034. /(swiftfox)/i, // Swiftfox
  8035. /(icedragon|iceweasel|camino|chimera|fennec|maemo\sbrowser|minimo|conkeror)[\/\s]?([\w\.\+]+)/i,
  8036. // IceDragon/Iceweasel/Camino/Chimera/Fennec/Maemo/Minimo/Conkeror
  8037. /(firefox|seamonkey|k-meleon|icecat|iceape|firebird|phoenix|palemoon|basilisk|waterfox)\/([\w\.-]+)$/i,
  8038. // Firefox/SeaMonkey/K-Meleon/IceCat/IceApe/Firebird/Phoenix
  8039. /(mozilla)\/([\w\.]+).+rv\:.+gecko\/\d+/i, // Mozilla
  8040. // Other
  8041. /(polaris|lynx|dillo|icab|doris|amaya|w3m|netsurf|sleipnir)[\/\s]?([\w\.]+)/i,
  8042. // Polaris/Lynx/Dillo/iCab/Doris/Amaya/w3m/NetSurf/Sleipnir
  8043. /(links)\s\(([\w\.]+)/i, // Links
  8044. /(gobrowser)\/?([\w\.]*)/i, // GoBrowser
  8045. /(ice\s?browser)\/v?([\w\._]+)/i, // ICE Browser
  8046. /(mosaic)[\/\s]([\w\.]+)/i // Mosaic
  8047. ], [NAME, VERSION]
  8048. ],
  8049. cpu : [[
  8050. /(?:(amd|x(?:(?:86|64)[_-])?|wow|win)64)[;\)]/i // AMD64
  8051. ], [[ARCHITECTURE, 'amd64']], [
  8052. /(ia32(?=;))/i // IA32 (quicktime)
  8053. ], [[ARCHITECTURE, util.lowerize]], [
  8054. /((?:i[346]|x)86)[;\)]/i // IA32
  8055. ], [[ARCHITECTURE, 'ia32']], [
  8056. // PocketPC mistakenly identified as PowerPC
  8057. /windows\s(ce|mobile);\sppc;/i
  8058. ], [[ARCHITECTURE, 'arm']], [
  8059. /((?:ppc|powerpc)(?:64)?)(?:\smac|;|\))/i // PowerPC
  8060. ], [[ARCHITECTURE, /ower/, '', util.lowerize]], [
  8061. /(sun4\w)[;\)]/i // SPARC
  8062. ], [[ARCHITECTURE, 'sparc']], [
  8063. /((?:avr32|ia64(?=;))|68k(?=\))|arm(?:64|(?=v\d+[;l]))|(?=atmel\s)avr|(?:irix|mips|sparc)(?:64)?(?=;)|pa-risc)/i
  8064. // IA64, 68K, ARM/64, AVR/32, IRIX/64, MIPS/64, SPARC/64, PA-RISC
  8065. ], [[ARCHITECTURE, util.lowerize]]
  8066. ],
  8067. device : [[
  8068. /\((ipad|playbook);[\w\s\),;-]+(rim|apple)/i // iPad/PlayBook
  8069. ], [MODEL, VENDOR, [TYPE, TABLET]], [
  8070. /applecoremedia\/[\w\.]+ \((ipad)/ // iPad
  8071. ], [MODEL, [VENDOR, 'Apple'], [TYPE, TABLET]], [
  8072. /(apple\s{0,1}tv)/i // Apple TV
  8073. ], [[MODEL, 'Apple TV'], [VENDOR, 'Apple'], [TYPE, SMARTTV]], [
  8074. /(archos)\s(gamepad2?)/i, // Archos
  8075. /(hp).+(touchpad)/i, // HP TouchPad
  8076. /(hp).+(tablet)/i, // HP Tablet
  8077. /(kindle)\/([\w\.]+)/i, // Kindle
  8078. /\s(nook)[\w\s]+build\/(\w+)/i, // Nook
  8079. /(dell)\s(strea[kpr\s\d]*[\dko])/i // Dell Streak
  8080. ], [VENDOR, MODEL, [TYPE, TABLET]], [
  8081. /(kf[A-z]+)\sbuild\/.+silk\//i // Kindle Fire HD
  8082. ], [MODEL, [VENDOR, 'Amazon'], [TYPE, TABLET]], [
  8083. /(sd|kf)[0349hijorstuw]+\sbuild\/.+silk\//i // Fire Phone
  8084. ], [[MODEL, mapper.str, maps.device.amazon.model], [VENDOR, 'Amazon'], [TYPE, MOBILE]], [
  8085. /android.+aft([bms])\sbuild/i // Fire TV
  8086. ], [MODEL, [VENDOR, 'Amazon'], [TYPE, SMARTTV]], [
  8087. /\((ip[honed|\s\w*]+);.+(apple)/i // iPod/iPhone
  8088. ], [MODEL, VENDOR, [TYPE, MOBILE]], [
  8089. /\((ip[honed|\s\w*]+);/i // iPod/iPhone
  8090. ], [MODEL, [VENDOR, 'Apple'], [TYPE, MOBILE]], [
  8091. /(blackberry)[\s-]?(\w+)/i, // BlackBerry
  8092. /(blackberry|benq|palm(?=\-)|sonyericsson|acer|asus|dell|meizu|motorola|polytron)[\s_-]?([\w-]*)/i,
  8093. // BenQ/Palm/Sony-Ericsson/Acer/Asus/Dell/Meizu/Motorola/Polytron
  8094. /(hp)\s([\w\s]+\w)/i, // HP iPAQ
  8095. /(asus)-?(\w+)/i // Asus
  8096. ], [VENDOR, MODEL, [TYPE, MOBILE]], [
  8097. /\(bb10;\s(\w+)/i // BlackBerry 10
  8098. ], [MODEL, [VENDOR, 'BlackBerry'], [TYPE, MOBILE]], [
  8099. // Asus Tablets
  8100. /android.+(transfo[prime\s]{4,10}\s\w+|eeepc|slider\s\w+|nexus 7|padfone|p00c)/i
  8101. ], [MODEL, [VENDOR, 'Asus'], [TYPE, TABLET]], [
  8102. /(sony)\s(tablet\s[ps])\sbuild\//i, // Sony
  8103. /(sony)?(?:sgp.+)\sbuild\//i
  8104. ], [[VENDOR, 'Sony'], [MODEL, 'Xperia Tablet'], [TYPE, TABLET]], [
  8105. /android.+\s([c-g]\d{4}|so[-l]\w+)(?=\sbuild\/|\).+chrome\/(?![1-6]{0,1}\d\.))/i
  8106. ], [MODEL, [VENDOR, 'Sony'], [TYPE, MOBILE]], [
  8107. /\s(ouya)\s/i, // Ouya
  8108. /(nintendo)\s([wids3u]+)/i // Nintendo
  8109. ], [VENDOR, MODEL, [TYPE, CONSOLE]], [
  8110. /android.+;\s(shield)\sbuild/i // Nvidia
  8111. ], [MODEL, [VENDOR, 'Nvidia'], [TYPE, CONSOLE]], [
  8112. /(playstation\s[34portablevi]+)/i // Playstation
  8113. ], [MODEL, [VENDOR, 'Sony'], [TYPE, CONSOLE]], [
  8114. /(sprint\s(\w+))/i // Sprint Phones
  8115. ], [[VENDOR, mapper.str, maps.device.sprint.vendor], [MODEL, mapper.str, maps.device.sprint.model], [TYPE, MOBILE]], [
  8116. /(htc)[;_\s-]+([\w\s]+(?=\)|\sbuild)|\w+)/i, // HTC
  8117. /(zte)-(\w*)/i, // ZTE
  8118. /(alcatel|geeksphone|nexian|panasonic|(?=;\s)sony)[_\s-]?([\w-]*)/i
  8119. // Alcatel/GeeksPhone/Nexian/Panasonic/Sony
  8120. ], [VENDOR, [MODEL, /_/g, ' '], [TYPE, MOBILE]], [
  8121. /(nexus\s9)/i // HTC Nexus 9
  8122. ], [MODEL, [VENDOR, 'HTC'], [TYPE, TABLET]], [
  8123. /d\/huawei([\w\s-]+)[;\)]/i,
  8124. /(nexus\s6p|vog-l29|ane-lx1|eml-l29)/i // Huawei
  8125. ], [MODEL, [VENDOR, 'Huawei'], [TYPE, MOBILE]], [
  8126. /android.+(bah2?-a?[lw]\d{2})/i // Huawei MediaPad
  8127. ], [MODEL, [VENDOR, 'Huawei'], [TYPE, TABLET]], [
  8128. /(microsoft);\s(lumia[\s\w]+)/i // Microsoft Lumia
  8129. ], [VENDOR, MODEL, [TYPE, MOBILE]], [
  8130. /[\s\(;](xbox(?:\sone)?)[\s\);]/i // Microsoft Xbox
  8131. ], [MODEL, [VENDOR, 'Microsoft'], [TYPE, CONSOLE]], [
  8132. /(kin\.[onetw]{3})/i // Microsoft Kin
  8133. ], [[MODEL, /\./g, ' '], [VENDOR, 'Microsoft'], [TYPE, MOBILE]], [
  8134. // Motorola
  8135. /\s(milestone|droid(?:[2-4x]|\s(?:bionic|x2|pro|razr))?:?(\s4g)?)[\w\s]+build\//i,
  8136. /mot[\s-]?(\w*)/i,
  8137. /(XT\d{3,4}) build\//i,
  8138. /(nexus\s6)/i
  8139. ], [MODEL, [VENDOR, 'Motorola'], [TYPE, MOBILE]], [
  8140. /android.+\s(mz60\d|xoom[\s2]{0,2})\sbuild\//i
  8141. ], [MODEL, [VENDOR, 'Motorola'], [TYPE, TABLET]], [
  8142. /hbbtv\/\d+\.\d+\.\d+\s+\([\w\s]*;\s*(\w[^;]*);([^;]*)/i // HbbTV devices
  8143. ], [[VENDOR, util.trim], [MODEL, util.trim], [TYPE, SMARTTV]], [
  8144. /hbbtv.+maple;(\d+)/i
  8145. ], [[MODEL, /^/, 'SmartTV'], [VENDOR, 'Samsung'], [TYPE, SMARTTV]], [
  8146. /\(dtv[\);].+(aquos)/i // Sharp
  8147. ], [MODEL, [VENDOR, 'Sharp'], [TYPE, SMARTTV]], [
  8148. /android.+((sch-i[89]0\d|shw-m380s|gt-p\d{4}|gt-n\d+|sgh-t8[56]9|nexus 10))/i,
  8149. /((SM-T\w+))/i
  8150. ], [[VENDOR, 'Samsung'], MODEL, [TYPE, TABLET]], [ // Samsung
  8151. /smart-tv.+(samsung)/i
  8152. ], [VENDOR, [TYPE, SMARTTV], MODEL], [
  8153. /((s[cgp]h-\w+|gt-\w+|galaxy\snexus|sm-\w[\w\d]+))/i,
  8154. /(sam[sung]*)[\s-]*(\w+-?[\w-]*)/i,
  8155. /sec-((sgh\w+))/i
  8156. ], [[VENDOR, 'Samsung'], MODEL, [TYPE, MOBILE]], [
  8157. /sie-(\w*)/i // Siemens
  8158. ], [MODEL, [VENDOR, 'Siemens'], [TYPE, MOBILE]], [
  8159. /(maemo|nokia).*(n900|lumia\s\d+)/i, // Nokia
  8160. /(nokia)[\s_-]?([\w-]*)/i
  8161. ], [[VENDOR, 'Nokia'], MODEL, [TYPE, MOBILE]], [
  8162. /android[x\d\.\s;]+\s([ab][1-7]\-?[0178a]\d\d?)/i // Acer
  8163. ], [MODEL, [VENDOR, 'Acer'], [TYPE, TABLET]], [
  8164. /android.+([vl]k\-?\d{3})\s+build/i // LG Tablet
  8165. ], [MODEL, [VENDOR, 'LG'], [TYPE, TABLET]], [
  8166. /android\s3\.[\s\w;-]{10}(lg?)-([06cv9]{3,4})/i // LG Tablet
  8167. ], [[VENDOR, 'LG'], MODEL, [TYPE, TABLET]], [
  8168. /(lg) netcast\.tv/i // LG SmartTV
  8169. ], [VENDOR, MODEL, [TYPE, SMARTTV]], [
  8170. /(nexus\s[45])/i, // LG
  8171. /lg[e;\s\/-]+(\w*)/i,
  8172. /android.+lg(\-?[\d\w]+)\s+build/i
  8173. ], [MODEL, [VENDOR, 'LG'], [TYPE, MOBILE]], [
  8174. /(lenovo)\s?(s(?:5000|6000)(?:[\w-]+)|tab(?:[\s\w]+))/i // Lenovo tablets
  8175. ], [VENDOR, MODEL, [TYPE, TABLET]], [
  8176. /android.+(ideatab[a-z0-9\-\s]+)/i // Lenovo
  8177. ], [MODEL, [VENDOR, 'Lenovo'], [TYPE, TABLET]], [
  8178. /(lenovo)[_\s-]?([\w-]+)/i
  8179. ], [VENDOR, MODEL, [TYPE, MOBILE]], [
  8180. /linux;.+((jolla));/i // Jolla
  8181. ], [VENDOR, MODEL, [TYPE, MOBILE]], [
  8182. /((pebble))app\/[\d\.]+\s/i // Pebble
  8183. ], [VENDOR, MODEL, [TYPE, WEARABLE]], [
  8184. /android.+;\s(oppo)\s?([\w\s]+)\sbuild/i // OPPO
  8185. ], [VENDOR, MODEL, [TYPE, MOBILE]], [
  8186. /crkey/i // Google Chromecast
  8187. ], [[MODEL, 'Chromecast'], [VENDOR, 'Google'], [TYPE, SMARTTV]], [
  8188. /android.+;\s(glass)\s\d/i // Google Glass
  8189. ], [MODEL, [VENDOR, 'Google'], [TYPE, WEARABLE]], [
  8190. /android.+;\s(pixel c)[\s)]/i // Google Pixel C
  8191. ], [MODEL, [VENDOR, 'Google'], [TYPE, TABLET]], [
  8192. /android.+;\s(pixel( [23])?( xl)?)[\s)]/i // Google Pixel
  8193. ], [MODEL, [VENDOR, 'Google'], [TYPE, MOBILE]], [
  8194. /android.+;\s(\w+)\s+build\/hm\1/i, // Xiaomi Hongmi 'numeric' models
  8195. /android.+(hm[\s\-_]*note?[\s_]*(?:\d\w)?)\s+build/i, // Xiaomi Hongmi
  8196. /android.+(mi[\s\-_]*(?:a\d|one|one[\s_]plus|note lte)?[\s_]*(?:\d?\w?)[\s_]*(?:plus)?)\s+build/i,
  8197. // Xiaomi Mi
  8198. /android.+(redmi[\s\-_]*(?:note)?(?:[\s_]*[\w\s]+))\s+build/i // Redmi Phones
  8199. ], [[MODEL, /_/g, ' '], [VENDOR, 'Xiaomi'], [TYPE, MOBILE]], [
  8200. /android.+(mi[\s\-_]*(?:pad)(?:[\s_]*[\w\s]+))\s+build/i // Mi Pad tablets
  8201. ],[[MODEL, /_/g, ' '], [VENDOR, 'Xiaomi'], [TYPE, TABLET]], [
  8202. /android.+;\s(m[1-5]\snote)\sbuild/i // Meizu
  8203. ], [MODEL, [VENDOR, 'Meizu'], [TYPE, MOBILE]], [
  8204. /(mz)-([\w-]{2,})/i
  8205. ], [[VENDOR, 'Meizu'], MODEL, [TYPE, MOBILE]], [
  8206. /android.+a000(1)\s+build/i, // OnePlus
  8207. /android.+oneplus\s(a\d{4})[\s)]/i
  8208. ], [MODEL, [VENDOR, 'OnePlus'], [TYPE, MOBILE]], [
  8209. /android.+[;\/]\s*(RCT[\d\w]+)\s+build/i // RCA Tablets
  8210. ], [MODEL, [VENDOR, 'RCA'], [TYPE, TABLET]], [
  8211. /android.+[;\/\s]+(Venue[\d\s]{2,7})\s+build/i // Dell Venue Tablets
  8212. ], [MODEL, [VENDOR, 'Dell'], [TYPE, TABLET]], [
  8213. /android.+[;\/]\s*(Q[T|M][\d\w]+)\s+build/i // Verizon Tablet
  8214. ], [MODEL, [VENDOR, 'Verizon'], [TYPE, TABLET]], [
  8215. /android.+[;\/]\s+(Barnes[&\s]+Noble\s+|BN[RT])(V?.*)\s+build/i // Barnes & Noble Tablet
  8216. ], [[VENDOR, 'Barnes & Noble'], MODEL, [TYPE, TABLET]], [
  8217. /android.+[;\/]\s+(TM\d{3}.*\b)\s+build/i // Barnes & Noble Tablet
  8218. ], [MODEL, [VENDOR, 'NuVision'], [TYPE, TABLET]], [
  8219. /android.+;\s(k88)\sbuild/i // ZTE K Series Tablet
  8220. ], [MODEL, [VENDOR, 'ZTE'], [TYPE, TABLET]], [
  8221. /android.+[;\/]\s*(gen\d{3})\s+build.*49h/i // Swiss GEN Mobile
  8222. ], [MODEL, [VENDOR, 'Swiss'], [TYPE, MOBILE]], [
  8223. /android.+[;\/]\s*(zur\d{3})\s+build/i // Swiss ZUR Tablet
  8224. ], [MODEL, [VENDOR, 'Swiss'], [TYPE, TABLET]], [
  8225. /android.+[;\/]\s*((Zeki)?TB.*\b)\s+build/i // Zeki Tablets
  8226. ], [MODEL, [VENDOR, 'Zeki'], [TYPE, TABLET]], [
  8227. /(android).+[;\/]\s+([YR]\d{2})\s+build/i,
  8228. /android.+[;\/]\s+(Dragon[\-\s]+Touch\s+|DT)(\w{5})\sbuild/i // Dragon Touch Tablet
  8229. ], [[VENDOR, 'Dragon Touch'], MODEL, [TYPE, TABLET]], [
  8230. /android.+[;\/]\s*(NS-?\w{0,9})\sbuild/i // Insignia Tablets
  8231. ], [MODEL, [VENDOR, 'Insignia'], [TYPE, TABLET]], [
  8232. /android.+[;\/]\s*((NX|Next)-?\w{0,9})\s+build/i // NextBook Tablets
  8233. ], [MODEL, [VENDOR, 'NextBook'], [TYPE, TABLET]], [
  8234. /android.+[;\/]\s*(Xtreme\_)?(V(1[045]|2[015]|30|40|60|7[05]|90))\s+build/i
  8235. ], [[VENDOR, 'Voice'], MODEL, [TYPE, MOBILE]], [ // Voice Xtreme Phones
  8236. /android.+[;\/]\s*(LVTEL\-)?(V1[12])\s+build/i // LvTel Phones
  8237. ], [[VENDOR, 'LvTel'], MODEL, [TYPE, MOBILE]], [
  8238. /android.+;\s(PH-1)\s/i
  8239. ], [MODEL, [VENDOR, 'Essential'], [TYPE, MOBILE]], [ // Essential PH-1
  8240. /android.+[;\/]\s*(V(100MD|700NA|7011|917G).*\b)\s+build/i // Envizen Tablets
  8241. ], [MODEL, [VENDOR, 'Envizen'], [TYPE, TABLET]], [
  8242. /android.+[;\/]\s*(Le[\s\-]+Pan)[\s\-]+(\w{1,9})\s+build/i // Le Pan Tablets
  8243. ], [VENDOR, MODEL, [TYPE, TABLET]], [
  8244. /android.+[;\/]\s*(Trio[\s\-]*.*)\s+build/i // MachSpeed Tablets
  8245. ], [MODEL, [VENDOR, 'MachSpeed'], [TYPE, TABLET]], [
  8246. /android.+[;\/]\s*(Trinity)[\-\s]*(T\d{3})\s+build/i // Trinity Tablets
  8247. ], [VENDOR, MODEL, [TYPE, TABLET]], [
  8248. /android.+[;\/]\s*TU_(1491)\s+build/i // Rotor Tablets
  8249. ], [MODEL, [VENDOR, 'Rotor'], [TYPE, TABLET]], [
  8250. /android.+(KS(.+))\s+build/i // Amazon Kindle Tablets
  8251. ], [MODEL, [VENDOR, 'Amazon'], [TYPE, TABLET]], [
  8252. /android.+(Gigaset)[\s\-]+(Q\w{1,9})\s+build/i // Gigaset Tablets
  8253. ], [VENDOR, MODEL, [TYPE, TABLET]], [
  8254. /\s(tablet|tab)[;\/]/i, // Unidentifiable Tablet
  8255. /\s(mobile)(?:[;\/]|\ssafari)/i // Unidentifiable Mobile
  8256. ], [[TYPE, util.lowerize], VENDOR, MODEL], [
  8257. /[\s\/\(](smart-?tv)[;\)]/i // SmartTV
  8258. ], [[TYPE, SMARTTV]], [
  8259. /(android[\w\.\s\-]{0,9});.+build/i // Generic Android Device
  8260. ], [MODEL, [VENDOR, 'Generic']]
  8261. ],
  8262. engine : [[
  8263. /windows.+\sedge\/([\w\.]+)/i // EdgeHTML
  8264. ], [VERSION, [NAME, 'EdgeHTML']], [
  8265. /webkit\/537\.36.+chrome\/(?!27)([\w\.]+)/i // Blink
  8266. ], [VERSION, [NAME, 'Blink']], [
  8267. /(presto)\/([\w\.]+)/i, // Presto
  8268. /(webkit|trident|netfront|netsurf|amaya|lynx|w3m|goanna)\/([\w\.]+)/i,
  8269. // WebKit/Trident/NetFront/NetSurf/Amaya/Lynx/w3m/Goanna
  8270. /(khtml|tasman|links)[\/\s]\(?([\w\.]+)/i, // KHTML/Tasman/Links
  8271. /(icab)[\/\s]([23]\.[\d\.]+)/i // iCab
  8272. ], [NAME, VERSION], [
  8273. /rv\:([\w\.]{1,9}).+(gecko)/i // Gecko
  8274. ], [VERSION, NAME]
  8275. ],
  8276. os : [[
  8277. // Windows based
  8278. /microsoft\s(windows)\s(vista|xp)/i // Windows (iTunes)
  8279. ], [NAME, VERSION], [
  8280. /(windows)\snt\s6\.2;\s(arm)/i, // Windows RT
  8281. /(windows\sphone(?:\sos)*)[\s\/]?([\d\.\s\w]*)/i, // Windows Phone
  8282. /(windows\smobile|windows)[\s\/]?([ntce\d\.\s]+\w)/i
  8283. ], [NAME, [VERSION, mapper.str, maps.os.windows.version]], [
  8284. /(win(?=3|9|n)|win\s9x\s)([nt\d\.]+)/i
  8285. ], [[NAME, 'Windows'], [VERSION, mapper.str, maps.os.windows.version]], [
  8286. // Mobile/Embedded OS
  8287. /\((bb)(10);/i // BlackBerry 10
  8288. ], [[NAME, 'BlackBerry'], VERSION], [
  8289. /(blackberry)\w*\/?([\w\.]*)/i, // Blackberry
  8290. /(tizen|kaios)[\/\s]([\w\.]+)/i, // Tizen/KaiOS
  8291. /(android|webos|palm\sos|qnx|bada|rim\stablet\sos|meego|sailfish|contiki)[\/\s-]?([\w\.]*)/i
  8292. // Android/WebOS/Palm/QNX/Bada/RIM/MeeGo/Contiki/Sailfish OS
  8293. ], [NAME, VERSION], [
  8294. /(symbian\s?os|symbos|s60(?=;))[\/\s-]?([\w\.]*)/i // Symbian
  8295. ], [[NAME, 'Symbian'], VERSION], [
  8296. /\((series40);/i // Series 40
  8297. ], [NAME], [
  8298. /mozilla.+\(mobile;.+gecko.+firefox/i // Firefox OS
  8299. ], [[NAME, 'Firefox OS'], VERSION], [
  8300. // Console
  8301. /(nintendo|playstation)\s([wids34portablevu]+)/i, // Nintendo/Playstation
  8302. // GNU/Linux based
  8303. /(mint)[\/\s\(]?(\w*)/i, // Mint
  8304. /(mageia|vectorlinux)[;\s]/i, // Mageia/VectorLinux
  8305. /(joli|[kxln]?ubuntu|debian|suse|opensuse|gentoo|(?=\s)arch|slackware|fedora|mandriva|centos|pclinuxos|redhat|zenwalk|linpus)[\/\s-]?(?!chrom)([\w\.-]*)/i,
  8306. // Joli/Ubuntu/Debian/SUSE/Gentoo/Arch/Slackware
  8307. // Fedora/Mandriva/CentOS/PCLinuxOS/RedHat/Zenwalk/Linpus
  8308. /(hurd|linux)\s?([\w\.]*)/i, // Hurd/Linux
  8309. /(gnu)\s?([\w\.]*)/i // GNU
  8310. ], [NAME, VERSION], [
  8311. /(cros)\s[\w]+\s([\w\.]+\w)/i // Chromium OS
  8312. ], [[NAME, 'Chromium OS'], VERSION],[
  8313. // Solaris
  8314. /(sunos)\s?([\w\.\d]*)/i // Solaris
  8315. ], [[NAME, 'Solaris'], VERSION], [
  8316. // BSD based
  8317. /\s([frentopc-]{0,4}bsd|dragonfly)\s?([\w\.]*)/i // FreeBSD/NetBSD/OpenBSD/PC-BSD/DragonFly
  8318. ], [NAME, VERSION],[
  8319. /(haiku)\s(\w+)/i // Haiku
  8320. ], [NAME, VERSION],[
  8321. /cfnetwork\/.+darwin/i,
  8322. /ip[honead]{2,4}(?:.*os\s([\w]+)\slike\smac|;\sopera)/i // iOS
  8323. ], [[VERSION, /_/g, '.'], [NAME, 'iOS']], [
  8324. /(mac\sos\sx)\s?([\w\s\.]*)/i,
  8325. /(macintosh|mac(?=_powerpc)\s)/i // Mac OS
  8326. ], [[NAME, 'Mac OS'], [VERSION, /_/g, '.']], [
  8327. // Other
  8328. /((?:open)?solaris)[\/\s-]?([\w\.]*)/i, // Solaris
  8329. /(aix)\s((\d)(?=\.|\)|\s)[\w\.])*/i, // AIX
  8330. /(plan\s9|minix|beos|os\/2|amigaos|morphos|risc\sos|openvms|fuchsia)/i,
  8331. // Plan9/Minix/BeOS/OS2/AmigaOS/MorphOS/RISCOS/OpenVMS/Fuchsia
  8332. /(unix)\s?([\w\.]*)/i // UNIX
  8333. ], [NAME, VERSION]
  8334. ]
  8335. };
  8336. /////////////////
  8337. // Constructor
  8338. ////////////////
  8339. var UAParser = function (uastring, extensions) {
  8340. if (typeof uastring === 'object') {
  8341. extensions = uastring;
  8342. uastring = undefined$1;
  8343. }
  8344. if (!(this instanceof UAParser)) {
  8345. return new UAParser(uastring, extensions).getResult();
  8346. }
  8347. var ua = uastring || ((window && window.navigator && window.navigator.userAgent) ? window.navigator.userAgent : EMPTY);
  8348. var rgxmap = extensions ? util.extend(regexes, extensions) : regexes;
  8349. this.getBrowser = function () {
  8350. var browser = { name: undefined$1, version: undefined$1 };
  8351. mapper.rgx.call(browser, ua, rgxmap.browser);
  8352. browser.major = util.major(browser.version); // deprecated
  8353. return browser;
  8354. };
  8355. this.getCPU = function () {
  8356. var cpu = { architecture: undefined$1 };
  8357. mapper.rgx.call(cpu, ua, rgxmap.cpu);
  8358. return cpu;
  8359. };
  8360. this.getDevice = function () {
  8361. var device = { vendor: undefined$1, model: undefined$1, type: undefined$1 };
  8362. mapper.rgx.call(device, ua, rgxmap.device);
  8363. return device;
  8364. };
  8365. this.getEngine = function () {
  8366. var engine = { name: undefined$1, version: undefined$1 };
  8367. mapper.rgx.call(engine, ua, rgxmap.engine);
  8368. return engine;
  8369. };
  8370. this.getOS = function () {
  8371. var os = { name: undefined$1, version: undefined$1 };
  8372. mapper.rgx.call(os, ua, rgxmap.os);
  8373. return os;
  8374. };
  8375. this.getResult = function () {
  8376. return {
  8377. ua : this.getUA(),
  8378. browser : this.getBrowser(),
  8379. engine : this.getEngine(),
  8380. os : this.getOS(),
  8381. device : this.getDevice(),
  8382. cpu : this.getCPU()
  8383. };
  8384. };
  8385. this.getUA = function () {
  8386. return ua;
  8387. };
  8388. this.setUA = function (uastring) {
  8389. ua = uastring;
  8390. return this;
  8391. };
  8392. return this;
  8393. };
  8394. UAParser.VERSION = LIBVERSION;
  8395. UAParser.BROWSER = {
  8396. NAME : NAME,
  8397. MAJOR : MAJOR, // deprecated
  8398. VERSION : VERSION
  8399. };
  8400. UAParser.CPU = {
  8401. ARCHITECTURE : ARCHITECTURE
  8402. };
  8403. UAParser.DEVICE = {
  8404. MODEL : MODEL,
  8405. VENDOR : VENDOR,
  8406. TYPE : TYPE,
  8407. CONSOLE : CONSOLE,
  8408. MOBILE : MOBILE,
  8409. SMARTTV : SMARTTV,
  8410. TABLET : TABLET,
  8411. WEARABLE: WEARABLE,
  8412. EMBEDDED: EMBEDDED
  8413. };
  8414. UAParser.ENGINE = {
  8415. NAME : NAME,
  8416. VERSION : VERSION
  8417. };
  8418. UAParser.OS = {
  8419. NAME : NAME,
  8420. VERSION : VERSION
  8421. };
  8422. ///////////
  8423. // Export
  8424. //////////
  8425. // check js environment
  8426. {
  8427. // nodejs env
  8428. if ( module.exports) {
  8429. exports = module.exports = UAParser;
  8430. }
  8431. exports.UAParser = UAParser;
  8432. }
  8433. // jQuery/Zepto specific (optional)
  8434. // Note:
  8435. // In AMD env the global scope should be kept clean, but jQuery is an exception.
  8436. // jQuery always exports to global scope, unless jQuery.noConflict(true) is used,
  8437. // and we should catch that.
  8438. var $ = window && (window.jQuery || window.Zepto);
  8439. if ($ && !$.ua) {
  8440. var parser = new UAParser();
  8441. $.ua = parser.getResult();
  8442. $.ua.get = function () {
  8443. return parser.getUA();
  8444. };
  8445. $.ua.set = function (uastring) {
  8446. parser.setUA(uastring);
  8447. var result = parser.getResult();
  8448. for (var prop in result) {
  8449. $.ua[prop] = result[prop];
  8450. }
  8451. };
  8452. }
  8453. })(typeof window === 'object' ? window : commonjsGlobal);
  8454. });
  8455. var uaParser_1 = uaParser.UAParser;
  8456. var UNKNOWN = 'Unknown';
  8457. var PLATFORM_MAP = {
  8458. 'Mac OS': 'Mac OS X'
  8459. };
  8460. /**
  8461. * Convert from UAParser platform name to what we expect.
  8462. */
  8463. function convertPlatformName(name) {
  8464. return PLATFORM_MAP[name] || name;
  8465. }
  8466. /**
  8467. * Get the version number in parts. This is very naive. We actually get major
  8468. * version as a part of UAParser already, which is generally good enough, but
  8469. * let's get the minor just in case.
  8470. */
  8471. function getBrowserVersion(version) {
  8472. if (!version) {
  8473. return {
  8474. major: '',
  8475. minor: ''
  8476. };
  8477. }
  8478. var parts = version.split('.');
  8479. return {
  8480. major: parts[0],
  8481. minor: parts[1]
  8482. };
  8483. }
  8484. /**
  8485. * Get the UA data fom UAParser and then convert it to the format we're
  8486. * expecting for our APIS.
  8487. */
  8488. var parser = new uaParser();
  8489. var results = parser.getResult();
  8490. // Do some conversion first.
  8491. var browserVersionData = getBrowserVersion(results.browser.version);
  8492. var uaData = {
  8493. browserArchitecture: results.cpu.architecture || UNKNOWN,
  8494. browserFullVersion: results.browser.version || UNKNOWN,
  8495. browserMinorVersion: browserVersionData.minor || UNKNOWN,
  8496. browserName: results.browser.name || UNKNOWN,
  8497. browserVersion: results.browser.major || UNKNOWN,
  8498. deviceName: results.device.model || UNKNOWN,
  8499. engineName: results.engine.name || UNKNOWN,
  8500. engineVersion: results.engine.version || UNKNOWN,
  8501. platformArchitecture: results.cpu.architecture || UNKNOWN,
  8502. platformName: convertPlatformName(results.os.name) || UNKNOWN,
  8503. platformVersion: results.os.version || UNKNOWN,
  8504. platformFullVersion: results.os.version || UNKNOWN
  8505. };
  8506. var UserAgentData = uaData;
  8507. var componentRegex = /\./;
  8508. var orRegex = /\|\|/;
  8509. var rangeRegex = /\s+\-\s+/;
  8510. var modifierRegex = /^(<=|<|=|>=|~>|~|>|)?\s*(.+)/;
  8511. var numericRegex = /^(\d*)(.*)/;
  8512. /**
  8513. * Splits input `range` on "||" and returns true if any subrange matches
  8514. * `version`.
  8515. *
  8516. * @param {string} range
  8517. * @param {string} version
  8518. * @returns {boolean}
  8519. */
  8520. function checkOrExpression(range, version) {
  8521. var expressions = range.split(orRegex);
  8522. if (expressions.length > 1) {
  8523. return expressions.some(function (range) {
  8524. return VersionRange.contains(range, version);
  8525. });
  8526. } else {
  8527. range = expressions[0].trim();
  8528. return checkRangeExpression(range, version);
  8529. }
  8530. }
  8531. /**
  8532. * Splits input `range` on " - " (the surrounding whitespace is required) and
  8533. * returns true if version falls between the two operands.
  8534. *
  8535. * @param {string} range
  8536. * @param {string} version
  8537. * @returns {boolean}
  8538. */
  8539. function checkRangeExpression(range, version) {
  8540. var expressions = range.split(rangeRegex);
  8541. !(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;
  8542. if (expressions.length === 1) {
  8543. return checkSimpleExpression(expressions[0], version);
  8544. } else {
  8545. var startVersion = expressions[0],
  8546. endVersion = expressions[1];
  8547. !(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;
  8548. return checkSimpleExpression('>=' + startVersion, version) && checkSimpleExpression('<=' + endVersion, version);
  8549. }
  8550. }
  8551. /**
  8552. * Checks if `range` matches `version`. `range` should be a "simple" range (ie.
  8553. * not a compound range using the " - " or "||" operators).
  8554. *
  8555. * @param {string} range
  8556. * @param {string} version
  8557. * @returns {boolean}
  8558. */
  8559. function checkSimpleExpression(range, version) {
  8560. range = range.trim();
  8561. if (range === '') {
  8562. return true;
  8563. }
  8564. var versionComponents = version.split(componentRegex);
  8565. var _getModifierAndCompon = getModifierAndComponents(range),
  8566. modifier = _getModifierAndCompon.modifier,
  8567. rangeComponents = _getModifierAndCompon.rangeComponents;
  8568. switch (modifier) {
  8569. case '<':
  8570. return checkLessThan(versionComponents, rangeComponents);
  8571. case '<=':
  8572. return checkLessThanOrEqual(versionComponents, rangeComponents);
  8573. case '>=':
  8574. return checkGreaterThanOrEqual(versionComponents, rangeComponents);
  8575. case '>':
  8576. return checkGreaterThan(versionComponents, rangeComponents);
  8577. case '~':
  8578. case '~>':
  8579. return checkApproximateVersion(versionComponents, rangeComponents);
  8580. default:
  8581. return checkEqual(versionComponents, rangeComponents);
  8582. }
  8583. }
  8584. /**
  8585. * Checks whether `a` is less than `b`.
  8586. *
  8587. * @param {array<string>} a
  8588. * @param {array<string>} b
  8589. * @returns {boolean}
  8590. */
  8591. function checkLessThan(a, b) {
  8592. return compareComponents(a, b) === -1;
  8593. }
  8594. /**
  8595. * Checks whether `a` is less than or equal to `b`.
  8596. *
  8597. * @param {array<string>} a
  8598. * @param {array<string>} b
  8599. * @returns {boolean}
  8600. */
  8601. function checkLessThanOrEqual(a, b) {
  8602. var result = compareComponents(a, b);
  8603. return result === -1 || result === 0;
  8604. }
  8605. /**
  8606. * Checks whether `a` is equal to `b`.
  8607. *
  8608. * @param {array<string>} a
  8609. * @param {array<string>} b
  8610. * @returns {boolean}
  8611. */
  8612. function checkEqual(a, b) {
  8613. return compareComponents(a, b) === 0;
  8614. }
  8615. /**
  8616. * Checks whether `a` is greater than or equal to `b`.
  8617. *
  8618. * @param {array<string>} a
  8619. * @param {array<string>} b
  8620. * @returns {boolean}
  8621. */
  8622. function checkGreaterThanOrEqual(a, b) {
  8623. var result = compareComponents(a, b);
  8624. return result === 1 || result === 0;
  8625. }
  8626. /**
  8627. * Checks whether `a` is greater than `b`.
  8628. *
  8629. * @param {array<string>} a
  8630. * @param {array<string>} b
  8631. * @returns {boolean}
  8632. */
  8633. function checkGreaterThan(a, b) {
  8634. return compareComponents(a, b) === 1;
  8635. }
  8636. /**
  8637. * Checks whether `a` is "reasonably close" to `b` (as described in
  8638. * https://www.npmjs.org/doc/misc/semver.html). For example, if `b` is "1.3.1"
  8639. * then "reasonably close" is defined as ">= 1.3.1 and < 1.4".
  8640. *
  8641. * @param {array<string>} a
  8642. * @param {array<string>} b
  8643. * @returns {boolean}
  8644. */
  8645. function checkApproximateVersion(a, b) {
  8646. var lowerBound = b.slice();
  8647. var upperBound = b.slice();
  8648. if (upperBound.length > 1) {
  8649. upperBound.pop();
  8650. }
  8651. var lastIndex = upperBound.length - 1;
  8652. var numeric = parseInt(upperBound[lastIndex], 10);
  8653. if (isNumber(numeric)) {
  8654. upperBound[lastIndex] = numeric + 1 + '';
  8655. }
  8656. return checkGreaterThanOrEqual(a, lowerBound) && checkLessThan(a, upperBound);
  8657. }
  8658. /**
  8659. * Extracts the optional modifier (<, <=, =, >=, >, ~, ~>) and version
  8660. * components from `range`.
  8661. *
  8662. * For example, given `range` ">= 1.2.3" returns an object with a `modifier` of
  8663. * `">="` and `components` of `[1, 2, 3]`.
  8664. *
  8665. * @param {string} range
  8666. * @returns {object}
  8667. */
  8668. function getModifierAndComponents(range) {
  8669. var rangeComponents = range.split(componentRegex);
  8670. var matches = rangeComponents[0].match(modifierRegex);
  8671. !matches ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'expected regex to match but it did not') : invariant_1(false) : void 0;
  8672. return {
  8673. modifier: matches[1],
  8674. rangeComponents: [matches[2]].concat(rangeComponents.slice(1))
  8675. };
  8676. }
  8677. /**
  8678. * Determines if `number` is a number.
  8679. *
  8680. * @param {mixed} number
  8681. * @returns {boolean}
  8682. */
  8683. function isNumber(number) {
  8684. return !isNaN(number) && isFinite(number);
  8685. }
  8686. /**
  8687. * Tests whether `range` is a "simple" version number without any modifiers
  8688. * (">", "~" etc).
  8689. *
  8690. * @param {string} range
  8691. * @returns {boolean}
  8692. */
  8693. function isSimpleVersion(range) {
  8694. return !getModifierAndComponents(range).modifier;
  8695. }
  8696. /**
  8697. * Zero-pads array `array` until it is at least `length` long.
  8698. *
  8699. * @param {array} array
  8700. * @param {number} length
  8701. */
  8702. function zeroPad(array, length) {
  8703. for (var i = array.length; i < length; i++) {
  8704. array[i] = '0';
  8705. }
  8706. }
  8707. /**
  8708. * Normalizes `a` and `b` in preparation for comparison by doing the following:
  8709. *
  8710. * - zero-pads `a` and `b`
  8711. * - marks any "x", "X" or "*" component in `b` as equivalent by zero-ing it out
  8712. * in both `a` and `b`
  8713. * - marks any final "*" component in `b` as a greedy wildcard by zero-ing it
  8714. * and all of its successors in `a`
  8715. *
  8716. * @param {array<string>} a
  8717. * @param {array<string>} b
  8718. * @returns {array<array<string>>}
  8719. */
  8720. function normalizeVersions(a, b) {
  8721. a = a.slice();
  8722. b = b.slice();
  8723. zeroPad(a, b.length);
  8724. // mark "x" and "*" components as equal
  8725. for (var i = 0; i < b.length; i++) {
  8726. var matches = b[i].match(/^[x*]$/i);
  8727. if (matches) {
  8728. b[i] = a[i] = '0';
  8729. // final "*" greedily zeros all remaining components
  8730. if (matches[0] === '*' && i === b.length - 1) {
  8731. for (var j = i; j < a.length; j++) {
  8732. a[j] = '0';
  8733. }
  8734. }
  8735. }
  8736. }
  8737. zeroPad(b, a.length);
  8738. return [a, b];
  8739. }
  8740. /**
  8741. * Returns the numerical -- not the lexicographical -- ordering of `a` and `b`.
  8742. *
  8743. * For example, `10-alpha` is greater than `2-beta`.
  8744. *
  8745. * @param {string} a
  8746. * @param {string} b
  8747. * @returns {number} -1, 0 or 1 to indicate whether `a` is less than, equal to,
  8748. * or greater than `b`, respectively
  8749. */
  8750. function compareNumeric(a, b) {
  8751. var aPrefix = a.match(numericRegex)[1];
  8752. var bPrefix = b.match(numericRegex)[1];
  8753. var aNumeric = parseInt(aPrefix, 10);
  8754. var bNumeric = parseInt(bPrefix, 10);
  8755. if (isNumber(aNumeric) && isNumber(bNumeric) && aNumeric !== bNumeric) {
  8756. return compare(aNumeric, bNumeric);
  8757. } else {
  8758. return compare(a, b);
  8759. }
  8760. }
  8761. /**
  8762. * Returns the ordering of `a` and `b`.
  8763. *
  8764. * @param {string|number} a
  8765. * @param {string|number} b
  8766. * @returns {number} -1, 0 or 1 to indicate whether `a` is less than, equal to,
  8767. * or greater than `b`, respectively
  8768. */
  8769. function compare(a, b) {
  8770. !(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;
  8771. if (a > b) {
  8772. return 1;
  8773. } else if (a < b) {
  8774. return -1;
  8775. } else {
  8776. return 0;
  8777. }
  8778. }
  8779. /**
  8780. * Compares arrays of version components.
  8781. *
  8782. * @param {array<string>} a
  8783. * @param {array<string>} b
  8784. * @returns {number} -1, 0 or 1 to indicate whether `a` is less than, equal to,
  8785. * or greater than `b`, respectively
  8786. */
  8787. function compareComponents(a, b) {
  8788. var _normalizeVersions = normalizeVersions(a, b),
  8789. aNormalized = _normalizeVersions[0],
  8790. bNormalized = _normalizeVersions[1];
  8791. for (var i = 0; i < bNormalized.length; i++) {
  8792. var result = compareNumeric(aNormalized[i], bNormalized[i]);
  8793. if (result) {
  8794. return result;
  8795. }
  8796. }
  8797. return 0;
  8798. }
  8799. var VersionRange = {
  8800. /**
  8801. * Checks whether `version` satisfies the `range` specification.
  8802. *
  8803. * We support a subset of the expressions defined in
  8804. * https://www.npmjs.org/doc/misc/semver.html:
  8805. *
  8806. * version Must match version exactly
  8807. * =version Same as just version
  8808. * >version Must be greater than version
  8809. * >=version Must be greater than or equal to version
  8810. * <version Must be less than version
  8811. * <=version Must be less than or equal to version
  8812. * ~version Must be at least version, but less than the next significant
  8813. * revision above version:
  8814. * "~1.2.3" is equivalent to ">= 1.2.3 and < 1.3"
  8815. * ~>version Equivalent to ~version
  8816. * 1.2.x Must match "1.2.x", where "x" is a wildcard that matches
  8817. * anything
  8818. * 1.2.* Similar to "1.2.x", but "*" in the trailing position is a
  8819. * "greedy" wildcard, so will match any number of additional
  8820. * components:
  8821. * "1.2.*" will match "1.2.1", "1.2.1.1", "1.2.1.1.1" etc
  8822. * * Any version
  8823. * "" (Empty string) Same as *
  8824. * v1 - v2 Equivalent to ">= v1 and <= v2"
  8825. * r1 || r2 Passes if either r1 or r2 are satisfied
  8826. *
  8827. * @param {string} range
  8828. * @param {string} version
  8829. * @returns {boolean}
  8830. */
  8831. contains: function contains(range, version) {
  8832. return checkOrExpression(range.trim(), version.trim());
  8833. }
  8834. };
  8835. var VersionRange_1 = VersionRange;
  8836. /**
  8837. * Copyright (c) 2013-present, Facebook, Inc.
  8838. *
  8839. * This source code is licensed under the MIT license found in the
  8840. * LICENSE file in the root directory of this source tree.
  8841. *
  8842. */
  8843. var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
  8844. /**
  8845. * Executes the provided `callback` once for each enumerable own property in the
  8846. * object and constructs a new object from the results. The `callback` is
  8847. * invoked with three arguments:
  8848. *
  8849. * - the property value
  8850. * - the property name
  8851. * - the object being traversed
  8852. *
  8853. * Properties that are added after the call to `mapObject` will not be visited
  8854. * by `callback`. If the values of existing properties are changed, the value
  8855. * passed to `callback` will be the value at the time `mapObject` visits them.
  8856. * Properties that are deleted before being visited are not visited.
  8857. *
  8858. * @grep function objectMap()
  8859. * @grep function objMap()
  8860. *
  8861. * @param {?object} object
  8862. * @param {function} callback
  8863. * @param {*} context
  8864. * @return {?object}
  8865. */
  8866. function mapObject(object, callback, context) {
  8867. if (!object) {
  8868. return null;
  8869. }
  8870. var result = {};
  8871. for (var name in object) {
  8872. if (hasOwnProperty$1.call(object, name)) {
  8873. result[name] = callback.call(context, object[name], name, object);
  8874. }
  8875. }
  8876. return result;
  8877. }
  8878. var mapObject_1 = mapObject;
  8879. /**
  8880. * Copyright (c) 2013-present, Facebook, Inc.
  8881. *
  8882. * This source code is licensed under the MIT license found in the
  8883. * LICENSE file in the root directory of this source tree.
  8884. *
  8885. *
  8886. * @typechecks static-only
  8887. */
  8888. /**
  8889. * Memoizes the return value of a function that accepts one string argument.
  8890. */
  8891. function memoizeStringOnly(callback) {
  8892. var cache = {};
  8893. return function (string) {
  8894. if (!cache.hasOwnProperty(string)) {
  8895. cache[string] = callback.call(this, string);
  8896. }
  8897. return cache[string];
  8898. };
  8899. }
  8900. var memoizeStringOnly_1 = memoizeStringOnly;
  8901. /**
  8902. * Checks to see whether `name` and `version` satisfy `query`.
  8903. *
  8904. * @param {string} name Name of the browser, device, engine or platform
  8905. * @param {?string} version Version of the browser, engine or platform
  8906. * @param {string} query Query of form "Name [range expression]"
  8907. * @param {?function} normalizer Optional pre-processor for range expression
  8908. * @return {boolean}
  8909. */
  8910. function compare$1(name, version, query, normalizer) {
  8911. // check for exact match with no version
  8912. if (name === query) {
  8913. return true;
  8914. }
  8915. // check for non-matching names
  8916. if (!query.startsWith(name)) {
  8917. return false;
  8918. }
  8919. // full comparison with version
  8920. var range = query.slice(name.length);
  8921. if (version) {
  8922. range = normalizer ? normalizer(range) : range;
  8923. return VersionRange_1.contains(range, version);
  8924. }
  8925. return false;
  8926. }
  8927. /**
  8928. * Normalizes `version` by stripping any "NT" prefix, but only on the Windows
  8929. * platform.
  8930. *
  8931. * Mimics the stripping performed by the `UserAgentWindowsPlatform` PHP class.
  8932. *
  8933. * @param {string} version
  8934. * @return {string}
  8935. */
  8936. function normalizePlatformVersion(version) {
  8937. if (UserAgentData.platformName === 'Windows') {
  8938. return version.replace(/^\s*NT/, '');
  8939. }
  8940. return version;
  8941. }
  8942. /**
  8943. * Provides client-side access to the authoritative PHP-generated User Agent
  8944. * information supplied by the server.
  8945. */
  8946. var UserAgent = {
  8947. /**
  8948. * Check if the User Agent browser matches `query`.
  8949. *
  8950. * `query` should be a string like "Chrome" or "Chrome > 33".
  8951. *
  8952. * Valid browser names include:
  8953. *
  8954. * - ACCESS NetFront
  8955. * - AOL
  8956. * - Amazon Silk
  8957. * - Android
  8958. * - BlackBerry
  8959. * - BlackBerry PlayBook
  8960. * - Chrome
  8961. * - Chrome for iOS
  8962. * - Chrome frame
  8963. * - Facebook PHP SDK
  8964. * - Facebook for iOS
  8965. * - Firefox
  8966. * - IE
  8967. * - IE Mobile
  8968. * - Mobile Safari
  8969. * - Motorola Internet Browser
  8970. * - Nokia
  8971. * - Openwave Mobile Browser
  8972. * - Opera
  8973. * - Opera Mini
  8974. * - Opera Mobile
  8975. * - Safari
  8976. * - UIWebView
  8977. * - Unknown
  8978. * - webOS
  8979. * - etc...
  8980. *
  8981. * An authoritative list can be found in the PHP `BrowserDetector` class and
  8982. * related classes in the same file (see calls to `new UserAgentBrowser` here:
  8983. * https://fburl.com/50728104).
  8984. *
  8985. * @note Function results are memoized
  8986. *
  8987. * @param {string} query Query of the form "Name [range expression]"
  8988. * @return {boolean}
  8989. */
  8990. isBrowser: function isBrowser(query) {
  8991. return compare$1(UserAgentData.browserName, UserAgentData.browserFullVersion, query);
  8992. },
  8993. /**
  8994. * Check if the User Agent browser uses a 32 or 64 bit architecture.
  8995. *
  8996. * @note Function results are memoized
  8997. *
  8998. * @param {string} query Query of the form "32" or "64".
  8999. * @return {boolean}
  9000. */
  9001. isBrowserArchitecture: function isBrowserArchitecture(query) {
  9002. return compare$1(UserAgentData.browserArchitecture, null, query);
  9003. },
  9004. /**
  9005. * Check if the User Agent device matches `query`.
  9006. *
  9007. * `query` should be a string like "iPhone" or "iPad".
  9008. *
  9009. * Valid device names include:
  9010. *
  9011. * - Kindle
  9012. * - Kindle Fire
  9013. * - Unknown
  9014. * - iPad
  9015. * - iPhone
  9016. * - iPod
  9017. * - etc...
  9018. *
  9019. * An authoritative list can be found in the PHP `DeviceDetector` class and
  9020. * related classes in the same file (see calls to `new UserAgentDevice` here:
  9021. * https://fburl.com/50728332).
  9022. *
  9023. * @note Function results are memoized
  9024. *
  9025. * @param {string} query Query of the form "Name"
  9026. * @return {boolean}
  9027. */
  9028. isDevice: function isDevice(query) {
  9029. return compare$1(UserAgentData.deviceName, null, query);
  9030. },
  9031. /**
  9032. * Check if the User Agent rendering engine matches `query`.
  9033. *
  9034. * `query` should be a string like "WebKit" or "WebKit >= 537".
  9035. *
  9036. * Valid engine names include:
  9037. *
  9038. * - Gecko
  9039. * - Presto
  9040. * - Trident
  9041. * - WebKit
  9042. * - etc...
  9043. *
  9044. * An authoritative list can be found in the PHP `RenderingEngineDetector`
  9045. * class related classes in the same file (see calls to `new
  9046. * UserAgentRenderingEngine` here: https://fburl.com/50728617).
  9047. *
  9048. * @note Function results are memoized
  9049. *
  9050. * @param {string} query Query of the form "Name [range expression]"
  9051. * @return {boolean}
  9052. */
  9053. isEngine: function isEngine(query) {
  9054. return compare$1(UserAgentData.engineName, UserAgentData.engineVersion, query);
  9055. },
  9056. /**
  9057. * Check if the User Agent platform matches `query`.
  9058. *
  9059. * `query` should be a string like "Windows" or "iOS 5 - 6".
  9060. *
  9061. * Valid platform names include:
  9062. *
  9063. * - Android
  9064. * - BlackBerry OS
  9065. * - Java ME
  9066. * - Linux
  9067. * - Mac OS X
  9068. * - Mac OS X Calendar
  9069. * - Mac OS X Internet Account
  9070. * - Symbian
  9071. * - SymbianOS
  9072. * - Windows
  9073. * - Windows Mobile
  9074. * - Windows Phone
  9075. * - iOS
  9076. * - iOS Facebook Integration Account
  9077. * - iOS Facebook Social Sharing UI
  9078. * - webOS
  9079. * - Chrome OS
  9080. * - etc...
  9081. *
  9082. * An authoritative list can be found in the PHP `PlatformDetector` class and
  9083. * related classes in the same file (see calls to `new UserAgentPlatform`
  9084. * here: https://fburl.com/50729226).
  9085. *
  9086. * @note Function results are memoized
  9087. *
  9088. * @param {string} query Query of the form "Name [range expression]"
  9089. * @return {boolean}
  9090. */
  9091. isPlatform: function isPlatform(query) {
  9092. return compare$1(UserAgentData.platformName, UserAgentData.platformFullVersion, query, normalizePlatformVersion);
  9093. },
  9094. /**
  9095. * Check if the User Agent platform is a 32 or 64 bit architecture.
  9096. *
  9097. * @note Function results are memoized
  9098. *
  9099. * @param {string} query Query of the form "32" or "64".
  9100. * @return {boolean}
  9101. */
  9102. isPlatformArchitecture: function isPlatformArchitecture(query) {
  9103. return compare$1(UserAgentData.platformArchitecture, null, query);
  9104. }
  9105. };
  9106. var UserAgent_1 = mapObject_1(UserAgent, memoizeStringOnly_1);
  9107. function _classCallCheck$9(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9108. 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; }
  9109. 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; }
  9110. // In IE, spans with <br> tags render as two newlines. By rendering a span
  9111. // with only a newline character, we can be sure to render a single line.
  9112. var useNewlineChar = UserAgent_1.isBrowser('IE <= 11');
  9113. /**
  9114. * Check whether the node should be considered a newline.
  9115. */
  9116. function isNewline(node) {
  9117. return useNewlineChar ? node.textContent === '\n' : node.tagName === 'BR';
  9118. }
  9119. /**
  9120. * Placeholder elements for empty text content.
  9121. *
  9122. * What is this `data-text` attribute, anyway? It turns out that we need to
  9123. * put an attribute on the lowest-level text node in order to preserve correct
  9124. * spellcheck handling. If the <span> is naked, Chrome and Safari may do
  9125. * bizarre things to do the DOM -- split text nodes, create extra spans, etc.
  9126. * If the <span> has an attribute, this appears not to happen.
  9127. * See http://jsfiddle.net/9khdavod/ for the failure case, and
  9128. * http://jsfiddle.net/7pg143f7/ for the fixed case.
  9129. */
  9130. var NEWLINE_A = useNewlineChar ? React.createElement(
  9131. 'span',
  9132. { key: 'A', 'data-text': 'true' },
  9133. '\n'
  9134. ) : React.createElement('br', { key: 'A', 'data-text': 'true' });
  9135. var NEWLINE_B = useNewlineChar ? React.createElement(
  9136. 'span',
  9137. { key: 'B', 'data-text': 'true' },
  9138. '\n'
  9139. ) : React.createElement('br', { key: 'B', 'data-text': 'true' });
  9140. /**
  9141. * The lowest-level component in a `DraftEditor`, the text node component
  9142. * replaces the default React text node implementation. This allows us to
  9143. * perform custom handling of newline behavior and avoid re-rendering text
  9144. * nodes with DOM state that already matches the expectations of our immutable
  9145. * editor state.
  9146. */
  9147. var DraftEditorTextNode = function (_React$Component) {
  9148. _inherits$6(DraftEditorTextNode, _React$Component);
  9149. function DraftEditorTextNode(props) {
  9150. _classCallCheck$9(this, DraftEditorTextNode);
  9151. // By flipping this flag, we also keep flipping keys which forces
  9152. // React to remount this node every time it rerenders.
  9153. var _this = _possibleConstructorReturn$6(this, _React$Component.call(this, props));
  9154. _this._forceFlag = false;
  9155. return _this;
  9156. }
  9157. DraftEditorTextNode.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
  9158. var node = ReactDOM.findDOMNode(this);
  9159. var shouldBeNewline = nextProps.children === '';
  9160. !(node instanceof Element) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'node is not an Element') : invariant_1(false) : void 0;
  9161. if (shouldBeNewline) {
  9162. return !isNewline(node);
  9163. }
  9164. return node.textContent !== nextProps.children;
  9165. };
  9166. DraftEditorTextNode.prototype.componentDidMount = function componentDidMount() {
  9167. this._forceFlag = !this._forceFlag;
  9168. };
  9169. DraftEditorTextNode.prototype.componentDidUpdate = function componentDidUpdate() {
  9170. this._forceFlag = !this._forceFlag;
  9171. };
  9172. DraftEditorTextNode.prototype.render = function render() {
  9173. if (this.props.children === '') {
  9174. return this._forceFlag ? NEWLINE_A : NEWLINE_B;
  9175. }
  9176. return React.createElement(
  9177. 'span',
  9178. { key: this._forceFlag ? 'A' : 'B', 'data-text': 'true' },
  9179. this.props.children
  9180. );
  9181. };
  9182. return DraftEditorTextNode;
  9183. }(React.Component);
  9184. var DraftEditorTextNode_react = DraftEditorTextNode;
  9185. /**
  9186. * Copyright (c) 2013-present, Facebook, Inc.
  9187. * All rights reserved.
  9188. *
  9189. * This source code is licensed under the BSD-style license found in the
  9190. * LICENSE file in the root directory of this source tree. An additional grant
  9191. * of patent rights can be found in the PATENTS file in the same directory.
  9192. *
  9193. * @providesModule DraftJsDebugLogging
  9194. */
  9195. var DraftJsDebugLogging = {
  9196. logSelectionStateFailure: function logSelectionStateFailure() {
  9197. return null;
  9198. }
  9199. };
  9200. /**
  9201. * Copyright (c) 2013-present, Facebook, Inc.
  9202. *
  9203. * This source code is licensed under the MIT license found in the
  9204. * LICENSE file in the root directory of this source tree.
  9205. *
  9206. * @typechecks
  9207. */
  9208. /**
  9209. * @param {*} object The object to check.
  9210. * @return {boolean} Whether or not the object is a DOM node.
  9211. */
  9212. function isNode(object) {
  9213. var doc = object ? object.ownerDocument || object : document;
  9214. var defaultView = doc.defaultView || window;
  9215. return !!(object && (typeof defaultView.Node === 'function' ? object instanceof defaultView.Node : typeof object === 'object' && typeof object.nodeType === 'number' && typeof object.nodeName === 'string'));
  9216. }
  9217. var isNode_1 = isNode;
  9218. /**
  9219. * Copyright (c) 2013-present, Facebook, Inc.
  9220. *
  9221. * This source code is licensed under the MIT license found in the
  9222. * LICENSE file in the root directory of this source tree.
  9223. *
  9224. * @typechecks
  9225. */
  9226. /**
  9227. * @param {*} object The object to check.
  9228. * @return {boolean} Whether or not the object is a DOM text node.
  9229. */
  9230. function isTextNode(object) {
  9231. return isNode_1(object) && object.nodeType == 3;
  9232. }
  9233. var isTextNode_1 = isTextNode;
  9234. /**
  9235. * Copyright (c) 2013-present, Facebook, Inc.
  9236. *
  9237. * This source code is licensed under the MIT license found in the
  9238. * LICENSE file in the root directory of this source tree.
  9239. *
  9240. *
  9241. */
  9242. /*eslint-disable no-bitwise */
  9243. /**
  9244. * Checks if a given DOM node contains or is another DOM node.
  9245. */
  9246. function containsNode(outerNode, innerNode) {
  9247. if (!outerNode || !innerNode) {
  9248. return false;
  9249. } else if (outerNode === innerNode) {
  9250. return true;
  9251. } else if (isTextNode_1(outerNode)) {
  9252. return false;
  9253. } else if (isTextNode_1(innerNode)) {
  9254. return containsNode(outerNode, innerNode.parentNode);
  9255. } else if ('contains' in outerNode) {
  9256. return outerNode.contains(innerNode);
  9257. } else if (outerNode.compareDocumentPosition) {
  9258. return !!(outerNode.compareDocumentPosition(innerNode) & 16);
  9259. } else {
  9260. return false;
  9261. }
  9262. }
  9263. var containsNode_1 = containsNode;
  9264. /**
  9265. * Copyright (c) 2013-present, Facebook, Inc.
  9266. *
  9267. * This source code is licensed under the MIT license found in the
  9268. * LICENSE file in the root directory of this source tree.
  9269. *
  9270. * @typechecks
  9271. */
  9272. /* eslint-disable fb-www/typeof-undefined */
  9273. /**
  9274. * Same as document.activeElement but wraps in a try-catch block. In IE it is
  9275. * not safe to call document.activeElement if there is nothing focused.
  9276. *
  9277. * The activeElement will be null only if the document or document body is not
  9278. * yet defined.
  9279. *
  9280. * @param {?DOMDocument} doc Defaults to current document.
  9281. * @return {?DOMElement}
  9282. */
  9283. function getActiveElement(doc) /*?DOMElement*/{
  9284. doc = doc || (typeof document !== 'undefined' ? document : undefined);
  9285. if (typeof doc === 'undefined') {
  9286. return null;
  9287. }
  9288. try {
  9289. return doc.activeElement || doc.body;
  9290. } catch (e) {
  9291. return doc.body;
  9292. }
  9293. }
  9294. var getActiveElement_1 = getActiveElement;
  9295. function getAnonymizedDOM(node, getNodeLabels) {
  9296. if (!node) {
  9297. return '[empty]';
  9298. }
  9299. var anonymized = anonymizeTextWithin(node, getNodeLabels);
  9300. if (anonymized.nodeType === Node.TEXT_NODE) {
  9301. return anonymized.textContent;
  9302. }
  9303. !(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;
  9304. return anonymized.outerHTML;
  9305. }
  9306. function anonymizeTextWithin(node, getNodeLabels) {
  9307. var labels = getNodeLabels !== undefined ? getNodeLabels(node) : [];
  9308. if (node.nodeType === Node.TEXT_NODE) {
  9309. var length = node.textContent.length;
  9310. return document.createTextNode('[text ' + length + (labels.length ? ' | ' + labels.join(', ') : '') + ']');
  9311. }
  9312. var clone = node.cloneNode();
  9313. if (clone.nodeType === 1 && labels.length) {
  9314. clone.setAttribute('data-labels', labels.join(', '));
  9315. }
  9316. var childNodes = node.childNodes;
  9317. for (var ii = 0; ii < childNodes.length; ii++) {
  9318. clone.appendChild(anonymizeTextWithin(childNodes[ii], getNodeLabels));
  9319. }
  9320. return clone;
  9321. }
  9322. function getAnonymizedEditorDOM(node, getNodeLabels) {
  9323. // grabbing the DOM content of the Draft editor
  9324. var currentNode = node;
  9325. while (currentNode) {
  9326. if (currentNode instanceof Element && currentNode.hasAttribute('contenteditable')) {
  9327. // found the Draft editor container
  9328. return getAnonymizedDOM(currentNode, getNodeLabels);
  9329. } else {
  9330. currentNode = currentNode.parentNode;
  9331. }
  9332. }
  9333. return 'Could not find contentEditable parent of node';
  9334. }
  9335. function getNodeLength(node) {
  9336. return node.nodeValue === null ? node.childNodes.length : node.nodeValue.length;
  9337. }
  9338. /**
  9339. * In modern non-IE browsers, we can support both forward and backward
  9340. * selections.
  9341. *
  9342. * Note: IE10+ supports the Selection object, but it does not support
  9343. * the `extend` method, which means that even in modern IE, it's not possible
  9344. * to programatically create a backward selection. Thus, for all IE
  9345. * versions, we use the old IE API to create our selections.
  9346. */
  9347. function setDraftEditorSelection(selectionState, node, blockKey, nodeStart, nodeEnd) {
  9348. // It's possible that the editor has been removed from the DOM but
  9349. // our selection code doesn't know it yet. Forcing selection in
  9350. // this case may lead to errors, so just bail now.
  9351. if (!containsNode_1(document.documentElement, node)) {
  9352. return;
  9353. }
  9354. var selection = commonjsGlobal.getSelection();
  9355. var anchorKey = selectionState.getAnchorKey();
  9356. var anchorOffset = selectionState.getAnchorOffset();
  9357. var focusKey = selectionState.getFocusKey();
  9358. var focusOffset = selectionState.getFocusOffset();
  9359. var isBackward = selectionState.getIsBackward();
  9360. // IE doesn't support backward selection. Swap key/offset pairs.
  9361. if (!selection.extend && isBackward) {
  9362. var tempKey = anchorKey;
  9363. var tempOffset = anchorOffset;
  9364. anchorKey = focusKey;
  9365. anchorOffset = focusOffset;
  9366. focusKey = tempKey;
  9367. focusOffset = tempOffset;
  9368. isBackward = false;
  9369. }
  9370. var hasAnchor = anchorKey === blockKey && nodeStart <= anchorOffset && nodeEnd >= anchorOffset;
  9371. var hasFocus = focusKey === blockKey && nodeStart <= focusOffset && nodeEnd >= focusOffset;
  9372. // If the selection is entirely bound within this node, set the selection
  9373. // and be done.
  9374. if (hasAnchor && hasFocus) {
  9375. selection.removeAllRanges();
  9376. addPointToSelection(selection, node, anchorOffset - nodeStart, selectionState);
  9377. addFocusToSelection(selection, node, focusOffset - nodeStart, selectionState);
  9378. return;
  9379. }
  9380. if (!isBackward) {
  9381. // If the anchor is within this node, set the range start.
  9382. if (hasAnchor) {
  9383. selection.removeAllRanges();
  9384. addPointToSelection(selection, node, anchorOffset - nodeStart, selectionState);
  9385. }
  9386. // If the focus is within this node, we can assume that we have
  9387. // already set the appropriate start range on the selection, and
  9388. // can simply extend the selection.
  9389. if (hasFocus) {
  9390. addFocusToSelection(selection, node, focusOffset - nodeStart, selectionState);
  9391. }
  9392. } else {
  9393. // If this node has the focus, set the selection range to be a
  9394. // collapsed range beginning here. Later, when we encounter the anchor,
  9395. // we'll use this information to extend the selection.
  9396. if (hasFocus) {
  9397. selection.removeAllRanges();
  9398. addPointToSelection(selection, node, focusOffset - nodeStart, selectionState);
  9399. }
  9400. // If this node has the anchor, we may assume that the correct
  9401. // focus information is already stored on the selection object.
  9402. // We keep track of it, reset the selection range, and extend it
  9403. // back to the focus point.
  9404. if (hasAnchor) {
  9405. var storedFocusNode = selection.focusNode;
  9406. var storedFocusOffset = selection.focusOffset;
  9407. selection.removeAllRanges();
  9408. addPointToSelection(selection, node, anchorOffset - nodeStart, selectionState);
  9409. addFocusToSelection(selection, storedFocusNode, storedFocusOffset, selectionState);
  9410. }
  9411. }
  9412. }
  9413. /**
  9414. * Extend selection towards focus point.
  9415. */
  9416. function addFocusToSelection(selection, node, offset, selectionState) {
  9417. var activeElement = getActiveElement_1();
  9418. if (selection.extend && containsNode_1(activeElement, node)) {
  9419. // If `extend` is called while another element has focus, an error is
  9420. // thrown. We therefore disable `extend` if the active element is somewhere
  9421. // other than the node we are selecting. This should only occur in Firefox,
  9422. // since it is the only browser to support multiple selections.
  9423. // See https://bugzilla.mozilla.org/show_bug.cgi?id=921444.
  9424. // logging to catch bug that is being reported in t16250795
  9425. if (offset > getNodeLength(node)) {
  9426. // the call to 'selection.extend' is about to throw
  9427. DraftJsDebugLogging.logSelectionStateFailure({
  9428. anonymizedDom: getAnonymizedEditorDOM(node),
  9429. extraParams: JSON.stringify({ offset: offset }),
  9430. selectionState: JSON.stringify(selectionState.toJS())
  9431. });
  9432. }
  9433. // logging to catch bug that is being reported in t18110632
  9434. var nodeWasFocus = node === selection.focusNode;
  9435. try {
  9436. selection.extend(node, offset);
  9437. } catch (e) {
  9438. DraftJsDebugLogging.logSelectionStateFailure({
  9439. anonymizedDom: getAnonymizedEditorDOM(node, function (n) {
  9440. var labels = [];
  9441. if (n === activeElement) {
  9442. labels.push('active element');
  9443. }
  9444. if (n === selection.anchorNode) {
  9445. labels.push('selection anchor node');
  9446. }
  9447. if (n === selection.focusNode) {
  9448. labels.push('selection focus node');
  9449. }
  9450. return labels;
  9451. }),
  9452. extraParams: JSON.stringify({
  9453. activeElementName: activeElement ? activeElement.nodeName : null,
  9454. nodeIsFocus: node === selection.focusNode,
  9455. nodeWasFocus: nodeWasFocus,
  9456. selectionRangeCount: selection.rangeCount,
  9457. selectionAnchorNodeName: selection.anchorNode ? selection.anchorNode.nodeName : null,
  9458. selectionAnchorOffset: selection.anchorOffset,
  9459. selectionFocusNodeName: selection.focusNode ? selection.focusNode.nodeName : null,
  9460. selectionFocusOffset: selection.focusOffset,
  9461. message: e ? '' + e : null,
  9462. offset: offset
  9463. }, null, 2),
  9464. selectionState: JSON.stringify(selectionState.toJS(), null, 2)
  9465. });
  9466. // allow the error to be thrown -
  9467. // better than continuing in a broken state
  9468. throw e;
  9469. }
  9470. } else {
  9471. // IE doesn't support extend. This will mean no backward selection.
  9472. // Extract the existing selection range and add focus to it.
  9473. // Additionally, clone the selection range. IE11 throws an
  9474. // InvalidStateError when attempting to access selection properties
  9475. // after the range is detached.
  9476. var range = selection.getRangeAt(0);
  9477. range.setEnd(node, offset);
  9478. selection.addRange(range.cloneRange());
  9479. }
  9480. }
  9481. function addPointToSelection(selection, node, offset, selectionState) {
  9482. var range = document.createRange();
  9483. // logging to catch bug that is being reported in t16250795
  9484. if (offset > getNodeLength(node)) {
  9485. // in this case we know that the call to 'range.setStart' is about to throw
  9486. DraftJsDebugLogging.logSelectionStateFailure({
  9487. anonymizedDom: getAnonymizedEditorDOM(node),
  9488. extraParams: JSON.stringify({ offset: offset }),
  9489. selectionState: JSON.stringify(selectionState.toJS())
  9490. });
  9491. }
  9492. range.setStart(node, offset);
  9493. selection.addRange(range);
  9494. }
  9495. var setDraftEditorSelection_1 = setDraftEditorSelection;
  9496. function _classCallCheck$a(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9497. 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; }
  9498. 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; }
  9499. /**
  9500. * All leaf nodes in the editor are spans with single text nodes. Leaf
  9501. * elements are styled based on the merging of an optional custom style map
  9502. * and a default style map.
  9503. *
  9504. * `DraftEditorLeaf` also provides a wrapper for calling into the imperative
  9505. * DOM Selection API. In this way, top-level components can declaratively
  9506. * maintain the selection state.
  9507. */
  9508. var DraftEditorLeaf = function (_React$Component) {
  9509. _inherits$7(DraftEditorLeaf, _React$Component);
  9510. function DraftEditorLeaf() {
  9511. _classCallCheck$a(this, DraftEditorLeaf);
  9512. return _possibleConstructorReturn$7(this, _React$Component.apply(this, arguments));
  9513. }
  9514. DraftEditorLeaf.prototype._setSelection = function _setSelection() {
  9515. var selection = this.props.selection;
  9516. // If selection state is irrelevant to the parent block, no-op.
  9517. if (selection == null || !selection.getHasFocus()) {
  9518. return;
  9519. }
  9520. var _props = this.props,
  9521. block = _props.block,
  9522. start = _props.start,
  9523. text = _props.text;
  9524. var blockKey = block.getKey();
  9525. var end = start + text.length;
  9526. if (!selection.hasEdgeWithin(blockKey, start, end)) {
  9527. return;
  9528. }
  9529. // Determine the appropriate target node for selection. If the child
  9530. // is not a text node, it is a <br /> spacer. In this case, use the
  9531. // <span> itself as the selection target.
  9532. var node = ReactDOM.findDOMNode(this);
  9533. !node ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing node') : invariant_1(false) : void 0;
  9534. var child = node.firstChild;
  9535. !child ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing child') : invariant_1(false) : void 0;
  9536. var targetNode = void 0;
  9537. if (child.nodeType === Node.TEXT_NODE) {
  9538. targetNode = child;
  9539. } else if (child.tagName === 'BR') {
  9540. targetNode = node;
  9541. } else {
  9542. targetNode = child.firstChild;
  9543. !targetNode ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing targetNode') : invariant_1(false) : void 0;
  9544. }
  9545. setDraftEditorSelection_1(selection, targetNode, blockKey, start, end);
  9546. };
  9547. /**
  9548. * By making individual leaf instances aware of their context within
  9549. * the text of the editor, we can set our selection range more
  9550. * easily than we could in the non-React world.
  9551. *
  9552. * Note that this depends on our maintaining tight control over the
  9553. * DOM structure of the DraftEditor component. If leaves had multiple
  9554. * text nodes, this would be harder.
  9555. */
  9556. DraftEditorLeaf.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
  9557. var leafNode = ReactDOM.findDOMNode(this.leaf);
  9558. !leafNode ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing leafNode') : invariant_1(false) : void 0;
  9559. return leafNode.textContent !== nextProps.text || nextProps.styleSet !== this.props.styleSet || nextProps.forceSelection;
  9560. };
  9561. DraftEditorLeaf.prototype.componentDidUpdate = function componentDidUpdate() {
  9562. this._setSelection();
  9563. };
  9564. DraftEditorLeaf.prototype.componentDidMount = function componentDidMount() {
  9565. this._setSelection();
  9566. };
  9567. DraftEditorLeaf.prototype.render = function render() {
  9568. var _this2 = this;
  9569. var block = this.props.block;
  9570. var text = this.props.text;
  9571. // If the leaf is at the end of its block and ends in a soft newline, append
  9572. // an extra line feed character. Browsers collapse trailing newline
  9573. // characters, which leaves the cursor in the wrong place after a
  9574. // shift+enter. The extra character repairs this.
  9575. if (text.endsWith('\n') && this.props.isLast) {
  9576. text += '\n';
  9577. }
  9578. var _props2 = this.props,
  9579. customStyleMap = _props2.customStyleMap,
  9580. customStyleFn = _props2.customStyleFn,
  9581. offsetKey = _props2.offsetKey,
  9582. styleSet = _props2.styleSet;
  9583. var styleObj = styleSet.reduce(function (map, styleName) {
  9584. var mergedStyles = {};
  9585. var style = customStyleMap[styleName];
  9586. if (style !== undefined && map.textDecoration !== style.textDecoration) {
  9587. // .trim() is necessary for IE9/10/11 and Edge
  9588. mergedStyles.textDecoration = [map.textDecoration, style.textDecoration].join(' ').trim();
  9589. }
  9590. return objectAssign(map, style, mergedStyles);
  9591. }, {});
  9592. if (customStyleFn) {
  9593. var newStyles = customStyleFn(styleSet, block);
  9594. styleObj = objectAssign(styleObj, newStyles);
  9595. }
  9596. return React.createElement(
  9597. 'span',
  9598. {
  9599. 'data-offset-key': offsetKey,
  9600. ref: function ref(_ref) {
  9601. return _this2.leaf = _ref;
  9602. },
  9603. style: styleObj },
  9604. React.createElement(
  9605. DraftEditorTextNode_react,
  9606. null,
  9607. text
  9608. )
  9609. );
  9610. };
  9611. return DraftEditorLeaf;
  9612. }(React.Component);
  9613. var DraftEditorLeaf_react = DraftEditorLeaf;
  9614. /**
  9615. * Copyright (c) 2013-present, Facebook, Inc.
  9616. * All rights reserved.
  9617. *
  9618. * This source code is licensed under the BSD-style license found in the
  9619. * LICENSE file in the root directory of this source tree. An additional grant
  9620. * of patent rights can be found in the PATENTS file in the same directory.
  9621. *
  9622. * @providesModule DraftOffsetKey
  9623. * @format
  9624. *
  9625. */
  9626. var KEY_DELIMITER = '-';
  9627. var DraftOffsetKey = {
  9628. encode: function encode(blockKey, decoratorKey, leafKey) {
  9629. return blockKey + KEY_DELIMITER + decoratorKey + KEY_DELIMITER + leafKey;
  9630. },
  9631. decode: function decode(offsetKey) {
  9632. var _offsetKey$split = offsetKey.split(KEY_DELIMITER),
  9633. blockKey = _offsetKey$split[0],
  9634. decoratorKey = _offsetKey$split[1],
  9635. leafKey = _offsetKey$split[2];
  9636. return {
  9637. blockKey: blockKey,
  9638. decoratorKey: parseInt(decoratorKey, 10),
  9639. leafKey: parseInt(leafKey, 10)
  9640. };
  9641. }
  9642. };
  9643. var DraftOffsetKey_1 = DraftOffsetKey;
  9644. /**
  9645. * Copyright (c) 2013-present, Facebook, Inc.
  9646. *
  9647. * This source code is licensed under the MIT license found in the
  9648. * LICENSE file in the root directory of this source tree.
  9649. *
  9650. */
  9651. /**
  9652. * @param {DOMElement} element
  9653. * @param {DOMDocument} doc
  9654. * @return {boolean}
  9655. */
  9656. function _isViewportScrollElement(element, doc) {
  9657. return !!doc && (element === doc.documentElement || element === doc.body);
  9658. }
  9659. /**
  9660. * Scroll Module. This class contains 4 simple static functions
  9661. * to be used to access Element.scrollTop/scrollLeft properties.
  9662. * To solve the inconsistencies between browsers when either
  9663. * document.body or document.documentElement is supplied,
  9664. * below logic will be used to alleviate the issue:
  9665. *
  9666. * 1. If 'element' is either 'document.body' or 'document.documentElement,
  9667. * get whichever element's 'scroll{Top,Left}' is larger.
  9668. * 2. If 'element' is either 'document.body' or 'document.documentElement',
  9669. * set the 'scroll{Top,Left}' on both elements.
  9670. */
  9671. var Scroll = {
  9672. /**
  9673. * @param {DOMElement} element
  9674. * @return {number}
  9675. */
  9676. getTop: function getTop(element) {
  9677. var doc = element.ownerDocument;
  9678. return _isViewportScrollElement(element, doc) ?
  9679. // In practice, they will either both have the same value,
  9680. // or one will be zero and the other will be the scroll position
  9681. // of the viewport. So we can use `X || Y` instead of `Math.max(X, Y)`
  9682. doc.body.scrollTop || doc.documentElement.scrollTop : element.scrollTop;
  9683. },
  9684. /**
  9685. * @param {DOMElement} element
  9686. * @param {number} newTop
  9687. */
  9688. setTop: function setTop(element, newTop) {
  9689. var doc = element.ownerDocument;
  9690. if (_isViewportScrollElement(element, doc)) {
  9691. doc.body.scrollTop = doc.documentElement.scrollTop = newTop;
  9692. } else {
  9693. element.scrollTop = newTop;
  9694. }
  9695. },
  9696. /**
  9697. * @param {DOMElement} element
  9698. * @return {number}
  9699. */
  9700. getLeft: function getLeft(element) {
  9701. var doc = element.ownerDocument;
  9702. return _isViewportScrollElement(element, doc) ? doc.body.scrollLeft || doc.documentElement.scrollLeft : element.scrollLeft;
  9703. },
  9704. /**
  9705. * @param {DOMElement} element
  9706. * @param {number} newLeft
  9707. */
  9708. setLeft: function setLeft(element, newLeft) {
  9709. var doc = element.ownerDocument;
  9710. if (_isViewportScrollElement(element, doc)) {
  9711. doc.body.scrollLeft = doc.documentElement.scrollLeft = newLeft;
  9712. } else {
  9713. element.scrollLeft = newLeft;
  9714. }
  9715. }
  9716. };
  9717. var Scroll_1 = Scroll;
  9718. /**
  9719. * Copyright (c) 2013-present, Facebook, Inc.
  9720. *
  9721. * This source code is licensed under the MIT license found in the
  9722. * LICENSE file in the root directory of this source tree.
  9723. *
  9724. * @typechecks
  9725. */
  9726. var _hyphenPattern = /-(.)/g;
  9727. /**
  9728. * Camelcases a hyphenated string, for example:
  9729. *
  9730. * > camelize('background-color')
  9731. * < "backgroundColor"
  9732. *
  9733. * @param {string} string
  9734. * @return {string}
  9735. */
  9736. function camelize(string) {
  9737. return string.replace(_hyphenPattern, function (_, character) {
  9738. return character.toUpperCase();
  9739. });
  9740. }
  9741. var camelize_1 = camelize;
  9742. /**
  9743. * Copyright (c) 2013-present, Facebook, Inc.
  9744. *
  9745. * This source code is licensed under the MIT license found in the
  9746. * LICENSE file in the root directory of this source tree.
  9747. *
  9748. * @typechecks
  9749. */
  9750. var _uppercasePattern = /([A-Z])/g;
  9751. /**
  9752. * Hyphenates a camelcased string, for example:
  9753. *
  9754. * > hyphenate('backgroundColor')
  9755. * < "background-color"
  9756. *
  9757. * For CSS style names, use `hyphenateStyleName` instead which works properly
  9758. * with all vendor prefixes, including `ms`.
  9759. *
  9760. * @param {string} string
  9761. * @return {string}
  9762. */
  9763. function hyphenate(string) {
  9764. return string.replace(_uppercasePattern, '-$1').toLowerCase();
  9765. }
  9766. var hyphenate_1 = hyphenate;
  9767. /**
  9768. * Copyright (c) 2013-present, Facebook, Inc.
  9769. *
  9770. * This source code is licensed under the MIT license found in the
  9771. * LICENSE file in the root directory of this source tree.
  9772. *
  9773. * @typechecks
  9774. */
  9775. function asString(value) /*?string*/{
  9776. return value == null ? value : String(value);
  9777. }
  9778. function getStyleProperty( /*DOMNode*/node, /*string*/name) /*?string*/{
  9779. var computedStyle = void 0;
  9780. // W3C Standard
  9781. if (window.getComputedStyle) {
  9782. // In certain cases such as within an iframe in FF3, this returns null.
  9783. computedStyle = window.getComputedStyle(node, null);
  9784. if (computedStyle) {
  9785. return asString(computedStyle.getPropertyValue(hyphenate_1(name)));
  9786. }
  9787. }
  9788. // Safari
  9789. if (document.defaultView && document.defaultView.getComputedStyle) {
  9790. computedStyle = document.defaultView.getComputedStyle(node, null);
  9791. // A Safari bug causes this to return null for `display: none` elements.
  9792. if (computedStyle) {
  9793. return asString(computedStyle.getPropertyValue(hyphenate_1(name)));
  9794. }
  9795. if (name === 'display') {
  9796. return 'none';
  9797. }
  9798. }
  9799. // Internet Explorer
  9800. if (node.currentStyle) {
  9801. if (name === 'float') {
  9802. return asString(node.currentStyle.cssFloat || node.currentStyle.styleFloat);
  9803. }
  9804. return asString(node.currentStyle[camelize_1(name)]);
  9805. }
  9806. return asString(node.style && node.style[camelize_1(name)]);
  9807. }
  9808. var getStyleProperty_1 = getStyleProperty;
  9809. /**
  9810. * Copyright (c) 2013-present, Facebook, Inc.
  9811. *
  9812. * This source code is licensed under the MIT license found in the
  9813. * LICENSE file in the root directory of this source tree.
  9814. *
  9815. * @typechecks
  9816. */
  9817. /**
  9818. * @param {DOMNode} element [description]
  9819. * @param {string} name Overflow style property name.
  9820. * @return {boolean} True if the supplied ndoe is scrollable.
  9821. */
  9822. function _isNodeScrollable(element, name) {
  9823. var overflow = Style.get(element, name);
  9824. return overflow === 'auto' || overflow === 'scroll';
  9825. }
  9826. /**
  9827. * Utilities for querying and mutating style properties.
  9828. */
  9829. var Style = {
  9830. /**
  9831. * Gets the style property for the supplied node. This will return either the
  9832. * computed style, if available, or the declared style.
  9833. *
  9834. * @param {DOMNode} node
  9835. * @param {string} name Style property name.
  9836. * @return {?string} Style property value.
  9837. */
  9838. get: getStyleProperty_1,
  9839. /**
  9840. * Determines the nearest ancestor of a node that is scrollable.
  9841. *
  9842. * NOTE: This can be expensive if used repeatedly or on a node nested deeply.
  9843. *
  9844. * @param {?DOMNode} node Node from which to start searching.
  9845. * @return {?DOMWindow|DOMElement} Scroll parent of the supplied node.
  9846. */
  9847. getScrollParent: function getScrollParent(node) {
  9848. if (!node) {
  9849. return null;
  9850. }
  9851. var ownerDocument = node.ownerDocument;
  9852. while (node && node !== ownerDocument.body) {
  9853. if (_isNodeScrollable(node, 'overflow') || _isNodeScrollable(node, 'overflowY') || _isNodeScrollable(node, 'overflowX')) {
  9854. return node;
  9855. }
  9856. node = node.parentNode;
  9857. }
  9858. return ownerDocument.defaultView || ownerDocument.parentWindow;
  9859. }
  9860. };
  9861. var Style_1 = Style;
  9862. /**
  9863. * Copyright (c) 2013-present, Facebook, Inc.
  9864. *
  9865. * This source code is licensed under the MIT license found in the
  9866. * LICENSE file in the root directory of this source tree.
  9867. *
  9868. * @typechecks
  9869. */
  9870. /**
  9871. * Gets an element's bounding rect in pixels relative to the viewport.
  9872. *
  9873. * @param {DOMElement} elem
  9874. * @return {object}
  9875. */
  9876. function getElementRect(elem) {
  9877. var docElem = elem.ownerDocument.documentElement;
  9878. // FF 2, Safari 3 and Opera 9.5- do not support getBoundingClientRect().
  9879. // IE9- will throw if the element is not in the document.
  9880. if (!('getBoundingClientRect' in elem) || !containsNode_1(docElem, elem)) {
  9881. return {
  9882. left: 0,
  9883. right: 0,
  9884. top: 0,
  9885. bottom: 0
  9886. };
  9887. }
  9888. // Subtracts clientTop/Left because IE8- added a 2px border to the
  9889. // <html> element (see http://fburl.com/1493213). IE 7 in
  9890. // Quicksmode does not report clientLeft/clientTop so there
  9891. // will be an unaccounted offset of 2px when in quirksmode
  9892. var rect = elem.getBoundingClientRect();
  9893. return {
  9894. left: Math.round(rect.left) - docElem.clientLeft,
  9895. right: Math.round(rect.right) - docElem.clientLeft,
  9896. top: Math.round(rect.top) - docElem.clientTop,
  9897. bottom: Math.round(rect.bottom) - docElem.clientTop
  9898. };
  9899. }
  9900. var getElementRect_1 = getElementRect;
  9901. /**
  9902. * Copyright (c) 2013-present, Facebook, Inc.
  9903. *
  9904. * This source code is licensed under the MIT license found in the
  9905. * LICENSE file in the root directory of this source tree.
  9906. *
  9907. * @typechecks
  9908. */
  9909. /**
  9910. * Gets an element's position in pixels relative to the viewport. The returned
  9911. * object represents the position of the element's top left corner.
  9912. *
  9913. * @param {DOMElement} element
  9914. * @return {object}
  9915. */
  9916. function getElementPosition(element) {
  9917. var rect = getElementRect_1(element);
  9918. return {
  9919. x: rect.left,
  9920. y: rect.top,
  9921. width: rect.right - rect.left,
  9922. height: rect.bottom - rect.top
  9923. };
  9924. }
  9925. var getElementPosition_1 = getElementPosition;
  9926. /**
  9927. * Copyright (c) 2013-present, Facebook, Inc.
  9928. *
  9929. * This source code is licensed under the MIT license found in the
  9930. * LICENSE file in the root directory of this source tree.
  9931. *
  9932. * @typechecks
  9933. */
  9934. var isWebkit = typeof navigator !== 'undefined' && navigator.userAgent.indexOf('AppleWebKit') > -1;
  9935. /**
  9936. * Gets the element with the document scroll properties such as `scrollLeft` and
  9937. * `scrollHeight`. This may differ across different browsers.
  9938. *
  9939. * NOTE: The return value can be null if the DOM is not yet ready.
  9940. *
  9941. * @param {?DOMDocument} doc Defaults to current document.
  9942. * @return {?DOMElement}
  9943. */
  9944. function getDocumentScrollElement(doc) {
  9945. doc = doc || document;
  9946. if (doc.scrollingElement) {
  9947. return doc.scrollingElement;
  9948. }
  9949. return !isWebkit && doc.compatMode === 'CSS1Compat' ? doc.documentElement : doc.body;
  9950. }
  9951. var getDocumentScrollElement_1 = getDocumentScrollElement;
  9952. /**
  9953. * Copyright (c) 2013-present, Facebook, Inc.
  9954. *
  9955. * This source code is licensed under the MIT license found in the
  9956. * LICENSE file in the root directory of this source tree.
  9957. *
  9958. * @typechecks
  9959. */
  9960. /**
  9961. * Gets the scroll position of the supplied element or window.
  9962. *
  9963. * The return values are unbounded, unlike `getScrollPosition`. This means they
  9964. * may be negative or exceed the element boundaries (which is possible using
  9965. * inertial scrolling).
  9966. *
  9967. * @param {DOMWindow|DOMElement} scrollable
  9968. * @return {object} Map with `x` and `y` keys.
  9969. */
  9970. function getUnboundedScrollPosition(scrollable) {
  9971. if (scrollable.Window && scrollable instanceof scrollable.Window) {
  9972. return {
  9973. x: scrollable.pageXOffset || scrollable.document.documentElement.scrollLeft,
  9974. y: scrollable.pageYOffset || scrollable.document.documentElement.scrollTop
  9975. };
  9976. }
  9977. return {
  9978. x: scrollable.scrollLeft,
  9979. y: scrollable.scrollTop
  9980. };
  9981. }
  9982. var getUnboundedScrollPosition_1 = getUnboundedScrollPosition;
  9983. /**
  9984. * Gets the scroll position of the supplied element or window.
  9985. *
  9986. * The return values are bounded. This means that if the scroll position is
  9987. * negative or exceeds the element boundaries (which is possible using inertial
  9988. * scrolling), you will get zero or the maximum scroll position, respectively.
  9989. *
  9990. * If you need the unbound scroll position, use `getUnboundedScrollPosition`.
  9991. *
  9992. * @param {DOMWindow|DOMElement} scrollable
  9993. * @return {object} Map with `x` and `y` keys.
  9994. */
  9995. function getScrollPosition(scrollable) {
  9996. var documentScrollElement = getDocumentScrollElement_1(scrollable.ownerDocument || scrollable.document);
  9997. if (scrollable.Window && scrollable instanceof scrollable.Window) {
  9998. scrollable = documentScrollElement;
  9999. }
  10000. var scrollPosition = getUnboundedScrollPosition_1(scrollable);
  10001. var viewport = scrollable === documentScrollElement ? scrollable.ownerDocument.documentElement : scrollable;
  10002. var xMax = scrollable.scrollWidth - viewport.clientWidth;
  10003. var yMax = scrollable.scrollHeight - viewport.clientHeight;
  10004. scrollPosition.x = Math.max(0, Math.min(scrollPosition.x, xMax));
  10005. scrollPosition.y = Math.max(0, Math.min(scrollPosition.y, yMax));
  10006. return scrollPosition;
  10007. }
  10008. var getScrollPosition_1 = getScrollPosition;
  10009. function getViewportWidth() {
  10010. var width = void 0;
  10011. if (document.documentElement) {
  10012. width = document.documentElement.clientWidth;
  10013. }
  10014. if (!width && document.body) {
  10015. width = document.body.clientWidth;
  10016. }
  10017. return width || 0;
  10018. } /**
  10019. * Copyright (c) 2013-present, Facebook, Inc.
  10020. *
  10021. * This source code is licensed under the MIT license found in the
  10022. * LICENSE file in the root directory of this source tree.
  10023. *
  10024. *
  10025. * @typechecks
  10026. */
  10027. function getViewportHeight() {
  10028. var height = void 0;
  10029. if (document.documentElement) {
  10030. height = document.documentElement.clientHeight;
  10031. }
  10032. if (!height && document.body) {
  10033. height = document.body.clientHeight;
  10034. }
  10035. return height || 0;
  10036. }
  10037. /**
  10038. * Gets the viewport dimensions including any scrollbars.
  10039. */
  10040. function getViewportDimensions() {
  10041. return {
  10042. width: window.innerWidth || getViewportWidth(),
  10043. height: window.innerHeight || getViewportHeight()
  10044. };
  10045. }
  10046. /**
  10047. * Gets the viewport dimensions excluding any scrollbars.
  10048. */
  10049. getViewportDimensions.withoutScrollbars = function () {
  10050. return {
  10051. width: getViewportWidth(),
  10052. height: getViewportHeight()
  10053. };
  10054. };
  10055. var getViewportDimensions_1 = getViewportDimensions;
  10056. 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; };
  10057. function _classCallCheck$b(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10058. 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; }
  10059. 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; }
  10060. var SCROLL_BUFFER = 10;
  10061. /**
  10062. * Return whether a block overlaps with either edge of the `SelectionState`.
  10063. */
  10064. var isBlockOnSelectionEdge = function isBlockOnSelectionEdge(selection, key) {
  10065. return selection.getAnchorKey() === key || selection.getFocusKey() === key;
  10066. };
  10067. /**
  10068. * The default block renderer for a `DraftEditor` component.
  10069. *
  10070. * A `DraftEditorBlock` is able to render a given `ContentBlock` to its
  10071. * appropriate decorator and inline style components.
  10072. */
  10073. var DraftEditorBlock = function (_React$Component) {
  10074. _inherits$8(DraftEditorBlock, _React$Component);
  10075. function DraftEditorBlock() {
  10076. _classCallCheck$b(this, DraftEditorBlock);
  10077. return _possibleConstructorReturn$8(this, _React$Component.apply(this, arguments));
  10078. }
  10079. DraftEditorBlock.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
  10080. return this.props.block !== nextProps.block || this.props.tree !== nextProps.tree || this.props.direction !== nextProps.direction || isBlockOnSelectionEdge(nextProps.selection, nextProps.block.getKey()) && nextProps.forceSelection;
  10081. };
  10082. /**
  10083. * When a block is mounted and overlaps the selection state, we need to make
  10084. * sure that the cursor is visible to match native behavior. This may not
  10085. * be the case if the user has pressed `RETURN` or pasted some content, since
  10086. * programatically creating these new blocks and setting the DOM selection
  10087. * will miss out on the browser natively scrolling to that position.
  10088. *
  10089. * To replicate native behavior, if the block overlaps the selection state
  10090. * on mount, force the scroll position. Check the scroll state of the scroll
  10091. * parent, and adjust it to align the entire block to the bottom of the
  10092. * scroll parent.
  10093. */
  10094. DraftEditorBlock.prototype.componentDidMount = function componentDidMount() {
  10095. var selection = this.props.selection;
  10096. var endKey = selection.getEndKey();
  10097. if (!selection.getHasFocus() || endKey !== this.props.block.getKey()) {
  10098. return;
  10099. }
  10100. var blockNode = ReactDOM.findDOMNode(this);
  10101. var scrollParent = Style_1.getScrollParent(blockNode);
  10102. var scrollPosition = getScrollPosition_1(scrollParent);
  10103. var scrollDelta = void 0;
  10104. if (scrollParent === window) {
  10105. var nodePosition = getElementPosition_1(blockNode);
  10106. var nodeBottom = nodePosition.y + nodePosition.height;
  10107. var viewportHeight = getViewportDimensions_1().height;
  10108. scrollDelta = nodeBottom - viewportHeight;
  10109. if (scrollDelta > 0) {
  10110. window.scrollTo(scrollPosition.x, scrollPosition.y + scrollDelta + SCROLL_BUFFER);
  10111. }
  10112. } else {
  10113. !(blockNode instanceof HTMLElement) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'blockNode is not an HTMLElement') : invariant_1(false) : void 0;
  10114. var blockBottom = blockNode.offsetHeight + blockNode.offsetTop;
  10115. var scrollBottom = scrollParent.offsetHeight + scrollPosition.y;
  10116. scrollDelta = blockBottom - scrollBottom;
  10117. if (scrollDelta > 0) {
  10118. Scroll_1.setTop(scrollParent, Scroll_1.getTop(scrollParent) + scrollDelta + SCROLL_BUFFER);
  10119. }
  10120. }
  10121. };
  10122. DraftEditorBlock.prototype._renderChildren = function _renderChildren() {
  10123. var _this2 = this;
  10124. var block = this.props.block;
  10125. var blockKey = block.getKey();
  10126. var text = block.getText();
  10127. var lastLeafSet = this.props.tree.size - 1;
  10128. var hasSelection = isBlockOnSelectionEdge(this.props.selection, blockKey);
  10129. return this.props.tree.map(function (leafSet, ii) {
  10130. var leavesForLeafSet = leafSet.get('leaves');
  10131. var lastLeaf = leavesForLeafSet.size - 1;
  10132. var leaves = leavesForLeafSet.map(function (leaf, jj) {
  10133. var offsetKey = DraftOffsetKey_1.encode(blockKey, ii, jj);
  10134. var start = leaf.get('start');
  10135. var end = leaf.get('end');
  10136. return React.createElement(DraftEditorLeaf_react, {
  10137. key: offsetKey,
  10138. offsetKey: offsetKey,
  10139. block: block,
  10140. start: start,
  10141. selection: hasSelection ? _this2.props.selection : null,
  10142. forceSelection: _this2.props.forceSelection,
  10143. text: text.slice(start, end),
  10144. styleSet: block.getInlineStyleAt(start),
  10145. customStyleMap: _this2.props.customStyleMap,
  10146. customStyleFn: _this2.props.customStyleFn,
  10147. isLast: ii === lastLeafSet && jj === lastLeaf
  10148. });
  10149. }).toArray();
  10150. var decoratorKey = leafSet.get('decoratorKey');
  10151. if (decoratorKey == null) {
  10152. return leaves;
  10153. }
  10154. if (!_this2.props.decorator) {
  10155. return leaves;
  10156. }
  10157. var decorator = nullthrows_1(_this2.props.decorator);
  10158. var DecoratorComponent = decorator.getComponentForKey(decoratorKey);
  10159. if (!DecoratorComponent) {
  10160. return leaves;
  10161. }
  10162. var decoratorProps = decorator.getPropsForKey(decoratorKey);
  10163. var decoratorOffsetKey = DraftOffsetKey_1.encode(blockKey, ii, 0);
  10164. var decoratedText = text.slice(leavesForLeafSet.first().get('start'), leavesForLeafSet.last().get('end'));
  10165. // Resetting dir to the same value on a child node makes Chrome/Firefox
  10166. // confused on cursor movement. See http://jsfiddle.net/d157kLck/3/
  10167. var dir = UnicodeBidiDirection_1.getHTMLDirIfDifferent(UnicodeBidi_1.getDirection(decoratedText), _this2.props.direction);
  10168. return React.createElement(
  10169. DecoratorComponent,
  10170. _extends$2({}, decoratorProps, {
  10171. contentState: _this2.props.contentState,
  10172. decoratedText: decoratedText,
  10173. dir: dir,
  10174. key: decoratorOffsetKey,
  10175. entityKey: block.getEntityAt(leafSet.get('start')),
  10176. offsetKey: decoratorOffsetKey }),
  10177. leaves
  10178. );
  10179. }).toArray();
  10180. };
  10181. DraftEditorBlock.prototype.render = function render() {
  10182. var _props = this.props,
  10183. direction = _props.direction,
  10184. offsetKey = _props.offsetKey;
  10185. var className = cx_1({
  10186. 'public/DraftStyleDefault/block': true,
  10187. 'public/DraftStyleDefault/ltr': direction === 'LTR',
  10188. 'public/DraftStyleDefault/rtl': direction === 'RTL'
  10189. });
  10190. return React.createElement(
  10191. 'div',
  10192. { 'data-offset-key': offsetKey, className: className },
  10193. this._renderChildren()
  10194. );
  10195. };
  10196. return DraftEditorBlock;
  10197. }(React.Component);
  10198. var DraftEditorBlock_react = DraftEditorBlock;
  10199. /**
  10200. * Copyright (c) 2013-present, Facebook, Inc.
  10201. *
  10202. * This source code is licensed under the MIT license found in the
  10203. * LICENSE file in the root directory of this source tree.
  10204. *
  10205. * @typechecks static-only
  10206. */
  10207. /**
  10208. * Combines multiple className strings into one.
  10209. * http://jsperf.com/joinclasses-args-vs-array
  10210. *
  10211. * @param {...?string} className
  10212. * @return {string}
  10213. */
  10214. function joinClasses(className /*, ... */) {
  10215. if (!className) {
  10216. className = '';
  10217. }
  10218. var nextClass = void 0;
  10219. var argLength = arguments.length;
  10220. if (argLength > 1) {
  10221. for (var ii = 1; ii < argLength; ii++) {
  10222. nextClass = arguments[ii];
  10223. if (nextClass) {
  10224. className = (className ? className + ' ' : '') + nextClass;
  10225. }
  10226. }
  10227. }
  10228. return className;
  10229. }
  10230. var joinClasses_1 = joinClasses;
  10231. 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; };
  10232. function _classCallCheck$c(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10233. 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; }
  10234. 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; }
  10235. /**
  10236. * Provide default styling for list items. This way, lists will be styled with
  10237. * proper counters and indentation even if the caller does not specify
  10238. * their own styling at all. If more than five levels of nesting are needed,
  10239. * the necessary CSS classes can be provided via `blockStyleFn` configuration.
  10240. */
  10241. var getListItemClasses = function getListItemClasses(type, depth, shouldResetCount, direction) {
  10242. return cx_1({
  10243. 'public/DraftStyleDefault/unorderedListItem': type === 'unordered-list-item',
  10244. 'public/DraftStyleDefault/orderedListItem': type === 'ordered-list-item',
  10245. 'public/DraftStyleDefault/reset': shouldResetCount,
  10246. 'public/DraftStyleDefault/depth0': depth === 0,
  10247. 'public/DraftStyleDefault/depth1': depth === 1,
  10248. 'public/DraftStyleDefault/depth2': depth === 2,
  10249. 'public/DraftStyleDefault/depth3': depth === 3,
  10250. 'public/DraftStyleDefault/depth4': depth === 4,
  10251. 'public/DraftStyleDefault/listLTR': direction === 'LTR',
  10252. 'public/DraftStyleDefault/listRTL': direction === 'RTL'
  10253. });
  10254. };
  10255. /**
  10256. * `DraftEditorContents` is the container component for all block components
  10257. * rendered for a `DraftEditor`. It is optimized to aggressively avoid
  10258. * re-rendering blocks whenever possible.
  10259. *
  10260. * This component is separate from `DraftEditor` because certain props
  10261. * (for instance, ARIA props) must be allowed to update without affecting
  10262. * the contents of the editor.
  10263. */
  10264. var DraftEditorContents = function (_React$Component) {
  10265. _inherits$9(DraftEditorContents, _React$Component);
  10266. function DraftEditorContents() {
  10267. _classCallCheck$c(this, DraftEditorContents);
  10268. return _possibleConstructorReturn$9(this, _React$Component.apply(this, arguments));
  10269. }
  10270. DraftEditorContents.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
  10271. var prevEditorState = this.props.editorState;
  10272. var nextEditorState = nextProps.editorState;
  10273. var prevDirectionMap = prevEditorState.getDirectionMap();
  10274. var nextDirectionMap = nextEditorState.getDirectionMap();
  10275. // Text direction has changed for one or more blocks. We must re-render.
  10276. if (prevDirectionMap !== nextDirectionMap) {
  10277. return true;
  10278. }
  10279. var didHaveFocus = prevEditorState.getSelection().getHasFocus();
  10280. var nowHasFocus = nextEditorState.getSelection().getHasFocus();
  10281. if (didHaveFocus !== nowHasFocus) {
  10282. return true;
  10283. }
  10284. var nextNativeContent = nextEditorState.getNativelyRenderedContent();
  10285. var wasComposing = prevEditorState.isInCompositionMode();
  10286. var nowComposing = nextEditorState.isInCompositionMode();
  10287. // If the state is unchanged or we're currently rendering a natively
  10288. // rendered state, there's nothing new to be done.
  10289. if (prevEditorState === nextEditorState || nextNativeContent !== null && nextEditorState.getCurrentContent() === nextNativeContent || wasComposing && nowComposing) {
  10290. return false;
  10291. }
  10292. var prevContent = prevEditorState.getCurrentContent();
  10293. var nextContent = nextEditorState.getCurrentContent();
  10294. var prevDecorator = prevEditorState.getDecorator();
  10295. var nextDecorator = nextEditorState.getDecorator();
  10296. return wasComposing !== nowComposing || prevContent !== nextContent || prevDecorator !== nextDecorator || nextEditorState.mustForceSelection();
  10297. };
  10298. DraftEditorContents.prototype.render = function render() {
  10299. var _props = this.props,
  10300. blockRenderMap = _props.blockRenderMap,
  10301. blockRendererFn = _props.blockRendererFn,
  10302. blockStyleFn = _props.blockStyleFn,
  10303. customStyleMap = _props.customStyleMap,
  10304. customStyleFn = _props.customStyleFn,
  10305. editorState = _props.editorState,
  10306. editorKey = _props.editorKey,
  10307. textDirectionality = _props.textDirectionality;
  10308. var content = editorState.getCurrentContent();
  10309. var selection = editorState.getSelection();
  10310. var forceSelection = editorState.mustForceSelection();
  10311. var decorator = editorState.getDecorator();
  10312. var directionMap = nullthrows_1(editorState.getDirectionMap());
  10313. var blocksAsArray = content.getBlocksAsArray();
  10314. var processedBlocks = [];
  10315. var currentDepth = null;
  10316. var lastWrapperTemplate = null;
  10317. for (var ii = 0; ii < blocksAsArray.length; ii++) {
  10318. var _block = blocksAsArray[ii];
  10319. var key = _block.getKey();
  10320. var blockType = _block.getType();
  10321. var customRenderer = blockRendererFn(_block);
  10322. var CustomComponent = void 0,
  10323. customProps = void 0,
  10324. customEditable = void 0;
  10325. if (customRenderer) {
  10326. CustomComponent = customRenderer.component;
  10327. customProps = customRenderer.props;
  10328. customEditable = customRenderer.editable;
  10329. }
  10330. var direction = textDirectionality ? textDirectionality : directionMap.get(key);
  10331. var offsetKey = DraftOffsetKey_1.encode(key, 0, 0);
  10332. var componentProps = {
  10333. contentState: content,
  10334. block: _block,
  10335. blockProps: customProps,
  10336. blockStyleFn: blockStyleFn,
  10337. customStyleMap: customStyleMap,
  10338. customStyleFn: customStyleFn,
  10339. decorator: decorator,
  10340. direction: direction,
  10341. forceSelection: forceSelection,
  10342. key: key,
  10343. offsetKey: offsetKey,
  10344. selection: selection,
  10345. tree: editorState.getBlockTree(key)
  10346. };
  10347. var configForType = blockRenderMap.get(blockType) || blockRenderMap.get('unstyled');
  10348. var wrapperTemplate = configForType.wrapper;
  10349. var Element = configForType.element || blockRenderMap.get('unstyled').element;
  10350. var depth = _block.getDepth();
  10351. var className = '';
  10352. if (blockStyleFn) {
  10353. className = blockStyleFn(_block);
  10354. }
  10355. // List items are special snowflakes, since we handle nesting and
  10356. // counters manually.
  10357. if (Element === 'li') {
  10358. var shouldResetCount = lastWrapperTemplate !== wrapperTemplate || currentDepth === null || depth > currentDepth;
  10359. className = joinClasses_1(className, getListItemClasses(blockType, depth, shouldResetCount, direction));
  10360. }
  10361. var Component = CustomComponent || DraftEditorBlock_react;
  10362. var childProps = {
  10363. className: className,
  10364. 'data-block': true,
  10365. 'data-editor': editorKey,
  10366. 'data-offset-key': offsetKey,
  10367. key: key
  10368. };
  10369. if (customEditable !== undefined) {
  10370. childProps = _extends$3({}, childProps, {
  10371. contentEditable: customEditable,
  10372. suppressContentEditableWarning: true
  10373. });
  10374. }
  10375. var child = React.createElement(Element, childProps, React.createElement(Component, componentProps));
  10376. processedBlocks.push({
  10377. block: child,
  10378. wrapperTemplate: wrapperTemplate,
  10379. key: key,
  10380. offsetKey: offsetKey
  10381. });
  10382. if (wrapperTemplate) {
  10383. currentDepth = _block.getDepth();
  10384. } else {
  10385. currentDepth = null;
  10386. }
  10387. lastWrapperTemplate = wrapperTemplate;
  10388. }
  10389. // Group contiguous runs of blocks that have the same wrapperTemplate
  10390. var outputBlocks = [];
  10391. for (var _ii = 0; _ii < processedBlocks.length;) {
  10392. var info = processedBlocks[_ii];
  10393. if (info.wrapperTemplate) {
  10394. var blocks = [];
  10395. do {
  10396. blocks.push(processedBlocks[_ii].block);
  10397. _ii++;
  10398. } while (_ii < processedBlocks.length && processedBlocks[_ii].wrapperTemplate === info.wrapperTemplate);
  10399. var wrapperElement = React.cloneElement(info.wrapperTemplate, {
  10400. key: info.key + '-wrap',
  10401. 'data-offset-key': info.offsetKey
  10402. }, blocks);
  10403. outputBlocks.push(wrapperElement);
  10404. } else {
  10405. outputBlocks.push(info.block);
  10406. _ii++;
  10407. }
  10408. }
  10409. return React.createElement(
  10410. 'div',
  10411. { 'data-contents': 'true' },
  10412. outputBlocks
  10413. );
  10414. };
  10415. return DraftEditorContents;
  10416. }(React.Component);
  10417. var DraftEditorContentsCore_react = DraftEditorContents;
  10418. var DraftEditorContents_react = DraftEditorContentsCore_react;
  10419. /**
  10420. * Copyright (c) 2013-present, Facebook, Inc.
  10421. *
  10422. * This source code is licensed under the MIT license found in the
  10423. * LICENSE file in the root directory of this source tree.
  10424. *
  10425. */
  10426. var PhotosMimeType = {
  10427. isImage: function isImage(mimeString) {
  10428. return getParts(mimeString)[0] === 'image';
  10429. },
  10430. isJpeg: function isJpeg(mimeString) {
  10431. var parts = getParts(mimeString);
  10432. return PhotosMimeType.isImage(mimeString) && (
  10433. // see http://fburl.com/10972194
  10434. parts[1] === 'jpeg' || parts[1] === 'pjpeg');
  10435. }
  10436. };
  10437. function getParts(mimeString) {
  10438. return mimeString.split('/');
  10439. }
  10440. var PhotosMimeType_1 = PhotosMimeType;
  10441. /**
  10442. * Copyright (c) 2013-present, Facebook, Inc.
  10443. *
  10444. * This source code is licensed under the MIT license found in the
  10445. * LICENSE file in the root directory of this source tree.
  10446. *
  10447. * @typechecks
  10448. */
  10449. /**
  10450. * Convert array-like objects to arrays.
  10451. *
  10452. * This API assumes the caller knows the contents of the data type. For less
  10453. * well defined inputs use createArrayFromMixed.
  10454. *
  10455. * @param {object|function|filelist} obj
  10456. * @return {array}
  10457. */
  10458. function toArray(obj) {
  10459. var length = obj.length;
  10460. // Some browsers builtin objects can report typeof 'function' (e.g. NodeList
  10461. // in old versions of Safari).
  10462. !(!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;
  10463. !(typeof length === 'number') ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'toArray: Object needs a length property') : invariant_1(false) : void 0;
  10464. !(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;
  10465. !(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;
  10466. // Old IE doesn't give collections access to hasOwnProperty. Assume inputs
  10467. // without method will throw during the slice call and skip straight to the
  10468. // fallback.
  10469. if (obj.hasOwnProperty) {
  10470. try {
  10471. return Array.prototype.slice.call(obj);
  10472. } catch (e) {
  10473. // IE < 9 does not support Array#slice on collections objects
  10474. }
  10475. }
  10476. // Fall back to copying key by key. This assumes all keys have a value,
  10477. // so will not preserve sparsely populated inputs.
  10478. var ret = Array(length);
  10479. for (var ii = 0; ii < length; ii++) {
  10480. ret[ii] = obj[ii];
  10481. }
  10482. return ret;
  10483. }
  10484. /**
  10485. * Perform a heuristic test to determine if an object is "array-like".
  10486. *
  10487. * A monk asked Joshu, a Zen master, "Has a dog Buddha nature?"
  10488. * Joshu replied: "Mu."
  10489. *
  10490. * This function determines if its argument has "array nature": it returns
  10491. * true if the argument is an actual array, an `arguments' object, or an
  10492. * HTMLCollection (e.g. node.childNodes or node.getElementsByTagName()).
  10493. *
  10494. * It will return false for other array-like objects like Filelist.
  10495. *
  10496. * @param {*} obj
  10497. * @return {boolean}
  10498. */
  10499. function hasArrayNature(obj) {
  10500. return (
  10501. // not null/false
  10502. !!obj && (
  10503. // arrays are objects, NodeLists are functions in Safari
  10504. typeof obj == 'object' || typeof obj == 'function') &&
  10505. // quacks like an array
  10506. 'length' in obj &&
  10507. // not window
  10508. !('setInterval' in obj) &&
  10509. // no DOM node should be considered an array-like
  10510. // a 'select' element has 'length' and 'item' properties on IE8
  10511. typeof obj.nodeType != 'number' && (
  10512. // a real array
  10513. Array.isArray(obj) ||
  10514. // arguments
  10515. 'callee' in obj ||
  10516. // HTMLCollection/NodeList
  10517. 'item' in obj)
  10518. );
  10519. }
  10520. /**
  10521. * Ensure that the argument is an array by wrapping it in an array if it is not.
  10522. * Creates a copy of the argument if it is already an array.
  10523. *
  10524. * This is mostly useful idiomatically:
  10525. *
  10526. * var createArrayFromMixed = require('createArrayFromMixed');
  10527. *
  10528. * function takesOneOrMoreThings(things) {
  10529. * things = createArrayFromMixed(things);
  10530. * ...
  10531. * }
  10532. *
  10533. * This allows you to treat `things' as an array, but accept scalars in the API.
  10534. *
  10535. * If you need to convert an array-like object, like `arguments`, into an array
  10536. * use toArray instead.
  10537. *
  10538. * @param {*} obj
  10539. * @return {array}
  10540. */
  10541. function createArrayFromMixed(obj) {
  10542. if (!hasArrayNature(obj)) {
  10543. return [obj];
  10544. } else if (Array.isArray(obj)) {
  10545. return obj.slice();
  10546. } else {
  10547. return toArray(obj);
  10548. }
  10549. }
  10550. var createArrayFromMixed_1 = createArrayFromMixed;
  10551. function _classCallCheck$d(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10552. /**
  10553. * Copyright (c) 2013-present, Facebook, Inc.
  10554. *
  10555. * This source code is licensed under the MIT license found in the
  10556. * LICENSE file in the root directory of this source tree.
  10557. *
  10558. * @typechecks
  10559. */
  10560. var CR_LF_REGEX = new RegExp('\r\n', 'g');
  10561. var LF_ONLY = '\n';
  10562. var RICH_TEXT_TYPES = {
  10563. 'text/rtf': 1,
  10564. 'text/html': 1
  10565. };
  10566. /**
  10567. * If DataTransferItem is a file then return the Blob of data.
  10568. *
  10569. * @param {object} item
  10570. * @return {?blob}
  10571. */
  10572. function getFileFromDataTransfer(item) {
  10573. if (item.kind == 'file') {
  10574. return item.getAsFile();
  10575. }
  10576. }
  10577. var DataTransfer = function () {
  10578. /**
  10579. * @param {object} data
  10580. */
  10581. function DataTransfer(data) {
  10582. _classCallCheck$d(this, DataTransfer);
  10583. this.data = data;
  10584. // Types could be DOMStringList or array
  10585. this.types = data.types ? createArrayFromMixed_1(data.types) : [];
  10586. }
  10587. /**
  10588. * Is this likely to be a rich text data transfer?
  10589. *
  10590. * @return {boolean}
  10591. */
  10592. DataTransfer.prototype.isRichText = function isRichText() {
  10593. // If HTML is available, treat this data as rich text. This way, we avoid
  10594. // using a pasted image if it is packaged with HTML -- this may occur with
  10595. // pastes from MS Word, for example. However this is only rich text if
  10596. // there's accompanying text.
  10597. if (this.getHTML() && this.getText()) {
  10598. return true;
  10599. }
  10600. // When an image is copied from a preview window, you end up with two
  10601. // DataTransferItems one of which is a file's metadata as text. Skip those.
  10602. if (this.isImage()) {
  10603. return false;
  10604. }
  10605. return this.types.some(function (type) {
  10606. return RICH_TEXT_TYPES[type];
  10607. });
  10608. };
  10609. /**
  10610. * Get raw text.
  10611. *
  10612. * @return {?string}
  10613. */
  10614. DataTransfer.prototype.getText = function getText() {
  10615. var text;
  10616. if (this.data.getData) {
  10617. if (!this.types.length) {
  10618. text = this.data.getData('Text');
  10619. } else if (this.types.indexOf('text/plain') != -1) {
  10620. text = this.data.getData('text/plain');
  10621. }
  10622. }
  10623. return text ? text.replace(CR_LF_REGEX, LF_ONLY) : null;
  10624. };
  10625. /**
  10626. * Get HTML paste data
  10627. *
  10628. * @return {?string}
  10629. */
  10630. DataTransfer.prototype.getHTML = function getHTML() {
  10631. if (this.data.getData) {
  10632. if (!this.types.length) {
  10633. return this.data.getData('Text');
  10634. } else if (this.types.indexOf('text/html') != -1) {
  10635. return this.data.getData('text/html');
  10636. }
  10637. }
  10638. };
  10639. /**
  10640. * Is this a link data transfer?
  10641. *
  10642. * @return {boolean}
  10643. */
  10644. DataTransfer.prototype.isLink = function isLink() {
  10645. return this.types.some(function (type) {
  10646. return type.indexOf('Url') != -1 || type.indexOf('text/uri-list') != -1 || type.indexOf('text/x-moz-url');
  10647. });
  10648. };
  10649. /**
  10650. * Get a link url.
  10651. *
  10652. * @return {?string}
  10653. */
  10654. DataTransfer.prototype.getLink = function getLink() {
  10655. if (this.data.getData) {
  10656. if (this.types.indexOf('text/x-moz-url') != -1) {
  10657. var url = this.data.getData('text/x-moz-url').split('\n');
  10658. return url[0];
  10659. }
  10660. return this.types.indexOf('text/uri-list') != -1 ? this.data.getData('text/uri-list') : this.data.getData('url');
  10661. }
  10662. return null;
  10663. };
  10664. /**
  10665. * Is this an image data transfer?
  10666. *
  10667. * @return {boolean}
  10668. */
  10669. DataTransfer.prototype.isImage = function isImage() {
  10670. var isImage = this.types.some(function (type) {
  10671. // Firefox will have a type of application/x-moz-file for images during
  10672. // dragging
  10673. return type.indexOf('application/x-moz-file') != -1;
  10674. });
  10675. if (isImage) {
  10676. return true;
  10677. }
  10678. var items = this.getFiles();
  10679. for (var i = 0; i < items.length; i++) {
  10680. var type = items[i].type;
  10681. if (!PhotosMimeType_1.isImage(type)) {
  10682. return false;
  10683. }
  10684. }
  10685. return true;
  10686. };
  10687. DataTransfer.prototype.getCount = function getCount() {
  10688. if (this.data.hasOwnProperty('items')) {
  10689. return this.data.items.length;
  10690. } else if (this.data.hasOwnProperty('mozItemCount')) {
  10691. return this.data.mozItemCount;
  10692. } else if (this.data.files) {
  10693. return this.data.files.length;
  10694. }
  10695. return null;
  10696. };
  10697. /**
  10698. * Get files.
  10699. *
  10700. * @return {array}
  10701. */
  10702. DataTransfer.prototype.getFiles = function getFiles() {
  10703. if (this.data.items) {
  10704. // createArrayFromMixed doesn't properly handle DataTransferItemLists.
  10705. return Array.prototype.slice.call(this.data.items).map(getFileFromDataTransfer).filter(emptyFunction_1.thatReturnsArgument);
  10706. } else if (this.data.files) {
  10707. return Array.prototype.slice.call(this.data.files);
  10708. } else {
  10709. return [];
  10710. }
  10711. };
  10712. /**
  10713. * Are there any files to fetch?
  10714. *
  10715. * @return {boolean}
  10716. */
  10717. DataTransfer.prototype.hasFiles = function hasFiles() {
  10718. return this.getFiles().length > 0;
  10719. };
  10720. return DataTransfer;
  10721. }();
  10722. var DataTransfer_1 = DataTransfer;
  10723. /**
  10724. * Copyright (c) 2013-present, Facebook, Inc.
  10725. * All rights reserved.
  10726. *
  10727. * This source code is licensed under the BSD-style license found in the
  10728. * LICENSE file in the root directory of this source tree. An additional grant
  10729. * of patent rights can be found in the PATENTS file in the same directory.
  10730. *
  10731. * @providesModule getSelectionOffsetKeyForNode
  10732. * @format
  10733. *
  10734. */
  10735. /**
  10736. * Get offset key from a node or it's child nodes. Return the first offset key
  10737. * found on the DOM tree of given node.
  10738. */
  10739. function getSelectionOffsetKeyForNode(node) {
  10740. if (node instanceof Element) {
  10741. var offsetKey = node.getAttribute('data-offset-key');
  10742. if (offsetKey) {
  10743. return offsetKey;
  10744. }
  10745. for (var ii = 0; ii < node.childNodes.length; ii++) {
  10746. var childOffsetKey = getSelectionOffsetKeyForNode(node.childNodes[ii]);
  10747. if (childOffsetKey) {
  10748. return childOffsetKey;
  10749. }
  10750. }
  10751. }
  10752. return null;
  10753. }
  10754. var getSelectionOffsetKeyForNode_1 = getSelectionOffsetKeyForNode;
  10755. /**
  10756. * Get the key from the node's nearest offset-aware ancestor.
  10757. */
  10758. function findAncestorOffsetKey(node) {
  10759. var searchNode = node;
  10760. while (searchNode && searchNode !== document.documentElement) {
  10761. var key = getSelectionOffsetKeyForNode_1(searchNode);
  10762. if (key != null) {
  10763. return key;
  10764. }
  10765. searchNode = searchNode.parentNode;
  10766. }
  10767. return null;
  10768. }
  10769. var findAncestorOffsetKey_1 = findAncestorOffsetKey;
  10770. var TEXT_CLIPPING_REGEX = /\.textClipping$/;
  10771. var TEXT_TYPES = {
  10772. 'text/plain': true,
  10773. 'text/html': true,
  10774. 'text/rtf': true
  10775. };
  10776. // Somewhat arbitrary upper bound on text size. Let's not lock up the browser.
  10777. var TEXT_SIZE_UPPER_BOUND = 5000;
  10778. /**
  10779. * Extract the text content from a file list.
  10780. */
  10781. function getTextContentFromFiles(files, callback) {
  10782. var readCount = 0;
  10783. var results = [];
  10784. files.forEach(function ( /*blob*/file) {
  10785. readFile(file, function ( /*string*/text) {
  10786. readCount++;
  10787. text && results.push(text.slice(0, TEXT_SIZE_UPPER_BOUND));
  10788. if (readCount == files.length) {
  10789. callback(results.join('\r'));
  10790. }
  10791. });
  10792. });
  10793. }
  10794. /**
  10795. * todo isaac: Do work to turn html/rtf into a content fragment.
  10796. */
  10797. function readFile(file, callback) {
  10798. if (!commonjsGlobal.FileReader || file.type && !(file.type in TEXT_TYPES)) {
  10799. callback('');
  10800. return;
  10801. }
  10802. if (file.type === '') {
  10803. var contents = '';
  10804. // Special-case text clippings, which have an empty type but include
  10805. // `.textClipping` in the file name. `readAsText` results in an empty
  10806. // string for text clippings, so we force the file name to serve
  10807. // as the text value for the file.
  10808. if (TEXT_CLIPPING_REGEX.test(file.name)) {
  10809. contents = file.name.replace(TEXT_CLIPPING_REGEX, '');
  10810. }
  10811. callback(contents);
  10812. return;
  10813. }
  10814. var reader = new FileReader();
  10815. reader.onload = function () {
  10816. var result = reader.result;
  10817. !(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;
  10818. callback(result);
  10819. };
  10820. reader.onerror = function () {
  10821. callback('');
  10822. };
  10823. reader.readAsText(file);
  10824. }
  10825. var getTextContentFromFiles_1 = getTextContentFromFiles;
  10826. function getUpdatedSelectionState(editorState, anchorKey, anchorOffset, focusKey, focusOffset) {
  10827. var selection = nullthrows_1(editorState.getSelection());
  10828. if (process.env.NODE_ENV !== 'production') {
  10829. if (!anchorKey || !focusKey) {
  10830. /*eslint-disable no-console */
  10831. console.warn('Invalid selection state.', arguments, editorState.toJS());
  10832. /*eslint-enable no-console */
  10833. return selection;
  10834. }
  10835. }
  10836. var anchorPath = DraftOffsetKey_1.decode(anchorKey);
  10837. var anchorBlockKey = anchorPath.blockKey;
  10838. var anchorLeaf = editorState.getBlockTree(anchorBlockKey).getIn([anchorPath.decoratorKey, 'leaves', anchorPath.leafKey]);
  10839. var focusPath = DraftOffsetKey_1.decode(focusKey);
  10840. var focusBlockKey = focusPath.blockKey;
  10841. var focusLeaf = editorState.getBlockTree(focusBlockKey).getIn([focusPath.decoratorKey, 'leaves', focusPath.leafKey]);
  10842. var anchorLeafStart = anchorLeaf.get('start');
  10843. var focusLeafStart = focusLeaf.get('start');
  10844. var anchorBlockOffset = anchorLeaf ? anchorLeafStart + anchorOffset : null;
  10845. var focusBlockOffset = focusLeaf ? focusLeafStart + focusOffset : null;
  10846. var areEqual = selection.getAnchorKey() === anchorBlockKey && selection.getAnchorOffset() === anchorBlockOffset && selection.getFocusKey() === focusBlockKey && selection.getFocusOffset() === focusBlockOffset;
  10847. if (areEqual) {
  10848. return selection;
  10849. }
  10850. var isBackward = false;
  10851. if (anchorBlockKey === focusBlockKey) {
  10852. var anchorLeafEnd = anchorLeaf.get('end');
  10853. var focusLeafEnd = focusLeaf.get('end');
  10854. if (focusLeafStart === anchorLeafStart && focusLeafEnd === anchorLeafEnd) {
  10855. isBackward = focusOffset < anchorOffset;
  10856. } else {
  10857. isBackward = focusLeafStart < anchorLeafStart;
  10858. }
  10859. } else {
  10860. var startKey = editorState.getCurrentContent().getBlockMap().keySeq().skipUntil(function (v) {
  10861. return v === anchorBlockKey || v === focusBlockKey;
  10862. }).first();
  10863. isBackward = startKey === focusBlockKey;
  10864. }
  10865. return selection.merge({
  10866. anchorKey: anchorBlockKey,
  10867. anchorOffset: anchorBlockOffset,
  10868. focusKey: focusBlockKey,
  10869. focusOffset: focusBlockOffset,
  10870. isBackward: isBackward
  10871. });
  10872. }
  10873. var getUpdatedSelectionState_1 = getUpdatedSelectionState;
  10874. /**
  10875. * Get a SelectionState for the supplied mouse event.
  10876. */
  10877. function getSelectionForEvent(event, editorState) {
  10878. var node = null;
  10879. var offset = null;
  10880. if (typeof document.caretRangeFromPoint === 'function') {
  10881. var dropRange = document.caretRangeFromPoint(event.x, event.y);
  10882. node = dropRange.startContainer;
  10883. offset = dropRange.startOffset;
  10884. } else if (event.rangeParent) {
  10885. node = event.rangeParent;
  10886. offset = event.rangeOffset;
  10887. } else {
  10888. return null;
  10889. }
  10890. node = nullthrows_1(node);
  10891. offset = nullthrows_1(offset);
  10892. var offsetKey = nullthrows_1(findAncestorOffsetKey_1(node));
  10893. return getUpdatedSelectionState_1(editorState, offsetKey, offset, offsetKey, offset);
  10894. }
  10895. var DraftEditorDragHandler = {
  10896. /**
  10897. * Drag originating from input terminated.
  10898. */
  10899. onDragEnd: function onDragEnd(editor) {
  10900. editor.exitCurrentMode();
  10901. },
  10902. /**
  10903. * Handle data being dropped.
  10904. */
  10905. onDrop: function onDrop(editor, e) {
  10906. var data = new DataTransfer_1(e.nativeEvent.dataTransfer);
  10907. var editorState = editor._latestEditorState;
  10908. var dropSelection = getSelectionForEvent(e.nativeEvent, editorState);
  10909. e.preventDefault();
  10910. editor.exitCurrentMode();
  10911. if (dropSelection == null) {
  10912. return;
  10913. }
  10914. var files = data.getFiles();
  10915. if (files.length > 0) {
  10916. if (editor.props.handleDroppedFiles && isEventHandled_1(editor.props.handleDroppedFiles(dropSelection, files))) {
  10917. return;
  10918. }
  10919. getTextContentFromFiles_1(files, function (fileText) {
  10920. fileText && editor.update(insertTextAtSelection(editorState, dropSelection, fileText));
  10921. });
  10922. return;
  10923. }
  10924. var dragType = editor._internalDrag ? 'internal' : 'external';
  10925. if (editor.props.handleDrop && isEventHandled_1(editor.props.handleDrop(dropSelection, data, dragType))) {
  10926. return;
  10927. }
  10928. if (editor._internalDrag) {
  10929. editor.update(moveText(editorState, dropSelection));
  10930. return;
  10931. }
  10932. editor.update(insertTextAtSelection(editorState, dropSelection, data.getText()));
  10933. }
  10934. };
  10935. function moveText(editorState, targetSelection) {
  10936. var newContentState = DraftModifier_1.moveText(editorState.getCurrentContent(), editorState.getSelection(), targetSelection);
  10937. return EditorState_1.push(editorState, newContentState, 'insert-fragment');
  10938. }
  10939. /**
  10940. * Insert text at a specified selection.
  10941. */
  10942. function insertTextAtSelection(editorState, selection, text) {
  10943. var newContentState = DraftModifier_1.insertText(editorState.getCurrentContent(), selection, text, editorState.getCurrentInlineStyle());
  10944. return EditorState_1.push(editorState, newContentState, 'insert-fragment');
  10945. }
  10946. var DraftEditorDragHandler_1 = DraftEditorDragHandler;
  10947. (function (global, undefined$1) {
  10948. if (global.setImmediate) {
  10949. return;
  10950. }
  10951. var nextHandle = 1; // Spec says greater than zero
  10952. var tasksByHandle = {};
  10953. var currentlyRunningATask = false;
  10954. var doc = global.document;
  10955. var registerImmediate;
  10956. function setImmediate(callback) {
  10957. // Callback can either be a function or a string
  10958. if (typeof callback !== "function") {
  10959. callback = new Function("" + callback);
  10960. }
  10961. // Copy function arguments
  10962. var args = new Array(arguments.length - 1);
  10963. for (var i = 0; i < args.length; i++) {
  10964. args[i] = arguments[i + 1];
  10965. }
  10966. // Store and register the task
  10967. var task = { callback: callback, args: args };
  10968. tasksByHandle[nextHandle] = task;
  10969. registerImmediate(nextHandle);
  10970. return nextHandle++;
  10971. }
  10972. function clearImmediate(handle) {
  10973. delete tasksByHandle[handle];
  10974. }
  10975. function run(task) {
  10976. var callback = task.callback;
  10977. var args = task.args;
  10978. switch (args.length) {
  10979. case 0:
  10980. callback();
  10981. break;
  10982. case 1:
  10983. callback(args[0]);
  10984. break;
  10985. case 2:
  10986. callback(args[0], args[1]);
  10987. break;
  10988. case 3:
  10989. callback(args[0], args[1], args[2]);
  10990. break;
  10991. default:
  10992. callback.apply(undefined$1, args);
  10993. break;
  10994. }
  10995. }
  10996. function runIfPresent(handle) {
  10997. // From the spec: "Wait until any invocations of this algorithm started before this one have completed."
  10998. // So if we're currently running a task, we'll need to delay this invocation.
  10999. if (currentlyRunningATask) {
  11000. // Delay by doing a setTimeout. setImmediate was tried instead, but in Firefox 7 it generated a
  11001. // "too much recursion" error.
  11002. setTimeout(runIfPresent, 0, handle);
  11003. } else {
  11004. var task = tasksByHandle[handle];
  11005. if (task) {
  11006. currentlyRunningATask = true;
  11007. try {
  11008. run(task);
  11009. } finally {
  11010. clearImmediate(handle);
  11011. currentlyRunningATask = false;
  11012. }
  11013. }
  11014. }
  11015. }
  11016. function installNextTickImplementation() {
  11017. registerImmediate = function(handle) {
  11018. process.nextTick(function () { runIfPresent(handle); });
  11019. };
  11020. }
  11021. function canUsePostMessage() {
  11022. // The test against `importScripts` prevents this implementation from being installed inside a web worker,
  11023. // where `global.postMessage` means something completely different and can't be used for this purpose.
  11024. if (global.postMessage && !global.importScripts) {
  11025. var postMessageIsAsynchronous = true;
  11026. var oldOnMessage = global.onmessage;
  11027. global.onmessage = function() {
  11028. postMessageIsAsynchronous = false;
  11029. };
  11030. global.postMessage("", "*");
  11031. global.onmessage = oldOnMessage;
  11032. return postMessageIsAsynchronous;
  11033. }
  11034. }
  11035. function installPostMessageImplementation() {
  11036. // Installs an event handler on `global` for the `message` event: see
  11037. // * https://developer.mozilla.org/en/DOM/window.postMessage
  11038. // * http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html#crossDocumentMessages
  11039. var messagePrefix = "setImmediate$" + Math.random() + "$";
  11040. var onGlobalMessage = function(event) {
  11041. if (event.source === global &&
  11042. typeof event.data === "string" &&
  11043. event.data.indexOf(messagePrefix) === 0) {
  11044. runIfPresent(+event.data.slice(messagePrefix.length));
  11045. }
  11046. };
  11047. if (global.addEventListener) {
  11048. global.addEventListener("message", onGlobalMessage, false);
  11049. } else {
  11050. global.attachEvent("onmessage", onGlobalMessage);
  11051. }
  11052. registerImmediate = function(handle) {
  11053. global.postMessage(messagePrefix + handle, "*");
  11054. };
  11055. }
  11056. function installMessageChannelImplementation() {
  11057. var channel = new MessageChannel();
  11058. channel.port1.onmessage = function(event) {
  11059. var handle = event.data;
  11060. runIfPresent(handle);
  11061. };
  11062. registerImmediate = function(handle) {
  11063. channel.port2.postMessage(handle);
  11064. };
  11065. }
  11066. function installReadyStateChangeImplementation() {
  11067. var html = doc.documentElement;
  11068. registerImmediate = function(handle) {
  11069. // Create a <script> element; its readystatechange event will be fired asynchronously once it is inserted
  11070. // into the document. Do so, thus queuing up the task. Remember to clean up once it's been called.
  11071. var script = doc.createElement("script");
  11072. script.onreadystatechange = function () {
  11073. runIfPresent(handle);
  11074. script.onreadystatechange = null;
  11075. html.removeChild(script);
  11076. script = null;
  11077. };
  11078. html.appendChild(script);
  11079. };
  11080. }
  11081. function installSetTimeoutImplementation() {
  11082. registerImmediate = function(handle) {
  11083. setTimeout(runIfPresent, 0, handle);
  11084. };
  11085. }
  11086. // If supported, we should attach to the prototype of global, since that is where setTimeout et al. live.
  11087. var attachTo = Object.getPrototypeOf && Object.getPrototypeOf(global);
  11088. attachTo = attachTo && attachTo.setTimeout ? attachTo : global;
  11089. // Don't get fooled by e.g. browserify environments.
  11090. if ({}.toString.call(global.process) === "[object process]") {
  11091. // For Node.js before 0.9
  11092. installNextTickImplementation();
  11093. } else if (canUsePostMessage()) {
  11094. // For non-IE10 modern browsers
  11095. installPostMessageImplementation();
  11096. } else if (global.MessageChannel) {
  11097. // For web workers, where supported
  11098. installMessageChannelImplementation();
  11099. } else if (doc && "onreadystatechange" in doc.createElement("script")) {
  11100. // For IE 6–8
  11101. installReadyStateChangeImplementation();
  11102. } else {
  11103. // For older browsers
  11104. installSetTimeoutImplementation();
  11105. }
  11106. attachTo.setImmediate = setImmediate;
  11107. attachTo.clearImmediate = clearImmediate;
  11108. }(typeof self === "undefined" ? typeof commonjsGlobal === "undefined" ? commonjsGlobal : commonjsGlobal : self));
  11109. // setimmediate adds setImmediate to the global. We want to make sure we export
  11110. // the actual function.
  11111. var setImmediate = commonjsGlobal.setImmediate;
  11112. // When nothing is focused, Firefox regards two characters, `'` and `/`, as
  11113. // commands that should open and focus the "quickfind" search bar. This should
  11114. // *never* happen while a contenteditable is focused, but as of v28, it
  11115. // sometimes does, even when the keypress event target is the contenteditable.
  11116. // This breaks the input. Special case these characters to ensure that when
  11117. // they are typed, we prevent default on the event to make sure not to
  11118. // trigger quickfind.
  11119. var FF_QUICKFIND_CHAR = "'";
  11120. var FF_QUICKFIND_LINK_CHAR = '/';
  11121. var isFirefox = UserAgent_1.isBrowser('Firefox');
  11122. function mustPreventDefaultForCharacter(character) {
  11123. return isFirefox && (character == FF_QUICKFIND_CHAR || character == FF_QUICKFIND_LINK_CHAR);
  11124. }
  11125. /**
  11126. * Replace the current selection with the specified text string, with the
  11127. * inline style and entity key applied to the newly inserted text.
  11128. */
  11129. function replaceText(editorState, text, inlineStyle, entityKey) {
  11130. var contentState = DraftModifier_1.replaceText(editorState.getCurrentContent(), editorState.getSelection(), text, inlineStyle, entityKey);
  11131. return EditorState_1.push(editorState, contentState, 'insert-characters');
  11132. }
  11133. /**
  11134. * When `onBeforeInput` executes, the browser is attempting to insert a
  11135. * character into the editor. Apply this character data to the document,
  11136. * allowing native insertion if possible.
  11137. *
  11138. * Native insertion is encouraged in order to limit re-rendering and to
  11139. * preserve spellcheck highlighting, which disappears or flashes if re-render
  11140. * occurs on the relevant text nodes.
  11141. */
  11142. function editOnBeforeInput(editor, e) {
  11143. if (editor._pendingStateFromBeforeInput !== undefined) {
  11144. editor.update(editor._pendingStateFromBeforeInput);
  11145. editor._pendingStateFromBeforeInput = undefined;
  11146. }
  11147. var editorState = editor._latestEditorState;
  11148. var chars = e.data;
  11149. // In some cases (ex: IE ideographic space insertion) no character data
  11150. // is provided. There's nothing to do when this happens.
  11151. if (!chars) {
  11152. return;
  11153. }
  11154. // Allow the top-level component to handle the insertion manually. This is
  11155. // useful when triggering interesting behaviors for a character insertion,
  11156. // Simple examples: replacing a raw text ':)' with a smile emoji or image
  11157. // decorator, or setting a block to be a list item after typing '- ' at the
  11158. // start of the block.
  11159. if (editor.props.handleBeforeInput && isEventHandled_1(editor.props.handleBeforeInput(chars, editorState))) {
  11160. e.preventDefault();
  11161. return;
  11162. }
  11163. // If selection is collapsed, conditionally allow native behavior. This
  11164. // reduces re-renders and preserves spellcheck highlighting. If the selection
  11165. // is not collapsed, we will re-render.
  11166. var selection = editorState.getSelection();
  11167. var selectionStart = selection.getStartOffset();
  11168. var selectionEnd = selection.getEndOffset();
  11169. var anchorKey = selection.getAnchorKey();
  11170. if (!selection.isCollapsed()) {
  11171. e.preventDefault();
  11172. // If the currently selected text matches what the user is trying to
  11173. // replace it with, let's just update the `SelectionState`. If not, update
  11174. // the `ContentState` with the new text.
  11175. var currentlySelectedChars = editorState.getCurrentContent().getPlainText().slice(selectionStart, selectionEnd);
  11176. if (chars === currentlySelectedChars) {
  11177. editor.update(EditorState_1.forceSelection(editorState, selection.merge({
  11178. focusOffset: selectionEnd
  11179. })));
  11180. } else {
  11181. editor.update(replaceText(editorState, chars, editorState.getCurrentInlineStyle(), getEntityKeyForSelection_1(editorState.getCurrentContent(), editorState.getSelection())));
  11182. }
  11183. return;
  11184. }
  11185. var newEditorState = replaceText(editorState, chars, editorState.getCurrentInlineStyle(), getEntityKeyForSelection_1(editorState.getCurrentContent(), editorState.getSelection()));
  11186. // Bunch of different cases follow where we need to prevent native insertion.
  11187. var mustPreventNative = false;
  11188. if (!mustPreventNative) {
  11189. // Browsers tend to insert text in weird places in the DOM when typing at
  11190. // the start of a leaf, so we'll handle it ourselves.
  11191. mustPreventNative = isSelectionAtLeafStart_1(editor._latestCommittedEditorState);
  11192. }
  11193. if (!mustPreventNative) {
  11194. // Chrome will also split up a node into two pieces if it contains a Tab
  11195. // char, for no explicable reason. Seemingly caused by this commit:
  11196. // https://chromium.googlesource.com/chromium/src/+/013ac5eaf3%5E%21/
  11197. var nativeSelection = commonjsGlobal.getSelection();
  11198. // Selection is necessarily collapsed at this point due to earlier check.
  11199. if (nativeSelection.anchorNode && nativeSelection.anchorNode.nodeType === Node.TEXT_NODE) {
  11200. // See isTabHTMLSpanElement in chromium EditingUtilities.cpp.
  11201. var parentNode = nativeSelection.anchorNode.parentNode;
  11202. mustPreventNative = parentNode.nodeName === 'SPAN' && parentNode.firstChild.nodeType === Node.TEXT_NODE && parentNode.firstChild.nodeValue.indexOf('\t') !== -1;
  11203. }
  11204. }
  11205. if (!mustPreventNative) {
  11206. // Check the old and new "fingerprints" of the current block to determine
  11207. // whether this insertion requires any addition or removal of text nodes,
  11208. // in which case we would prevent the native character insertion.
  11209. var originalFingerprint = BlockTree_1.getFingerprint(editorState.getBlockTree(anchorKey));
  11210. var newFingerprint = BlockTree_1.getFingerprint(newEditorState.getBlockTree(anchorKey));
  11211. mustPreventNative = originalFingerprint !== newFingerprint;
  11212. }
  11213. if (!mustPreventNative) {
  11214. mustPreventNative = mustPreventDefaultForCharacter(chars);
  11215. }
  11216. if (!mustPreventNative) {
  11217. mustPreventNative = nullthrows_1(newEditorState.getDirectionMap()).get(anchorKey) !== nullthrows_1(editorState.getDirectionMap()).get(anchorKey);
  11218. }
  11219. if (mustPreventNative) {
  11220. e.preventDefault();
  11221. editor.update(newEditorState);
  11222. return;
  11223. }
  11224. // We made it all the way! Let the browser do its thing and insert the char.
  11225. newEditorState = EditorState_1.set(newEditorState, {
  11226. nativelyRenderedContent: newEditorState.getCurrentContent()
  11227. });
  11228. // The native event is allowed to occur. To allow user onChange handlers to
  11229. // change the inserted text, we wait until the text is actually inserted
  11230. // before we actually update our state. That way when we rerender, the text
  11231. // we see in the DOM will already have been inserted properly.
  11232. editor._pendingStateFromBeforeInput = newEditorState;
  11233. setImmediate(function () {
  11234. if (editor._pendingStateFromBeforeInput !== undefined) {
  11235. editor.update(editor._pendingStateFromBeforeInput);
  11236. editor._pendingStateFromBeforeInput = undefined;
  11237. }
  11238. });
  11239. }
  11240. var editOnBeforeInput_1 = editOnBeforeInput;
  11241. function editOnBlur(editor, e) {
  11242. // In a contentEditable element, when you select a range and then click
  11243. // another active element, this does trigger a `blur` event but will not
  11244. // remove the DOM selection from the contenteditable.
  11245. // This is consistent across all browsers, but we prefer that the editor
  11246. // behave like a textarea, where a `blur` event clears the DOM selection.
  11247. // We therefore force the issue to be certain, checking whether the active
  11248. // element is `body` to force it when blurring occurs within the window (as
  11249. // opposed to clicking to another tab or window).
  11250. if (getActiveElement_1() === document.body) {
  11251. var _selection = commonjsGlobal.getSelection();
  11252. var editorNode = editor.editor;
  11253. if (_selection.rangeCount === 1 && containsNode_1(editorNode, _selection.anchorNode) && containsNode_1(editorNode, _selection.focusNode)) {
  11254. _selection.removeAllRanges();
  11255. }
  11256. }
  11257. var editorState = editor._latestEditorState;
  11258. var currentSelection = editorState.getSelection();
  11259. if (!currentSelection.getHasFocus()) {
  11260. return;
  11261. }
  11262. var selection = currentSelection.set('hasFocus', false);
  11263. editor.props.onBlur && editor.props.onBlur(e);
  11264. editor.update(EditorState_1.acceptSelection(editorState, selection));
  11265. }
  11266. var editOnBlur_1 = editOnBlur;
  11267. /**
  11268. * The user has begun using an IME input system. Switching to `composite` mode
  11269. * allows handling composition input and disables other edit behavior.
  11270. */
  11271. function editOnCompositionStart(editor, e) {
  11272. editor.setMode('composite');
  11273. editor.update(EditorState_1.set(editor._latestEditorState, { inCompositionMode: true }));
  11274. // Allow composition handler to interpret the compositionstart event
  11275. editor._onCompositionStart(e);
  11276. }
  11277. var editOnCompositionStart_1 = editOnCompositionStart;
  11278. function getFragmentFromSelection(editorState) {
  11279. var selectionState = editorState.getSelection();
  11280. if (selectionState.isCollapsed()) {
  11281. return null;
  11282. }
  11283. return getContentStateFragment_1(editorState.getCurrentContent(), selectionState);
  11284. }
  11285. var getFragmentFromSelection_1 = getFragmentFromSelection;
  11286. /**
  11287. * If we have a selection, create a ContentState fragment and store
  11288. * it in our internal clipboard. Subsequent paste events will use this
  11289. * fragment if no external clipboard data is supplied.
  11290. */
  11291. function editOnCopy(editor, e) {
  11292. var editorState = editor._latestEditorState;
  11293. var selection = editorState.getSelection();
  11294. // No selection, so there's nothing to copy.
  11295. if (selection.isCollapsed()) {
  11296. e.preventDefault();
  11297. return;
  11298. }
  11299. editor.setClipboard(getFragmentFromSelection_1(editor._latestEditorState));
  11300. }
  11301. var editOnCopy_1 = editOnCopy;
  11302. /**
  11303. * On `cut` events, native behavior is allowed to occur so that the system
  11304. * clipboard is set properly. This means that we need to take steps to recover
  11305. * the editor DOM state after the `cut` has occurred in order to maintain
  11306. * control of the component.
  11307. *
  11308. * In addition, we can keep a copy of the removed fragment, including all
  11309. * styles and entities, for use as an internal paste.
  11310. */
  11311. function editOnCut(editor, e) {
  11312. var editorState = editor._latestEditorState;
  11313. var selection = editorState.getSelection();
  11314. var element = e.target;
  11315. var scrollPosition = void 0;
  11316. // No selection, so there's nothing to cut.
  11317. if (selection.isCollapsed()) {
  11318. e.preventDefault();
  11319. return;
  11320. }
  11321. // Track the current scroll position so that it can be forced back in place
  11322. // after the editor regains control of the DOM.
  11323. if (element instanceof Node) {
  11324. scrollPosition = getScrollPosition_1(Style_1.getScrollParent(element));
  11325. }
  11326. var fragment = getFragmentFromSelection_1(editorState);
  11327. editor.setClipboard(fragment);
  11328. // Set `cut` mode to disable all event handling temporarily.
  11329. editor.setMode('cut');
  11330. // Let native `cut` behavior occur, then recover control.
  11331. setTimeout(function () {
  11332. editor.restoreEditorDOM(scrollPosition);
  11333. editor.exitCurrentMode();
  11334. editor.update(removeFragment(editorState));
  11335. }, 0);
  11336. }
  11337. function removeFragment(editorState) {
  11338. var newContent = DraftModifier_1.removeRange(editorState.getCurrentContent(), editorState.getSelection(), 'forward');
  11339. return EditorState_1.push(editorState, newContent, 'remove-range');
  11340. }
  11341. var editOnCut_1 = editOnCut;
  11342. /**
  11343. * Copyright (c) 2013-present, Facebook, Inc.
  11344. * All rights reserved.
  11345. *
  11346. * This source code is licensed under the BSD-style license found in the
  11347. * LICENSE file in the root directory of this source tree. An additional grant
  11348. * of patent rights can be found in the PATENTS file in the same directory.
  11349. *
  11350. * @providesModule editOnDragOver
  11351. * @format
  11352. *
  11353. */
  11354. /**
  11355. * Drag behavior has begun from outside the editor element.
  11356. */
  11357. function editOnDragOver(editor, e) {
  11358. editor._internalDrag = false;
  11359. editor.setMode('drag');
  11360. e.preventDefault();
  11361. }
  11362. var editOnDragOver_1 = editOnDragOver;
  11363. /**
  11364. * Copyright (c) 2013-present, Facebook, Inc.
  11365. * All rights reserved.
  11366. *
  11367. * This source code is licensed under the BSD-style license found in the
  11368. * LICENSE file in the root directory of this source tree. An additional grant
  11369. * of patent rights can be found in the PATENTS file in the same directory.
  11370. *
  11371. * @providesModule editOnDragStart
  11372. * @format
  11373. *
  11374. */
  11375. /**
  11376. * A `dragstart` event has begun within the text editor component.
  11377. */
  11378. function editOnDragStart(editor) {
  11379. editor._internalDrag = true;
  11380. editor.setMode('drag');
  11381. }
  11382. var editOnDragStart_1 = editOnDragStart;
  11383. function editOnFocus(editor, e) {
  11384. var editorState = editor._latestEditorState;
  11385. var currentSelection = editorState.getSelection();
  11386. if (currentSelection.getHasFocus()) {
  11387. return;
  11388. }
  11389. var selection = currentSelection.set('hasFocus', true);
  11390. editor.props.onFocus && editor.props.onFocus(e);
  11391. // When the tab containing this text editor is hidden and the user does a
  11392. // find-in-page in a _different_ tab, Chrome on Mac likes to forget what the
  11393. // selection was right after sending this focus event and (if you let it)
  11394. // moves the cursor back to the beginning of the editor, so we force the
  11395. // selection here instead of simply accepting it in order to preserve the
  11396. // old cursor position. See https://crbug.com/540004.
  11397. // But it looks like this is fixed in Chrome 60.0.3081.0.
  11398. // Other browsers also don't have this bug, so we prefer to acceptSelection
  11399. // when possible, to ensure that unfocusing and refocusing a Draft editor
  11400. // doesn't preserve the selection, matching how textareas work.
  11401. if (UserAgent_1.isBrowser('Chrome < 60.0.3081.0')) {
  11402. editor.update(EditorState_1.forceSelection(editorState, selection));
  11403. } else {
  11404. editor.update(EditorState_1.acceptSelection(editorState, selection));
  11405. }
  11406. }
  11407. var editOnFocus_1 = editOnFocus;
  11408. var isGecko = UserAgent_1.isEngine('Gecko');
  11409. var DOUBLE_NEWLINE = '\n\n';
  11410. /**
  11411. * This function is intended to handle spellcheck and autocorrect changes,
  11412. * which occur in the DOM natively without any opportunity to observe or
  11413. * interpret the changes before they occur.
  11414. *
  11415. * The `input` event fires in contentEditable elements reliably for non-IE
  11416. * browsers, immediately after changes occur to the editor DOM. Since our other
  11417. * handlers override or otherwise handle cover other varieties of text input,
  11418. * the DOM state should match the model in all controlled input cases. Thus,
  11419. * when an `input` change leads to a DOM/model mismatch, the change should be
  11420. * due to a spellcheck change, and we can incorporate it into our model.
  11421. */
  11422. function editOnInput(editor) {
  11423. if (editor._pendingStateFromBeforeInput !== undefined) {
  11424. editor.update(editor._pendingStateFromBeforeInput);
  11425. editor._pendingStateFromBeforeInput = undefined;
  11426. }
  11427. var domSelection = commonjsGlobal.getSelection();
  11428. var anchorNode = domSelection.anchorNode,
  11429. isCollapsed = domSelection.isCollapsed;
  11430. var isNotTextNode = anchorNode.nodeType !== Node.TEXT_NODE;
  11431. var isNotTextOrElementNode = anchorNode.nodeType !== Node.TEXT_NODE && anchorNode.nodeType !== Node.ELEMENT_NODE;
  11432. {
  11433. if (isNotTextOrElementNode) {
  11434. // TODO: (t16149272) figure out context for this change
  11435. return;
  11436. }
  11437. }
  11438. if (anchorNode.nodeType === Node.TEXT_NODE && (anchorNode.previousSibling !== null || anchorNode.nextSibling !== null)) {
  11439. // When typing at the beginning of a visual line, Chrome splits the text
  11440. // nodes into two. Why? No one knows. This commit is suspicious:
  11441. // https://chromium.googlesource.com/chromium/src/+/a3b600981286b135632371477f902214c55a1724
  11442. // To work around, we'll merge the sibling text nodes back into this one.
  11443. var span = anchorNode.parentNode;
  11444. anchorNode.nodeValue = span.textContent;
  11445. for (var child = span.firstChild; child !== null; child = child.nextSibling) {
  11446. if (child !== anchorNode) {
  11447. span.removeChild(child);
  11448. }
  11449. }
  11450. }
  11451. var domText = anchorNode.textContent;
  11452. var editorState = editor._latestEditorState;
  11453. var offsetKey = nullthrows_1(findAncestorOffsetKey_1(anchorNode));
  11454. var _DraftOffsetKey$decod = DraftOffsetKey_1.decode(offsetKey),
  11455. blockKey = _DraftOffsetKey$decod.blockKey,
  11456. decoratorKey = _DraftOffsetKey$decod.decoratorKey,
  11457. leafKey = _DraftOffsetKey$decod.leafKey;
  11458. var _editorState$getBlock = editorState.getBlockTree(blockKey).getIn([decoratorKey, 'leaves', leafKey]),
  11459. start = _editorState$getBlock.start,
  11460. end = _editorState$getBlock.end;
  11461. var content = editorState.getCurrentContent();
  11462. var block = content.getBlockForKey(blockKey);
  11463. var modelText = block.getText().slice(start, end);
  11464. // Special-case soft newlines here. If the DOM text ends in a soft newline,
  11465. // we will have manually inserted an extra soft newline in DraftEditorLeaf.
  11466. // We want to remove this extra newline for the purpose of our comparison
  11467. // of DOM and model text.
  11468. if (domText.endsWith(DOUBLE_NEWLINE)) {
  11469. domText = domText.slice(0, -1);
  11470. }
  11471. // No change -- the DOM is up to date. Nothing to do here.
  11472. if (domText === modelText) {
  11473. // This can be buggy for some Android keyboards because they don't fire
  11474. // standard onkeydown/pressed events and only fired editOnInput
  11475. // so domText is already changed by the browser and ends up being equal
  11476. // to modelText unexpectedly
  11477. return;
  11478. }
  11479. var selection = editorState.getSelection();
  11480. // We'll replace the entire leaf with the text content of the target.
  11481. var targetRange = selection.merge({
  11482. anchorOffset: start,
  11483. focusOffset: end,
  11484. isBackward: false
  11485. });
  11486. var entityKey = block.getEntityAt(start);
  11487. var entity = entityKey && content.getEntity(entityKey);
  11488. var entityType = entity && entity.getMutability();
  11489. var preserveEntity = entityType === 'MUTABLE';
  11490. // Immutable or segmented entities cannot properly be handled by the
  11491. // default browser undo, so we have to use a different change type to
  11492. // force using our internal undo method instead of falling through to the
  11493. // native browser undo.
  11494. var changeType = preserveEntity ? 'spellcheck-change' : 'apply-entity';
  11495. var newContent = DraftModifier_1.replaceText(content, targetRange, domText, block.getInlineStyleAt(start), preserveEntity ? block.getEntityAt(start) : null);
  11496. var anchorOffset, focusOffset, startOffset, endOffset;
  11497. if (isGecko) {
  11498. // Firefox selection does not change while the context menu is open, so
  11499. // we preserve the anchor and focus values of the DOM selection.
  11500. anchorOffset = domSelection.anchorOffset;
  11501. focusOffset = domSelection.focusOffset;
  11502. startOffset = start + Math.min(anchorOffset, focusOffset);
  11503. endOffset = startOffset + Math.abs(anchorOffset - focusOffset);
  11504. anchorOffset = startOffset;
  11505. focusOffset = endOffset;
  11506. } else {
  11507. // Browsers other than Firefox may adjust DOM selection while the context
  11508. // menu is open, and Safari autocorrect is prone to providing an inaccurate
  11509. // DOM selection. Don't trust it. Instead, use our existing SelectionState
  11510. // and adjust it based on the number of characters changed during the
  11511. // mutation.
  11512. var charDelta = domText.length - modelText.length;
  11513. startOffset = selection.getStartOffset();
  11514. endOffset = selection.getEndOffset();
  11515. anchorOffset = isCollapsed ? endOffset + charDelta : startOffset;
  11516. focusOffset = endOffset + charDelta;
  11517. }
  11518. // Segmented entities are completely or partially removed when their
  11519. // text content changes. For this case we do not want any text to be selected
  11520. // after the change, so we are not merging the selection.
  11521. var contentWithAdjustedDOMSelection = newContent.merge({
  11522. selectionBefore: content.getSelectionAfter(),
  11523. selectionAfter: selection.merge({ anchorOffset: anchorOffset, focusOffset: focusOffset })
  11524. });
  11525. editor.update(EditorState_1.push(editorState, contentWithAdjustedDOMSelection, changeType));
  11526. }
  11527. var editOnInput_1 = editOnInput;
  11528. var isOSX = UserAgent_1.isPlatform('Mac OS X');
  11529. var KeyBindingUtil = {
  11530. /**
  11531. * Check whether the ctrlKey modifier is *not* being used in conjunction with
  11532. * the altKey modifier. If they are combined, the result is an `altGraph`
  11533. * key modifier, which should not be handled by this set of key bindings.
  11534. */
  11535. isCtrlKeyCommand: function isCtrlKeyCommand(e) {
  11536. return !!e.ctrlKey && !e.altKey;
  11537. },
  11538. isOptionKeyCommand: function isOptionKeyCommand(e) {
  11539. return isOSX && e.altKey;
  11540. },
  11541. hasCommandModifier: function hasCommandModifier(e) {
  11542. return isOSX ? !!e.metaKey && !e.altKey : KeyBindingUtil.isCtrlKeyCommand(e);
  11543. }
  11544. };
  11545. var KeyBindingUtil_1 = KeyBindingUtil;
  11546. var clipboard = null;
  11547. /**
  11548. * Some systems offer a "secondary" clipboard to allow quick internal cut
  11549. * and paste behavior. For instance, Ctrl+K (cut) and Ctrl+Y (paste).
  11550. */
  11551. var SecondaryClipboard = {
  11552. cut: function cut(editorState) {
  11553. var content = editorState.getCurrentContent();
  11554. var selection = editorState.getSelection();
  11555. var targetRange = null;
  11556. if (selection.isCollapsed()) {
  11557. var anchorKey = selection.getAnchorKey();
  11558. var blockEnd = content.getBlockForKey(anchorKey).getLength();
  11559. if (blockEnd === selection.getAnchorOffset()) {
  11560. return editorState;
  11561. }
  11562. targetRange = selection.set('focusOffset', blockEnd);
  11563. } else {
  11564. targetRange = selection;
  11565. }
  11566. targetRange = nullthrows_1(targetRange);
  11567. clipboard = getContentStateFragment_1(content, targetRange);
  11568. var afterRemoval = DraftModifier_1.removeRange(content, targetRange, 'forward');
  11569. if (afterRemoval === content) {
  11570. return editorState;
  11571. }
  11572. return EditorState_1.push(editorState, afterRemoval, 'remove-range');
  11573. },
  11574. paste: function paste(editorState) {
  11575. if (!clipboard) {
  11576. return editorState;
  11577. }
  11578. var newContent = DraftModifier_1.replaceWithFragment(editorState.getCurrentContent(), editorState.getSelection(), clipboard);
  11579. return EditorState_1.push(editorState, newContent, 'insert-fragment');
  11580. }
  11581. };
  11582. var SecondaryClipboard_1 = SecondaryClipboard;
  11583. // These two ranges are consecutive so anything in [HIGH_START, LOW_END] is a
  11584. // surrogate code unit.
  11585. var SURROGATE_HIGH_START = 0xD800;
  11586. var SURROGATE_HIGH_END = 0xDBFF;
  11587. var SURROGATE_LOW_START = 0xDC00;
  11588. var SURROGATE_LOW_END = 0xDFFF;
  11589. var SURROGATE_UNITS_REGEX = /[\uD800-\uDFFF]/;
  11590. /**
  11591. * @param {number} codeUnit A Unicode code-unit, in range [0, 0x10FFFF]
  11592. * @return {boolean} Whether code-unit is in a surrogate (hi/low) range
  11593. */
  11594. function isCodeUnitInSurrogateRange(codeUnit) {
  11595. return SURROGATE_HIGH_START <= codeUnit && codeUnit <= SURROGATE_LOW_END;
  11596. }
  11597. /**
  11598. * Returns whether the two characters starting at `index` form a surrogate pair.
  11599. * For example, given the string s = "\uD83D\uDE0A", (s, 0) returns true and
  11600. * (s, 1) returns false.
  11601. *
  11602. * @param {string} str
  11603. * @param {number} index
  11604. * @return {boolean}
  11605. */
  11606. function isSurrogatePair(str, index) {
  11607. !(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;
  11608. if (index + 1 === str.length) {
  11609. return false;
  11610. }
  11611. var first = str.charCodeAt(index);
  11612. var second = str.charCodeAt(index + 1);
  11613. return SURROGATE_HIGH_START <= first && first <= SURROGATE_HIGH_END && SURROGATE_LOW_START <= second && second <= SURROGATE_LOW_END;
  11614. }
  11615. /**
  11616. * @param {string} str Non-empty string
  11617. * @return {boolean} True if the input includes any surrogate code units
  11618. */
  11619. function hasSurrogateUnit(str) {
  11620. return SURROGATE_UNITS_REGEX.test(str);
  11621. }
  11622. /**
  11623. * Return the length of the original Unicode character at given position in the
  11624. * String by looking into the UTF-16 code unit; that is equal to 1 for any
  11625. * non-surrogate characters in BMP ([U+0000..U+D7FF] and [U+E000, U+FFFF]); and
  11626. * returns 2 for the hi/low surrogates ([U+D800..U+DFFF]), which are in fact
  11627. * representing non-BMP characters ([U+10000..U+10FFFF]).
  11628. *
  11629. * Examples:
  11630. * - '\u0020' => 1
  11631. * - '\u3020' => 1
  11632. * - '\uD835' => 2
  11633. * - '\uD835\uDDEF' => 2
  11634. * - '\uDDEF' => 2
  11635. *
  11636. * @param {string} str Non-empty string
  11637. * @param {number} pos Position in the string to look for one code unit
  11638. * @return {number} Number 1 or 2
  11639. */
  11640. function getUTF16Length(str, pos) {
  11641. return 1 + isCodeUnitInSurrogateRange(str.charCodeAt(pos));
  11642. }
  11643. /**
  11644. * Fully Unicode-enabled replacement for String#length
  11645. *
  11646. * @param {string} str Valid Unicode string
  11647. * @return {number} The number of Unicode characters in the string
  11648. */
  11649. function strlen(str) {
  11650. // Call the native functions if there's no surrogate char
  11651. if (!hasSurrogateUnit(str)) {
  11652. return str.length;
  11653. }
  11654. var len = 0;
  11655. for (var pos = 0; pos < str.length; pos += getUTF16Length(str, pos)) {
  11656. len++;
  11657. }
  11658. return len;
  11659. }
  11660. /**
  11661. * Fully Unicode-enabled replacement for String#substr()
  11662. *
  11663. * @param {string} str Valid Unicode string
  11664. * @param {number} start Location in Unicode sequence to begin extracting
  11665. * @param {?number} length The number of Unicode characters to extract
  11666. * (default: to the end of the string)
  11667. * @return {string} Extracted sub-string
  11668. */
  11669. function substr(str, start, length) {
  11670. start = start || 0;
  11671. length = length === undefined ? Infinity : length || 0;
  11672. // Call the native functions if there's no surrogate char
  11673. if (!hasSurrogateUnit(str)) {
  11674. return str.substr(start, length);
  11675. }
  11676. // Obvious cases
  11677. var size = str.length;
  11678. if (size <= 0 || start > size || length <= 0) {
  11679. return '';
  11680. }
  11681. // Find the actual starting position
  11682. var posA = 0;
  11683. if (start > 0) {
  11684. for (; start > 0 && posA < size; start--) {
  11685. posA += getUTF16Length(str, posA);
  11686. }
  11687. if (posA >= size) {
  11688. return '';
  11689. }
  11690. } else if (start < 0) {
  11691. for (posA = size; start < 0 && 0 < posA; start++) {
  11692. posA -= getUTF16Length(str, posA - 1);
  11693. }
  11694. if (posA < 0) {
  11695. posA = 0;
  11696. }
  11697. }
  11698. // Find the actual ending position
  11699. var posB = size;
  11700. if (length < size) {
  11701. for (posB = posA; length > 0 && posB < size; length--) {
  11702. posB += getUTF16Length(str, posB);
  11703. }
  11704. }
  11705. return str.substring(posA, posB);
  11706. }
  11707. /**
  11708. * Fully Unicode-enabled replacement for String#substring()
  11709. *
  11710. * @param {string} str Valid Unicode string
  11711. * @param {number} start Location in Unicode sequence to begin extracting
  11712. * @param {?number} end Location in Unicode sequence to end extracting
  11713. * (default: end of the string)
  11714. * @return {string} Extracted sub-string
  11715. */
  11716. function substring(str, start, end) {
  11717. start = start || 0;
  11718. end = end === undefined ? Infinity : end || 0;
  11719. if (start < 0) {
  11720. start = 0;
  11721. }
  11722. if (end < 0) {
  11723. end = 0;
  11724. }
  11725. var length = Math.abs(end - start);
  11726. start = start < end ? start : end;
  11727. return substr(str, start, length);
  11728. }
  11729. /**
  11730. * Get a list of Unicode code-points from a String
  11731. *
  11732. * @param {string} str Valid Unicode string
  11733. * @return {array<number>} A list of code-points in [0..0x10FFFF]
  11734. */
  11735. function getCodePoints(str) {
  11736. var codePoints = [];
  11737. for (var pos = 0; pos < str.length; pos += getUTF16Length(str, pos)) {
  11738. codePoints.push(str.codePointAt(pos));
  11739. }
  11740. return codePoints;
  11741. }
  11742. var UnicodeUtils = {
  11743. getCodePoints: getCodePoints,
  11744. getUTF16Length: getUTF16Length,
  11745. hasSurrogateUnit: hasSurrogateUnit,
  11746. isCodeUnitInSurrogateRange: isCodeUnitInSurrogateRange,
  11747. isSurrogatePair: isSurrogatePair,
  11748. strlen: strlen,
  11749. substring: substring,
  11750. substr: substr
  11751. };
  11752. var UnicodeUtils_1 = UnicodeUtils;
  11753. var isChrome = UserAgent_1.isBrowser('Chrome');
  11754. // In Chrome, the client rects will include the entire bounds of all nodes that
  11755. // begin (have a start tag) within the selection, even if the selection does
  11756. // not overlap the entire node. To resolve this, we split the range at each
  11757. // start tag and join the client rects together.
  11758. // https://code.google.com/p/chromium/issues/detail?id=324437
  11759. /* eslint-disable consistent-return */
  11760. function getRangeClientRectsChrome(range) {
  11761. var tempRange = range.cloneRange();
  11762. var clientRects = [];
  11763. for (var ancestor = range.endContainer; ancestor != null; ancestor = ancestor.parentNode) {
  11764. // If we've climbed up to the common ancestor, we can now use the
  11765. // original start point and stop climbing the tree.
  11766. var atCommonAncestor = ancestor === range.commonAncestorContainer;
  11767. if (atCommonAncestor) {
  11768. tempRange.setStart(range.startContainer, range.startOffset);
  11769. } else {
  11770. tempRange.setStart(tempRange.endContainer, 0);
  11771. }
  11772. var rects = Array.from(tempRange.getClientRects());
  11773. clientRects.push(rects);
  11774. if (atCommonAncestor) {
  11775. var _ref;
  11776. clientRects.reverse();
  11777. return (_ref = []).concat.apply(_ref, clientRects);
  11778. }
  11779. tempRange.setEndBefore(ancestor);
  11780. }
  11781. process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Found an unexpected detached subtree when getting range client rects.') : invariant_1(false) ;
  11782. }
  11783. /* eslint-enable consistent-return */
  11784. /**
  11785. * Like range.getClientRects() but normalizes for browser bugs.
  11786. */
  11787. var getRangeClientRects = isChrome ? getRangeClientRectsChrome : function (range) {
  11788. return Array.from(range.getClientRects());
  11789. };
  11790. var getRangeClientRects_1 = getRangeClientRects;
  11791. /**
  11792. * Copyright (c) 2013-present, Facebook, Inc.
  11793. * All rights reserved.
  11794. *
  11795. * This source code is licensed under the BSD-style license found in the
  11796. * LICENSE file in the root directory of this source tree. An additional grant
  11797. * of patent rights can be found in the PATENTS file in the same directory.
  11798. *
  11799. * @providesModule expandRangeToStartOfLine
  11800. * @format
  11801. *
  11802. */
  11803. /**
  11804. * Return the computed line height, in pixels, for the provided element.
  11805. */
  11806. function getLineHeightPx(element) {
  11807. var computed = getComputedStyle(element);
  11808. var div = document.createElement('div');
  11809. div.style.fontFamily = computed.fontFamily;
  11810. div.style.fontSize = computed.fontSize;
  11811. div.style.fontStyle = computed.fontStyle;
  11812. div.style.fontWeight = computed.fontWeight;
  11813. div.style.lineHeight = computed.lineHeight;
  11814. div.style.position = 'absolute';
  11815. div.textContent = 'M';
  11816. var documentBody = document.body;
  11817. !documentBody ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing document.body') : invariant_1(false) : void 0;
  11818. // forced layout here
  11819. documentBody.appendChild(div);
  11820. var rect = div.getBoundingClientRect();
  11821. documentBody.removeChild(div);
  11822. return rect.height;
  11823. }
  11824. /**
  11825. * Return whether every ClientRect in the provided list lies on the same line.
  11826. *
  11827. * We assume that the rects on the same line all contain the baseline, so the
  11828. * lowest top line needs to be above the highest bottom line (i.e., if you were
  11829. * to project the rects onto the y-axis, their intersection would be nonempty).
  11830. *
  11831. * In addition, we require that no two boxes are lineHeight (or more) apart at
  11832. * either top or bottom, which helps protect against false positives for fonts
  11833. * with extremely large glyph heights (e.g., with a font size of 17px, Zapfino
  11834. * produces rects of height 58px!).
  11835. */
  11836. function areRectsOnOneLine(rects, lineHeight) {
  11837. var minTop = Infinity;
  11838. var minBottom = Infinity;
  11839. var maxTop = -Infinity;
  11840. var maxBottom = -Infinity;
  11841. for (var ii = 0; ii < rects.length; ii++) {
  11842. var rect = rects[ii];
  11843. if (rect.width === 0 || rect.width === 1) {
  11844. // When a range starts or ends a soft wrap, many browsers (Chrome, IE,
  11845. // Safari) include an empty rect on the previous or next line. When the
  11846. // text lies in a container whose position is not integral (e.g., from
  11847. // margin: auto), Safari makes these empty rects have width 1 (instead of
  11848. // 0). Having one-pixel-wide characters seems unlikely (and most browsers
  11849. // report widths in subpixel precision anyway) so it's relatively safe to
  11850. // skip over them.
  11851. continue;
  11852. }
  11853. minTop = Math.min(minTop, rect.top);
  11854. minBottom = Math.min(minBottom, rect.bottom);
  11855. maxTop = Math.max(maxTop, rect.top);
  11856. maxBottom = Math.max(maxBottom, rect.bottom);
  11857. }
  11858. return maxTop <= minBottom && maxTop - minTop < lineHeight && maxBottom - minBottom < lineHeight;
  11859. }
  11860. /**
  11861. * Return the length of a node, as used by Range offsets.
  11862. */
  11863. function getNodeLength$1(node) {
  11864. // http://www.w3.org/TR/dom/#concept-node-length
  11865. switch (node.nodeType) {
  11866. case Node.DOCUMENT_TYPE_NODE:
  11867. return 0;
  11868. case Node.TEXT_NODE:
  11869. case Node.PROCESSING_INSTRUCTION_NODE:
  11870. case Node.COMMENT_NODE:
  11871. return node.length;
  11872. default:
  11873. return node.childNodes.length;
  11874. }
  11875. }
  11876. /**
  11877. * Given a collapsed range, move the start position backwards as far as
  11878. * possible while the range still spans only a single line.
  11879. */
  11880. function expandRangeToStartOfLine(range) {
  11881. !range.collapsed ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'expandRangeToStartOfLine: Provided range is not collapsed.') : invariant_1(false) : void 0;
  11882. range = range.cloneRange();
  11883. var containingElement = range.startContainer;
  11884. if (containingElement.nodeType !== 1) {
  11885. containingElement = containingElement.parentNode;
  11886. }
  11887. var lineHeight = getLineHeightPx(containingElement);
  11888. // Imagine our text looks like:
  11889. // <div><span>once upon a time, there was a <em>boy
  11890. // who lived</em> </span><q><strong>under^ the
  11891. // stairs</strong> in a small closet.</q></div>
  11892. // where the caret represents the cursor. First, we crawl up the tree until
  11893. // the range spans multiple lines (setting the start point to before
  11894. // "<strong>", then before "<div>"), then at each level we do a search to
  11895. // find the latest point which is still on a previous line. We'll find that
  11896. // the break point is inside the span, then inside the <em>, then in its text
  11897. // node child, the actual break point before "who".
  11898. var bestContainer = range.endContainer;
  11899. var bestOffset = range.endOffset;
  11900. range.setStart(range.startContainer, 0);
  11901. while (areRectsOnOneLine(getRangeClientRects_1(range), lineHeight)) {
  11902. bestContainer = range.startContainer;
  11903. bestOffset = range.startOffset;
  11904. !bestContainer.parentNode ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Found unexpected detached subtree when traversing.') : invariant_1(false) : void 0;
  11905. range.setStartBefore(bestContainer);
  11906. if (bestContainer.nodeType === 1 && getComputedStyle(bestContainer).display !== 'inline') {
  11907. // The start of the line is never in a different block-level container.
  11908. break;
  11909. }
  11910. }
  11911. // In the above example, range now spans from "<div>" to "under",
  11912. // bestContainer is <div>, and bestOffset is 1 (index of <q> inside <div>)].
  11913. // Picking out which child to recurse into here is a special case since we
  11914. // don't want to check past <q> -- once we find that the final range starts
  11915. // in <span>, we can look at all of its children (and all of their children)
  11916. // to find the break point.
  11917. // At all times, (bestContainer, bestOffset) is the latest single-line start
  11918. // point that we know of.
  11919. var currentContainer = bestContainer;
  11920. var maxIndexToConsider = bestOffset - 1;
  11921. do {
  11922. var nodeValue = currentContainer.nodeValue;
  11923. for (var ii = maxIndexToConsider; ii >= 0; ii--) {
  11924. if (nodeValue != null && ii > 0 && UnicodeUtils_1.isSurrogatePair(nodeValue, ii - 1)) {
  11925. // We're in the middle of a surrogate pair -- skip over so we never
  11926. // return a range with an endpoint in the middle of a code point.
  11927. continue;
  11928. }
  11929. range.setStart(currentContainer, ii);
  11930. if (areRectsOnOneLine(getRangeClientRects_1(range), lineHeight)) {
  11931. bestContainer = currentContainer;
  11932. bestOffset = ii;
  11933. } else {
  11934. break;
  11935. }
  11936. }
  11937. if (ii === -1 || currentContainer.childNodes.length === 0) {
  11938. // If ii === -1, then (bestContainer, bestOffset), which is equal to
  11939. // (currentContainer, 0), was a single-line start point but a start
  11940. // point before currentContainer wasn't, so the line break seems to
  11941. // have occurred immediately after currentContainer's start tag
  11942. //
  11943. // If currentContainer.childNodes.length === 0, we're already at a
  11944. // terminal node (e.g., text node) and should return our current best.
  11945. break;
  11946. }
  11947. currentContainer = currentContainer.childNodes[ii];
  11948. maxIndexToConsider = getNodeLength$1(currentContainer);
  11949. } while (true);
  11950. range.setStart(bestContainer, bestOffset);
  11951. return range;
  11952. }
  11953. var expandRangeToStartOfLine_1 = expandRangeToStartOfLine;
  11954. /**
  11955. * Convert the current selection range to an anchor/focus pair of offset keys
  11956. * and values that can be interpreted by components.
  11957. */
  11958. function getDraftEditorSelectionWithNodes(editorState, root, anchorNode, anchorOffset, focusNode, focusOffset) {
  11959. var anchorIsTextNode = anchorNode.nodeType === Node.TEXT_NODE;
  11960. var focusIsTextNode = focusNode.nodeType === Node.TEXT_NODE;
  11961. // If the selection range lies only on text nodes, the task is simple.
  11962. // Find the nearest offset-aware elements and use the
  11963. // offset values supplied by the selection range.
  11964. if (anchorIsTextNode && focusIsTextNode) {
  11965. return {
  11966. selectionState: getUpdatedSelectionState_1(editorState, nullthrows_1(findAncestorOffsetKey_1(anchorNode)), anchorOffset, nullthrows_1(findAncestorOffsetKey_1(focusNode)), focusOffset),
  11967. needsRecovery: false
  11968. };
  11969. }
  11970. var anchorPoint = null;
  11971. var focusPoint = null;
  11972. var needsRecovery = true;
  11973. // An element is selected. Convert this selection range into leaf offset
  11974. // keys and offset values for consumption at the component level. This
  11975. // is common in Firefox, where select-all and triple click behavior leads
  11976. // to entire elements being selected.
  11977. //
  11978. // Note that we use the `needsRecovery` parameter in the callback here. This
  11979. // is because when certain elements are selected, the behavior for subsequent
  11980. // cursor movement (e.g. via arrow keys) is uncertain and may not match
  11981. // expectations at the component level. For example, if an entire <div> is
  11982. // selected and the user presses the right arrow, Firefox keeps the selection
  11983. // on the <div>. If we allow subsequent keypresses to insert characters
  11984. // natively, they will be inserted into a browser-created text node to the
  11985. // right of that <div>. This is obviously undesirable.
  11986. //
  11987. // With the `needsRecovery` flag, we inform the caller that it is responsible
  11988. // for manually setting the selection state on the rendered document to
  11989. // ensure proper selection state maintenance.
  11990. if (anchorIsTextNode) {
  11991. anchorPoint = {
  11992. key: nullthrows_1(findAncestorOffsetKey_1(anchorNode)),
  11993. offset: anchorOffset
  11994. };
  11995. focusPoint = getPointForNonTextNode(root, focusNode, focusOffset);
  11996. } else if (focusIsTextNode) {
  11997. focusPoint = {
  11998. key: nullthrows_1(findAncestorOffsetKey_1(focusNode)),
  11999. offset: focusOffset
  12000. };
  12001. anchorPoint = getPointForNonTextNode(root, anchorNode, anchorOffset);
  12002. } else {
  12003. anchorPoint = getPointForNonTextNode(root, anchorNode, anchorOffset);
  12004. focusPoint = getPointForNonTextNode(root, focusNode, focusOffset);
  12005. // If the selection is collapsed on an empty block, don't force recovery.
  12006. // This way, on arrow key selection changes, the browser can move the
  12007. // cursor from a non-zero offset on one block, through empty blocks,
  12008. // to a matching non-zero offset on other text blocks.
  12009. if (anchorNode === focusNode && anchorOffset === focusOffset) {
  12010. needsRecovery = !!anchorNode.firstChild && anchorNode.firstChild.nodeName !== 'BR';
  12011. }
  12012. }
  12013. return {
  12014. selectionState: getUpdatedSelectionState_1(editorState, anchorPoint.key, anchorPoint.offset, focusPoint.key, focusPoint.offset),
  12015. needsRecovery: needsRecovery
  12016. };
  12017. }
  12018. /**
  12019. * Identify the first leaf descendant for the given node.
  12020. */
  12021. function getFirstLeaf(node) {
  12022. while (node.firstChild && (
  12023. // data-blocks has no offset
  12024. node.firstChild instanceof Element && node.firstChild.getAttribute('data-blocks') === 'true' || getSelectionOffsetKeyForNode_1(node.firstChild))) {
  12025. node = node.firstChild;
  12026. }
  12027. return node;
  12028. }
  12029. /**
  12030. * Identify the last leaf descendant for the given node.
  12031. */
  12032. function getLastLeaf(node) {
  12033. while (node.lastChild && (
  12034. // data-blocks has no offset
  12035. node.lastChild instanceof Element && node.lastChild.getAttribute('data-blocks') === 'true' || getSelectionOffsetKeyForNode_1(node.lastChild))) {
  12036. node = node.lastChild;
  12037. }
  12038. return node;
  12039. }
  12040. function getPointForNonTextNode(editorRoot, startNode, childOffset) {
  12041. var node = startNode;
  12042. var offsetKey = findAncestorOffsetKey_1(node);
  12043. !(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;
  12044. // If the editorRoot is the selection, step downward into the content
  12045. // wrapper.
  12046. if (editorRoot === node) {
  12047. node = node.firstChild;
  12048. !(node instanceof Element && node.getAttribute('data-contents') === 'true') ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Invalid DraftEditorContents structure.') : invariant_1(false) : void 0;
  12049. if (childOffset > 0) {
  12050. childOffset = node.childNodes.length;
  12051. }
  12052. }
  12053. // If the child offset is zero and we have an offset key, we're done.
  12054. // If there's no offset key because the entire editor is selected,
  12055. // find the leftmost ("first") leaf in the tree and use that as the offset
  12056. // key.
  12057. if (childOffset === 0) {
  12058. var key = null;
  12059. if (offsetKey != null) {
  12060. key = offsetKey;
  12061. } else {
  12062. var firstLeaf = getFirstLeaf(node);
  12063. key = nullthrows_1(getSelectionOffsetKeyForNode_1(firstLeaf));
  12064. }
  12065. return { key: key, offset: 0 };
  12066. }
  12067. var nodeBeforeCursor = node.childNodes[childOffset - 1];
  12068. var leafKey = null;
  12069. var textLength = null;
  12070. if (!getSelectionOffsetKeyForNode_1(nodeBeforeCursor)) {
  12071. // Our target node may be a leaf or a text node, in which case we're
  12072. // already where we want to be and can just use the child's length as
  12073. // our offset.
  12074. leafKey = nullthrows_1(offsetKey);
  12075. textLength = getTextContentLength(nodeBeforeCursor);
  12076. } else {
  12077. // Otherwise, we'll look at the child to the left of the cursor and find
  12078. // the last leaf node in its subtree.
  12079. var lastLeaf = getLastLeaf(nodeBeforeCursor);
  12080. leafKey = nullthrows_1(getSelectionOffsetKeyForNode_1(lastLeaf));
  12081. textLength = getTextContentLength(lastLeaf);
  12082. }
  12083. return {
  12084. key: leafKey,
  12085. offset: textLength
  12086. };
  12087. }
  12088. /**
  12089. * Return the length of a node's textContent, regarding single newline
  12090. * characters as zero-length. This allows us to avoid problems with identifying
  12091. * the correct selection offset for empty blocks in IE, in which we
  12092. * render newlines instead of break tags.
  12093. */
  12094. function getTextContentLength(node) {
  12095. var textContent = node.textContent;
  12096. return textContent === '\n' ? 0 : textContent.length;
  12097. }
  12098. var getDraftEditorSelectionWithNodes_1 = getDraftEditorSelectionWithNodes;
  12099. /**
  12100. * Copyright (c) 2013-present, Facebook, Inc.
  12101. * All rights reserved.
  12102. *
  12103. * This source code is licensed under the BSD-style license found in the
  12104. * LICENSE file in the root directory of this source tree. An additional grant
  12105. * of patent rights can be found in the PATENTS file in the same directory.
  12106. *
  12107. * @providesModule moveSelectionBackward
  12108. * @format
  12109. *
  12110. */
  12111. /**
  12112. * Given a collapsed selection, move the focus `maxDistance` backward within
  12113. * the selected block. If the selection will go beyond the start of the block,
  12114. * move focus to the end of the previous block, but no further.
  12115. *
  12116. * This function is not Unicode-aware, so surrogate pairs will be treated
  12117. * as having length 2.
  12118. */
  12119. function moveSelectionBackward(editorState, maxDistance) {
  12120. var selection = editorState.getSelection();
  12121. var content = editorState.getCurrentContent();
  12122. var key = selection.getStartKey();
  12123. var offset = selection.getStartOffset();
  12124. var focusKey = key;
  12125. var focusOffset = 0;
  12126. if (maxDistance > offset) {
  12127. var keyBefore = content.getKeyBefore(key);
  12128. if (keyBefore == null) {
  12129. focusKey = key;
  12130. } else {
  12131. focusKey = keyBefore;
  12132. var blockBefore = content.getBlockForKey(keyBefore);
  12133. focusOffset = blockBefore.getText().length;
  12134. }
  12135. } else {
  12136. focusOffset = offset - maxDistance;
  12137. }
  12138. return selection.merge({
  12139. focusKey: focusKey,
  12140. focusOffset: focusOffset,
  12141. isBackward: true
  12142. });
  12143. }
  12144. var moveSelectionBackward_1 = moveSelectionBackward;
  12145. /**
  12146. * For a collapsed selection state, remove text based on the specified strategy.
  12147. * If the selection state is not collapsed, remove the entire selected range.
  12148. */
  12149. function removeTextWithStrategy(editorState, strategy, direction) {
  12150. var selection = editorState.getSelection();
  12151. var content = editorState.getCurrentContent();
  12152. var target = selection;
  12153. if (selection.isCollapsed()) {
  12154. if (direction === 'forward') {
  12155. if (editorState.isSelectionAtEndOfContent()) {
  12156. return content;
  12157. }
  12158. } else if (editorState.isSelectionAtStartOfContent()) {
  12159. return content;
  12160. }
  12161. target = strategy(editorState);
  12162. if (target === selection) {
  12163. return content;
  12164. }
  12165. }
  12166. return DraftModifier_1.removeRange(content, target, direction);
  12167. }
  12168. var removeTextWithStrategy_1 = removeTextWithStrategy;
  12169. function keyCommandBackspaceToStartOfLine(editorState) {
  12170. var afterRemoval = removeTextWithStrategy_1(editorState, function (strategyState) {
  12171. var selection = strategyState.getSelection();
  12172. if (selection.isCollapsed() && selection.getAnchorOffset() === 0) {
  12173. return moveSelectionBackward_1(strategyState, 1);
  12174. }
  12175. var domSelection = commonjsGlobal.getSelection();
  12176. var range = domSelection.getRangeAt(0);
  12177. range = expandRangeToStartOfLine_1(range);
  12178. return getDraftEditorSelectionWithNodes_1(strategyState, null, range.endContainer, range.endOffset, range.startContainer, range.startOffset).selectionState;
  12179. }, 'backward');
  12180. if (afterRemoval === editorState.getCurrentContent()) {
  12181. return editorState;
  12182. }
  12183. return EditorState_1.push(editorState, afterRemoval, 'remove-range');
  12184. }
  12185. var keyCommandBackspaceToStartOfLine_1 = keyCommandBackspaceToStartOfLine;
  12186. /**
  12187. * Copyright (c) 2013-present, Facebook, Inc.
  12188. *
  12189. * This source code is licensed under the MIT license found in the
  12190. * LICENSE file in the root directory of this source tree.
  12191. *
  12192. * @typechecks
  12193. * @stub
  12194. *
  12195. */
  12196. // \u00a1-\u00b1\u00b4-\u00b8\u00ba\u00bb\u00bf
  12197. // is latin supplement punctuation except fractions and superscript
  12198. // numbers
  12199. // \u2010-\u2027\u2030-\u205e
  12200. // is punctuation from the general punctuation block:
  12201. // weird quotes, commas, bullets, dashes, etc.
  12202. // \u30fb\u3001\u3002\u3008-\u3011\u3014-\u301f
  12203. // is CJK punctuation
  12204. // \uff1a-\uff1f\uff01-\uff0f\uff3b-\uff40\uff5b-\uff65
  12205. // is some full-width/half-width punctuation
  12206. // \u2E2E\u061f\u066a-\u066c\u061b\u060c\u060d\uFD3e\uFD3F
  12207. // is some Arabic punctuation marks
  12208. // \u1801\u0964\u104a\u104b
  12209. // is misc. other language punctuation marks
  12210. 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]';
  12211. var TokenizeUtil = {
  12212. getPunctuation: function getPunctuation() {
  12213. return PUNCTUATION;
  12214. }
  12215. };
  12216. var punctuation = TokenizeUtil.getPunctuation();
  12217. // The apostrophe and curly single quotes behave in a curious way: when
  12218. // surrounded on both sides by word characters, they behave as word chars; when
  12219. // either neighbor is punctuation or an end of the string, they behave as
  12220. // punctuation.
  12221. var CHAMELEON_CHARS = '[\'\u2018\u2019]';
  12222. // Remove the underscore, which should count as part of the removable word. The
  12223. // "chameleon chars" also count as punctuation in this regex.
  12224. var WHITESPACE_AND_PUNCTUATION = '\\s|(?![_])' + punctuation;
  12225. var DELETE_STRING = '^' + '(?:' + WHITESPACE_AND_PUNCTUATION + ')*' + '(?:' + CHAMELEON_CHARS + '|(?!' + WHITESPACE_AND_PUNCTUATION + ').)*' + '(?:(?!' + WHITESPACE_AND_PUNCTUATION + ').)';
  12226. var DELETE_REGEX = new RegExp(DELETE_STRING);
  12227. var BACKSPACE_STRING = '(?:(?!' + WHITESPACE_AND_PUNCTUATION + ').)' + '(?:' + CHAMELEON_CHARS + '|(?!' + WHITESPACE_AND_PUNCTUATION + ').)*' + '(?:' + WHITESPACE_AND_PUNCTUATION + ')*' + '$';
  12228. var BACKSPACE_REGEX = new RegExp(BACKSPACE_STRING);
  12229. function getRemovableWord(text, isBackward) {
  12230. var matches = isBackward ? BACKSPACE_REGEX.exec(text) : DELETE_REGEX.exec(text);
  12231. return matches ? matches[0] : text;
  12232. }
  12233. var DraftRemovableWord = {
  12234. getBackward: function getBackward(text) {
  12235. return getRemovableWord(text, true);
  12236. },
  12237. getForward: function getForward(text) {
  12238. return getRemovableWord(text, false);
  12239. }
  12240. };
  12241. var DraftRemovableWord_1 = DraftRemovableWord;
  12242. /**
  12243. * Delete the word that is left of the cursor, as well as any spaces or
  12244. * punctuation after the word.
  12245. */
  12246. function keyCommandBackspaceWord(editorState) {
  12247. var afterRemoval = removeTextWithStrategy_1(editorState, function (strategyState) {
  12248. var selection = strategyState.getSelection();
  12249. var offset = selection.getStartOffset();
  12250. // If there are no words before the cursor, remove the preceding newline.
  12251. if (offset === 0) {
  12252. return moveSelectionBackward_1(strategyState, 1);
  12253. }
  12254. var key = selection.getStartKey();
  12255. var content = strategyState.getCurrentContent();
  12256. var text = content.getBlockForKey(key).getText().slice(0, offset);
  12257. var toRemove = DraftRemovableWord_1.getBackward(text);
  12258. return moveSelectionBackward_1(strategyState, toRemove.length || 1);
  12259. }, 'backward');
  12260. if (afterRemoval === editorState.getCurrentContent()) {
  12261. return editorState;
  12262. }
  12263. return EditorState_1.push(editorState, afterRemoval, 'remove-range');
  12264. }
  12265. var keyCommandBackspaceWord_1 = keyCommandBackspaceWord;
  12266. /**
  12267. * Copyright (c) 2013-present, Facebook, Inc.
  12268. * All rights reserved.
  12269. *
  12270. * This source code is licensed under the BSD-style license found in the
  12271. * LICENSE file in the root directory of this source tree. An additional grant
  12272. * of patent rights can be found in the PATENTS file in the same directory.
  12273. *
  12274. * @providesModule moveSelectionForward
  12275. * @format
  12276. *
  12277. */
  12278. /**
  12279. * Given a collapsed selection, move the focus `maxDistance` forward within
  12280. * the selected block. If the selection will go beyond the end of the block,
  12281. * move focus to the start of the next block, but no further.
  12282. *
  12283. * This function is not Unicode-aware, so surrogate pairs will be treated
  12284. * as having length 2.
  12285. */
  12286. function moveSelectionForward(editorState, maxDistance) {
  12287. var selection = editorState.getSelection();
  12288. var key = selection.getStartKey();
  12289. var offset = selection.getStartOffset();
  12290. var content = editorState.getCurrentContent();
  12291. var focusKey = key;
  12292. var focusOffset;
  12293. var block = content.getBlockForKey(key);
  12294. if (maxDistance > block.getText().length - offset) {
  12295. focusKey = content.getKeyAfter(key);
  12296. focusOffset = 0;
  12297. } else {
  12298. focusOffset = offset + maxDistance;
  12299. }
  12300. return selection.merge({ focusKey: focusKey, focusOffset: focusOffset });
  12301. }
  12302. var moveSelectionForward_1 = moveSelectionForward;
  12303. /**
  12304. * Delete the word that is right of the cursor, as well as any spaces or
  12305. * punctuation before the word.
  12306. */
  12307. function keyCommandDeleteWord(editorState) {
  12308. var afterRemoval = removeTextWithStrategy_1(editorState, function (strategyState) {
  12309. var selection = strategyState.getSelection();
  12310. var offset = selection.getStartOffset();
  12311. var key = selection.getStartKey();
  12312. var content = strategyState.getCurrentContent();
  12313. var text = content.getBlockForKey(key).getText().slice(offset);
  12314. var toRemove = DraftRemovableWord_1.getForward(text);
  12315. // If there are no words in front of the cursor, remove the newline.
  12316. return moveSelectionForward_1(strategyState, toRemove.length || 1);
  12317. }, 'forward');
  12318. if (afterRemoval === editorState.getCurrentContent()) {
  12319. return editorState;
  12320. }
  12321. return EditorState_1.push(editorState, afterRemoval, 'remove-range');
  12322. }
  12323. var keyCommandDeleteWord_1 = keyCommandDeleteWord;
  12324. function keyCommandInsertNewline(editorState) {
  12325. var contentState = DraftModifier_1.splitBlock(editorState.getCurrentContent(), editorState.getSelection());
  12326. return EditorState_1.push(editorState, contentState, 'split-block');
  12327. }
  12328. var keyCommandInsertNewline_1 = keyCommandInsertNewline;
  12329. /**
  12330. * See comment for `moveSelectionToStartOfBlock`.
  12331. */
  12332. function keyCommandMoveSelectionToEndOfBlock(editorState) {
  12333. var selection = editorState.getSelection();
  12334. var endKey = selection.getEndKey();
  12335. var content = editorState.getCurrentContent();
  12336. var textLength = content.getBlockForKey(endKey).getLength();
  12337. return EditorState_1.set(editorState, {
  12338. selection: selection.merge({
  12339. anchorKey: endKey,
  12340. anchorOffset: textLength,
  12341. focusKey: endKey,
  12342. focusOffset: textLength,
  12343. isBackward: false
  12344. }),
  12345. forceSelection: true
  12346. });
  12347. }
  12348. var keyCommandMoveSelectionToEndOfBlock_1 = keyCommandMoveSelectionToEndOfBlock;
  12349. /**
  12350. * Collapse selection at the start of the first selected block. This is used
  12351. * for Firefox versions that attempt to navigate forward/backward instead of
  12352. * moving the cursor. Other browsers are able to move the cursor natively.
  12353. */
  12354. function keyCommandMoveSelectionToStartOfBlock(editorState) {
  12355. var selection = editorState.getSelection();
  12356. var startKey = selection.getStartKey();
  12357. return EditorState_1.set(editorState, {
  12358. selection: selection.merge({
  12359. anchorKey: startKey,
  12360. anchorOffset: 0,
  12361. focusKey: startKey,
  12362. focusOffset: 0,
  12363. isBackward: false
  12364. }),
  12365. forceSelection: true
  12366. });
  12367. }
  12368. var keyCommandMoveSelectionToStartOfBlock_1 = keyCommandMoveSelectionToStartOfBlock;
  12369. /**
  12370. * Remove the selected range. If the cursor is collapsed, remove the preceding
  12371. * character. This operation is Unicode-aware, so removing a single character
  12372. * will remove a surrogate pair properly as well.
  12373. */
  12374. function keyCommandPlainBackspace(editorState) {
  12375. var afterRemoval = removeTextWithStrategy_1(editorState, function (strategyState) {
  12376. var selection = strategyState.getSelection();
  12377. var content = strategyState.getCurrentContent();
  12378. var key = selection.getAnchorKey();
  12379. var offset = selection.getAnchorOffset();
  12380. var charBehind = content.getBlockForKey(key).getText()[offset - 1];
  12381. return moveSelectionBackward_1(strategyState, charBehind ? UnicodeUtils_1.getUTF16Length(charBehind, 0) : 1);
  12382. }, 'backward');
  12383. if (afterRemoval === editorState.getCurrentContent()) {
  12384. return editorState;
  12385. }
  12386. var selection = editorState.getSelection();
  12387. return EditorState_1.push(editorState, afterRemoval.set('selectionBefore', selection), selection.isCollapsed() ? 'backspace-character' : 'remove-range');
  12388. }
  12389. var keyCommandPlainBackspace_1 = keyCommandPlainBackspace;
  12390. /**
  12391. * Remove the selected range. If the cursor is collapsed, remove the following
  12392. * character. This operation is Unicode-aware, so removing a single character
  12393. * will remove a surrogate pair properly as well.
  12394. */
  12395. function keyCommandPlainDelete(editorState) {
  12396. var afterRemoval = removeTextWithStrategy_1(editorState, function (strategyState) {
  12397. var selection = strategyState.getSelection();
  12398. var content = strategyState.getCurrentContent();
  12399. var key = selection.getAnchorKey();
  12400. var offset = selection.getAnchorOffset();
  12401. var charAhead = content.getBlockForKey(key).getText()[offset];
  12402. return moveSelectionForward_1(strategyState, charAhead ? UnicodeUtils_1.getUTF16Length(charAhead, 0) : 1);
  12403. }, 'forward');
  12404. if (afterRemoval === editorState.getCurrentContent()) {
  12405. return editorState;
  12406. }
  12407. var selection = editorState.getSelection();
  12408. return EditorState_1.push(editorState, afterRemoval.set('selectionBefore', selection), selection.isCollapsed() ? 'delete-character' : 'remove-range');
  12409. }
  12410. var keyCommandPlainDelete_1 = keyCommandPlainDelete;
  12411. /**
  12412. * Transpose the characters on either side of a collapsed cursor, or
  12413. * if the cursor is at the end of the block, transpose the last two
  12414. * characters.
  12415. */
  12416. function keyCommandTransposeCharacters(editorState) {
  12417. var selection = editorState.getSelection();
  12418. if (!selection.isCollapsed()) {
  12419. return editorState;
  12420. }
  12421. var offset = selection.getAnchorOffset();
  12422. if (offset === 0) {
  12423. return editorState;
  12424. }
  12425. var blockKey = selection.getAnchorKey();
  12426. var content = editorState.getCurrentContent();
  12427. var block = content.getBlockForKey(blockKey);
  12428. var length = block.getLength();
  12429. // Nothing to transpose if there aren't two characters.
  12430. if (length <= 1) {
  12431. return editorState;
  12432. }
  12433. var removalRange;
  12434. var finalSelection;
  12435. if (offset === length) {
  12436. // The cursor is at the end of the block. Swap the last two characters.
  12437. removalRange = selection.set('anchorOffset', offset - 1);
  12438. finalSelection = selection;
  12439. } else {
  12440. removalRange = selection.set('focusOffset', offset + 1);
  12441. finalSelection = removalRange.set('anchorOffset', offset + 1);
  12442. }
  12443. // Extract the character to move as a fragment. This preserves its
  12444. // styling and entity, if any.
  12445. var movedFragment = getContentStateFragment_1(content, removalRange);
  12446. var afterRemoval = DraftModifier_1.removeRange(content, removalRange, 'backward');
  12447. // After the removal, the insertion target is one character back.
  12448. var selectionAfter = afterRemoval.getSelectionAfter();
  12449. var targetOffset = selectionAfter.getAnchorOffset() - 1;
  12450. var targetRange = selectionAfter.merge({
  12451. anchorOffset: targetOffset,
  12452. focusOffset: targetOffset
  12453. });
  12454. var afterInsert = DraftModifier_1.replaceWithFragment(afterRemoval, targetRange, movedFragment);
  12455. var newEditorState = EditorState_1.push(editorState, afterInsert, 'insert-fragment');
  12456. return EditorState_1.acceptSelection(newEditorState, finalSelection);
  12457. }
  12458. var keyCommandTransposeCharacters_1 = keyCommandTransposeCharacters;
  12459. function keyCommandUndo(e, editorState, updateFn) {
  12460. var undoneState = EditorState_1.undo(editorState);
  12461. // If the last change to occur was a spellcheck change, allow the undo
  12462. // event to fall through to the browser. This allows the browser to record
  12463. // the unwanted change, which should soon lead it to learn not to suggest
  12464. // the correction again.
  12465. if (editorState.getLastChangeType() === 'spellcheck-change') {
  12466. var nativelyRenderedContent = undoneState.getCurrentContent();
  12467. updateFn(EditorState_1.set(undoneState, { nativelyRenderedContent: nativelyRenderedContent }));
  12468. return;
  12469. }
  12470. // Otheriwse, manage the undo behavior manually.
  12471. e.preventDefault();
  12472. if (!editorState.getNativelyRenderedContent()) {
  12473. updateFn(undoneState);
  12474. return;
  12475. }
  12476. // Trigger a re-render with the current content state to ensure that the
  12477. // component tree has up-to-date props for comparison.
  12478. updateFn(EditorState_1.set(editorState, { nativelyRenderedContent: null }));
  12479. // Wait to ensure that the re-render has occurred before performing
  12480. // the undo action.
  12481. setTimeout(function () {
  12482. updateFn(undoneState);
  12483. }, 0);
  12484. }
  12485. var keyCommandUndo_1 = keyCommandUndo;
  12486. var isOptionKeyCommand = KeyBindingUtil_1.isOptionKeyCommand;
  12487. var isChrome$1 = UserAgent_1.isBrowser('Chrome');
  12488. /**
  12489. * Map a `DraftEditorCommand` command value to a corresponding function.
  12490. */
  12491. function onKeyCommand(command, editorState) {
  12492. switch (command) {
  12493. case 'redo':
  12494. return EditorState_1.redo(editorState);
  12495. case 'delete':
  12496. return keyCommandPlainDelete_1(editorState);
  12497. case 'delete-word':
  12498. return keyCommandDeleteWord_1(editorState);
  12499. case 'backspace':
  12500. return keyCommandPlainBackspace_1(editorState);
  12501. case 'backspace-word':
  12502. return keyCommandBackspaceWord_1(editorState);
  12503. case 'backspace-to-start-of-line':
  12504. return keyCommandBackspaceToStartOfLine_1(editorState);
  12505. case 'split-block':
  12506. return keyCommandInsertNewline_1(editorState);
  12507. case 'transpose-characters':
  12508. return keyCommandTransposeCharacters_1(editorState);
  12509. case 'move-selection-to-start-of-block':
  12510. return keyCommandMoveSelectionToStartOfBlock_1(editorState);
  12511. case 'move-selection-to-end-of-block':
  12512. return keyCommandMoveSelectionToEndOfBlock_1(editorState);
  12513. case 'secondary-cut':
  12514. return SecondaryClipboard_1.cut(editorState);
  12515. case 'secondary-paste':
  12516. return SecondaryClipboard_1.paste(editorState);
  12517. default:
  12518. return editorState;
  12519. }
  12520. }
  12521. /**
  12522. * Intercept keydown behavior to handle keys and commands manually, if desired.
  12523. *
  12524. * Keydown combinations may be mapped to `DraftCommand` values, which may
  12525. * correspond to command functions that modify the editor or its contents.
  12526. *
  12527. * See `getDefaultKeyBinding` for defaults. Alternatively, the top-level
  12528. * component may provide a custom mapping via the `keyBindingFn` prop.
  12529. */
  12530. function editOnKeyDown(editor, e) {
  12531. var keyCode = e.which;
  12532. var editorState = editor._latestEditorState;
  12533. switch (keyCode) {
  12534. case Keys.RETURN:
  12535. e.preventDefault();
  12536. // The top-level component may manually handle newline insertion. If
  12537. // no special handling is performed, fall through to command handling.
  12538. if (editor.props.handleReturn && isEventHandled_1(editor.props.handleReturn(e, editorState))) {
  12539. return;
  12540. }
  12541. break;
  12542. case Keys.ESC:
  12543. e.preventDefault();
  12544. editor.props.onEscape && editor.props.onEscape(e);
  12545. return;
  12546. case Keys.TAB:
  12547. editor.props.onTab && editor.props.onTab(e);
  12548. return;
  12549. case Keys.UP:
  12550. editor.props.onUpArrow && editor.props.onUpArrow(e);
  12551. return;
  12552. case Keys.RIGHT:
  12553. editor.props.onRightArrow && editor.props.onRightArrow(e);
  12554. return;
  12555. case Keys.DOWN:
  12556. editor.props.onDownArrow && editor.props.onDownArrow(e);
  12557. return;
  12558. case Keys.LEFT:
  12559. editor.props.onLeftArrow && editor.props.onLeftArrow(e);
  12560. return;
  12561. case Keys.SPACE:
  12562. // Handling for OSX where option + space scrolls.
  12563. if (isChrome$1 && isOptionKeyCommand(e)) {
  12564. e.preventDefault();
  12565. // Insert a nbsp into the editor.
  12566. var contentState = DraftModifier_1.replaceText(editorState.getCurrentContent(), editorState.getSelection(), '\xA0');
  12567. editor.update(EditorState_1.push(editorState, contentState, 'insert-characters'));
  12568. return;
  12569. }
  12570. }
  12571. var command = editor.props.keyBindingFn(e);
  12572. // If no command is specified, allow keydown event to continue.
  12573. if (!command) {
  12574. return;
  12575. }
  12576. if (command === 'undo') {
  12577. // Since undo requires some special updating behavior to keep the editor
  12578. // in sync, handle it separately.
  12579. keyCommandUndo_1(e, editorState, editor.update);
  12580. return;
  12581. }
  12582. // At this point, we know that we're handling a command of some kind, so
  12583. // we don't want to insert a character following the keydown.
  12584. e.preventDefault();
  12585. // Allow components higher up the tree to handle the command first.
  12586. if (editor.props.handleKeyCommand && isEventHandled_1(editor.props.handleKeyCommand(command, editorState))) {
  12587. return;
  12588. }
  12589. var newState = onKeyCommand(command, editorState);
  12590. if (newState !== editorState) {
  12591. editor.update(newState);
  12592. }
  12593. }
  12594. var editOnKeyDown_1 = editOnKeyDown;
  12595. /**
  12596. * Copyright (c) 2013-present, Facebook, Inc.
  12597. *
  12598. * This source code is licensed under the MIT license found in the
  12599. * LICENSE file in the root directory of this source tree.
  12600. *
  12601. *
  12602. */
  12603. function _classCallCheck$e(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  12604. var URI = function () {
  12605. function URI(uri) {
  12606. _classCallCheck$e(this, URI);
  12607. this._uri = uri;
  12608. }
  12609. URI.prototype.toString = function toString() {
  12610. return this._uri;
  12611. };
  12612. return URI;
  12613. }();
  12614. var URI_1 = URI;
  12615. var isOldIE = UserAgent_1.isBrowser('IE <= 9');
  12616. // Provides a dom node that will not execute scripts
  12617. // https://developer.mozilla.org/en-US/docs/Web/API/DOMImplementation.createHTMLDocument
  12618. // https://developer.mozilla.org/en-US/Add-ons/Code_snippets/HTML_to_DOM
  12619. function getSafeBodyFromHTML(html) {
  12620. var doc;
  12621. var root = null;
  12622. // Provides a safe context
  12623. if (!isOldIE && document.implementation && document.implementation.createHTMLDocument) {
  12624. doc = document.implementation.createHTMLDocument('foo');
  12625. !doc.documentElement ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing doc.documentElement') : invariant_1(false) : void 0;
  12626. doc.documentElement.innerHTML = html;
  12627. root = doc.getElementsByTagName('body')[0];
  12628. }
  12629. return root;
  12630. }
  12631. var getSafeBodyFromHTML_1 = getSafeBodyFromHTML;
  12632. 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; };
  12633. var _knownListItemDepthCl;
  12634. 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; }
  12635. var _require = immutable,
  12636. Set = _require.Set;
  12637. var experimentalTreeDataSupport = DraftFeatureFlags_1.draft_tree_data_support;
  12638. var List$a = immutable.List,
  12639. OrderedSet$5 = immutable.OrderedSet;
  12640. var NBSP = '&nbsp;';
  12641. var SPACE = ' ';
  12642. // Arbitrary max indent
  12643. var MAX_DEPTH = 4;
  12644. // used for replacing characters in HTML
  12645. var REGEX_CR = new RegExp('\r', 'g');
  12646. var REGEX_LF = new RegExp('\n', 'g');
  12647. var REGEX_NBSP = new RegExp(NBSP, 'g');
  12648. var REGEX_CARRIAGE = new RegExp('&#13;?', 'g');
  12649. var REGEX_ZWS = new RegExp('&#8203;?', 'g');
  12650. // https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight
  12651. var boldValues = ['bold', 'bolder', '500', '600', '700', '800', '900'];
  12652. var notBoldValues = ['light', 'lighter', '100', '200', '300', '400'];
  12653. // Block tag flow is different because LIs do not have
  12654. // a deterministic style ;_;
  12655. var inlineTags = {
  12656. b: 'BOLD',
  12657. code: 'CODE',
  12658. del: 'STRIKETHROUGH',
  12659. em: 'ITALIC',
  12660. i: 'ITALIC',
  12661. s: 'STRIKETHROUGH',
  12662. strike: 'STRIKETHROUGH',
  12663. strong: 'BOLD',
  12664. u: 'UNDERLINE'
  12665. };
  12666. 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);
  12667. var anchorAttr = ['className', 'href', 'rel', 'target', 'title'];
  12668. var imgAttr = ['alt', 'className', 'height', 'src', 'width'];
  12669. var lastBlock = void 0;
  12670. var EMPTY_CHUNK = {
  12671. text: '',
  12672. inlines: [],
  12673. entities: [],
  12674. blocks: []
  12675. };
  12676. var EMPTY_BLOCK = {
  12677. children: List$a(),
  12678. depth: 0,
  12679. key: '',
  12680. type: ''
  12681. };
  12682. var getListBlockType = function getListBlockType(tag, lastList) {
  12683. if (tag === 'li') {
  12684. return lastList === 'ol' ? 'ordered-list-item' : 'unordered-list-item';
  12685. }
  12686. return null;
  12687. };
  12688. var getBlockMapSupportedTags = function getBlockMapSupportedTags(blockRenderMap) {
  12689. var unstyledElement = blockRenderMap.get('unstyled').element;
  12690. var tags = Set([]);
  12691. blockRenderMap.forEach(function (draftBlock) {
  12692. if (draftBlock.aliasedElements) {
  12693. draftBlock.aliasedElements.forEach(function (tag) {
  12694. tags = tags.add(tag);
  12695. });
  12696. }
  12697. tags = tags.add(draftBlock.element);
  12698. });
  12699. return tags.filter(function (tag) {
  12700. return tag && tag !== unstyledElement;
  12701. }).toArray().sort();
  12702. };
  12703. // custom element conversions
  12704. var getMultiMatchedType = function getMultiMatchedType(tag, lastList, multiMatchExtractor) {
  12705. for (var ii = 0; ii < multiMatchExtractor.length; ii++) {
  12706. var matchType = multiMatchExtractor[ii](tag, lastList);
  12707. if (matchType) {
  12708. return matchType;
  12709. }
  12710. }
  12711. return null;
  12712. };
  12713. var getBlockTypeForTag = function getBlockTypeForTag(tag, lastList, blockRenderMap) {
  12714. var matchedTypes = blockRenderMap.filter(function (draftBlock) {
  12715. return draftBlock.element === tag || draftBlock.wrapper === tag || draftBlock.aliasedElements && draftBlock.aliasedElements.some(function (alias) {
  12716. return alias === tag;
  12717. });
  12718. }).keySeq().toSet().toArray().sort();
  12719. // if we dont have any matched type, return unstyled
  12720. // if we have one matched type return it
  12721. // if we have multi matched types use the multi-match function to gather type
  12722. switch (matchedTypes.length) {
  12723. case 0:
  12724. return 'unstyled';
  12725. case 1:
  12726. return matchedTypes[0];
  12727. default:
  12728. return getMultiMatchedType(tag, lastList, [getListBlockType]) || 'unstyled';
  12729. }
  12730. };
  12731. var processInlineTag = function processInlineTag(tag, node, currentStyle) {
  12732. var styleToCheck = inlineTags[tag];
  12733. if (styleToCheck) {
  12734. currentStyle = currentStyle.add(styleToCheck).toOrderedSet();
  12735. } else if (node instanceof HTMLElement) {
  12736. var htmlElement = node;
  12737. currentStyle = currentStyle.withMutations(function (style) {
  12738. var fontWeight = htmlElement.style.fontWeight;
  12739. var fontStyle = htmlElement.style.fontStyle;
  12740. var textDecoration = htmlElement.style.textDecoration;
  12741. if (boldValues.indexOf(fontWeight) >= 0) {
  12742. style.add('BOLD');
  12743. } else if (notBoldValues.indexOf(fontWeight) >= 0) {
  12744. style.remove('BOLD');
  12745. }
  12746. if (fontStyle === 'italic') {
  12747. style.add('ITALIC');
  12748. } else if (fontStyle === 'normal') {
  12749. style.remove('ITALIC');
  12750. }
  12751. if (textDecoration === 'underline') {
  12752. style.add('UNDERLINE');
  12753. }
  12754. if (textDecoration === 'line-through') {
  12755. style.add('STRIKETHROUGH');
  12756. }
  12757. if (textDecoration === 'none') {
  12758. style.remove('UNDERLINE');
  12759. style.remove('STRIKETHROUGH');
  12760. }
  12761. }).toOrderedSet();
  12762. }
  12763. return currentStyle;
  12764. };
  12765. var joinChunks = function joinChunks(A, B, experimentalHasNestedBlocks) {
  12766. // Sometimes two blocks will touch in the DOM and we need to strip the
  12767. // extra delimiter to preserve niceness.
  12768. var lastInA = A.text.slice(-1);
  12769. var firstInB = B.text.slice(0, 1);
  12770. if (lastInA === '\r' && firstInB === '\r' && !experimentalHasNestedBlocks) {
  12771. A.text = A.text.slice(0, -1);
  12772. A.inlines.pop();
  12773. A.entities.pop();
  12774. A.blocks.pop();
  12775. }
  12776. // Kill whitespace after blocks
  12777. if (lastInA === '\r') {
  12778. if (B.text === SPACE || B.text === '\n') {
  12779. return A;
  12780. } else if (firstInB === SPACE || firstInB === '\n') {
  12781. B.text = B.text.slice(1);
  12782. B.inlines.shift();
  12783. B.entities.shift();
  12784. }
  12785. }
  12786. return {
  12787. text: A.text + B.text,
  12788. inlines: A.inlines.concat(B.inlines),
  12789. entities: A.entities.concat(B.entities),
  12790. blocks: A.blocks.concat(B.blocks)
  12791. };
  12792. };
  12793. /**
  12794. * Check to see if we have anything like <p> <blockquote> <h1>... to create
  12795. * block tags from. If we do, we can use those and ignore <div> tags. If we
  12796. * don't, we can treat <div> tags as meaningful (unstyled) blocks.
  12797. */
  12798. var containsSemanticBlockMarkup = function containsSemanticBlockMarkup(html, blockTags) {
  12799. return blockTags.some(function (tag) {
  12800. return html.indexOf('<' + tag) !== -1;
  12801. });
  12802. };
  12803. var hasValidLinkText = function hasValidLinkText(link) {
  12804. !(link instanceof HTMLAnchorElement) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Link must be an HTMLAnchorElement.') : invariant_1(false) : void 0;
  12805. var protocol = link.protocol;
  12806. return protocol === 'http:' || protocol === 'https:' || protocol === 'mailto:';
  12807. };
  12808. var getWhitespaceChunk = function getWhitespaceChunk(inEntity) {
  12809. var entities = new Array(1);
  12810. if (inEntity) {
  12811. entities[0] = inEntity;
  12812. }
  12813. return _extends$4({}, EMPTY_CHUNK, {
  12814. text: SPACE,
  12815. inlines: [OrderedSet$5()],
  12816. entities: entities
  12817. });
  12818. };
  12819. var getSoftNewlineChunk = function getSoftNewlineChunk() {
  12820. return _extends$4({}, EMPTY_CHUNK, {
  12821. text: '\n',
  12822. inlines: [OrderedSet$5()],
  12823. entities: new Array(1)
  12824. });
  12825. };
  12826. var getChunkedBlock = function getChunkedBlock() {
  12827. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  12828. return _extends$4({}, EMPTY_BLOCK, props);
  12829. };
  12830. var getBlockDividerChunk = function getBlockDividerChunk(block, depth) {
  12831. var parentKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  12832. return {
  12833. text: '\r',
  12834. inlines: [OrderedSet$5()],
  12835. entities: new Array(1),
  12836. blocks: [getChunkedBlock({
  12837. parent: parentKey,
  12838. key: generateRandomKey_1(),
  12839. type: block,
  12840. depth: Math.max(0, Math.min(MAX_DEPTH, depth))
  12841. })]
  12842. };
  12843. };
  12844. /**
  12845. * If we're pasting from one DraftEditor to another we can check to see if
  12846. * existing list item depth classes are being used and preserve this style
  12847. */
  12848. var getListItemDepth = function getListItemDepth(node) {
  12849. var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  12850. Object.keys(knownListItemDepthClasses).some(function (depthClass) {
  12851. if (node.classList.contains(depthClass)) {
  12852. depth = knownListItemDepthClasses[depthClass];
  12853. }
  12854. });
  12855. return depth;
  12856. };
  12857. var genFragment = function genFragment(entityMap, node, inlineStyle, lastList, inBlock, blockTags, depth, blockRenderMap, inEntity, parentKey) {
  12858. var lastLastBlock = lastBlock;
  12859. var nodeName = node.nodeName.toLowerCase();
  12860. var newEntityMap = entityMap;
  12861. var nextBlockType = 'unstyled';
  12862. var newBlock = false;
  12863. var inBlockType = inBlock && getBlockTypeForTag(inBlock, lastList, blockRenderMap);
  12864. var chunk = _extends$4({}, EMPTY_CHUNK);
  12865. var newChunk = null;
  12866. var blockKey = void 0;
  12867. // Base Case
  12868. if (nodeName === '#text') {
  12869. var _text = node.textContent;
  12870. var nodeTextContent = _text.trim();
  12871. // We should not create blocks for leading spaces that are
  12872. // existing around ol/ul and their children list items
  12873. if (lastList && nodeTextContent === '' && node.parentElement) {
  12874. var parentNodeName = node.parentElement.nodeName.toLowerCase();
  12875. if (parentNodeName === 'ol' || parentNodeName === 'ul') {
  12876. return { chunk: _extends$4({}, EMPTY_CHUNK), entityMap: entityMap };
  12877. }
  12878. }
  12879. if (nodeTextContent === '' && inBlock !== 'pre') {
  12880. return { chunk: getWhitespaceChunk(inEntity), entityMap: entityMap };
  12881. }
  12882. if (inBlock !== 'pre') {
  12883. // Can't use empty string because MSWord
  12884. _text = _text.replace(REGEX_LF, SPACE);
  12885. }
  12886. // save the last block so we can use it later
  12887. lastBlock = nodeName;
  12888. return {
  12889. chunk: {
  12890. text: _text,
  12891. inlines: Array(_text.length).fill(inlineStyle),
  12892. entities: Array(_text.length).fill(inEntity),
  12893. blocks: []
  12894. },
  12895. entityMap: entityMap
  12896. };
  12897. }
  12898. // save the last block so we can use it later
  12899. lastBlock = nodeName;
  12900. // BR tags
  12901. if (nodeName === 'br') {
  12902. if (lastLastBlock === 'br' && (!inBlock || inBlockType === 'unstyled')) {
  12903. return {
  12904. chunk: getBlockDividerChunk('unstyled', depth, parentKey),
  12905. entityMap: entityMap
  12906. };
  12907. }
  12908. return { chunk: getSoftNewlineChunk(), entityMap: entityMap };
  12909. }
  12910. // IMG tags
  12911. if (nodeName === 'img' && node instanceof HTMLImageElement && node.attributes.getNamedItem('src') && node.attributes.getNamedItem('src').value) {
  12912. var image = node;
  12913. var entityConfig = {};
  12914. imgAttr.forEach(function (attr) {
  12915. var imageAttribute = image.getAttribute(attr);
  12916. if (imageAttribute) {
  12917. entityConfig[attr] = imageAttribute;
  12918. }
  12919. });
  12920. // Forcing this node to have children because otherwise no entity will be
  12921. // created for this node.
  12922. // The child text node cannot just have a space or return as content -
  12923. // we strip those out.
  12924. // See https://github.com/facebook/draft-js/issues/231 for some context.
  12925. node.textContent = '\uD83D\uDCF7';
  12926. // TODO: update this when we remove DraftEntity entirely
  12927. inEntity = DraftEntity_1.__create('IMAGE', 'MUTABLE', entityConfig || {});
  12928. }
  12929. // Inline tags
  12930. inlineStyle = processInlineTag(nodeName, node, inlineStyle);
  12931. // Handle lists
  12932. if (nodeName === 'ul' || nodeName === 'ol') {
  12933. if (lastList) {
  12934. depth += 1;
  12935. }
  12936. lastList = nodeName;
  12937. }
  12938. if ( nodeName === 'li' && node instanceof HTMLElement) {
  12939. depth = getListItemDepth(node, depth);
  12940. }
  12941. var blockType = getBlockTypeForTag(nodeName, lastList, blockRenderMap);
  12942. var inListBlock = lastList && inBlock === 'li' && nodeName === 'li';
  12943. var inBlockOrHasNestedBlocks = (!inBlock || experimentalTreeDataSupport) && blockTags.indexOf(nodeName) !== -1;
  12944. // Block Tags
  12945. if (inListBlock || inBlockOrHasNestedBlocks) {
  12946. chunk = getBlockDividerChunk(blockType, depth, parentKey);
  12947. blockKey = chunk.blocks[0].key;
  12948. inBlock = nodeName;
  12949. newBlock = !experimentalTreeDataSupport;
  12950. }
  12951. // this is required so that we can handle 'ul' and 'ol'
  12952. if (inListBlock) {
  12953. nextBlockType = lastList === 'ul' ? 'unordered-list-item' : 'ordered-list-item';
  12954. }
  12955. // Recurse through children
  12956. var child = node.firstChild;
  12957. if (child != null) {
  12958. nodeName = child.nodeName.toLowerCase();
  12959. }
  12960. var entityId = null;
  12961. while (child) {
  12962. if (child instanceof HTMLAnchorElement && child.href && hasValidLinkText(child)) {
  12963. (function () {
  12964. var anchor = child;
  12965. var entityConfig = {};
  12966. anchorAttr.forEach(function (attr) {
  12967. var anchorAttribute = anchor.getAttribute(attr);
  12968. if (anchorAttribute) {
  12969. entityConfig[attr] = anchorAttribute;
  12970. }
  12971. });
  12972. entityConfig.url = new URI_1(anchor.href).toString();
  12973. // TODO: update this when we remove DraftEntity completely
  12974. entityId = DraftEntity_1.__create('LINK', 'MUTABLE', entityConfig || {});
  12975. })();
  12976. } else {
  12977. entityId = undefined;
  12978. }
  12979. var _genFragment = genFragment(newEntityMap, child, inlineStyle, lastList, inBlock, blockTags, depth, blockRenderMap, entityId || inEntity, null),
  12980. generatedChunk = _genFragment.chunk,
  12981. maybeUpdatedEntityMap = _genFragment.entityMap;
  12982. newChunk = generatedChunk;
  12983. newEntityMap = maybeUpdatedEntityMap;
  12984. chunk = joinChunks(chunk, newChunk, experimentalTreeDataSupport);
  12985. var sibling = child.nextSibling;
  12986. // Put in a newline to break up blocks inside blocks
  12987. if (!parentKey && sibling && blockTags.indexOf(nodeName) >= 0 && inBlock) {
  12988. chunk = joinChunks(chunk, getSoftNewlineChunk());
  12989. }
  12990. if (sibling) {
  12991. nodeName = sibling.nodeName.toLowerCase();
  12992. }
  12993. child = sibling;
  12994. }
  12995. if (newBlock) {
  12996. chunk = joinChunks(chunk, getBlockDividerChunk(nextBlockType, depth, parentKey));
  12997. }
  12998. return { chunk: chunk, entityMap: newEntityMap };
  12999. };
  13000. var getChunkForHTML = function getChunkForHTML(html, DOMBuilder, blockRenderMap, entityMap) {
  13001. html = html.trim().replace(REGEX_CR, '').replace(REGEX_NBSP, SPACE).replace(REGEX_CARRIAGE, '').replace(REGEX_ZWS, '');
  13002. var supportedBlockTags = getBlockMapSupportedTags(blockRenderMap);
  13003. var safeBody = DOMBuilder(html);
  13004. if (!safeBody) {
  13005. return null;
  13006. }
  13007. lastBlock = null;
  13008. // Sometimes we aren't dealing with content that contains nice semantic
  13009. // tags. In this case, use divs to separate everything out into paragraphs
  13010. // and hope for the best.
  13011. var workingBlocks = containsSemanticBlockMarkup(html, supportedBlockTags) ? supportedBlockTags : ['div'];
  13012. // Start with -1 block depth to offset the fact that we are passing in a fake
  13013. // UL block to start with.
  13014. var fragment = genFragment(entityMap, safeBody, OrderedSet$5(), 'ul', null, workingBlocks, -1, blockRenderMap);
  13015. var chunk = fragment.chunk;
  13016. var newEntityMap = fragment.entityMap;
  13017. // join with previous block to prevent weirdness on paste
  13018. if (chunk.text.indexOf('\r') === 0) {
  13019. chunk = {
  13020. text: chunk.text.slice(1),
  13021. inlines: chunk.inlines.slice(1),
  13022. entities: chunk.entities.slice(1),
  13023. blocks: chunk.blocks
  13024. };
  13025. }
  13026. // Kill block delimiter at the end
  13027. if (chunk.text.slice(-1) === '\r') {
  13028. chunk.text = chunk.text.slice(0, -1);
  13029. chunk.inlines = chunk.inlines.slice(0, -1);
  13030. chunk.entities = chunk.entities.slice(0, -1);
  13031. chunk.blocks.pop();
  13032. }
  13033. // If we saw no block tags, put an unstyled one in
  13034. if (chunk.blocks.length === 0) {
  13035. chunk.blocks.push(_extends$4({}, EMPTY_CHUNK, {
  13036. type: 'unstyled',
  13037. depth: 0
  13038. }));
  13039. }
  13040. // Sometimes we start with text that isn't in a block, which is then
  13041. // followed by blocks. Need to fix up the blocks to add in
  13042. // an unstyled block for this content
  13043. if (chunk.text.split('\r').length === chunk.blocks.length + 1) {
  13044. chunk.blocks.unshift({ type: 'unstyled', depth: 0 });
  13045. }
  13046. return { chunk: chunk, entityMap: newEntityMap };
  13047. };
  13048. var convertChunkToContentBlocks = function convertChunkToContentBlocks(chunk) {
  13049. if (!chunk || !chunk.text || !Array.isArray(chunk.blocks)) {
  13050. return null;
  13051. }
  13052. var initialState = {
  13053. cacheRef: {},
  13054. contentBlocks: []
  13055. };
  13056. var start = 0;
  13057. var rawBlocks = chunk.blocks,
  13058. rawInlines = chunk.inlines,
  13059. rawEntities = chunk.entities;
  13060. var BlockNodeRecord = ContentBlock_1;
  13061. return chunk.text.split('\r').reduce(function (acc, textBlock, index) {
  13062. // Make absolutely certain that our text is acceptable.
  13063. textBlock = sanitizeDraftText_1(textBlock);
  13064. var block = rawBlocks[index];
  13065. var end = start + textBlock.length;
  13066. var inlines = rawInlines.slice(start, end);
  13067. var entities = rawEntities.slice(start, end);
  13068. var characterList = List$a(inlines.map(function (style, index) {
  13069. var data = { style: style, entity: null };
  13070. if (entities[index]) {
  13071. data.entity = entities[index];
  13072. }
  13073. return CharacterMetadata_1.create(data);
  13074. }));
  13075. start = end + 1;
  13076. var depth = block.depth,
  13077. type = block.type,
  13078. parent = block.parent;
  13079. var key = block.key || generateRandomKey_1();
  13080. var parentTextNodeKey = null; // will be used to store container text nodes
  13081. // childrens add themselves to their parents since we are iterating in order
  13082. if (parent) {
  13083. var parentIndex = acc.cacheRef[parent];
  13084. var parentRecord = acc.contentBlocks[parentIndex];
  13085. // if parent has text we need to split it into a separate unstyled element
  13086. if (parentRecord.getChildKeys().isEmpty() && parentRecord.getText()) {
  13087. var parentCharacterList = parentRecord.getCharacterList();
  13088. var parentText = parentRecord.getText();
  13089. parentTextNodeKey = generateRandomKey_1();
  13090. var textNode = new ContentBlockNode_1({
  13091. key: parentTextNodeKey,
  13092. text: parentText,
  13093. characterList: parentCharacterList,
  13094. parent: parent,
  13095. nextSibling: key
  13096. });
  13097. acc.contentBlocks.push(textNode);
  13098. parentRecord = parentRecord.withMutations(function (block) {
  13099. block.set('characterList', List$a()).set('text', '').set('children', parentRecord.children.push(textNode.getKey()));
  13100. });
  13101. }
  13102. acc.contentBlocks[parentIndex] = parentRecord.set('children', parentRecord.children.push(key));
  13103. }
  13104. var blockNode = new BlockNodeRecord({
  13105. key: key,
  13106. parent: parent,
  13107. type: type,
  13108. depth: depth,
  13109. text: textBlock,
  13110. characterList: characterList,
  13111. prevSibling: parentTextNodeKey || (index === 0 || rawBlocks[index - 1].parent !== parent ? null : rawBlocks[index - 1].key),
  13112. nextSibling: index === rawBlocks.length - 1 || rawBlocks[index + 1].parent !== parent ? null : rawBlocks[index + 1].key
  13113. });
  13114. // insert node
  13115. acc.contentBlocks.push(blockNode);
  13116. // cache ref for building links
  13117. acc.cacheRef[blockNode.key] = index;
  13118. return acc;
  13119. }, initialState).contentBlocks;
  13120. };
  13121. var convertFromHTMLtoContentBlocks = function convertFromHTMLtoContentBlocks(html) {
  13122. var DOMBuilder = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : getSafeBodyFromHTML_1;
  13123. var blockRenderMap = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DefaultDraftBlockRenderMap_1;
  13124. // Be ABSOLUTELY SURE that the dom builder you pass here won't execute
  13125. // arbitrary code in whatever environment you're running this in. For an
  13126. // example of how we try to do this in-browser, see getSafeBodyFromHTML.
  13127. // TODO: replace DraftEntity with an OrderedMap here
  13128. var chunkData = getChunkForHTML(html, DOMBuilder, blockRenderMap, DraftEntity_1);
  13129. if (chunkData == null) {
  13130. return null;
  13131. }
  13132. var chunk = chunkData.chunk,
  13133. entityMap = chunkData.entityMap;
  13134. var contentBlocks = convertChunkToContentBlocks(chunk);
  13135. return {
  13136. contentBlocks: contentBlocks,
  13137. entityMap: entityMap
  13138. };
  13139. };
  13140. var convertFromHTMLToContentBlocks = convertFromHTMLtoContentBlocks;
  13141. var List$b = immutable.List,
  13142. Repeat$6 = immutable.Repeat;
  13143. var ContentBlockRecord$2 = ContentBlock_1;
  13144. var DraftPasteProcessor = {
  13145. processHTML: function processHTML(html, blockRenderMap) {
  13146. return convertFromHTMLToContentBlocks(html, getSafeBodyFromHTML_1, blockRenderMap);
  13147. },
  13148. processText: function processText(textBlocks, character, type) {
  13149. return textBlocks.reduce(function (acc, textLine, index) {
  13150. textLine = sanitizeDraftText_1(textLine);
  13151. var key = generateRandomKey_1();
  13152. var blockNodeConfig = {
  13153. key: key,
  13154. type: type,
  13155. text: textLine,
  13156. characterList: List$b(Repeat$6(character, textLine.length))
  13157. };
  13158. acc.push(new ContentBlockRecord$2(blockNodeConfig));
  13159. return acc;
  13160. }, []);
  13161. }
  13162. };
  13163. var DraftPasteProcessor_1 = DraftPasteProcessor;
  13164. /**
  13165. * Copyright (c) 2013-present, Facebook, Inc.
  13166. * All rights reserved.
  13167. *
  13168. * This source code is licensed under the BSD-style license found in the
  13169. * LICENSE file in the root directory of this source tree. An additional grant
  13170. * of patent rights can be found in the PATENTS file in the same directory.
  13171. *
  13172. * @providesModule adjustBlockDepthForContentState
  13173. * @format
  13174. *
  13175. */
  13176. function adjustBlockDepthForContentState(contentState, selectionState, adjustment, maxDepth) {
  13177. var startKey = selectionState.getStartKey();
  13178. var endKey = selectionState.getEndKey();
  13179. var blockMap = contentState.getBlockMap();
  13180. var blocks = blockMap.toSeq().skipUntil(function (_, k) {
  13181. return k === startKey;
  13182. }).takeUntil(function (_, k) {
  13183. return k === endKey;
  13184. }).concat([[endKey, blockMap.get(endKey)]]).map(function (block) {
  13185. var depth = block.getDepth() + adjustment;
  13186. depth = Math.max(0, Math.min(depth, maxDepth));
  13187. return block.set('depth', depth);
  13188. });
  13189. blockMap = blockMap.merge(blocks);
  13190. return contentState.merge({
  13191. blockMap: blockMap,
  13192. selectionBefore: selectionState,
  13193. selectionAfter: selectionState
  13194. });
  13195. }
  13196. var adjustBlockDepthForContentState_1 = adjustBlockDepthForContentState;
  13197. var RichTextEditorUtil = {
  13198. currentBlockContainsLink: function currentBlockContainsLink(editorState) {
  13199. var selection = editorState.getSelection();
  13200. var contentState = editorState.getCurrentContent();
  13201. var entityMap = contentState.getEntityMap();
  13202. return contentState.getBlockForKey(selection.getAnchorKey()).getCharacterList().slice(selection.getStartOffset(), selection.getEndOffset()).some(function (v) {
  13203. var entity = v.getEntity();
  13204. return !!entity && entityMap.__get(entity).getType() === 'LINK';
  13205. });
  13206. },
  13207. getCurrentBlockType: function getCurrentBlockType(editorState) {
  13208. var selection = editorState.getSelection();
  13209. return editorState.getCurrentContent().getBlockForKey(selection.getStartKey()).getType();
  13210. },
  13211. getDataObjectForLinkURL: function getDataObjectForLinkURL(uri) {
  13212. return { url: uri.toString() };
  13213. },
  13214. handleKeyCommand: function handleKeyCommand(editorState, command) {
  13215. switch (command) {
  13216. case 'bold':
  13217. return RichTextEditorUtil.toggleInlineStyle(editorState, 'BOLD');
  13218. case 'italic':
  13219. return RichTextEditorUtil.toggleInlineStyle(editorState, 'ITALIC');
  13220. case 'underline':
  13221. return RichTextEditorUtil.toggleInlineStyle(editorState, 'UNDERLINE');
  13222. case 'code':
  13223. return RichTextEditorUtil.toggleCode(editorState);
  13224. case 'backspace':
  13225. case 'backspace-word':
  13226. case 'backspace-to-start-of-line':
  13227. return RichTextEditorUtil.onBackspace(editorState);
  13228. case 'delete':
  13229. case 'delete-word':
  13230. case 'delete-to-end-of-block':
  13231. return RichTextEditorUtil.onDelete(editorState);
  13232. default:
  13233. // they may have custom editor commands; ignore those
  13234. return null;
  13235. }
  13236. },
  13237. insertSoftNewline: function insertSoftNewline(editorState) {
  13238. var contentState = DraftModifier_1.insertText(editorState.getCurrentContent(), editorState.getSelection(), '\n', editorState.getCurrentInlineStyle(), null);
  13239. var newEditorState = EditorState_1.push(editorState, contentState, 'insert-characters');
  13240. return EditorState_1.forceSelection(newEditorState, contentState.getSelectionAfter());
  13241. },
  13242. /**
  13243. * For collapsed selections at the start of styled blocks, backspace should
  13244. * just remove the existing style.
  13245. */
  13246. onBackspace: function onBackspace(editorState) {
  13247. var selection = editorState.getSelection();
  13248. if (!selection.isCollapsed() || selection.getAnchorOffset() || selection.getFocusOffset()) {
  13249. return null;
  13250. }
  13251. // First, try to remove a preceding atomic block.
  13252. var content = editorState.getCurrentContent();
  13253. var startKey = selection.getStartKey();
  13254. var blockBefore = content.getBlockBefore(startKey);
  13255. if (blockBefore && blockBefore.getType() === 'atomic') {
  13256. var blockMap = content.getBlockMap()['delete'](blockBefore.getKey());
  13257. var withoutAtomicBlock = content.merge({
  13258. blockMap: blockMap,
  13259. selectionAfter: selection
  13260. });
  13261. if (withoutAtomicBlock !== content) {
  13262. return EditorState_1.push(editorState, withoutAtomicBlock, 'remove-range');
  13263. }
  13264. }
  13265. // If that doesn't succeed, try to remove the current block style.
  13266. var withoutBlockStyle = RichTextEditorUtil.tryToRemoveBlockStyle(editorState);
  13267. if (withoutBlockStyle) {
  13268. return EditorState_1.push(editorState, withoutBlockStyle, 'change-block-type');
  13269. }
  13270. return null;
  13271. },
  13272. onDelete: function onDelete(editorState) {
  13273. var selection = editorState.getSelection();
  13274. if (!selection.isCollapsed()) {
  13275. return null;
  13276. }
  13277. var content = editorState.getCurrentContent();
  13278. var startKey = selection.getStartKey();
  13279. var block = content.getBlockForKey(startKey);
  13280. var length = block.getLength();
  13281. // The cursor is somewhere within the text. Behave normally.
  13282. if (selection.getStartOffset() < length) {
  13283. return null;
  13284. }
  13285. var blockAfter = content.getBlockAfter(startKey);
  13286. if (!blockAfter || blockAfter.getType() !== 'atomic') {
  13287. return null;
  13288. }
  13289. var atomicBlockTarget = selection.merge({
  13290. focusKey: blockAfter.getKey(),
  13291. focusOffset: blockAfter.getLength()
  13292. });
  13293. var withoutAtomicBlock = DraftModifier_1.removeRange(content, atomicBlockTarget, 'forward');
  13294. if (withoutAtomicBlock !== content) {
  13295. return EditorState_1.push(editorState, withoutAtomicBlock, 'remove-range');
  13296. }
  13297. return null;
  13298. },
  13299. onTab: function onTab(event, editorState, maxDepth) {
  13300. var selection = editorState.getSelection();
  13301. var key = selection.getAnchorKey();
  13302. if (key !== selection.getFocusKey()) {
  13303. return editorState;
  13304. }
  13305. var content = editorState.getCurrentContent();
  13306. var block = content.getBlockForKey(key);
  13307. var type = block.getType();
  13308. if (type !== 'unordered-list-item' && type !== 'ordered-list-item') {
  13309. return editorState;
  13310. }
  13311. event.preventDefault();
  13312. // Only allow indenting one level beyond the block above, and only if
  13313. // the block above is a list item as well.
  13314. var blockAbove = content.getBlockBefore(key);
  13315. if (!blockAbove) {
  13316. return editorState;
  13317. }
  13318. var typeAbove = blockAbove.getType();
  13319. if (typeAbove !== 'unordered-list-item' && typeAbove !== 'ordered-list-item') {
  13320. return editorState;
  13321. }
  13322. var depth = block.getDepth();
  13323. if (!event.shiftKey && depth === maxDepth) {
  13324. return editorState;
  13325. }
  13326. maxDepth = Math.min(blockAbove.getDepth() + 1, maxDepth);
  13327. var withAdjustment = adjustBlockDepthForContentState_1(content, selection, event.shiftKey ? -1 : 1, maxDepth);
  13328. return EditorState_1.push(editorState, withAdjustment, 'adjust-depth');
  13329. },
  13330. toggleBlockType: function toggleBlockType(editorState, blockType) {
  13331. var selection = editorState.getSelection();
  13332. var startKey = selection.getStartKey();
  13333. var endKey = selection.getEndKey();
  13334. var content = editorState.getCurrentContent();
  13335. var target = selection;
  13336. // Triple-click can lead to a selection that includes offset 0 of the
  13337. // following block. The `SelectionState` for this case is accurate, but
  13338. // we should avoid toggling block type for the trailing block because it
  13339. // is a confusing interaction.
  13340. if (startKey !== endKey && selection.getEndOffset() === 0) {
  13341. var blockBefore = nullthrows_1(content.getBlockBefore(endKey));
  13342. endKey = blockBefore.getKey();
  13343. target = target.merge({
  13344. anchorKey: startKey,
  13345. anchorOffset: selection.getStartOffset(),
  13346. focusKey: endKey,
  13347. focusOffset: blockBefore.getLength(),
  13348. isBackward: false
  13349. });
  13350. }
  13351. var hasAtomicBlock = content.getBlockMap().skipWhile(function (_, k) {
  13352. return k !== startKey;
  13353. }).reverse().skipWhile(function (_, k) {
  13354. return k !== endKey;
  13355. }).some(function (v) {
  13356. return v.getType() === 'atomic';
  13357. });
  13358. if (hasAtomicBlock) {
  13359. return editorState;
  13360. }
  13361. var typeToSet = content.getBlockForKey(startKey).getType() === blockType ? 'unstyled' : blockType;
  13362. return EditorState_1.push(editorState, DraftModifier_1.setBlockType(content, target, typeToSet), 'change-block-type');
  13363. },
  13364. toggleCode: function toggleCode(editorState) {
  13365. var selection = editorState.getSelection();
  13366. var anchorKey = selection.getAnchorKey();
  13367. var focusKey = selection.getFocusKey();
  13368. if (selection.isCollapsed() || anchorKey !== focusKey) {
  13369. return RichTextEditorUtil.toggleBlockType(editorState, 'code-block');
  13370. }
  13371. return RichTextEditorUtil.toggleInlineStyle(editorState, 'CODE');
  13372. },
  13373. /**
  13374. * Toggle the specified inline style for the selection. If the
  13375. * user's selection is collapsed, apply or remove the style for the
  13376. * internal state. If it is not collapsed, apply the change directly
  13377. * to the document state.
  13378. */
  13379. toggleInlineStyle: function toggleInlineStyle(editorState, inlineStyle) {
  13380. var selection = editorState.getSelection();
  13381. var currentStyle = editorState.getCurrentInlineStyle();
  13382. // If the selection is collapsed, toggle the specified style on or off and
  13383. // set the result as the new inline style override. This will then be
  13384. // used as the inline style for the next character to be inserted.
  13385. if (selection.isCollapsed()) {
  13386. return EditorState_1.setInlineStyleOverride(editorState, currentStyle.has(inlineStyle) ? currentStyle.remove(inlineStyle) : currentStyle.add(inlineStyle));
  13387. }
  13388. // If characters are selected, immediately apply or remove the
  13389. // inline style on the document state itself.
  13390. var content = editorState.getCurrentContent();
  13391. var newContent;
  13392. // If the style is already present for the selection range, remove it.
  13393. // Otherwise, apply it.
  13394. if (currentStyle.has(inlineStyle)) {
  13395. newContent = DraftModifier_1.removeInlineStyle(content, selection, inlineStyle);
  13396. } else {
  13397. newContent = DraftModifier_1.applyInlineStyle(content, selection, inlineStyle);
  13398. }
  13399. return EditorState_1.push(editorState, newContent, 'change-inline-style');
  13400. },
  13401. toggleLink: function toggleLink(editorState, targetSelection, entityKey) {
  13402. var withoutLink = DraftModifier_1.applyEntity(editorState.getCurrentContent(), targetSelection, entityKey);
  13403. return EditorState_1.push(editorState, withoutLink, 'apply-entity');
  13404. },
  13405. /**
  13406. * When a collapsed cursor is at the start of the first styled block, or
  13407. * an empty styled block, changes block to 'unstyled'. Returns null if
  13408. * block or selection does not meet that criteria.
  13409. */
  13410. tryToRemoveBlockStyle: function tryToRemoveBlockStyle(editorState) {
  13411. var selection = editorState.getSelection();
  13412. var offset = selection.getAnchorOffset();
  13413. if (selection.isCollapsed() && offset === 0) {
  13414. var key = selection.getAnchorKey();
  13415. var content = editorState.getCurrentContent();
  13416. var block = content.getBlockForKey(key);
  13417. var firstBlock = content.getFirstBlock();
  13418. if (block.getLength() > 0 && block !== firstBlock) {
  13419. return null;
  13420. }
  13421. var type = block.getType();
  13422. var blockBefore = content.getBlockBefore(key);
  13423. if (type === 'code-block' && blockBefore && blockBefore.getType() === 'code-block' && blockBefore.getLength() !== 0) {
  13424. return null;
  13425. }
  13426. if (type !== 'unstyled') {
  13427. return DraftModifier_1.setBlockType(content, selection, 'unstyled');
  13428. }
  13429. }
  13430. return null;
  13431. }
  13432. };
  13433. var RichTextEditorUtil_1 = RichTextEditorUtil;
  13434. /**
  13435. * Copyright (c) 2013-present, Facebook, Inc.
  13436. * All rights reserved.
  13437. *
  13438. * This source code is licensed under the BSD-style license found in the
  13439. * LICENSE file in the root directory of this source tree. An additional grant
  13440. * of patent rights can be found in the PATENTS file in the same directory.
  13441. *
  13442. * @providesModule splitTextIntoTextBlocks
  13443. * @format
  13444. *
  13445. */
  13446. var NEWLINE_REGEX = /\r\n?|\n/g;
  13447. function splitTextIntoTextBlocks(text) {
  13448. return text.split(NEWLINE_REGEX);
  13449. }
  13450. var splitTextIntoTextBlocks_1 = splitTextIntoTextBlocks;
  13451. /**
  13452. * Paste content.
  13453. */
  13454. function editOnPaste(editor, e) {
  13455. e.preventDefault();
  13456. var data = new DataTransfer_1(e.clipboardData);
  13457. // Get files, unless this is likely to be a string the user wants inline.
  13458. if (!data.isRichText()) {
  13459. var files = data.getFiles();
  13460. var defaultFileText = data.getText();
  13461. if (files.length > 0) {
  13462. // Allow customized paste handling for images, etc. Otherwise, fall
  13463. // through to insert text contents into the editor.
  13464. if (editor.props.handlePastedFiles && isEventHandled_1(editor.props.handlePastedFiles(files))) {
  13465. return;
  13466. }
  13467. getTextContentFromFiles_1(files, function ( /*string*/fileText) {
  13468. fileText = fileText || defaultFileText;
  13469. if (!fileText) {
  13470. return;
  13471. }
  13472. var editorState = editor._latestEditorState;
  13473. var blocks = splitTextIntoTextBlocks_1(fileText);
  13474. var character = CharacterMetadata_1.create({
  13475. style: editorState.getCurrentInlineStyle(),
  13476. entity: getEntityKeyForSelection_1(editorState.getCurrentContent(), editorState.getSelection())
  13477. });
  13478. var currentBlockType = RichTextEditorUtil_1.getCurrentBlockType(editorState);
  13479. var text = DraftPasteProcessor_1.processText(blocks, character, currentBlockType);
  13480. var fragment = BlockMapBuilder_1.createFromArray(text);
  13481. var withInsertedText = DraftModifier_1.replaceWithFragment(editorState.getCurrentContent(), editorState.getSelection(), fragment);
  13482. editor.update(EditorState_1.push(editorState, withInsertedText, 'insert-fragment'));
  13483. });
  13484. return;
  13485. }
  13486. }
  13487. var textBlocks = [];
  13488. var text = data.getText();
  13489. var html = data.getHTML();
  13490. var editorState = editor._latestEditorState;
  13491. if (editor.props.handlePastedText && isEventHandled_1(editor.props.handlePastedText(text, html, editorState))) {
  13492. return;
  13493. }
  13494. if (text) {
  13495. textBlocks = splitTextIntoTextBlocks_1(text);
  13496. }
  13497. if (!editor.props.stripPastedStyles) {
  13498. // If the text from the paste event is rich content that matches what we
  13499. // already have on the internal clipboard, assume that we should just use
  13500. // the clipboard fragment for the paste. This will allow us to preserve
  13501. // styling and entities, if any are present. Note that newlines are
  13502. // stripped during comparison -- this is because copy/paste within the
  13503. // editor in Firefox and IE will not include empty lines. The resulting
  13504. // paste will preserve the newlines correctly.
  13505. var internalClipboard = editor.getClipboard();
  13506. if (data.isRichText() && internalClipboard) {
  13507. if (
  13508. // If the editorKey is present in the pasted HTML, it should be safe to
  13509. // assume this is an internal paste.
  13510. html.indexOf(editor.getEditorKey()) !== -1 ||
  13511. // The copy may have been made within a single block, in which case the
  13512. // editor key won't be part of the paste. In this case, just check
  13513. // whether the pasted text matches the internal clipboard.
  13514. textBlocks.length === 1 && internalClipboard.size === 1 && internalClipboard.first().getText() === text) {
  13515. editor.update(insertFragment$1(editor._latestEditorState, internalClipboard));
  13516. return;
  13517. }
  13518. } else if (internalClipboard && data.types.includes('com.apple.webarchive') && !data.types.includes('text/html') && areTextBlocksAndClipboardEqual(textBlocks, internalClipboard)) {
  13519. // Safari does not properly store text/html in some cases.
  13520. // Use the internalClipboard if present and equal to what is on
  13521. // the clipboard. See https://bugs.webkit.org/show_bug.cgi?id=19893.
  13522. editor.update(insertFragment$1(editor._latestEditorState, internalClipboard));
  13523. return;
  13524. }
  13525. // If there is html paste data, try to parse that.
  13526. if (html) {
  13527. var htmlFragment = DraftPasteProcessor_1.processHTML(html, editor.props.blockRenderMap);
  13528. if (htmlFragment) {
  13529. var contentBlocks = htmlFragment.contentBlocks,
  13530. entityMap = htmlFragment.entityMap;
  13531. if (contentBlocks) {
  13532. var htmlMap = BlockMapBuilder_1.createFromArray(contentBlocks);
  13533. editor.update(insertFragment$1(editor._latestEditorState, htmlMap, entityMap));
  13534. return;
  13535. }
  13536. }
  13537. }
  13538. // Otherwise, create a new fragment from our pasted text. Also
  13539. // empty the internal clipboard, since it's no longer valid.
  13540. editor.setClipboard(null);
  13541. }
  13542. if (textBlocks.length) {
  13543. var character = CharacterMetadata_1.create({
  13544. style: editorState.getCurrentInlineStyle(),
  13545. entity: getEntityKeyForSelection_1(editorState.getCurrentContent(), editorState.getSelection())
  13546. });
  13547. var currentBlockType = RichTextEditorUtil_1.getCurrentBlockType(editorState);
  13548. var textFragment = DraftPasteProcessor_1.processText(textBlocks, character, currentBlockType);
  13549. var textMap = BlockMapBuilder_1.createFromArray(textFragment);
  13550. editor.update(insertFragment$1(editor._latestEditorState, textMap));
  13551. }
  13552. }
  13553. function insertFragment$1(editorState, fragment, entityMap) {
  13554. var newContent = DraftModifier_1.replaceWithFragment(editorState.getCurrentContent(), editorState.getSelection(), fragment);
  13555. // TODO: merge the entity map once we stop using DraftEntity
  13556. // like this:
  13557. // const mergedEntityMap = newContent.getEntityMap().merge(entityMap);
  13558. return EditorState_1.push(editorState, newContent.set('entityMap', entityMap), 'insert-fragment');
  13559. }
  13560. function areTextBlocksAndClipboardEqual(textBlocks, blockMap) {
  13561. return textBlocks.length === blockMap.size && blockMap.valueSeq().every(function (block, ii) {
  13562. return block.getText() === textBlocks[ii];
  13563. });
  13564. }
  13565. var editOnPaste_1 = editOnPaste;
  13566. /**
  13567. * Convert the current selection range to an anchor/focus pair of offset keys
  13568. * and values that can be interpreted by components.
  13569. */
  13570. function getDraftEditorSelection(editorState, root) {
  13571. var selection = commonjsGlobal.getSelection();
  13572. // No active selection.
  13573. if (selection.rangeCount === 0) {
  13574. return {
  13575. selectionState: editorState.getSelection().set('hasFocus', false),
  13576. needsRecovery: false
  13577. };
  13578. }
  13579. return getDraftEditorSelectionWithNodes_1(editorState, root, selection.anchorNode, selection.anchorOffset, selection.focusNode, selection.focusOffset);
  13580. }
  13581. var getDraftEditorSelection_1 = getDraftEditorSelection;
  13582. function editOnSelect(editor) {
  13583. if (editor._blockSelectEvents || editor._latestEditorState !== editor.props.editorState) {
  13584. return;
  13585. }
  13586. var editorState = editor.props.editorState;
  13587. var editorNode = ReactDOM.findDOMNode(editor.editorContainer);
  13588. !editorNode ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing editorNode') : invariant_1(false) : void 0;
  13589. !(editorNode.firstChild instanceof HTMLElement) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'editorNode.firstChild is not an HTMLElement') : invariant_1(false) : void 0;
  13590. var documentSelection = getDraftEditorSelection_1(editorState, editorNode.firstChild);
  13591. var updatedSelectionState = documentSelection.selectionState;
  13592. if (updatedSelectionState !== editorState.getSelection()) {
  13593. if (documentSelection.needsRecovery) {
  13594. editorState = EditorState_1.forceSelection(editorState, updatedSelectionState);
  13595. } else {
  13596. editorState = EditorState_1.acceptSelection(editorState, updatedSelectionState);
  13597. }
  13598. editor.update(editorState);
  13599. }
  13600. }
  13601. var editOnSelect_1 = editOnSelect;
  13602. var DraftEditorEditHandler = {
  13603. onBeforeInput: editOnBeforeInput_1,
  13604. onBlur: editOnBlur_1,
  13605. onCompositionStart: editOnCompositionStart_1,
  13606. onCopy: editOnCopy_1,
  13607. onCut: editOnCut_1,
  13608. onDragOver: editOnDragOver_1,
  13609. onDragStart: editOnDragStart_1,
  13610. onFocus: editOnFocus_1,
  13611. onInput: editOnInput_1,
  13612. onKeyDown: editOnKeyDown_1,
  13613. onPaste: editOnPaste_1,
  13614. onSelect: editOnSelect_1
  13615. };
  13616. var DraftEditorEditHandler_1 = DraftEditorEditHandler;
  13617. function _classCallCheck$f(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13618. 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; }
  13619. 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; }
  13620. /**
  13621. * This component is responsible for rendering placeholder text for the
  13622. * `DraftEditor` component.
  13623. *
  13624. * Override placeholder style via CSS.
  13625. */
  13626. var DraftEditorPlaceholder = function (_React$Component) {
  13627. _inherits$a(DraftEditorPlaceholder, _React$Component);
  13628. function DraftEditorPlaceholder() {
  13629. _classCallCheck$f(this, DraftEditorPlaceholder);
  13630. return _possibleConstructorReturn$a(this, _React$Component.apply(this, arguments));
  13631. }
  13632. DraftEditorPlaceholder.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
  13633. return this.props.text !== nextProps.text || this.props.editorState.getSelection().getHasFocus() !== nextProps.editorState.getSelection().getHasFocus();
  13634. };
  13635. DraftEditorPlaceholder.prototype.render = function render() {
  13636. var hasFocus = this.props.editorState.getSelection().getHasFocus();
  13637. var className = cx_1({
  13638. 'public/DraftEditorPlaceholder/root': true,
  13639. 'public/DraftEditorPlaceholder/hasFocus': hasFocus
  13640. });
  13641. var contentStyle = {
  13642. whiteSpace: 'pre-wrap'
  13643. };
  13644. return React.createElement(
  13645. 'div',
  13646. { className: className },
  13647. React.createElement(
  13648. 'div',
  13649. {
  13650. className: cx_1('public/DraftEditorPlaceholder/inner'),
  13651. id: this.props.accessibilityID,
  13652. style: contentStyle },
  13653. this.props.text
  13654. )
  13655. );
  13656. };
  13657. return DraftEditorPlaceholder;
  13658. }(React.Component);
  13659. var DraftEditorPlaceholder_react = DraftEditorPlaceholder;
  13660. var isOSX$1 = UserAgent_1.isPlatform('Mac OS X');
  13661. var isWindows = UserAgent_1.isPlatform('Windows');
  13662. // Firefox on OSX had a bug resulting in navigation instead of cursor movement.
  13663. // This bug was fixed in Firefox 29. Feature detection is virtually impossible
  13664. // so we just check the version number. See #342765.
  13665. var shouldFixFirefoxMovement = isOSX$1 && UserAgent_1.isBrowser('Firefox < 29');
  13666. var hasCommandModifier = KeyBindingUtil_1.hasCommandModifier,
  13667. isCtrlKeyCommand = KeyBindingUtil_1.isCtrlKeyCommand;
  13668. function shouldRemoveWord(e) {
  13669. return isOSX$1 && e.altKey || isCtrlKeyCommand(e);
  13670. }
  13671. /**
  13672. * Get the appropriate undo/redo command for a Z key command.
  13673. */
  13674. function getZCommand(e) {
  13675. if (!hasCommandModifier(e)) {
  13676. return null;
  13677. }
  13678. return e.shiftKey ? 'redo' : 'undo';
  13679. }
  13680. function getDeleteCommand(e) {
  13681. // Allow default "cut" behavior for Windows on Shift + Delete.
  13682. if (isWindows && e.shiftKey) {
  13683. return null;
  13684. }
  13685. return shouldRemoveWord(e) ? 'delete-word' : 'delete';
  13686. }
  13687. function getBackspaceCommand(e) {
  13688. if (hasCommandModifier(e) && isOSX$1) {
  13689. return 'backspace-to-start-of-line';
  13690. }
  13691. return shouldRemoveWord(e) ? 'backspace-word' : 'backspace';
  13692. }
  13693. /**
  13694. * Retrieve a bound key command for the given event.
  13695. */
  13696. function getDefaultKeyBinding(e) {
  13697. switch (e.keyCode) {
  13698. case 66:
  13699. // B
  13700. return hasCommandModifier(e) ? 'bold' : null;
  13701. case 68:
  13702. // D
  13703. return isCtrlKeyCommand(e) ? 'delete' : null;
  13704. case 72:
  13705. // H
  13706. return isCtrlKeyCommand(e) ? 'backspace' : null;
  13707. case 73:
  13708. // I
  13709. return hasCommandModifier(e) ? 'italic' : null;
  13710. case 74:
  13711. // J
  13712. return hasCommandModifier(e) ? 'code' : null;
  13713. case 75:
  13714. // K
  13715. return !isWindows && isCtrlKeyCommand(e) ? 'secondary-cut' : null;
  13716. case 77:
  13717. // M
  13718. return isCtrlKeyCommand(e) ? 'split-block' : null;
  13719. case 79:
  13720. // O
  13721. return isCtrlKeyCommand(e) ? 'split-block' : null;
  13722. case 84:
  13723. // T
  13724. return isOSX$1 && isCtrlKeyCommand(e) ? 'transpose-characters' : null;
  13725. case 85:
  13726. // U
  13727. return hasCommandModifier(e) ? 'underline' : null;
  13728. case 87:
  13729. // W
  13730. return isOSX$1 && isCtrlKeyCommand(e) ? 'backspace-word' : null;
  13731. case 89:
  13732. // Y
  13733. if (isCtrlKeyCommand(e)) {
  13734. return isWindows ? 'redo' : 'secondary-paste';
  13735. }
  13736. return null;
  13737. case 90:
  13738. // Z
  13739. return getZCommand(e) || null;
  13740. case Keys.RETURN:
  13741. return 'split-block';
  13742. case Keys.DELETE:
  13743. return getDeleteCommand(e);
  13744. case Keys.BACKSPACE:
  13745. return getBackspaceCommand(e);
  13746. // LEFT/RIGHT handlers serve as a workaround for a Firefox bug.
  13747. case Keys.LEFT:
  13748. return shouldFixFirefoxMovement && hasCommandModifier(e) ? 'move-selection-to-start-of-block' : null;
  13749. case Keys.RIGHT:
  13750. return shouldFixFirefoxMovement && hasCommandModifier(e) ? 'move-selection-to-end-of-block' : null;
  13751. default:
  13752. return null;
  13753. }
  13754. }
  13755. var getDefaultKeyBinding_1 = getDefaultKeyBinding;
  13756. 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; };
  13757. function _classCallCheck$g(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13758. 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; }
  13759. 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; }
  13760. var isIE = UserAgent_1.isBrowser('IE');
  13761. // IE does not support the `input` event on contentEditable, so we can't
  13762. // observe spellcheck behavior.
  13763. var allowSpellCheck = !isIE;
  13764. // Define a set of handler objects to correspond to each possible `mode`
  13765. // of editor behavior.
  13766. var handlerMap = {
  13767. edit: DraftEditorEditHandler_1,
  13768. composite: DraftEditorCompositionHandler_1,
  13769. drag: DraftEditorDragHandler_1,
  13770. cut: null,
  13771. render: null
  13772. };
  13773. /**
  13774. * `DraftEditor` is the root editor component. It composes a `contentEditable`
  13775. * div, and provides a wide variety of useful function props for managing the
  13776. * state of the editor. See `DraftEditorProps` for details.
  13777. */
  13778. var DraftEditor = function (_React$Component) {
  13779. _inherits$b(DraftEditor, _React$Component);
  13780. function DraftEditor(props) {
  13781. _classCallCheck$g(this, DraftEditor);
  13782. var _this = _possibleConstructorReturn$b(this, _React$Component.call(this, props));
  13783. _this.focus = function (scrollPosition) {
  13784. var editorState = _this.props.editorState;
  13785. var alreadyHasFocus = editorState.getSelection().getHasFocus();
  13786. var editorNode = ReactDOM.findDOMNode(_this.editor);
  13787. if (!editorNode) {
  13788. // once in a while people call 'focus' in a setTimeout, and the node has
  13789. // been deleted, so it can be null in that case.
  13790. return;
  13791. }
  13792. var scrollParent = Style_1.getScrollParent(editorNode);
  13793. var _ref = scrollPosition || getScrollPosition_1(scrollParent),
  13794. x = _ref.x,
  13795. y = _ref.y;
  13796. !(editorNode instanceof HTMLElement) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'editorNode is not an HTMLElement') : invariant_1(false) : void 0;
  13797. editorNode.focus();
  13798. // Restore scroll position
  13799. if (scrollParent === window) {
  13800. window.scrollTo(x, y);
  13801. } else {
  13802. Scroll_1.setTop(scrollParent, y);
  13803. }
  13804. // On Chrome and Safari, calling focus on contenteditable focuses the
  13805. // cursor at the first character. This is something you don't expect when
  13806. // you're clicking on an input element but not directly on a character.
  13807. // Put the cursor back where it was before the blur.
  13808. if (!alreadyHasFocus) {
  13809. _this.update(EditorState_1.forceSelection(editorState, editorState.getSelection()));
  13810. }
  13811. };
  13812. _this.blur = function () {
  13813. var editorNode = ReactDOM.findDOMNode(_this.editor);
  13814. !(editorNode instanceof HTMLElement) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'editorNode is not an HTMLElement') : invariant_1(false) : void 0;
  13815. editorNode.blur();
  13816. };
  13817. _this.setMode = function (mode) {
  13818. _this._handler = handlerMap[mode];
  13819. };
  13820. _this.exitCurrentMode = function () {
  13821. _this.setMode('edit');
  13822. };
  13823. _this.restoreEditorDOM = function (scrollPosition) {
  13824. _this.setState({ contentsKey: _this.state.contentsKey + 1 }, function () {
  13825. _this.focus(scrollPosition);
  13826. });
  13827. };
  13828. _this.setClipboard = function (clipboard) {
  13829. _this._clipboard = clipboard;
  13830. };
  13831. _this.getClipboard = function () {
  13832. return _this._clipboard;
  13833. };
  13834. _this.update = function (editorState) {
  13835. _this._latestEditorState = editorState;
  13836. _this.props.onChange(editorState);
  13837. };
  13838. _this.onDragEnter = function () {
  13839. _this._dragCount++;
  13840. };
  13841. _this.onDragLeave = function () {
  13842. _this._dragCount--;
  13843. if (_this._dragCount === 0) {
  13844. _this.exitCurrentMode();
  13845. }
  13846. };
  13847. _this._blockSelectEvents = false;
  13848. _this._clipboard = null;
  13849. _this._handler = null;
  13850. _this._dragCount = 0;
  13851. _this._editorKey = props.editorKey || generateRandomKey_1();
  13852. _this._placeholderAccessibilityID = 'placeholder-' + _this._editorKey;
  13853. _this._latestEditorState = props.editorState;
  13854. _this._latestCommittedEditorState = props.editorState;
  13855. _this._onBeforeInput = _this._buildHandler('onBeforeInput');
  13856. _this._onBlur = _this._buildHandler('onBlur');
  13857. _this._onCharacterData = _this._buildHandler('onCharacterData');
  13858. _this._onCompositionEnd = _this._buildHandler('onCompositionEnd');
  13859. _this._onCompositionStart = _this._buildHandler('onCompositionStart');
  13860. _this._onCopy = _this._buildHandler('onCopy');
  13861. _this._onCut = _this._buildHandler('onCut');
  13862. _this._onDragEnd = _this._buildHandler('onDragEnd');
  13863. _this._onDragOver = _this._buildHandler('onDragOver');
  13864. _this._onDragStart = _this._buildHandler('onDragStart');
  13865. _this._onDrop = _this._buildHandler('onDrop');
  13866. _this._onInput = _this._buildHandler('onInput');
  13867. _this._onFocus = _this._buildHandler('onFocus');
  13868. _this._onKeyDown = _this._buildHandler('onKeyDown');
  13869. _this._onKeyPress = _this._buildHandler('onKeyPress');
  13870. _this._onKeyUp = _this._buildHandler('onKeyUp');
  13871. _this._onMouseDown = _this._buildHandler('onMouseDown');
  13872. _this._onMouseUp = _this._buildHandler('onMouseUp');
  13873. _this._onPaste = _this._buildHandler('onPaste');
  13874. _this._onSelect = _this._buildHandler('onSelect');
  13875. _this.getEditorKey = function () {
  13876. return _this._editorKey;
  13877. };
  13878. // See `restoreEditorDOM()`.
  13879. _this.state = { contentsKey: 0 };
  13880. return _this;
  13881. }
  13882. /**
  13883. * Build a method that will pass the event to the specified handler method.
  13884. * This allows us to look up the correct handler function for the current
  13885. * editor mode, if any has been specified.
  13886. */
  13887. /**
  13888. * Define proxies that can route events to the current handler.
  13889. */
  13890. DraftEditor.prototype._buildHandler = function _buildHandler(eventName) {
  13891. var _this2 = this;
  13892. return function (e) {
  13893. if (!_this2.props.readOnly) {
  13894. var method = _this2._handler && _this2._handler[eventName];
  13895. method && method(_this2, e);
  13896. }
  13897. };
  13898. };
  13899. DraftEditor.prototype._showPlaceholder = function _showPlaceholder() {
  13900. return !!this.props.placeholder && !this.props.editorState.isInCompositionMode() && !this.props.editorState.getCurrentContent().hasText();
  13901. };
  13902. DraftEditor.prototype._renderPlaceholder = function _renderPlaceholder() {
  13903. if (this._showPlaceholder()) {
  13904. var placeHolderProps = {
  13905. text: nullthrows_1(this.props.placeholder),
  13906. editorState: this.props.editorState,
  13907. textAlignment: this.props.textAlignment,
  13908. accessibilityID: this._placeholderAccessibilityID
  13909. };
  13910. return React.createElement(DraftEditorPlaceholder_react, placeHolderProps);
  13911. }
  13912. return null;
  13913. };
  13914. DraftEditor.prototype.render = function render() {
  13915. var _this3 = this;
  13916. var _props = this.props,
  13917. blockRenderMap = _props.blockRenderMap,
  13918. blockRendererFn = _props.blockRendererFn,
  13919. blockStyleFn = _props.blockStyleFn,
  13920. customStyleFn = _props.customStyleFn,
  13921. customStyleMap = _props.customStyleMap,
  13922. editorState = _props.editorState,
  13923. readOnly = _props.readOnly,
  13924. textAlignment = _props.textAlignment,
  13925. textDirectionality = _props.textDirectionality;
  13926. var rootClass = cx_1({
  13927. 'DraftEditor/root': true,
  13928. 'DraftEditor/alignLeft': textAlignment === 'left',
  13929. 'DraftEditor/alignRight': textAlignment === 'right',
  13930. 'DraftEditor/alignCenter': textAlignment === 'center'
  13931. });
  13932. var contentStyle = {
  13933. outline: 'none',
  13934. // fix parent-draggable Safari bug. #1326
  13935. userSelect: 'text',
  13936. WebkitUserSelect: 'text',
  13937. whiteSpace: 'pre-wrap',
  13938. wordWrap: 'break-word'
  13939. };
  13940. // The aria-expanded and aria-haspopup properties should only be rendered
  13941. // for a combobox.
  13942. var ariaRole = this.props.role || 'textbox';
  13943. var ariaExpanded = ariaRole === 'combobox' ? !!this.props.ariaExpanded : null;
  13944. var editorContentsProps = {
  13945. blockRenderMap: blockRenderMap,
  13946. blockRendererFn: blockRendererFn,
  13947. blockStyleFn: blockStyleFn,
  13948. customStyleMap: _extends$5({}, DefaultDraftInlineStyle, customStyleMap),
  13949. customStyleFn: customStyleFn,
  13950. editorKey: this._editorKey,
  13951. editorState: editorState,
  13952. key: 'contents' + this.state.contentsKey,
  13953. textDirectionality: textDirectionality
  13954. };
  13955. return React.createElement(
  13956. 'div',
  13957. { className: rootClass },
  13958. this._renderPlaceholder(),
  13959. React.createElement(
  13960. 'div',
  13961. {
  13962. className: cx_1('DraftEditor/editorContainer'),
  13963. ref: function ref(_ref3) {
  13964. return _this3.editorContainer = _ref3;
  13965. } },
  13966. React.createElement(
  13967. 'div',
  13968. {
  13969. 'aria-activedescendant': readOnly ? null : this.props.ariaActiveDescendantID,
  13970. 'aria-autocomplete': readOnly ? null : this.props.ariaAutoComplete,
  13971. 'aria-controls': readOnly ? null : this.props.ariaControls,
  13972. 'aria-describedby': this.props.ariaDescribedBy || this._placeholderAccessibilityID,
  13973. 'aria-expanded': readOnly ? null : ariaExpanded,
  13974. 'aria-label': this.props.ariaLabel,
  13975. 'aria-labelledby': this.props.ariaLabelledBy,
  13976. 'aria-multiline': this.props.ariaMultiline,
  13977. autoCapitalize: this.props.autoCapitalize,
  13978. autoComplete: this.props.autoComplete,
  13979. autoCorrect: this.props.autoCorrect,
  13980. className: cx_1({
  13981. // Chrome's built-in translation feature mutates the DOM in ways
  13982. // that Draft doesn't expect (ex: adding <font> tags inside
  13983. // DraftEditorLeaf spans) and causes problems. We add notranslate
  13984. // here which makes its autotranslation skip over this subtree.
  13985. notranslate: !readOnly,
  13986. 'public/DraftEditor/content': true
  13987. }),
  13988. contentEditable: !readOnly,
  13989. 'data-testid': this.props.webDriverTestID,
  13990. onBeforeInput: this._onBeforeInput,
  13991. onBlur: this._onBlur,
  13992. onCompositionEnd: this._onCompositionEnd,
  13993. onCompositionStart: this._onCompositionStart,
  13994. onCopy: this._onCopy,
  13995. onCut: this._onCut,
  13996. onDragEnd: this._onDragEnd,
  13997. onDragEnter: this.onDragEnter,
  13998. onDragLeave: this.onDragLeave,
  13999. onDragOver: this._onDragOver,
  14000. onDragStart: this._onDragStart,
  14001. onDrop: this._onDrop,
  14002. onFocus: this._onFocus,
  14003. onInput: this._onInput,
  14004. onKeyDown: this._onKeyDown,
  14005. onKeyPress: this._onKeyPress,
  14006. onKeyUp: this._onKeyUp,
  14007. onMouseUp: this._onMouseUp,
  14008. onPaste: this._onPaste,
  14009. onSelect: this._onSelect,
  14010. ref: function ref(_ref2) {
  14011. return _this3.editor = _ref2;
  14012. },
  14013. role: readOnly ? null : ariaRole,
  14014. spellCheck: allowSpellCheck && this.props.spellCheck,
  14015. style: contentStyle,
  14016. suppressContentEditableWarning: true,
  14017. tabIndex: this.props.tabIndex },
  14018. React.createElement(DraftEditorContents_react, editorContentsProps)
  14019. )
  14020. )
  14021. );
  14022. };
  14023. DraftEditor.prototype.componentDidMount = function componentDidMount() {
  14024. this.setMode('edit');
  14025. /**
  14026. * IE has a hardcoded "feature" that attempts to convert link text into
  14027. * anchors in contentEditable DOM. This breaks the editor's expectations of
  14028. * the DOM, and control is lost. Disable it to make IE behave.
  14029. * See: http://blogs.msdn.com/b/ieinternals/archive/2010/09/15/
  14030. * ie9-beta-minor-change-list.aspx
  14031. */
  14032. if (isIE) {
  14033. document.execCommand('AutoUrlDetect', false, false);
  14034. }
  14035. };
  14036. /**
  14037. * Prevent selection events from affecting the current editor state. This
  14038. * is mostly intended to defend against IE, which fires off `selectionchange`
  14039. * events regardless of whether the selection is set via the browser or
  14040. * programmatically. We only care about selection events that occur because
  14041. * of browser interaction, not re-renders and forced selections.
  14042. */
  14043. DraftEditor.prototype.componentWillUpdate = function componentWillUpdate(nextProps) {
  14044. this._blockSelectEvents = true;
  14045. this._latestEditorState = nextProps.editorState;
  14046. };
  14047. DraftEditor.prototype.componentDidUpdate = function componentDidUpdate() {
  14048. this._blockSelectEvents = false;
  14049. this._latestCommittedEditorState = this.props.editorState;
  14050. };
  14051. /**
  14052. * Used via `this.focus()`.
  14053. *
  14054. * Force focus back onto the editor node.
  14055. *
  14056. * We attempt to preserve scroll position when focusing. You can also pass
  14057. * a specified scroll position (for cases like `cut` behavior where it should
  14058. * be restored to a known position).
  14059. */
  14060. /**
  14061. * Used via `this.setMode(...)`.
  14062. *
  14063. * Set the behavior mode for the editor component. This switches the current
  14064. * handler module to ensure that DOM events are managed appropriately for
  14065. * the active mode.
  14066. */
  14067. /**
  14068. * Used via `this.restoreEditorDOM()`.
  14069. *
  14070. * Force a complete re-render of the DraftEditorContents based on the current
  14071. * EditorState. This is useful when we know we are going to lose control of
  14072. * the DOM state (cut command, IME) and we want to make sure that
  14073. * reconciliation occurs on a version of the DOM that is synchronized with
  14074. * our EditorState.
  14075. */
  14076. /**
  14077. * Used via `this.setClipboard(...)`.
  14078. *
  14079. * Set the clipboard state for a cut/copy event.
  14080. */
  14081. /**
  14082. * Used via `this.getClipboard()`.
  14083. *
  14084. * Retrieve the clipboard state for a cut/copy event.
  14085. */
  14086. /**
  14087. * Used via `this.update(...)`.
  14088. *
  14089. * Propagate a new `EditorState` object to higher-level components. This is
  14090. * the method by which event handlers inform the `DraftEditor` component of
  14091. * state changes. A component that composes a `DraftEditor` **must** provide
  14092. * an `onChange` prop to receive state updates passed along from this
  14093. * function.
  14094. */
  14095. /**
  14096. * Used in conjunction with `onDragLeave()`, by counting the number of times
  14097. * a dragged element enters and leaves the editor (or any of its children),
  14098. * to determine when the dragged element absolutely leaves the editor.
  14099. */
  14100. /**
  14101. * See `onDragEnter()`.
  14102. */
  14103. return DraftEditor;
  14104. }(React.Component);
  14105. DraftEditor.defaultProps = {
  14106. blockRenderMap: DefaultDraftBlockRenderMap_1,
  14107. blockRendererFn: emptyFunction_1.thatReturnsNull,
  14108. blockStyleFn: emptyFunction_1.thatReturns(''),
  14109. keyBindingFn: getDefaultKeyBinding_1,
  14110. readOnly: false,
  14111. spellCheck: false,
  14112. stripPastedStyles: false
  14113. };
  14114. var DraftEditor_react = DraftEditor;
  14115. /**
  14116. * Copyright (c) 2013-present, Facebook, Inc.
  14117. * All rights reserved.
  14118. *
  14119. * This source code is licensed under the BSD-style license found in the
  14120. * LICENSE file in the root directory of this source tree. An additional grant
  14121. * of patent rights can be found in the PATENTS file in the same directory.
  14122. *
  14123. * @providesModule DraftStringKey
  14124. * @format
  14125. *
  14126. */
  14127. var DraftStringKey = {
  14128. stringify: function stringify(key) {
  14129. return '_' + String(key);
  14130. },
  14131. unstringify: function unstringify(key) {
  14132. return key.slice(1);
  14133. }
  14134. };
  14135. var DraftStringKey_1 = DraftStringKey;
  14136. var strlen$1 = UnicodeUtils_1.strlen;
  14137. /**
  14138. * Convert to UTF-8 character counts for storage.
  14139. */
  14140. function encodeEntityRanges(block, storageMap) {
  14141. var encoded = [];
  14142. block.findEntityRanges(function (character) {
  14143. return !!character.getEntity();
  14144. }, function ( /*number*/start, /*number*/end) {
  14145. var text = block.getText();
  14146. var key = block.getEntityAt(start);
  14147. encoded.push({
  14148. offset: strlen$1(text.slice(0, start)),
  14149. length: strlen$1(text.slice(start, end)),
  14150. // Encode the key as a number for range storage.
  14151. key: Number(storageMap[DraftStringKey_1.stringify(key)])
  14152. });
  14153. });
  14154. return encoded;
  14155. }
  14156. var encodeEntityRanges_1 = encodeEntityRanges;
  14157. var areEqual$1 = function areEqual(a, b) {
  14158. return a === b;
  14159. };
  14160. var isTruthy = function isTruthy(a) {
  14161. return !!a;
  14162. };
  14163. var EMPTY_ARRAY = [];
  14164. /**
  14165. * Helper function for getting encoded styles for each inline style. Convert
  14166. * to UTF-8 character counts for storage.
  14167. */
  14168. function getEncodedInlinesForType(block, styleList, styleToEncode) {
  14169. var ranges = [];
  14170. // Obtain an array with ranges for only the specified style.
  14171. var filteredInlines = styleList.map(function (style) {
  14172. return style.has(styleToEncode);
  14173. }).toList();
  14174. findRangesImmutable_1(filteredInlines, areEqual$1,
  14175. // We only want to keep ranges with nonzero style values.
  14176. isTruthy, function (start, end) {
  14177. var text = block.getText();
  14178. ranges.push({
  14179. offset: UnicodeUtils_1.strlen(text.slice(0, start)),
  14180. length: UnicodeUtils_1.strlen(text.slice(start, end)),
  14181. style: styleToEncode
  14182. });
  14183. });
  14184. return ranges;
  14185. }
  14186. /*
  14187. * Retrieve the encoded arrays of inline styles, with each individual style
  14188. * treated separately.
  14189. */
  14190. function encodeInlineStyleRanges(block) {
  14191. var styleList = block.getCharacterList().map(function (c) {
  14192. return c.getStyle();
  14193. }).toList();
  14194. var ranges = styleList.flatten().toSet().map(function (style) {
  14195. return getEncodedInlinesForType(block, styleList, style);
  14196. });
  14197. return Array.prototype.concat.apply(EMPTY_ARRAY, ranges.toJS());
  14198. }
  14199. var encodeInlineStyleRanges_1 = encodeInlineStyleRanges;
  14200. 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; };
  14201. var createRawBlock = function createRawBlock(block, entityStorageMap) {
  14202. return {
  14203. key: block.getKey(),
  14204. text: block.getText(),
  14205. type: block.getType(),
  14206. depth: block.getDepth(),
  14207. inlineStyleRanges: encodeInlineStyleRanges_1(block),
  14208. entityRanges: encodeEntityRanges_1(block, entityStorageMap),
  14209. data: block.getData().toObject()
  14210. };
  14211. };
  14212. var insertRawBlock = function insertRawBlock(block, entityMap, rawBlocks, blockCacheRef) {
  14213. if (block instanceof ContentBlock_1) {
  14214. rawBlocks.push(createRawBlock(block, entityMap));
  14215. return;
  14216. }
  14217. !(block instanceof ContentBlockNode_1) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'block is not a BlockNode') : invariant_1(false) : void 0;
  14218. var parentKey = block.getParentKey();
  14219. var rawBlock = blockCacheRef[block.getKey()] = _extends$6({}, createRawBlock(block, entityMap), {
  14220. children: []
  14221. });
  14222. if (parentKey) {
  14223. blockCacheRef[parentKey].children.push(rawBlock);
  14224. return;
  14225. }
  14226. rawBlocks.push(rawBlock);
  14227. };
  14228. var encodeRawBlocks = function encodeRawBlocks(contentState, rawState) {
  14229. var entityMap = rawState.entityMap;
  14230. var rawBlocks = [];
  14231. var blockCacheRef = {};
  14232. var entityCacheRef = {};
  14233. var entityStorageKey = 0;
  14234. contentState.getBlockMap().forEach(function (block) {
  14235. block.findEntityRanges(function (character) {
  14236. return character.getEntity() !== null;
  14237. }, function (start) {
  14238. var entityKey = block.getEntityAt(start);
  14239. // Stringify to maintain order of otherwise numeric keys.
  14240. var stringifiedEntityKey = DraftStringKey_1.stringify(entityKey);
  14241. // This makes this function resilient to two entities
  14242. // erroneously having the same key
  14243. if (entityCacheRef[stringifiedEntityKey]) {
  14244. return;
  14245. }
  14246. entityCacheRef[stringifiedEntityKey] = entityKey;
  14247. // we need the `any` casting here since this is a temporary state
  14248. // where we will later on flip the entity map and populate it with
  14249. // real entity, at this stage we just need to map back the entity
  14250. // key used by the BlockNode
  14251. entityMap[stringifiedEntityKey] = '' + entityStorageKey;
  14252. entityStorageKey++;
  14253. });
  14254. insertRawBlock(block, entityMap, rawBlocks, blockCacheRef);
  14255. });
  14256. return {
  14257. blocks: rawBlocks,
  14258. entityMap: entityMap
  14259. };
  14260. };
  14261. // Flip storage map so that our storage keys map to global
  14262. // DraftEntity keys.
  14263. var encodeRawEntityMap = function encodeRawEntityMap(contentState, rawState) {
  14264. var blocks = rawState.blocks,
  14265. entityMap = rawState.entityMap;
  14266. var rawEntityMap = {};
  14267. Object.keys(entityMap).forEach(function (key, index) {
  14268. var entity = contentState.getEntity(DraftStringKey_1.unstringify(key));
  14269. rawEntityMap[index] = {
  14270. type: entity.getType(),
  14271. mutability: entity.getMutability(),
  14272. data: entity.getData()
  14273. };
  14274. });
  14275. return {
  14276. blocks: blocks,
  14277. entityMap: rawEntityMap
  14278. };
  14279. };
  14280. var convertFromDraftStateToRaw = function convertFromDraftStateToRaw(contentState) {
  14281. var rawDraftContentState = {
  14282. entityMap: {},
  14283. blocks: []
  14284. };
  14285. // add blocks
  14286. rawDraftContentState = encodeRawBlocks(contentState, rawDraftContentState);
  14287. // add entities
  14288. rawDraftContentState = encodeRawEntityMap(contentState, rawDraftContentState);
  14289. return rawDraftContentState;
  14290. };
  14291. var convertFromDraftStateToRaw_1 = convertFromDraftStateToRaw;
  14292. 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; };
  14293. /**
  14294. * Copyright (c) 2013-present, Facebook, Inc.
  14295. * All rights reserved.
  14296. *
  14297. * This source code is licensed under the BSD-style license found in the
  14298. * LICENSE file in the root directory of this source tree. An additional grant
  14299. * of patent rights can be found in the PATENTS file in the same directory.
  14300. *
  14301. * @providesModule DraftTreeAdapter
  14302. * @format
  14303. *
  14304. *
  14305. * This is unstable and not part of the public API and should not be used by
  14306. * production systems. This file may be update/removed without notice.
  14307. */
  14308. var traverseInDepthOrder = function traverseInDepthOrder(blocks, fn) {
  14309. var stack = [].concat(blocks).reverse();
  14310. while (stack.length) {
  14311. var _block = stack.pop();
  14312. fn(_block);
  14313. var children = _block.children;
  14314. !Array.isArray(children) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Invalid tree raw block') : invariant_1(false) : void 0;
  14315. stack = stack.concat([].concat(children.reverse()));
  14316. }
  14317. };
  14318. var isListBlock = function isListBlock(block) {
  14319. if (!(block && block.type)) {
  14320. return false;
  14321. }
  14322. var type = block.type;
  14323. return type === 'unordered-list-item' || type === 'ordered-list-item';
  14324. };
  14325. var addDepthToChildren = function addDepthToChildren(block) {
  14326. if (Array.isArray(block.children)) {
  14327. block.children = block.children.map(function (child) {
  14328. return child.type === block.type ? _extends$7({}, child, { depth: (block.depth || 0) + 1 }) : child;
  14329. });
  14330. }
  14331. };
  14332. /**
  14333. * This adapter is intended to be be used as an adapter to draft tree data
  14334. *
  14335. * draft state <=====> draft tree state
  14336. */
  14337. var DraftTreeAdapter = {
  14338. /**
  14339. * Converts from a tree raw state back to draft raw state
  14340. */
  14341. fromRawTreeStateToRawState: function fromRawTreeStateToRawState(draftTreeState) {
  14342. var blocks = draftTreeState.blocks;
  14343. var transformedBlocks = [];
  14344. !Array.isArray(blocks) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Invalid raw state') : invariant_1(false) : void 0;
  14345. if (!Array.isArray(blocks) || !blocks.length) {
  14346. return draftTreeState;
  14347. }
  14348. traverseInDepthOrder(blocks, function (block) {
  14349. var newBlock = _extends$7({}, block);
  14350. if (isListBlock(block)) {
  14351. newBlock.depth = newBlock.depth || 0;
  14352. addDepthToChildren(block);
  14353. }
  14354. delete newBlock.children;
  14355. transformedBlocks.push(newBlock);
  14356. });
  14357. draftTreeState.blocks = transformedBlocks;
  14358. return _extends$7({}, draftTreeState, {
  14359. blocks: transformedBlocks
  14360. });
  14361. },
  14362. /**
  14363. * Converts from draft raw state to tree draft state
  14364. */
  14365. fromRawStateToRawTreeState: function fromRawStateToRawTreeState(draftState) {
  14366. var lastListDepthCacheRef = {};
  14367. var transformedBlocks = [];
  14368. draftState.blocks.forEach(function (block) {
  14369. var isList = isListBlock(block);
  14370. var depth = block.depth || 0;
  14371. var treeBlock = _extends$7({}, block, {
  14372. children: []
  14373. });
  14374. if (!isList) {
  14375. // reset the cache path
  14376. lastListDepthCacheRef = {};
  14377. transformedBlocks.push(treeBlock);
  14378. return;
  14379. }
  14380. // update our depth cache reference path
  14381. lastListDepthCacheRef[depth] = treeBlock;
  14382. // if we are greater than zero we must have seen a parent already
  14383. if (depth > 0) {
  14384. var parent = lastListDepthCacheRef[depth - 1];
  14385. !parent ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Invalid depth for RawDraftContentBlock') : invariant_1(false) : void 0;
  14386. // push nested list blocks
  14387. parent.children.push(treeBlock);
  14388. return;
  14389. }
  14390. // push root list blocks
  14391. transformedBlocks.push(treeBlock);
  14392. });
  14393. return _extends$7({}, draftState, {
  14394. blocks: transformedBlocks
  14395. });
  14396. }
  14397. };
  14398. var DraftTreeAdapter_1 = DraftTreeAdapter;
  14399. var List$c = immutable.List;
  14400. function createCharacterList(inlineStyles, entities) {
  14401. var characterArray = inlineStyles.map(function (style, ii) {
  14402. var entity = entities[ii];
  14403. return CharacterMetadata_1.create({ style: style, entity: entity });
  14404. });
  14405. return List$c(characterArray);
  14406. }
  14407. var createCharacterList_1 = createCharacterList;
  14408. var substr$1 = UnicodeUtils_1.substr;
  14409. /**
  14410. * Convert to native JavaScript string lengths to determine ranges.
  14411. */
  14412. function decodeEntityRanges(text, ranges) {
  14413. var entities = Array(text.length).fill(null);
  14414. if (ranges) {
  14415. ranges.forEach(function (range) {
  14416. // Using Unicode-enabled substrings converted to JavaScript lengths,
  14417. // fill the output array with entity keys.
  14418. var start = substr$1(text, 0, range.offset).length;
  14419. var end = start + substr$1(text, range.offset, range.length).length;
  14420. for (var ii = start; ii < end; ii++) {
  14421. entities[ii] = range.key;
  14422. }
  14423. });
  14424. }
  14425. return entities;
  14426. }
  14427. var decodeEntityRanges_1 = decodeEntityRanges;
  14428. var OrderedSet$6 = immutable.OrderedSet;
  14429. var substr$2 = UnicodeUtils_1.substr;
  14430. var EMPTY_SET$3 = OrderedSet$6();
  14431. /**
  14432. * Convert to native JavaScript string lengths to determine ranges.
  14433. */
  14434. function decodeInlineStyleRanges(text, ranges) {
  14435. var styles = Array(text.length).fill(EMPTY_SET$3);
  14436. if (ranges) {
  14437. ranges.forEach(function ( /*object*/range) {
  14438. var cursor = substr$2(text, 0, range.offset).length;
  14439. var end = cursor + substr$2(text, range.offset, range.length).length;
  14440. while (cursor < end) {
  14441. styles[cursor] = styles[cursor].add(range.style);
  14442. cursor++;
  14443. }
  14444. });
  14445. }
  14446. return styles;
  14447. }
  14448. var decodeInlineStyleRanges_1 = decodeInlineStyleRanges;
  14449. 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; };
  14450. var List$d = immutable.List,
  14451. Map$9 = immutable.Map,
  14452. OrderedMap$4 = immutable.OrderedMap;
  14453. var decodeBlockNodeConfig = function decodeBlockNodeConfig(block, entityMap) {
  14454. var key = block.key,
  14455. type = block.type,
  14456. data = block.data,
  14457. text = block.text,
  14458. depth = block.depth;
  14459. var blockNodeConfig = {
  14460. text: text,
  14461. depth: depth || 0,
  14462. type: type || 'unstyled',
  14463. key: key || generateRandomKey_1(),
  14464. data: Map$9(data),
  14465. characterList: decodeCharacterList(block, entityMap)
  14466. };
  14467. return blockNodeConfig;
  14468. };
  14469. var decodeCharacterList = function decodeCharacterList(block, entityMap) {
  14470. var text = block.text,
  14471. rawEntityRanges = block.entityRanges,
  14472. rawInlineStyleRanges = block.inlineStyleRanges;
  14473. var entityRanges = rawEntityRanges || [];
  14474. var inlineStyleRanges = rawInlineStyleRanges || [];
  14475. // Translate entity range keys to the DraftEntity map.
  14476. return createCharacterList_1(decodeInlineStyleRanges_1(text, inlineStyleRanges), decodeEntityRanges_1(text, entityRanges.filter(function (range) {
  14477. return entityMap.hasOwnProperty(range.key);
  14478. }).map(function (range) {
  14479. return _extends$8({}, range, { key: entityMap[range.key] });
  14480. })));
  14481. };
  14482. var decodeContentBlocks = function decodeContentBlocks(blocks, entityMap) {
  14483. return OrderedMap$4(blocks.map(function (block) {
  14484. var contentBlock = new ContentBlock_1(decodeBlockNodeConfig(block, entityMap));
  14485. return [contentBlock.getKey(), contentBlock];
  14486. }));
  14487. };
  14488. var decodeRawBlocks = function decodeRawBlocks(rawState, entityMap) {
  14489. var isTreeRawBlock = Array.isArray(rawState.blocks[0].children);
  14490. var rawBlocks = rawState.blocks;
  14491. {
  14492. return decodeContentBlocks(isTreeRawBlock ? DraftTreeAdapter_1.fromRawTreeStateToRawState(rawState).blocks : rawBlocks, entityMap);
  14493. }
  14494. };
  14495. var decodeRawEntityMap = function decodeRawEntityMap(rawState) {
  14496. var rawEntityMap = rawState.entityMap;
  14497. var entityMap = {};
  14498. // TODO: Update this once we completely remove DraftEntity
  14499. Object.keys(rawEntityMap).forEach(function (rawEntityKey) {
  14500. var _rawEntityMap$rawEnti = rawEntityMap[rawEntityKey],
  14501. type = _rawEntityMap$rawEnti.type,
  14502. mutability = _rawEntityMap$rawEnti.mutability,
  14503. data = _rawEntityMap$rawEnti.data;
  14504. // get the key reference to created entity
  14505. entityMap[rawEntityKey] = DraftEntity_1.__create(type, mutability, data || {});
  14506. });
  14507. return entityMap;
  14508. };
  14509. var convertFromRawToDraftState = function convertFromRawToDraftState(rawState) {
  14510. !Array.isArray(rawState.blocks) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'invalid RawDraftContentState') : invariant_1(false) : void 0;
  14511. // decode entities
  14512. var entityMap = decodeRawEntityMap(rawState);
  14513. // decode blockMap
  14514. var blockMap = decodeRawBlocks(rawState, entityMap);
  14515. // create initial selection
  14516. var selectionState = blockMap.isEmpty() ? new SelectionState_1() : SelectionState_1.createEmpty(blockMap.first().getKey());
  14517. return new ContentState_1({
  14518. blockMap: blockMap,
  14519. entityMap: entityMap,
  14520. selectionBefore: selectionState,
  14521. selectionAfter: selectionState
  14522. });
  14523. };
  14524. var convertFromRawToDraftState_1 = convertFromRawToDraftState;
  14525. /**
  14526. * Like range.getBoundingClientRect() but normalizes for browser bugs.
  14527. */
  14528. function getRangeBoundingClientRect(range) {
  14529. // "Return a DOMRect object describing the smallest rectangle that includes
  14530. // the first rectangle in list and all of the remaining rectangles of which
  14531. // the height or width is not zero."
  14532. // http://www.w3.org/TR/cssom-view/#dom-range-getboundingclientrect
  14533. var rects = getRangeClientRects_1(range);
  14534. var top = 0;
  14535. var right = 0;
  14536. var bottom = 0;
  14537. var left = 0;
  14538. if (rects.length) {
  14539. // If the first rectangle has 0 width, we use the second, this is needed
  14540. // because Chrome renders a 0 width rectangle when the selection contains
  14541. // a line break.
  14542. if (rects.length > 1 && rects[0].width === 0) {
  14543. var _rects$ = rects[1];
  14544. top = _rects$.top;
  14545. right = _rects$.right;
  14546. bottom = _rects$.bottom;
  14547. left = _rects$.left;
  14548. } else {
  14549. var _rects$2 = rects[0];
  14550. top = _rects$2.top;
  14551. right = _rects$2.right;
  14552. bottom = _rects$2.bottom;
  14553. left = _rects$2.left;
  14554. }
  14555. for (var ii = 1; ii < rects.length; ii++) {
  14556. var rect = rects[ii];
  14557. if (rect.height !== 0 && rect.width !== 0) {
  14558. top = Math.min(top, rect.top);
  14559. right = Math.max(right, rect.right);
  14560. bottom = Math.max(bottom, rect.bottom);
  14561. left = Math.min(left, rect.left);
  14562. }
  14563. }
  14564. }
  14565. return {
  14566. top: top,
  14567. right: right,
  14568. bottom: bottom,
  14569. left: left,
  14570. width: right - left,
  14571. height: bottom - top
  14572. };
  14573. }
  14574. var getRangeBoundingClientRect_1 = getRangeBoundingClientRect;
  14575. /**
  14576. * Return the bounding ClientRect for the visible DOM selection, if any.
  14577. * In cases where there are no selected ranges or the bounding rect is
  14578. * temporarily invalid, return null.
  14579. */
  14580. function getVisibleSelectionRect(global) {
  14581. var selection = global.getSelection();
  14582. if (!selection.rangeCount) {
  14583. return null;
  14584. }
  14585. var range = selection.getRangeAt(0);
  14586. var boundingRect = getRangeBoundingClientRect_1(range);
  14587. var top = boundingRect.top,
  14588. right = boundingRect.right,
  14589. bottom = boundingRect.bottom,
  14590. left = boundingRect.left;
  14591. // When a re-render leads to a node being removed, the DOM selection will
  14592. // temporarily be placed on an ancestor node, which leads to an invalid
  14593. // bounding rect. Discard this state.
  14594. if (top === 0 && right === 0 && bottom === 0 && left === 0) {
  14595. return null;
  14596. }
  14597. return boundingRect;
  14598. }
  14599. var getVisibleSelectionRect_1 = getVisibleSelectionRect;
  14600. var DraftPublic = {
  14601. Editor: DraftEditor_react,
  14602. EditorBlock: DraftEditorBlock_react,
  14603. EditorState: EditorState_1,
  14604. CompositeDecorator: CompositeDraftDecorator_1,
  14605. Entity: DraftEntity_1,
  14606. EntityInstance: DraftEntityInstance_1,
  14607. BlockMapBuilder: BlockMapBuilder_1,
  14608. CharacterMetadata: CharacterMetadata_1,
  14609. ContentBlock: ContentBlock_1,
  14610. ContentState: ContentState_1,
  14611. SelectionState: SelectionState_1,
  14612. AtomicBlockUtils: AtomicBlockUtils_1,
  14613. KeyBindingUtil: KeyBindingUtil_1,
  14614. Modifier: DraftModifier_1,
  14615. RichUtils: RichTextEditorUtil_1,
  14616. DefaultDraftBlockRenderMap: DefaultDraftBlockRenderMap_1,
  14617. DefaultDraftInlineStyle: DefaultDraftInlineStyle,
  14618. convertFromHTML: convertFromHTMLToContentBlocks,
  14619. convertFromRaw: convertFromRawToDraftState_1,
  14620. convertToRaw: convertFromDraftStateToRaw_1,
  14621. genKey: generateRandomKey_1,
  14622. getDefaultKeyBinding: getDefaultKeyBinding_1,
  14623. getVisibleSelectionRect: getVisibleSelectionRect_1
  14624. };
  14625. var Draft = DraftPublic;
  14626. var immutable$1 = createCommonjsModule(function (module, exports) {
  14627. /**
  14628. * Copyright (c) 2014-present, Facebook, Inc.
  14629. *
  14630. * This source code is licensed under the MIT license found in the
  14631. * LICENSE file in the root directory of this source tree.
  14632. */
  14633. (function (global, factory) {
  14634. factory(exports) ;
  14635. }(commonjsGlobal, (function (exports) {
  14636. // Used for setting prototype methods that IE8 chokes on.
  14637. var DELETE = 'delete';
  14638. // Constants describing the size of trie nodes.
  14639. var SHIFT = 5; // Resulted in best performance after ______?
  14640. var SIZE = 1 << SHIFT;
  14641. var MASK = SIZE - 1;
  14642. // A consistent shared value representing "not set" which equals nothing other
  14643. // than itself, and nothing that could be provided externally.
  14644. var NOT_SET = {};
  14645. // Boolean references, Rough equivalent of `bool &`.
  14646. function MakeRef() {
  14647. return { value: false };
  14648. }
  14649. function SetRef(ref) {
  14650. if (ref) {
  14651. ref.value = true;
  14652. }
  14653. }
  14654. // A function which returns a value representing an "owner" for transient writes
  14655. // to tries. The return value will only ever equal itself, and will not equal
  14656. // the return of any subsequent call of this function.
  14657. function OwnerID() {}
  14658. function ensureSize(iter) {
  14659. if (iter.size === undefined) {
  14660. iter.size = iter.__iterate(returnTrue);
  14661. }
  14662. return iter.size;
  14663. }
  14664. function wrapIndex(iter, index) {
  14665. // This implements "is array index" which the ECMAString spec defines as:
  14666. //
  14667. // A String property name P is an array index if and only if
  14668. // ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal
  14669. // to 2^32−1.
  14670. //
  14671. // http://www.ecma-international.org/ecma-262/6.0/#sec-array-exotic-objects
  14672. if (typeof index !== 'number') {
  14673. var uint32Index = index >>> 0; // N >>> 0 is shorthand for ToUint32
  14674. if ('' + uint32Index !== index || uint32Index === 4294967295) {
  14675. return NaN;
  14676. }
  14677. index = uint32Index;
  14678. }
  14679. return index < 0 ? ensureSize(iter) + index : index;
  14680. }
  14681. function returnTrue() {
  14682. return true;
  14683. }
  14684. function wholeSlice(begin, end, size) {
  14685. return (
  14686. ((begin === 0 && !isNeg(begin)) ||
  14687. (size !== undefined && begin <= -size)) &&
  14688. (end === undefined || (size !== undefined && end >= size))
  14689. );
  14690. }
  14691. function resolveBegin(begin, size) {
  14692. return resolveIndex(begin, size, 0);
  14693. }
  14694. function resolveEnd(end, size) {
  14695. return resolveIndex(end, size, size);
  14696. }
  14697. function resolveIndex(index, size, defaultIndex) {
  14698. // Sanitize indices using this shorthand for ToInt32(argument)
  14699. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  14700. return index === undefined
  14701. ? defaultIndex
  14702. : isNeg(index)
  14703. ? size === Infinity
  14704. ? size
  14705. : Math.max(0, size + index) | 0
  14706. : size === undefined || size === index
  14707. ? index
  14708. : Math.min(size, index) | 0;
  14709. }
  14710. function isNeg(value) {
  14711. // Account for -0 which is negative, but not less than 0.
  14712. return value < 0 || (value === 0 && 1 / value === -Infinity);
  14713. }
  14714. // Note: value is unchanged to not break immutable-devtools.
  14715. var IS_COLLECTION_SYMBOL = '@@__IMMUTABLE_ITERABLE__@@';
  14716. function isCollection(maybeCollection) {
  14717. return Boolean(maybeCollection && maybeCollection[IS_COLLECTION_SYMBOL]);
  14718. }
  14719. var IS_KEYED_SYMBOL = '@@__IMMUTABLE_KEYED__@@';
  14720. function isKeyed(maybeKeyed) {
  14721. return Boolean(maybeKeyed && maybeKeyed[IS_KEYED_SYMBOL]);
  14722. }
  14723. var IS_INDEXED_SYMBOL = '@@__IMMUTABLE_INDEXED__@@';
  14724. function isIndexed(maybeIndexed) {
  14725. return Boolean(maybeIndexed && maybeIndexed[IS_INDEXED_SYMBOL]);
  14726. }
  14727. function isAssociative(maybeAssociative) {
  14728. return isKeyed(maybeAssociative) || isIndexed(maybeAssociative);
  14729. }
  14730. var Collection = function Collection(value) {
  14731. return isCollection(value) ? value : Seq(value);
  14732. };
  14733. var KeyedCollection = /*@__PURE__*/(function (Collection) {
  14734. function KeyedCollection(value) {
  14735. return isKeyed(value) ? value : KeyedSeq(value);
  14736. }
  14737. if ( Collection ) KeyedCollection.__proto__ = Collection;
  14738. KeyedCollection.prototype = Object.create( Collection && Collection.prototype );
  14739. KeyedCollection.prototype.constructor = KeyedCollection;
  14740. return KeyedCollection;
  14741. }(Collection));
  14742. var IndexedCollection = /*@__PURE__*/(function (Collection) {
  14743. function IndexedCollection(value) {
  14744. return isIndexed(value) ? value : IndexedSeq(value);
  14745. }
  14746. if ( Collection ) IndexedCollection.__proto__ = Collection;
  14747. IndexedCollection.prototype = Object.create( Collection && Collection.prototype );
  14748. IndexedCollection.prototype.constructor = IndexedCollection;
  14749. return IndexedCollection;
  14750. }(Collection));
  14751. var SetCollection = /*@__PURE__*/(function (Collection) {
  14752. function SetCollection(value) {
  14753. return isCollection(value) && !isAssociative(value) ? value : SetSeq(value);
  14754. }
  14755. if ( Collection ) SetCollection.__proto__ = Collection;
  14756. SetCollection.prototype = Object.create( Collection && Collection.prototype );
  14757. SetCollection.prototype.constructor = SetCollection;
  14758. return SetCollection;
  14759. }(Collection));
  14760. Collection.Keyed = KeyedCollection;
  14761. Collection.Indexed = IndexedCollection;
  14762. Collection.Set = SetCollection;
  14763. var IS_SEQ_SYMBOL = '@@__IMMUTABLE_SEQ__@@';
  14764. function isSeq(maybeSeq) {
  14765. return Boolean(maybeSeq && maybeSeq[IS_SEQ_SYMBOL]);
  14766. }
  14767. var IS_RECORD_SYMBOL = '@@__IMMUTABLE_RECORD__@@';
  14768. function isRecord(maybeRecord) {
  14769. return Boolean(maybeRecord && maybeRecord[IS_RECORD_SYMBOL]);
  14770. }
  14771. function isImmutable(maybeImmutable) {
  14772. return isCollection(maybeImmutable) || isRecord(maybeImmutable);
  14773. }
  14774. var IS_ORDERED_SYMBOL = '@@__IMMUTABLE_ORDERED__@@';
  14775. function isOrdered(maybeOrdered) {
  14776. return Boolean(maybeOrdered && maybeOrdered[IS_ORDERED_SYMBOL]);
  14777. }
  14778. var ITERATE_KEYS = 0;
  14779. var ITERATE_VALUES = 1;
  14780. var ITERATE_ENTRIES = 2;
  14781. var REAL_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
  14782. var FAUX_ITERATOR_SYMBOL = '@@iterator';
  14783. var ITERATOR_SYMBOL = REAL_ITERATOR_SYMBOL || FAUX_ITERATOR_SYMBOL;
  14784. var Iterator = function Iterator(next) {
  14785. this.next = next;
  14786. };
  14787. Iterator.prototype.toString = function toString () {
  14788. return '[Iterator]';
  14789. };
  14790. Iterator.KEYS = ITERATE_KEYS;
  14791. Iterator.VALUES = ITERATE_VALUES;
  14792. Iterator.ENTRIES = ITERATE_ENTRIES;
  14793. Iterator.prototype.inspect = Iterator.prototype.toSource = function() {
  14794. return this.toString();
  14795. };
  14796. Iterator.prototype[ITERATOR_SYMBOL] = function() {
  14797. return this;
  14798. };
  14799. function iteratorValue(type, k, v, iteratorResult) {
  14800. var value = type === 0 ? k : type === 1 ? v : [k, v];
  14801. iteratorResult
  14802. ? (iteratorResult.value = value)
  14803. : (iteratorResult = {
  14804. value: value,
  14805. done: false,
  14806. });
  14807. return iteratorResult;
  14808. }
  14809. function iteratorDone() {
  14810. return { value: undefined, done: true };
  14811. }
  14812. function hasIterator(maybeIterable) {
  14813. return !!getIteratorFn(maybeIterable);
  14814. }
  14815. function isIterator(maybeIterator) {
  14816. return maybeIterator && typeof maybeIterator.next === 'function';
  14817. }
  14818. function getIterator(iterable) {
  14819. var iteratorFn = getIteratorFn(iterable);
  14820. return iteratorFn && iteratorFn.call(iterable);
  14821. }
  14822. function getIteratorFn(iterable) {
  14823. var iteratorFn =
  14824. iterable &&
  14825. ((REAL_ITERATOR_SYMBOL && iterable[REAL_ITERATOR_SYMBOL]) ||
  14826. iterable[FAUX_ITERATOR_SYMBOL]);
  14827. if (typeof iteratorFn === 'function') {
  14828. return iteratorFn;
  14829. }
  14830. }
  14831. var hasOwnProperty = Object.prototype.hasOwnProperty;
  14832. function isArrayLike(value) {
  14833. if (Array.isArray(value) || typeof value === 'string') {
  14834. return true;
  14835. }
  14836. return (
  14837. value &&
  14838. typeof value === 'object' &&
  14839. Number.isInteger(value.length) &&
  14840. value.length >= 0 &&
  14841. (value.length === 0
  14842. ? // Only {length: 0} is considered Array-like.
  14843. Object.keys(value).length === 1
  14844. : // An object is only Array-like if it has a property where the last value
  14845. // in the array-like may be found (which could be undefined).
  14846. value.hasOwnProperty(value.length - 1))
  14847. );
  14848. }
  14849. var Seq = /*@__PURE__*/(function (Collection$$1) {
  14850. function Seq(value) {
  14851. return value === null || value === undefined
  14852. ? emptySequence()
  14853. : isImmutable(value)
  14854. ? value.toSeq()
  14855. : seqFromValue(value);
  14856. }
  14857. if ( Collection$$1 ) Seq.__proto__ = Collection$$1;
  14858. Seq.prototype = Object.create( Collection$$1 && Collection$$1.prototype );
  14859. Seq.prototype.constructor = Seq;
  14860. Seq.prototype.toSeq = function toSeq () {
  14861. return this;
  14862. };
  14863. Seq.prototype.toString = function toString () {
  14864. return this.__toString('Seq {', '}');
  14865. };
  14866. Seq.prototype.cacheResult = function cacheResult () {
  14867. if (!this._cache && this.__iterateUncached) {
  14868. this._cache = this.entrySeq().toArray();
  14869. this.size = this._cache.length;
  14870. }
  14871. return this;
  14872. };
  14873. // abstract __iterateUncached(fn, reverse)
  14874. Seq.prototype.__iterate = function __iterate (fn, reverse) {
  14875. var cache = this._cache;
  14876. if (cache) {
  14877. var size = cache.length;
  14878. var i = 0;
  14879. while (i !== size) {
  14880. var entry = cache[reverse ? size - ++i : i++];
  14881. if (fn(entry[1], entry[0], this) === false) {
  14882. break;
  14883. }
  14884. }
  14885. return i;
  14886. }
  14887. return this.__iterateUncached(fn, reverse);
  14888. };
  14889. // abstract __iteratorUncached(type, reverse)
  14890. Seq.prototype.__iterator = function __iterator (type, reverse) {
  14891. var cache = this._cache;
  14892. if (cache) {
  14893. var size = cache.length;
  14894. var i = 0;
  14895. return new Iterator(function () {
  14896. if (i === size) {
  14897. return iteratorDone();
  14898. }
  14899. var entry = cache[reverse ? size - ++i : i++];
  14900. return iteratorValue(type, entry[0], entry[1]);
  14901. });
  14902. }
  14903. return this.__iteratorUncached(type, reverse);
  14904. };
  14905. return Seq;
  14906. }(Collection));
  14907. var KeyedSeq = /*@__PURE__*/(function (Seq) {
  14908. function KeyedSeq(value) {
  14909. return value === null || value === undefined
  14910. ? emptySequence().toKeyedSeq()
  14911. : isCollection(value)
  14912. ? isKeyed(value)
  14913. ? value.toSeq()
  14914. : value.fromEntrySeq()
  14915. : isRecord(value)
  14916. ? value.toSeq()
  14917. : keyedSeqFromValue(value);
  14918. }
  14919. if ( Seq ) KeyedSeq.__proto__ = Seq;
  14920. KeyedSeq.prototype = Object.create( Seq && Seq.prototype );
  14921. KeyedSeq.prototype.constructor = KeyedSeq;
  14922. KeyedSeq.prototype.toKeyedSeq = function toKeyedSeq () {
  14923. return this;
  14924. };
  14925. return KeyedSeq;
  14926. }(Seq));
  14927. var IndexedSeq = /*@__PURE__*/(function (Seq) {
  14928. function IndexedSeq(value) {
  14929. return value === null || value === undefined
  14930. ? emptySequence()
  14931. : isCollection(value)
  14932. ? isKeyed(value)
  14933. ? value.entrySeq()
  14934. : value.toIndexedSeq()
  14935. : isRecord(value)
  14936. ? value.toSeq().entrySeq()
  14937. : indexedSeqFromValue(value);
  14938. }
  14939. if ( Seq ) IndexedSeq.__proto__ = Seq;
  14940. IndexedSeq.prototype = Object.create( Seq && Seq.prototype );
  14941. IndexedSeq.prototype.constructor = IndexedSeq;
  14942. IndexedSeq.of = function of (/*...values*/) {
  14943. return IndexedSeq(arguments);
  14944. };
  14945. IndexedSeq.prototype.toIndexedSeq = function toIndexedSeq () {
  14946. return this;
  14947. };
  14948. IndexedSeq.prototype.toString = function toString () {
  14949. return this.__toString('Seq [', ']');
  14950. };
  14951. return IndexedSeq;
  14952. }(Seq));
  14953. var SetSeq = /*@__PURE__*/(function (Seq) {
  14954. function SetSeq(value) {
  14955. return (isCollection(value) && !isAssociative(value)
  14956. ? value
  14957. : IndexedSeq(value)
  14958. ).toSetSeq();
  14959. }
  14960. if ( Seq ) SetSeq.__proto__ = Seq;
  14961. SetSeq.prototype = Object.create( Seq && Seq.prototype );
  14962. SetSeq.prototype.constructor = SetSeq;
  14963. SetSeq.of = function of (/*...values*/) {
  14964. return SetSeq(arguments);
  14965. };
  14966. SetSeq.prototype.toSetSeq = function toSetSeq () {
  14967. return this;
  14968. };
  14969. return SetSeq;
  14970. }(Seq));
  14971. Seq.isSeq = isSeq;
  14972. Seq.Keyed = KeyedSeq;
  14973. Seq.Set = SetSeq;
  14974. Seq.Indexed = IndexedSeq;
  14975. Seq.prototype[IS_SEQ_SYMBOL] = true;
  14976. // #pragma Root Sequences
  14977. var ArraySeq = /*@__PURE__*/(function (IndexedSeq) {
  14978. function ArraySeq(array) {
  14979. this._array = array;
  14980. this.size = array.length;
  14981. }
  14982. if ( IndexedSeq ) ArraySeq.__proto__ = IndexedSeq;
  14983. ArraySeq.prototype = Object.create( IndexedSeq && IndexedSeq.prototype );
  14984. ArraySeq.prototype.constructor = ArraySeq;
  14985. ArraySeq.prototype.get = function get (index, notSetValue) {
  14986. return this.has(index) ? this._array[wrapIndex(this, index)] : notSetValue;
  14987. };
  14988. ArraySeq.prototype.__iterate = function __iterate (fn, reverse) {
  14989. var array = this._array;
  14990. var size = array.length;
  14991. var i = 0;
  14992. while (i !== size) {
  14993. var ii = reverse ? size - ++i : i++;
  14994. if (fn(array[ii], ii, this) === false) {
  14995. break;
  14996. }
  14997. }
  14998. return i;
  14999. };
  15000. ArraySeq.prototype.__iterator = function __iterator (type, reverse) {
  15001. var array = this._array;
  15002. var size = array.length;
  15003. var i = 0;
  15004. return new Iterator(function () {
  15005. if (i === size) {
  15006. return iteratorDone();
  15007. }
  15008. var ii = reverse ? size - ++i : i++;
  15009. return iteratorValue(type, ii, array[ii]);
  15010. });
  15011. };
  15012. return ArraySeq;
  15013. }(IndexedSeq));
  15014. var ObjectSeq = /*@__PURE__*/(function (KeyedSeq) {
  15015. function ObjectSeq(object) {
  15016. var keys = Object.keys(object);
  15017. this._object = object;
  15018. this._keys = keys;
  15019. this.size = keys.length;
  15020. }
  15021. if ( KeyedSeq ) ObjectSeq.__proto__ = KeyedSeq;
  15022. ObjectSeq.prototype = Object.create( KeyedSeq && KeyedSeq.prototype );
  15023. ObjectSeq.prototype.constructor = ObjectSeq;
  15024. ObjectSeq.prototype.get = function get (key, notSetValue) {
  15025. if (notSetValue !== undefined && !this.has(key)) {
  15026. return notSetValue;
  15027. }
  15028. return this._object[key];
  15029. };
  15030. ObjectSeq.prototype.has = function has (key) {
  15031. return hasOwnProperty.call(this._object, key);
  15032. };
  15033. ObjectSeq.prototype.__iterate = function __iterate (fn, reverse) {
  15034. var object = this._object;
  15035. var keys = this._keys;
  15036. var size = keys.length;
  15037. var i = 0;
  15038. while (i !== size) {
  15039. var key = keys[reverse ? size - ++i : i++];
  15040. if (fn(object[key], key, this) === false) {
  15041. break;
  15042. }
  15043. }
  15044. return i;
  15045. };
  15046. ObjectSeq.prototype.__iterator = function __iterator (type, reverse) {
  15047. var object = this._object;
  15048. var keys = this._keys;
  15049. var size = keys.length;
  15050. var i = 0;
  15051. return new Iterator(function () {
  15052. if (i === size) {
  15053. return iteratorDone();
  15054. }
  15055. var key = keys[reverse ? size - ++i : i++];
  15056. return iteratorValue(type, key, object[key]);
  15057. });
  15058. };
  15059. return ObjectSeq;
  15060. }(KeyedSeq));
  15061. ObjectSeq.prototype[IS_ORDERED_SYMBOL] = true;
  15062. var CollectionSeq = /*@__PURE__*/(function (IndexedSeq) {
  15063. function CollectionSeq(collection) {
  15064. this._collection = collection;
  15065. this.size = collection.length || collection.size;
  15066. }
  15067. if ( IndexedSeq ) CollectionSeq.__proto__ = IndexedSeq;
  15068. CollectionSeq.prototype = Object.create( IndexedSeq && IndexedSeq.prototype );
  15069. CollectionSeq.prototype.constructor = CollectionSeq;
  15070. CollectionSeq.prototype.__iterateUncached = function __iterateUncached (fn, reverse) {
  15071. if (reverse) {
  15072. return this.cacheResult().__iterate(fn, reverse);
  15073. }
  15074. var collection = this._collection;
  15075. var iterator = getIterator(collection);
  15076. var iterations = 0;
  15077. if (isIterator(iterator)) {
  15078. var step;
  15079. while (!(step = iterator.next()).done) {
  15080. if (fn(step.value, iterations++, this) === false) {
  15081. break;
  15082. }
  15083. }
  15084. }
  15085. return iterations;
  15086. };
  15087. CollectionSeq.prototype.__iteratorUncached = function __iteratorUncached (type, reverse) {
  15088. if (reverse) {
  15089. return this.cacheResult().__iterator(type, reverse);
  15090. }
  15091. var collection = this._collection;
  15092. var iterator = getIterator(collection);
  15093. if (!isIterator(iterator)) {
  15094. return new Iterator(iteratorDone);
  15095. }
  15096. var iterations = 0;
  15097. return new Iterator(function () {
  15098. var step = iterator.next();
  15099. return step.done ? step : iteratorValue(type, iterations++, step.value);
  15100. });
  15101. };
  15102. return CollectionSeq;
  15103. }(IndexedSeq));
  15104. // # pragma Helper functions
  15105. var EMPTY_SEQ;
  15106. function emptySequence() {
  15107. return EMPTY_SEQ || (EMPTY_SEQ = new ArraySeq([]));
  15108. }
  15109. function keyedSeqFromValue(value) {
  15110. var seq = Array.isArray(value)
  15111. ? new ArraySeq(value)
  15112. : hasIterator(value)
  15113. ? new CollectionSeq(value)
  15114. : undefined;
  15115. if (seq) {
  15116. return seq.fromEntrySeq();
  15117. }
  15118. if (typeof value === 'object') {
  15119. return new ObjectSeq(value);
  15120. }
  15121. throw new TypeError(
  15122. 'Expected Array or collection object of [k, v] entries, or keyed object: ' +
  15123. value
  15124. );
  15125. }
  15126. function indexedSeqFromValue(value) {
  15127. var seq = maybeIndexedSeqFromValue(value);
  15128. if (seq) {
  15129. return seq;
  15130. }
  15131. throw new TypeError(
  15132. 'Expected Array or collection object of values: ' + value
  15133. );
  15134. }
  15135. function seqFromValue(value) {
  15136. var seq = maybeIndexedSeqFromValue(value);
  15137. if (seq) {
  15138. return seq;
  15139. }
  15140. if (typeof value === 'object') {
  15141. return new ObjectSeq(value);
  15142. }
  15143. throw new TypeError(
  15144. 'Expected Array or collection object of values, or keyed object: ' + value
  15145. );
  15146. }
  15147. function maybeIndexedSeqFromValue(value) {
  15148. return isArrayLike(value)
  15149. ? new ArraySeq(value)
  15150. : hasIterator(value)
  15151. ? new CollectionSeq(value)
  15152. : undefined;
  15153. }
  15154. var IS_MAP_SYMBOL = '@@__IMMUTABLE_MAP__@@';
  15155. function isMap(maybeMap) {
  15156. return Boolean(maybeMap && maybeMap[IS_MAP_SYMBOL]);
  15157. }
  15158. function isOrderedMap(maybeOrderedMap) {
  15159. return isMap(maybeOrderedMap) && isOrdered(maybeOrderedMap);
  15160. }
  15161. function isValueObject(maybeValue) {
  15162. return Boolean(
  15163. maybeValue &&
  15164. typeof maybeValue.equals === 'function' &&
  15165. typeof maybeValue.hashCode === 'function'
  15166. );
  15167. }
  15168. /**
  15169. * An extension of the "same-value" algorithm as [described for use by ES6 Map
  15170. * and Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map#Key_equality)
  15171. *
  15172. * NaN is considered the same as NaN, however -0 and 0 are considered the same
  15173. * value, which is different from the algorithm described by
  15174. * [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is).
  15175. *
  15176. * This is extended further to allow Objects to describe the values they
  15177. * represent, by way of `valueOf` or `equals` (and `hashCode`).
  15178. *
  15179. * Note: because of this extension, the key equality of Immutable.Map and the
  15180. * value equality of Immutable.Set will differ from ES6 Map and Set.
  15181. *
  15182. * ### Defining custom values
  15183. *
  15184. * The easiest way to describe the value an object represents is by implementing
  15185. * `valueOf`. For example, `Date` represents a value by returning a unix
  15186. * timestamp for `valueOf`:
  15187. *
  15188. * var date1 = new Date(1234567890000); // Fri Feb 13 2009 ...
  15189. * var date2 = new Date(1234567890000);
  15190. * date1.valueOf(); // 1234567890000
  15191. * assert( date1 !== date2 );
  15192. * assert( Immutable.is( date1, date2 ) );
  15193. *
  15194. * Note: overriding `valueOf` may have other implications if you use this object
  15195. * where JavaScript expects a primitive, such as implicit string coercion.
  15196. *
  15197. * For more complex types, especially collections, implementing `valueOf` may
  15198. * not be performant. An alternative is to implement `equals` and `hashCode`.
  15199. *
  15200. * `equals` takes another object, presumably of similar type, and returns true
  15201. * if it is equal. Equality is symmetrical, so the same result should be
  15202. * returned if this and the argument are flipped.
  15203. *
  15204. * assert( a.equals(b) === b.equals(a) );
  15205. *
  15206. * `hashCode` returns a 32bit integer number representing the object which will
  15207. * be used to determine how to store the value object in a Map or Set. You must
  15208. * provide both or neither methods, one must not exist without the other.
  15209. *
  15210. * Also, an important relationship between these methods must be upheld: if two
  15211. * values are equal, they *must* return the same hashCode. If the values are not
  15212. * equal, they might have the same hashCode; this is called a hash collision,
  15213. * and while undesirable for performance reasons, it is acceptable.
  15214. *
  15215. * if (a.equals(b)) {
  15216. * assert( a.hashCode() === b.hashCode() );
  15217. * }
  15218. *
  15219. * All Immutable collections are Value Objects: they implement `equals()`
  15220. * and `hashCode()`.
  15221. */
  15222. function is(valueA, valueB) {
  15223. if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
  15224. return true;
  15225. }
  15226. if (!valueA || !valueB) {
  15227. return false;
  15228. }
  15229. if (
  15230. typeof valueA.valueOf === 'function' &&
  15231. typeof valueB.valueOf === 'function'
  15232. ) {
  15233. valueA = valueA.valueOf();
  15234. valueB = valueB.valueOf();
  15235. if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
  15236. return true;
  15237. }
  15238. if (!valueA || !valueB) {
  15239. return false;
  15240. }
  15241. }
  15242. return !!(
  15243. isValueObject(valueA) &&
  15244. isValueObject(valueB) &&
  15245. valueA.equals(valueB)
  15246. );
  15247. }
  15248. var imul =
  15249. typeof Math.imul === 'function' && Math.imul(0xffffffff, 2) === -2
  15250. ? Math.imul
  15251. : function imul(a, b) {
  15252. a |= 0; // int
  15253. b |= 0; // int
  15254. var c = a & 0xffff;
  15255. var d = b & 0xffff;
  15256. // Shift by 0 fixes the sign on the high part.
  15257. return (c * d + ((((a >>> 16) * d + c * (b >>> 16)) << 16) >>> 0)) | 0; // int
  15258. };
  15259. // v8 has an optimization for storing 31-bit signed numbers.
  15260. // Values which have either 00 or 11 as the high order bits qualify.
  15261. // This function drops the highest order bit in a signed number, maintaining
  15262. // the sign bit.
  15263. function smi(i32) {
  15264. return ((i32 >>> 1) & 0x40000000) | (i32 & 0xbfffffff);
  15265. }
  15266. var defaultValueOf = Object.prototype.valueOf;
  15267. function hash(o) {
  15268. switch (typeof o) {
  15269. case 'boolean':
  15270. // The hash values for built-in constants are a 1 value for each 5-byte
  15271. // shift region expect for the first, which encodes the value. This
  15272. // reduces the odds of a hash collision for these common values.
  15273. return o ? 0x42108421 : 0x42108420;
  15274. case 'number':
  15275. return hashNumber(o);
  15276. case 'string':
  15277. return o.length > STRING_HASH_CACHE_MIN_STRLEN
  15278. ? cachedHashString(o)
  15279. : hashString(o);
  15280. case 'object':
  15281. case 'function':
  15282. if (o === null) {
  15283. return 0x42108422;
  15284. }
  15285. if (typeof o.hashCode === 'function') {
  15286. // Drop any high bits from accidentally long hash codes.
  15287. return smi(o.hashCode(o));
  15288. }
  15289. if (o.valueOf !== defaultValueOf && typeof o.valueOf === 'function') {
  15290. o = o.valueOf(o);
  15291. }
  15292. return hashJSObj(o);
  15293. case 'undefined':
  15294. return 0x42108423;
  15295. default:
  15296. if (typeof o.toString === 'function') {
  15297. return hashString(o.toString());
  15298. }
  15299. throw new Error('Value type ' + typeof o + ' cannot be hashed.');
  15300. }
  15301. }
  15302. // Compress arbitrarily large numbers into smi hashes.
  15303. function hashNumber(n) {
  15304. if (n !== n || n === Infinity) {
  15305. return 0;
  15306. }
  15307. var hash = n | 0;
  15308. if (hash !== n) {
  15309. hash ^= n * 0xffffffff;
  15310. }
  15311. while (n > 0xffffffff) {
  15312. n /= 0xffffffff;
  15313. hash ^= n;
  15314. }
  15315. return smi(hash);
  15316. }
  15317. function cachedHashString(string) {
  15318. var hashed = stringHashCache[string];
  15319. if (hashed === undefined) {
  15320. hashed = hashString(string);
  15321. if (STRING_HASH_CACHE_SIZE === STRING_HASH_CACHE_MAX_SIZE) {
  15322. STRING_HASH_CACHE_SIZE = 0;
  15323. stringHashCache = {};
  15324. }
  15325. STRING_HASH_CACHE_SIZE++;
  15326. stringHashCache[string] = hashed;
  15327. }
  15328. return hashed;
  15329. }
  15330. // http://jsperf.com/hashing-strings
  15331. function hashString(string) {
  15332. // This is the hash from JVM
  15333. // The hash code for a string is computed as
  15334. // s[0] * 31 ^ (n - 1) + s[1] * 31 ^ (n - 2) + ... + s[n - 1],
  15335. // where s[i] is the ith character of the string and n is the length of
  15336. // the string. We "mod" the result to make it between 0 (inclusive) and 2^31
  15337. // (exclusive) by dropping high bits.
  15338. var hashed = 0;
  15339. for (var ii = 0; ii < string.length; ii++) {
  15340. hashed = (31 * hashed + string.charCodeAt(ii)) | 0;
  15341. }
  15342. return smi(hashed);
  15343. }
  15344. function hashJSObj(obj) {
  15345. var hashed;
  15346. if (usingWeakMap) {
  15347. hashed = weakMap.get(obj);
  15348. if (hashed !== undefined) {
  15349. return hashed;
  15350. }
  15351. }
  15352. hashed = obj[UID_HASH_KEY];
  15353. if (hashed !== undefined) {
  15354. return hashed;
  15355. }
  15356. if (!canDefineProperty) {
  15357. hashed = obj.propertyIsEnumerable && obj.propertyIsEnumerable[UID_HASH_KEY];
  15358. if (hashed !== undefined) {
  15359. return hashed;
  15360. }
  15361. hashed = getIENodeHash(obj);
  15362. if (hashed !== undefined) {
  15363. return hashed;
  15364. }
  15365. }
  15366. hashed = ++objHashUID;
  15367. if (objHashUID & 0x40000000) {
  15368. objHashUID = 0;
  15369. }
  15370. if (usingWeakMap) {
  15371. weakMap.set(obj, hashed);
  15372. } else if (isExtensible !== undefined && isExtensible(obj) === false) {
  15373. throw new Error('Non-extensible objects are not allowed as keys.');
  15374. } else if (canDefineProperty) {
  15375. Object.defineProperty(obj, UID_HASH_KEY, {
  15376. enumerable: false,
  15377. configurable: false,
  15378. writable: false,
  15379. value: hashed,
  15380. });
  15381. } else if (
  15382. obj.propertyIsEnumerable !== undefined &&
  15383. obj.propertyIsEnumerable === obj.constructor.prototype.propertyIsEnumerable
  15384. ) {
  15385. // Since we can't define a non-enumerable property on the object
  15386. // we'll hijack one of the less-used non-enumerable properties to
  15387. // save our hash on it. Since this is a function it will not show up in
  15388. // `JSON.stringify` which is what we want.
  15389. obj.propertyIsEnumerable = function() {
  15390. return this.constructor.prototype.propertyIsEnumerable.apply(
  15391. this,
  15392. arguments
  15393. );
  15394. };
  15395. obj.propertyIsEnumerable[UID_HASH_KEY] = hashed;
  15396. } else if (obj.nodeType !== undefined) {
  15397. // At this point we couldn't get the IE `uniqueID` to use as a hash
  15398. // and we couldn't use a non-enumerable property to exploit the
  15399. // dontEnum bug so we simply add the `UID_HASH_KEY` on the node
  15400. // itself.
  15401. obj[UID_HASH_KEY] = hashed;
  15402. } else {
  15403. throw new Error('Unable to set a non-enumerable property on object.');
  15404. }
  15405. return hashed;
  15406. }
  15407. // Get references to ES5 object methods.
  15408. var isExtensible = Object.isExtensible;
  15409. // True if Object.defineProperty works as expected. IE8 fails this test.
  15410. var canDefineProperty = (function() {
  15411. try {
  15412. Object.defineProperty({}, '@', {});
  15413. return true;
  15414. } catch (e) {
  15415. return false;
  15416. }
  15417. })();
  15418. // IE has a `uniqueID` property on DOM nodes. We can construct the hash from it
  15419. // and avoid memory leaks from the IE cloneNode bug.
  15420. function getIENodeHash(node) {
  15421. if (node && node.nodeType > 0) {
  15422. switch (node.nodeType) {
  15423. case 1: // Element
  15424. return node.uniqueID;
  15425. case 9: // Document
  15426. return node.documentElement && node.documentElement.uniqueID;
  15427. }
  15428. }
  15429. }
  15430. // If possible, use a WeakMap.
  15431. var usingWeakMap = typeof WeakMap === 'function';
  15432. var weakMap;
  15433. if (usingWeakMap) {
  15434. weakMap = new WeakMap();
  15435. }
  15436. var objHashUID = 0;
  15437. var UID_HASH_KEY = '__immutablehash__';
  15438. if (typeof Symbol === 'function') {
  15439. UID_HASH_KEY = Symbol(UID_HASH_KEY);
  15440. }
  15441. var STRING_HASH_CACHE_MIN_STRLEN = 16;
  15442. var STRING_HASH_CACHE_MAX_SIZE = 255;
  15443. var STRING_HASH_CACHE_SIZE = 0;
  15444. var stringHashCache = {};
  15445. var ToKeyedSequence = /*@__PURE__*/(function (KeyedSeq$$1) {
  15446. function ToKeyedSequence(indexed, useKeys) {
  15447. this._iter = indexed;
  15448. this._useKeys = useKeys;
  15449. this.size = indexed.size;
  15450. }
  15451. if ( KeyedSeq$$1 ) ToKeyedSequence.__proto__ = KeyedSeq$$1;
  15452. ToKeyedSequence.prototype = Object.create( KeyedSeq$$1 && KeyedSeq$$1.prototype );
  15453. ToKeyedSequence.prototype.constructor = ToKeyedSequence;
  15454. ToKeyedSequence.prototype.get = function get (key, notSetValue) {
  15455. return this._iter.get(key, notSetValue);
  15456. };
  15457. ToKeyedSequence.prototype.has = function has (key) {
  15458. return this._iter.has(key);
  15459. };
  15460. ToKeyedSequence.prototype.valueSeq = function valueSeq () {
  15461. return this._iter.valueSeq();
  15462. };
  15463. ToKeyedSequence.prototype.reverse = function reverse () {
  15464. var this$1 = this;
  15465. var reversedSequence = reverseFactory(this, true);
  15466. if (!this._useKeys) {
  15467. reversedSequence.valueSeq = function () { return this$1._iter.toSeq().reverse(); };
  15468. }
  15469. return reversedSequence;
  15470. };
  15471. ToKeyedSequence.prototype.map = function map (mapper, context) {
  15472. var this$1 = this;
  15473. var mappedSequence = mapFactory(this, mapper, context);
  15474. if (!this._useKeys) {
  15475. mappedSequence.valueSeq = function () { return this$1._iter.toSeq().map(mapper, context); };
  15476. }
  15477. return mappedSequence;
  15478. };
  15479. ToKeyedSequence.prototype.__iterate = function __iterate (fn, reverse) {
  15480. var this$1 = this;
  15481. return this._iter.__iterate(function (v, k) { return fn(v, k, this$1); }, reverse);
  15482. };
  15483. ToKeyedSequence.prototype.__iterator = function __iterator (type, reverse) {
  15484. return this._iter.__iterator(type, reverse);
  15485. };
  15486. return ToKeyedSequence;
  15487. }(KeyedSeq));
  15488. ToKeyedSequence.prototype[IS_ORDERED_SYMBOL] = true;
  15489. var ToIndexedSequence = /*@__PURE__*/(function (IndexedSeq$$1) {
  15490. function ToIndexedSequence(iter) {
  15491. this._iter = iter;
  15492. this.size = iter.size;
  15493. }
  15494. if ( IndexedSeq$$1 ) ToIndexedSequence.__proto__ = IndexedSeq$$1;
  15495. ToIndexedSequence.prototype = Object.create( IndexedSeq$$1 && IndexedSeq$$1.prototype );
  15496. ToIndexedSequence.prototype.constructor = ToIndexedSequence;
  15497. ToIndexedSequence.prototype.includes = function includes (value) {
  15498. return this._iter.includes(value);
  15499. };
  15500. ToIndexedSequence.prototype.__iterate = function __iterate (fn, reverse) {
  15501. var this$1 = this;
  15502. var i = 0;
  15503. reverse && ensureSize(this);
  15504. return this._iter.__iterate(
  15505. function (v) { return fn(v, reverse ? this$1.size - ++i : i++, this$1); },
  15506. reverse
  15507. );
  15508. };
  15509. ToIndexedSequence.prototype.__iterator = function __iterator (type, reverse) {
  15510. var this$1 = this;
  15511. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  15512. var i = 0;
  15513. reverse && ensureSize(this);
  15514. return new Iterator(function () {
  15515. var step = iterator.next();
  15516. return step.done
  15517. ? step
  15518. : iteratorValue(
  15519. type,
  15520. reverse ? this$1.size - ++i : i++,
  15521. step.value,
  15522. step
  15523. );
  15524. });
  15525. };
  15526. return ToIndexedSequence;
  15527. }(IndexedSeq));
  15528. var ToSetSequence = /*@__PURE__*/(function (SetSeq$$1) {
  15529. function ToSetSequence(iter) {
  15530. this._iter = iter;
  15531. this.size = iter.size;
  15532. }
  15533. if ( SetSeq$$1 ) ToSetSequence.__proto__ = SetSeq$$1;
  15534. ToSetSequence.prototype = Object.create( SetSeq$$1 && SetSeq$$1.prototype );
  15535. ToSetSequence.prototype.constructor = ToSetSequence;
  15536. ToSetSequence.prototype.has = function has (key) {
  15537. return this._iter.includes(key);
  15538. };
  15539. ToSetSequence.prototype.__iterate = function __iterate (fn, reverse) {
  15540. var this$1 = this;
  15541. return this._iter.__iterate(function (v) { return fn(v, v, this$1); }, reverse);
  15542. };
  15543. ToSetSequence.prototype.__iterator = function __iterator (type, reverse) {
  15544. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  15545. return new Iterator(function () {
  15546. var step = iterator.next();
  15547. return step.done
  15548. ? step
  15549. : iteratorValue(type, step.value, step.value, step);
  15550. });
  15551. };
  15552. return ToSetSequence;
  15553. }(SetSeq));
  15554. var FromEntriesSequence = /*@__PURE__*/(function (KeyedSeq$$1) {
  15555. function FromEntriesSequence(entries) {
  15556. this._iter = entries;
  15557. this.size = entries.size;
  15558. }
  15559. if ( KeyedSeq$$1 ) FromEntriesSequence.__proto__ = KeyedSeq$$1;
  15560. FromEntriesSequence.prototype = Object.create( KeyedSeq$$1 && KeyedSeq$$1.prototype );
  15561. FromEntriesSequence.prototype.constructor = FromEntriesSequence;
  15562. FromEntriesSequence.prototype.entrySeq = function entrySeq () {
  15563. return this._iter.toSeq();
  15564. };
  15565. FromEntriesSequence.prototype.__iterate = function __iterate (fn, reverse) {
  15566. var this$1 = this;
  15567. return this._iter.__iterate(function (entry) {
  15568. // Check if entry exists first so array access doesn't throw for holes
  15569. // in the parent iteration.
  15570. if (entry) {
  15571. validateEntry(entry);
  15572. var indexedCollection = isCollection(entry);
  15573. return fn(
  15574. indexedCollection ? entry.get(1) : entry[1],
  15575. indexedCollection ? entry.get(0) : entry[0],
  15576. this$1
  15577. );
  15578. }
  15579. }, reverse);
  15580. };
  15581. FromEntriesSequence.prototype.__iterator = function __iterator (type, reverse) {
  15582. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  15583. return new Iterator(function () {
  15584. while (true) {
  15585. var step = iterator.next();
  15586. if (step.done) {
  15587. return step;
  15588. }
  15589. var entry = step.value;
  15590. // Check if entry exists first so array access doesn't throw for holes
  15591. // in the parent iteration.
  15592. if (entry) {
  15593. validateEntry(entry);
  15594. var indexedCollection = isCollection(entry);
  15595. return iteratorValue(
  15596. type,
  15597. indexedCollection ? entry.get(0) : entry[0],
  15598. indexedCollection ? entry.get(1) : entry[1],
  15599. step
  15600. );
  15601. }
  15602. }
  15603. });
  15604. };
  15605. return FromEntriesSequence;
  15606. }(KeyedSeq));
  15607. ToIndexedSequence.prototype.cacheResult = ToKeyedSequence.prototype.cacheResult = ToSetSequence.prototype.cacheResult = FromEntriesSequence.prototype.cacheResult = cacheResultThrough;
  15608. function flipFactory(collection) {
  15609. var flipSequence = makeSequence(collection);
  15610. flipSequence._iter = collection;
  15611. flipSequence.size = collection.size;
  15612. flipSequence.flip = function () { return collection; };
  15613. flipSequence.reverse = function() {
  15614. var reversedSequence = collection.reverse.apply(this); // super.reverse()
  15615. reversedSequence.flip = function () { return collection.reverse(); };
  15616. return reversedSequence;
  15617. };
  15618. flipSequence.has = function (key) { return collection.includes(key); };
  15619. flipSequence.includes = function (key) { return collection.has(key); };
  15620. flipSequence.cacheResult = cacheResultThrough;
  15621. flipSequence.__iterateUncached = function(fn, reverse) {
  15622. var this$1 = this;
  15623. return collection.__iterate(function (v, k) { return fn(k, v, this$1) !== false; }, reverse);
  15624. };
  15625. flipSequence.__iteratorUncached = function(type, reverse) {
  15626. if (type === ITERATE_ENTRIES) {
  15627. var iterator = collection.__iterator(type, reverse);
  15628. return new Iterator(function () {
  15629. var step = iterator.next();
  15630. if (!step.done) {
  15631. var k = step.value[0];
  15632. step.value[0] = step.value[1];
  15633. step.value[1] = k;
  15634. }
  15635. return step;
  15636. });
  15637. }
  15638. return collection.__iterator(
  15639. type === ITERATE_VALUES ? ITERATE_KEYS : ITERATE_VALUES,
  15640. reverse
  15641. );
  15642. };
  15643. return flipSequence;
  15644. }
  15645. function mapFactory(collection, mapper, context) {
  15646. var mappedSequence = makeSequence(collection);
  15647. mappedSequence.size = collection.size;
  15648. mappedSequence.has = function (key) { return collection.has(key); };
  15649. mappedSequence.get = function (key, notSetValue) {
  15650. var v = collection.get(key, NOT_SET);
  15651. return v === NOT_SET
  15652. ? notSetValue
  15653. : mapper.call(context, v, key, collection);
  15654. };
  15655. mappedSequence.__iterateUncached = function(fn, reverse) {
  15656. var this$1 = this;
  15657. return collection.__iterate(
  15658. function (v, k, c) { return fn(mapper.call(context, v, k, c), k, this$1) !== false; },
  15659. reverse
  15660. );
  15661. };
  15662. mappedSequence.__iteratorUncached = function(type, reverse) {
  15663. var iterator = collection.__iterator(ITERATE_ENTRIES, reverse);
  15664. return new Iterator(function () {
  15665. var step = iterator.next();
  15666. if (step.done) {
  15667. return step;
  15668. }
  15669. var entry = step.value;
  15670. var key = entry[0];
  15671. return iteratorValue(
  15672. type,
  15673. key,
  15674. mapper.call(context, entry[1], key, collection),
  15675. step
  15676. );
  15677. });
  15678. };
  15679. return mappedSequence;
  15680. }
  15681. function reverseFactory(collection, useKeys) {
  15682. var this$1 = this;
  15683. var reversedSequence = makeSequence(collection);
  15684. reversedSequence._iter = collection;
  15685. reversedSequence.size = collection.size;
  15686. reversedSequence.reverse = function () { return collection; };
  15687. if (collection.flip) {
  15688. reversedSequence.flip = function() {
  15689. var flipSequence = flipFactory(collection);
  15690. flipSequence.reverse = function () { return collection.flip(); };
  15691. return flipSequence;
  15692. };
  15693. }
  15694. reversedSequence.get = function (key, notSetValue) { return collection.get(useKeys ? key : -1 - key, notSetValue); };
  15695. reversedSequence.has = function (key) { return collection.has(useKeys ? key : -1 - key); };
  15696. reversedSequence.includes = function (value) { return collection.includes(value); };
  15697. reversedSequence.cacheResult = cacheResultThrough;
  15698. reversedSequence.__iterate = function(fn, reverse) {
  15699. var this$1 = this;
  15700. var i = 0;
  15701. reverse && ensureSize(collection);
  15702. return collection.__iterate(
  15703. function (v, k) { return fn(v, useKeys ? k : reverse ? this$1.size - ++i : i++, this$1); },
  15704. !reverse
  15705. );
  15706. };
  15707. reversedSequence.__iterator = function (type, reverse) {
  15708. var i = 0;
  15709. reverse && ensureSize(collection);
  15710. var iterator = collection.__iterator(ITERATE_ENTRIES, !reverse);
  15711. return new Iterator(function () {
  15712. var step = iterator.next();
  15713. if (step.done) {
  15714. return step;
  15715. }
  15716. var entry = step.value;
  15717. return iteratorValue(
  15718. type,
  15719. useKeys ? entry[0] : reverse ? this$1.size - ++i : i++,
  15720. entry[1],
  15721. step
  15722. );
  15723. });
  15724. };
  15725. return reversedSequence;
  15726. }
  15727. function filterFactory(collection, predicate, context, useKeys) {
  15728. var filterSequence = makeSequence(collection);
  15729. if (useKeys) {
  15730. filterSequence.has = function (key) {
  15731. var v = collection.get(key, NOT_SET);
  15732. return v !== NOT_SET && !!predicate.call(context, v, key, collection);
  15733. };
  15734. filterSequence.get = function (key, notSetValue) {
  15735. var v = collection.get(key, NOT_SET);
  15736. return v !== NOT_SET && predicate.call(context, v, key, collection)
  15737. ? v
  15738. : notSetValue;
  15739. };
  15740. }
  15741. filterSequence.__iterateUncached = function(fn, reverse) {
  15742. var this$1 = this;
  15743. var iterations = 0;
  15744. collection.__iterate(function (v, k, c) {
  15745. if (predicate.call(context, v, k, c)) {
  15746. iterations++;
  15747. return fn(v, useKeys ? k : iterations - 1, this$1);
  15748. }
  15749. }, reverse);
  15750. return iterations;
  15751. };
  15752. filterSequence.__iteratorUncached = function(type, reverse) {
  15753. var iterator = collection.__iterator(ITERATE_ENTRIES, reverse);
  15754. var iterations = 0;
  15755. return new Iterator(function () {
  15756. while (true) {
  15757. var step = iterator.next();
  15758. if (step.done) {
  15759. return step;
  15760. }
  15761. var entry = step.value;
  15762. var key = entry[0];
  15763. var value = entry[1];
  15764. if (predicate.call(context, value, key, collection)) {
  15765. return iteratorValue(type, useKeys ? key : iterations++, value, step);
  15766. }
  15767. }
  15768. });
  15769. };
  15770. return filterSequence;
  15771. }
  15772. function countByFactory(collection, grouper, context) {
  15773. var groups = Map().asMutable();
  15774. collection.__iterate(function (v, k) {
  15775. groups.update(grouper.call(context, v, k, collection), 0, function (a) { return a + 1; });
  15776. });
  15777. return groups.asImmutable();
  15778. }
  15779. function groupByFactory(collection, grouper, context) {
  15780. var isKeyedIter = isKeyed(collection);
  15781. var groups = (isOrdered(collection) ? OrderedMap() : Map()).asMutable();
  15782. collection.__iterate(function (v, k) {
  15783. groups.update(
  15784. grouper.call(context, v, k, collection),
  15785. function (a) { return ((a = a || []), a.push(isKeyedIter ? [k, v] : v), a); }
  15786. );
  15787. });
  15788. var coerce = collectionClass(collection);
  15789. return groups.map(function (arr) { return reify(collection, coerce(arr)); }).asImmutable();
  15790. }
  15791. function sliceFactory(collection, begin, end, useKeys) {
  15792. var originalSize = collection.size;
  15793. if (wholeSlice(begin, end, originalSize)) {
  15794. return collection;
  15795. }
  15796. var resolvedBegin = resolveBegin(begin, originalSize);
  15797. var resolvedEnd = resolveEnd(end, originalSize);
  15798. // begin or end will be NaN if they were provided as negative numbers and
  15799. // this collection's size is unknown. In that case, cache first so there is
  15800. // a known size and these do not resolve to NaN.
  15801. if (resolvedBegin !== resolvedBegin || resolvedEnd !== resolvedEnd) {
  15802. return sliceFactory(collection.toSeq().cacheResult(), begin, end, useKeys);
  15803. }
  15804. // Note: resolvedEnd is undefined when the original sequence's length is
  15805. // unknown and this slice did not supply an end and should contain all
  15806. // elements after resolvedBegin.
  15807. // In that case, resolvedSize will be NaN and sliceSize will remain undefined.
  15808. var resolvedSize = resolvedEnd - resolvedBegin;
  15809. var sliceSize;
  15810. if (resolvedSize === resolvedSize) {
  15811. sliceSize = resolvedSize < 0 ? 0 : resolvedSize;
  15812. }
  15813. var sliceSeq = makeSequence(collection);
  15814. // If collection.size is undefined, the size of the realized sliceSeq is
  15815. // unknown at this point unless the number of items to slice is 0
  15816. sliceSeq.size =
  15817. sliceSize === 0 ? sliceSize : (collection.size && sliceSize) || undefined;
  15818. if (!useKeys && isSeq(collection) && sliceSize >= 0) {
  15819. sliceSeq.get = function(index, notSetValue) {
  15820. index = wrapIndex(this, index);
  15821. return index >= 0 && index < sliceSize
  15822. ? collection.get(index + resolvedBegin, notSetValue)
  15823. : notSetValue;
  15824. };
  15825. }
  15826. sliceSeq.__iterateUncached = function(fn, reverse) {
  15827. var this$1 = this;
  15828. if (sliceSize === 0) {
  15829. return 0;
  15830. }
  15831. if (reverse) {
  15832. return this.cacheResult().__iterate(fn, reverse);
  15833. }
  15834. var skipped = 0;
  15835. var isSkipping = true;
  15836. var iterations = 0;
  15837. collection.__iterate(function (v, k) {
  15838. if (!(isSkipping && (isSkipping = skipped++ < resolvedBegin))) {
  15839. iterations++;
  15840. return (
  15841. fn(v, useKeys ? k : iterations - 1, this$1) !== false &&
  15842. iterations !== sliceSize
  15843. );
  15844. }
  15845. });
  15846. return iterations;
  15847. };
  15848. sliceSeq.__iteratorUncached = function(type, reverse) {
  15849. if (sliceSize !== 0 && reverse) {
  15850. return this.cacheResult().__iterator(type, reverse);
  15851. }
  15852. // Don't bother instantiating parent iterator if taking 0.
  15853. if (sliceSize === 0) {
  15854. return new Iterator(iteratorDone);
  15855. }
  15856. var iterator = collection.__iterator(type, reverse);
  15857. var skipped = 0;
  15858. var iterations = 0;
  15859. return new Iterator(function () {
  15860. while (skipped++ < resolvedBegin) {
  15861. iterator.next();
  15862. }
  15863. if (++iterations > sliceSize) {
  15864. return iteratorDone();
  15865. }
  15866. var step = iterator.next();
  15867. if (useKeys || type === ITERATE_VALUES || step.done) {
  15868. return step;
  15869. }
  15870. if (type === ITERATE_KEYS) {
  15871. return iteratorValue(type, iterations - 1, undefined, step);
  15872. }
  15873. return iteratorValue(type, iterations - 1, step.value[1], step);
  15874. });
  15875. };
  15876. return sliceSeq;
  15877. }
  15878. function takeWhileFactory(collection, predicate, context) {
  15879. var takeSequence = makeSequence(collection);
  15880. takeSequence.__iterateUncached = function(fn, reverse) {
  15881. var this$1 = this;
  15882. if (reverse) {
  15883. return this.cacheResult().__iterate(fn, reverse);
  15884. }
  15885. var iterations = 0;
  15886. collection.__iterate(
  15887. function (v, k, c) { return predicate.call(context, v, k, c) && ++iterations && fn(v, k, this$1); }
  15888. );
  15889. return iterations;
  15890. };
  15891. takeSequence.__iteratorUncached = function(type, reverse) {
  15892. var this$1 = this;
  15893. if (reverse) {
  15894. return this.cacheResult().__iterator(type, reverse);
  15895. }
  15896. var iterator = collection.__iterator(ITERATE_ENTRIES, reverse);
  15897. var iterating = true;
  15898. return new Iterator(function () {
  15899. if (!iterating) {
  15900. return iteratorDone();
  15901. }
  15902. var step = iterator.next();
  15903. if (step.done) {
  15904. return step;
  15905. }
  15906. var entry = step.value;
  15907. var k = entry[0];
  15908. var v = entry[1];
  15909. if (!predicate.call(context, v, k, this$1)) {
  15910. iterating = false;
  15911. return iteratorDone();
  15912. }
  15913. return type === ITERATE_ENTRIES ? step : iteratorValue(type, k, v, step);
  15914. });
  15915. };
  15916. return takeSequence;
  15917. }
  15918. function skipWhileFactory(collection, predicate, context, useKeys) {
  15919. var skipSequence = makeSequence(collection);
  15920. skipSequence.__iterateUncached = function(fn, reverse) {
  15921. var this$1 = this;
  15922. if (reverse) {
  15923. return this.cacheResult().__iterate(fn, reverse);
  15924. }
  15925. var isSkipping = true;
  15926. var iterations = 0;
  15927. collection.__iterate(function (v, k, c) {
  15928. if (!(isSkipping && (isSkipping = predicate.call(context, v, k, c)))) {
  15929. iterations++;
  15930. return fn(v, useKeys ? k : iterations - 1, this$1);
  15931. }
  15932. });
  15933. return iterations;
  15934. };
  15935. skipSequence.__iteratorUncached = function(type, reverse) {
  15936. var this$1 = this;
  15937. if (reverse) {
  15938. return this.cacheResult().__iterator(type, reverse);
  15939. }
  15940. var iterator = collection.__iterator(ITERATE_ENTRIES, reverse);
  15941. var skipping = true;
  15942. var iterations = 0;
  15943. return new Iterator(function () {
  15944. var step;
  15945. var k;
  15946. var v;
  15947. do {
  15948. step = iterator.next();
  15949. if (step.done) {
  15950. if (useKeys || type === ITERATE_VALUES) {
  15951. return step;
  15952. }
  15953. if (type === ITERATE_KEYS) {
  15954. return iteratorValue(type, iterations++, undefined, step);
  15955. }
  15956. return iteratorValue(type, iterations++, step.value[1], step);
  15957. }
  15958. var entry = step.value;
  15959. k = entry[0];
  15960. v = entry[1];
  15961. skipping && (skipping = predicate.call(context, v, k, this$1));
  15962. } while (skipping);
  15963. return type === ITERATE_ENTRIES ? step : iteratorValue(type, k, v, step);
  15964. });
  15965. };
  15966. return skipSequence;
  15967. }
  15968. function concatFactory(collection, values) {
  15969. var isKeyedCollection = isKeyed(collection);
  15970. var iters = [collection]
  15971. .concat(values)
  15972. .map(function (v) {
  15973. if (!isCollection(v)) {
  15974. v = isKeyedCollection
  15975. ? keyedSeqFromValue(v)
  15976. : indexedSeqFromValue(Array.isArray(v) ? v : [v]);
  15977. } else if (isKeyedCollection) {
  15978. v = KeyedCollection(v);
  15979. }
  15980. return v;
  15981. })
  15982. .filter(function (v) { return v.size !== 0; });
  15983. if (iters.length === 0) {
  15984. return collection;
  15985. }
  15986. if (iters.length === 1) {
  15987. var singleton = iters[0];
  15988. if (
  15989. singleton === collection ||
  15990. (isKeyedCollection && isKeyed(singleton)) ||
  15991. (isIndexed(collection) && isIndexed(singleton))
  15992. ) {
  15993. return singleton;
  15994. }
  15995. }
  15996. var concatSeq = new ArraySeq(iters);
  15997. if (isKeyedCollection) {
  15998. concatSeq = concatSeq.toKeyedSeq();
  15999. } else if (!isIndexed(collection)) {
  16000. concatSeq = concatSeq.toSetSeq();
  16001. }
  16002. concatSeq = concatSeq.flatten(true);
  16003. concatSeq.size = iters.reduce(function (sum, seq) {
  16004. if (sum !== undefined) {
  16005. var size = seq.size;
  16006. if (size !== undefined) {
  16007. return sum + size;
  16008. }
  16009. }
  16010. }, 0);
  16011. return concatSeq;
  16012. }
  16013. function flattenFactory(collection, depth, useKeys) {
  16014. var flatSequence = makeSequence(collection);
  16015. flatSequence.__iterateUncached = function(fn, reverse) {
  16016. if (reverse) {
  16017. return this.cacheResult().__iterate(fn, reverse);
  16018. }
  16019. var iterations = 0;
  16020. var stopped = false;
  16021. function flatDeep(iter, currentDepth) {
  16022. iter.__iterate(function (v, k) {
  16023. if ((!depth || currentDepth < depth) && isCollection(v)) {
  16024. flatDeep(v, currentDepth + 1);
  16025. } else {
  16026. iterations++;
  16027. if (fn(v, useKeys ? k : iterations - 1, flatSequence) === false) {
  16028. stopped = true;
  16029. }
  16030. }
  16031. return !stopped;
  16032. }, reverse);
  16033. }
  16034. flatDeep(collection, 0);
  16035. return iterations;
  16036. };
  16037. flatSequence.__iteratorUncached = function(type, reverse) {
  16038. if (reverse) {
  16039. return this.cacheResult().__iterator(type, reverse);
  16040. }
  16041. var iterator = collection.__iterator(type, reverse);
  16042. var stack = [];
  16043. var iterations = 0;
  16044. return new Iterator(function () {
  16045. while (iterator) {
  16046. var step = iterator.next();
  16047. if (step.done !== false) {
  16048. iterator = stack.pop();
  16049. continue;
  16050. }
  16051. var v = step.value;
  16052. if (type === ITERATE_ENTRIES) {
  16053. v = v[1];
  16054. }
  16055. if ((!depth || stack.length < depth) && isCollection(v)) {
  16056. stack.push(iterator);
  16057. iterator = v.__iterator(type, reverse);
  16058. } else {
  16059. return useKeys ? step : iteratorValue(type, iterations++, v, step);
  16060. }
  16061. }
  16062. return iteratorDone();
  16063. });
  16064. };
  16065. return flatSequence;
  16066. }
  16067. function flatMapFactory(collection, mapper, context) {
  16068. var coerce = collectionClass(collection);
  16069. return collection
  16070. .toSeq()
  16071. .map(function (v, k) { return coerce(mapper.call(context, v, k, collection)); })
  16072. .flatten(true);
  16073. }
  16074. function interposeFactory(collection, separator) {
  16075. var interposedSequence = makeSequence(collection);
  16076. interposedSequence.size = collection.size && collection.size * 2 - 1;
  16077. interposedSequence.__iterateUncached = function(fn, reverse) {
  16078. var this$1 = this;
  16079. var iterations = 0;
  16080. collection.__iterate(
  16081. function (v) { return (!iterations || fn(separator, iterations++, this$1) !== false) &&
  16082. fn(v, iterations++, this$1) !== false; },
  16083. reverse
  16084. );
  16085. return iterations;
  16086. };
  16087. interposedSequence.__iteratorUncached = function(type, reverse) {
  16088. var iterator = collection.__iterator(ITERATE_VALUES, reverse);
  16089. var iterations = 0;
  16090. var step;
  16091. return new Iterator(function () {
  16092. if (!step || iterations % 2) {
  16093. step = iterator.next();
  16094. if (step.done) {
  16095. return step;
  16096. }
  16097. }
  16098. return iterations % 2
  16099. ? iteratorValue(type, iterations++, separator)
  16100. : iteratorValue(type, iterations++, step.value, step);
  16101. });
  16102. };
  16103. return interposedSequence;
  16104. }
  16105. function sortFactory(collection, comparator, mapper) {
  16106. if (!comparator) {
  16107. comparator = defaultComparator;
  16108. }
  16109. var isKeyedCollection = isKeyed(collection);
  16110. var index = 0;
  16111. var entries = collection
  16112. .toSeq()
  16113. .map(function (v, k) { return [k, v, index++, mapper ? mapper(v, k, collection) : v]; })
  16114. .valueSeq()
  16115. .toArray();
  16116. entries.sort(function (a, b) { return comparator(a[3], b[3]) || a[2] - b[2]; }).forEach(
  16117. isKeyedCollection
  16118. ? function (v, i) {
  16119. entries[i].length = 2;
  16120. }
  16121. : function (v, i) {
  16122. entries[i] = v[1];
  16123. }
  16124. );
  16125. return isKeyedCollection
  16126. ? KeyedSeq(entries)
  16127. : isIndexed(collection)
  16128. ? IndexedSeq(entries)
  16129. : SetSeq(entries);
  16130. }
  16131. function maxFactory(collection, comparator, mapper) {
  16132. if (!comparator) {
  16133. comparator = defaultComparator;
  16134. }
  16135. if (mapper) {
  16136. var entry = collection
  16137. .toSeq()
  16138. .map(function (v, k) { return [v, mapper(v, k, collection)]; })
  16139. .reduce(function (a, b) { return (maxCompare(comparator, a[1], b[1]) ? b : a); });
  16140. return entry && entry[0];
  16141. }
  16142. return collection.reduce(function (a, b) { return (maxCompare(comparator, a, b) ? b : a); });
  16143. }
  16144. function maxCompare(comparator, a, b) {
  16145. var comp = comparator(b, a);
  16146. // b is considered the new max if the comparator declares them equal, but
  16147. // they are not equal and b is in fact a nullish value.
  16148. return (
  16149. (comp === 0 && b !== a && (b === undefined || b === null || b !== b)) ||
  16150. comp > 0
  16151. );
  16152. }
  16153. function zipWithFactory(keyIter, zipper, iters, zipAll) {
  16154. var zipSequence = makeSequence(keyIter);
  16155. var sizes = new ArraySeq(iters).map(function (i) { return i.size; });
  16156. zipSequence.size = zipAll ? sizes.max() : sizes.min();
  16157. // Note: this a generic base implementation of __iterate in terms of
  16158. // __iterator which may be more generically useful in the future.
  16159. zipSequence.__iterate = function(fn, reverse) {
  16160. /* generic:
  16161. var iterator = this.__iterator(ITERATE_ENTRIES, reverse);
  16162. var step;
  16163. var iterations = 0;
  16164. while (!(step = iterator.next()).done) {
  16165. iterations++;
  16166. if (fn(step.value[1], step.value[0], this) === false) {
  16167. break;
  16168. }
  16169. }
  16170. return iterations;
  16171. */
  16172. // indexed:
  16173. var iterator = this.__iterator(ITERATE_VALUES, reverse);
  16174. var step;
  16175. var iterations = 0;
  16176. while (!(step = iterator.next()).done) {
  16177. if (fn(step.value, iterations++, this) === false) {
  16178. break;
  16179. }
  16180. }
  16181. return iterations;
  16182. };
  16183. zipSequence.__iteratorUncached = function(type, reverse) {
  16184. var iterators = iters.map(
  16185. function (i) { return ((i = Collection(i)), getIterator(reverse ? i.reverse() : i)); }
  16186. );
  16187. var iterations = 0;
  16188. var isDone = false;
  16189. return new Iterator(function () {
  16190. var steps;
  16191. if (!isDone) {
  16192. steps = iterators.map(function (i) { return i.next(); });
  16193. isDone = zipAll ? steps.every(function (s) { return s.done; }) : steps.some(function (s) { return s.done; });
  16194. }
  16195. if (isDone) {
  16196. return iteratorDone();
  16197. }
  16198. return iteratorValue(
  16199. type,
  16200. iterations++,
  16201. zipper.apply(null, steps.map(function (s) { return s.value; }))
  16202. );
  16203. });
  16204. };
  16205. return zipSequence;
  16206. }
  16207. // #pragma Helper Functions
  16208. function reify(iter, seq) {
  16209. return iter === seq ? iter : isSeq(iter) ? seq : iter.constructor(seq);
  16210. }
  16211. function validateEntry(entry) {
  16212. if (entry !== Object(entry)) {
  16213. throw new TypeError('Expected [K, V] tuple: ' + entry);
  16214. }
  16215. }
  16216. function collectionClass(collection) {
  16217. return isKeyed(collection)
  16218. ? KeyedCollection
  16219. : isIndexed(collection)
  16220. ? IndexedCollection
  16221. : SetCollection;
  16222. }
  16223. function makeSequence(collection) {
  16224. return Object.create(
  16225. (isKeyed(collection)
  16226. ? KeyedSeq
  16227. : isIndexed(collection)
  16228. ? IndexedSeq
  16229. : SetSeq
  16230. ).prototype
  16231. );
  16232. }
  16233. function cacheResultThrough() {
  16234. if (this._iter.cacheResult) {
  16235. this._iter.cacheResult();
  16236. this.size = this._iter.size;
  16237. return this;
  16238. }
  16239. return Seq.prototype.cacheResult.call(this);
  16240. }
  16241. function defaultComparator(a, b) {
  16242. if (a === undefined && b === undefined) {
  16243. return 0;
  16244. }
  16245. if (a === undefined) {
  16246. return 1;
  16247. }
  16248. if (b === undefined) {
  16249. return -1;
  16250. }
  16251. return a > b ? 1 : a < b ? -1 : 0;
  16252. }
  16253. // http://jsperf.com/copy-array-inline
  16254. function arrCopy(arr, offset) {
  16255. offset = offset || 0;
  16256. var len = Math.max(0, arr.length - offset);
  16257. var newArr = new Array(len);
  16258. for (var ii = 0; ii < len; ii++) {
  16259. newArr[ii] = arr[ii + offset];
  16260. }
  16261. return newArr;
  16262. }
  16263. function invariant(condition, error) {
  16264. if (!condition) { throw new Error(error); }
  16265. }
  16266. function assertNotInfinite(size) {
  16267. invariant(
  16268. size !== Infinity,
  16269. 'Cannot perform this action with an infinite size.'
  16270. );
  16271. }
  16272. function coerceKeyPath(keyPath) {
  16273. if (isArrayLike(keyPath) && typeof keyPath !== 'string') {
  16274. return keyPath;
  16275. }
  16276. if (isOrdered(keyPath)) {
  16277. return keyPath.toArray();
  16278. }
  16279. throw new TypeError(
  16280. 'Invalid keyPath: expected Ordered Collection or Array: ' + keyPath
  16281. );
  16282. }
  16283. function isPlainObj(value) {
  16284. return (
  16285. value &&
  16286. (typeof value.constructor !== 'function' ||
  16287. value.constructor.name === 'Object')
  16288. );
  16289. }
  16290. /**
  16291. * Returns true if the value is a potentially-persistent data structure, either
  16292. * provided by Immutable.js or a plain Array or Object.
  16293. */
  16294. function isDataStructure(value) {
  16295. return (
  16296. typeof value === 'object' &&
  16297. (isImmutable(value) || Array.isArray(value) || isPlainObj(value))
  16298. );
  16299. }
  16300. /**
  16301. * Converts a value to a string, adding quotes if a string was provided.
  16302. */
  16303. function quoteString(value) {
  16304. try {
  16305. return typeof value === 'string' ? JSON.stringify(value) : String(value);
  16306. } catch (_ignoreError) {
  16307. return JSON.stringify(value);
  16308. }
  16309. }
  16310. function has(collection, key) {
  16311. return isImmutable(collection)
  16312. ? collection.has(key)
  16313. : isDataStructure(collection) && hasOwnProperty.call(collection, key);
  16314. }
  16315. function get(collection, key, notSetValue) {
  16316. return isImmutable(collection)
  16317. ? collection.get(key, notSetValue)
  16318. : !has(collection, key)
  16319. ? notSetValue
  16320. : typeof collection.get === 'function'
  16321. ? collection.get(key)
  16322. : collection[key];
  16323. }
  16324. function shallowCopy(from) {
  16325. if (Array.isArray(from)) {
  16326. return arrCopy(from);
  16327. }
  16328. var to = {};
  16329. for (var key in from) {
  16330. if (hasOwnProperty.call(from, key)) {
  16331. to[key] = from[key];
  16332. }
  16333. }
  16334. return to;
  16335. }
  16336. function remove(collection, key) {
  16337. if (!isDataStructure(collection)) {
  16338. throw new TypeError(
  16339. 'Cannot update non-data-structure value: ' + collection
  16340. );
  16341. }
  16342. if (isImmutable(collection)) {
  16343. if (!collection.remove) {
  16344. throw new TypeError(
  16345. 'Cannot update immutable value without .remove() method: ' + collection
  16346. );
  16347. }
  16348. return collection.remove(key);
  16349. }
  16350. if (!hasOwnProperty.call(collection, key)) {
  16351. return collection;
  16352. }
  16353. var collectionCopy = shallowCopy(collection);
  16354. if (Array.isArray(collectionCopy)) {
  16355. collectionCopy.splice(key, 1);
  16356. } else {
  16357. delete collectionCopy[key];
  16358. }
  16359. return collectionCopy;
  16360. }
  16361. function set(collection, key, value) {
  16362. if (!isDataStructure(collection)) {
  16363. throw new TypeError(
  16364. 'Cannot update non-data-structure value: ' + collection
  16365. );
  16366. }
  16367. if (isImmutable(collection)) {
  16368. if (!collection.set) {
  16369. throw new TypeError(
  16370. 'Cannot update immutable value without .set() method: ' + collection
  16371. );
  16372. }
  16373. return collection.set(key, value);
  16374. }
  16375. if (hasOwnProperty.call(collection, key) && value === collection[key]) {
  16376. return collection;
  16377. }
  16378. var collectionCopy = shallowCopy(collection);
  16379. collectionCopy[key] = value;
  16380. return collectionCopy;
  16381. }
  16382. function updateIn(collection, keyPath, notSetValue, updater) {
  16383. if (!updater) {
  16384. updater = notSetValue;
  16385. notSetValue = undefined;
  16386. }
  16387. var updatedValue = updateInDeeply(
  16388. isImmutable(collection),
  16389. collection,
  16390. coerceKeyPath(keyPath),
  16391. 0,
  16392. notSetValue,
  16393. updater
  16394. );
  16395. return updatedValue === NOT_SET ? notSetValue : updatedValue;
  16396. }
  16397. function updateInDeeply(
  16398. inImmutable,
  16399. existing,
  16400. keyPath,
  16401. i,
  16402. notSetValue,
  16403. updater
  16404. ) {
  16405. var wasNotSet = existing === NOT_SET;
  16406. if (i === keyPath.length) {
  16407. var existingValue = wasNotSet ? notSetValue : existing;
  16408. var newValue = updater(existingValue);
  16409. return newValue === existingValue ? existing : newValue;
  16410. }
  16411. if (!wasNotSet && !isDataStructure(existing)) {
  16412. throw new TypeError(
  16413. 'Cannot update within non-data-structure value in path [' +
  16414. keyPath.slice(0, i).map(quoteString) +
  16415. ']: ' +
  16416. existing
  16417. );
  16418. }
  16419. var key = keyPath[i];
  16420. var nextExisting = wasNotSet ? NOT_SET : get(existing, key, NOT_SET);
  16421. var nextUpdated = updateInDeeply(
  16422. nextExisting === NOT_SET ? inImmutable : isImmutable(nextExisting),
  16423. nextExisting,
  16424. keyPath,
  16425. i + 1,
  16426. notSetValue,
  16427. updater
  16428. );
  16429. return nextUpdated === nextExisting
  16430. ? existing
  16431. : nextUpdated === NOT_SET
  16432. ? remove(existing, key)
  16433. : set(
  16434. wasNotSet ? (inImmutable ? emptyMap() : {}) : existing,
  16435. key,
  16436. nextUpdated
  16437. );
  16438. }
  16439. function setIn(collection, keyPath, value) {
  16440. return updateIn(collection, keyPath, NOT_SET, function () { return value; });
  16441. }
  16442. function setIn$1(keyPath, v) {
  16443. return setIn(this, keyPath, v);
  16444. }
  16445. function removeIn(collection, keyPath) {
  16446. return updateIn(collection, keyPath, function () { return NOT_SET; });
  16447. }
  16448. function deleteIn(keyPath) {
  16449. return removeIn(this, keyPath);
  16450. }
  16451. function update(collection, key, notSetValue, updater) {
  16452. return updateIn(collection, [key], notSetValue, updater);
  16453. }
  16454. function update$1(key, notSetValue, updater) {
  16455. return arguments.length === 1
  16456. ? key(this)
  16457. : update(this, key, notSetValue, updater);
  16458. }
  16459. function updateIn$1(keyPath, notSetValue, updater) {
  16460. return updateIn(this, keyPath, notSetValue, updater);
  16461. }
  16462. function merge() {
  16463. var iters = [], len = arguments.length;
  16464. while ( len-- ) iters[ len ] = arguments[ len ];
  16465. return mergeIntoKeyedWith(this, iters);
  16466. }
  16467. function mergeWith(merger) {
  16468. var iters = [], len = arguments.length - 1;
  16469. while ( len-- > 0 ) iters[ len ] = arguments[ len + 1 ];
  16470. if (typeof merger !== 'function') {
  16471. throw new TypeError('Invalid merger function: ' + merger);
  16472. }
  16473. return mergeIntoKeyedWith(this, iters, merger);
  16474. }
  16475. function mergeIntoKeyedWith(collection, collections, merger) {
  16476. var iters = [];
  16477. for (var ii = 0; ii < collections.length; ii++) {
  16478. var collection$1 = KeyedCollection(collections[ii]);
  16479. if (collection$1.size !== 0) {
  16480. iters.push(collection$1);
  16481. }
  16482. }
  16483. if (iters.length === 0) {
  16484. return collection;
  16485. }
  16486. if (
  16487. collection.toSeq().size === 0 &&
  16488. !collection.__ownerID &&
  16489. iters.length === 1
  16490. ) {
  16491. return collection.constructor(iters[0]);
  16492. }
  16493. return collection.withMutations(function (collection) {
  16494. var mergeIntoCollection = merger
  16495. ? function (value, key) {
  16496. update(
  16497. collection,
  16498. key,
  16499. NOT_SET,
  16500. function (oldVal) { return (oldVal === NOT_SET ? value : merger(oldVal, value, key)); }
  16501. );
  16502. }
  16503. : function (value, key) {
  16504. collection.set(key, value);
  16505. };
  16506. for (var ii = 0; ii < iters.length; ii++) {
  16507. iters[ii].forEach(mergeIntoCollection);
  16508. }
  16509. });
  16510. }
  16511. function merge$1(collection) {
  16512. var sources = [], len = arguments.length - 1;
  16513. while ( len-- > 0 ) sources[ len ] = arguments[ len + 1 ];
  16514. return mergeWithSources(collection, sources);
  16515. }
  16516. function mergeWith$1(merger, collection) {
  16517. var sources = [], len = arguments.length - 2;
  16518. while ( len-- > 0 ) sources[ len ] = arguments[ len + 2 ];
  16519. return mergeWithSources(collection, sources, merger);
  16520. }
  16521. function mergeDeep(collection) {
  16522. var sources = [], len = arguments.length - 1;
  16523. while ( len-- > 0 ) sources[ len ] = arguments[ len + 1 ];
  16524. return mergeDeepWithSources(collection, sources);
  16525. }
  16526. function mergeDeepWith(merger, collection) {
  16527. var sources = [], len = arguments.length - 2;
  16528. while ( len-- > 0 ) sources[ len ] = arguments[ len + 2 ];
  16529. return mergeDeepWithSources(collection, sources, merger);
  16530. }
  16531. function mergeDeepWithSources(collection, sources, merger) {
  16532. return mergeWithSources(collection, sources, deepMergerWith(merger));
  16533. }
  16534. function mergeWithSources(collection, sources, merger) {
  16535. if (!isDataStructure(collection)) {
  16536. throw new TypeError(
  16537. 'Cannot merge into non-data-structure value: ' + collection
  16538. );
  16539. }
  16540. if (isImmutable(collection)) {
  16541. return typeof merger === 'function' && collection.mergeWith
  16542. ? collection.mergeWith.apply(collection, [ merger ].concat( sources ))
  16543. : collection.merge
  16544. ? collection.merge.apply(collection, sources)
  16545. : collection.concat.apply(collection, sources);
  16546. }
  16547. var isArray = Array.isArray(collection);
  16548. var merged = collection;
  16549. var Collection$$1 = isArray ? IndexedCollection : KeyedCollection;
  16550. var mergeItem = isArray
  16551. ? function (value) {
  16552. // Copy on write
  16553. if (merged === collection) {
  16554. merged = shallowCopy(merged);
  16555. }
  16556. merged.push(value);
  16557. }
  16558. : function (value, key) {
  16559. var hasVal = hasOwnProperty.call(merged, key);
  16560. var nextVal =
  16561. hasVal && merger ? merger(merged[key], value, key) : value;
  16562. if (!hasVal || nextVal !== merged[key]) {
  16563. // Copy on write
  16564. if (merged === collection) {
  16565. merged = shallowCopy(merged);
  16566. }
  16567. merged[key] = nextVal;
  16568. }
  16569. };
  16570. for (var i = 0; i < sources.length; i++) {
  16571. Collection$$1(sources[i]).forEach(mergeItem);
  16572. }
  16573. return merged;
  16574. }
  16575. function deepMergerWith(merger) {
  16576. function deepMerger(oldValue, newValue, key) {
  16577. return isDataStructure(oldValue) && isDataStructure(newValue)
  16578. ? mergeWithSources(oldValue, [newValue], deepMerger)
  16579. : merger
  16580. ? merger(oldValue, newValue, key)
  16581. : newValue;
  16582. }
  16583. return deepMerger;
  16584. }
  16585. function mergeDeep$1() {
  16586. var iters = [], len = arguments.length;
  16587. while ( len-- ) iters[ len ] = arguments[ len ];
  16588. return mergeDeepWithSources(this, iters);
  16589. }
  16590. function mergeDeepWith$1(merger) {
  16591. var iters = [], len = arguments.length - 1;
  16592. while ( len-- > 0 ) iters[ len ] = arguments[ len + 1 ];
  16593. return mergeDeepWithSources(this, iters, merger);
  16594. }
  16595. function mergeIn(keyPath) {
  16596. var iters = [], len = arguments.length - 1;
  16597. while ( len-- > 0 ) iters[ len ] = arguments[ len + 1 ];
  16598. return updateIn(this, keyPath, emptyMap(), function (m) { return mergeWithSources(m, iters); });
  16599. }
  16600. function mergeDeepIn(keyPath) {
  16601. var iters = [], len = arguments.length - 1;
  16602. while ( len-- > 0 ) iters[ len ] = arguments[ len + 1 ];
  16603. return updateIn(this, keyPath, emptyMap(), function (m) { return mergeDeepWithSources(m, iters); }
  16604. );
  16605. }
  16606. function withMutations(fn) {
  16607. var mutable = this.asMutable();
  16608. fn(mutable);
  16609. return mutable.wasAltered() ? mutable.__ensureOwner(this.__ownerID) : this;
  16610. }
  16611. function asMutable() {
  16612. return this.__ownerID ? this : this.__ensureOwner(new OwnerID());
  16613. }
  16614. function asImmutable() {
  16615. return this.__ensureOwner();
  16616. }
  16617. function wasAltered() {
  16618. return this.__altered;
  16619. }
  16620. var Map = /*@__PURE__*/(function (KeyedCollection$$1) {
  16621. function Map(value) {
  16622. return value === null || value === undefined
  16623. ? emptyMap()
  16624. : isMap(value) && !isOrdered(value)
  16625. ? value
  16626. : emptyMap().withMutations(function (map) {
  16627. var iter = KeyedCollection$$1(value);
  16628. assertNotInfinite(iter.size);
  16629. iter.forEach(function (v, k) { return map.set(k, v); });
  16630. });
  16631. }
  16632. if ( KeyedCollection$$1 ) Map.__proto__ = KeyedCollection$$1;
  16633. Map.prototype = Object.create( KeyedCollection$$1 && KeyedCollection$$1.prototype );
  16634. Map.prototype.constructor = Map;
  16635. Map.of = function of () {
  16636. var keyValues = [], len = arguments.length;
  16637. while ( len-- ) keyValues[ len ] = arguments[ len ];
  16638. return emptyMap().withMutations(function (map) {
  16639. for (var i = 0; i < keyValues.length; i += 2) {
  16640. if (i + 1 >= keyValues.length) {
  16641. throw new Error('Missing value for key: ' + keyValues[i]);
  16642. }
  16643. map.set(keyValues[i], keyValues[i + 1]);
  16644. }
  16645. });
  16646. };
  16647. Map.prototype.toString = function toString () {
  16648. return this.__toString('Map {', '}');
  16649. };
  16650. // @pragma Access
  16651. Map.prototype.get = function get (k, notSetValue) {
  16652. return this._root
  16653. ? this._root.get(0, undefined, k, notSetValue)
  16654. : notSetValue;
  16655. };
  16656. // @pragma Modification
  16657. Map.prototype.set = function set (k, v) {
  16658. return updateMap(this, k, v);
  16659. };
  16660. Map.prototype.remove = function remove (k) {
  16661. return updateMap(this, k, NOT_SET);
  16662. };
  16663. Map.prototype.deleteAll = function deleteAll (keys) {
  16664. var collection = Collection(keys);
  16665. if (collection.size === 0) {
  16666. return this;
  16667. }
  16668. return this.withMutations(function (map) {
  16669. collection.forEach(function (key) { return map.remove(key); });
  16670. });
  16671. };
  16672. Map.prototype.clear = function clear () {
  16673. if (this.size === 0) {
  16674. return this;
  16675. }
  16676. if (this.__ownerID) {
  16677. this.size = 0;
  16678. this._root = null;
  16679. this.__hash = undefined;
  16680. this.__altered = true;
  16681. return this;
  16682. }
  16683. return emptyMap();
  16684. };
  16685. // @pragma Composition
  16686. Map.prototype.sort = function sort (comparator) {
  16687. // Late binding
  16688. return OrderedMap(sortFactory(this, comparator));
  16689. };
  16690. Map.prototype.sortBy = function sortBy (mapper, comparator) {
  16691. // Late binding
  16692. return OrderedMap(sortFactory(this, comparator, mapper));
  16693. };
  16694. Map.prototype.map = function map (mapper, context) {
  16695. return this.withMutations(function (map) {
  16696. map.forEach(function (value, key) {
  16697. map.set(key, mapper.call(context, value, key, map));
  16698. });
  16699. });
  16700. };
  16701. // @pragma Mutability
  16702. Map.prototype.__iterator = function __iterator (type, reverse) {
  16703. return new MapIterator(this, type, reverse);
  16704. };
  16705. Map.prototype.__iterate = function __iterate (fn, reverse) {
  16706. var this$1 = this;
  16707. var iterations = 0;
  16708. this._root &&
  16709. this._root.iterate(function (entry) {
  16710. iterations++;
  16711. return fn(entry[1], entry[0], this$1);
  16712. }, reverse);
  16713. return iterations;
  16714. };
  16715. Map.prototype.__ensureOwner = function __ensureOwner (ownerID) {
  16716. if (ownerID === this.__ownerID) {
  16717. return this;
  16718. }
  16719. if (!ownerID) {
  16720. if (this.size === 0) {
  16721. return emptyMap();
  16722. }
  16723. this.__ownerID = ownerID;
  16724. this.__altered = false;
  16725. return this;
  16726. }
  16727. return makeMap(this.size, this._root, ownerID, this.__hash);
  16728. };
  16729. return Map;
  16730. }(KeyedCollection));
  16731. Map.isMap = isMap;
  16732. var MapPrototype = Map.prototype;
  16733. MapPrototype[IS_MAP_SYMBOL] = true;
  16734. MapPrototype[DELETE] = MapPrototype.remove;
  16735. MapPrototype.removeAll = MapPrototype.deleteAll;
  16736. MapPrototype.setIn = setIn$1;
  16737. MapPrototype.removeIn = MapPrototype.deleteIn = deleteIn;
  16738. MapPrototype.update = update$1;
  16739. MapPrototype.updateIn = updateIn$1;
  16740. MapPrototype.merge = MapPrototype.concat = merge;
  16741. MapPrototype.mergeWith = mergeWith;
  16742. MapPrototype.mergeDeep = mergeDeep$1;
  16743. MapPrototype.mergeDeepWith = mergeDeepWith$1;
  16744. MapPrototype.mergeIn = mergeIn;
  16745. MapPrototype.mergeDeepIn = mergeDeepIn;
  16746. MapPrototype.withMutations = withMutations;
  16747. MapPrototype.wasAltered = wasAltered;
  16748. MapPrototype.asImmutable = asImmutable;
  16749. MapPrototype['@@transducer/init'] = MapPrototype.asMutable = asMutable;
  16750. MapPrototype['@@transducer/step'] = function(result, arr) {
  16751. return result.set(arr[0], arr[1]);
  16752. };
  16753. MapPrototype['@@transducer/result'] = function(obj) {
  16754. return obj.asImmutable();
  16755. };
  16756. // #pragma Trie Nodes
  16757. var ArrayMapNode = function ArrayMapNode(ownerID, entries) {
  16758. this.ownerID = ownerID;
  16759. this.entries = entries;
  16760. };
  16761. ArrayMapNode.prototype.get = function get (shift, keyHash, key, notSetValue) {
  16762. var entries = this.entries;
  16763. for (var ii = 0, len = entries.length; ii < len; ii++) {
  16764. if (is(key, entries[ii][0])) {
  16765. return entries[ii][1];
  16766. }
  16767. }
  16768. return notSetValue;
  16769. };
  16770. ArrayMapNode.prototype.update = function update (ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  16771. var removed = value === NOT_SET;
  16772. var entries = this.entries;
  16773. var idx = 0;
  16774. var len = entries.length;
  16775. for (; idx < len; idx++) {
  16776. if (is(key, entries[idx][0])) {
  16777. break;
  16778. }
  16779. }
  16780. var exists = idx < len;
  16781. if (exists ? entries[idx][1] === value : removed) {
  16782. return this;
  16783. }
  16784. SetRef(didAlter);
  16785. (removed || !exists) && SetRef(didChangeSize);
  16786. if (removed && entries.length === 1) {
  16787. return; // undefined
  16788. }
  16789. if (!exists && !removed && entries.length >= MAX_ARRAY_MAP_SIZE) {
  16790. return createNodes(ownerID, entries, key, value);
  16791. }
  16792. var isEditable = ownerID && ownerID === this.ownerID;
  16793. var newEntries = isEditable ? entries : arrCopy(entries);
  16794. if (exists) {
  16795. if (removed) {
  16796. idx === len - 1
  16797. ? newEntries.pop()
  16798. : (newEntries[idx] = newEntries.pop());
  16799. } else {
  16800. newEntries[idx] = [key, value];
  16801. }
  16802. } else {
  16803. newEntries.push([key, value]);
  16804. }
  16805. if (isEditable) {
  16806. this.entries = newEntries;
  16807. return this;
  16808. }
  16809. return new ArrayMapNode(ownerID, newEntries);
  16810. };
  16811. var BitmapIndexedNode = function BitmapIndexedNode(ownerID, bitmap, nodes) {
  16812. this.ownerID = ownerID;
  16813. this.bitmap = bitmap;
  16814. this.nodes = nodes;
  16815. };
  16816. BitmapIndexedNode.prototype.get = function get (shift, keyHash, key, notSetValue) {
  16817. if (keyHash === undefined) {
  16818. keyHash = hash(key);
  16819. }
  16820. var bit = 1 << ((shift === 0 ? keyHash : keyHash >>> shift) & MASK);
  16821. var bitmap = this.bitmap;
  16822. return (bitmap & bit) === 0
  16823. ? notSetValue
  16824. : this.nodes[popCount(bitmap & (bit - 1))].get(
  16825. shift + SHIFT,
  16826. keyHash,
  16827. key,
  16828. notSetValue
  16829. );
  16830. };
  16831. BitmapIndexedNode.prototype.update = function update (ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  16832. if (keyHash === undefined) {
  16833. keyHash = hash(key);
  16834. }
  16835. var keyHashFrag = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  16836. var bit = 1 << keyHashFrag;
  16837. var bitmap = this.bitmap;
  16838. var exists = (bitmap & bit) !== 0;
  16839. if (!exists && value === NOT_SET) {
  16840. return this;
  16841. }
  16842. var idx = popCount(bitmap & (bit - 1));
  16843. var nodes = this.nodes;
  16844. var node = exists ? nodes[idx] : undefined;
  16845. var newNode = updateNode(
  16846. node,
  16847. ownerID,
  16848. shift + SHIFT,
  16849. keyHash,
  16850. key,
  16851. value,
  16852. didChangeSize,
  16853. didAlter
  16854. );
  16855. if (newNode === node) {
  16856. return this;
  16857. }
  16858. if (!exists && newNode && nodes.length >= MAX_BITMAP_INDEXED_SIZE) {
  16859. return expandNodes(ownerID, nodes, bitmap, keyHashFrag, newNode);
  16860. }
  16861. if (
  16862. exists &&
  16863. !newNode &&
  16864. nodes.length === 2 &&
  16865. isLeafNode(nodes[idx ^ 1])
  16866. ) {
  16867. return nodes[idx ^ 1];
  16868. }
  16869. if (exists && newNode && nodes.length === 1 && isLeafNode(newNode)) {
  16870. return newNode;
  16871. }
  16872. var isEditable = ownerID && ownerID === this.ownerID;
  16873. var newBitmap = exists ? (newNode ? bitmap : bitmap ^ bit) : bitmap | bit;
  16874. var newNodes = exists
  16875. ? newNode
  16876. ? setAt(nodes, idx, newNode, isEditable)
  16877. : spliceOut(nodes, idx, isEditable)
  16878. : spliceIn(nodes, idx, newNode, isEditable);
  16879. if (isEditable) {
  16880. this.bitmap = newBitmap;
  16881. this.nodes = newNodes;
  16882. return this;
  16883. }
  16884. return new BitmapIndexedNode(ownerID, newBitmap, newNodes);
  16885. };
  16886. var HashArrayMapNode = function HashArrayMapNode(ownerID, count, nodes) {
  16887. this.ownerID = ownerID;
  16888. this.count = count;
  16889. this.nodes = nodes;
  16890. };
  16891. HashArrayMapNode.prototype.get = function get (shift, keyHash, key, notSetValue) {
  16892. if (keyHash === undefined) {
  16893. keyHash = hash(key);
  16894. }
  16895. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  16896. var node = this.nodes[idx];
  16897. return node
  16898. ? node.get(shift + SHIFT, keyHash, key, notSetValue)
  16899. : notSetValue;
  16900. };
  16901. HashArrayMapNode.prototype.update = function update (ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  16902. if (keyHash === undefined) {
  16903. keyHash = hash(key);
  16904. }
  16905. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  16906. var removed = value === NOT_SET;
  16907. var nodes = this.nodes;
  16908. var node = nodes[idx];
  16909. if (removed && !node) {
  16910. return this;
  16911. }
  16912. var newNode = updateNode(
  16913. node,
  16914. ownerID,
  16915. shift + SHIFT,
  16916. keyHash,
  16917. key,
  16918. value,
  16919. didChangeSize,
  16920. didAlter
  16921. );
  16922. if (newNode === node) {
  16923. return this;
  16924. }
  16925. var newCount = this.count;
  16926. if (!node) {
  16927. newCount++;
  16928. } else if (!newNode) {
  16929. newCount--;
  16930. if (newCount < MIN_HASH_ARRAY_MAP_SIZE) {
  16931. return packNodes(ownerID, nodes, newCount, idx);
  16932. }
  16933. }
  16934. var isEditable = ownerID && ownerID === this.ownerID;
  16935. var newNodes = setAt(nodes, idx, newNode, isEditable);
  16936. if (isEditable) {
  16937. this.count = newCount;
  16938. this.nodes = newNodes;
  16939. return this;
  16940. }
  16941. return new HashArrayMapNode(ownerID, newCount, newNodes);
  16942. };
  16943. var HashCollisionNode = function HashCollisionNode(ownerID, keyHash, entries) {
  16944. this.ownerID = ownerID;
  16945. this.keyHash = keyHash;
  16946. this.entries = entries;
  16947. };
  16948. HashCollisionNode.prototype.get = function get (shift, keyHash, key, notSetValue) {
  16949. var entries = this.entries;
  16950. for (var ii = 0, len = entries.length; ii < len; ii++) {
  16951. if (is(key, entries[ii][0])) {
  16952. return entries[ii][1];
  16953. }
  16954. }
  16955. return notSetValue;
  16956. };
  16957. HashCollisionNode.prototype.update = function update (ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  16958. if (keyHash === undefined) {
  16959. keyHash = hash(key);
  16960. }
  16961. var removed = value === NOT_SET;
  16962. if (keyHash !== this.keyHash) {
  16963. if (removed) {
  16964. return this;
  16965. }
  16966. SetRef(didAlter);
  16967. SetRef(didChangeSize);
  16968. return mergeIntoNode(this, ownerID, shift, keyHash, [key, value]);
  16969. }
  16970. var entries = this.entries;
  16971. var idx = 0;
  16972. var len = entries.length;
  16973. for (; idx < len; idx++) {
  16974. if (is(key, entries[idx][0])) {
  16975. break;
  16976. }
  16977. }
  16978. var exists = idx < len;
  16979. if (exists ? entries[idx][1] === value : removed) {
  16980. return this;
  16981. }
  16982. SetRef(didAlter);
  16983. (removed || !exists) && SetRef(didChangeSize);
  16984. if (removed && len === 2) {
  16985. return new ValueNode(ownerID, this.keyHash, entries[idx ^ 1]);
  16986. }
  16987. var isEditable = ownerID && ownerID === this.ownerID;
  16988. var newEntries = isEditable ? entries : arrCopy(entries);
  16989. if (exists) {
  16990. if (removed) {
  16991. idx === len - 1
  16992. ? newEntries.pop()
  16993. : (newEntries[idx] = newEntries.pop());
  16994. } else {
  16995. newEntries[idx] = [key, value];
  16996. }
  16997. } else {
  16998. newEntries.push([key, value]);
  16999. }
  17000. if (isEditable) {
  17001. this.entries = newEntries;
  17002. return this;
  17003. }
  17004. return new HashCollisionNode(ownerID, this.keyHash, newEntries);
  17005. };
  17006. var ValueNode = function ValueNode(ownerID, keyHash, entry) {
  17007. this.ownerID = ownerID;
  17008. this.keyHash = keyHash;
  17009. this.entry = entry;
  17010. };
  17011. ValueNode.prototype.get = function get (shift, keyHash, key, notSetValue) {
  17012. return is(key, this.entry[0]) ? this.entry[1] : notSetValue;
  17013. };
  17014. ValueNode.prototype.update = function update (ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  17015. var removed = value === NOT_SET;
  17016. var keyMatch = is(key, this.entry[0]);
  17017. if (keyMatch ? value === this.entry[1] : removed) {
  17018. return this;
  17019. }
  17020. SetRef(didAlter);
  17021. if (removed) {
  17022. SetRef(didChangeSize);
  17023. return; // undefined
  17024. }
  17025. if (keyMatch) {
  17026. if (ownerID && ownerID === this.ownerID) {
  17027. this.entry[1] = value;
  17028. return this;
  17029. }
  17030. return new ValueNode(ownerID, this.keyHash, [key, value]);
  17031. }
  17032. SetRef(didChangeSize);
  17033. return mergeIntoNode(this, ownerID, shift, hash(key), [key, value]);
  17034. };
  17035. // #pragma Iterators
  17036. ArrayMapNode.prototype.iterate = HashCollisionNode.prototype.iterate = function(
  17037. fn,
  17038. reverse
  17039. ) {
  17040. var entries = this.entries;
  17041. for (var ii = 0, maxIndex = entries.length - 1; ii <= maxIndex; ii++) {
  17042. if (fn(entries[reverse ? maxIndex - ii : ii]) === false) {
  17043. return false;
  17044. }
  17045. }
  17046. };
  17047. BitmapIndexedNode.prototype.iterate = HashArrayMapNode.prototype.iterate = function(
  17048. fn,
  17049. reverse
  17050. ) {
  17051. var nodes = this.nodes;
  17052. for (var ii = 0, maxIndex = nodes.length - 1; ii <= maxIndex; ii++) {
  17053. var node = nodes[reverse ? maxIndex - ii : ii];
  17054. if (node && node.iterate(fn, reverse) === false) {
  17055. return false;
  17056. }
  17057. }
  17058. };
  17059. // eslint-disable-next-line no-unused-vars
  17060. ValueNode.prototype.iterate = function(fn, reverse) {
  17061. return fn(this.entry);
  17062. };
  17063. var MapIterator = /*@__PURE__*/(function (Iterator$$1) {
  17064. function MapIterator(map, type, reverse) {
  17065. this._type = type;
  17066. this._reverse = reverse;
  17067. this._stack = map._root && mapIteratorFrame(map._root);
  17068. }
  17069. if ( Iterator$$1 ) MapIterator.__proto__ = Iterator$$1;
  17070. MapIterator.prototype = Object.create( Iterator$$1 && Iterator$$1.prototype );
  17071. MapIterator.prototype.constructor = MapIterator;
  17072. MapIterator.prototype.next = function next () {
  17073. var type = this._type;
  17074. var stack = this._stack;
  17075. while (stack) {
  17076. var node = stack.node;
  17077. var index = stack.index++;
  17078. var maxIndex = (void 0);
  17079. if (node.entry) {
  17080. if (index === 0) {
  17081. return mapIteratorValue(type, node.entry);
  17082. }
  17083. } else if (node.entries) {
  17084. maxIndex = node.entries.length - 1;
  17085. if (index <= maxIndex) {
  17086. return mapIteratorValue(
  17087. type,
  17088. node.entries[this._reverse ? maxIndex - index : index]
  17089. );
  17090. }
  17091. } else {
  17092. maxIndex = node.nodes.length - 1;
  17093. if (index <= maxIndex) {
  17094. var subNode = node.nodes[this._reverse ? maxIndex - index : index];
  17095. if (subNode) {
  17096. if (subNode.entry) {
  17097. return mapIteratorValue(type, subNode.entry);
  17098. }
  17099. stack = this._stack = mapIteratorFrame(subNode, stack);
  17100. }
  17101. continue;
  17102. }
  17103. }
  17104. stack = this._stack = this._stack.__prev;
  17105. }
  17106. return iteratorDone();
  17107. };
  17108. return MapIterator;
  17109. }(Iterator));
  17110. function mapIteratorValue(type, entry) {
  17111. return iteratorValue(type, entry[0], entry[1]);
  17112. }
  17113. function mapIteratorFrame(node, prev) {
  17114. return {
  17115. node: node,
  17116. index: 0,
  17117. __prev: prev,
  17118. };
  17119. }
  17120. function makeMap(size, root, ownerID, hash$$1) {
  17121. var map = Object.create(MapPrototype);
  17122. map.size = size;
  17123. map._root = root;
  17124. map.__ownerID = ownerID;
  17125. map.__hash = hash$$1;
  17126. map.__altered = false;
  17127. return map;
  17128. }
  17129. var EMPTY_MAP;
  17130. function emptyMap() {
  17131. return EMPTY_MAP || (EMPTY_MAP = makeMap(0));
  17132. }
  17133. function updateMap(map, k, v) {
  17134. var newRoot;
  17135. var newSize;
  17136. if (!map._root) {
  17137. if (v === NOT_SET) {
  17138. return map;
  17139. }
  17140. newSize = 1;
  17141. newRoot = new ArrayMapNode(map.__ownerID, [[k, v]]);
  17142. } else {
  17143. var didChangeSize = MakeRef();
  17144. var didAlter = MakeRef();
  17145. newRoot = updateNode(
  17146. map._root,
  17147. map.__ownerID,
  17148. 0,
  17149. undefined,
  17150. k,
  17151. v,
  17152. didChangeSize,
  17153. didAlter
  17154. );
  17155. if (!didAlter.value) {
  17156. return map;
  17157. }
  17158. newSize = map.size + (didChangeSize.value ? (v === NOT_SET ? -1 : 1) : 0);
  17159. }
  17160. if (map.__ownerID) {
  17161. map.size = newSize;
  17162. map._root = newRoot;
  17163. map.__hash = undefined;
  17164. map.__altered = true;
  17165. return map;
  17166. }
  17167. return newRoot ? makeMap(newSize, newRoot) : emptyMap();
  17168. }
  17169. function updateNode(
  17170. node,
  17171. ownerID,
  17172. shift,
  17173. keyHash,
  17174. key,
  17175. value,
  17176. didChangeSize,
  17177. didAlter
  17178. ) {
  17179. if (!node) {
  17180. if (value === NOT_SET) {
  17181. return node;
  17182. }
  17183. SetRef(didAlter);
  17184. SetRef(didChangeSize);
  17185. return new ValueNode(ownerID, keyHash, [key, value]);
  17186. }
  17187. return node.update(
  17188. ownerID,
  17189. shift,
  17190. keyHash,
  17191. key,
  17192. value,
  17193. didChangeSize,
  17194. didAlter
  17195. );
  17196. }
  17197. function isLeafNode(node) {
  17198. return (
  17199. node.constructor === ValueNode || node.constructor === HashCollisionNode
  17200. );
  17201. }
  17202. function mergeIntoNode(node, ownerID, shift, keyHash, entry) {
  17203. if (node.keyHash === keyHash) {
  17204. return new HashCollisionNode(ownerID, keyHash, [node.entry, entry]);
  17205. }
  17206. var idx1 = (shift === 0 ? node.keyHash : node.keyHash >>> shift) & MASK;
  17207. var idx2 = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  17208. var newNode;
  17209. var nodes =
  17210. idx1 === idx2
  17211. ? [mergeIntoNode(node, ownerID, shift + SHIFT, keyHash, entry)]
  17212. : ((newNode = new ValueNode(ownerID, keyHash, entry)),
  17213. idx1 < idx2 ? [node, newNode] : [newNode, node]);
  17214. return new BitmapIndexedNode(ownerID, (1 << idx1) | (1 << idx2), nodes);
  17215. }
  17216. function createNodes(ownerID, entries, key, value) {
  17217. if (!ownerID) {
  17218. ownerID = new OwnerID();
  17219. }
  17220. var node = new ValueNode(ownerID, hash(key), [key, value]);
  17221. for (var ii = 0; ii < entries.length; ii++) {
  17222. var entry = entries[ii];
  17223. node = node.update(ownerID, 0, undefined, entry[0], entry[1]);
  17224. }
  17225. return node;
  17226. }
  17227. function packNodes(ownerID, nodes, count, excluding) {
  17228. var bitmap = 0;
  17229. var packedII = 0;
  17230. var packedNodes = new Array(count);
  17231. for (var ii = 0, bit = 1, len = nodes.length; ii < len; ii++, bit <<= 1) {
  17232. var node = nodes[ii];
  17233. if (node !== undefined && ii !== excluding) {
  17234. bitmap |= bit;
  17235. packedNodes[packedII++] = node;
  17236. }
  17237. }
  17238. return new BitmapIndexedNode(ownerID, bitmap, packedNodes);
  17239. }
  17240. function expandNodes(ownerID, nodes, bitmap, including, node) {
  17241. var count = 0;
  17242. var expandedNodes = new Array(SIZE);
  17243. for (var ii = 0; bitmap !== 0; ii++, bitmap >>>= 1) {
  17244. expandedNodes[ii] = bitmap & 1 ? nodes[count++] : undefined;
  17245. }
  17246. expandedNodes[including] = node;
  17247. return new HashArrayMapNode(ownerID, count + 1, expandedNodes);
  17248. }
  17249. function popCount(x) {
  17250. x -= (x >> 1) & 0x55555555;
  17251. x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
  17252. x = (x + (x >> 4)) & 0x0f0f0f0f;
  17253. x += x >> 8;
  17254. x += x >> 16;
  17255. return x & 0x7f;
  17256. }
  17257. function setAt(array, idx, val, canEdit) {
  17258. var newArray = canEdit ? array : arrCopy(array);
  17259. newArray[idx] = val;
  17260. return newArray;
  17261. }
  17262. function spliceIn(array, idx, val, canEdit) {
  17263. var newLen = array.length + 1;
  17264. if (canEdit && idx + 1 === newLen) {
  17265. array[idx] = val;
  17266. return array;
  17267. }
  17268. var newArray = new Array(newLen);
  17269. var after = 0;
  17270. for (var ii = 0; ii < newLen; ii++) {
  17271. if (ii === idx) {
  17272. newArray[ii] = val;
  17273. after = -1;
  17274. } else {
  17275. newArray[ii] = array[ii + after];
  17276. }
  17277. }
  17278. return newArray;
  17279. }
  17280. function spliceOut(array, idx, canEdit) {
  17281. var newLen = array.length - 1;
  17282. if (canEdit && idx === newLen) {
  17283. array.pop();
  17284. return array;
  17285. }
  17286. var newArray = new Array(newLen);
  17287. var after = 0;
  17288. for (var ii = 0; ii < newLen; ii++) {
  17289. if (ii === idx) {
  17290. after = 1;
  17291. }
  17292. newArray[ii] = array[ii + after];
  17293. }
  17294. return newArray;
  17295. }
  17296. var MAX_ARRAY_MAP_SIZE = SIZE / 4;
  17297. var MAX_BITMAP_INDEXED_SIZE = SIZE / 2;
  17298. var MIN_HASH_ARRAY_MAP_SIZE = SIZE / 4;
  17299. var IS_LIST_SYMBOL = '@@__IMMUTABLE_LIST__@@';
  17300. function isList(maybeList) {
  17301. return Boolean(maybeList && maybeList[IS_LIST_SYMBOL]);
  17302. }
  17303. var List = /*@__PURE__*/(function (IndexedCollection$$1) {
  17304. function List(value) {
  17305. var empty = emptyList();
  17306. if (value === null || value === undefined) {
  17307. return empty;
  17308. }
  17309. if (isList(value)) {
  17310. return value;
  17311. }
  17312. var iter = IndexedCollection$$1(value);
  17313. var size = iter.size;
  17314. if (size === 0) {
  17315. return empty;
  17316. }
  17317. assertNotInfinite(size);
  17318. if (size > 0 && size < SIZE) {
  17319. return makeList(0, size, SHIFT, null, new VNode(iter.toArray()));
  17320. }
  17321. return empty.withMutations(function (list) {
  17322. list.setSize(size);
  17323. iter.forEach(function (v, i) { return list.set(i, v); });
  17324. });
  17325. }
  17326. if ( IndexedCollection$$1 ) List.__proto__ = IndexedCollection$$1;
  17327. List.prototype = Object.create( IndexedCollection$$1 && IndexedCollection$$1.prototype );
  17328. List.prototype.constructor = List;
  17329. List.of = function of (/*...values*/) {
  17330. return this(arguments);
  17331. };
  17332. List.prototype.toString = function toString () {
  17333. return this.__toString('List [', ']');
  17334. };
  17335. // @pragma Access
  17336. List.prototype.get = function get (index, notSetValue) {
  17337. index = wrapIndex(this, index);
  17338. if (index >= 0 && index < this.size) {
  17339. index += this._origin;
  17340. var node = listNodeFor(this, index);
  17341. return node && node.array[index & MASK];
  17342. }
  17343. return notSetValue;
  17344. };
  17345. // @pragma Modification
  17346. List.prototype.set = function set (index, value) {
  17347. return updateList(this, index, value);
  17348. };
  17349. List.prototype.remove = function remove (index) {
  17350. return !this.has(index)
  17351. ? this
  17352. : index === 0
  17353. ? this.shift()
  17354. : index === this.size - 1
  17355. ? this.pop()
  17356. : this.splice(index, 1);
  17357. };
  17358. List.prototype.insert = function insert (index, value) {
  17359. return this.splice(index, 0, value);
  17360. };
  17361. List.prototype.clear = function clear () {
  17362. if (this.size === 0) {
  17363. return this;
  17364. }
  17365. if (this.__ownerID) {
  17366. this.size = this._origin = this._capacity = 0;
  17367. this._level = SHIFT;
  17368. this._root = this._tail = null;
  17369. this.__hash = undefined;
  17370. this.__altered = true;
  17371. return this;
  17372. }
  17373. return emptyList();
  17374. };
  17375. List.prototype.push = function push (/*...values*/) {
  17376. var values = arguments;
  17377. var oldSize = this.size;
  17378. return this.withMutations(function (list) {
  17379. setListBounds(list, 0, oldSize + values.length);
  17380. for (var ii = 0; ii < values.length; ii++) {
  17381. list.set(oldSize + ii, values[ii]);
  17382. }
  17383. });
  17384. };
  17385. List.prototype.pop = function pop () {
  17386. return setListBounds(this, 0, -1);
  17387. };
  17388. List.prototype.unshift = function unshift (/*...values*/) {
  17389. var values = arguments;
  17390. return this.withMutations(function (list) {
  17391. setListBounds(list, -values.length);
  17392. for (var ii = 0; ii < values.length; ii++) {
  17393. list.set(ii, values[ii]);
  17394. }
  17395. });
  17396. };
  17397. List.prototype.shift = function shift () {
  17398. return setListBounds(this, 1);
  17399. };
  17400. // @pragma Composition
  17401. List.prototype.concat = function concat (/*...collections*/) {
  17402. var arguments$1 = arguments;
  17403. var seqs = [];
  17404. for (var i = 0; i < arguments.length; i++) {
  17405. var argument = arguments$1[i];
  17406. var seq = IndexedCollection$$1(
  17407. typeof argument !== 'string' && hasIterator(argument)
  17408. ? argument
  17409. : [argument]
  17410. );
  17411. if (seq.size !== 0) {
  17412. seqs.push(seq);
  17413. }
  17414. }
  17415. if (seqs.length === 0) {
  17416. return this;
  17417. }
  17418. if (this.size === 0 && !this.__ownerID && seqs.length === 1) {
  17419. return this.constructor(seqs[0]);
  17420. }
  17421. return this.withMutations(function (list) {
  17422. seqs.forEach(function (seq) { return seq.forEach(function (value) { return list.push(value); }); });
  17423. });
  17424. };
  17425. List.prototype.setSize = function setSize (size) {
  17426. return setListBounds(this, 0, size);
  17427. };
  17428. List.prototype.map = function map (mapper, context) {
  17429. var this$1 = this;
  17430. return this.withMutations(function (list) {
  17431. for (var i = 0; i < this$1.size; i++) {
  17432. list.set(i, mapper.call(context, list.get(i), i, list));
  17433. }
  17434. });
  17435. };
  17436. // @pragma Iteration
  17437. List.prototype.slice = function slice (begin, end) {
  17438. var size = this.size;
  17439. if (wholeSlice(begin, end, size)) {
  17440. return this;
  17441. }
  17442. return setListBounds(
  17443. this,
  17444. resolveBegin(begin, size),
  17445. resolveEnd(end, size)
  17446. );
  17447. };
  17448. List.prototype.__iterator = function __iterator (type, reverse) {
  17449. var index = reverse ? this.size : 0;
  17450. var values = iterateList(this, reverse);
  17451. return new Iterator(function () {
  17452. var value = values();
  17453. return value === DONE
  17454. ? iteratorDone()
  17455. : iteratorValue(type, reverse ? --index : index++, value);
  17456. });
  17457. };
  17458. List.prototype.__iterate = function __iterate (fn, reverse) {
  17459. var index = reverse ? this.size : 0;
  17460. var values = iterateList(this, reverse);
  17461. var value;
  17462. while ((value = values()) !== DONE) {
  17463. if (fn(value, reverse ? --index : index++, this) === false) {
  17464. break;
  17465. }
  17466. }
  17467. return index;
  17468. };
  17469. List.prototype.__ensureOwner = function __ensureOwner (ownerID) {
  17470. if (ownerID === this.__ownerID) {
  17471. return this;
  17472. }
  17473. if (!ownerID) {
  17474. if (this.size === 0) {
  17475. return emptyList();
  17476. }
  17477. this.__ownerID = ownerID;
  17478. this.__altered = false;
  17479. return this;
  17480. }
  17481. return makeList(
  17482. this._origin,
  17483. this._capacity,
  17484. this._level,
  17485. this._root,
  17486. this._tail,
  17487. ownerID,
  17488. this.__hash
  17489. );
  17490. };
  17491. return List;
  17492. }(IndexedCollection));
  17493. List.isList = isList;
  17494. var ListPrototype = List.prototype;
  17495. ListPrototype[IS_LIST_SYMBOL] = true;
  17496. ListPrototype[DELETE] = ListPrototype.remove;
  17497. ListPrototype.merge = ListPrototype.concat;
  17498. ListPrototype.setIn = setIn$1;
  17499. ListPrototype.deleteIn = ListPrototype.removeIn = deleteIn;
  17500. ListPrototype.update = update$1;
  17501. ListPrototype.updateIn = updateIn$1;
  17502. ListPrototype.mergeIn = mergeIn;
  17503. ListPrototype.mergeDeepIn = mergeDeepIn;
  17504. ListPrototype.withMutations = withMutations;
  17505. ListPrototype.wasAltered = wasAltered;
  17506. ListPrototype.asImmutable = asImmutable;
  17507. ListPrototype['@@transducer/init'] = ListPrototype.asMutable = asMutable;
  17508. ListPrototype['@@transducer/step'] = function(result, arr) {
  17509. return result.push(arr);
  17510. };
  17511. ListPrototype['@@transducer/result'] = function(obj) {
  17512. return obj.asImmutable();
  17513. };
  17514. var VNode = function VNode(array, ownerID) {
  17515. this.array = array;
  17516. this.ownerID = ownerID;
  17517. };
  17518. // TODO: seems like these methods are very similar
  17519. VNode.prototype.removeBefore = function removeBefore (ownerID, level, index) {
  17520. if (index === level ? 1 << level : this.array.length === 0) {
  17521. return this;
  17522. }
  17523. var originIndex = (index >>> level) & MASK;
  17524. if (originIndex >= this.array.length) {
  17525. return new VNode([], ownerID);
  17526. }
  17527. var removingFirst = originIndex === 0;
  17528. var newChild;
  17529. if (level > 0) {
  17530. var oldChild = this.array[originIndex];
  17531. newChild =
  17532. oldChild && oldChild.removeBefore(ownerID, level - SHIFT, index);
  17533. if (newChild === oldChild && removingFirst) {
  17534. return this;
  17535. }
  17536. }
  17537. if (removingFirst && !newChild) {
  17538. return this;
  17539. }
  17540. var editable = editableVNode(this, ownerID);
  17541. if (!removingFirst) {
  17542. for (var ii = 0; ii < originIndex; ii++) {
  17543. editable.array[ii] = undefined;
  17544. }
  17545. }
  17546. if (newChild) {
  17547. editable.array[originIndex] = newChild;
  17548. }
  17549. return editable;
  17550. };
  17551. VNode.prototype.removeAfter = function removeAfter (ownerID, level, index) {
  17552. if (index === (level ? 1 << level : 0) || this.array.length === 0) {
  17553. return this;
  17554. }
  17555. var sizeIndex = ((index - 1) >>> level) & MASK;
  17556. if (sizeIndex >= this.array.length) {
  17557. return this;
  17558. }
  17559. var newChild;
  17560. if (level > 0) {
  17561. var oldChild = this.array[sizeIndex];
  17562. newChild =
  17563. oldChild && oldChild.removeAfter(ownerID, level - SHIFT, index);
  17564. if (newChild === oldChild && sizeIndex === this.array.length - 1) {
  17565. return this;
  17566. }
  17567. }
  17568. var editable = editableVNode(this, ownerID);
  17569. editable.array.splice(sizeIndex + 1);
  17570. if (newChild) {
  17571. editable.array[sizeIndex] = newChild;
  17572. }
  17573. return editable;
  17574. };
  17575. var DONE = {};
  17576. function iterateList(list, reverse) {
  17577. var left = list._origin;
  17578. var right = list._capacity;
  17579. var tailPos = getTailOffset(right);
  17580. var tail = list._tail;
  17581. return iterateNodeOrLeaf(list._root, list._level, 0);
  17582. function iterateNodeOrLeaf(node, level, offset) {
  17583. return level === 0
  17584. ? iterateLeaf(node, offset)
  17585. : iterateNode(node, level, offset);
  17586. }
  17587. function iterateLeaf(node, offset) {
  17588. var array = offset === tailPos ? tail && tail.array : node && node.array;
  17589. var from = offset > left ? 0 : left - offset;
  17590. var to = right - offset;
  17591. if (to > SIZE) {
  17592. to = SIZE;
  17593. }
  17594. return function () {
  17595. if (from === to) {
  17596. return DONE;
  17597. }
  17598. var idx = reverse ? --to : from++;
  17599. return array && array[idx];
  17600. };
  17601. }
  17602. function iterateNode(node, level, offset) {
  17603. var values;
  17604. var array = node && node.array;
  17605. var from = offset > left ? 0 : (left - offset) >> level;
  17606. var to = ((right - offset) >> level) + 1;
  17607. if (to > SIZE) {
  17608. to = SIZE;
  17609. }
  17610. return function () {
  17611. while (true) {
  17612. if (values) {
  17613. var value = values();
  17614. if (value !== DONE) {
  17615. return value;
  17616. }
  17617. values = null;
  17618. }
  17619. if (from === to) {
  17620. return DONE;
  17621. }
  17622. var idx = reverse ? --to : from++;
  17623. values = iterateNodeOrLeaf(
  17624. array && array[idx],
  17625. level - SHIFT,
  17626. offset + (idx << level)
  17627. );
  17628. }
  17629. };
  17630. }
  17631. }
  17632. function makeList(origin, capacity, level, root, tail, ownerID, hash) {
  17633. var list = Object.create(ListPrototype);
  17634. list.size = capacity - origin;
  17635. list._origin = origin;
  17636. list._capacity = capacity;
  17637. list._level = level;
  17638. list._root = root;
  17639. list._tail = tail;
  17640. list.__ownerID = ownerID;
  17641. list.__hash = hash;
  17642. list.__altered = false;
  17643. return list;
  17644. }
  17645. var EMPTY_LIST;
  17646. function emptyList() {
  17647. return EMPTY_LIST || (EMPTY_LIST = makeList(0, 0, SHIFT));
  17648. }
  17649. function updateList(list, index, value) {
  17650. index = wrapIndex(list, index);
  17651. if (index !== index) {
  17652. return list;
  17653. }
  17654. if (index >= list.size || index < 0) {
  17655. return list.withMutations(function (list) {
  17656. index < 0
  17657. ? setListBounds(list, index).set(0, value)
  17658. : setListBounds(list, 0, index + 1).set(index, value);
  17659. });
  17660. }
  17661. index += list._origin;
  17662. var newTail = list._tail;
  17663. var newRoot = list._root;
  17664. var didAlter = MakeRef();
  17665. if (index >= getTailOffset(list._capacity)) {
  17666. newTail = updateVNode(newTail, list.__ownerID, 0, index, value, didAlter);
  17667. } else {
  17668. newRoot = updateVNode(
  17669. newRoot,
  17670. list.__ownerID,
  17671. list._level,
  17672. index,
  17673. value,
  17674. didAlter
  17675. );
  17676. }
  17677. if (!didAlter.value) {
  17678. return list;
  17679. }
  17680. if (list.__ownerID) {
  17681. list._root = newRoot;
  17682. list._tail = newTail;
  17683. list.__hash = undefined;
  17684. list.__altered = true;
  17685. return list;
  17686. }
  17687. return makeList(list._origin, list._capacity, list._level, newRoot, newTail);
  17688. }
  17689. function updateVNode(node, ownerID, level, index, value, didAlter) {
  17690. var idx = (index >>> level) & MASK;
  17691. var nodeHas = node && idx < node.array.length;
  17692. if (!nodeHas && value === undefined) {
  17693. return node;
  17694. }
  17695. var newNode;
  17696. if (level > 0) {
  17697. var lowerNode = node && node.array[idx];
  17698. var newLowerNode = updateVNode(
  17699. lowerNode,
  17700. ownerID,
  17701. level - SHIFT,
  17702. index,
  17703. value,
  17704. didAlter
  17705. );
  17706. if (newLowerNode === lowerNode) {
  17707. return node;
  17708. }
  17709. newNode = editableVNode(node, ownerID);
  17710. newNode.array[idx] = newLowerNode;
  17711. return newNode;
  17712. }
  17713. if (nodeHas && node.array[idx] === value) {
  17714. return node;
  17715. }
  17716. if (didAlter) {
  17717. SetRef(didAlter);
  17718. }
  17719. newNode = editableVNode(node, ownerID);
  17720. if (value === undefined && idx === newNode.array.length - 1) {
  17721. newNode.array.pop();
  17722. } else {
  17723. newNode.array[idx] = value;
  17724. }
  17725. return newNode;
  17726. }
  17727. function editableVNode(node, ownerID) {
  17728. if (ownerID && node && ownerID === node.ownerID) {
  17729. return node;
  17730. }
  17731. return new VNode(node ? node.array.slice() : [], ownerID);
  17732. }
  17733. function listNodeFor(list, rawIndex) {
  17734. if (rawIndex >= getTailOffset(list._capacity)) {
  17735. return list._tail;
  17736. }
  17737. if (rawIndex < 1 << (list._level + SHIFT)) {
  17738. var node = list._root;
  17739. var level = list._level;
  17740. while (node && level > 0) {
  17741. node = node.array[(rawIndex >>> level) & MASK];
  17742. level -= SHIFT;
  17743. }
  17744. return node;
  17745. }
  17746. }
  17747. function setListBounds(list, begin, end) {
  17748. // Sanitize begin & end using this shorthand for ToInt32(argument)
  17749. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  17750. if (begin !== undefined) {
  17751. begin |= 0;
  17752. }
  17753. if (end !== undefined) {
  17754. end |= 0;
  17755. }
  17756. var owner = list.__ownerID || new OwnerID();
  17757. var oldOrigin = list._origin;
  17758. var oldCapacity = list._capacity;
  17759. var newOrigin = oldOrigin + begin;
  17760. var newCapacity =
  17761. end === undefined
  17762. ? oldCapacity
  17763. : end < 0
  17764. ? oldCapacity + end
  17765. : oldOrigin + end;
  17766. if (newOrigin === oldOrigin && newCapacity === oldCapacity) {
  17767. return list;
  17768. }
  17769. // If it's going to end after it starts, it's empty.
  17770. if (newOrigin >= newCapacity) {
  17771. return list.clear();
  17772. }
  17773. var newLevel = list._level;
  17774. var newRoot = list._root;
  17775. // New origin might need creating a higher root.
  17776. var offsetShift = 0;
  17777. while (newOrigin + offsetShift < 0) {
  17778. newRoot = new VNode(
  17779. newRoot && newRoot.array.length ? [undefined, newRoot] : [],
  17780. owner
  17781. );
  17782. newLevel += SHIFT;
  17783. offsetShift += 1 << newLevel;
  17784. }
  17785. if (offsetShift) {
  17786. newOrigin += offsetShift;
  17787. oldOrigin += offsetShift;
  17788. newCapacity += offsetShift;
  17789. oldCapacity += offsetShift;
  17790. }
  17791. var oldTailOffset = getTailOffset(oldCapacity);
  17792. var newTailOffset = getTailOffset(newCapacity);
  17793. // New size might need creating a higher root.
  17794. while (newTailOffset >= 1 << (newLevel + SHIFT)) {
  17795. newRoot = new VNode(
  17796. newRoot && newRoot.array.length ? [newRoot] : [],
  17797. owner
  17798. );
  17799. newLevel += SHIFT;
  17800. }
  17801. // Locate or create the new tail.
  17802. var oldTail = list._tail;
  17803. var newTail =
  17804. newTailOffset < oldTailOffset
  17805. ? listNodeFor(list, newCapacity - 1)
  17806. : newTailOffset > oldTailOffset
  17807. ? new VNode([], owner)
  17808. : oldTail;
  17809. // Merge Tail into tree.
  17810. if (
  17811. oldTail &&
  17812. newTailOffset > oldTailOffset &&
  17813. newOrigin < oldCapacity &&
  17814. oldTail.array.length
  17815. ) {
  17816. newRoot = editableVNode(newRoot, owner);
  17817. var node = newRoot;
  17818. for (var level = newLevel; level > SHIFT; level -= SHIFT) {
  17819. var idx = (oldTailOffset >>> level) & MASK;
  17820. node = node.array[idx] = editableVNode(node.array[idx], owner);
  17821. }
  17822. node.array[(oldTailOffset >>> SHIFT) & MASK] = oldTail;
  17823. }
  17824. // If the size has been reduced, there's a chance the tail needs to be trimmed.
  17825. if (newCapacity < oldCapacity) {
  17826. newTail = newTail && newTail.removeAfter(owner, 0, newCapacity);
  17827. }
  17828. // If the new origin is within the tail, then we do not need a root.
  17829. if (newOrigin >= newTailOffset) {
  17830. newOrigin -= newTailOffset;
  17831. newCapacity -= newTailOffset;
  17832. newLevel = SHIFT;
  17833. newRoot = null;
  17834. newTail = newTail && newTail.removeBefore(owner, 0, newOrigin);
  17835. // Otherwise, if the root has been trimmed, garbage collect.
  17836. } else if (newOrigin > oldOrigin || newTailOffset < oldTailOffset) {
  17837. offsetShift = 0;
  17838. // Identify the new top root node of the subtree of the old root.
  17839. while (newRoot) {
  17840. var beginIndex = (newOrigin >>> newLevel) & MASK;
  17841. if ((beginIndex !== newTailOffset >>> newLevel) & MASK) {
  17842. break;
  17843. }
  17844. if (beginIndex) {
  17845. offsetShift += (1 << newLevel) * beginIndex;
  17846. }
  17847. newLevel -= SHIFT;
  17848. newRoot = newRoot.array[beginIndex];
  17849. }
  17850. // Trim the new sides of the new root.
  17851. if (newRoot && newOrigin > oldOrigin) {
  17852. newRoot = newRoot.removeBefore(owner, newLevel, newOrigin - offsetShift);
  17853. }
  17854. if (newRoot && newTailOffset < oldTailOffset) {
  17855. newRoot = newRoot.removeAfter(
  17856. owner,
  17857. newLevel,
  17858. newTailOffset - offsetShift
  17859. );
  17860. }
  17861. if (offsetShift) {
  17862. newOrigin -= offsetShift;
  17863. newCapacity -= offsetShift;
  17864. }
  17865. }
  17866. if (list.__ownerID) {
  17867. list.size = newCapacity - newOrigin;
  17868. list._origin = newOrigin;
  17869. list._capacity = newCapacity;
  17870. list._level = newLevel;
  17871. list._root = newRoot;
  17872. list._tail = newTail;
  17873. list.__hash = undefined;
  17874. list.__altered = true;
  17875. return list;
  17876. }
  17877. return makeList(newOrigin, newCapacity, newLevel, newRoot, newTail);
  17878. }
  17879. function getTailOffset(size) {
  17880. return size < SIZE ? 0 : ((size - 1) >>> SHIFT) << SHIFT;
  17881. }
  17882. var OrderedMap = /*@__PURE__*/(function (Map$$1) {
  17883. function OrderedMap(value) {
  17884. return value === null || value === undefined
  17885. ? emptyOrderedMap()
  17886. : isOrderedMap(value)
  17887. ? value
  17888. : emptyOrderedMap().withMutations(function (map) {
  17889. var iter = KeyedCollection(value);
  17890. assertNotInfinite(iter.size);
  17891. iter.forEach(function (v, k) { return map.set(k, v); });
  17892. });
  17893. }
  17894. if ( Map$$1 ) OrderedMap.__proto__ = Map$$1;
  17895. OrderedMap.prototype = Object.create( Map$$1 && Map$$1.prototype );
  17896. OrderedMap.prototype.constructor = OrderedMap;
  17897. OrderedMap.of = function of (/*...values*/) {
  17898. return this(arguments);
  17899. };
  17900. OrderedMap.prototype.toString = function toString () {
  17901. return this.__toString('OrderedMap {', '}');
  17902. };
  17903. // @pragma Access
  17904. OrderedMap.prototype.get = function get (k, notSetValue) {
  17905. var index = this._map.get(k);
  17906. return index !== undefined ? this._list.get(index)[1] : notSetValue;
  17907. };
  17908. // @pragma Modification
  17909. OrderedMap.prototype.clear = function clear () {
  17910. if (this.size === 0) {
  17911. return this;
  17912. }
  17913. if (this.__ownerID) {
  17914. this.size = 0;
  17915. this._map.clear();
  17916. this._list.clear();
  17917. return this;
  17918. }
  17919. return emptyOrderedMap();
  17920. };
  17921. OrderedMap.prototype.set = function set (k, v) {
  17922. return updateOrderedMap(this, k, v);
  17923. };
  17924. OrderedMap.prototype.remove = function remove (k) {
  17925. return updateOrderedMap(this, k, NOT_SET);
  17926. };
  17927. OrderedMap.prototype.wasAltered = function wasAltered () {
  17928. return this._map.wasAltered() || this._list.wasAltered();
  17929. };
  17930. OrderedMap.prototype.__iterate = function __iterate (fn, reverse) {
  17931. var this$1 = this;
  17932. return this._list.__iterate(
  17933. function (entry) { return entry && fn(entry[1], entry[0], this$1); },
  17934. reverse
  17935. );
  17936. };
  17937. OrderedMap.prototype.__iterator = function __iterator (type, reverse) {
  17938. return this._list.fromEntrySeq().__iterator(type, reverse);
  17939. };
  17940. OrderedMap.prototype.__ensureOwner = function __ensureOwner (ownerID) {
  17941. if (ownerID === this.__ownerID) {
  17942. return this;
  17943. }
  17944. var newMap = this._map.__ensureOwner(ownerID);
  17945. var newList = this._list.__ensureOwner(ownerID);
  17946. if (!ownerID) {
  17947. if (this.size === 0) {
  17948. return emptyOrderedMap();
  17949. }
  17950. this.__ownerID = ownerID;
  17951. this._map = newMap;
  17952. this._list = newList;
  17953. return this;
  17954. }
  17955. return makeOrderedMap(newMap, newList, ownerID, this.__hash);
  17956. };
  17957. return OrderedMap;
  17958. }(Map));
  17959. OrderedMap.isOrderedMap = isOrderedMap;
  17960. OrderedMap.prototype[IS_ORDERED_SYMBOL] = true;
  17961. OrderedMap.prototype[DELETE] = OrderedMap.prototype.remove;
  17962. function makeOrderedMap(map, list, ownerID, hash) {
  17963. var omap = Object.create(OrderedMap.prototype);
  17964. omap.size = map ? map.size : 0;
  17965. omap._map = map;
  17966. omap._list = list;
  17967. omap.__ownerID = ownerID;
  17968. omap.__hash = hash;
  17969. return omap;
  17970. }
  17971. var EMPTY_ORDERED_MAP;
  17972. function emptyOrderedMap() {
  17973. return (
  17974. EMPTY_ORDERED_MAP ||
  17975. (EMPTY_ORDERED_MAP = makeOrderedMap(emptyMap(), emptyList()))
  17976. );
  17977. }
  17978. function updateOrderedMap(omap, k, v) {
  17979. var map = omap._map;
  17980. var list = omap._list;
  17981. var i = map.get(k);
  17982. var has = i !== undefined;
  17983. var newMap;
  17984. var newList;
  17985. if (v === NOT_SET) {
  17986. // removed
  17987. if (!has) {
  17988. return omap;
  17989. }
  17990. if (list.size >= SIZE && list.size >= map.size * 2) {
  17991. newList = list.filter(function (entry, idx) { return entry !== undefined && i !== idx; });
  17992. newMap = newList
  17993. .toKeyedSeq()
  17994. .map(function (entry) { return entry[0]; })
  17995. .flip()
  17996. .toMap();
  17997. if (omap.__ownerID) {
  17998. newMap.__ownerID = newList.__ownerID = omap.__ownerID;
  17999. }
  18000. } else {
  18001. newMap = map.remove(k);
  18002. newList = i === list.size - 1 ? list.pop() : list.set(i, undefined);
  18003. }
  18004. } else if (has) {
  18005. if (v === list.get(i)[1]) {
  18006. return omap;
  18007. }
  18008. newMap = map;
  18009. newList = list.set(i, [k, v]);
  18010. } else {
  18011. newMap = map.set(k, list.size);
  18012. newList = list.set(list.size, [k, v]);
  18013. }
  18014. if (omap.__ownerID) {
  18015. omap.size = newMap.size;
  18016. omap._map = newMap;
  18017. omap._list = newList;
  18018. omap.__hash = undefined;
  18019. return omap;
  18020. }
  18021. return makeOrderedMap(newMap, newList);
  18022. }
  18023. var IS_STACK_SYMBOL = '@@__IMMUTABLE_STACK__@@';
  18024. function isStack(maybeStack) {
  18025. return Boolean(maybeStack && maybeStack[IS_STACK_SYMBOL]);
  18026. }
  18027. var Stack = /*@__PURE__*/(function (IndexedCollection$$1) {
  18028. function Stack(value) {
  18029. return value === null || value === undefined
  18030. ? emptyStack()
  18031. : isStack(value)
  18032. ? value
  18033. : emptyStack().pushAll(value);
  18034. }
  18035. if ( IndexedCollection$$1 ) Stack.__proto__ = IndexedCollection$$1;
  18036. Stack.prototype = Object.create( IndexedCollection$$1 && IndexedCollection$$1.prototype );
  18037. Stack.prototype.constructor = Stack;
  18038. Stack.of = function of (/*...values*/) {
  18039. return this(arguments);
  18040. };
  18041. Stack.prototype.toString = function toString () {
  18042. return this.__toString('Stack [', ']');
  18043. };
  18044. // @pragma Access
  18045. Stack.prototype.get = function get (index, notSetValue) {
  18046. var head = this._head;
  18047. index = wrapIndex(this, index);
  18048. while (head && index--) {
  18049. head = head.next;
  18050. }
  18051. return head ? head.value : notSetValue;
  18052. };
  18053. Stack.prototype.peek = function peek () {
  18054. return this._head && this._head.value;
  18055. };
  18056. // @pragma Modification
  18057. Stack.prototype.push = function push (/*...values*/) {
  18058. var arguments$1 = arguments;
  18059. if (arguments.length === 0) {
  18060. return this;
  18061. }
  18062. var newSize = this.size + arguments.length;
  18063. var head = this._head;
  18064. for (var ii = arguments.length - 1; ii >= 0; ii--) {
  18065. head = {
  18066. value: arguments$1[ii],
  18067. next: head,
  18068. };
  18069. }
  18070. if (this.__ownerID) {
  18071. this.size = newSize;
  18072. this._head = head;
  18073. this.__hash = undefined;
  18074. this.__altered = true;
  18075. return this;
  18076. }
  18077. return makeStack(newSize, head);
  18078. };
  18079. Stack.prototype.pushAll = function pushAll (iter) {
  18080. iter = IndexedCollection$$1(iter);
  18081. if (iter.size === 0) {
  18082. return this;
  18083. }
  18084. if (this.size === 0 && isStack(iter)) {
  18085. return iter;
  18086. }
  18087. assertNotInfinite(iter.size);
  18088. var newSize = this.size;
  18089. var head = this._head;
  18090. iter.__iterate(function (value) {
  18091. newSize++;
  18092. head = {
  18093. value: value,
  18094. next: head,
  18095. };
  18096. }, /* reverse */ true);
  18097. if (this.__ownerID) {
  18098. this.size = newSize;
  18099. this._head = head;
  18100. this.__hash = undefined;
  18101. this.__altered = true;
  18102. return this;
  18103. }
  18104. return makeStack(newSize, head);
  18105. };
  18106. Stack.prototype.pop = function pop () {
  18107. return this.slice(1);
  18108. };
  18109. Stack.prototype.clear = function clear () {
  18110. if (this.size === 0) {
  18111. return this;
  18112. }
  18113. if (this.__ownerID) {
  18114. this.size = 0;
  18115. this._head = undefined;
  18116. this.__hash = undefined;
  18117. this.__altered = true;
  18118. return this;
  18119. }
  18120. return emptyStack();
  18121. };
  18122. Stack.prototype.slice = function slice (begin, end) {
  18123. if (wholeSlice(begin, end, this.size)) {
  18124. return this;
  18125. }
  18126. var resolvedBegin = resolveBegin(begin, this.size);
  18127. var resolvedEnd = resolveEnd(end, this.size);
  18128. if (resolvedEnd !== this.size) {
  18129. // super.slice(begin, end);
  18130. return IndexedCollection$$1.prototype.slice.call(this, begin, end);
  18131. }
  18132. var newSize = this.size - resolvedBegin;
  18133. var head = this._head;
  18134. while (resolvedBegin--) {
  18135. head = head.next;
  18136. }
  18137. if (this.__ownerID) {
  18138. this.size = newSize;
  18139. this._head = head;
  18140. this.__hash = undefined;
  18141. this.__altered = true;
  18142. return this;
  18143. }
  18144. return makeStack(newSize, head);
  18145. };
  18146. // @pragma Mutability
  18147. Stack.prototype.__ensureOwner = function __ensureOwner (ownerID) {
  18148. if (ownerID === this.__ownerID) {
  18149. return this;
  18150. }
  18151. if (!ownerID) {
  18152. if (this.size === 0) {
  18153. return emptyStack();
  18154. }
  18155. this.__ownerID = ownerID;
  18156. this.__altered = false;
  18157. return this;
  18158. }
  18159. return makeStack(this.size, this._head, ownerID, this.__hash);
  18160. };
  18161. // @pragma Iteration
  18162. Stack.prototype.__iterate = function __iterate (fn, reverse) {
  18163. var this$1 = this;
  18164. if (reverse) {
  18165. return new ArraySeq(this.toArray()).__iterate(
  18166. function (v, k) { return fn(v, k, this$1); },
  18167. reverse
  18168. );
  18169. }
  18170. var iterations = 0;
  18171. var node = this._head;
  18172. while (node) {
  18173. if (fn(node.value, iterations++, this) === false) {
  18174. break;
  18175. }
  18176. node = node.next;
  18177. }
  18178. return iterations;
  18179. };
  18180. Stack.prototype.__iterator = function __iterator (type, reverse) {
  18181. if (reverse) {
  18182. return new ArraySeq(this.toArray()).__iterator(type, reverse);
  18183. }
  18184. var iterations = 0;
  18185. var node = this._head;
  18186. return new Iterator(function () {
  18187. if (node) {
  18188. var value = node.value;
  18189. node = node.next;
  18190. return iteratorValue(type, iterations++, value);
  18191. }
  18192. return iteratorDone();
  18193. });
  18194. };
  18195. return Stack;
  18196. }(IndexedCollection));
  18197. Stack.isStack = isStack;
  18198. var StackPrototype = Stack.prototype;
  18199. StackPrototype[IS_STACK_SYMBOL] = true;
  18200. StackPrototype.shift = StackPrototype.pop;
  18201. StackPrototype.unshift = StackPrototype.push;
  18202. StackPrototype.unshiftAll = StackPrototype.pushAll;
  18203. StackPrototype.withMutations = withMutations;
  18204. StackPrototype.wasAltered = wasAltered;
  18205. StackPrototype.asImmutable = asImmutable;
  18206. StackPrototype['@@transducer/init'] = StackPrototype.asMutable = asMutable;
  18207. StackPrototype['@@transducer/step'] = function(result, arr) {
  18208. return result.unshift(arr);
  18209. };
  18210. StackPrototype['@@transducer/result'] = function(obj) {
  18211. return obj.asImmutable();
  18212. };
  18213. function makeStack(size, head, ownerID, hash) {
  18214. var map = Object.create(StackPrototype);
  18215. map.size = size;
  18216. map._head = head;
  18217. map.__ownerID = ownerID;
  18218. map.__hash = hash;
  18219. map.__altered = false;
  18220. return map;
  18221. }
  18222. var EMPTY_STACK;
  18223. function emptyStack() {
  18224. return EMPTY_STACK || (EMPTY_STACK = makeStack(0));
  18225. }
  18226. var IS_SET_SYMBOL = '@@__IMMUTABLE_SET__@@';
  18227. function isSet(maybeSet) {
  18228. return Boolean(maybeSet && maybeSet[IS_SET_SYMBOL]);
  18229. }
  18230. function isOrderedSet(maybeOrderedSet) {
  18231. return isSet(maybeOrderedSet) && isOrdered(maybeOrderedSet);
  18232. }
  18233. function deepEqual(a, b) {
  18234. if (a === b) {
  18235. return true;
  18236. }
  18237. if (
  18238. !isCollection(b) ||
  18239. (a.size !== undefined && b.size !== undefined && a.size !== b.size) ||
  18240. (a.__hash !== undefined &&
  18241. b.__hash !== undefined &&
  18242. a.__hash !== b.__hash) ||
  18243. isKeyed(a) !== isKeyed(b) ||
  18244. isIndexed(a) !== isIndexed(b) ||
  18245. isOrdered(a) !== isOrdered(b)
  18246. ) {
  18247. return false;
  18248. }
  18249. if (a.size === 0 && b.size === 0) {
  18250. return true;
  18251. }
  18252. var notAssociative = !isAssociative(a);
  18253. if (isOrdered(a)) {
  18254. var entries = a.entries();
  18255. return (
  18256. b.every(function (v, k) {
  18257. var entry = entries.next().value;
  18258. return entry && is(entry[1], v) && (notAssociative || is(entry[0], k));
  18259. }) && entries.next().done
  18260. );
  18261. }
  18262. var flipped = false;
  18263. if (a.size === undefined) {
  18264. if (b.size === undefined) {
  18265. if (typeof a.cacheResult === 'function') {
  18266. a.cacheResult();
  18267. }
  18268. } else {
  18269. flipped = true;
  18270. var _ = a;
  18271. a = b;
  18272. b = _;
  18273. }
  18274. }
  18275. var allEqual = true;
  18276. var bSize = b.__iterate(function (v, k) {
  18277. if (
  18278. notAssociative
  18279. ? !a.has(v)
  18280. : flipped
  18281. ? !is(v, a.get(k, NOT_SET))
  18282. : !is(a.get(k, NOT_SET), v)
  18283. ) {
  18284. allEqual = false;
  18285. return false;
  18286. }
  18287. });
  18288. return allEqual && a.size === bSize;
  18289. }
  18290. /**
  18291. * Contributes additional methods to a constructor
  18292. */
  18293. function mixin(ctor, methods) {
  18294. var keyCopier = function (key) {
  18295. ctor.prototype[key] = methods[key];
  18296. };
  18297. Object.keys(methods).forEach(keyCopier);
  18298. Object.getOwnPropertySymbols &&
  18299. Object.getOwnPropertySymbols(methods).forEach(keyCopier);
  18300. return ctor;
  18301. }
  18302. function toJS(value) {
  18303. if (!value || typeof value !== 'object') {
  18304. return value;
  18305. }
  18306. if (!isCollection(value)) {
  18307. if (!isDataStructure(value)) {
  18308. return value;
  18309. }
  18310. value = Seq(value);
  18311. }
  18312. if (isKeyed(value)) {
  18313. var result$1 = {};
  18314. value.__iterate(function (v, k) {
  18315. result$1[k] = toJS(v);
  18316. });
  18317. return result$1;
  18318. }
  18319. var result = [];
  18320. value.__iterate(function (v) {
  18321. result.push(toJS(v));
  18322. });
  18323. return result;
  18324. }
  18325. var Set = /*@__PURE__*/(function (SetCollection$$1) {
  18326. function Set(value) {
  18327. return value === null || value === undefined
  18328. ? emptySet()
  18329. : isSet(value) && !isOrdered(value)
  18330. ? value
  18331. : emptySet().withMutations(function (set) {
  18332. var iter = SetCollection$$1(value);
  18333. assertNotInfinite(iter.size);
  18334. iter.forEach(function (v) { return set.add(v); });
  18335. });
  18336. }
  18337. if ( SetCollection$$1 ) Set.__proto__ = SetCollection$$1;
  18338. Set.prototype = Object.create( SetCollection$$1 && SetCollection$$1.prototype );
  18339. Set.prototype.constructor = Set;
  18340. Set.of = function of (/*...values*/) {
  18341. return this(arguments);
  18342. };
  18343. Set.fromKeys = function fromKeys (value) {
  18344. return this(KeyedCollection(value).keySeq());
  18345. };
  18346. Set.intersect = function intersect (sets) {
  18347. sets = Collection(sets).toArray();
  18348. return sets.length
  18349. ? SetPrototype.intersect.apply(Set(sets.pop()), sets)
  18350. : emptySet();
  18351. };
  18352. Set.union = function union (sets) {
  18353. sets = Collection(sets).toArray();
  18354. return sets.length
  18355. ? SetPrototype.union.apply(Set(sets.pop()), sets)
  18356. : emptySet();
  18357. };
  18358. Set.prototype.toString = function toString () {
  18359. return this.__toString('Set {', '}');
  18360. };
  18361. // @pragma Access
  18362. Set.prototype.has = function has (value) {
  18363. return this._map.has(value);
  18364. };
  18365. // @pragma Modification
  18366. Set.prototype.add = function add (value) {
  18367. return updateSet(this, this._map.set(value, value));
  18368. };
  18369. Set.prototype.remove = function remove (value) {
  18370. return updateSet(this, this._map.remove(value));
  18371. };
  18372. Set.prototype.clear = function clear () {
  18373. return updateSet(this, this._map.clear());
  18374. };
  18375. // @pragma Composition
  18376. Set.prototype.map = function map (mapper, context) {
  18377. var this$1 = this;
  18378. var removes = [];
  18379. var adds = [];
  18380. this.forEach(function (value) {
  18381. var mapped = mapper.call(context, value, value, this$1);
  18382. if (mapped !== value) {
  18383. removes.push(value);
  18384. adds.push(mapped);
  18385. }
  18386. });
  18387. return this.withMutations(function (set) {
  18388. removes.forEach(function (value) { return set.remove(value); });
  18389. adds.forEach(function (value) { return set.add(value); });
  18390. });
  18391. };
  18392. Set.prototype.union = function union () {
  18393. var iters = [], len = arguments.length;
  18394. while ( len-- ) iters[ len ] = arguments[ len ];
  18395. iters = iters.filter(function (x) { return x.size !== 0; });
  18396. if (iters.length === 0) {
  18397. return this;
  18398. }
  18399. if (this.size === 0 && !this.__ownerID && iters.length === 1) {
  18400. return this.constructor(iters[0]);
  18401. }
  18402. return this.withMutations(function (set) {
  18403. for (var ii = 0; ii < iters.length; ii++) {
  18404. SetCollection$$1(iters[ii]).forEach(function (value) { return set.add(value); });
  18405. }
  18406. });
  18407. };
  18408. Set.prototype.intersect = function intersect () {
  18409. var iters = [], len = arguments.length;
  18410. while ( len-- ) iters[ len ] = arguments[ len ];
  18411. if (iters.length === 0) {
  18412. return this;
  18413. }
  18414. iters = iters.map(function (iter) { return SetCollection$$1(iter); });
  18415. var toRemove = [];
  18416. this.forEach(function (value) {
  18417. if (!iters.every(function (iter) { return iter.includes(value); })) {
  18418. toRemove.push(value);
  18419. }
  18420. });
  18421. return this.withMutations(function (set) {
  18422. toRemove.forEach(function (value) {
  18423. set.remove(value);
  18424. });
  18425. });
  18426. };
  18427. Set.prototype.subtract = function subtract () {
  18428. var iters = [], len = arguments.length;
  18429. while ( len-- ) iters[ len ] = arguments[ len ];
  18430. if (iters.length === 0) {
  18431. return this;
  18432. }
  18433. iters = iters.map(function (iter) { return SetCollection$$1(iter); });
  18434. var toRemove = [];
  18435. this.forEach(function (value) {
  18436. if (iters.some(function (iter) { return iter.includes(value); })) {
  18437. toRemove.push(value);
  18438. }
  18439. });
  18440. return this.withMutations(function (set) {
  18441. toRemove.forEach(function (value) {
  18442. set.remove(value);
  18443. });
  18444. });
  18445. };
  18446. Set.prototype.sort = function sort (comparator) {
  18447. // Late binding
  18448. return OrderedSet(sortFactory(this, comparator));
  18449. };
  18450. Set.prototype.sortBy = function sortBy (mapper, comparator) {
  18451. // Late binding
  18452. return OrderedSet(sortFactory(this, comparator, mapper));
  18453. };
  18454. Set.prototype.wasAltered = function wasAltered () {
  18455. return this._map.wasAltered();
  18456. };
  18457. Set.prototype.__iterate = function __iterate (fn, reverse) {
  18458. var this$1 = this;
  18459. return this._map.__iterate(function (k) { return fn(k, k, this$1); }, reverse);
  18460. };
  18461. Set.prototype.__iterator = function __iterator (type, reverse) {
  18462. return this._map.__iterator(type, reverse);
  18463. };
  18464. Set.prototype.__ensureOwner = function __ensureOwner (ownerID) {
  18465. if (ownerID === this.__ownerID) {
  18466. return this;
  18467. }
  18468. var newMap = this._map.__ensureOwner(ownerID);
  18469. if (!ownerID) {
  18470. if (this.size === 0) {
  18471. return this.__empty();
  18472. }
  18473. this.__ownerID = ownerID;
  18474. this._map = newMap;
  18475. return this;
  18476. }
  18477. return this.__make(newMap, ownerID);
  18478. };
  18479. return Set;
  18480. }(SetCollection));
  18481. Set.isSet = isSet;
  18482. var SetPrototype = Set.prototype;
  18483. SetPrototype[IS_SET_SYMBOL] = true;
  18484. SetPrototype[DELETE] = SetPrototype.remove;
  18485. SetPrototype.merge = SetPrototype.concat = SetPrototype.union;
  18486. SetPrototype.withMutations = withMutations;
  18487. SetPrototype.asImmutable = asImmutable;
  18488. SetPrototype['@@transducer/init'] = SetPrototype.asMutable = asMutable;
  18489. SetPrototype['@@transducer/step'] = function(result, arr) {
  18490. return result.add(arr);
  18491. };
  18492. SetPrototype['@@transducer/result'] = function(obj) {
  18493. return obj.asImmutable();
  18494. };
  18495. SetPrototype.__empty = emptySet;
  18496. SetPrototype.__make = makeSet;
  18497. function updateSet(set, newMap) {
  18498. if (set.__ownerID) {
  18499. set.size = newMap.size;
  18500. set._map = newMap;
  18501. return set;
  18502. }
  18503. return newMap === set._map
  18504. ? set
  18505. : newMap.size === 0
  18506. ? set.__empty()
  18507. : set.__make(newMap);
  18508. }
  18509. function makeSet(map, ownerID) {
  18510. var set = Object.create(SetPrototype);
  18511. set.size = map ? map.size : 0;
  18512. set._map = map;
  18513. set.__ownerID = ownerID;
  18514. return set;
  18515. }
  18516. var EMPTY_SET;
  18517. function emptySet() {
  18518. return EMPTY_SET || (EMPTY_SET = makeSet(emptyMap()));
  18519. }
  18520. /**
  18521. * Returns a lazy seq of nums from start (inclusive) to end
  18522. * (exclusive), by step, where start defaults to 0, step to 1, and end to
  18523. * infinity. When start is equal to end, returns empty list.
  18524. */
  18525. var Range = /*@__PURE__*/(function (IndexedSeq$$1) {
  18526. function Range(start, end, step) {
  18527. if (!(this instanceof Range)) {
  18528. return new Range(start, end, step);
  18529. }
  18530. invariant(step !== 0, 'Cannot step a Range by 0');
  18531. start = start || 0;
  18532. if (end === undefined) {
  18533. end = Infinity;
  18534. }
  18535. step = step === undefined ? 1 : Math.abs(step);
  18536. if (end < start) {
  18537. step = -step;
  18538. }
  18539. this._start = start;
  18540. this._end = end;
  18541. this._step = step;
  18542. this.size = Math.max(0, Math.ceil((end - start) / step - 1) + 1);
  18543. if (this.size === 0) {
  18544. if (EMPTY_RANGE) {
  18545. return EMPTY_RANGE;
  18546. }
  18547. EMPTY_RANGE = this;
  18548. }
  18549. }
  18550. if ( IndexedSeq$$1 ) Range.__proto__ = IndexedSeq$$1;
  18551. Range.prototype = Object.create( IndexedSeq$$1 && IndexedSeq$$1.prototype );
  18552. Range.prototype.constructor = Range;
  18553. Range.prototype.toString = function toString () {
  18554. if (this.size === 0) {
  18555. return 'Range []';
  18556. }
  18557. return (
  18558. 'Range [ ' +
  18559. this._start +
  18560. '...' +
  18561. this._end +
  18562. (this._step !== 1 ? ' by ' + this._step : '') +
  18563. ' ]'
  18564. );
  18565. };
  18566. Range.prototype.get = function get (index, notSetValue) {
  18567. return this.has(index)
  18568. ? this._start + wrapIndex(this, index) * this._step
  18569. : notSetValue;
  18570. };
  18571. Range.prototype.includes = function includes (searchValue) {
  18572. var possibleIndex = (searchValue - this._start) / this._step;
  18573. return (
  18574. possibleIndex >= 0 &&
  18575. possibleIndex < this.size &&
  18576. possibleIndex === Math.floor(possibleIndex)
  18577. );
  18578. };
  18579. Range.prototype.slice = function slice (begin, end) {
  18580. if (wholeSlice(begin, end, this.size)) {
  18581. return this;
  18582. }
  18583. begin = resolveBegin(begin, this.size);
  18584. end = resolveEnd(end, this.size);
  18585. if (end <= begin) {
  18586. return new Range(0, 0);
  18587. }
  18588. return new Range(
  18589. this.get(begin, this._end),
  18590. this.get(end, this._end),
  18591. this._step
  18592. );
  18593. };
  18594. Range.prototype.indexOf = function indexOf (searchValue) {
  18595. var offsetValue = searchValue - this._start;
  18596. if (offsetValue % this._step === 0) {
  18597. var index = offsetValue / this._step;
  18598. if (index >= 0 && index < this.size) {
  18599. return index;
  18600. }
  18601. }
  18602. return -1;
  18603. };
  18604. Range.prototype.lastIndexOf = function lastIndexOf (searchValue) {
  18605. return this.indexOf(searchValue);
  18606. };
  18607. Range.prototype.__iterate = function __iterate (fn, reverse) {
  18608. var size = this.size;
  18609. var step = this._step;
  18610. var value = reverse ? this._start + (size - 1) * step : this._start;
  18611. var i = 0;
  18612. while (i !== size) {
  18613. if (fn(value, reverse ? size - ++i : i++, this) === false) {
  18614. break;
  18615. }
  18616. value += reverse ? -step : step;
  18617. }
  18618. return i;
  18619. };
  18620. Range.prototype.__iterator = function __iterator (type, reverse) {
  18621. var size = this.size;
  18622. var step = this._step;
  18623. var value = reverse ? this._start + (size - 1) * step : this._start;
  18624. var i = 0;
  18625. return new Iterator(function () {
  18626. if (i === size) {
  18627. return iteratorDone();
  18628. }
  18629. var v = value;
  18630. value += reverse ? -step : step;
  18631. return iteratorValue(type, reverse ? size - ++i : i++, v);
  18632. });
  18633. };
  18634. Range.prototype.equals = function equals (other) {
  18635. return other instanceof Range
  18636. ? this._start === other._start &&
  18637. this._end === other._end &&
  18638. this._step === other._step
  18639. : deepEqual(this, other);
  18640. };
  18641. return Range;
  18642. }(IndexedSeq));
  18643. var EMPTY_RANGE;
  18644. function getIn(collection, searchKeyPath, notSetValue) {
  18645. var keyPath = coerceKeyPath(searchKeyPath);
  18646. var i = 0;
  18647. while (i !== keyPath.length) {
  18648. collection = get(collection, keyPath[i++], NOT_SET);
  18649. if (collection === NOT_SET) {
  18650. return notSetValue;
  18651. }
  18652. }
  18653. return collection;
  18654. }
  18655. function getIn$1(searchKeyPath, notSetValue) {
  18656. return getIn(this, searchKeyPath, notSetValue);
  18657. }
  18658. function hasIn(collection, keyPath) {
  18659. return getIn(collection, keyPath, NOT_SET) !== NOT_SET;
  18660. }
  18661. function hasIn$1(searchKeyPath) {
  18662. return hasIn(this, searchKeyPath);
  18663. }
  18664. function toObject() {
  18665. assertNotInfinite(this.size);
  18666. var object = {};
  18667. this.__iterate(function (v, k) {
  18668. object[k] = v;
  18669. });
  18670. return object;
  18671. }
  18672. // Note: all of these methods are deprecated.
  18673. Collection.isIterable = isCollection;
  18674. Collection.isKeyed = isKeyed;
  18675. Collection.isIndexed = isIndexed;
  18676. Collection.isAssociative = isAssociative;
  18677. Collection.isOrdered = isOrdered;
  18678. Collection.Iterator = Iterator;
  18679. mixin(Collection, {
  18680. // ### Conversion to other types
  18681. toArray: function toArray() {
  18682. assertNotInfinite(this.size);
  18683. var array = new Array(this.size || 0);
  18684. var useTuples = isKeyed(this);
  18685. var i = 0;
  18686. this.__iterate(function (v, k) {
  18687. // Keyed collections produce an array of tuples.
  18688. array[i++] = useTuples ? [k, v] : v;
  18689. });
  18690. return array;
  18691. },
  18692. toIndexedSeq: function toIndexedSeq() {
  18693. return new ToIndexedSequence(this);
  18694. },
  18695. toJS: function toJS$1() {
  18696. return toJS(this);
  18697. },
  18698. toKeyedSeq: function toKeyedSeq() {
  18699. return new ToKeyedSequence(this, true);
  18700. },
  18701. toMap: function toMap() {
  18702. // Use Late Binding here to solve the circular dependency.
  18703. return Map(this.toKeyedSeq());
  18704. },
  18705. toObject: toObject,
  18706. toOrderedMap: function toOrderedMap() {
  18707. // Use Late Binding here to solve the circular dependency.
  18708. return OrderedMap(this.toKeyedSeq());
  18709. },
  18710. toOrderedSet: function toOrderedSet() {
  18711. // Use Late Binding here to solve the circular dependency.
  18712. return OrderedSet(isKeyed(this) ? this.valueSeq() : this);
  18713. },
  18714. toSet: function toSet() {
  18715. // Use Late Binding here to solve the circular dependency.
  18716. return Set(isKeyed(this) ? this.valueSeq() : this);
  18717. },
  18718. toSetSeq: function toSetSeq() {
  18719. return new ToSetSequence(this);
  18720. },
  18721. toSeq: function toSeq() {
  18722. return isIndexed(this)
  18723. ? this.toIndexedSeq()
  18724. : isKeyed(this)
  18725. ? this.toKeyedSeq()
  18726. : this.toSetSeq();
  18727. },
  18728. toStack: function toStack() {
  18729. // Use Late Binding here to solve the circular dependency.
  18730. return Stack(isKeyed(this) ? this.valueSeq() : this);
  18731. },
  18732. toList: function toList() {
  18733. // Use Late Binding here to solve the circular dependency.
  18734. return List(isKeyed(this) ? this.valueSeq() : this);
  18735. },
  18736. // ### Common JavaScript methods and properties
  18737. toString: function toString() {
  18738. return '[Collection]';
  18739. },
  18740. __toString: function __toString(head, tail) {
  18741. if (this.size === 0) {
  18742. return head + tail;
  18743. }
  18744. return (
  18745. head +
  18746. ' ' +
  18747. this.toSeq()
  18748. .map(this.__toStringMapper)
  18749. .join(', ') +
  18750. ' ' +
  18751. tail
  18752. );
  18753. },
  18754. // ### ES6 Collection methods (ES6 Array and Map)
  18755. concat: function concat() {
  18756. var values = [], len = arguments.length;
  18757. while ( len-- ) values[ len ] = arguments[ len ];
  18758. return reify(this, concatFactory(this, values));
  18759. },
  18760. includes: function includes(searchValue) {
  18761. return this.some(function (value) { return is(value, searchValue); });
  18762. },
  18763. entries: function entries() {
  18764. return this.__iterator(ITERATE_ENTRIES);
  18765. },
  18766. every: function every(predicate, context) {
  18767. assertNotInfinite(this.size);
  18768. var returnValue = true;
  18769. this.__iterate(function (v, k, c) {
  18770. if (!predicate.call(context, v, k, c)) {
  18771. returnValue = false;
  18772. return false;
  18773. }
  18774. });
  18775. return returnValue;
  18776. },
  18777. filter: function filter(predicate, context) {
  18778. return reify(this, filterFactory(this, predicate, context, true));
  18779. },
  18780. find: function find(predicate, context, notSetValue) {
  18781. var entry = this.findEntry(predicate, context);
  18782. return entry ? entry[1] : notSetValue;
  18783. },
  18784. forEach: function forEach(sideEffect, context) {
  18785. assertNotInfinite(this.size);
  18786. return this.__iterate(context ? sideEffect.bind(context) : sideEffect);
  18787. },
  18788. join: function join(separator) {
  18789. assertNotInfinite(this.size);
  18790. separator = separator !== undefined ? '' + separator : ',';
  18791. var joined = '';
  18792. var isFirst = true;
  18793. this.__iterate(function (v) {
  18794. isFirst ? (isFirst = false) : (joined += separator);
  18795. joined += v !== null && v !== undefined ? v.toString() : '';
  18796. });
  18797. return joined;
  18798. },
  18799. keys: function keys() {
  18800. return this.__iterator(ITERATE_KEYS);
  18801. },
  18802. map: function map(mapper, context) {
  18803. return reify(this, mapFactory(this, mapper, context));
  18804. },
  18805. reduce: function reduce$1(reducer, initialReduction, context) {
  18806. return reduce(
  18807. this,
  18808. reducer,
  18809. initialReduction,
  18810. context,
  18811. arguments.length < 2,
  18812. false
  18813. );
  18814. },
  18815. reduceRight: function reduceRight(reducer, initialReduction, context) {
  18816. return reduce(
  18817. this,
  18818. reducer,
  18819. initialReduction,
  18820. context,
  18821. arguments.length < 2,
  18822. true
  18823. );
  18824. },
  18825. reverse: function reverse() {
  18826. return reify(this, reverseFactory(this, true));
  18827. },
  18828. slice: function slice(begin, end) {
  18829. return reify(this, sliceFactory(this, begin, end, true));
  18830. },
  18831. some: function some(predicate, context) {
  18832. return !this.every(not(predicate), context);
  18833. },
  18834. sort: function sort(comparator) {
  18835. return reify(this, sortFactory(this, comparator));
  18836. },
  18837. values: function values() {
  18838. return this.__iterator(ITERATE_VALUES);
  18839. },
  18840. // ### More sequential methods
  18841. butLast: function butLast() {
  18842. return this.slice(0, -1);
  18843. },
  18844. isEmpty: function isEmpty() {
  18845. return this.size !== undefined ? this.size === 0 : !this.some(function () { return true; });
  18846. },
  18847. count: function count(predicate, context) {
  18848. return ensureSize(
  18849. predicate ? this.toSeq().filter(predicate, context) : this
  18850. );
  18851. },
  18852. countBy: function countBy(grouper, context) {
  18853. return countByFactory(this, grouper, context);
  18854. },
  18855. equals: function equals(other) {
  18856. return deepEqual(this, other);
  18857. },
  18858. entrySeq: function entrySeq() {
  18859. var collection = this;
  18860. if (collection._cache) {
  18861. // We cache as an entries array, so we can just return the cache!
  18862. return new ArraySeq(collection._cache);
  18863. }
  18864. var entriesSequence = collection
  18865. .toSeq()
  18866. .map(entryMapper)
  18867. .toIndexedSeq();
  18868. entriesSequence.fromEntrySeq = function () { return collection.toSeq(); };
  18869. return entriesSequence;
  18870. },
  18871. filterNot: function filterNot(predicate, context) {
  18872. return this.filter(not(predicate), context);
  18873. },
  18874. findEntry: function findEntry(predicate, context, notSetValue) {
  18875. var found = notSetValue;
  18876. this.__iterate(function (v, k, c) {
  18877. if (predicate.call(context, v, k, c)) {
  18878. found = [k, v];
  18879. return false;
  18880. }
  18881. });
  18882. return found;
  18883. },
  18884. findKey: function findKey(predicate, context) {
  18885. var entry = this.findEntry(predicate, context);
  18886. return entry && entry[0];
  18887. },
  18888. findLast: function findLast(predicate, context, notSetValue) {
  18889. return this.toKeyedSeq()
  18890. .reverse()
  18891. .find(predicate, context, notSetValue);
  18892. },
  18893. findLastEntry: function findLastEntry(predicate, context, notSetValue) {
  18894. return this.toKeyedSeq()
  18895. .reverse()
  18896. .findEntry(predicate, context, notSetValue);
  18897. },
  18898. findLastKey: function findLastKey(predicate, context) {
  18899. return this.toKeyedSeq()
  18900. .reverse()
  18901. .findKey(predicate, context);
  18902. },
  18903. first: function first(notSetValue) {
  18904. return this.find(returnTrue, null, notSetValue);
  18905. },
  18906. flatMap: function flatMap(mapper, context) {
  18907. return reify(this, flatMapFactory(this, mapper, context));
  18908. },
  18909. flatten: function flatten(depth) {
  18910. return reify(this, flattenFactory(this, depth, true));
  18911. },
  18912. fromEntrySeq: function fromEntrySeq() {
  18913. return new FromEntriesSequence(this);
  18914. },
  18915. get: function get(searchKey, notSetValue) {
  18916. return this.find(function (_, key) { return is(key, searchKey); }, undefined, notSetValue);
  18917. },
  18918. getIn: getIn$1,
  18919. groupBy: function groupBy(grouper, context) {
  18920. return groupByFactory(this, grouper, context);
  18921. },
  18922. has: function has(searchKey) {
  18923. return this.get(searchKey, NOT_SET) !== NOT_SET;
  18924. },
  18925. hasIn: hasIn$1,
  18926. isSubset: function isSubset(iter) {
  18927. iter = typeof iter.includes === 'function' ? iter : Collection(iter);
  18928. return this.every(function (value) { return iter.includes(value); });
  18929. },
  18930. isSuperset: function isSuperset(iter) {
  18931. iter = typeof iter.isSubset === 'function' ? iter : Collection(iter);
  18932. return iter.isSubset(this);
  18933. },
  18934. keyOf: function keyOf(searchValue) {
  18935. return this.findKey(function (value) { return is(value, searchValue); });
  18936. },
  18937. keySeq: function keySeq() {
  18938. return this.toSeq()
  18939. .map(keyMapper)
  18940. .toIndexedSeq();
  18941. },
  18942. last: function last(notSetValue) {
  18943. return this.toSeq()
  18944. .reverse()
  18945. .first(notSetValue);
  18946. },
  18947. lastKeyOf: function lastKeyOf(searchValue) {
  18948. return this.toKeyedSeq()
  18949. .reverse()
  18950. .keyOf(searchValue);
  18951. },
  18952. max: function max(comparator) {
  18953. return maxFactory(this, comparator);
  18954. },
  18955. maxBy: function maxBy(mapper, comparator) {
  18956. return maxFactory(this, comparator, mapper);
  18957. },
  18958. min: function min(comparator) {
  18959. return maxFactory(
  18960. this,
  18961. comparator ? neg(comparator) : defaultNegComparator
  18962. );
  18963. },
  18964. minBy: function minBy(mapper, comparator) {
  18965. return maxFactory(
  18966. this,
  18967. comparator ? neg(comparator) : defaultNegComparator,
  18968. mapper
  18969. );
  18970. },
  18971. rest: function rest() {
  18972. return this.slice(1);
  18973. },
  18974. skip: function skip(amount) {
  18975. return amount === 0 ? this : this.slice(Math.max(0, amount));
  18976. },
  18977. skipLast: function skipLast(amount) {
  18978. return amount === 0 ? this : this.slice(0, -Math.max(0, amount));
  18979. },
  18980. skipWhile: function skipWhile(predicate, context) {
  18981. return reify(this, skipWhileFactory(this, predicate, context, true));
  18982. },
  18983. skipUntil: function skipUntil(predicate, context) {
  18984. return this.skipWhile(not(predicate), context);
  18985. },
  18986. sortBy: function sortBy(mapper, comparator) {
  18987. return reify(this, sortFactory(this, comparator, mapper));
  18988. },
  18989. take: function take(amount) {
  18990. return this.slice(0, Math.max(0, amount));
  18991. },
  18992. takeLast: function takeLast(amount) {
  18993. return this.slice(-Math.max(0, amount));
  18994. },
  18995. takeWhile: function takeWhile(predicate, context) {
  18996. return reify(this, takeWhileFactory(this, predicate, context));
  18997. },
  18998. takeUntil: function takeUntil(predicate, context) {
  18999. return this.takeWhile(not(predicate), context);
  19000. },
  19001. update: function update(fn) {
  19002. return fn(this);
  19003. },
  19004. valueSeq: function valueSeq() {
  19005. return this.toIndexedSeq();
  19006. },
  19007. // ### Hashable Object
  19008. hashCode: function hashCode() {
  19009. return this.__hash || (this.__hash = hashCollection(this));
  19010. },
  19011. // ### Internal
  19012. // abstract __iterate(fn, reverse)
  19013. // abstract __iterator(type, reverse)
  19014. });
  19015. var CollectionPrototype = Collection.prototype;
  19016. CollectionPrototype[IS_COLLECTION_SYMBOL] = true;
  19017. CollectionPrototype[ITERATOR_SYMBOL] = CollectionPrototype.values;
  19018. CollectionPrototype.toJSON = CollectionPrototype.toArray;
  19019. CollectionPrototype.__toStringMapper = quoteString;
  19020. CollectionPrototype.inspect = CollectionPrototype.toSource = function() {
  19021. return this.toString();
  19022. };
  19023. CollectionPrototype.chain = CollectionPrototype.flatMap;
  19024. CollectionPrototype.contains = CollectionPrototype.includes;
  19025. mixin(KeyedCollection, {
  19026. // ### More sequential methods
  19027. flip: function flip() {
  19028. return reify(this, flipFactory(this));
  19029. },
  19030. mapEntries: function mapEntries(mapper, context) {
  19031. var this$1 = this;
  19032. var iterations = 0;
  19033. return reify(
  19034. this,
  19035. this.toSeq()
  19036. .map(function (v, k) { return mapper.call(context, [k, v], iterations++, this$1); })
  19037. .fromEntrySeq()
  19038. );
  19039. },
  19040. mapKeys: function mapKeys(mapper, context) {
  19041. var this$1 = this;
  19042. return reify(
  19043. this,
  19044. this.toSeq()
  19045. .flip()
  19046. .map(function (k, v) { return mapper.call(context, k, v, this$1); })
  19047. .flip()
  19048. );
  19049. },
  19050. });
  19051. var KeyedCollectionPrototype = KeyedCollection.prototype;
  19052. KeyedCollectionPrototype[IS_KEYED_SYMBOL] = true;
  19053. KeyedCollectionPrototype[ITERATOR_SYMBOL] = CollectionPrototype.entries;
  19054. KeyedCollectionPrototype.toJSON = toObject;
  19055. KeyedCollectionPrototype.__toStringMapper = function (v, k) { return quoteString(k) + ': ' + quoteString(v); };
  19056. mixin(IndexedCollection, {
  19057. // ### Conversion to other types
  19058. toKeyedSeq: function toKeyedSeq() {
  19059. return new ToKeyedSequence(this, false);
  19060. },
  19061. // ### ES6 Collection methods (ES6 Array and Map)
  19062. filter: function filter(predicate, context) {
  19063. return reify(this, filterFactory(this, predicate, context, false));
  19064. },
  19065. findIndex: function findIndex(predicate, context) {
  19066. var entry = this.findEntry(predicate, context);
  19067. return entry ? entry[0] : -1;
  19068. },
  19069. indexOf: function indexOf(searchValue) {
  19070. var key = this.keyOf(searchValue);
  19071. return key === undefined ? -1 : key;
  19072. },
  19073. lastIndexOf: function lastIndexOf(searchValue) {
  19074. var key = this.lastKeyOf(searchValue);
  19075. return key === undefined ? -1 : key;
  19076. },
  19077. reverse: function reverse() {
  19078. return reify(this, reverseFactory(this, false));
  19079. },
  19080. slice: function slice(begin, end) {
  19081. return reify(this, sliceFactory(this, begin, end, false));
  19082. },
  19083. splice: function splice(index, removeNum /*, ...values*/) {
  19084. var numArgs = arguments.length;
  19085. removeNum = Math.max(removeNum || 0, 0);
  19086. if (numArgs === 0 || (numArgs === 2 && !removeNum)) {
  19087. return this;
  19088. }
  19089. // If index is negative, it should resolve relative to the size of the
  19090. // collection. However size may be expensive to compute if not cached, so
  19091. // only call count() if the number is in fact negative.
  19092. index = resolveBegin(index, index < 0 ? this.count() : this.size);
  19093. var spliced = this.slice(0, index);
  19094. return reify(
  19095. this,
  19096. numArgs === 1
  19097. ? spliced
  19098. : spliced.concat(arrCopy(arguments, 2), this.slice(index + removeNum))
  19099. );
  19100. },
  19101. // ### More collection methods
  19102. findLastIndex: function findLastIndex(predicate, context) {
  19103. var entry = this.findLastEntry(predicate, context);
  19104. return entry ? entry[0] : -1;
  19105. },
  19106. first: function first(notSetValue) {
  19107. return this.get(0, notSetValue);
  19108. },
  19109. flatten: function flatten(depth) {
  19110. return reify(this, flattenFactory(this, depth, false));
  19111. },
  19112. get: function get(index, notSetValue) {
  19113. index = wrapIndex(this, index);
  19114. return index < 0 ||
  19115. (this.size === Infinity || (this.size !== undefined && index > this.size))
  19116. ? notSetValue
  19117. : this.find(function (_, key) { return key === index; }, undefined, notSetValue);
  19118. },
  19119. has: function has(index) {
  19120. index = wrapIndex(this, index);
  19121. return (
  19122. index >= 0 &&
  19123. (this.size !== undefined
  19124. ? this.size === Infinity || index < this.size
  19125. : this.indexOf(index) !== -1)
  19126. );
  19127. },
  19128. interpose: function interpose(separator) {
  19129. return reify(this, interposeFactory(this, separator));
  19130. },
  19131. interleave: function interleave(/*...collections*/) {
  19132. var collections = [this].concat(arrCopy(arguments));
  19133. var zipped = zipWithFactory(this.toSeq(), IndexedSeq.of, collections);
  19134. var interleaved = zipped.flatten(true);
  19135. if (zipped.size) {
  19136. interleaved.size = zipped.size * collections.length;
  19137. }
  19138. return reify(this, interleaved);
  19139. },
  19140. keySeq: function keySeq() {
  19141. return Range(0, this.size);
  19142. },
  19143. last: function last(notSetValue) {
  19144. return this.get(-1, notSetValue);
  19145. },
  19146. skipWhile: function skipWhile(predicate, context) {
  19147. return reify(this, skipWhileFactory(this, predicate, context, false));
  19148. },
  19149. zip: function zip(/*, ...collections */) {
  19150. var collections = [this].concat(arrCopy(arguments));
  19151. return reify(this, zipWithFactory(this, defaultZipper, collections));
  19152. },
  19153. zipAll: function zipAll(/*, ...collections */) {
  19154. var collections = [this].concat(arrCopy(arguments));
  19155. return reify(this, zipWithFactory(this, defaultZipper, collections, true));
  19156. },
  19157. zipWith: function zipWith(zipper /*, ...collections */) {
  19158. var collections = arrCopy(arguments);
  19159. collections[0] = this;
  19160. return reify(this, zipWithFactory(this, zipper, collections));
  19161. },
  19162. });
  19163. var IndexedCollectionPrototype = IndexedCollection.prototype;
  19164. IndexedCollectionPrototype[IS_INDEXED_SYMBOL] = true;
  19165. IndexedCollectionPrototype[IS_ORDERED_SYMBOL] = true;
  19166. mixin(SetCollection, {
  19167. // ### ES6 Collection methods (ES6 Array and Map)
  19168. get: function get(value, notSetValue) {
  19169. return this.has(value) ? value : notSetValue;
  19170. },
  19171. includes: function includes(value) {
  19172. return this.has(value);
  19173. },
  19174. // ### More sequential methods
  19175. keySeq: function keySeq() {
  19176. return this.valueSeq();
  19177. },
  19178. });
  19179. SetCollection.prototype.has = CollectionPrototype.includes;
  19180. SetCollection.prototype.contains = SetCollection.prototype.includes;
  19181. // Mixin subclasses
  19182. mixin(KeyedSeq, KeyedCollection.prototype);
  19183. mixin(IndexedSeq, IndexedCollection.prototype);
  19184. mixin(SetSeq, SetCollection.prototype);
  19185. // #pragma Helper functions
  19186. function reduce(collection, reducer, reduction, context, useFirst, reverse) {
  19187. assertNotInfinite(collection.size);
  19188. collection.__iterate(function (v, k, c) {
  19189. if (useFirst) {
  19190. useFirst = false;
  19191. reduction = v;
  19192. } else {
  19193. reduction = reducer.call(context, reduction, v, k, c);
  19194. }
  19195. }, reverse);
  19196. return reduction;
  19197. }
  19198. function keyMapper(v, k) {
  19199. return k;
  19200. }
  19201. function entryMapper(v, k) {
  19202. return [k, v];
  19203. }
  19204. function not(predicate) {
  19205. return function() {
  19206. return !predicate.apply(this, arguments);
  19207. };
  19208. }
  19209. function neg(predicate) {
  19210. return function() {
  19211. return -predicate.apply(this, arguments);
  19212. };
  19213. }
  19214. function defaultZipper() {
  19215. return arrCopy(arguments);
  19216. }
  19217. function defaultNegComparator(a, b) {
  19218. return a < b ? 1 : a > b ? -1 : 0;
  19219. }
  19220. function hashCollection(collection) {
  19221. if (collection.size === Infinity) {
  19222. return 0;
  19223. }
  19224. var ordered = isOrdered(collection);
  19225. var keyed = isKeyed(collection);
  19226. var h = ordered ? 1 : 0;
  19227. var size = collection.__iterate(
  19228. keyed
  19229. ? ordered
  19230. ? function (v, k) {
  19231. h = (31 * h + hashMerge(hash(v), hash(k))) | 0;
  19232. }
  19233. : function (v, k) {
  19234. h = (h + hashMerge(hash(v), hash(k))) | 0;
  19235. }
  19236. : ordered
  19237. ? function (v) {
  19238. h = (31 * h + hash(v)) | 0;
  19239. }
  19240. : function (v) {
  19241. h = (h + hash(v)) | 0;
  19242. }
  19243. );
  19244. return murmurHashOfSize(size, h);
  19245. }
  19246. function murmurHashOfSize(size, h) {
  19247. h = imul(h, 0xcc9e2d51);
  19248. h = imul((h << 15) | (h >>> -15), 0x1b873593);
  19249. h = imul((h << 13) | (h >>> -13), 5);
  19250. h = ((h + 0xe6546b64) | 0) ^ size;
  19251. h = imul(h ^ (h >>> 16), 0x85ebca6b);
  19252. h = imul(h ^ (h >>> 13), 0xc2b2ae35);
  19253. h = smi(h ^ (h >>> 16));
  19254. return h;
  19255. }
  19256. function hashMerge(a, b) {
  19257. return (a ^ (b + 0x9e3779b9 + (a << 6) + (a >> 2))) | 0; // int
  19258. }
  19259. var OrderedSet = /*@__PURE__*/(function (Set$$1) {
  19260. function OrderedSet(value) {
  19261. return value === null || value === undefined
  19262. ? emptyOrderedSet()
  19263. : isOrderedSet(value)
  19264. ? value
  19265. : emptyOrderedSet().withMutations(function (set) {
  19266. var iter = SetCollection(value);
  19267. assertNotInfinite(iter.size);
  19268. iter.forEach(function (v) { return set.add(v); });
  19269. });
  19270. }
  19271. if ( Set$$1 ) OrderedSet.__proto__ = Set$$1;
  19272. OrderedSet.prototype = Object.create( Set$$1 && Set$$1.prototype );
  19273. OrderedSet.prototype.constructor = OrderedSet;
  19274. OrderedSet.of = function of (/*...values*/) {
  19275. return this(arguments);
  19276. };
  19277. OrderedSet.fromKeys = function fromKeys (value) {
  19278. return this(KeyedCollection(value).keySeq());
  19279. };
  19280. OrderedSet.prototype.toString = function toString () {
  19281. return this.__toString('OrderedSet {', '}');
  19282. };
  19283. return OrderedSet;
  19284. }(Set));
  19285. OrderedSet.isOrderedSet = isOrderedSet;
  19286. var OrderedSetPrototype = OrderedSet.prototype;
  19287. OrderedSetPrototype[IS_ORDERED_SYMBOL] = true;
  19288. OrderedSetPrototype.zip = IndexedCollectionPrototype.zip;
  19289. OrderedSetPrototype.zipWith = IndexedCollectionPrototype.zipWith;
  19290. OrderedSetPrototype.__empty = emptyOrderedSet;
  19291. OrderedSetPrototype.__make = makeOrderedSet;
  19292. function makeOrderedSet(map, ownerID) {
  19293. var set = Object.create(OrderedSetPrototype);
  19294. set.size = map ? map.size : 0;
  19295. set._map = map;
  19296. set.__ownerID = ownerID;
  19297. return set;
  19298. }
  19299. var EMPTY_ORDERED_SET;
  19300. function emptyOrderedSet() {
  19301. return (
  19302. EMPTY_ORDERED_SET || (EMPTY_ORDERED_SET = makeOrderedSet(emptyOrderedMap()))
  19303. );
  19304. }
  19305. var Record = function Record(defaultValues, name) {
  19306. var hasInitialized;
  19307. var RecordType = function Record(values) {
  19308. var this$1 = this;
  19309. if (values instanceof RecordType) {
  19310. return values;
  19311. }
  19312. if (!(this instanceof RecordType)) {
  19313. return new RecordType(values);
  19314. }
  19315. if (!hasInitialized) {
  19316. hasInitialized = true;
  19317. var keys = Object.keys(defaultValues);
  19318. var indices = (RecordTypePrototype._indices = {});
  19319. // Deprecated: left to attempt not to break any external code which
  19320. // relies on a ._name property existing on record instances.
  19321. // Use Record.getDescriptiveName() instead
  19322. RecordTypePrototype._name = name;
  19323. RecordTypePrototype._keys = keys;
  19324. RecordTypePrototype._defaultValues = defaultValues;
  19325. for (var i = 0; i < keys.length; i++) {
  19326. var propName = keys[i];
  19327. indices[propName] = i;
  19328. if (RecordTypePrototype[propName]) {
  19329. /* eslint-disable no-console */
  19330. typeof console === 'object' &&
  19331. console.warn &&
  19332. console.warn(
  19333. 'Cannot define ' +
  19334. recordName(this) +
  19335. ' with property "' +
  19336. propName +
  19337. '" since that property name is part of the Record API.'
  19338. );
  19339. /* eslint-enable no-console */
  19340. } else {
  19341. setProp(RecordTypePrototype, propName);
  19342. }
  19343. }
  19344. }
  19345. this.__ownerID = undefined;
  19346. this._values = List().withMutations(function (l) {
  19347. l.setSize(this$1._keys.length);
  19348. KeyedCollection(values).forEach(function (v, k) {
  19349. l.set(this$1._indices[k], v === this$1._defaultValues[k] ? undefined : v);
  19350. });
  19351. });
  19352. };
  19353. var RecordTypePrototype = (RecordType.prototype = Object.create(
  19354. RecordPrototype
  19355. ));
  19356. RecordTypePrototype.constructor = RecordType;
  19357. if (name) {
  19358. RecordType.displayName = name;
  19359. }
  19360. return RecordType;
  19361. };
  19362. Record.prototype.toString = function toString () {
  19363. var str = recordName(this) + ' { ';
  19364. var keys = this._keys;
  19365. var k;
  19366. for (var i = 0, l = keys.length; i !== l; i++) {
  19367. k = keys[i];
  19368. str += (i ? ', ' : '') + k + ': ' + quoteString(this.get(k));
  19369. }
  19370. return str + ' }';
  19371. };
  19372. Record.prototype.equals = function equals (other) {
  19373. return (
  19374. this === other ||
  19375. (other &&
  19376. this._keys === other._keys &&
  19377. recordSeq(this).equals(recordSeq(other)))
  19378. );
  19379. };
  19380. Record.prototype.hashCode = function hashCode () {
  19381. return recordSeq(this).hashCode();
  19382. };
  19383. // @pragma Access
  19384. Record.prototype.has = function has (k) {
  19385. return this._indices.hasOwnProperty(k);
  19386. };
  19387. Record.prototype.get = function get (k, notSetValue) {
  19388. if (!this.has(k)) {
  19389. return notSetValue;
  19390. }
  19391. var index = this._indices[k];
  19392. var value = this._values.get(index);
  19393. return value === undefined ? this._defaultValues[k] : value;
  19394. };
  19395. // @pragma Modification
  19396. Record.prototype.set = function set (k, v) {
  19397. if (this.has(k)) {
  19398. var newValues = this._values.set(
  19399. this._indices[k],
  19400. v === this._defaultValues[k] ? undefined : v
  19401. );
  19402. if (newValues !== this._values && !this.__ownerID) {
  19403. return makeRecord(this, newValues);
  19404. }
  19405. }
  19406. return this;
  19407. };
  19408. Record.prototype.remove = function remove (k) {
  19409. return this.set(k);
  19410. };
  19411. Record.prototype.clear = function clear () {
  19412. var newValues = this._values.clear().setSize(this._keys.length);
  19413. return this.__ownerID ? this : makeRecord(this, newValues);
  19414. };
  19415. Record.prototype.wasAltered = function wasAltered () {
  19416. return this._values.wasAltered();
  19417. };
  19418. Record.prototype.toSeq = function toSeq () {
  19419. return recordSeq(this);
  19420. };
  19421. Record.prototype.toJS = function toJS$1 () {
  19422. return toJS(this);
  19423. };
  19424. Record.prototype.entries = function entries () {
  19425. return this.__iterator(ITERATE_ENTRIES);
  19426. };
  19427. Record.prototype.__iterator = function __iterator (type, reverse) {
  19428. return recordSeq(this).__iterator(type, reverse);
  19429. };
  19430. Record.prototype.__iterate = function __iterate (fn, reverse) {
  19431. return recordSeq(this).__iterate(fn, reverse);
  19432. };
  19433. Record.prototype.__ensureOwner = function __ensureOwner (ownerID) {
  19434. if (ownerID === this.__ownerID) {
  19435. return this;
  19436. }
  19437. var newValues = this._values.__ensureOwner(ownerID);
  19438. if (!ownerID) {
  19439. this.__ownerID = ownerID;
  19440. this._values = newValues;
  19441. return this;
  19442. }
  19443. return makeRecord(this, newValues, ownerID);
  19444. };
  19445. Record.isRecord = isRecord;
  19446. Record.getDescriptiveName = recordName;
  19447. var RecordPrototype = Record.prototype;
  19448. RecordPrototype[IS_RECORD_SYMBOL] = true;
  19449. RecordPrototype[DELETE] = RecordPrototype.remove;
  19450. RecordPrototype.deleteIn = RecordPrototype.removeIn = deleteIn;
  19451. RecordPrototype.getIn = getIn$1;
  19452. RecordPrototype.hasIn = CollectionPrototype.hasIn;
  19453. RecordPrototype.merge = merge;
  19454. RecordPrototype.mergeWith = mergeWith;
  19455. RecordPrototype.mergeIn = mergeIn;
  19456. RecordPrototype.mergeDeep = mergeDeep$1;
  19457. RecordPrototype.mergeDeepWith = mergeDeepWith$1;
  19458. RecordPrototype.mergeDeepIn = mergeDeepIn;
  19459. RecordPrototype.setIn = setIn$1;
  19460. RecordPrototype.update = update$1;
  19461. RecordPrototype.updateIn = updateIn$1;
  19462. RecordPrototype.withMutations = withMutations;
  19463. RecordPrototype.asMutable = asMutable;
  19464. RecordPrototype.asImmutable = asImmutable;
  19465. RecordPrototype[ITERATOR_SYMBOL] = RecordPrototype.entries;
  19466. RecordPrototype.toJSON = RecordPrototype.toObject =
  19467. CollectionPrototype.toObject;
  19468. RecordPrototype.inspect = RecordPrototype.toSource = function() {
  19469. return this.toString();
  19470. };
  19471. function makeRecord(likeRecord, values, ownerID) {
  19472. var record = Object.create(Object.getPrototypeOf(likeRecord));
  19473. record._values = values;
  19474. record.__ownerID = ownerID;
  19475. return record;
  19476. }
  19477. function recordName(record) {
  19478. return record.constructor.displayName || record.constructor.name || 'Record';
  19479. }
  19480. function recordSeq(record) {
  19481. return keyedSeqFromValue(record._keys.map(function (k) { return [k, record.get(k)]; }));
  19482. }
  19483. function setProp(prototype, name) {
  19484. try {
  19485. Object.defineProperty(prototype, name, {
  19486. get: function() {
  19487. return this.get(name);
  19488. },
  19489. set: function(value) {
  19490. invariant(this.__ownerID, 'Cannot set on an immutable record.');
  19491. this.set(name, value);
  19492. },
  19493. });
  19494. } catch (error) {
  19495. // Object.defineProperty failed. Probably IE8.
  19496. }
  19497. }
  19498. /**
  19499. * Returns a lazy Seq of `value` repeated `times` times. When `times` is
  19500. * undefined, returns an infinite sequence of `value`.
  19501. */
  19502. var Repeat = /*@__PURE__*/(function (IndexedSeq$$1) {
  19503. function Repeat(value, times) {
  19504. if (!(this instanceof Repeat)) {
  19505. return new Repeat(value, times);
  19506. }
  19507. this._value = value;
  19508. this.size = times === undefined ? Infinity : Math.max(0, times);
  19509. if (this.size === 0) {
  19510. if (EMPTY_REPEAT) {
  19511. return EMPTY_REPEAT;
  19512. }
  19513. EMPTY_REPEAT = this;
  19514. }
  19515. }
  19516. if ( IndexedSeq$$1 ) Repeat.__proto__ = IndexedSeq$$1;
  19517. Repeat.prototype = Object.create( IndexedSeq$$1 && IndexedSeq$$1.prototype );
  19518. Repeat.prototype.constructor = Repeat;
  19519. Repeat.prototype.toString = function toString () {
  19520. if (this.size === 0) {
  19521. return 'Repeat []';
  19522. }
  19523. return 'Repeat [ ' + this._value + ' ' + this.size + ' times ]';
  19524. };
  19525. Repeat.prototype.get = function get (index, notSetValue) {
  19526. return this.has(index) ? this._value : notSetValue;
  19527. };
  19528. Repeat.prototype.includes = function includes (searchValue) {
  19529. return is(this._value, searchValue);
  19530. };
  19531. Repeat.prototype.slice = function slice (begin, end) {
  19532. var size = this.size;
  19533. return wholeSlice(begin, end, size)
  19534. ? this
  19535. : new Repeat(
  19536. this._value,
  19537. resolveEnd(end, size) - resolveBegin(begin, size)
  19538. );
  19539. };
  19540. Repeat.prototype.reverse = function reverse () {
  19541. return this;
  19542. };
  19543. Repeat.prototype.indexOf = function indexOf (searchValue) {
  19544. if (is(this._value, searchValue)) {
  19545. return 0;
  19546. }
  19547. return -1;
  19548. };
  19549. Repeat.prototype.lastIndexOf = function lastIndexOf (searchValue) {
  19550. if (is(this._value, searchValue)) {
  19551. return this.size;
  19552. }
  19553. return -1;
  19554. };
  19555. Repeat.prototype.__iterate = function __iterate (fn, reverse) {
  19556. var size = this.size;
  19557. var i = 0;
  19558. while (i !== size) {
  19559. if (fn(this._value, reverse ? size - ++i : i++, this) === false) {
  19560. break;
  19561. }
  19562. }
  19563. return i;
  19564. };
  19565. Repeat.prototype.__iterator = function __iterator (type, reverse) {
  19566. var this$1 = this;
  19567. var size = this.size;
  19568. var i = 0;
  19569. return new Iterator(
  19570. function () { return i === size
  19571. ? iteratorDone()
  19572. : iteratorValue(type, reverse ? size - ++i : i++, this$1._value); }
  19573. );
  19574. };
  19575. Repeat.prototype.equals = function equals (other) {
  19576. return other instanceof Repeat
  19577. ? is(this._value, other._value)
  19578. : deepEqual(other);
  19579. };
  19580. return Repeat;
  19581. }(IndexedSeq));
  19582. var EMPTY_REPEAT;
  19583. function fromJS(value, converter) {
  19584. return fromJSWith(
  19585. [],
  19586. converter || defaultConverter,
  19587. value,
  19588. '',
  19589. converter && converter.length > 2 ? [] : undefined,
  19590. { '': value }
  19591. );
  19592. }
  19593. function fromJSWith(stack, converter, value, key, keyPath, parentValue) {
  19594. var toSeq = Array.isArray(value)
  19595. ? IndexedSeq
  19596. : isPlainObj(value)
  19597. ? KeyedSeq
  19598. : null;
  19599. if (toSeq) {
  19600. if (~stack.indexOf(value)) {
  19601. throw new TypeError('Cannot convert circular structure to Immutable');
  19602. }
  19603. stack.push(value);
  19604. keyPath && key !== '' && keyPath.push(key);
  19605. var converted = converter.call(
  19606. parentValue,
  19607. key,
  19608. toSeq(value).map(function (v, k) { return fromJSWith(stack, converter, v, k, keyPath, value); }
  19609. ),
  19610. keyPath && keyPath.slice()
  19611. );
  19612. stack.pop();
  19613. keyPath && keyPath.pop();
  19614. return converted;
  19615. }
  19616. return value;
  19617. }
  19618. function defaultConverter(k, v) {
  19619. return isKeyed(v) ? v.toMap() : v.toList();
  19620. }
  19621. var version = "4.0.0-rc.11";
  19622. var Immutable = {
  19623. version: version,
  19624. Collection: Collection,
  19625. // Note: Iterable is deprecated
  19626. Iterable: Collection,
  19627. Seq: Seq,
  19628. Map: Map,
  19629. OrderedMap: OrderedMap,
  19630. List: List,
  19631. Stack: Stack,
  19632. Set: Set,
  19633. OrderedSet: OrderedSet,
  19634. Record: Record,
  19635. Range: Range,
  19636. Repeat: Repeat,
  19637. is: is,
  19638. fromJS: fromJS,
  19639. hash: hash,
  19640. isImmutable: isImmutable,
  19641. isCollection: isCollection,
  19642. isKeyed: isKeyed,
  19643. isIndexed: isIndexed,
  19644. isAssociative: isAssociative,
  19645. isOrdered: isOrdered,
  19646. isValueObject: isValueObject,
  19647. isSeq: isSeq,
  19648. isList: isList,
  19649. isMap: isMap,
  19650. isOrderedMap: isOrderedMap,
  19651. isStack: isStack,
  19652. isSet: isSet,
  19653. isOrderedSet: isOrderedSet,
  19654. isRecord: isRecord,
  19655. get: get,
  19656. getIn: getIn,
  19657. has: has,
  19658. hasIn: hasIn,
  19659. merge: merge$1,
  19660. mergeDeep: mergeDeep,
  19661. mergeWith: mergeWith$1,
  19662. mergeDeepWith: mergeDeepWith,
  19663. remove: remove,
  19664. removeIn: removeIn,
  19665. set: set,
  19666. setIn: setIn,
  19667. update: update,
  19668. updateIn: updateIn,
  19669. };
  19670. // Note: Iterable is deprecated
  19671. var Iterable = Collection;
  19672. exports.default = Immutable;
  19673. exports.version = version;
  19674. exports.Collection = Collection;
  19675. exports.Iterable = Iterable;
  19676. exports.Seq = Seq;
  19677. exports.Map = Map;
  19678. exports.OrderedMap = OrderedMap;
  19679. exports.List = List;
  19680. exports.Stack = Stack;
  19681. exports.Set = Set;
  19682. exports.OrderedSet = OrderedSet;
  19683. exports.Record = Record;
  19684. exports.Range = Range;
  19685. exports.Repeat = Repeat;
  19686. exports.is = is;
  19687. exports.fromJS = fromJS;
  19688. exports.hash = hash;
  19689. exports.isImmutable = isImmutable;
  19690. exports.isCollection = isCollection;
  19691. exports.isKeyed = isKeyed;
  19692. exports.isIndexed = isIndexed;
  19693. exports.isAssociative = isAssociative;
  19694. exports.isOrdered = isOrdered;
  19695. exports.isValueObject = isValueObject;
  19696. exports.get = get;
  19697. exports.getIn = getIn;
  19698. exports.has = has;
  19699. exports.hasIn = hasIn;
  19700. exports.merge = merge$1;
  19701. exports.mergeDeep = mergeDeep;
  19702. exports.mergeWith = mergeWith$1;
  19703. exports.mergeDeepWith = mergeDeepWith;
  19704. exports.remove = remove;
  19705. exports.removeIn = removeIn;
  19706. exports.set = set;
  19707. exports.setIn = setIn;
  19708. exports.update = update;
  19709. exports.updateIn = updateIn;
  19710. Object.defineProperty(exports, '__esModule', { value: true });
  19711. })));
  19712. });
  19713. unwrapExports(immutable$1);
  19714. var draftjsUtils = createCommonjsModule(function (module, exports) {
  19715. !function(t,e){module.exports=e(Draft,immutable$1);}(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;});
  19716. });
  19717. unwrapExports(draftjsUtils);
  19718. var draftjsUtils_1 = draftjsUtils.draftjsUtils;
  19719. var interopRequireDefault = createCommonjsModule(function (module) {
  19720. function _interopRequireDefault(obj) {
  19721. return obj && obj.__esModule ? obj : {
  19722. "default": obj
  19723. };
  19724. }
  19725. module.exports = _interopRequireDefault;
  19726. });
  19727. unwrapExports(interopRequireDefault);
  19728. /**
  19729. * Copyright (c) 2013-present, Facebook, Inc.
  19730. *
  19731. * This source code is licensed under the MIT license found in the
  19732. * LICENSE file in the root directory of this source tree.
  19733. */
  19734. /**
  19735. * Use invariant() to assert state which your program assumes to be true.
  19736. *
  19737. * Provide sprintf-style format (only %s is supported) and arguments
  19738. * to provide information about what broke and what you were
  19739. * expecting.
  19740. *
  19741. * The invariant message will be stripped in production, but the invariant
  19742. * will remain to ensure logic does not differ in production.
  19743. */
  19744. var invariant$1 = function(condition, format, a, b, c, d, e, f) {
  19745. if (process.env.NODE_ENV !== 'production') {
  19746. if (format === undefined) {
  19747. throw new Error('invariant requires an error message argument');
  19748. }
  19749. }
  19750. if (!condition) {
  19751. var error;
  19752. if (format === undefined) {
  19753. error = new Error(
  19754. 'Minified exception occurred; use the non-minified dev environment ' +
  19755. 'for the full error message and additional helpful warnings.'
  19756. );
  19757. } else {
  19758. var args = [a, b, c, d, e, f];
  19759. var argIndex = 0;
  19760. error = new Error(
  19761. format.replace(/%s/g, function() { return args[argIndex++]; })
  19762. );
  19763. error.name = 'Invariant Violation';
  19764. }
  19765. error.framesToPop = 1; // we don't care about invariant's own frame
  19766. throw error;
  19767. }
  19768. };
  19769. var browser = invariant$1;
  19770. function _arrayWithoutHoles(arr) {
  19771. if (Array.isArray(arr)) {
  19772. for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {
  19773. arr2[i] = arr[i];
  19774. }
  19775. return arr2;
  19776. }
  19777. }
  19778. var arrayWithoutHoles = _arrayWithoutHoles;
  19779. function _iterableToArray(iter) {
  19780. if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
  19781. }
  19782. var iterableToArray = _iterableToArray;
  19783. function _nonIterableSpread() {
  19784. throw new TypeError("Invalid attempt to spread non-iterable instance");
  19785. }
  19786. var nonIterableSpread = _nonIterableSpread;
  19787. function _toConsumableArray(arr) {
  19788. return arrayWithoutHoles(arr) || iterableToArray(arr) || nonIterableSpread();
  19789. }
  19790. var toConsumableArray = _toConsumableArray;
  19791. var updateMutation_1 = createCommonjsModule(function (module, exports) {
  19792. Object.defineProperty(exports, "__esModule", {
  19793. value: true
  19794. });
  19795. exports["default"] = updateMutation;
  19796. function updateMutation(mutation, originalOffset, originalLength, newLength, prefixLength, suffixLength) {
  19797. // three cases we can reasonably adjust - disjoint mutations that
  19798. // happen later on where the offset will need to be changed,
  19799. // mutations that completely contain the new one where we can adjust
  19800. // the length, and mutations that occur partially within the new one.
  19801. var lengthDiff = newLength - originalLength;
  19802. var mutationAfterChange = originalOffset + originalLength <= mutation.offset;
  19803. if (mutationAfterChange) {
  19804. return Object.assign({}, mutation, {
  19805. offset: mutation.offset + lengthDiff
  19806. });
  19807. }
  19808. var mutationContainsChange = originalOffset >= mutation.offset && originalOffset + originalLength <= mutation.offset + mutation.length;
  19809. if (mutationContainsChange) {
  19810. return Object.assign({}, mutation, {
  19811. length: mutation.length + lengthDiff
  19812. });
  19813. }
  19814. var mutationWithinPrefixChange = mutation.offset >= originalOffset && mutation.offset + mutation.length <= originalOffset + originalLength && prefixLength > 0;
  19815. if (mutationWithinPrefixChange) {
  19816. return Object.assign({}, mutation, {
  19817. offset: mutation.offset + prefixLength
  19818. });
  19819. }
  19820. var mutationContainsPrefix = mutation.offset < originalOffset && mutation.offset + mutation.length <= originalOffset + originalLength && mutation.offset + mutation.length > originalOffset && prefixLength > 0;
  19821. if (mutationContainsPrefix) {
  19822. return [Object.assign({}, mutation, {
  19823. length: originalOffset - mutation.offset
  19824. }), Object.assign({}, mutation, {
  19825. offset: originalOffset + prefixLength,
  19826. length: mutation.offset - originalOffset + mutation.length
  19827. })];
  19828. }
  19829. var mutationContainsSuffix = mutation.offset >= originalOffset && mutation.offset + mutation.length > originalOffset + originalLength && originalOffset + originalLength > mutation.offset && suffixLength > 0;
  19830. if (mutationContainsSuffix) {
  19831. return [Object.assign({}, mutation, {
  19832. offset: mutation.offset + prefixLength,
  19833. length: originalOffset + originalLength - mutation.offset
  19834. }), Object.assign({}, mutation, {
  19835. offset: originalOffset + originalLength + prefixLength + suffixLength,
  19836. length: mutation.offset + mutation.length - (originalOffset + originalLength)
  19837. })];
  19838. }
  19839. return mutation;
  19840. }
  19841. });
  19842. unwrapExports(updateMutation_1);
  19843. var rangeSort = createCommonjsModule(function (module, exports) {
  19844. Object.defineProperty(exports, "__esModule", {
  19845. value: true
  19846. });
  19847. exports["default"] = void 0;
  19848. var _default = function _default(r1, r2) {
  19849. if (r1.offset === r2.offset) {
  19850. return r2.length - r1.length;
  19851. }
  19852. return r1.offset - r2.offset;
  19853. };
  19854. exports["default"] = _default;
  19855. });
  19856. unwrapExports(rangeSort);
  19857. var encodeBlock = createCommonjsModule(function (module, exports) {
  19858. Object.defineProperty(exports, "__esModule", {
  19859. value: true
  19860. });
  19861. exports["default"] = void 0;
  19862. var _toConsumableArray2 = interopRequireDefault(toConsumableArray);
  19863. var _updateMutation = interopRequireDefault(updateMutation_1);
  19864. var _rangeSort = interopRequireDefault(rangeSort);
  19865. var ENTITY_MAP = {
  19866. '&': '&amp;',
  19867. '<': '&lt;',
  19868. '>': '&gt;',
  19869. '"': '&quot;',
  19870. "'": '&#x27;',
  19871. '`': '&#x60;',
  19872. '\n': '<br/>'
  19873. };
  19874. var _default = function _default(block) {
  19875. var blockText = (0, _toConsumableArray2["default"])(block.text);
  19876. var entities = block.entityRanges.sort(_rangeSort["default"]);
  19877. var styles = block.inlineStyleRanges.sort(_rangeSort["default"]);
  19878. var resultText = '';
  19879. var _loop = function _loop(index) {
  19880. var _char = blockText[index];
  19881. if (ENTITY_MAP[_char] !== undefined) {
  19882. var encoded = ENTITY_MAP[_char];
  19883. var resultIndex = (0, _toConsumableArray2["default"])(resultText).length;
  19884. resultText += encoded;
  19885. var updateForChar = function updateForChar(mutation) {
  19886. return (0, _updateMutation["default"])(mutation, resultIndex, _char.length, encoded.length, 0, 0);
  19887. };
  19888. entities = entities.map(updateForChar);
  19889. styles = styles.map(updateForChar);
  19890. } else {
  19891. resultText += _char;
  19892. }
  19893. };
  19894. for (var index = 0; index < blockText.length; index++) {
  19895. _loop(index);
  19896. }
  19897. return Object.assign({}, block, {
  19898. text: resultText,
  19899. inlineStyleRanges: styles,
  19900. entityRanges: entities
  19901. });
  19902. };
  19903. exports["default"] = _default;
  19904. });
  19905. unwrapExports(encodeBlock);
  19906. var _typeof_1 = createCommonjsModule(function (module) {
  19907. function _typeof(obj) {
  19908. "@babel/helpers - typeof";
  19909. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  19910. module.exports = _typeof = function _typeof(obj) {
  19911. return typeof obj;
  19912. };
  19913. } else {
  19914. module.exports = _typeof = function _typeof(obj) {
  19915. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  19916. };
  19917. }
  19918. return _typeof(obj);
  19919. }
  19920. module.exports = _typeof;
  19921. });
  19922. var splitReactElement_1 = createCommonjsModule(function (module, exports) {
  19923. Object.defineProperty(exports, "__esModule", {
  19924. value: true
  19925. });
  19926. exports["default"] = splitReactElement;
  19927. var _invariant = interopRequireDefault(browser);
  19928. var _react = interopRequireDefault(React);
  19929. var _server = interopRequireDefault(server);
  19930. // see http://w3c.github.io/html/syntax.html#writing-html-documents-elements
  19931. var VOID_TAGS = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr'];
  19932. function splitReactElement(element) {
  19933. if (VOID_TAGS.indexOf(element.type) !== -1) {
  19934. return _server["default"].renderToStaticMarkup(element);
  19935. }
  19936. var tags = _server["default"].renderToStaticMarkup(_react["default"].cloneElement(element, {}, '\r')).split('\r');
  19937. (0, _invariant["default"])(tags.length > 1, "convertToHTML: Element of type ".concat(element.type, " must render children"));
  19938. (0, _invariant["default"])(tags.length < 3, "convertToHTML: Element of type ".concat(element.type, " cannot use carriage return character"));
  19939. return {
  19940. start: tags[0],
  19941. end: tags[1]
  19942. };
  19943. }
  19944. });
  19945. unwrapExports(splitReactElement_1);
  19946. var getElementHTML_1 = createCommonjsModule(function (module, exports) {
  19947. Object.defineProperty(exports, "__esModule", {
  19948. value: true
  19949. });
  19950. exports["default"] = getElementHTML;
  19951. var _typeof2 = interopRequireDefault(_typeof_1);
  19952. var _invariant = interopRequireDefault(browser);
  19953. var _react = interopRequireDefault(React);
  19954. var _server = interopRequireDefault(server);
  19955. var _splitReactElement = interopRequireDefault(splitReactElement_1);
  19956. function hasChildren(element) {
  19957. return _react["default"].isValidElement(element) && _react["default"].Children.count(element.props.children) > 0;
  19958. }
  19959. function getElementHTML(element) {
  19960. var text = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  19961. if (element === undefined || element === null) {
  19962. return element;
  19963. }
  19964. if (typeof element === 'string') {
  19965. return element;
  19966. }
  19967. if (_react["default"].isValidElement(element)) {
  19968. if (hasChildren(element)) {
  19969. return _server["default"].renderToStaticMarkup(element);
  19970. }
  19971. var tags = (0, _splitReactElement["default"])(element);
  19972. if (text !== null && (0, _typeof2["default"])(tags) === 'object') {
  19973. var start = tags.start,
  19974. end = tags.end;
  19975. return start + text + end;
  19976. }
  19977. return tags;
  19978. }
  19979. (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');
  19980. if (text !== null) {
  19981. var _start = element.start,
  19982. _end = element.end;
  19983. return _start + text + _end;
  19984. }
  19985. return element;
  19986. }
  19987. });
  19988. unwrapExports(getElementHTML_1);
  19989. var getElementTagLength_1 = createCommonjsModule(function (module, exports) {
  19990. Object.defineProperty(exports, "__esModule", {
  19991. value: true
  19992. });
  19993. exports["default"] = void 0;
  19994. var _typeof2 = interopRequireDefault(_typeof_1);
  19995. var _react = interopRequireDefault(React);
  19996. var _splitReactElement = interopRequireDefault(splitReactElement_1);
  19997. var getElementTagLength = function getElementTagLength(element) {
  19998. var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'start';
  19999. if (_react["default"].isValidElement(element)) {
  20000. var splitElement = (0, _splitReactElement["default"])(element);
  20001. if (typeof splitElement === 'string') {
  20002. return 0;
  20003. }
  20004. var length = splitElement[type].length;
  20005. var child = _react["default"].Children.toArray(element.props.children)[0];
  20006. return length + (child && _react["default"].isValidElement(child) ? getElementTagLength(child, type) : 0);
  20007. }
  20008. if ((0, _typeof2["default"])(element) === 'object') {
  20009. return element[type] ? element[type].length : 0;
  20010. }
  20011. return 0;
  20012. };
  20013. var _default = getElementTagLength;
  20014. exports["default"] = _default;
  20015. });
  20016. unwrapExports(getElementTagLength_1);
  20017. var blockEntities = createCommonjsModule(function (module, exports) {
  20018. Object.defineProperty(exports, "__esModule", {
  20019. value: true
  20020. });
  20021. exports["default"] = void 0;
  20022. var _toConsumableArray2 = interopRequireDefault(toConsumableArray);
  20023. var _updateMutation = interopRequireDefault(updateMutation_1);
  20024. var _rangeSort = interopRequireDefault(rangeSort);
  20025. var _getElementHTML = interopRequireDefault(getElementHTML_1);
  20026. var _getElementTagLength = interopRequireDefault(getElementTagLength_1);
  20027. var converter = function converter() {
  20028. var originalText = arguments.length > 1 ? arguments[1] : undefined;
  20029. return originalText;
  20030. };
  20031. var _default = function _default(block, entityMap) {
  20032. var entityConverter = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : converter;
  20033. var resultText = (0, _toConsumableArray2["default"])(block.text);
  20034. var getEntityHTML = entityConverter;
  20035. if (entityConverter.__isMiddleware) {
  20036. getEntityHTML = entityConverter(converter);
  20037. }
  20038. if (Object.prototype.hasOwnProperty.call(block, 'entityRanges') && block.entityRanges.length > 0) {
  20039. var entities = block.entityRanges.sort(_rangeSort["default"]);
  20040. var styles = block.inlineStyleRanges;
  20041. var _loop = function _loop(index) {
  20042. var entityRange = entities[index];
  20043. var entity = entityMap[entityRange.key];
  20044. var originalText = resultText.slice(entityRange.offset, entityRange.offset + entityRange.length).join('');
  20045. var entityHTML = getEntityHTML(entity, originalText);
  20046. var converted = (0, _toConsumableArray2["default"])((0, _getElementHTML["default"])(entityHTML, originalText) || originalText);
  20047. var prefixLength = (0, _getElementTagLength["default"])(entityHTML, 'start');
  20048. var suffixLength = (0, _getElementTagLength["default"])(entityHTML, 'end');
  20049. var updateLaterMutation = function updateLaterMutation(mutation, mutationIndex) {
  20050. if (mutationIndex > index || Object.prototype.hasOwnProperty.call(mutation, 'style')) {
  20051. return (0, _updateMutation["default"])(mutation, entityRange.offset, entityRange.length, converted.length, prefixLength, suffixLength);
  20052. }
  20053. return mutation;
  20054. };
  20055. var updateLaterMutations = function updateLaterMutations(mutationList) {
  20056. return mutationList.reduce(function (acc, mutation, mutationIndex) {
  20057. var updatedMutation = updateLaterMutation(mutation, mutationIndex);
  20058. if (Array.isArray(updatedMutation)) {
  20059. return acc.concat(updatedMutation);
  20060. }
  20061. return acc.concat([updatedMutation]);
  20062. }, []);
  20063. };
  20064. entities = updateLaterMutations(entities);
  20065. styles = updateLaterMutations(styles);
  20066. resultText = [].concat((0, _toConsumableArray2["default"])(resultText.slice(0, entityRange.offset)), (0, _toConsumableArray2["default"])(converted), (0, _toConsumableArray2["default"])(resultText.slice(entityRange.offset + entityRange.length)));
  20067. };
  20068. for (var index = 0; index < entities.length; index++) {
  20069. _loop(index);
  20070. }
  20071. return Object.assign({}, block, {
  20072. text: resultText.join(''),
  20073. inlineStyleRanges: styles,
  20074. entityRanges: entities
  20075. });
  20076. }
  20077. return block;
  20078. };
  20079. exports["default"] = _default;
  20080. });
  20081. unwrapExports(blockEntities);
  20082. var styleObjectFunction = createCommonjsModule(function (module, exports) {
  20083. Object.defineProperty(exports, "__esModule", {
  20084. value: true
  20085. });
  20086. exports["default"] = void 0;
  20087. var _default = function _default(object) {
  20088. return function (style) {
  20089. if (typeof object === 'function') {
  20090. return object(style);
  20091. }
  20092. return object[style];
  20093. };
  20094. };
  20095. exports["default"] = _default;
  20096. });
  20097. unwrapExports(styleObjectFunction);
  20098. var accumulateFunction = createCommonjsModule(function (module, exports) {
  20099. Object.defineProperty(exports, "__esModule", {
  20100. value: true
  20101. });
  20102. exports["default"] = void 0;
  20103. var _default = function _default(newFn, rest) {
  20104. return function () {
  20105. var newResult = newFn.apply(void 0, arguments);
  20106. if (newResult !== undefined && newResult !== null) {
  20107. return newResult;
  20108. }
  20109. return rest.apply(void 0, arguments);
  20110. };
  20111. };
  20112. exports["default"] = _default;
  20113. });
  20114. unwrapExports(accumulateFunction);
  20115. var defaultInlineHTML_1 = createCommonjsModule(function (module, exports) {
  20116. Object.defineProperty(exports, "__esModule", {
  20117. value: true
  20118. });
  20119. exports["default"] = defaultInlineHTML;
  20120. var _react = interopRequireDefault(React);
  20121. function defaultInlineHTML(style) {
  20122. switch (style) {
  20123. case 'BOLD':
  20124. return _react["default"].createElement("strong", null);
  20125. case 'ITALIC':
  20126. return _react["default"].createElement("em", null);
  20127. case 'UNDERLINE':
  20128. return _react["default"].createElement("u", null);
  20129. case 'CODE':
  20130. return _react["default"].createElement("code", null);
  20131. default:
  20132. return {
  20133. start: '',
  20134. end: ''
  20135. };
  20136. }
  20137. }
  20138. });
  20139. unwrapExports(defaultInlineHTML_1);
  20140. var blockInlineStyles = createCommonjsModule(function (module, exports) {
  20141. Object.defineProperty(exports, "__esModule", {
  20142. value: true
  20143. });
  20144. exports["default"] = void 0;
  20145. var _toConsumableArray2 = interopRequireDefault(toConsumableArray);
  20146. var _invariant = interopRequireDefault(browser);
  20147. var _styleObjectFunction = interopRequireDefault(styleObjectFunction);
  20148. var _accumulateFunction = interopRequireDefault(accumulateFunction);
  20149. var _getElementHTML = interopRequireDefault(getElementHTML_1);
  20150. var _rangeSort = interopRequireDefault(rangeSort);
  20151. var _defaultInlineHTML = interopRequireDefault(defaultInlineHTML_1);
  20152. var subtractStyles = function subtractStyles(original, toRemove) {
  20153. return original.filter(function (el) {
  20154. return !toRemove.some(function (elToRemove) {
  20155. return elToRemove.style === el.style;
  20156. });
  20157. });
  20158. };
  20159. var popEndingStyles = function popEndingStyles(styleStack, endingStyles) {
  20160. return endingStyles.reduceRight(function (stack, style) {
  20161. var styleToRemove = stack[stack.length - 1];
  20162. (0, _invariant["default"])(styleToRemove.style === style.style, "Style ".concat(styleToRemove.style, " to be removed doesn't match expected ").concat(style.style));
  20163. return stack.slice(0, -1);
  20164. }, styleStack);
  20165. };
  20166. var characterStyles = function characterStyles(offset, ranges) {
  20167. return ranges.filter(function (range) {
  20168. return offset >= range.offset && offset < range.offset + range.length;
  20169. });
  20170. };
  20171. var rangeIsSubset = function rangeIsSubset(firstRange, secondRange) {
  20172. // returns true if the second range is a subset of the first
  20173. var secondStartWithinFirst = firstRange.offset <= secondRange.offset;
  20174. var secondEndWithinFirst = firstRange.offset + firstRange.length >= secondRange.offset + secondRange.length;
  20175. return secondStartWithinFirst && secondEndWithinFirst;
  20176. };
  20177. var latestStyleLast = function latestStyleLast(s1, s2) {
  20178. // make sure longer-lasting styles are added first
  20179. var s2endIndex = s2.offset + s2.length;
  20180. var s1endIndex = s1.offset + s1.length;
  20181. return s2endIndex - s1endIndex;
  20182. };
  20183. var getStylesToReset = function getStylesToReset(remainingStyles, newStyles) {
  20184. var i = 0;
  20185. while (i < remainingStyles.length) {
  20186. if (newStyles.every(rangeIsSubset.bind(null, remainingStyles[i]))) {
  20187. i++;
  20188. } else {
  20189. return remainingStyles.slice(i);
  20190. }
  20191. }
  20192. return [];
  20193. };
  20194. var appendStartMarkup = function appendStartMarkup(inlineHTML, string, styleRange) {
  20195. return string + (0, _getElementHTML["default"])(inlineHTML(styleRange.style)).start;
  20196. };
  20197. var prependEndMarkup = function prependEndMarkup(inlineHTML, string, styleRange) {
  20198. return (0, _getElementHTML["default"])(inlineHTML(styleRange.style)).end + string;
  20199. };
  20200. var defaultCustomInlineHTML = function defaultCustomInlineHTML(next) {
  20201. return function (style) {
  20202. return next(style);
  20203. };
  20204. };
  20205. defaultCustomInlineHTML.__isMiddleware = true;
  20206. var _default = function _default(rawBlock) {
  20207. var customInlineHTML = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultCustomInlineHTML;
  20208. (0, _invariant["default"])(rawBlock !== null && rawBlock !== undefined, 'Expected raw block to be non-null');
  20209. var inlineHTML;
  20210. if (customInlineHTML.__isMiddleware === true) {
  20211. inlineHTML = customInlineHTML(_defaultInlineHTML["default"]);
  20212. } else {
  20213. inlineHTML = (0, _accumulateFunction["default"])((0, _styleObjectFunction["default"])(customInlineHTML), (0, _styleObjectFunction["default"])(_defaultInlineHTML["default"]));
  20214. }
  20215. var result = '';
  20216. var styleStack = [];
  20217. var sortedRanges = rawBlock.inlineStyleRanges.sort(_rangeSort["default"]);
  20218. var originalTextArray = (0, _toConsumableArray2["default"])(rawBlock.text);
  20219. for (var i = 0; i < originalTextArray.length; i++) {
  20220. var styles = characterStyles(i, sortedRanges);
  20221. var endingStyles = subtractStyles(styleStack, styles);
  20222. var newStyles = subtractStyles(styles, styleStack);
  20223. var remainingStyles = subtractStyles(styleStack, endingStyles); // reset styles: look for any already existing styles that will need to
  20224. // end before styles that are being added on this character. to solve this
  20225. // close out those current tags and all nested children,
  20226. // then open new ones nested within the new styles.
  20227. var resetStyles = getStylesToReset(remainingStyles, newStyles);
  20228. var openingStyles = resetStyles.concat(newStyles).sort(latestStyleLast);
  20229. var openingStyleTags = openingStyles.reduce(appendStartMarkup.bind(null, inlineHTML), '');
  20230. var endingStyleTags = endingStyles.concat(resetStyles).reduce(prependEndMarkup.bind(null, inlineHTML), '');
  20231. result += endingStyleTags + openingStyleTags + originalTextArray[i];
  20232. styleStack = popEndingStyles(styleStack, resetStyles.concat(endingStyles));
  20233. styleStack = styleStack.concat(openingStyles);
  20234. (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"));
  20235. }
  20236. result = styleStack.reduceRight(function (res, openStyle) {
  20237. return res + (0, _getElementHTML["default"])(inlineHTML(openStyle.style)).end;
  20238. }, result);
  20239. return result;
  20240. };
  20241. exports["default"] = _default;
  20242. });
  20243. unwrapExports(blockInlineStyles);
  20244. var blockTypeObjectFunction = createCommonjsModule(function (module, exports) {
  20245. Object.defineProperty(exports, "__esModule", {
  20246. value: true
  20247. });
  20248. exports["default"] = void 0;
  20249. var _default = function _default(typeObject) {
  20250. return function (block) {
  20251. if (typeof typeObject === 'function') {
  20252. // handle case where typeObject is already a function
  20253. return typeObject(block);
  20254. }
  20255. return typeObject[block.type];
  20256. };
  20257. };
  20258. exports["default"] = _default;
  20259. });
  20260. unwrapExports(blockTypeObjectFunction);
  20261. var getBlockTags_1 = createCommonjsModule(function (module, exports) {
  20262. Object.defineProperty(exports, "__esModule", {
  20263. value: true
  20264. });
  20265. exports["default"] = getBlockTags;
  20266. var _invariant = interopRequireDefault(browser);
  20267. var _react = interopRequireDefault(React);
  20268. var _server = interopRequireDefault(server);
  20269. var _splitReactElement = interopRequireDefault(splitReactElement_1);
  20270. function hasChildren(element) {
  20271. return _react["default"].isValidElement(element) && _react["default"].Children.count(element.props.children) > 0;
  20272. }
  20273. function getBlockTags(blockHTML) {
  20274. (0, _invariant["default"])(blockHTML !== null && blockHTML !== undefined, 'Expected block HTML value to be non-null');
  20275. if (typeof blockHTML === 'string') {
  20276. return blockHTML;
  20277. }
  20278. if (_react["default"].isValidElement(blockHTML)) {
  20279. if (hasChildren(blockHTML)) {
  20280. return _server["default"].renderToStaticMarkup(blockHTML);
  20281. }
  20282. return (0, _splitReactElement["default"])(blockHTML);
  20283. }
  20284. if (Object.prototype.hasOwnProperty.call(blockHTML, 'element') && _react["default"].isValidElement(blockHTML.element)) {
  20285. return Object.assign({}, blockHTML, (0, _splitReactElement["default"])(blockHTML.element));
  20286. }
  20287. (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');
  20288. return blockHTML;
  20289. }
  20290. });
  20291. unwrapExports(getBlockTags_1);
  20292. var getNestedBlockTags_1 = createCommonjsModule(function (module, exports) {
  20293. Object.defineProperty(exports, "__esModule", {
  20294. value: true
  20295. });
  20296. exports["default"] = getNestedBlockTags;
  20297. var _invariant = interopRequireDefault(browser);
  20298. var _react = interopRequireDefault(React);
  20299. var _splitReactElement2 = interopRequireDefault(splitReactElement_1);
  20300. function getNestedBlockTags(blockHTML) {
  20301. (0, _invariant["default"])(blockHTML !== null && blockHTML !== undefined, 'Expected block HTML value to be non-null');
  20302. if (_react["default"].isValidElement(blockHTML.nest)) {
  20303. var _splitReactElement = (0, _splitReactElement2["default"])(blockHTML.nest),
  20304. start = _splitReactElement.start,
  20305. end = _splitReactElement.end;
  20306. return Object.assign({}, blockHTML, {
  20307. nestStart: start,
  20308. nestEnd: end
  20309. });
  20310. }
  20311. (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');
  20312. return blockHTML;
  20313. }
  20314. });
  20315. unwrapExports(getNestedBlockTags_1);
  20316. var defaultBlockHTML = createCommonjsModule(function (module, exports) {
  20317. Object.defineProperty(exports, "__esModule", {
  20318. value: true
  20319. });
  20320. exports["default"] = void 0;
  20321. var _react = interopRequireDefault(React);
  20322. var _default = {
  20323. unstyled: _react["default"].createElement("p", null),
  20324. paragraph: _react["default"].createElement("p", null),
  20325. 'header-one': _react["default"].createElement("h1", null),
  20326. 'header-two': _react["default"].createElement("h2", null),
  20327. 'header-three': _react["default"].createElement("h3", null),
  20328. 'header-four': _react["default"].createElement("h4", null),
  20329. 'header-five': _react["default"].createElement("h5", null),
  20330. 'header-six': _react["default"].createElement("h6", null),
  20331. blockquote: _react["default"].createElement("blockquote", null),
  20332. 'unordered-list-item': {
  20333. element: _react["default"].createElement("li", null),
  20334. nest: _react["default"].createElement("ul", null)
  20335. },
  20336. 'ordered-list-item': {
  20337. element: _react["default"].createElement("li", null),
  20338. nest: _react["default"].createElement("ol", null)
  20339. },
  20340. media: _react["default"].createElement("figure", null),
  20341. atomic: _react["default"].createElement("figure", null)
  20342. };
  20343. exports["default"] = _default;
  20344. });
  20345. unwrapExports(defaultBlockHTML);
  20346. var convertToHTML_1 = createCommonjsModule(function (module, exports) {
  20347. Object.defineProperty(exports, "__esModule", {
  20348. value: true
  20349. });
  20350. exports["default"] = void 0;
  20351. var _invariant = interopRequireDefault(browser);
  20352. var _react = interopRequireDefault(React);
  20353. var _server = interopRequireDefault(server);
  20354. var _encodeBlock = interopRequireDefault(encodeBlock);
  20355. var _blockEntities = interopRequireDefault(blockEntities);
  20356. var _blockInlineStyles = interopRequireDefault(blockInlineStyles);
  20357. var _accumulateFunction = interopRequireDefault(accumulateFunction);
  20358. var _blockTypeObjectFunction = interopRequireDefault(blockTypeObjectFunction);
  20359. var _getBlockTags = interopRequireDefault(getBlockTags_1);
  20360. var _getNestedBlockTags = interopRequireDefault(getNestedBlockTags_1);
  20361. var _defaultBlockHTML = interopRequireDefault(defaultBlockHTML);
  20362. // import Immutable from 'immutable'; // eslint-disable-line no-unused-vars
  20363. var defaultEntityToHTML = function defaultEntityToHTML(entity, originalText) {
  20364. return originalText;
  20365. };
  20366. var convertToHTML = function convertToHTML(_ref) {
  20367. var _ref$styleToHTML = _ref.styleToHTML,
  20368. styleToHTML = _ref$styleToHTML === void 0 ? {} : _ref$styleToHTML,
  20369. _ref$blockToHTML = _ref.blockToHTML,
  20370. blockToHTML = _ref$blockToHTML === void 0 ? {} : _ref$blockToHTML,
  20371. _ref$entityToHTML = _ref.entityToHTML,
  20372. entityToHTML = _ref$entityToHTML === void 0 ? defaultEntityToHTML : _ref$entityToHTML;
  20373. return function (contentState) {
  20374. (0, _invariant["default"])(contentState !== null && contentState !== undefined, 'Expected contentState to be non-null');
  20375. var getBlockHTML;
  20376. if (blockToHTML.__isMiddleware === true) {
  20377. getBlockHTML = blockToHTML((0, _blockTypeObjectFunction["default"])(_defaultBlockHTML["default"]));
  20378. } else {
  20379. getBlockHTML = (0, _accumulateFunction["default"])((0, _blockTypeObjectFunction["default"])(blockToHTML), (0, _blockTypeObjectFunction["default"])(_defaultBlockHTML["default"]));
  20380. }
  20381. var rawState = (0, Draft.convertToRaw)(contentState);
  20382. var listStack = [];
  20383. var result = rawState.blocks.map(function (block) {
  20384. var type = block.type,
  20385. depth = block.depth;
  20386. var closeNestTags = '';
  20387. var openNestTags = '';
  20388. var blockHTMLResult = getBlockHTML(block);
  20389. if (!blockHTMLResult) {
  20390. throw new Error("convertToHTML: missing HTML definition for block with type ".concat(block.type));
  20391. }
  20392. if (!blockHTMLResult.nest) {
  20393. // this block can't be nested, so reset all nesting if necessary
  20394. closeNestTags = listStack.reduceRight(function (string, nestedBlock) {
  20395. return string + (0, _getNestedBlockTags["default"])(getBlockHTML(nestedBlock)).nestEnd;
  20396. }, '');
  20397. listStack = [];
  20398. } else {
  20399. while (depth + 1 !== listStack.length || type !== listStack[depth].type) {
  20400. if (depth + 1 === listStack.length) {
  20401. // depth is right but doesn't match type
  20402. var blockToClose = listStack[depth];
  20403. closeNestTags += (0, _getNestedBlockTags["default"])(getBlockHTML(blockToClose)).nestEnd;
  20404. openNestTags += (0, _getNestedBlockTags["default"])(getBlockHTML(block)).nestStart;
  20405. listStack[depth] = block;
  20406. } else if (depth + 1 < listStack.length) {
  20407. var _blockToClose = listStack[listStack.length - 1];
  20408. closeNestTags += (0, _getNestedBlockTags["default"])(getBlockHTML(_blockToClose)).nestEnd;
  20409. listStack = listStack.slice(0, -1);
  20410. } else {
  20411. openNestTags += (0, _getNestedBlockTags["default"])(getBlockHTML(block)).nestStart;
  20412. listStack.push(block);
  20413. }
  20414. }
  20415. }
  20416. var innerHTML = (0, _blockInlineStyles["default"])((0, _blockEntities["default"])((0, _encodeBlock["default"])(block), rawState.entityMap, entityToHTML), styleToHTML);
  20417. var blockHTML = (0, _getBlockTags["default"])(getBlockHTML(block));
  20418. var html;
  20419. if (typeof blockHTML === 'string') {
  20420. html = blockHTML;
  20421. } else {
  20422. html = blockHTML.start + innerHTML + blockHTML.end;
  20423. }
  20424. if (innerHTML.length === 0 && Object.prototype.hasOwnProperty.call(blockHTML, 'empty')) {
  20425. if (_react["default"].isValidElement(blockHTML.empty)) {
  20426. html = _server["default"].renderToStaticMarkup(blockHTML.empty);
  20427. } else {
  20428. html = blockHTML.empty;
  20429. }
  20430. }
  20431. return closeNestTags + openNestTags + html;
  20432. }).join('');
  20433. result = listStack.reduce(function (res, nestBlock) {
  20434. return res + (0, _getNestedBlockTags["default"])(getBlockHTML(nestBlock)).nestEnd;
  20435. }, result);
  20436. return result;
  20437. };
  20438. };
  20439. var _default = function _default() {
  20440. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  20441. args[_key] = arguments[_key];
  20442. }
  20443. if (args.length === 1 && Object.prototype.hasOwnProperty.call(args[0], '_map') && args[0].getBlockMap != null) {
  20444. // skip higher-order function and use defaults
  20445. return convertToHTML({}).apply(void 0, args);
  20446. }
  20447. return convertToHTML.apply(void 0, args);
  20448. };
  20449. exports["default"] = _default;
  20450. });
  20451. unwrapExports(convertToHTML_1);
  20452. var immutable$2 = createCommonjsModule(function (module, exports) {
  20453. /**
  20454. * Copyright (c) 2014-2015, Facebook, Inc.
  20455. * All rights reserved.
  20456. *
  20457. * This source code is licensed under the BSD-style license found in the
  20458. * LICENSE file in the root directory of this source tree. An additional grant
  20459. * of patent rights can be found in the PATENTS file in the same directory.
  20460. */
  20461. (function (global, factory) {
  20462. module.exports = factory() ;
  20463. }(commonjsGlobal, function () {var SLICE$0 = Array.prototype.slice;
  20464. function createClass(ctor, superClass) {
  20465. if (superClass) {
  20466. ctor.prototype = Object.create(superClass.prototype);
  20467. }
  20468. ctor.prototype.constructor = ctor;
  20469. }
  20470. function Iterable(value) {
  20471. return isIterable(value) ? value : Seq(value);
  20472. }
  20473. createClass(KeyedIterable, Iterable);
  20474. function KeyedIterable(value) {
  20475. return isKeyed(value) ? value : KeyedSeq(value);
  20476. }
  20477. createClass(IndexedIterable, Iterable);
  20478. function IndexedIterable(value) {
  20479. return isIndexed(value) ? value : IndexedSeq(value);
  20480. }
  20481. createClass(SetIterable, Iterable);
  20482. function SetIterable(value) {
  20483. return isIterable(value) && !isAssociative(value) ? value : SetSeq(value);
  20484. }
  20485. function isIterable(maybeIterable) {
  20486. return !!(maybeIterable && maybeIterable[IS_ITERABLE_SENTINEL]);
  20487. }
  20488. function isKeyed(maybeKeyed) {
  20489. return !!(maybeKeyed && maybeKeyed[IS_KEYED_SENTINEL]);
  20490. }
  20491. function isIndexed(maybeIndexed) {
  20492. return !!(maybeIndexed && maybeIndexed[IS_INDEXED_SENTINEL]);
  20493. }
  20494. function isAssociative(maybeAssociative) {
  20495. return isKeyed(maybeAssociative) || isIndexed(maybeAssociative);
  20496. }
  20497. function isOrdered(maybeOrdered) {
  20498. return !!(maybeOrdered && maybeOrdered[IS_ORDERED_SENTINEL]);
  20499. }
  20500. Iterable.isIterable = isIterable;
  20501. Iterable.isKeyed = isKeyed;
  20502. Iterable.isIndexed = isIndexed;
  20503. Iterable.isAssociative = isAssociative;
  20504. Iterable.isOrdered = isOrdered;
  20505. Iterable.Keyed = KeyedIterable;
  20506. Iterable.Indexed = IndexedIterable;
  20507. Iterable.Set = SetIterable;
  20508. var IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
  20509. var IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
  20510. var IS_INDEXED_SENTINEL = '@@__IMMUTABLE_INDEXED__@@';
  20511. var IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
  20512. // Used for setting prototype methods that IE8 chokes on.
  20513. var DELETE = 'delete';
  20514. // Constants describing the size of trie nodes.
  20515. var SHIFT = 5; // Resulted in best performance after ______?
  20516. var SIZE = 1 << SHIFT;
  20517. var MASK = SIZE - 1;
  20518. // A consistent shared value representing "not set" which equals nothing other
  20519. // than itself, and nothing that could be provided externally.
  20520. var NOT_SET = {};
  20521. // Boolean references, Rough equivalent of `bool &`.
  20522. var CHANGE_LENGTH = { value: false };
  20523. var DID_ALTER = { value: false };
  20524. function MakeRef(ref) {
  20525. ref.value = false;
  20526. return ref;
  20527. }
  20528. function SetRef(ref) {
  20529. ref && (ref.value = true);
  20530. }
  20531. // A function which returns a value representing an "owner" for transient writes
  20532. // to tries. The return value will only ever equal itself, and will not equal
  20533. // the return of any subsequent call of this function.
  20534. function OwnerID() {}
  20535. // http://jsperf.com/copy-array-inline
  20536. function arrCopy(arr, offset) {
  20537. offset = offset || 0;
  20538. var len = Math.max(0, arr.length - offset);
  20539. var newArr = new Array(len);
  20540. for (var ii = 0; ii < len; ii++) {
  20541. newArr[ii] = arr[ii + offset];
  20542. }
  20543. return newArr;
  20544. }
  20545. function ensureSize(iter) {
  20546. if (iter.size === undefined) {
  20547. iter.size = iter.__iterate(returnTrue);
  20548. }
  20549. return iter.size;
  20550. }
  20551. function wrapIndex(iter, index) {
  20552. // This implements "is array index" which the ECMAString spec defines as:
  20553. //
  20554. // A String property name P is an array index if and only if
  20555. // ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal
  20556. // to 2^32−1.
  20557. //
  20558. // http://www.ecma-international.org/ecma-262/6.0/#sec-array-exotic-objects
  20559. if (typeof index !== 'number') {
  20560. var uint32Index = index >>> 0; // N >>> 0 is shorthand for ToUint32
  20561. if ('' + uint32Index !== index || uint32Index === 4294967295) {
  20562. return NaN;
  20563. }
  20564. index = uint32Index;
  20565. }
  20566. return index < 0 ? ensureSize(iter) + index : index;
  20567. }
  20568. function returnTrue() {
  20569. return true;
  20570. }
  20571. function wholeSlice(begin, end, size) {
  20572. return (begin === 0 || (size !== undefined && begin <= -size)) &&
  20573. (end === undefined || (size !== undefined && end >= size));
  20574. }
  20575. function resolveBegin(begin, size) {
  20576. return resolveIndex(begin, size, 0);
  20577. }
  20578. function resolveEnd(end, size) {
  20579. return resolveIndex(end, size, size);
  20580. }
  20581. function resolveIndex(index, size, defaultIndex) {
  20582. return index === undefined ?
  20583. defaultIndex :
  20584. index < 0 ?
  20585. Math.max(0, size + index) :
  20586. size === undefined ?
  20587. index :
  20588. Math.min(size, index);
  20589. }
  20590. /* global Symbol */
  20591. var ITERATE_KEYS = 0;
  20592. var ITERATE_VALUES = 1;
  20593. var ITERATE_ENTRIES = 2;
  20594. var REAL_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
  20595. var FAUX_ITERATOR_SYMBOL = '@@iterator';
  20596. var ITERATOR_SYMBOL = REAL_ITERATOR_SYMBOL || FAUX_ITERATOR_SYMBOL;
  20597. function Iterator(next) {
  20598. this.next = next;
  20599. }
  20600. Iterator.prototype.toString = function() {
  20601. return '[Iterator]';
  20602. };
  20603. Iterator.KEYS = ITERATE_KEYS;
  20604. Iterator.VALUES = ITERATE_VALUES;
  20605. Iterator.ENTRIES = ITERATE_ENTRIES;
  20606. Iterator.prototype.inspect =
  20607. Iterator.prototype.toSource = function () { return this.toString(); };
  20608. Iterator.prototype[ITERATOR_SYMBOL] = function () {
  20609. return this;
  20610. };
  20611. function iteratorValue(type, k, v, iteratorResult) {
  20612. var value = type === 0 ? k : type === 1 ? v : [k, v];
  20613. iteratorResult ? (iteratorResult.value = value) : (iteratorResult = {
  20614. value: value, done: false
  20615. });
  20616. return iteratorResult;
  20617. }
  20618. function iteratorDone() {
  20619. return { value: undefined, done: true };
  20620. }
  20621. function hasIterator(maybeIterable) {
  20622. return !!getIteratorFn(maybeIterable);
  20623. }
  20624. function isIterator(maybeIterator) {
  20625. return maybeIterator && typeof maybeIterator.next === 'function';
  20626. }
  20627. function getIterator(iterable) {
  20628. var iteratorFn = getIteratorFn(iterable);
  20629. return iteratorFn && iteratorFn.call(iterable);
  20630. }
  20631. function getIteratorFn(iterable) {
  20632. var iteratorFn = iterable && (
  20633. (REAL_ITERATOR_SYMBOL && iterable[REAL_ITERATOR_SYMBOL]) ||
  20634. iterable[FAUX_ITERATOR_SYMBOL]
  20635. );
  20636. if (typeof iteratorFn === 'function') {
  20637. return iteratorFn;
  20638. }
  20639. }
  20640. function isArrayLike(value) {
  20641. return value && typeof value.length === 'number';
  20642. }
  20643. createClass(Seq, Iterable);
  20644. function Seq(value) {
  20645. return value === null || value === undefined ? emptySequence() :
  20646. isIterable(value) ? value.toSeq() : seqFromValue(value);
  20647. }
  20648. Seq.of = function(/*...values*/) {
  20649. return Seq(arguments);
  20650. };
  20651. Seq.prototype.toSeq = function() {
  20652. return this;
  20653. };
  20654. Seq.prototype.toString = function() {
  20655. return this.__toString('Seq {', '}');
  20656. };
  20657. Seq.prototype.cacheResult = function() {
  20658. if (!this._cache && this.__iterateUncached) {
  20659. this._cache = this.entrySeq().toArray();
  20660. this.size = this._cache.length;
  20661. }
  20662. return this;
  20663. };
  20664. // abstract __iterateUncached(fn, reverse)
  20665. Seq.prototype.__iterate = function(fn, reverse) {
  20666. return seqIterate(this, fn, reverse, true);
  20667. };
  20668. // abstract __iteratorUncached(type, reverse)
  20669. Seq.prototype.__iterator = function(type, reverse) {
  20670. return seqIterator(this, type, reverse, true);
  20671. };
  20672. createClass(KeyedSeq, Seq);
  20673. function KeyedSeq(value) {
  20674. return value === null || value === undefined ?
  20675. emptySequence().toKeyedSeq() :
  20676. isIterable(value) ?
  20677. (isKeyed(value) ? value.toSeq() : value.fromEntrySeq()) :
  20678. keyedSeqFromValue(value);
  20679. }
  20680. KeyedSeq.prototype.toKeyedSeq = function() {
  20681. return this;
  20682. };
  20683. createClass(IndexedSeq, Seq);
  20684. function IndexedSeq(value) {
  20685. return value === null || value === undefined ? emptySequence() :
  20686. !isIterable(value) ? indexedSeqFromValue(value) :
  20687. isKeyed(value) ? value.entrySeq() : value.toIndexedSeq();
  20688. }
  20689. IndexedSeq.of = function(/*...values*/) {
  20690. return IndexedSeq(arguments);
  20691. };
  20692. IndexedSeq.prototype.toIndexedSeq = function() {
  20693. return this;
  20694. };
  20695. IndexedSeq.prototype.toString = function() {
  20696. return this.__toString('Seq [', ']');
  20697. };
  20698. IndexedSeq.prototype.__iterate = function(fn, reverse) {
  20699. return seqIterate(this, fn, reverse, false);
  20700. };
  20701. IndexedSeq.prototype.__iterator = function(type, reverse) {
  20702. return seqIterator(this, type, reverse, false);
  20703. };
  20704. createClass(SetSeq, Seq);
  20705. function SetSeq(value) {
  20706. return (
  20707. value === null || value === undefined ? emptySequence() :
  20708. !isIterable(value) ? indexedSeqFromValue(value) :
  20709. isKeyed(value) ? value.entrySeq() : value
  20710. ).toSetSeq();
  20711. }
  20712. SetSeq.of = function(/*...values*/) {
  20713. return SetSeq(arguments);
  20714. };
  20715. SetSeq.prototype.toSetSeq = function() {
  20716. return this;
  20717. };
  20718. Seq.isSeq = isSeq;
  20719. Seq.Keyed = KeyedSeq;
  20720. Seq.Set = SetSeq;
  20721. Seq.Indexed = IndexedSeq;
  20722. var IS_SEQ_SENTINEL = '@@__IMMUTABLE_SEQ__@@';
  20723. Seq.prototype[IS_SEQ_SENTINEL] = true;
  20724. createClass(ArraySeq, IndexedSeq);
  20725. function ArraySeq(array) {
  20726. this._array = array;
  20727. this.size = array.length;
  20728. }
  20729. ArraySeq.prototype.get = function(index, notSetValue) {
  20730. return this.has(index) ? this._array[wrapIndex(this, index)] : notSetValue;
  20731. };
  20732. ArraySeq.prototype.__iterate = function(fn, reverse) {
  20733. var array = this._array;
  20734. var maxIndex = array.length - 1;
  20735. for (var ii = 0; ii <= maxIndex; ii++) {
  20736. if (fn(array[reverse ? maxIndex - ii : ii], ii, this) === false) {
  20737. return ii + 1;
  20738. }
  20739. }
  20740. return ii;
  20741. };
  20742. ArraySeq.prototype.__iterator = function(type, reverse) {
  20743. var array = this._array;
  20744. var maxIndex = array.length - 1;
  20745. var ii = 0;
  20746. return new Iterator(function()
  20747. {return ii > maxIndex ?
  20748. iteratorDone() :
  20749. iteratorValue(type, ii, array[reverse ? maxIndex - ii++ : ii++])}
  20750. );
  20751. };
  20752. createClass(ObjectSeq, KeyedSeq);
  20753. function ObjectSeq(object) {
  20754. var keys = Object.keys(object);
  20755. this._object = object;
  20756. this._keys = keys;
  20757. this.size = keys.length;
  20758. }
  20759. ObjectSeq.prototype.get = function(key, notSetValue) {
  20760. if (notSetValue !== undefined && !this.has(key)) {
  20761. return notSetValue;
  20762. }
  20763. return this._object[key];
  20764. };
  20765. ObjectSeq.prototype.has = function(key) {
  20766. return this._object.hasOwnProperty(key);
  20767. };
  20768. ObjectSeq.prototype.__iterate = function(fn, reverse) {
  20769. var object = this._object;
  20770. var keys = this._keys;
  20771. var maxIndex = keys.length - 1;
  20772. for (var ii = 0; ii <= maxIndex; ii++) {
  20773. var key = keys[reverse ? maxIndex - ii : ii];
  20774. if (fn(object[key], key, this) === false) {
  20775. return ii + 1;
  20776. }
  20777. }
  20778. return ii;
  20779. };
  20780. ObjectSeq.prototype.__iterator = function(type, reverse) {
  20781. var object = this._object;
  20782. var keys = this._keys;
  20783. var maxIndex = keys.length - 1;
  20784. var ii = 0;
  20785. return new Iterator(function() {
  20786. var key = keys[reverse ? maxIndex - ii : ii];
  20787. return ii++ > maxIndex ?
  20788. iteratorDone() :
  20789. iteratorValue(type, key, object[key]);
  20790. });
  20791. };
  20792. ObjectSeq.prototype[IS_ORDERED_SENTINEL] = true;
  20793. createClass(IterableSeq, IndexedSeq);
  20794. function IterableSeq(iterable) {
  20795. this._iterable = iterable;
  20796. this.size = iterable.length || iterable.size;
  20797. }
  20798. IterableSeq.prototype.__iterateUncached = function(fn, reverse) {
  20799. if (reverse) {
  20800. return this.cacheResult().__iterate(fn, reverse);
  20801. }
  20802. var iterable = this._iterable;
  20803. var iterator = getIterator(iterable);
  20804. var iterations = 0;
  20805. if (isIterator(iterator)) {
  20806. var step;
  20807. while (!(step = iterator.next()).done) {
  20808. if (fn(step.value, iterations++, this) === false) {
  20809. break;
  20810. }
  20811. }
  20812. }
  20813. return iterations;
  20814. };
  20815. IterableSeq.prototype.__iteratorUncached = function(type, reverse) {
  20816. if (reverse) {
  20817. return this.cacheResult().__iterator(type, reverse);
  20818. }
  20819. var iterable = this._iterable;
  20820. var iterator = getIterator(iterable);
  20821. if (!isIterator(iterator)) {
  20822. return new Iterator(iteratorDone);
  20823. }
  20824. var iterations = 0;
  20825. return new Iterator(function() {
  20826. var step = iterator.next();
  20827. return step.done ? step : iteratorValue(type, iterations++, step.value);
  20828. });
  20829. };
  20830. createClass(IteratorSeq, IndexedSeq);
  20831. function IteratorSeq(iterator) {
  20832. this._iterator = iterator;
  20833. this._iteratorCache = [];
  20834. }
  20835. IteratorSeq.prototype.__iterateUncached = function(fn, reverse) {
  20836. if (reverse) {
  20837. return this.cacheResult().__iterate(fn, reverse);
  20838. }
  20839. var iterator = this._iterator;
  20840. var cache = this._iteratorCache;
  20841. var iterations = 0;
  20842. while (iterations < cache.length) {
  20843. if (fn(cache[iterations], iterations++, this) === false) {
  20844. return iterations;
  20845. }
  20846. }
  20847. var step;
  20848. while (!(step = iterator.next()).done) {
  20849. var val = step.value;
  20850. cache[iterations] = val;
  20851. if (fn(val, iterations++, this) === false) {
  20852. break;
  20853. }
  20854. }
  20855. return iterations;
  20856. };
  20857. IteratorSeq.prototype.__iteratorUncached = function(type, reverse) {
  20858. if (reverse) {
  20859. return this.cacheResult().__iterator(type, reverse);
  20860. }
  20861. var iterator = this._iterator;
  20862. var cache = this._iteratorCache;
  20863. var iterations = 0;
  20864. return new Iterator(function() {
  20865. if (iterations >= cache.length) {
  20866. var step = iterator.next();
  20867. if (step.done) {
  20868. return step;
  20869. }
  20870. cache[iterations] = step.value;
  20871. }
  20872. return iteratorValue(type, iterations, cache[iterations++]);
  20873. });
  20874. };
  20875. // # pragma Helper functions
  20876. function isSeq(maybeSeq) {
  20877. return !!(maybeSeq && maybeSeq[IS_SEQ_SENTINEL]);
  20878. }
  20879. var EMPTY_SEQ;
  20880. function emptySequence() {
  20881. return EMPTY_SEQ || (EMPTY_SEQ = new ArraySeq([]));
  20882. }
  20883. function keyedSeqFromValue(value) {
  20884. var seq =
  20885. Array.isArray(value) ? new ArraySeq(value).fromEntrySeq() :
  20886. isIterator(value) ? new IteratorSeq(value).fromEntrySeq() :
  20887. hasIterator(value) ? new IterableSeq(value).fromEntrySeq() :
  20888. typeof value === 'object' ? new ObjectSeq(value) :
  20889. undefined;
  20890. if (!seq) {
  20891. throw new TypeError(
  20892. 'Expected Array or iterable object of [k, v] entries, '+
  20893. 'or keyed object: ' + value
  20894. );
  20895. }
  20896. return seq;
  20897. }
  20898. function indexedSeqFromValue(value) {
  20899. var seq = maybeIndexedSeqFromValue(value);
  20900. if (!seq) {
  20901. throw new TypeError(
  20902. 'Expected Array or iterable object of values: ' + value
  20903. );
  20904. }
  20905. return seq;
  20906. }
  20907. function seqFromValue(value) {
  20908. var seq = maybeIndexedSeqFromValue(value) ||
  20909. (typeof value === 'object' && new ObjectSeq(value));
  20910. if (!seq) {
  20911. throw new TypeError(
  20912. 'Expected Array or iterable object of values, or keyed object: ' + value
  20913. );
  20914. }
  20915. return seq;
  20916. }
  20917. function maybeIndexedSeqFromValue(value) {
  20918. return (
  20919. isArrayLike(value) ? new ArraySeq(value) :
  20920. isIterator(value) ? new IteratorSeq(value) :
  20921. hasIterator(value) ? new IterableSeq(value) :
  20922. undefined
  20923. );
  20924. }
  20925. function seqIterate(seq, fn, reverse, useKeys) {
  20926. var cache = seq._cache;
  20927. if (cache) {
  20928. var maxIndex = cache.length - 1;
  20929. for (var ii = 0; ii <= maxIndex; ii++) {
  20930. var entry = cache[reverse ? maxIndex - ii : ii];
  20931. if (fn(entry[1], useKeys ? entry[0] : ii, seq) === false) {
  20932. return ii + 1;
  20933. }
  20934. }
  20935. return ii;
  20936. }
  20937. return seq.__iterateUncached(fn, reverse);
  20938. }
  20939. function seqIterator(seq, type, reverse, useKeys) {
  20940. var cache = seq._cache;
  20941. if (cache) {
  20942. var maxIndex = cache.length - 1;
  20943. var ii = 0;
  20944. return new Iterator(function() {
  20945. var entry = cache[reverse ? maxIndex - ii : ii];
  20946. return ii++ > maxIndex ?
  20947. iteratorDone() :
  20948. iteratorValue(type, useKeys ? entry[0] : ii - 1, entry[1]);
  20949. });
  20950. }
  20951. return seq.__iteratorUncached(type, reverse);
  20952. }
  20953. function fromJS(json, converter) {
  20954. return converter ?
  20955. fromJSWith(converter, json, '', {'': json}) :
  20956. fromJSDefault(json);
  20957. }
  20958. function fromJSWith(converter, json, key, parentJSON) {
  20959. if (Array.isArray(json)) {
  20960. return converter.call(parentJSON, key, IndexedSeq(json).map(function(v, k) {return fromJSWith(converter, v, k, json)}));
  20961. }
  20962. if (isPlainObj(json)) {
  20963. return converter.call(parentJSON, key, KeyedSeq(json).map(function(v, k) {return fromJSWith(converter, v, k, json)}));
  20964. }
  20965. return json;
  20966. }
  20967. function fromJSDefault(json) {
  20968. if (Array.isArray(json)) {
  20969. return IndexedSeq(json).map(fromJSDefault).toList();
  20970. }
  20971. if (isPlainObj(json)) {
  20972. return KeyedSeq(json).map(fromJSDefault).toMap();
  20973. }
  20974. return json;
  20975. }
  20976. function isPlainObj(value) {
  20977. return value && (value.constructor === Object || value.constructor === undefined);
  20978. }
  20979. /**
  20980. * An extension of the "same-value" algorithm as [described for use by ES6 Map
  20981. * and Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map#Key_equality)
  20982. *
  20983. * NaN is considered the same as NaN, however -0 and 0 are considered the same
  20984. * value, which is different from the algorithm described by
  20985. * [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is).
  20986. *
  20987. * This is extended further to allow Objects to describe the values they
  20988. * represent, by way of `valueOf` or `equals` (and `hashCode`).
  20989. *
  20990. * Note: because of this extension, the key equality of Immutable.Map and the
  20991. * value equality of Immutable.Set will differ from ES6 Map and Set.
  20992. *
  20993. * ### Defining custom values
  20994. *
  20995. * The easiest way to describe the value an object represents is by implementing
  20996. * `valueOf`. For example, `Date` represents a value by returning a unix
  20997. * timestamp for `valueOf`:
  20998. *
  20999. * var date1 = new Date(1234567890000); // Fri Feb 13 2009 ...
  21000. * var date2 = new Date(1234567890000);
  21001. * date1.valueOf(); // 1234567890000
  21002. * assert( date1 !== date2 );
  21003. * assert( Immutable.is( date1, date2 ) );
  21004. *
  21005. * Note: overriding `valueOf` may have other implications if you use this object
  21006. * where JavaScript expects a primitive, such as implicit string coercion.
  21007. *
  21008. * For more complex types, especially collections, implementing `valueOf` may
  21009. * not be performant. An alternative is to implement `equals` and `hashCode`.
  21010. *
  21011. * `equals` takes another object, presumably of similar type, and returns true
  21012. * if the it is equal. Equality is symmetrical, so the same result should be
  21013. * returned if this and the argument are flipped.
  21014. *
  21015. * assert( a.equals(b) === b.equals(a) );
  21016. *
  21017. * `hashCode` returns a 32bit integer number representing the object which will
  21018. * be used to determine how to store the value object in a Map or Set. You must
  21019. * provide both or neither methods, one must not exist without the other.
  21020. *
  21021. * Also, an important relationship between these methods must be upheld: if two
  21022. * values are equal, they *must* return the same hashCode. If the values are not
  21023. * equal, they might have the same hashCode; this is called a hash collision,
  21024. * and while undesirable for performance reasons, it is acceptable.
  21025. *
  21026. * if (a.equals(b)) {
  21027. * assert( a.hashCode() === b.hashCode() );
  21028. * }
  21029. *
  21030. * All Immutable collections implement `equals` and `hashCode`.
  21031. *
  21032. */
  21033. function is(valueA, valueB) {
  21034. if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
  21035. return true;
  21036. }
  21037. if (!valueA || !valueB) {
  21038. return false;
  21039. }
  21040. if (typeof valueA.valueOf === 'function' &&
  21041. typeof valueB.valueOf === 'function') {
  21042. valueA = valueA.valueOf();
  21043. valueB = valueB.valueOf();
  21044. if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
  21045. return true;
  21046. }
  21047. if (!valueA || !valueB) {
  21048. return false;
  21049. }
  21050. }
  21051. if (typeof valueA.equals === 'function' &&
  21052. typeof valueB.equals === 'function' &&
  21053. valueA.equals(valueB)) {
  21054. return true;
  21055. }
  21056. return false;
  21057. }
  21058. function deepEqual(a, b) {
  21059. if (a === b) {
  21060. return true;
  21061. }
  21062. if (
  21063. !isIterable(b) ||
  21064. a.size !== undefined && b.size !== undefined && a.size !== b.size ||
  21065. a.__hash !== undefined && b.__hash !== undefined && a.__hash !== b.__hash ||
  21066. isKeyed(a) !== isKeyed(b) ||
  21067. isIndexed(a) !== isIndexed(b) ||
  21068. isOrdered(a) !== isOrdered(b)
  21069. ) {
  21070. return false;
  21071. }
  21072. if (a.size === 0 && b.size === 0) {
  21073. return true;
  21074. }
  21075. var notAssociative = !isAssociative(a);
  21076. if (isOrdered(a)) {
  21077. var entries = a.entries();
  21078. return b.every(function(v, k) {
  21079. var entry = entries.next().value;
  21080. return entry && is(entry[1], v) && (notAssociative || is(entry[0], k));
  21081. }) && entries.next().done;
  21082. }
  21083. var flipped = false;
  21084. if (a.size === undefined) {
  21085. if (b.size === undefined) {
  21086. if (typeof a.cacheResult === 'function') {
  21087. a.cacheResult();
  21088. }
  21089. } else {
  21090. flipped = true;
  21091. var _ = a;
  21092. a = b;
  21093. b = _;
  21094. }
  21095. }
  21096. var allEqual = true;
  21097. var bSize = b.__iterate(function(v, k) {
  21098. if (notAssociative ? !a.has(v) :
  21099. flipped ? !is(v, a.get(k, NOT_SET)) : !is(a.get(k, NOT_SET), v)) {
  21100. allEqual = false;
  21101. return false;
  21102. }
  21103. });
  21104. return allEqual && a.size === bSize;
  21105. }
  21106. createClass(Repeat, IndexedSeq);
  21107. function Repeat(value, times) {
  21108. if (!(this instanceof Repeat)) {
  21109. return new Repeat(value, times);
  21110. }
  21111. this._value = value;
  21112. this.size = times === undefined ? Infinity : Math.max(0, times);
  21113. if (this.size === 0) {
  21114. if (EMPTY_REPEAT) {
  21115. return EMPTY_REPEAT;
  21116. }
  21117. EMPTY_REPEAT = this;
  21118. }
  21119. }
  21120. Repeat.prototype.toString = function() {
  21121. if (this.size === 0) {
  21122. return 'Repeat []';
  21123. }
  21124. return 'Repeat [ ' + this._value + ' ' + this.size + ' times ]';
  21125. };
  21126. Repeat.prototype.get = function(index, notSetValue) {
  21127. return this.has(index) ? this._value : notSetValue;
  21128. };
  21129. Repeat.prototype.includes = function(searchValue) {
  21130. return is(this._value, searchValue);
  21131. };
  21132. Repeat.prototype.slice = function(begin, end) {
  21133. var size = this.size;
  21134. return wholeSlice(begin, end, size) ? this :
  21135. new Repeat(this._value, resolveEnd(end, size) - resolveBegin(begin, size));
  21136. };
  21137. Repeat.prototype.reverse = function() {
  21138. return this;
  21139. };
  21140. Repeat.prototype.indexOf = function(searchValue) {
  21141. if (is(this._value, searchValue)) {
  21142. return 0;
  21143. }
  21144. return -1;
  21145. };
  21146. Repeat.prototype.lastIndexOf = function(searchValue) {
  21147. if (is(this._value, searchValue)) {
  21148. return this.size;
  21149. }
  21150. return -1;
  21151. };
  21152. Repeat.prototype.__iterate = function(fn, reverse) {
  21153. for (var ii = 0; ii < this.size; ii++) {
  21154. if (fn(this._value, ii, this) === false) {
  21155. return ii + 1;
  21156. }
  21157. }
  21158. return ii;
  21159. };
  21160. Repeat.prototype.__iterator = function(type, reverse) {var this$0 = this;
  21161. var ii = 0;
  21162. return new Iterator(function()
  21163. {return ii < this$0.size ? iteratorValue(type, ii++, this$0._value) : iteratorDone()}
  21164. );
  21165. };
  21166. Repeat.prototype.equals = function(other) {
  21167. return other instanceof Repeat ?
  21168. is(this._value, other._value) :
  21169. deepEqual(other);
  21170. };
  21171. var EMPTY_REPEAT;
  21172. function invariant(condition, error) {
  21173. if (!condition) throw new Error(error);
  21174. }
  21175. createClass(Range, IndexedSeq);
  21176. function Range(start, end, step) {
  21177. if (!(this instanceof Range)) {
  21178. return new Range(start, end, step);
  21179. }
  21180. invariant(step !== 0, 'Cannot step a Range by 0');
  21181. start = start || 0;
  21182. if (end === undefined) {
  21183. end = Infinity;
  21184. }
  21185. step = step === undefined ? 1 : Math.abs(step);
  21186. if (end < start) {
  21187. step = -step;
  21188. }
  21189. this._start = start;
  21190. this._end = end;
  21191. this._step = step;
  21192. this.size = Math.max(0, Math.ceil((end - start) / step - 1) + 1);
  21193. if (this.size === 0) {
  21194. if (EMPTY_RANGE) {
  21195. return EMPTY_RANGE;
  21196. }
  21197. EMPTY_RANGE = this;
  21198. }
  21199. }
  21200. Range.prototype.toString = function() {
  21201. if (this.size === 0) {
  21202. return 'Range []';
  21203. }
  21204. return 'Range [ ' +
  21205. this._start + '...' + this._end +
  21206. (this._step > 1 ? ' by ' + this._step : '') +
  21207. ' ]';
  21208. };
  21209. Range.prototype.get = function(index, notSetValue) {
  21210. return this.has(index) ?
  21211. this._start + wrapIndex(this, index) * this._step :
  21212. notSetValue;
  21213. };
  21214. Range.prototype.includes = function(searchValue) {
  21215. var possibleIndex = (searchValue - this._start) / this._step;
  21216. return possibleIndex >= 0 &&
  21217. possibleIndex < this.size &&
  21218. possibleIndex === Math.floor(possibleIndex);
  21219. };
  21220. Range.prototype.slice = function(begin, end) {
  21221. if (wholeSlice(begin, end, this.size)) {
  21222. return this;
  21223. }
  21224. begin = resolveBegin(begin, this.size);
  21225. end = resolveEnd(end, this.size);
  21226. if (end <= begin) {
  21227. return new Range(0, 0);
  21228. }
  21229. return new Range(this.get(begin, this._end), this.get(end, this._end), this._step);
  21230. };
  21231. Range.prototype.indexOf = function(searchValue) {
  21232. var offsetValue = searchValue - this._start;
  21233. if (offsetValue % this._step === 0) {
  21234. var index = offsetValue / this._step;
  21235. if (index >= 0 && index < this.size) {
  21236. return index
  21237. }
  21238. }
  21239. return -1;
  21240. };
  21241. Range.prototype.lastIndexOf = function(searchValue) {
  21242. return this.indexOf(searchValue);
  21243. };
  21244. Range.prototype.__iterate = function(fn, reverse) {
  21245. var maxIndex = this.size - 1;
  21246. var step = this._step;
  21247. var value = reverse ? this._start + maxIndex * step : this._start;
  21248. for (var ii = 0; ii <= maxIndex; ii++) {
  21249. if (fn(value, ii, this) === false) {
  21250. return ii + 1;
  21251. }
  21252. value += reverse ? -step : step;
  21253. }
  21254. return ii;
  21255. };
  21256. Range.prototype.__iterator = function(type, reverse) {
  21257. var maxIndex = this.size - 1;
  21258. var step = this._step;
  21259. var value = reverse ? this._start + maxIndex * step : this._start;
  21260. var ii = 0;
  21261. return new Iterator(function() {
  21262. var v = value;
  21263. value += reverse ? -step : step;
  21264. return ii > maxIndex ? iteratorDone() : iteratorValue(type, ii++, v);
  21265. });
  21266. };
  21267. Range.prototype.equals = function(other) {
  21268. return other instanceof Range ?
  21269. this._start === other._start &&
  21270. this._end === other._end &&
  21271. this._step === other._step :
  21272. deepEqual(this, other);
  21273. };
  21274. var EMPTY_RANGE;
  21275. createClass(Collection, Iterable);
  21276. function Collection() {
  21277. throw TypeError('Abstract');
  21278. }
  21279. createClass(KeyedCollection, Collection);function KeyedCollection() {}
  21280. createClass(IndexedCollection, Collection);function IndexedCollection() {}
  21281. createClass(SetCollection, Collection);function SetCollection() {}
  21282. Collection.Keyed = KeyedCollection;
  21283. Collection.Indexed = IndexedCollection;
  21284. Collection.Set = SetCollection;
  21285. var imul =
  21286. typeof Math.imul === 'function' && Math.imul(0xffffffff, 2) === -2 ?
  21287. Math.imul :
  21288. function imul(a, b) {
  21289. a = a | 0; // int
  21290. b = b | 0; // int
  21291. var c = a & 0xffff;
  21292. var d = b & 0xffff;
  21293. // Shift by 0 fixes the sign on the high part.
  21294. return (c * d) + ((((a >>> 16) * d + c * (b >>> 16)) << 16) >>> 0) | 0; // int
  21295. };
  21296. // v8 has an optimization for storing 31-bit signed numbers.
  21297. // Values which have either 00 or 11 as the high order bits qualify.
  21298. // This function drops the highest order bit in a signed number, maintaining
  21299. // the sign bit.
  21300. function smi(i32) {
  21301. return ((i32 >>> 1) & 0x40000000) | (i32 & 0xBFFFFFFF);
  21302. }
  21303. function hash(o) {
  21304. if (o === false || o === null || o === undefined) {
  21305. return 0;
  21306. }
  21307. if (typeof o.valueOf === 'function') {
  21308. o = o.valueOf();
  21309. if (o === false || o === null || o === undefined) {
  21310. return 0;
  21311. }
  21312. }
  21313. if (o === true) {
  21314. return 1;
  21315. }
  21316. var type = typeof o;
  21317. if (type === 'number') {
  21318. var h = o | 0;
  21319. if (h !== o) {
  21320. h ^= o * 0xFFFFFFFF;
  21321. }
  21322. while (o > 0xFFFFFFFF) {
  21323. o /= 0xFFFFFFFF;
  21324. h ^= o;
  21325. }
  21326. return smi(h);
  21327. }
  21328. if (type === 'string') {
  21329. return o.length > STRING_HASH_CACHE_MIN_STRLEN ? cachedHashString(o) : hashString(o);
  21330. }
  21331. if (typeof o.hashCode === 'function') {
  21332. return o.hashCode();
  21333. }
  21334. if (type === 'object') {
  21335. return hashJSObj(o);
  21336. }
  21337. if (typeof o.toString === 'function') {
  21338. return hashString(o.toString());
  21339. }
  21340. throw new Error('Value type ' + type + ' cannot be hashed.');
  21341. }
  21342. function cachedHashString(string) {
  21343. var hash = stringHashCache[string];
  21344. if (hash === undefined) {
  21345. hash = hashString(string);
  21346. if (STRING_HASH_CACHE_SIZE === STRING_HASH_CACHE_MAX_SIZE) {
  21347. STRING_HASH_CACHE_SIZE = 0;
  21348. stringHashCache = {};
  21349. }
  21350. STRING_HASH_CACHE_SIZE++;
  21351. stringHashCache[string] = hash;
  21352. }
  21353. return hash;
  21354. }
  21355. // http://jsperf.com/hashing-strings
  21356. function hashString(string) {
  21357. // This is the hash from JVM
  21358. // The hash code for a string is computed as
  21359. // s[0] * 31 ^ (n - 1) + s[1] * 31 ^ (n - 2) + ... + s[n - 1],
  21360. // where s[i] is the ith character of the string and n is the length of
  21361. // the string. We "mod" the result to make it between 0 (inclusive) and 2^31
  21362. // (exclusive) by dropping high bits.
  21363. var hash = 0;
  21364. for (var ii = 0; ii < string.length; ii++) {
  21365. hash = 31 * hash + string.charCodeAt(ii) | 0;
  21366. }
  21367. return smi(hash);
  21368. }
  21369. function hashJSObj(obj) {
  21370. var hash;
  21371. if (usingWeakMap) {
  21372. hash = weakMap.get(obj);
  21373. if (hash !== undefined) {
  21374. return hash;
  21375. }
  21376. }
  21377. hash = obj[UID_HASH_KEY];
  21378. if (hash !== undefined) {
  21379. return hash;
  21380. }
  21381. if (!canDefineProperty) {
  21382. hash = obj.propertyIsEnumerable && obj.propertyIsEnumerable[UID_HASH_KEY];
  21383. if (hash !== undefined) {
  21384. return hash;
  21385. }
  21386. hash = getIENodeHash(obj);
  21387. if (hash !== undefined) {
  21388. return hash;
  21389. }
  21390. }
  21391. hash = ++objHashUID;
  21392. if (objHashUID & 0x40000000) {
  21393. objHashUID = 0;
  21394. }
  21395. if (usingWeakMap) {
  21396. weakMap.set(obj, hash);
  21397. } else if (isExtensible !== undefined && isExtensible(obj) === false) {
  21398. throw new Error('Non-extensible objects are not allowed as keys.');
  21399. } else if (canDefineProperty) {
  21400. Object.defineProperty(obj, UID_HASH_KEY, {
  21401. 'enumerable': false,
  21402. 'configurable': false,
  21403. 'writable': false,
  21404. 'value': hash
  21405. });
  21406. } else if (obj.propertyIsEnumerable !== undefined &&
  21407. obj.propertyIsEnumerable === obj.constructor.prototype.propertyIsEnumerable) {
  21408. // Since we can't define a non-enumerable property on the object
  21409. // we'll hijack one of the less-used non-enumerable properties to
  21410. // save our hash on it. Since this is a function it will not show up in
  21411. // `JSON.stringify` which is what we want.
  21412. obj.propertyIsEnumerable = function() {
  21413. return this.constructor.prototype.propertyIsEnumerable.apply(this, arguments);
  21414. };
  21415. obj.propertyIsEnumerable[UID_HASH_KEY] = hash;
  21416. } else if (obj.nodeType !== undefined) {
  21417. // At this point we couldn't get the IE `uniqueID` to use as a hash
  21418. // and we couldn't use a non-enumerable property to exploit the
  21419. // dontEnum bug so we simply add the `UID_HASH_KEY` on the node
  21420. // itself.
  21421. obj[UID_HASH_KEY] = hash;
  21422. } else {
  21423. throw new Error('Unable to set a non-enumerable property on object.');
  21424. }
  21425. return hash;
  21426. }
  21427. // Get references to ES5 object methods.
  21428. var isExtensible = Object.isExtensible;
  21429. // True if Object.defineProperty works as expected. IE8 fails this test.
  21430. var canDefineProperty = (function() {
  21431. try {
  21432. Object.defineProperty({}, '@', {});
  21433. return true;
  21434. } catch (e) {
  21435. return false;
  21436. }
  21437. }());
  21438. // IE has a `uniqueID` property on DOM nodes. We can construct the hash from it
  21439. // and avoid memory leaks from the IE cloneNode bug.
  21440. function getIENodeHash(node) {
  21441. if (node && node.nodeType > 0) {
  21442. switch (node.nodeType) {
  21443. case 1: // Element
  21444. return node.uniqueID;
  21445. case 9: // Document
  21446. return node.documentElement && node.documentElement.uniqueID;
  21447. }
  21448. }
  21449. }
  21450. // If possible, use a WeakMap.
  21451. var usingWeakMap = typeof WeakMap === 'function';
  21452. var weakMap;
  21453. if (usingWeakMap) {
  21454. weakMap = new WeakMap();
  21455. }
  21456. var objHashUID = 0;
  21457. var UID_HASH_KEY = '__immutablehash__';
  21458. if (typeof Symbol === 'function') {
  21459. UID_HASH_KEY = Symbol(UID_HASH_KEY);
  21460. }
  21461. var STRING_HASH_CACHE_MIN_STRLEN = 16;
  21462. var STRING_HASH_CACHE_MAX_SIZE = 255;
  21463. var STRING_HASH_CACHE_SIZE = 0;
  21464. var stringHashCache = {};
  21465. function assertNotInfinite(size) {
  21466. invariant(
  21467. size !== Infinity,
  21468. 'Cannot perform this action with an infinite size.'
  21469. );
  21470. }
  21471. createClass(Map, KeyedCollection);
  21472. // @pragma Construction
  21473. function Map(value) {
  21474. return value === null || value === undefined ? emptyMap() :
  21475. isMap(value) && !isOrdered(value) ? value :
  21476. emptyMap().withMutations(function(map ) {
  21477. var iter = KeyedIterable(value);
  21478. assertNotInfinite(iter.size);
  21479. iter.forEach(function(v, k) {return map.set(k, v)});
  21480. });
  21481. }
  21482. Map.prototype.toString = function() {
  21483. return this.__toString('Map {', '}');
  21484. };
  21485. // @pragma Access
  21486. Map.prototype.get = function(k, notSetValue) {
  21487. return this._root ?
  21488. this._root.get(0, undefined, k, notSetValue) :
  21489. notSetValue;
  21490. };
  21491. // @pragma Modification
  21492. Map.prototype.set = function(k, v) {
  21493. return updateMap(this, k, v);
  21494. };
  21495. Map.prototype.setIn = function(keyPath, v) {
  21496. return this.updateIn(keyPath, NOT_SET, function() {return v});
  21497. };
  21498. Map.prototype.remove = function(k) {
  21499. return updateMap(this, k, NOT_SET);
  21500. };
  21501. Map.prototype.deleteIn = function(keyPath) {
  21502. return this.updateIn(keyPath, function() {return NOT_SET});
  21503. };
  21504. Map.prototype.update = function(k, notSetValue, updater) {
  21505. return arguments.length === 1 ?
  21506. k(this) :
  21507. this.updateIn([k], notSetValue, updater);
  21508. };
  21509. Map.prototype.updateIn = function(keyPath, notSetValue, updater) {
  21510. if (!updater) {
  21511. updater = notSetValue;
  21512. notSetValue = undefined;
  21513. }
  21514. var updatedValue = updateInDeepMap(
  21515. this,
  21516. forceIterator(keyPath),
  21517. notSetValue,
  21518. updater
  21519. );
  21520. return updatedValue === NOT_SET ? undefined : updatedValue;
  21521. };
  21522. Map.prototype.clear = function() {
  21523. if (this.size === 0) {
  21524. return this;
  21525. }
  21526. if (this.__ownerID) {
  21527. this.size = 0;
  21528. this._root = null;
  21529. this.__hash = undefined;
  21530. this.__altered = true;
  21531. return this;
  21532. }
  21533. return emptyMap();
  21534. };
  21535. // @pragma Composition
  21536. Map.prototype.merge = function(/*...iters*/) {
  21537. return mergeIntoMapWith(this, undefined, arguments);
  21538. };
  21539. Map.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  21540. return mergeIntoMapWith(this, merger, iters);
  21541. };
  21542. Map.prototype.mergeIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1);
  21543. return this.updateIn(
  21544. keyPath,
  21545. emptyMap(),
  21546. function(m ) {return typeof m.merge === 'function' ?
  21547. m.merge.apply(m, iters) :
  21548. iters[iters.length - 1]}
  21549. );
  21550. };
  21551. Map.prototype.mergeDeep = function(/*...iters*/) {
  21552. return mergeIntoMapWith(this, deepMerger, arguments);
  21553. };
  21554. Map.prototype.mergeDeepWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  21555. return mergeIntoMapWith(this, deepMergerWith(merger), iters);
  21556. };
  21557. Map.prototype.mergeDeepIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1);
  21558. return this.updateIn(
  21559. keyPath,
  21560. emptyMap(),
  21561. function(m ) {return typeof m.mergeDeep === 'function' ?
  21562. m.mergeDeep.apply(m, iters) :
  21563. iters[iters.length - 1]}
  21564. );
  21565. };
  21566. Map.prototype.sort = function(comparator) {
  21567. // Late binding
  21568. return OrderedMap(sortFactory(this, comparator));
  21569. };
  21570. Map.prototype.sortBy = function(mapper, comparator) {
  21571. // Late binding
  21572. return OrderedMap(sortFactory(this, comparator, mapper));
  21573. };
  21574. // @pragma Mutability
  21575. Map.prototype.withMutations = function(fn) {
  21576. var mutable = this.asMutable();
  21577. fn(mutable);
  21578. return mutable.wasAltered() ? mutable.__ensureOwner(this.__ownerID) : this;
  21579. };
  21580. Map.prototype.asMutable = function() {
  21581. return this.__ownerID ? this : this.__ensureOwner(new OwnerID());
  21582. };
  21583. Map.prototype.asImmutable = function() {
  21584. return this.__ensureOwner();
  21585. };
  21586. Map.prototype.wasAltered = function() {
  21587. return this.__altered;
  21588. };
  21589. Map.prototype.__iterator = function(type, reverse) {
  21590. return new MapIterator(this, type, reverse);
  21591. };
  21592. Map.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  21593. var iterations = 0;
  21594. this._root && this._root.iterate(function(entry ) {
  21595. iterations++;
  21596. return fn(entry[1], entry[0], this$0);
  21597. }, reverse);
  21598. return iterations;
  21599. };
  21600. Map.prototype.__ensureOwner = function(ownerID) {
  21601. if (ownerID === this.__ownerID) {
  21602. return this;
  21603. }
  21604. if (!ownerID) {
  21605. this.__ownerID = ownerID;
  21606. this.__altered = false;
  21607. return this;
  21608. }
  21609. return makeMap(this.size, this._root, ownerID, this.__hash);
  21610. };
  21611. function isMap(maybeMap) {
  21612. return !!(maybeMap && maybeMap[IS_MAP_SENTINEL]);
  21613. }
  21614. Map.isMap = isMap;
  21615. var IS_MAP_SENTINEL = '@@__IMMUTABLE_MAP__@@';
  21616. var MapPrototype = Map.prototype;
  21617. MapPrototype[IS_MAP_SENTINEL] = true;
  21618. MapPrototype[DELETE] = MapPrototype.remove;
  21619. MapPrototype.removeIn = MapPrototype.deleteIn;
  21620. // #pragma Trie Nodes
  21621. function ArrayMapNode(ownerID, entries) {
  21622. this.ownerID = ownerID;
  21623. this.entries = entries;
  21624. }
  21625. ArrayMapNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  21626. var entries = this.entries;
  21627. for (var ii = 0, len = entries.length; ii < len; ii++) {
  21628. if (is(key, entries[ii][0])) {
  21629. return entries[ii][1];
  21630. }
  21631. }
  21632. return notSetValue;
  21633. };
  21634. ArrayMapNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  21635. var removed = value === NOT_SET;
  21636. var entries = this.entries;
  21637. var idx = 0;
  21638. for (var len = entries.length; idx < len; idx++) {
  21639. if (is(key, entries[idx][0])) {
  21640. break;
  21641. }
  21642. }
  21643. var exists = idx < len;
  21644. if (exists ? entries[idx][1] === value : removed) {
  21645. return this;
  21646. }
  21647. SetRef(didAlter);
  21648. (removed || !exists) && SetRef(didChangeSize);
  21649. if (removed && entries.length === 1) {
  21650. return; // undefined
  21651. }
  21652. if (!exists && !removed && entries.length >= MAX_ARRAY_MAP_SIZE) {
  21653. return createNodes(ownerID, entries, key, value);
  21654. }
  21655. var isEditable = ownerID && ownerID === this.ownerID;
  21656. var newEntries = isEditable ? entries : arrCopy(entries);
  21657. if (exists) {
  21658. if (removed) {
  21659. idx === len - 1 ? newEntries.pop() : (newEntries[idx] = newEntries.pop());
  21660. } else {
  21661. newEntries[idx] = [key, value];
  21662. }
  21663. } else {
  21664. newEntries.push([key, value]);
  21665. }
  21666. if (isEditable) {
  21667. this.entries = newEntries;
  21668. return this;
  21669. }
  21670. return new ArrayMapNode(ownerID, newEntries);
  21671. };
  21672. function BitmapIndexedNode(ownerID, bitmap, nodes) {
  21673. this.ownerID = ownerID;
  21674. this.bitmap = bitmap;
  21675. this.nodes = nodes;
  21676. }
  21677. BitmapIndexedNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  21678. if (keyHash === undefined) {
  21679. keyHash = hash(key);
  21680. }
  21681. var bit = (1 << ((shift === 0 ? keyHash : keyHash >>> shift) & MASK));
  21682. var bitmap = this.bitmap;
  21683. return (bitmap & bit) === 0 ? notSetValue :
  21684. this.nodes[popCount(bitmap & (bit - 1))].get(shift + SHIFT, keyHash, key, notSetValue);
  21685. };
  21686. BitmapIndexedNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  21687. if (keyHash === undefined) {
  21688. keyHash = hash(key);
  21689. }
  21690. var keyHashFrag = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  21691. var bit = 1 << keyHashFrag;
  21692. var bitmap = this.bitmap;
  21693. var exists = (bitmap & bit) !== 0;
  21694. if (!exists && value === NOT_SET) {
  21695. return this;
  21696. }
  21697. var idx = popCount(bitmap & (bit - 1));
  21698. var nodes = this.nodes;
  21699. var node = exists ? nodes[idx] : undefined;
  21700. var newNode = updateNode(node, ownerID, shift + SHIFT, keyHash, key, value, didChangeSize, didAlter);
  21701. if (newNode === node) {
  21702. return this;
  21703. }
  21704. if (!exists && newNode && nodes.length >= MAX_BITMAP_INDEXED_SIZE) {
  21705. return expandNodes(ownerID, nodes, bitmap, keyHashFrag, newNode);
  21706. }
  21707. if (exists && !newNode && nodes.length === 2 && isLeafNode(nodes[idx ^ 1])) {
  21708. return nodes[idx ^ 1];
  21709. }
  21710. if (exists && newNode && nodes.length === 1 && isLeafNode(newNode)) {
  21711. return newNode;
  21712. }
  21713. var isEditable = ownerID && ownerID === this.ownerID;
  21714. var newBitmap = exists ? newNode ? bitmap : bitmap ^ bit : bitmap | bit;
  21715. var newNodes = exists ? newNode ?
  21716. setIn(nodes, idx, newNode, isEditable) :
  21717. spliceOut(nodes, idx, isEditable) :
  21718. spliceIn(nodes, idx, newNode, isEditable);
  21719. if (isEditable) {
  21720. this.bitmap = newBitmap;
  21721. this.nodes = newNodes;
  21722. return this;
  21723. }
  21724. return new BitmapIndexedNode(ownerID, newBitmap, newNodes);
  21725. };
  21726. function HashArrayMapNode(ownerID, count, nodes) {
  21727. this.ownerID = ownerID;
  21728. this.count = count;
  21729. this.nodes = nodes;
  21730. }
  21731. HashArrayMapNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  21732. if (keyHash === undefined) {
  21733. keyHash = hash(key);
  21734. }
  21735. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  21736. var node = this.nodes[idx];
  21737. return node ? node.get(shift + SHIFT, keyHash, key, notSetValue) : notSetValue;
  21738. };
  21739. HashArrayMapNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  21740. if (keyHash === undefined) {
  21741. keyHash = hash(key);
  21742. }
  21743. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  21744. var removed = value === NOT_SET;
  21745. var nodes = this.nodes;
  21746. var node = nodes[idx];
  21747. if (removed && !node) {
  21748. return this;
  21749. }
  21750. var newNode = updateNode(node, ownerID, shift + SHIFT, keyHash, key, value, didChangeSize, didAlter);
  21751. if (newNode === node) {
  21752. return this;
  21753. }
  21754. var newCount = this.count;
  21755. if (!node) {
  21756. newCount++;
  21757. } else if (!newNode) {
  21758. newCount--;
  21759. if (newCount < MIN_HASH_ARRAY_MAP_SIZE) {
  21760. return packNodes(ownerID, nodes, newCount, idx);
  21761. }
  21762. }
  21763. var isEditable = ownerID && ownerID === this.ownerID;
  21764. var newNodes = setIn(nodes, idx, newNode, isEditable);
  21765. if (isEditable) {
  21766. this.count = newCount;
  21767. this.nodes = newNodes;
  21768. return this;
  21769. }
  21770. return new HashArrayMapNode(ownerID, newCount, newNodes);
  21771. };
  21772. function HashCollisionNode(ownerID, keyHash, entries) {
  21773. this.ownerID = ownerID;
  21774. this.keyHash = keyHash;
  21775. this.entries = entries;
  21776. }
  21777. HashCollisionNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  21778. var entries = this.entries;
  21779. for (var ii = 0, len = entries.length; ii < len; ii++) {
  21780. if (is(key, entries[ii][0])) {
  21781. return entries[ii][1];
  21782. }
  21783. }
  21784. return notSetValue;
  21785. };
  21786. HashCollisionNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  21787. if (keyHash === undefined) {
  21788. keyHash = hash(key);
  21789. }
  21790. var removed = value === NOT_SET;
  21791. if (keyHash !== this.keyHash) {
  21792. if (removed) {
  21793. return this;
  21794. }
  21795. SetRef(didAlter);
  21796. SetRef(didChangeSize);
  21797. return mergeIntoNode(this, ownerID, shift, keyHash, [key, value]);
  21798. }
  21799. var entries = this.entries;
  21800. var idx = 0;
  21801. for (var len = entries.length; idx < len; idx++) {
  21802. if (is(key, entries[idx][0])) {
  21803. break;
  21804. }
  21805. }
  21806. var exists = idx < len;
  21807. if (exists ? entries[idx][1] === value : removed) {
  21808. return this;
  21809. }
  21810. SetRef(didAlter);
  21811. (removed || !exists) && SetRef(didChangeSize);
  21812. if (removed && len === 2) {
  21813. return new ValueNode(ownerID, this.keyHash, entries[idx ^ 1]);
  21814. }
  21815. var isEditable = ownerID && ownerID === this.ownerID;
  21816. var newEntries = isEditable ? entries : arrCopy(entries);
  21817. if (exists) {
  21818. if (removed) {
  21819. idx === len - 1 ? newEntries.pop() : (newEntries[idx] = newEntries.pop());
  21820. } else {
  21821. newEntries[idx] = [key, value];
  21822. }
  21823. } else {
  21824. newEntries.push([key, value]);
  21825. }
  21826. if (isEditable) {
  21827. this.entries = newEntries;
  21828. return this;
  21829. }
  21830. return new HashCollisionNode(ownerID, this.keyHash, newEntries);
  21831. };
  21832. function ValueNode(ownerID, keyHash, entry) {
  21833. this.ownerID = ownerID;
  21834. this.keyHash = keyHash;
  21835. this.entry = entry;
  21836. }
  21837. ValueNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  21838. return is(key, this.entry[0]) ? this.entry[1] : notSetValue;
  21839. };
  21840. ValueNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  21841. var removed = value === NOT_SET;
  21842. var keyMatch = is(key, this.entry[0]);
  21843. if (keyMatch ? value === this.entry[1] : removed) {
  21844. return this;
  21845. }
  21846. SetRef(didAlter);
  21847. if (removed) {
  21848. SetRef(didChangeSize);
  21849. return; // undefined
  21850. }
  21851. if (keyMatch) {
  21852. if (ownerID && ownerID === this.ownerID) {
  21853. this.entry[1] = value;
  21854. return this;
  21855. }
  21856. return new ValueNode(ownerID, this.keyHash, [key, value]);
  21857. }
  21858. SetRef(didChangeSize);
  21859. return mergeIntoNode(this, ownerID, shift, hash(key), [key, value]);
  21860. };
  21861. // #pragma Iterators
  21862. ArrayMapNode.prototype.iterate =
  21863. HashCollisionNode.prototype.iterate = function (fn, reverse) {
  21864. var entries = this.entries;
  21865. for (var ii = 0, maxIndex = entries.length - 1; ii <= maxIndex; ii++) {
  21866. if (fn(entries[reverse ? maxIndex - ii : ii]) === false) {
  21867. return false;
  21868. }
  21869. }
  21870. };
  21871. BitmapIndexedNode.prototype.iterate =
  21872. HashArrayMapNode.prototype.iterate = function (fn, reverse) {
  21873. var nodes = this.nodes;
  21874. for (var ii = 0, maxIndex = nodes.length - 1; ii <= maxIndex; ii++) {
  21875. var node = nodes[reverse ? maxIndex - ii : ii];
  21876. if (node && node.iterate(fn, reverse) === false) {
  21877. return false;
  21878. }
  21879. }
  21880. };
  21881. ValueNode.prototype.iterate = function (fn, reverse) {
  21882. return fn(this.entry);
  21883. };
  21884. createClass(MapIterator, Iterator);
  21885. function MapIterator(map, type, reverse) {
  21886. this._type = type;
  21887. this._reverse = reverse;
  21888. this._stack = map._root && mapIteratorFrame(map._root);
  21889. }
  21890. MapIterator.prototype.next = function() {
  21891. var type = this._type;
  21892. var stack = this._stack;
  21893. while (stack) {
  21894. var node = stack.node;
  21895. var index = stack.index++;
  21896. var maxIndex;
  21897. if (node.entry) {
  21898. if (index === 0) {
  21899. return mapIteratorValue(type, node.entry);
  21900. }
  21901. } else if (node.entries) {
  21902. maxIndex = node.entries.length - 1;
  21903. if (index <= maxIndex) {
  21904. return mapIteratorValue(type, node.entries[this._reverse ? maxIndex - index : index]);
  21905. }
  21906. } else {
  21907. maxIndex = node.nodes.length - 1;
  21908. if (index <= maxIndex) {
  21909. var subNode = node.nodes[this._reverse ? maxIndex - index : index];
  21910. if (subNode) {
  21911. if (subNode.entry) {
  21912. return mapIteratorValue(type, subNode.entry);
  21913. }
  21914. stack = this._stack = mapIteratorFrame(subNode, stack);
  21915. }
  21916. continue;
  21917. }
  21918. }
  21919. stack = this._stack = this._stack.__prev;
  21920. }
  21921. return iteratorDone();
  21922. };
  21923. function mapIteratorValue(type, entry) {
  21924. return iteratorValue(type, entry[0], entry[1]);
  21925. }
  21926. function mapIteratorFrame(node, prev) {
  21927. return {
  21928. node: node,
  21929. index: 0,
  21930. __prev: prev
  21931. };
  21932. }
  21933. function makeMap(size, root, ownerID, hash) {
  21934. var map = Object.create(MapPrototype);
  21935. map.size = size;
  21936. map._root = root;
  21937. map.__ownerID = ownerID;
  21938. map.__hash = hash;
  21939. map.__altered = false;
  21940. return map;
  21941. }
  21942. var EMPTY_MAP;
  21943. function emptyMap() {
  21944. return EMPTY_MAP || (EMPTY_MAP = makeMap(0));
  21945. }
  21946. function updateMap(map, k, v) {
  21947. var newRoot;
  21948. var newSize;
  21949. if (!map._root) {
  21950. if (v === NOT_SET) {
  21951. return map;
  21952. }
  21953. newSize = 1;
  21954. newRoot = new ArrayMapNode(map.__ownerID, [[k, v]]);
  21955. } else {
  21956. var didChangeSize = MakeRef(CHANGE_LENGTH);
  21957. var didAlter = MakeRef(DID_ALTER);
  21958. newRoot = updateNode(map._root, map.__ownerID, 0, undefined, k, v, didChangeSize, didAlter);
  21959. if (!didAlter.value) {
  21960. return map;
  21961. }
  21962. newSize = map.size + (didChangeSize.value ? v === NOT_SET ? -1 : 1 : 0);
  21963. }
  21964. if (map.__ownerID) {
  21965. map.size = newSize;
  21966. map._root = newRoot;
  21967. map.__hash = undefined;
  21968. map.__altered = true;
  21969. return map;
  21970. }
  21971. return newRoot ? makeMap(newSize, newRoot) : emptyMap();
  21972. }
  21973. function updateNode(node, ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  21974. if (!node) {
  21975. if (value === NOT_SET) {
  21976. return node;
  21977. }
  21978. SetRef(didAlter);
  21979. SetRef(didChangeSize);
  21980. return new ValueNode(ownerID, keyHash, [key, value]);
  21981. }
  21982. return node.update(ownerID, shift, keyHash, key, value, didChangeSize, didAlter);
  21983. }
  21984. function isLeafNode(node) {
  21985. return node.constructor === ValueNode || node.constructor === HashCollisionNode;
  21986. }
  21987. function mergeIntoNode(node, ownerID, shift, keyHash, entry) {
  21988. if (node.keyHash === keyHash) {
  21989. return new HashCollisionNode(ownerID, keyHash, [node.entry, entry]);
  21990. }
  21991. var idx1 = (shift === 0 ? node.keyHash : node.keyHash >>> shift) & MASK;
  21992. var idx2 = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  21993. var newNode;
  21994. var nodes = idx1 === idx2 ?
  21995. [mergeIntoNode(node, ownerID, shift + SHIFT, keyHash, entry)] :
  21996. ((newNode = new ValueNode(ownerID, keyHash, entry)), idx1 < idx2 ? [node, newNode] : [newNode, node]);
  21997. return new BitmapIndexedNode(ownerID, (1 << idx1) | (1 << idx2), nodes);
  21998. }
  21999. function createNodes(ownerID, entries, key, value) {
  22000. if (!ownerID) {
  22001. ownerID = new OwnerID();
  22002. }
  22003. var node = new ValueNode(ownerID, hash(key), [key, value]);
  22004. for (var ii = 0; ii < entries.length; ii++) {
  22005. var entry = entries[ii];
  22006. node = node.update(ownerID, 0, undefined, entry[0], entry[1]);
  22007. }
  22008. return node;
  22009. }
  22010. function packNodes(ownerID, nodes, count, excluding) {
  22011. var bitmap = 0;
  22012. var packedII = 0;
  22013. var packedNodes = new Array(count);
  22014. for (var ii = 0, bit = 1, len = nodes.length; ii < len; ii++, bit <<= 1) {
  22015. var node = nodes[ii];
  22016. if (node !== undefined && ii !== excluding) {
  22017. bitmap |= bit;
  22018. packedNodes[packedII++] = node;
  22019. }
  22020. }
  22021. return new BitmapIndexedNode(ownerID, bitmap, packedNodes);
  22022. }
  22023. function expandNodes(ownerID, nodes, bitmap, including, node) {
  22024. var count = 0;
  22025. var expandedNodes = new Array(SIZE);
  22026. for (var ii = 0; bitmap !== 0; ii++, bitmap >>>= 1) {
  22027. expandedNodes[ii] = bitmap & 1 ? nodes[count++] : undefined;
  22028. }
  22029. expandedNodes[including] = node;
  22030. return new HashArrayMapNode(ownerID, count + 1, expandedNodes);
  22031. }
  22032. function mergeIntoMapWith(map, merger, iterables) {
  22033. var iters = [];
  22034. for (var ii = 0; ii < iterables.length; ii++) {
  22035. var value = iterables[ii];
  22036. var iter = KeyedIterable(value);
  22037. if (!isIterable(value)) {
  22038. iter = iter.map(function(v ) {return fromJS(v)});
  22039. }
  22040. iters.push(iter);
  22041. }
  22042. return mergeIntoCollectionWith(map, merger, iters);
  22043. }
  22044. function deepMerger(existing, value, key) {
  22045. return existing && existing.mergeDeep && isIterable(value) ?
  22046. existing.mergeDeep(value) :
  22047. is(existing, value) ? existing : value;
  22048. }
  22049. function deepMergerWith(merger) {
  22050. return function(existing, value, key) {
  22051. if (existing && existing.mergeDeepWith && isIterable(value)) {
  22052. return existing.mergeDeepWith(merger, value);
  22053. }
  22054. var nextValue = merger(existing, value, key);
  22055. return is(existing, nextValue) ? existing : nextValue;
  22056. };
  22057. }
  22058. function mergeIntoCollectionWith(collection, merger, iters) {
  22059. iters = iters.filter(function(x ) {return x.size !== 0});
  22060. if (iters.length === 0) {
  22061. return collection;
  22062. }
  22063. if (collection.size === 0 && !collection.__ownerID && iters.length === 1) {
  22064. return collection.constructor(iters[0]);
  22065. }
  22066. return collection.withMutations(function(collection ) {
  22067. var mergeIntoMap = merger ?
  22068. function(value, key) {
  22069. collection.update(key, NOT_SET, function(existing )
  22070. {return existing === NOT_SET ? value : merger(existing, value, key)}
  22071. );
  22072. } :
  22073. function(value, key) {
  22074. collection.set(key, value);
  22075. };
  22076. for (var ii = 0; ii < iters.length; ii++) {
  22077. iters[ii].forEach(mergeIntoMap);
  22078. }
  22079. });
  22080. }
  22081. function updateInDeepMap(existing, keyPathIter, notSetValue, updater) {
  22082. var isNotSet = existing === NOT_SET;
  22083. var step = keyPathIter.next();
  22084. if (step.done) {
  22085. var existingValue = isNotSet ? notSetValue : existing;
  22086. var newValue = updater(existingValue);
  22087. return newValue === existingValue ? existing : newValue;
  22088. }
  22089. invariant(
  22090. isNotSet || (existing && existing.set),
  22091. 'invalid keyPath'
  22092. );
  22093. var key = step.value;
  22094. var nextExisting = isNotSet ? NOT_SET : existing.get(key, NOT_SET);
  22095. var nextUpdated = updateInDeepMap(
  22096. nextExisting,
  22097. keyPathIter,
  22098. notSetValue,
  22099. updater
  22100. );
  22101. return nextUpdated === nextExisting ? existing :
  22102. nextUpdated === NOT_SET ? existing.remove(key) :
  22103. (isNotSet ? emptyMap() : existing).set(key, nextUpdated);
  22104. }
  22105. function popCount(x) {
  22106. x = x - ((x >> 1) & 0x55555555);
  22107. x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
  22108. x = (x + (x >> 4)) & 0x0f0f0f0f;
  22109. x = x + (x >> 8);
  22110. x = x + (x >> 16);
  22111. return x & 0x7f;
  22112. }
  22113. function setIn(array, idx, val, canEdit) {
  22114. var newArray = canEdit ? array : arrCopy(array);
  22115. newArray[idx] = val;
  22116. return newArray;
  22117. }
  22118. function spliceIn(array, idx, val, canEdit) {
  22119. var newLen = array.length + 1;
  22120. if (canEdit && idx + 1 === newLen) {
  22121. array[idx] = val;
  22122. return array;
  22123. }
  22124. var newArray = new Array(newLen);
  22125. var after = 0;
  22126. for (var ii = 0; ii < newLen; ii++) {
  22127. if (ii === idx) {
  22128. newArray[ii] = val;
  22129. after = -1;
  22130. } else {
  22131. newArray[ii] = array[ii + after];
  22132. }
  22133. }
  22134. return newArray;
  22135. }
  22136. function spliceOut(array, idx, canEdit) {
  22137. var newLen = array.length - 1;
  22138. if (canEdit && idx === newLen) {
  22139. array.pop();
  22140. return array;
  22141. }
  22142. var newArray = new Array(newLen);
  22143. var after = 0;
  22144. for (var ii = 0; ii < newLen; ii++) {
  22145. if (ii === idx) {
  22146. after = 1;
  22147. }
  22148. newArray[ii] = array[ii + after];
  22149. }
  22150. return newArray;
  22151. }
  22152. var MAX_ARRAY_MAP_SIZE = SIZE / 4;
  22153. var MAX_BITMAP_INDEXED_SIZE = SIZE / 2;
  22154. var MIN_HASH_ARRAY_MAP_SIZE = SIZE / 4;
  22155. createClass(List, IndexedCollection);
  22156. // @pragma Construction
  22157. function List(value) {
  22158. var empty = emptyList();
  22159. if (value === null || value === undefined) {
  22160. return empty;
  22161. }
  22162. if (isList(value)) {
  22163. return value;
  22164. }
  22165. var iter = IndexedIterable(value);
  22166. var size = iter.size;
  22167. if (size === 0) {
  22168. return empty;
  22169. }
  22170. assertNotInfinite(size);
  22171. if (size > 0 && size < SIZE) {
  22172. return makeList(0, size, SHIFT, null, new VNode(iter.toArray()));
  22173. }
  22174. return empty.withMutations(function(list ) {
  22175. list.setSize(size);
  22176. iter.forEach(function(v, i) {return list.set(i, v)});
  22177. });
  22178. }
  22179. List.of = function(/*...values*/) {
  22180. return this(arguments);
  22181. };
  22182. List.prototype.toString = function() {
  22183. return this.__toString('List [', ']');
  22184. };
  22185. // @pragma Access
  22186. List.prototype.get = function(index, notSetValue) {
  22187. index = wrapIndex(this, index);
  22188. if (index >= 0 && index < this.size) {
  22189. index += this._origin;
  22190. var node = listNodeFor(this, index);
  22191. return node && node.array[index & MASK];
  22192. }
  22193. return notSetValue;
  22194. };
  22195. // @pragma Modification
  22196. List.prototype.set = function(index, value) {
  22197. return updateList(this, index, value);
  22198. };
  22199. List.prototype.remove = function(index) {
  22200. return !this.has(index) ? this :
  22201. index === 0 ? this.shift() :
  22202. index === this.size - 1 ? this.pop() :
  22203. this.splice(index, 1);
  22204. };
  22205. List.prototype.insert = function(index, value) {
  22206. return this.splice(index, 0, value);
  22207. };
  22208. List.prototype.clear = function() {
  22209. if (this.size === 0) {
  22210. return this;
  22211. }
  22212. if (this.__ownerID) {
  22213. this.size = this._origin = this._capacity = 0;
  22214. this._level = SHIFT;
  22215. this._root = this._tail = null;
  22216. this.__hash = undefined;
  22217. this.__altered = true;
  22218. return this;
  22219. }
  22220. return emptyList();
  22221. };
  22222. List.prototype.push = function(/*...values*/) {
  22223. var values = arguments;
  22224. var oldSize = this.size;
  22225. return this.withMutations(function(list ) {
  22226. setListBounds(list, 0, oldSize + values.length);
  22227. for (var ii = 0; ii < values.length; ii++) {
  22228. list.set(oldSize + ii, values[ii]);
  22229. }
  22230. });
  22231. };
  22232. List.prototype.pop = function() {
  22233. return setListBounds(this, 0, -1);
  22234. };
  22235. List.prototype.unshift = function(/*...values*/) {
  22236. var values = arguments;
  22237. return this.withMutations(function(list ) {
  22238. setListBounds(list, -values.length);
  22239. for (var ii = 0; ii < values.length; ii++) {
  22240. list.set(ii, values[ii]);
  22241. }
  22242. });
  22243. };
  22244. List.prototype.shift = function() {
  22245. return setListBounds(this, 1);
  22246. };
  22247. // @pragma Composition
  22248. List.prototype.merge = function(/*...iters*/) {
  22249. return mergeIntoListWith(this, undefined, arguments);
  22250. };
  22251. List.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  22252. return mergeIntoListWith(this, merger, iters);
  22253. };
  22254. List.prototype.mergeDeep = function(/*...iters*/) {
  22255. return mergeIntoListWith(this, deepMerger, arguments);
  22256. };
  22257. List.prototype.mergeDeepWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  22258. return mergeIntoListWith(this, deepMergerWith(merger), iters);
  22259. };
  22260. List.prototype.setSize = function(size) {
  22261. return setListBounds(this, 0, size);
  22262. };
  22263. // @pragma Iteration
  22264. List.prototype.slice = function(begin, end) {
  22265. var size = this.size;
  22266. if (wholeSlice(begin, end, size)) {
  22267. return this;
  22268. }
  22269. return setListBounds(
  22270. this,
  22271. resolveBegin(begin, size),
  22272. resolveEnd(end, size)
  22273. );
  22274. };
  22275. List.prototype.__iterator = function(type, reverse) {
  22276. var index = 0;
  22277. var values = iterateList(this, reverse);
  22278. return new Iterator(function() {
  22279. var value = values();
  22280. return value === DONE ?
  22281. iteratorDone() :
  22282. iteratorValue(type, index++, value);
  22283. });
  22284. };
  22285. List.prototype.__iterate = function(fn, reverse) {
  22286. var index = 0;
  22287. var values = iterateList(this, reverse);
  22288. var value;
  22289. while ((value = values()) !== DONE) {
  22290. if (fn(value, index++, this) === false) {
  22291. break;
  22292. }
  22293. }
  22294. return index;
  22295. };
  22296. List.prototype.__ensureOwner = function(ownerID) {
  22297. if (ownerID === this.__ownerID) {
  22298. return this;
  22299. }
  22300. if (!ownerID) {
  22301. this.__ownerID = ownerID;
  22302. return this;
  22303. }
  22304. return makeList(this._origin, this._capacity, this._level, this._root, this._tail, ownerID, this.__hash);
  22305. };
  22306. function isList(maybeList) {
  22307. return !!(maybeList && maybeList[IS_LIST_SENTINEL]);
  22308. }
  22309. List.isList = isList;
  22310. var IS_LIST_SENTINEL = '@@__IMMUTABLE_LIST__@@';
  22311. var ListPrototype = List.prototype;
  22312. ListPrototype[IS_LIST_SENTINEL] = true;
  22313. ListPrototype[DELETE] = ListPrototype.remove;
  22314. ListPrototype.setIn = MapPrototype.setIn;
  22315. ListPrototype.deleteIn =
  22316. ListPrototype.removeIn = MapPrototype.removeIn;
  22317. ListPrototype.update = MapPrototype.update;
  22318. ListPrototype.updateIn = MapPrototype.updateIn;
  22319. ListPrototype.mergeIn = MapPrototype.mergeIn;
  22320. ListPrototype.mergeDeepIn = MapPrototype.mergeDeepIn;
  22321. ListPrototype.withMutations = MapPrototype.withMutations;
  22322. ListPrototype.asMutable = MapPrototype.asMutable;
  22323. ListPrototype.asImmutable = MapPrototype.asImmutable;
  22324. ListPrototype.wasAltered = MapPrototype.wasAltered;
  22325. function VNode(array, ownerID) {
  22326. this.array = array;
  22327. this.ownerID = ownerID;
  22328. }
  22329. // TODO: seems like these methods are very similar
  22330. VNode.prototype.removeBefore = function(ownerID, level, index) {
  22331. if (index === level ? 1 << level : this.array.length === 0) {
  22332. return this;
  22333. }
  22334. var originIndex = (index >>> level) & MASK;
  22335. if (originIndex >= this.array.length) {
  22336. return new VNode([], ownerID);
  22337. }
  22338. var removingFirst = originIndex === 0;
  22339. var newChild;
  22340. if (level > 0) {
  22341. var oldChild = this.array[originIndex];
  22342. newChild = oldChild && oldChild.removeBefore(ownerID, level - SHIFT, index);
  22343. if (newChild === oldChild && removingFirst) {
  22344. return this;
  22345. }
  22346. }
  22347. if (removingFirst && !newChild) {
  22348. return this;
  22349. }
  22350. var editable = editableVNode(this, ownerID);
  22351. if (!removingFirst) {
  22352. for (var ii = 0; ii < originIndex; ii++) {
  22353. editable.array[ii] = undefined;
  22354. }
  22355. }
  22356. if (newChild) {
  22357. editable.array[originIndex] = newChild;
  22358. }
  22359. return editable;
  22360. };
  22361. VNode.prototype.removeAfter = function(ownerID, level, index) {
  22362. if (index === (level ? 1 << level : 0) || this.array.length === 0) {
  22363. return this;
  22364. }
  22365. var sizeIndex = ((index - 1) >>> level) & MASK;
  22366. if (sizeIndex >= this.array.length) {
  22367. return this;
  22368. }
  22369. var newChild;
  22370. if (level > 0) {
  22371. var oldChild = this.array[sizeIndex];
  22372. newChild = oldChild && oldChild.removeAfter(ownerID, level - SHIFT, index);
  22373. if (newChild === oldChild && sizeIndex === this.array.length - 1) {
  22374. return this;
  22375. }
  22376. }
  22377. var editable = editableVNode(this, ownerID);
  22378. editable.array.splice(sizeIndex + 1);
  22379. if (newChild) {
  22380. editable.array[sizeIndex] = newChild;
  22381. }
  22382. return editable;
  22383. };
  22384. var DONE = {};
  22385. function iterateList(list, reverse) {
  22386. var left = list._origin;
  22387. var right = list._capacity;
  22388. var tailPos = getTailOffset(right);
  22389. var tail = list._tail;
  22390. return iterateNodeOrLeaf(list._root, list._level, 0);
  22391. function iterateNodeOrLeaf(node, level, offset) {
  22392. return level === 0 ?
  22393. iterateLeaf(node, offset) :
  22394. iterateNode(node, level, offset);
  22395. }
  22396. function iterateLeaf(node, offset) {
  22397. var array = offset === tailPos ? tail && tail.array : node && node.array;
  22398. var from = offset > left ? 0 : left - offset;
  22399. var to = right - offset;
  22400. if (to > SIZE) {
  22401. to = SIZE;
  22402. }
  22403. return function() {
  22404. if (from === to) {
  22405. return DONE;
  22406. }
  22407. var idx = reverse ? --to : from++;
  22408. return array && array[idx];
  22409. };
  22410. }
  22411. function iterateNode(node, level, offset) {
  22412. var values;
  22413. var array = node && node.array;
  22414. var from = offset > left ? 0 : (left - offset) >> level;
  22415. var to = ((right - offset) >> level) + 1;
  22416. if (to > SIZE) {
  22417. to = SIZE;
  22418. }
  22419. return function() {
  22420. do {
  22421. if (values) {
  22422. var value = values();
  22423. if (value !== DONE) {
  22424. return value;
  22425. }
  22426. values = null;
  22427. }
  22428. if (from === to) {
  22429. return DONE;
  22430. }
  22431. var idx = reverse ? --to : from++;
  22432. values = iterateNodeOrLeaf(
  22433. array && array[idx], level - SHIFT, offset + (idx << level)
  22434. );
  22435. } while (true);
  22436. };
  22437. }
  22438. }
  22439. function makeList(origin, capacity, level, root, tail, ownerID, hash) {
  22440. var list = Object.create(ListPrototype);
  22441. list.size = capacity - origin;
  22442. list._origin = origin;
  22443. list._capacity = capacity;
  22444. list._level = level;
  22445. list._root = root;
  22446. list._tail = tail;
  22447. list.__ownerID = ownerID;
  22448. list.__hash = hash;
  22449. list.__altered = false;
  22450. return list;
  22451. }
  22452. var EMPTY_LIST;
  22453. function emptyList() {
  22454. return EMPTY_LIST || (EMPTY_LIST = makeList(0, 0, SHIFT));
  22455. }
  22456. function updateList(list, index, value) {
  22457. index = wrapIndex(list, index);
  22458. if (index !== index) {
  22459. return list;
  22460. }
  22461. if (index >= list.size || index < 0) {
  22462. return list.withMutations(function(list ) {
  22463. index < 0 ?
  22464. setListBounds(list, index).set(0, value) :
  22465. setListBounds(list, 0, index + 1).set(index, value);
  22466. });
  22467. }
  22468. index += list._origin;
  22469. var newTail = list._tail;
  22470. var newRoot = list._root;
  22471. var didAlter = MakeRef(DID_ALTER);
  22472. if (index >= getTailOffset(list._capacity)) {
  22473. newTail = updateVNode(newTail, list.__ownerID, 0, index, value, didAlter);
  22474. } else {
  22475. newRoot = updateVNode(newRoot, list.__ownerID, list._level, index, value, didAlter);
  22476. }
  22477. if (!didAlter.value) {
  22478. return list;
  22479. }
  22480. if (list.__ownerID) {
  22481. list._root = newRoot;
  22482. list._tail = newTail;
  22483. list.__hash = undefined;
  22484. list.__altered = true;
  22485. return list;
  22486. }
  22487. return makeList(list._origin, list._capacity, list._level, newRoot, newTail);
  22488. }
  22489. function updateVNode(node, ownerID, level, index, value, didAlter) {
  22490. var idx = (index >>> level) & MASK;
  22491. var nodeHas = node && idx < node.array.length;
  22492. if (!nodeHas && value === undefined) {
  22493. return node;
  22494. }
  22495. var newNode;
  22496. if (level > 0) {
  22497. var lowerNode = node && node.array[idx];
  22498. var newLowerNode = updateVNode(lowerNode, ownerID, level - SHIFT, index, value, didAlter);
  22499. if (newLowerNode === lowerNode) {
  22500. return node;
  22501. }
  22502. newNode = editableVNode(node, ownerID);
  22503. newNode.array[idx] = newLowerNode;
  22504. return newNode;
  22505. }
  22506. if (nodeHas && node.array[idx] === value) {
  22507. return node;
  22508. }
  22509. SetRef(didAlter);
  22510. newNode = editableVNode(node, ownerID);
  22511. if (value === undefined && idx === newNode.array.length - 1) {
  22512. newNode.array.pop();
  22513. } else {
  22514. newNode.array[idx] = value;
  22515. }
  22516. return newNode;
  22517. }
  22518. function editableVNode(node, ownerID) {
  22519. if (ownerID && node && ownerID === node.ownerID) {
  22520. return node;
  22521. }
  22522. return new VNode(node ? node.array.slice() : [], ownerID);
  22523. }
  22524. function listNodeFor(list, rawIndex) {
  22525. if (rawIndex >= getTailOffset(list._capacity)) {
  22526. return list._tail;
  22527. }
  22528. if (rawIndex < 1 << (list._level + SHIFT)) {
  22529. var node = list._root;
  22530. var level = list._level;
  22531. while (node && level > 0) {
  22532. node = node.array[(rawIndex >>> level) & MASK];
  22533. level -= SHIFT;
  22534. }
  22535. return node;
  22536. }
  22537. }
  22538. function setListBounds(list, begin, end) {
  22539. // Sanitize begin & end using this shorthand for ToInt32(argument)
  22540. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  22541. if (begin !== undefined) {
  22542. begin = begin | 0;
  22543. }
  22544. if (end !== undefined) {
  22545. end = end | 0;
  22546. }
  22547. var owner = list.__ownerID || new OwnerID();
  22548. var oldOrigin = list._origin;
  22549. var oldCapacity = list._capacity;
  22550. var newOrigin = oldOrigin + begin;
  22551. var newCapacity = end === undefined ? oldCapacity : end < 0 ? oldCapacity + end : oldOrigin + end;
  22552. if (newOrigin === oldOrigin && newCapacity === oldCapacity) {
  22553. return list;
  22554. }
  22555. // If it's going to end after it starts, it's empty.
  22556. if (newOrigin >= newCapacity) {
  22557. return list.clear();
  22558. }
  22559. var newLevel = list._level;
  22560. var newRoot = list._root;
  22561. // New origin might need creating a higher root.
  22562. var offsetShift = 0;
  22563. while (newOrigin + offsetShift < 0) {
  22564. newRoot = new VNode(newRoot && newRoot.array.length ? [undefined, newRoot] : [], owner);
  22565. newLevel += SHIFT;
  22566. offsetShift += 1 << newLevel;
  22567. }
  22568. if (offsetShift) {
  22569. newOrigin += offsetShift;
  22570. oldOrigin += offsetShift;
  22571. newCapacity += offsetShift;
  22572. oldCapacity += offsetShift;
  22573. }
  22574. var oldTailOffset = getTailOffset(oldCapacity);
  22575. var newTailOffset = getTailOffset(newCapacity);
  22576. // New size might need creating a higher root.
  22577. while (newTailOffset >= 1 << (newLevel + SHIFT)) {
  22578. newRoot = new VNode(newRoot && newRoot.array.length ? [newRoot] : [], owner);
  22579. newLevel += SHIFT;
  22580. }
  22581. // Locate or create the new tail.
  22582. var oldTail = list._tail;
  22583. var newTail = newTailOffset < oldTailOffset ?
  22584. listNodeFor(list, newCapacity - 1) :
  22585. newTailOffset > oldTailOffset ? new VNode([], owner) : oldTail;
  22586. // Merge Tail into tree.
  22587. if (oldTail && newTailOffset > oldTailOffset && newOrigin < oldCapacity && oldTail.array.length) {
  22588. newRoot = editableVNode(newRoot, owner);
  22589. var node = newRoot;
  22590. for (var level = newLevel; level > SHIFT; level -= SHIFT) {
  22591. var idx = (oldTailOffset >>> level) & MASK;
  22592. node = node.array[idx] = editableVNode(node.array[idx], owner);
  22593. }
  22594. node.array[(oldTailOffset >>> SHIFT) & MASK] = oldTail;
  22595. }
  22596. // If the size has been reduced, there's a chance the tail needs to be trimmed.
  22597. if (newCapacity < oldCapacity) {
  22598. newTail = newTail && newTail.removeAfter(owner, 0, newCapacity);
  22599. }
  22600. // If the new origin is within the tail, then we do not need a root.
  22601. if (newOrigin >= newTailOffset) {
  22602. newOrigin -= newTailOffset;
  22603. newCapacity -= newTailOffset;
  22604. newLevel = SHIFT;
  22605. newRoot = null;
  22606. newTail = newTail && newTail.removeBefore(owner, 0, newOrigin);
  22607. // Otherwise, if the root has been trimmed, garbage collect.
  22608. } else if (newOrigin > oldOrigin || newTailOffset < oldTailOffset) {
  22609. offsetShift = 0;
  22610. // Identify the new top root node of the subtree of the old root.
  22611. while (newRoot) {
  22612. var beginIndex = (newOrigin >>> newLevel) & MASK;
  22613. if (beginIndex !== (newTailOffset >>> newLevel) & MASK) {
  22614. break;
  22615. }
  22616. if (beginIndex) {
  22617. offsetShift += (1 << newLevel) * beginIndex;
  22618. }
  22619. newLevel -= SHIFT;
  22620. newRoot = newRoot.array[beginIndex];
  22621. }
  22622. // Trim the new sides of the new root.
  22623. if (newRoot && newOrigin > oldOrigin) {
  22624. newRoot = newRoot.removeBefore(owner, newLevel, newOrigin - offsetShift);
  22625. }
  22626. if (newRoot && newTailOffset < oldTailOffset) {
  22627. newRoot = newRoot.removeAfter(owner, newLevel, newTailOffset - offsetShift);
  22628. }
  22629. if (offsetShift) {
  22630. newOrigin -= offsetShift;
  22631. newCapacity -= offsetShift;
  22632. }
  22633. }
  22634. if (list.__ownerID) {
  22635. list.size = newCapacity - newOrigin;
  22636. list._origin = newOrigin;
  22637. list._capacity = newCapacity;
  22638. list._level = newLevel;
  22639. list._root = newRoot;
  22640. list._tail = newTail;
  22641. list.__hash = undefined;
  22642. list.__altered = true;
  22643. return list;
  22644. }
  22645. return makeList(newOrigin, newCapacity, newLevel, newRoot, newTail);
  22646. }
  22647. function mergeIntoListWith(list, merger, iterables) {
  22648. var iters = [];
  22649. var maxSize = 0;
  22650. for (var ii = 0; ii < iterables.length; ii++) {
  22651. var value = iterables[ii];
  22652. var iter = IndexedIterable(value);
  22653. if (iter.size > maxSize) {
  22654. maxSize = iter.size;
  22655. }
  22656. if (!isIterable(value)) {
  22657. iter = iter.map(function(v ) {return fromJS(v)});
  22658. }
  22659. iters.push(iter);
  22660. }
  22661. if (maxSize > list.size) {
  22662. list = list.setSize(maxSize);
  22663. }
  22664. return mergeIntoCollectionWith(list, merger, iters);
  22665. }
  22666. function getTailOffset(size) {
  22667. return size < SIZE ? 0 : (((size - 1) >>> SHIFT) << SHIFT);
  22668. }
  22669. createClass(OrderedMap, Map);
  22670. // @pragma Construction
  22671. function OrderedMap(value) {
  22672. return value === null || value === undefined ? emptyOrderedMap() :
  22673. isOrderedMap(value) ? value :
  22674. emptyOrderedMap().withMutations(function(map ) {
  22675. var iter = KeyedIterable(value);
  22676. assertNotInfinite(iter.size);
  22677. iter.forEach(function(v, k) {return map.set(k, v)});
  22678. });
  22679. }
  22680. OrderedMap.of = function(/*...values*/) {
  22681. return this(arguments);
  22682. };
  22683. OrderedMap.prototype.toString = function() {
  22684. return this.__toString('OrderedMap {', '}');
  22685. };
  22686. // @pragma Access
  22687. OrderedMap.prototype.get = function(k, notSetValue) {
  22688. var index = this._map.get(k);
  22689. return index !== undefined ? this._list.get(index)[1] : notSetValue;
  22690. };
  22691. // @pragma Modification
  22692. OrderedMap.prototype.clear = function() {
  22693. if (this.size === 0) {
  22694. return this;
  22695. }
  22696. if (this.__ownerID) {
  22697. this.size = 0;
  22698. this._map.clear();
  22699. this._list.clear();
  22700. return this;
  22701. }
  22702. return emptyOrderedMap();
  22703. };
  22704. OrderedMap.prototype.set = function(k, v) {
  22705. return updateOrderedMap(this, k, v);
  22706. };
  22707. OrderedMap.prototype.remove = function(k) {
  22708. return updateOrderedMap(this, k, NOT_SET);
  22709. };
  22710. OrderedMap.prototype.wasAltered = function() {
  22711. return this._map.wasAltered() || this._list.wasAltered();
  22712. };
  22713. OrderedMap.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  22714. return this._list.__iterate(
  22715. function(entry ) {return entry && fn(entry[1], entry[0], this$0)},
  22716. reverse
  22717. );
  22718. };
  22719. OrderedMap.prototype.__iterator = function(type, reverse) {
  22720. return this._list.fromEntrySeq().__iterator(type, reverse);
  22721. };
  22722. OrderedMap.prototype.__ensureOwner = function(ownerID) {
  22723. if (ownerID === this.__ownerID) {
  22724. return this;
  22725. }
  22726. var newMap = this._map.__ensureOwner(ownerID);
  22727. var newList = this._list.__ensureOwner(ownerID);
  22728. if (!ownerID) {
  22729. this.__ownerID = ownerID;
  22730. this._map = newMap;
  22731. this._list = newList;
  22732. return this;
  22733. }
  22734. return makeOrderedMap(newMap, newList, ownerID, this.__hash);
  22735. };
  22736. function isOrderedMap(maybeOrderedMap) {
  22737. return isMap(maybeOrderedMap) && isOrdered(maybeOrderedMap);
  22738. }
  22739. OrderedMap.isOrderedMap = isOrderedMap;
  22740. OrderedMap.prototype[IS_ORDERED_SENTINEL] = true;
  22741. OrderedMap.prototype[DELETE] = OrderedMap.prototype.remove;
  22742. function makeOrderedMap(map, list, ownerID, hash) {
  22743. var omap = Object.create(OrderedMap.prototype);
  22744. omap.size = map ? map.size : 0;
  22745. omap._map = map;
  22746. omap._list = list;
  22747. omap.__ownerID = ownerID;
  22748. omap.__hash = hash;
  22749. return omap;
  22750. }
  22751. var EMPTY_ORDERED_MAP;
  22752. function emptyOrderedMap() {
  22753. return EMPTY_ORDERED_MAP || (EMPTY_ORDERED_MAP = makeOrderedMap(emptyMap(), emptyList()));
  22754. }
  22755. function updateOrderedMap(omap, k, v) {
  22756. var map = omap._map;
  22757. var list = omap._list;
  22758. var i = map.get(k);
  22759. var has = i !== undefined;
  22760. var newMap;
  22761. var newList;
  22762. if (v === NOT_SET) { // removed
  22763. if (!has) {
  22764. return omap;
  22765. }
  22766. if (list.size >= SIZE && list.size >= map.size * 2) {
  22767. newList = list.filter(function(entry, idx) {return entry !== undefined && i !== idx});
  22768. newMap = newList.toKeyedSeq().map(function(entry ) {return entry[0]}).flip().toMap();
  22769. if (omap.__ownerID) {
  22770. newMap.__ownerID = newList.__ownerID = omap.__ownerID;
  22771. }
  22772. } else {
  22773. newMap = map.remove(k);
  22774. newList = i === list.size - 1 ? list.pop() : list.set(i, undefined);
  22775. }
  22776. } else {
  22777. if (has) {
  22778. if (v === list.get(i)[1]) {
  22779. return omap;
  22780. }
  22781. newMap = map;
  22782. newList = list.set(i, [k, v]);
  22783. } else {
  22784. newMap = map.set(k, list.size);
  22785. newList = list.set(list.size, [k, v]);
  22786. }
  22787. }
  22788. if (omap.__ownerID) {
  22789. omap.size = newMap.size;
  22790. omap._map = newMap;
  22791. omap._list = newList;
  22792. omap.__hash = undefined;
  22793. return omap;
  22794. }
  22795. return makeOrderedMap(newMap, newList);
  22796. }
  22797. createClass(ToKeyedSequence, KeyedSeq);
  22798. function ToKeyedSequence(indexed, useKeys) {
  22799. this._iter = indexed;
  22800. this._useKeys = useKeys;
  22801. this.size = indexed.size;
  22802. }
  22803. ToKeyedSequence.prototype.get = function(key, notSetValue) {
  22804. return this._iter.get(key, notSetValue);
  22805. };
  22806. ToKeyedSequence.prototype.has = function(key) {
  22807. return this._iter.has(key);
  22808. };
  22809. ToKeyedSequence.prototype.valueSeq = function() {
  22810. return this._iter.valueSeq();
  22811. };
  22812. ToKeyedSequence.prototype.reverse = function() {var this$0 = this;
  22813. var reversedSequence = reverseFactory(this, true);
  22814. if (!this._useKeys) {
  22815. reversedSequence.valueSeq = function() {return this$0._iter.toSeq().reverse()};
  22816. }
  22817. return reversedSequence;
  22818. };
  22819. ToKeyedSequence.prototype.map = function(mapper, context) {var this$0 = this;
  22820. var mappedSequence = mapFactory(this, mapper, context);
  22821. if (!this._useKeys) {
  22822. mappedSequence.valueSeq = function() {return this$0._iter.toSeq().map(mapper, context)};
  22823. }
  22824. return mappedSequence;
  22825. };
  22826. ToKeyedSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  22827. var ii;
  22828. return this._iter.__iterate(
  22829. this._useKeys ?
  22830. function(v, k) {return fn(v, k, this$0)} :
  22831. ((ii = reverse ? resolveSize(this) : 0),
  22832. function(v ) {return fn(v, reverse ? --ii : ii++, this$0)}),
  22833. reverse
  22834. );
  22835. };
  22836. ToKeyedSequence.prototype.__iterator = function(type, reverse) {
  22837. if (this._useKeys) {
  22838. return this._iter.__iterator(type, reverse);
  22839. }
  22840. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  22841. var ii = reverse ? resolveSize(this) : 0;
  22842. return new Iterator(function() {
  22843. var step = iterator.next();
  22844. return step.done ? step :
  22845. iteratorValue(type, reverse ? --ii : ii++, step.value, step);
  22846. });
  22847. };
  22848. ToKeyedSequence.prototype[IS_ORDERED_SENTINEL] = true;
  22849. createClass(ToIndexedSequence, IndexedSeq);
  22850. function ToIndexedSequence(iter) {
  22851. this._iter = iter;
  22852. this.size = iter.size;
  22853. }
  22854. ToIndexedSequence.prototype.includes = function(value) {
  22855. return this._iter.includes(value);
  22856. };
  22857. ToIndexedSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  22858. var iterations = 0;
  22859. return this._iter.__iterate(function(v ) {return fn(v, iterations++, this$0)}, reverse);
  22860. };
  22861. ToIndexedSequence.prototype.__iterator = function(type, reverse) {
  22862. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  22863. var iterations = 0;
  22864. return new Iterator(function() {
  22865. var step = iterator.next();
  22866. return step.done ? step :
  22867. iteratorValue(type, iterations++, step.value, step)
  22868. });
  22869. };
  22870. createClass(ToSetSequence, SetSeq);
  22871. function ToSetSequence(iter) {
  22872. this._iter = iter;
  22873. this.size = iter.size;
  22874. }
  22875. ToSetSequence.prototype.has = function(key) {
  22876. return this._iter.includes(key);
  22877. };
  22878. ToSetSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  22879. return this._iter.__iterate(function(v ) {return fn(v, v, this$0)}, reverse);
  22880. };
  22881. ToSetSequence.prototype.__iterator = function(type, reverse) {
  22882. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  22883. return new Iterator(function() {
  22884. var step = iterator.next();
  22885. return step.done ? step :
  22886. iteratorValue(type, step.value, step.value, step);
  22887. });
  22888. };
  22889. createClass(FromEntriesSequence, KeyedSeq);
  22890. function FromEntriesSequence(entries) {
  22891. this._iter = entries;
  22892. this.size = entries.size;
  22893. }
  22894. FromEntriesSequence.prototype.entrySeq = function() {
  22895. return this._iter.toSeq();
  22896. };
  22897. FromEntriesSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  22898. return this._iter.__iterate(function(entry ) {
  22899. // Check if entry exists first so array access doesn't throw for holes
  22900. // in the parent iteration.
  22901. if (entry) {
  22902. validateEntry(entry);
  22903. var indexedIterable = isIterable(entry);
  22904. return fn(
  22905. indexedIterable ? entry.get(1) : entry[1],
  22906. indexedIterable ? entry.get(0) : entry[0],
  22907. this$0
  22908. );
  22909. }
  22910. }, reverse);
  22911. };
  22912. FromEntriesSequence.prototype.__iterator = function(type, reverse) {
  22913. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  22914. return new Iterator(function() {
  22915. while (true) {
  22916. var step = iterator.next();
  22917. if (step.done) {
  22918. return step;
  22919. }
  22920. var entry = step.value;
  22921. // Check if entry exists first so array access doesn't throw for holes
  22922. // in the parent iteration.
  22923. if (entry) {
  22924. validateEntry(entry);
  22925. var indexedIterable = isIterable(entry);
  22926. return iteratorValue(
  22927. type,
  22928. indexedIterable ? entry.get(0) : entry[0],
  22929. indexedIterable ? entry.get(1) : entry[1],
  22930. step
  22931. );
  22932. }
  22933. }
  22934. });
  22935. };
  22936. ToIndexedSequence.prototype.cacheResult =
  22937. ToKeyedSequence.prototype.cacheResult =
  22938. ToSetSequence.prototype.cacheResult =
  22939. FromEntriesSequence.prototype.cacheResult =
  22940. cacheResultThrough;
  22941. function flipFactory(iterable) {
  22942. var flipSequence = makeSequence(iterable);
  22943. flipSequence._iter = iterable;
  22944. flipSequence.size = iterable.size;
  22945. flipSequence.flip = function() {return iterable};
  22946. flipSequence.reverse = function () {
  22947. var reversedSequence = iterable.reverse.apply(this); // super.reverse()
  22948. reversedSequence.flip = function() {return iterable.reverse()};
  22949. return reversedSequence;
  22950. };
  22951. flipSequence.has = function(key ) {return iterable.includes(key)};
  22952. flipSequence.includes = function(key ) {return iterable.has(key)};
  22953. flipSequence.cacheResult = cacheResultThrough;
  22954. flipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  22955. return iterable.__iterate(function(v, k) {return fn(k, v, this$0) !== false}, reverse);
  22956. };
  22957. flipSequence.__iteratorUncached = function(type, reverse) {
  22958. if (type === ITERATE_ENTRIES) {
  22959. var iterator = iterable.__iterator(type, reverse);
  22960. return new Iterator(function() {
  22961. var step = iterator.next();
  22962. if (!step.done) {
  22963. var k = step.value[0];
  22964. step.value[0] = step.value[1];
  22965. step.value[1] = k;
  22966. }
  22967. return step;
  22968. });
  22969. }
  22970. return iterable.__iterator(
  22971. type === ITERATE_VALUES ? ITERATE_KEYS : ITERATE_VALUES,
  22972. reverse
  22973. );
  22974. };
  22975. return flipSequence;
  22976. }
  22977. function mapFactory(iterable, mapper, context) {
  22978. var mappedSequence = makeSequence(iterable);
  22979. mappedSequence.size = iterable.size;
  22980. mappedSequence.has = function(key ) {return iterable.has(key)};
  22981. mappedSequence.get = function(key, notSetValue) {
  22982. var v = iterable.get(key, NOT_SET);
  22983. return v === NOT_SET ?
  22984. notSetValue :
  22985. mapper.call(context, v, key, iterable);
  22986. };
  22987. mappedSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  22988. return iterable.__iterate(
  22989. function(v, k, c) {return fn(mapper.call(context, v, k, c), k, this$0) !== false},
  22990. reverse
  22991. );
  22992. };
  22993. mappedSequence.__iteratorUncached = function (type, reverse) {
  22994. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  22995. return new Iterator(function() {
  22996. var step = iterator.next();
  22997. if (step.done) {
  22998. return step;
  22999. }
  23000. var entry = step.value;
  23001. var key = entry[0];
  23002. return iteratorValue(
  23003. type,
  23004. key,
  23005. mapper.call(context, entry[1], key, iterable),
  23006. step
  23007. );
  23008. });
  23009. };
  23010. return mappedSequence;
  23011. }
  23012. function reverseFactory(iterable, useKeys) {
  23013. var reversedSequence = makeSequence(iterable);
  23014. reversedSequence._iter = iterable;
  23015. reversedSequence.size = iterable.size;
  23016. reversedSequence.reverse = function() {return iterable};
  23017. if (iterable.flip) {
  23018. reversedSequence.flip = function () {
  23019. var flipSequence = flipFactory(iterable);
  23020. flipSequence.reverse = function() {return iterable.flip()};
  23021. return flipSequence;
  23022. };
  23023. }
  23024. reversedSequence.get = function(key, notSetValue)
  23025. {return iterable.get(useKeys ? key : -1 - key, notSetValue)};
  23026. reversedSequence.has = function(key )
  23027. {return iterable.has(useKeys ? key : -1 - key)};
  23028. reversedSequence.includes = function(value ) {return iterable.includes(value)};
  23029. reversedSequence.cacheResult = cacheResultThrough;
  23030. reversedSequence.__iterate = function (fn, reverse) {var this$0 = this;
  23031. return iterable.__iterate(function(v, k) {return fn(v, k, this$0)}, !reverse);
  23032. };
  23033. reversedSequence.__iterator =
  23034. function(type, reverse) {return iterable.__iterator(type, !reverse)};
  23035. return reversedSequence;
  23036. }
  23037. function filterFactory(iterable, predicate, context, useKeys) {
  23038. var filterSequence = makeSequence(iterable);
  23039. if (useKeys) {
  23040. filterSequence.has = function(key ) {
  23041. var v = iterable.get(key, NOT_SET);
  23042. return v !== NOT_SET && !!predicate.call(context, v, key, iterable);
  23043. };
  23044. filterSequence.get = function(key, notSetValue) {
  23045. var v = iterable.get(key, NOT_SET);
  23046. return v !== NOT_SET && predicate.call(context, v, key, iterable) ?
  23047. v : notSetValue;
  23048. };
  23049. }
  23050. filterSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  23051. var iterations = 0;
  23052. iterable.__iterate(function(v, k, c) {
  23053. if (predicate.call(context, v, k, c)) {
  23054. iterations++;
  23055. return fn(v, useKeys ? k : iterations - 1, this$0);
  23056. }
  23057. }, reverse);
  23058. return iterations;
  23059. };
  23060. filterSequence.__iteratorUncached = function (type, reverse) {
  23061. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  23062. var iterations = 0;
  23063. return new Iterator(function() {
  23064. while (true) {
  23065. var step = iterator.next();
  23066. if (step.done) {
  23067. return step;
  23068. }
  23069. var entry = step.value;
  23070. var key = entry[0];
  23071. var value = entry[1];
  23072. if (predicate.call(context, value, key, iterable)) {
  23073. return iteratorValue(type, useKeys ? key : iterations++, value, step);
  23074. }
  23075. }
  23076. });
  23077. };
  23078. return filterSequence;
  23079. }
  23080. function countByFactory(iterable, grouper, context) {
  23081. var groups = Map().asMutable();
  23082. iterable.__iterate(function(v, k) {
  23083. groups.update(
  23084. grouper.call(context, v, k, iterable),
  23085. 0,
  23086. function(a ) {return a + 1}
  23087. );
  23088. });
  23089. return groups.asImmutable();
  23090. }
  23091. function groupByFactory(iterable, grouper, context) {
  23092. var isKeyedIter = isKeyed(iterable);
  23093. var groups = (isOrdered(iterable) ? OrderedMap() : Map()).asMutable();
  23094. iterable.__iterate(function(v, k) {
  23095. groups.update(
  23096. grouper.call(context, v, k, iterable),
  23097. function(a ) {return (a = a || [], a.push(isKeyedIter ? [k, v] : v), a)}
  23098. );
  23099. });
  23100. var coerce = iterableClass(iterable);
  23101. return groups.map(function(arr ) {return reify(iterable, coerce(arr))});
  23102. }
  23103. function sliceFactory(iterable, begin, end, useKeys) {
  23104. var originalSize = iterable.size;
  23105. // Sanitize begin & end using this shorthand for ToInt32(argument)
  23106. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  23107. if (begin !== undefined) {
  23108. begin = begin | 0;
  23109. }
  23110. if (end !== undefined) {
  23111. end = end | 0;
  23112. }
  23113. if (wholeSlice(begin, end, originalSize)) {
  23114. return iterable;
  23115. }
  23116. var resolvedBegin = resolveBegin(begin, originalSize);
  23117. var resolvedEnd = resolveEnd(end, originalSize);
  23118. // begin or end will be NaN if they were provided as negative numbers and
  23119. // this iterable's size is unknown. In that case, cache first so there is
  23120. // a known size and these do not resolve to NaN.
  23121. if (resolvedBegin !== resolvedBegin || resolvedEnd !== resolvedEnd) {
  23122. return sliceFactory(iterable.toSeq().cacheResult(), begin, end, useKeys);
  23123. }
  23124. // Note: resolvedEnd is undefined when the original sequence's length is
  23125. // unknown and this slice did not supply an end and should contain all
  23126. // elements after resolvedBegin.
  23127. // In that case, resolvedSize will be NaN and sliceSize will remain undefined.
  23128. var resolvedSize = resolvedEnd - resolvedBegin;
  23129. var sliceSize;
  23130. if (resolvedSize === resolvedSize) {
  23131. sliceSize = resolvedSize < 0 ? 0 : resolvedSize;
  23132. }
  23133. var sliceSeq = makeSequence(iterable);
  23134. // If iterable.size is undefined, the size of the realized sliceSeq is
  23135. // unknown at this point unless the number of items to slice is 0
  23136. sliceSeq.size = sliceSize === 0 ? sliceSize : iterable.size && sliceSize || undefined;
  23137. if (!useKeys && isSeq(iterable) && sliceSize >= 0) {
  23138. sliceSeq.get = function (index, notSetValue) {
  23139. index = wrapIndex(this, index);
  23140. return index >= 0 && index < sliceSize ?
  23141. iterable.get(index + resolvedBegin, notSetValue) :
  23142. notSetValue;
  23143. };
  23144. }
  23145. sliceSeq.__iterateUncached = function(fn, reverse) {var this$0 = this;
  23146. if (sliceSize === 0) {
  23147. return 0;
  23148. }
  23149. if (reverse) {
  23150. return this.cacheResult().__iterate(fn, reverse);
  23151. }
  23152. var skipped = 0;
  23153. var isSkipping = true;
  23154. var iterations = 0;
  23155. iterable.__iterate(function(v, k) {
  23156. if (!(isSkipping && (isSkipping = skipped++ < resolvedBegin))) {
  23157. iterations++;
  23158. return fn(v, useKeys ? k : iterations - 1, this$0) !== false &&
  23159. iterations !== sliceSize;
  23160. }
  23161. });
  23162. return iterations;
  23163. };
  23164. sliceSeq.__iteratorUncached = function(type, reverse) {
  23165. if (sliceSize !== 0 && reverse) {
  23166. return this.cacheResult().__iterator(type, reverse);
  23167. }
  23168. // Don't bother instantiating parent iterator if taking 0.
  23169. var iterator = sliceSize !== 0 && iterable.__iterator(type, reverse);
  23170. var skipped = 0;
  23171. var iterations = 0;
  23172. return new Iterator(function() {
  23173. while (skipped++ < resolvedBegin) {
  23174. iterator.next();
  23175. }
  23176. if (++iterations > sliceSize) {
  23177. return iteratorDone();
  23178. }
  23179. var step = iterator.next();
  23180. if (useKeys || type === ITERATE_VALUES) {
  23181. return step;
  23182. } else if (type === ITERATE_KEYS) {
  23183. return iteratorValue(type, iterations - 1, undefined, step);
  23184. } else {
  23185. return iteratorValue(type, iterations - 1, step.value[1], step);
  23186. }
  23187. });
  23188. };
  23189. return sliceSeq;
  23190. }
  23191. function takeWhileFactory(iterable, predicate, context) {
  23192. var takeSequence = makeSequence(iterable);
  23193. takeSequence.__iterateUncached = function(fn, reverse) {var this$0 = this;
  23194. if (reverse) {
  23195. return this.cacheResult().__iterate(fn, reverse);
  23196. }
  23197. var iterations = 0;
  23198. iterable.__iterate(function(v, k, c)
  23199. {return predicate.call(context, v, k, c) && ++iterations && fn(v, k, this$0)}
  23200. );
  23201. return iterations;
  23202. };
  23203. takeSequence.__iteratorUncached = function(type, reverse) {var this$0 = this;
  23204. if (reverse) {
  23205. return this.cacheResult().__iterator(type, reverse);
  23206. }
  23207. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  23208. var iterating = true;
  23209. return new Iterator(function() {
  23210. if (!iterating) {
  23211. return iteratorDone();
  23212. }
  23213. var step = iterator.next();
  23214. if (step.done) {
  23215. return step;
  23216. }
  23217. var entry = step.value;
  23218. var k = entry[0];
  23219. var v = entry[1];
  23220. if (!predicate.call(context, v, k, this$0)) {
  23221. iterating = false;
  23222. return iteratorDone();
  23223. }
  23224. return type === ITERATE_ENTRIES ? step :
  23225. iteratorValue(type, k, v, step);
  23226. });
  23227. };
  23228. return takeSequence;
  23229. }
  23230. function skipWhileFactory(iterable, predicate, context, useKeys) {
  23231. var skipSequence = makeSequence(iterable);
  23232. skipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  23233. if (reverse) {
  23234. return this.cacheResult().__iterate(fn, reverse);
  23235. }
  23236. var isSkipping = true;
  23237. var iterations = 0;
  23238. iterable.__iterate(function(v, k, c) {
  23239. if (!(isSkipping && (isSkipping = predicate.call(context, v, k, c)))) {
  23240. iterations++;
  23241. return fn(v, useKeys ? k : iterations - 1, this$0);
  23242. }
  23243. });
  23244. return iterations;
  23245. };
  23246. skipSequence.__iteratorUncached = function(type, reverse) {var this$0 = this;
  23247. if (reverse) {
  23248. return this.cacheResult().__iterator(type, reverse);
  23249. }
  23250. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  23251. var skipping = true;
  23252. var iterations = 0;
  23253. return new Iterator(function() {
  23254. var step, k, v;
  23255. do {
  23256. step = iterator.next();
  23257. if (step.done) {
  23258. if (useKeys || type === ITERATE_VALUES) {
  23259. return step;
  23260. } else if (type === ITERATE_KEYS) {
  23261. return iteratorValue(type, iterations++, undefined, step);
  23262. } else {
  23263. return iteratorValue(type, iterations++, step.value[1], step);
  23264. }
  23265. }
  23266. var entry = step.value;
  23267. k = entry[0];
  23268. v = entry[1];
  23269. skipping && (skipping = predicate.call(context, v, k, this$0));
  23270. } while (skipping);
  23271. return type === ITERATE_ENTRIES ? step :
  23272. iteratorValue(type, k, v, step);
  23273. });
  23274. };
  23275. return skipSequence;
  23276. }
  23277. function concatFactory(iterable, values) {
  23278. var isKeyedIterable = isKeyed(iterable);
  23279. var iters = [iterable].concat(values).map(function(v ) {
  23280. if (!isIterable(v)) {
  23281. v = isKeyedIterable ?
  23282. keyedSeqFromValue(v) :
  23283. indexedSeqFromValue(Array.isArray(v) ? v : [v]);
  23284. } else if (isKeyedIterable) {
  23285. v = KeyedIterable(v);
  23286. }
  23287. return v;
  23288. }).filter(function(v ) {return v.size !== 0});
  23289. if (iters.length === 0) {
  23290. return iterable;
  23291. }
  23292. if (iters.length === 1) {
  23293. var singleton = iters[0];
  23294. if (singleton === iterable ||
  23295. isKeyedIterable && isKeyed(singleton) ||
  23296. isIndexed(iterable) && isIndexed(singleton)) {
  23297. return singleton;
  23298. }
  23299. }
  23300. var concatSeq = new ArraySeq(iters);
  23301. if (isKeyedIterable) {
  23302. concatSeq = concatSeq.toKeyedSeq();
  23303. } else if (!isIndexed(iterable)) {
  23304. concatSeq = concatSeq.toSetSeq();
  23305. }
  23306. concatSeq = concatSeq.flatten(true);
  23307. concatSeq.size = iters.reduce(
  23308. function(sum, seq) {
  23309. if (sum !== undefined) {
  23310. var size = seq.size;
  23311. if (size !== undefined) {
  23312. return sum + size;
  23313. }
  23314. }
  23315. },
  23316. 0
  23317. );
  23318. return concatSeq;
  23319. }
  23320. function flattenFactory(iterable, depth, useKeys) {
  23321. var flatSequence = makeSequence(iterable);
  23322. flatSequence.__iterateUncached = function(fn, reverse) {
  23323. var iterations = 0;
  23324. var stopped = false;
  23325. function flatDeep(iter, currentDepth) {var this$0 = this;
  23326. iter.__iterate(function(v, k) {
  23327. if ((!depth || currentDepth < depth) && isIterable(v)) {
  23328. flatDeep(v, currentDepth + 1);
  23329. } else if (fn(v, useKeys ? k : iterations++, this$0) === false) {
  23330. stopped = true;
  23331. }
  23332. return !stopped;
  23333. }, reverse);
  23334. }
  23335. flatDeep(iterable, 0);
  23336. return iterations;
  23337. };
  23338. flatSequence.__iteratorUncached = function(type, reverse) {
  23339. var iterator = iterable.__iterator(type, reverse);
  23340. var stack = [];
  23341. var iterations = 0;
  23342. return new Iterator(function() {
  23343. while (iterator) {
  23344. var step = iterator.next();
  23345. if (step.done !== false) {
  23346. iterator = stack.pop();
  23347. continue;
  23348. }
  23349. var v = step.value;
  23350. if (type === ITERATE_ENTRIES) {
  23351. v = v[1];
  23352. }
  23353. if ((!depth || stack.length < depth) && isIterable(v)) {
  23354. stack.push(iterator);
  23355. iterator = v.__iterator(type, reverse);
  23356. } else {
  23357. return useKeys ? step : iteratorValue(type, iterations++, v, step);
  23358. }
  23359. }
  23360. return iteratorDone();
  23361. });
  23362. };
  23363. return flatSequence;
  23364. }
  23365. function flatMapFactory(iterable, mapper, context) {
  23366. var coerce = iterableClass(iterable);
  23367. return iterable.toSeq().map(
  23368. function(v, k) {return coerce(mapper.call(context, v, k, iterable))}
  23369. ).flatten(true);
  23370. }
  23371. function interposeFactory(iterable, separator) {
  23372. var interposedSequence = makeSequence(iterable);
  23373. interposedSequence.size = iterable.size && iterable.size * 2 -1;
  23374. interposedSequence.__iterateUncached = function(fn, reverse) {var this$0 = this;
  23375. var iterations = 0;
  23376. iterable.__iterate(function(v, k)
  23377. {return (!iterations || fn(separator, iterations++, this$0) !== false) &&
  23378. fn(v, iterations++, this$0) !== false},
  23379. reverse
  23380. );
  23381. return iterations;
  23382. };
  23383. interposedSequence.__iteratorUncached = function(type, reverse) {
  23384. var iterator = iterable.__iterator(ITERATE_VALUES, reverse);
  23385. var iterations = 0;
  23386. var step;
  23387. return new Iterator(function() {
  23388. if (!step || iterations % 2) {
  23389. step = iterator.next();
  23390. if (step.done) {
  23391. return step;
  23392. }
  23393. }
  23394. return iterations % 2 ?
  23395. iteratorValue(type, iterations++, separator) :
  23396. iteratorValue(type, iterations++, step.value, step);
  23397. });
  23398. };
  23399. return interposedSequence;
  23400. }
  23401. function sortFactory(iterable, comparator, mapper) {
  23402. if (!comparator) {
  23403. comparator = defaultComparator;
  23404. }
  23405. var isKeyedIterable = isKeyed(iterable);
  23406. var index = 0;
  23407. var entries = iterable.toSeq().map(
  23408. function(v, k) {return [k, v, index++, mapper ? mapper(v, k, iterable) : v]}
  23409. ).toArray();
  23410. entries.sort(function(a, b) {return comparator(a[3], b[3]) || a[2] - b[2]}).forEach(
  23411. isKeyedIterable ?
  23412. function(v, i) { entries[i].length = 2; } :
  23413. function(v, i) { entries[i] = v[1]; }
  23414. );
  23415. return isKeyedIterable ? KeyedSeq(entries) :
  23416. isIndexed(iterable) ? IndexedSeq(entries) :
  23417. SetSeq(entries);
  23418. }
  23419. function maxFactory(iterable, comparator, mapper) {
  23420. if (!comparator) {
  23421. comparator = defaultComparator;
  23422. }
  23423. if (mapper) {
  23424. var entry = iterable.toSeq()
  23425. .map(function(v, k) {return [v, mapper(v, k, iterable)]})
  23426. .reduce(function(a, b) {return maxCompare(comparator, a[1], b[1]) ? b : a});
  23427. return entry && entry[0];
  23428. } else {
  23429. return iterable.reduce(function(a, b) {return maxCompare(comparator, a, b) ? b : a});
  23430. }
  23431. }
  23432. function maxCompare(comparator, a, b) {
  23433. var comp = comparator(b, a);
  23434. // b is considered the new max if the comparator declares them equal, but
  23435. // they are not equal and b is in fact a nullish value.
  23436. return (comp === 0 && b !== a && (b === undefined || b === null || b !== b)) || comp > 0;
  23437. }
  23438. function zipWithFactory(keyIter, zipper, iters) {
  23439. var zipSequence = makeSequence(keyIter);
  23440. zipSequence.size = new ArraySeq(iters).map(function(i ) {return i.size}).min();
  23441. // Note: this a generic base implementation of __iterate in terms of
  23442. // __iterator which may be more generically useful in the future.
  23443. zipSequence.__iterate = function(fn, reverse) {
  23444. /* generic:
  23445. var iterator = this.__iterator(ITERATE_ENTRIES, reverse);
  23446. var step;
  23447. var iterations = 0;
  23448. while (!(step = iterator.next()).done) {
  23449. iterations++;
  23450. if (fn(step.value[1], step.value[0], this) === false) {
  23451. break;
  23452. }
  23453. }
  23454. return iterations;
  23455. */
  23456. // indexed:
  23457. var iterator = this.__iterator(ITERATE_VALUES, reverse);
  23458. var step;
  23459. var iterations = 0;
  23460. while (!(step = iterator.next()).done) {
  23461. if (fn(step.value, iterations++, this) === false) {
  23462. break;
  23463. }
  23464. }
  23465. return iterations;
  23466. };
  23467. zipSequence.__iteratorUncached = function(type, reverse) {
  23468. var iterators = iters.map(function(i )
  23469. {return (i = Iterable(i), getIterator(reverse ? i.reverse() : i))}
  23470. );
  23471. var iterations = 0;
  23472. var isDone = false;
  23473. return new Iterator(function() {
  23474. var steps;
  23475. if (!isDone) {
  23476. steps = iterators.map(function(i ) {return i.next()});
  23477. isDone = steps.some(function(s ) {return s.done});
  23478. }
  23479. if (isDone) {
  23480. return iteratorDone();
  23481. }
  23482. return iteratorValue(
  23483. type,
  23484. iterations++,
  23485. zipper.apply(null, steps.map(function(s ) {return s.value}))
  23486. );
  23487. });
  23488. };
  23489. return zipSequence
  23490. }
  23491. // #pragma Helper Functions
  23492. function reify(iter, seq) {
  23493. return isSeq(iter) ? seq : iter.constructor(seq);
  23494. }
  23495. function validateEntry(entry) {
  23496. if (entry !== Object(entry)) {
  23497. throw new TypeError('Expected [K, V] tuple: ' + entry);
  23498. }
  23499. }
  23500. function resolveSize(iter) {
  23501. assertNotInfinite(iter.size);
  23502. return ensureSize(iter);
  23503. }
  23504. function iterableClass(iterable) {
  23505. return isKeyed(iterable) ? KeyedIterable :
  23506. isIndexed(iterable) ? IndexedIterable :
  23507. SetIterable;
  23508. }
  23509. function makeSequence(iterable) {
  23510. return Object.create(
  23511. (
  23512. isKeyed(iterable) ? KeyedSeq :
  23513. isIndexed(iterable) ? IndexedSeq :
  23514. SetSeq
  23515. ).prototype
  23516. );
  23517. }
  23518. function cacheResultThrough() {
  23519. if (this._iter.cacheResult) {
  23520. this._iter.cacheResult();
  23521. this.size = this._iter.size;
  23522. return this;
  23523. } else {
  23524. return Seq.prototype.cacheResult.call(this);
  23525. }
  23526. }
  23527. function defaultComparator(a, b) {
  23528. return a > b ? 1 : a < b ? -1 : 0;
  23529. }
  23530. function forceIterator(keyPath) {
  23531. var iter = getIterator(keyPath);
  23532. if (!iter) {
  23533. // Array might not be iterable in this environment, so we need a fallback
  23534. // to our wrapped type.
  23535. if (!isArrayLike(keyPath)) {
  23536. throw new TypeError('Expected iterable or array-like: ' + keyPath);
  23537. }
  23538. iter = getIterator(Iterable(keyPath));
  23539. }
  23540. return iter;
  23541. }
  23542. createClass(Record, KeyedCollection);
  23543. function Record(defaultValues, name) {
  23544. var hasInitialized;
  23545. var RecordType = function Record(values) {
  23546. if (values instanceof RecordType) {
  23547. return values;
  23548. }
  23549. if (!(this instanceof RecordType)) {
  23550. return new RecordType(values);
  23551. }
  23552. if (!hasInitialized) {
  23553. hasInitialized = true;
  23554. var keys = Object.keys(defaultValues);
  23555. setProps(RecordTypePrototype, keys);
  23556. RecordTypePrototype.size = keys.length;
  23557. RecordTypePrototype._name = name;
  23558. RecordTypePrototype._keys = keys;
  23559. RecordTypePrototype._defaultValues = defaultValues;
  23560. }
  23561. this._map = Map(values);
  23562. };
  23563. var RecordTypePrototype = RecordType.prototype = Object.create(RecordPrototype);
  23564. RecordTypePrototype.constructor = RecordType;
  23565. return RecordType;
  23566. }
  23567. Record.prototype.toString = function() {
  23568. return this.__toString(recordName(this) + ' {', '}');
  23569. };
  23570. // @pragma Access
  23571. Record.prototype.has = function(k) {
  23572. return this._defaultValues.hasOwnProperty(k);
  23573. };
  23574. Record.prototype.get = function(k, notSetValue) {
  23575. if (!this.has(k)) {
  23576. return notSetValue;
  23577. }
  23578. var defaultVal = this._defaultValues[k];
  23579. return this._map ? this._map.get(k, defaultVal) : defaultVal;
  23580. };
  23581. // @pragma Modification
  23582. Record.prototype.clear = function() {
  23583. if (this.__ownerID) {
  23584. this._map && this._map.clear();
  23585. return this;
  23586. }
  23587. var RecordType = this.constructor;
  23588. return RecordType._empty || (RecordType._empty = makeRecord(this, emptyMap()));
  23589. };
  23590. Record.prototype.set = function(k, v) {
  23591. if (!this.has(k)) {
  23592. throw new Error('Cannot set unknown key "' + k + '" on ' + recordName(this));
  23593. }
  23594. var newMap = this._map && this._map.set(k, v);
  23595. if (this.__ownerID || newMap === this._map) {
  23596. return this;
  23597. }
  23598. return makeRecord(this, newMap);
  23599. };
  23600. Record.prototype.remove = function(k) {
  23601. if (!this.has(k)) {
  23602. return this;
  23603. }
  23604. var newMap = this._map && this._map.remove(k);
  23605. if (this.__ownerID || newMap === this._map) {
  23606. return this;
  23607. }
  23608. return makeRecord(this, newMap);
  23609. };
  23610. Record.prototype.wasAltered = function() {
  23611. return this._map.wasAltered();
  23612. };
  23613. Record.prototype.__iterator = function(type, reverse) {var this$0 = this;
  23614. return KeyedIterable(this._defaultValues).map(function(_, k) {return this$0.get(k)}).__iterator(type, reverse);
  23615. };
  23616. Record.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  23617. return KeyedIterable(this._defaultValues).map(function(_, k) {return this$0.get(k)}).__iterate(fn, reverse);
  23618. };
  23619. Record.prototype.__ensureOwner = function(ownerID) {
  23620. if (ownerID === this.__ownerID) {
  23621. return this;
  23622. }
  23623. var newMap = this._map && this._map.__ensureOwner(ownerID);
  23624. if (!ownerID) {
  23625. this.__ownerID = ownerID;
  23626. this._map = newMap;
  23627. return this;
  23628. }
  23629. return makeRecord(this, newMap, ownerID);
  23630. };
  23631. var RecordPrototype = Record.prototype;
  23632. RecordPrototype[DELETE] = RecordPrototype.remove;
  23633. RecordPrototype.deleteIn =
  23634. RecordPrototype.removeIn = MapPrototype.removeIn;
  23635. RecordPrototype.merge = MapPrototype.merge;
  23636. RecordPrototype.mergeWith = MapPrototype.mergeWith;
  23637. RecordPrototype.mergeIn = MapPrototype.mergeIn;
  23638. RecordPrototype.mergeDeep = MapPrototype.mergeDeep;
  23639. RecordPrototype.mergeDeepWith = MapPrototype.mergeDeepWith;
  23640. RecordPrototype.mergeDeepIn = MapPrototype.mergeDeepIn;
  23641. RecordPrototype.setIn = MapPrototype.setIn;
  23642. RecordPrototype.update = MapPrototype.update;
  23643. RecordPrototype.updateIn = MapPrototype.updateIn;
  23644. RecordPrototype.withMutations = MapPrototype.withMutations;
  23645. RecordPrototype.asMutable = MapPrototype.asMutable;
  23646. RecordPrototype.asImmutable = MapPrototype.asImmutable;
  23647. function makeRecord(likeRecord, map, ownerID) {
  23648. var record = Object.create(Object.getPrototypeOf(likeRecord));
  23649. record._map = map;
  23650. record.__ownerID = ownerID;
  23651. return record;
  23652. }
  23653. function recordName(record) {
  23654. return record._name || record.constructor.name || 'Record';
  23655. }
  23656. function setProps(prototype, names) {
  23657. try {
  23658. names.forEach(setProp.bind(undefined, prototype));
  23659. } catch (error) {
  23660. // Object.defineProperty failed. Probably IE8.
  23661. }
  23662. }
  23663. function setProp(prototype, name) {
  23664. Object.defineProperty(prototype, name, {
  23665. get: function() {
  23666. return this.get(name);
  23667. },
  23668. set: function(value) {
  23669. invariant(this.__ownerID, 'Cannot set on an immutable record.');
  23670. this.set(name, value);
  23671. }
  23672. });
  23673. }
  23674. createClass(Set, SetCollection);
  23675. // @pragma Construction
  23676. function Set(value) {
  23677. return value === null || value === undefined ? emptySet() :
  23678. isSet(value) && !isOrdered(value) ? value :
  23679. emptySet().withMutations(function(set ) {
  23680. var iter = SetIterable(value);
  23681. assertNotInfinite(iter.size);
  23682. iter.forEach(function(v ) {return set.add(v)});
  23683. });
  23684. }
  23685. Set.of = function(/*...values*/) {
  23686. return this(arguments);
  23687. };
  23688. Set.fromKeys = function(value) {
  23689. return this(KeyedIterable(value).keySeq());
  23690. };
  23691. Set.prototype.toString = function() {
  23692. return this.__toString('Set {', '}');
  23693. };
  23694. // @pragma Access
  23695. Set.prototype.has = function(value) {
  23696. return this._map.has(value);
  23697. };
  23698. // @pragma Modification
  23699. Set.prototype.add = function(value) {
  23700. return updateSet(this, this._map.set(value, true));
  23701. };
  23702. Set.prototype.remove = function(value) {
  23703. return updateSet(this, this._map.remove(value));
  23704. };
  23705. Set.prototype.clear = function() {
  23706. return updateSet(this, this._map.clear());
  23707. };
  23708. // @pragma Composition
  23709. Set.prototype.union = function() {var iters = SLICE$0.call(arguments, 0);
  23710. iters = iters.filter(function(x ) {return x.size !== 0});
  23711. if (iters.length === 0) {
  23712. return this;
  23713. }
  23714. if (this.size === 0 && !this.__ownerID && iters.length === 1) {
  23715. return this.constructor(iters[0]);
  23716. }
  23717. return this.withMutations(function(set ) {
  23718. for (var ii = 0; ii < iters.length; ii++) {
  23719. SetIterable(iters[ii]).forEach(function(value ) {return set.add(value)});
  23720. }
  23721. });
  23722. };
  23723. Set.prototype.intersect = function() {var iters = SLICE$0.call(arguments, 0);
  23724. if (iters.length === 0) {
  23725. return this;
  23726. }
  23727. iters = iters.map(function(iter ) {return SetIterable(iter)});
  23728. var originalSet = this;
  23729. return this.withMutations(function(set ) {
  23730. originalSet.forEach(function(value ) {
  23731. if (!iters.every(function(iter ) {return iter.includes(value)})) {
  23732. set.remove(value);
  23733. }
  23734. });
  23735. });
  23736. };
  23737. Set.prototype.subtract = function() {var iters = SLICE$0.call(arguments, 0);
  23738. if (iters.length === 0) {
  23739. return this;
  23740. }
  23741. iters = iters.map(function(iter ) {return SetIterable(iter)});
  23742. var originalSet = this;
  23743. return this.withMutations(function(set ) {
  23744. originalSet.forEach(function(value ) {
  23745. if (iters.some(function(iter ) {return iter.includes(value)})) {
  23746. set.remove(value);
  23747. }
  23748. });
  23749. });
  23750. };
  23751. Set.prototype.merge = function() {
  23752. return this.union.apply(this, arguments);
  23753. };
  23754. Set.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  23755. return this.union.apply(this, iters);
  23756. };
  23757. Set.prototype.sort = function(comparator) {
  23758. // Late binding
  23759. return OrderedSet(sortFactory(this, comparator));
  23760. };
  23761. Set.prototype.sortBy = function(mapper, comparator) {
  23762. // Late binding
  23763. return OrderedSet(sortFactory(this, comparator, mapper));
  23764. };
  23765. Set.prototype.wasAltered = function() {
  23766. return this._map.wasAltered();
  23767. };
  23768. Set.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  23769. return this._map.__iterate(function(_, k) {return fn(k, k, this$0)}, reverse);
  23770. };
  23771. Set.prototype.__iterator = function(type, reverse) {
  23772. return this._map.map(function(_, k) {return k}).__iterator(type, reverse);
  23773. };
  23774. Set.prototype.__ensureOwner = function(ownerID) {
  23775. if (ownerID === this.__ownerID) {
  23776. return this;
  23777. }
  23778. var newMap = this._map.__ensureOwner(ownerID);
  23779. if (!ownerID) {
  23780. this.__ownerID = ownerID;
  23781. this._map = newMap;
  23782. return this;
  23783. }
  23784. return this.__make(newMap, ownerID);
  23785. };
  23786. function isSet(maybeSet) {
  23787. return !!(maybeSet && maybeSet[IS_SET_SENTINEL]);
  23788. }
  23789. Set.isSet = isSet;
  23790. var IS_SET_SENTINEL = '@@__IMMUTABLE_SET__@@';
  23791. var SetPrototype = Set.prototype;
  23792. SetPrototype[IS_SET_SENTINEL] = true;
  23793. SetPrototype[DELETE] = SetPrototype.remove;
  23794. SetPrototype.mergeDeep = SetPrototype.merge;
  23795. SetPrototype.mergeDeepWith = SetPrototype.mergeWith;
  23796. SetPrototype.withMutations = MapPrototype.withMutations;
  23797. SetPrototype.asMutable = MapPrototype.asMutable;
  23798. SetPrototype.asImmutable = MapPrototype.asImmutable;
  23799. SetPrototype.__empty = emptySet;
  23800. SetPrototype.__make = makeSet;
  23801. function updateSet(set, newMap) {
  23802. if (set.__ownerID) {
  23803. set.size = newMap.size;
  23804. set._map = newMap;
  23805. return set;
  23806. }
  23807. return newMap === set._map ? set :
  23808. newMap.size === 0 ? set.__empty() :
  23809. set.__make(newMap);
  23810. }
  23811. function makeSet(map, ownerID) {
  23812. var set = Object.create(SetPrototype);
  23813. set.size = map ? map.size : 0;
  23814. set._map = map;
  23815. set.__ownerID = ownerID;
  23816. return set;
  23817. }
  23818. var EMPTY_SET;
  23819. function emptySet() {
  23820. return EMPTY_SET || (EMPTY_SET = makeSet(emptyMap()));
  23821. }
  23822. createClass(OrderedSet, Set);
  23823. // @pragma Construction
  23824. function OrderedSet(value) {
  23825. return value === null || value === undefined ? emptyOrderedSet() :
  23826. isOrderedSet(value) ? value :
  23827. emptyOrderedSet().withMutations(function(set ) {
  23828. var iter = SetIterable(value);
  23829. assertNotInfinite(iter.size);
  23830. iter.forEach(function(v ) {return set.add(v)});
  23831. });
  23832. }
  23833. OrderedSet.of = function(/*...values*/) {
  23834. return this(arguments);
  23835. };
  23836. OrderedSet.fromKeys = function(value) {
  23837. return this(KeyedIterable(value).keySeq());
  23838. };
  23839. OrderedSet.prototype.toString = function() {
  23840. return this.__toString('OrderedSet {', '}');
  23841. };
  23842. function isOrderedSet(maybeOrderedSet) {
  23843. return isSet(maybeOrderedSet) && isOrdered(maybeOrderedSet);
  23844. }
  23845. OrderedSet.isOrderedSet = isOrderedSet;
  23846. var OrderedSetPrototype = OrderedSet.prototype;
  23847. OrderedSetPrototype[IS_ORDERED_SENTINEL] = true;
  23848. OrderedSetPrototype.__empty = emptyOrderedSet;
  23849. OrderedSetPrototype.__make = makeOrderedSet;
  23850. function makeOrderedSet(map, ownerID) {
  23851. var set = Object.create(OrderedSetPrototype);
  23852. set.size = map ? map.size : 0;
  23853. set._map = map;
  23854. set.__ownerID = ownerID;
  23855. return set;
  23856. }
  23857. var EMPTY_ORDERED_SET;
  23858. function emptyOrderedSet() {
  23859. return EMPTY_ORDERED_SET || (EMPTY_ORDERED_SET = makeOrderedSet(emptyOrderedMap()));
  23860. }
  23861. createClass(Stack, IndexedCollection);
  23862. // @pragma Construction
  23863. function Stack(value) {
  23864. return value === null || value === undefined ? emptyStack() :
  23865. isStack(value) ? value :
  23866. emptyStack().unshiftAll(value);
  23867. }
  23868. Stack.of = function(/*...values*/) {
  23869. return this(arguments);
  23870. };
  23871. Stack.prototype.toString = function() {
  23872. return this.__toString('Stack [', ']');
  23873. };
  23874. // @pragma Access
  23875. Stack.prototype.get = function(index, notSetValue) {
  23876. var head = this._head;
  23877. index = wrapIndex(this, index);
  23878. while (head && index--) {
  23879. head = head.next;
  23880. }
  23881. return head ? head.value : notSetValue;
  23882. };
  23883. Stack.prototype.peek = function() {
  23884. return this._head && this._head.value;
  23885. };
  23886. // @pragma Modification
  23887. Stack.prototype.push = function(/*...values*/) {
  23888. if (arguments.length === 0) {
  23889. return this;
  23890. }
  23891. var newSize = this.size + arguments.length;
  23892. var head = this._head;
  23893. for (var ii = arguments.length - 1; ii >= 0; ii--) {
  23894. head = {
  23895. value: arguments[ii],
  23896. next: head
  23897. };
  23898. }
  23899. if (this.__ownerID) {
  23900. this.size = newSize;
  23901. this._head = head;
  23902. this.__hash = undefined;
  23903. this.__altered = true;
  23904. return this;
  23905. }
  23906. return makeStack(newSize, head);
  23907. };
  23908. Stack.prototype.pushAll = function(iter) {
  23909. iter = IndexedIterable(iter);
  23910. if (iter.size === 0) {
  23911. return this;
  23912. }
  23913. assertNotInfinite(iter.size);
  23914. var newSize = this.size;
  23915. var head = this._head;
  23916. iter.reverse().forEach(function(value ) {
  23917. newSize++;
  23918. head = {
  23919. value: value,
  23920. next: head
  23921. };
  23922. });
  23923. if (this.__ownerID) {
  23924. this.size = newSize;
  23925. this._head = head;
  23926. this.__hash = undefined;
  23927. this.__altered = true;
  23928. return this;
  23929. }
  23930. return makeStack(newSize, head);
  23931. };
  23932. Stack.prototype.pop = function() {
  23933. return this.slice(1);
  23934. };
  23935. Stack.prototype.unshift = function(/*...values*/) {
  23936. return this.push.apply(this, arguments);
  23937. };
  23938. Stack.prototype.unshiftAll = function(iter) {
  23939. return this.pushAll(iter);
  23940. };
  23941. Stack.prototype.shift = function() {
  23942. return this.pop.apply(this, arguments);
  23943. };
  23944. Stack.prototype.clear = function() {
  23945. if (this.size === 0) {
  23946. return this;
  23947. }
  23948. if (this.__ownerID) {
  23949. this.size = 0;
  23950. this._head = undefined;
  23951. this.__hash = undefined;
  23952. this.__altered = true;
  23953. return this;
  23954. }
  23955. return emptyStack();
  23956. };
  23957. Stack.prototype.slice = function(begin, end) {
  23958. if (wholeSlice(begin, end, this.size)) {
  23959. return this;
  23960. }
  23961. var resolvedBegin = resolveBegin(begin, this.size);
  23962. var resolvedEnd = resolveEnd(end, this.size);
  23963. if (resolvedEnd !== this.size) {
  23964. // super.slice(begin, end);
  23965. return IndexedCollection.prototype.slice.call(this, begin, end);
  23966. }
  23967. var newSize = this.size - resolvedBegin;
  23968. var head = this._head;
  23969. while (resolvedBegin--) {
  23970. head = head.next;
  23971. }
  23972. if (this.__ownerID) {
  23973. this.size = newSize;
  23974. this._head = head;
  23975. this.__hash = undefined;
  23976. this.__altered = true;
  23977. return this;
  23978. }
  23979. return makeStack(newSize, head);
  23980. };
  23981. // @pragma Mutability
  23982. Stack.prototype.__ensureOwner = function(ownerID) {
  23983. if (ownerID === this.__ownerID) {
  23984. return this;
  23985. }
  23986. if (!ownerID) {
  23987. this.__ownerID = ownerID;
  23988. this.__altered = false;
  23989. return this;
  23990. }
  23991. return makeStack(this.size, this._head, ownerID, this.__hash);
  23992. };
  23993. // @pragma Iteration
  23994. Stack.prototype.__iterate = function(fn, reverse) {
  23995. if (reverse) {
  23996. return this.reverse().__iterate(fn);
  23997. }
  23998. var iterations = 0;
  23999. var node = this._head;
  24000. while (node) {
  24001. if (fn(node.value, iterations++, this) === false) {
  24002. break;
  24003. }
  24004. node = node.next;
  24005. }
  24006. return iterations;
  24007. };
  24008. Stack.prototype.__iterator = function(type, reverse) {
  24009. if (reverse) {
  24010. return this.reverse().__iterator(type);
  24011. }
  24012. var iterations = 0;
  24013. var node = this._head;
  24014. return new Iterator(function() {
  24015. if (node) {
  24016. var value = node.value;
  24017. node = node.next;
  24018. return iteratorValue(type, iterations++, value);
  24019. }
  24020. return iteratorDone();
  24021. });
  24022. };
  24023. function isStack(maybeStack) {
  24024. return !!(maybeStack && maybeStack[IS_STACK_SENTINEL]);
  24025. }
  24026. Stack.isStack = isStack;
  24027. var IS_STACK_SENTINEL = '@@__IMMUTABLE_STACK__@@';
  24028. var StackPrototype = Stack.prototype;
  24029. StackPrototype[IS_STACK_SENTINEL] = true;
  24030. StackPrototype.withMutations = MapPrototype.withMutations;
  24031. StackPrototype.asMutable = MapPrototype.asMutable;
  24032. StackPrototype.asImmutable = MapPrototype.asImmutable;
  24033. StackPrototype.wasAltered = MapPrototype.wasAltered;
  24034. function makeStack(size, head, ownerID, hash) {
  24035. var map = Object.create(StackPrototype);
  24036. map.size = size;
  24037. map._head = head;
  24038. map.__ownerID = ownerID;
  24039. map.__hash = hash;
  24040. map.__altered = false;
  24041. return map;
  24042. }
  24043. var EMPTY_STACK;
  24044. function emptyStack() {
  24045. return EMPTY_STACK || (EMPTY_STACK = makeStack(0));
  24046. }
  24047. /**
  24048. * Contributes additional methods to a constructor
  24049. */
  24050. function mixin(ctor, methods) {
  24051. var keyCopier = function(key ) { ctor.prototype[key] = methods[key]; };
  24052. Object.keys(methods).forEach(keyCopier);
  24053. Object.getOwnPropertySymbols &&
  24054. Object.getOwnPropertySymbols(methods).forEach(keyCopier);
  24055. return ctor;
  24056. }
  24057. Iterable.Iterator = Iterator;
  24058. mixin(Iterable, {
  24059. // ### Conversion to other types
  24060. toArray: function() {
  24061. assertNotInfinite(this.size);
  24062. var array = new Array(this.size || 0);
  24063. this.valueSeq().__iterate(function(v, i) { array[i] = v; });
  24064. return array;
  24065. },
  24066. toIndexedSeq: function() {
  24067. return new ToIndexedSequence(this);
  24068. },
  24069. toJS: function() {
  24070. return this.toSeq().map(
  24071. function(value ) {return value && typeof value.toJS === 'function' ? value.toJS() : value}
  24072. ).__toJS();
  24073. },
  24074. toJSON: function() {
  24075. return this.toSeq().map(
  24076. function(value ) {return value && typeof value.toJSON === 'function' ? value.toJSON() : value}
  24077. ).__toJS();
  24078. },
  24079. toKeyedSeq: function() {
  24080. return new ToKeyedSequence(this, true);
  24081. },
  24082. toMap: function() {
  24083. // Use Late Binding here to solve the circular dependency.
  24084. return Map(this.toKeyedSeq());
  24085. },
  24086. toObject: function() {
  24087. assertNotInfinite(this.size);
  24088. var object = {};
  24089. this.__iterate(function(v, k) { object[k] = v; });
  24090. return object;
  24091. },
  24092. toOrderedMap: function() {
  24093. // Use Late Binding here to solve the circular dependency.
  24094. return OrderedMap(this.toKeyedSeq());
  24095. },
  24096. toOrderedSet: function() {
  24097. // Use Late Binding here to solve the circular dependency.
  24098. return OrderedSet(isKeyed(this) ? this.valueSeq() : this);
  24099. },
  24100. toSet: function() {
  24101. // Use Late Binding here to solve the circular dependency.
  24102. return Set(isKeyed(this) ? this.valueSeq() : this);
  24103. },
  24104. toSetSeq: function() {
  24105. return new ToSetSequence(this);
  24106. },
  24107. toSeq: function() {
  24108. return isIndexed(this) ? this.toIndexedSeq() :
  24109. isKeyed(this) ? this.toKeyedSeq() :
  24110. this.toSetSeq();
  24111. },
  24112. toStack: function() {
  24113. // Use Late Binding here to solve the circular dependency.
  24114. return Stack(isKeyed(this) ? this.valueSeq() : this);
  24115. },
  24116. toList: function() {
  24117. // Use Late Binding here to solve the circular dependency.
  24118. return List(isKeyed(this) ? this.valueSeq() : this);
  24119. },
  24120. // ### Common JavaScript methods and properties
  24121. toString: function() {
  24122. return '[Iterable]';
  24123. },
  24124. __toString: function(head, tail) {
  24125. if (this.size === 0) {
  24126. return head + tail;
  24127. }
  24128. return head + ' ' + this.toSeq().map(this.__toStringMapper).join(', ') + ' ' + tail;
  24129. },
  24130. // ### ES6 Collection methods (ES6 Array and Map)
  24131. concat: function() {var values = SLICE$0.call(arguments, 0);
  24132. return reify(this, concatFactory(this, values));
  24133. },
  24134. includes: function(searchValue) {
  24135. return this.some(function(value ) {return is(value, searchValue)});
  24136. },
  24137. entries: function() {
  24138. return this.__iterator(ITERATE_ENTRIES);
  24139. },
  24140. every: function(predicate, context) {
  24141. assertNotInfinite(this.size);
  24142. var returnValue = true;
  24143. this.__iterate(function(v, k, c) {
  24144. if (!predicate.call(context, v, k, c)) {
  24145. returnValue = false;
  24146. return false;
  24147. }
  24148. });
  24149. return returnValue;
  24150. },
  24151. filter: function(predicate, context) {
  24152. return reify(this, filterFactory(this, predicate, context, true));
  24153. },
  24154. find: function(predicate, context, notSetValue) {
  24155. var entry = this.findEntry(predicate, context);
  24156. return entry ? entry[1] : notSetValue;
  24157. },
  24158. findEntry: function(predicate, context) {
  24159. var found;
  24160. this.__iterate(function(v, k, c) {
  24161. if (predicate.call(context, v, k, c)) {
  24162. found = [k, v];
  24163. return false;
  24164. }
  24165. });
  24166. return found;
  24167. },
  24168. findLastEntry: function(predicate, context) {
  24169. return this.toSeq().reverse().findEntry(predicate, context);
  24170. },
  24171. forEach: function(sideEffect, context) {
  24172. assertNotInfinite(this.size);
  24173. return this.__iterate(context ? sideEffect.bind(context) : sideEffect);
  24174. },
  24175. join: function(separator) {
  24176. assertNotInfinite(this.size);
  24177. separator = separator !== undefined ? '' + separator : ',';
  24178. var joined = '';
  24179. var isFirst = true;
  24180. this.__iterate(function(v ) {
  24181. isFirst ? (isFirst = false) : (joined += separator);
  24182. joined += v !== null && v !== undefined ? v.toString() : '';
  24183. });
  24184. return joined;
  24185. },
  24186. keys: function() {
  24187. return this.__iterator(ITERATE_KEYS);
  24188. },
  24189. map: function(mapper, context) {
  24190. return reify(this, mapFactory(this, mapper, context));
  24191. },
  24192. reduce: function(reducer, initialReduction, context) {
  24193. assertNotInfinite(this.size);
  24194. var reduction;
  24195. var useFirst;
  24196. if (arguments.length < 2) {
  24197. useFirst = true;
  24198. } else {
  24199. reduction = initialReduction;
  24200. }
  24201. this.__iterate(function(v, k, c) {
  24202. if (useFirst) {
  24203. useFirst = false;
  24204. reduction = v;
  24205. } else {
  24206. reduction = reducer.call(context, reduction, v, k, c);
  24207. }
  24208. });
  24209. return reduction;
  24210. },
  24211. reduceRight: function(reducer, initialReduction, context) {
  24212. var reversed = this.toKeyedSeq().reverse();
  24213. return reversed.reduce.apply(reversed, arguments);
  24214. },
  24215. reverse: function() {
  24216. return reify(this, reverseFactory(this, true));
  24217. },
  24218. slice: function(begin, end) {
  24219. return reify(this, sliceFactory(this, begin, end, true));
  24220. },
  24221. some: function(predicate, context) {
  24222. return !this.every(not(predicate), context);
  24223. },
  24224. sort: function(comparator) {
  24225. return reify(this, sortFactory(this, comparator));
  24226. },
  24227. values: function() {
  24228. return this.__iterator(ITERATE_VALUES);
  24229. },
  24230. // ### More sequential methods
  24231. butLast: function() {
  24232. return this.slice(0, -1);
  24233. },
  24234. isEmpty: function() {
  24235. return this.size !== undefined ? this.size === 0 : !this.some(function() {return true});
  24236. },
  24237. count: function(predicate, context) {
  24238. return ensureSize(
  24239. predicate ? this.toSeq().filter(predicate, context) : this
  24240. );
  24241. },
  24242. countBy: function(grouper, context) {
  24243. return countByFactory(this, grouper, context);
  24244. },
  24245. equals: function(other) {
  24246. return deepEqual(this, other);
  24247. },
  24248. entrySeq: function() {
  24249. var iterable = this;
  24250. if (iterable._cache) {
  24251. // We cache as an entries array, so we can just return the cache!
  24252. return new ArraySeq(iterable._cache);
  24253. }
  24254. var entriesSequence = iterable.toSeq().map(entryMapper).toIndexedSeq();
  24255. entriesSequence.fromEntrySeq = function() {return iterable.toSeq()};
  24256. return entriesSequence;
  24257. },
  24258. filterNot: function(predicate, context) {
  24259. return this.filter(not(predicate), context);
  24260. },
  24261. findLast: function(predicate, context, notSetValue) {
  24262. return this.toKeyedSeq().reverse().find(predicate, context, notSetValue);
  24263. },
  24264. first: function() {
  24265. return this.find(returnTrue);
  24266. },
  24267. flatMap: function(mapper, context) {
  24268. return reify(this, flatMapFactory(this, mapper, context));
  24269. },
  24270. flatten: function(depth) {
  24271. return reify(this, flattenFactory(this, depth, true));
  24272. },
  24273. fromEntrySeq: function() {
  24274. return new FromEntriesSequence(this);
  24275. },
  24276. get: function(searchKey, notSetValue) {
  24277. return this.find(function(_, key) {return is(key, searchKey)}, undefined, notSetValue);
  24278. },
  24279. getIn: function(searchKeyPath, notSetValue) {
  24280. var nested = this;
  24281. // Note: in an ES6 environment, we would prefer:
  24282. // for (var key of searchKeyPath) {
  24283. var iter = forceIterator(searchKeyPath);
  24284. var step;
  24285. while (!(step = iter.next()).done) {
  24286. var key = step.value;
  24287. nested = nested && nested.get ? nested.get(key, NOT_SET) : NOT_SET;
  24288. if (nested === NOT_SET) {
  24289. return notSetValue;
  24290. }
  24291. }
  24292. return nested;
  24293. },
  24294. groupBy: function(grouper, context) {
  24295. return groupByFactory(this, grouper, context);
  24296. },
  24297. has: function(searchKey) {
  24298. return this.get(searchKey, NOT_SET) !== NOT_SET;
  24299. },
  24300. hasIn: function(searchKeyPath) {
  24301. return this.getIn(searchKeyPath, NOT_SET) !== NOT_SET;
  24302. },
  24303. isSubset: function(iter) {
  24304. iter = typeof iter.includes === 'function' ? iter : Iterable(iter);
  24305. return this.every(function(value ) {return iter.includes(value)});
  24306. },
  24307. isSuperset: function(iter) {
  24308. iter = typeof iter.isSubset === 'function' ? iter : Iterable(iter);
  24309. return iter.isSubset(this);
  24310. },
  24311. keySeq: function() {
  24312. return this.toSeq().map(keyMapper).toIndexedSeq();
  24313. },
  24314. last: function() {
  24315. return this.toSeq().reverse().first();
  24316. },
  24317. max: function(comparator) {
  24318. return maxFactory(this, comparator);
  24319. },
  24320. maxBy: function(mapper, comparator) {
  24321. return maxFactory(this, comparator, mapper);
  24322. },
  24323. min: function(comparator) {
  24324. return maxFactory(this, comparator ? neg(comparator) : defaultNegComparator);
  24325. },
  24326. minBy: function(mapper, comparator) {
  24327. return maxFactory(this, comparator ? neg(comparator) : defaultNegComparator, mapper);
  24328. },
  24329. rest: function() {
  24330. return this.slice(1);
  24331. },
  24332. skip: function(amount) {
  24333. return this.slice(Math.max(0, amount));
  24334. },
  24335. skipLast: function(amount) {
  24336. return reify(this, this.toSeq().reverse().skip(amount).reverse());
  24337. },
  24338. skipWhile: function(predicate, context) {
  24339. return reify(this, skipWhileFactory(this, predicate, context, true));
  24340. },
  24341. skipUntil: function(predicate, context) {
  24342. return this.skipWhile(not(predicate), context);
  24343. },
  24344. sortBy: function(mapper, comparator) {
  24345. return reify(this, sortFactory(this, comparator, mapper));
  24346. },
  24347. take: function(amount) {
  24348. return this.slice(0, Math.max(0, amount));
  24349. },
  24350. takeLast: function(amount) {
  24351. return reify(this, this.toSeq().reverse().take(amount).reverse());
  24352. },
  24353. takeWhile: function(predicate, context) {
  24354. return reify(this, takeWhileFactory(this, predicate, context));
  24355. },
  24356. takeUntil: function(predicate, context) {
  24357. return this.takeWhile(not(predicate), context);
  24358. },
  24359. valueSeq: function() {
  24360. return this.toIndexedSeq();
  24361. },
  24362. // ### Hashable Object
  24363. hashCode: function() {
  24364. return this.__hash || (this.__hash = hashIterable(this));
  24365. }
  24366. // ### Internal
  24367. // abstract __iterate(fn, reverse)
  24368. // abstract __iterator(type, reverse)
  24369. });
  24370. // var IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
  24371. // var IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
  24372. // var IS_INDEXED_SENTINEL = '@@__IMMUTABLE_INDEXED__@@';
  24373. // var IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
  24374. var IterablePrototype = Iterable.prototype;
  24375. IterablePrototype[IS_ITERABLE_SENTINEL] = true;
  24376. IterablePrototype[ITERATOR_SYMBOL] = IterablePrototype.values;
  24377. IterablePrototype.__toJS = IterablePrototype.toArray;
  24378. IterablePrototype.__toStringMapper = quoteString;
  24379. IterablePrototype.inspect =
  24380. IterablePrototype.toSource = function() { return this.toString(); };
  24381. IterablePrototype.chain = IterablePrototype.flatMap;
  24382. IterablePrototype.contains = IterablePrototype.includes;
  24383. // Temporary warning about using length
  24384. (function () {
  24385. try {
  24386. Object.defineProperty(IterablePrototype, 'length', {
  24387. get: function () {
  24388. if (!Iterable.noLengthWarning) {
  24389. var stack;
  24390. try {
  24391. throw new Error();
  24392. } catch (error) {
  24393. stack = error.stack;
  24394. }
  24395. if (stack.indexOf('_wrapObject') === -1) {
  24396. console && console.warn && console.warn(
  24397. 'iterable.length has been deprecated, '+
  24398. 'use iterable.size or iterable.count(). '+
  24399. 'This warning will become a silent error in a future version. ' +
  24400. stack
  24401. );
  24402. return this.size;
  24403. }
  24404. }
  24405. }
  24406. });
  24407. } catch (e) {}
  24408. })();
  24409. mixin(KeyedIterable, {
  24410. // ### More sequential methods
  24411. flip: function() {
  24412. return reify(this, flipFactory(this));
  24413. },
  24414. findKey: function(predicate, context) {
  24415. var entry = this.findEntry(predicate, context);
  24416. return entry && entry[0];
  24417. },
  24418. findLastKey: function(predicate, context) {
  24419. return this.toSeq().reverse().findKey(predicate, context);
  24420. },
  24421. keyOf: function(searchValue) {
  24422. return this.findKey(function(value ) {return is(value, searchValue)});
  24423. },
  24424. lastKeyOf: function(searchValue) {
  24425. return this.findLastKey(function(value ) {return is(value, searchValue)});
  24426. },
  24427. mapEntries: function(mapper, context) {var this$0 = this;
  24428. var iterations = 0;
  24429. return reify(this,
  24430. this.toSeq().map(
  24431. function(v, k) {return mapper.call(context, [k, v], iterations++, this$0)}
  24432. ).fromEntrySeq()
  24433. );
  24434. },
  24435. mapKeys: function(mapper, context) {var this$0 = this;
  24436. return reify(this,
  24437. this.toSeq().flip().map(
  24438. function(k, v) {return mapper.call(context, k, v, this$0)}
  24439. ).flip()
  24440. );
  24441. }
  24442. });
  24443. var KeyedIterablePrototype = KeyedIterable.prototype;
  24444. KeyedIterablePrototype[IS_KEYED_SENTINEL] = true;
  24445. KeyedIterablePrototype[ITERATOR_SYMBOL] = IterablePrototype.entries;
  24446. KeyedIterablePrototype.__toJS = IterablePrototype.toObject;
  24447. KeyedIterablePrototype.__toStringMapper = function(v, k) {return JSON.stringify(k) + ': ' + quoteString(v)};
  24448. mixin(IndexedIterable, {
  24449. // ### Conversion to other types
  24450. toKeyedSeq: function() {
  24451. return new ToKeyedSequence(this, false);
  24452. },
  24453. // ### ES6 Collection methods (ES6 Array and Map)
  24454. filter: function(predicate, context) {
  24455. return reify(this, filterFactory(this, predicate, context, false));
  24456. },
  24457. findIndex: function(predicate, context) {
  24458. var entry = this.findEntry(predicate, context);
  24459. return entry ? entry[0] : -1;
  24460. },
  24461. indexOf: function(searchValue) {
  24462. var key = this.toKeyedSeq().keyOf(searchValue);
  24463. return key === undefined ? -1 : key;
  24464. },
  24465. lastIndexOf: function(searchValue) {
  24466. var key = this.toKeyedSeq().reverse().keyOf(searchValue);
  24467. return key === undefined ? -1 : key;
  24468. // var index =
  24469. // return this.toSeq().reverse().indexOf(searchValue);
  24470. },
  24471. reverse: function() {
  24472. return reify(this, reverseFactory(this, false));
  24473. },
  24474. slice: function(begin, end) {
  24475. return reify(this, sliceFactory(this, begin, end, false));
  24476. },
  24477. splice: function(index, removeNum /*, ...values*/) {
  24478. var numArgs = arguments.length;
  24479. removeNum = Math.max(removeNum | 0, 0);
  24480. if (numArgs === 0 || (numArgs === 2 && !removeNum)) {
  24481. return this;
  24482. }
  24483. // If index is negative, it should resolve relative to the size of the
  24484. // collection. However size may be expensive to compute if not cached, so
  24485. // only call count() if the number is in fact negative.
  24486. index = resolveBegin(index, index < 0 ? this.count() : this.size);
  24487. var spliced = this.slice(0, index);
  24488. return reify(
  24489. this,
  24490. numArgs === 1 ?
  24491. spliced :
  24492. spliced.concat(arrCopy(arguments, 2), this.slice(index + removeNum))
  24493. );
  24494. },
  24495. // ### More collection methods
  24496. findLastIndex: function(predicate, context) {
  24497. var key = this.toKeyedSeq().findLastKey(predicate, context);
  24498. return key === undefined ? -1 : key;
  24499. },
  24500. first: function() {
  24501. return this.get(0);
  24502. },
  24503. flatten: function(depth) {
  24504. return reify(this, flattenFactory(this, depth, false));
  24505. },
  24506. get: function(index, notSetValue) {
  24507. index = wrapIndex(this, index);
  24508. return (index < 0 || (this.size === Infinity ||
  24509. (this.size !== undefined && index > this.size))) ?
  24510. notSetValue :
  24511. this.find(function(_, key) {return key === index}, undefined, notSetValue);
  24512. },
  24513. has: function(index) {
  24514. index = wrapIndex(this, index);
  24515. return index >= 0 && (this.size !== undefined ?
  24516. this.size === Infinity || index < this.size :
  24517. this.indexOf(index) !== -1
  24518. );
  24519. },
  24520. interpose: function(separator) {
  24521. return reify(this, interposeFactory(this, separator));
  24522. },
  24523. interleave: function(/*...iterables*/) {
  24524. var iterables = [this].concat(arrCopy(arguments));
  24525. var zipped = zipWithFactory(this.toSeq(), IndexedSeq.of, iterables);
  24526. var interleaved = zipped.flatten(true);
  24527. if (zipped.size) {
  24528. interleaved.size = zipped.size * iterables.length;
  24529. }
  24530. return reify(this, interleaved);
  24531. },
  24532. last: function() {
  24533. return this.get(-1);
  24534. },
  24535. skipWhile: function(predicate, context) {
  24536. return reify(this, skipWhileFactory(this, predicate, context, false));
  24537. },
  24538. zip: function(/*, ...iterables */) {
  24539. var iterables = [this].concat(arrCopy(arguments));
  24540. return reify(this, zipWithFactory(this, defaultZipper, iterables));
  24541. },
  24542. zipWith: function(zipper/*, ...iterables */) {
  24543. var iterables = arrCopy(arguments);
  24544. iterables[0] = this;
  24545. return reify(this, zipWithFactory(this, zipper, iterables));
  24546. }
  24547. });
  24548. IndexedIterable.prototype[IS_INDEXED_SENTINEL] = true;
  24549. IndexedIterable.prototype[IS_ORDERED_SENTINEL] = true;
  24550. mixin(SetIterable, {
  24551. // ### ES6 Collection methods (ES6 Array and Map)
  24552. get: function(value, notSetValue) {
  24553. return this.has(value) ? value : notSetValue;
  24554. },
  24555. includes: function(value) {
  24556. return this.has(value);
  24557. },
  24558. // ### More sequential methods
  24559. keySeq: function() {
  24560. return this.valueSeq();
  24561. }
  24562. });
  24563. SetIterable.prototype.has = IterablePrototype.includes;
  24564. // Mixin subclasses
  24565. mixin(KeyedSeq, KeyedIterable.prototype);
  24566. mixin(IndexedSeq, IndexedIterable.prototype);
  24567. mixin(SetSeq, SetIterable.prototype);
  24568. mixin(KeyedCollection, KeyedIterable.prototype);
  24569. mixin(IndexedCollection, IndexedIterable.prototype);
  24570. mixin(SetCollection, SetIterable.prototype);
  24571. // #pragma Helper functions
  24572. function keyMapper(v, k) {
  24573. return k;
  24574. }
  24575. function entryMapper(v, k) {
  24576. return [k, v];
  24577. }
  24578. function not(predicate) {
  24579. return function() {
  24580. return !predicate.apply(this, arguments);
  24581. }
  24582. }
  24583. function neg(predicate) {
  24584. return function() {
  24585. return -predicate.apply(this, arguments);
  24586. }
  24587. }
  24588. function quoteString(value) {
  24589. return typeof value === 'string' ? JSON.stringify(value) : value;
  24590. }
  24591. function defaultZipper() {
  24592. return arrCopy(arguments);
  24593. }
  24594. function defaultNegComparator(a, b) {
  24595. return a < b ? 1 : a > b ? -1 : 0;
  24596. }
  24597. function hashIterable(iterable) {
  24598. if (iterable.size === Infinity) {
  24599. return 0;
  24600. }
  24601. var ordered = isOrdered(iterable);
  24602. var keyed = isKeyed(iterable);
  24603. var h = ordered ? 1 : 0;
  24604. var size = iterable.__iterate(
  24605. keyed ?
  24606. ordered ?
  24607. function(v, k) { h = 31 * h + hashMerge(hash(v), hash(k)) | 0; } :
  24608. function(v, k) { h = h + hashMerge(hash(v), hash(k)) | 0; } :
  24609. ordered ?
  24610. function(v ) { h = 31 * h + hash(v) | 0; } :
  24611. function(v ) { h = h + hash(v) | 0; }
  24612. );
  24613. return murmurHashOfSize(size, h);
  24614. }
  24615. function murmurHashOfSize(size, h) {
  24616. h = imul(h, 0xCC9E2D51);
  24617. h = imul(h << 15 | h >>> -15, 0x1B873593);
  24618. h = imul(h << 13 | h >>> -13, 5);
  24619. h = (h + 0xE6546B64 | 0) ^ size;
  24620. h = imul(h ^ h >>> 16, 0x85EBCA6B);
  24621. h = imul(h ^ h >>> 13, 0xC2B2AE35);
  24622. h = smi(h ^ h >>> 16);
  24623. return h;
  24624. }
  24625. function hashMerge(a, b) {
  24626. return a ^ b + 0x9E3779B9 + (a << 6) + (a >> 2) | 0; // int
  24627. }
  24628. var Immutable = {
  24629. Iterable: Iterable,
  24630. Seq: Seq,
  24631. Collection: Collection,
  24632. Map: Map,
  24633. OrderedMap: OrderedMap,
  24634. List: List,
  24635. Stack: Stack,
  24636. Set: Set,
  24637. OrderedSet: OrderedSet,
  24638. Record: Record,
  24639. Range: Range,
  24640. Repeat: Repeat,
  24641. is: is,
  24642. fromJS: fromJS
  24643. };
  24644. return Immutable;
  24645. }));
  24646. });
  24647. var parseHTML_1 = createCommonjsModule(function (module, exports) {
  24648. Object.defineProperty(exports, "__esModule", {
  24649. value: true
  24650. });
  24651. exports["default"] = parseHTML;
  24652. var fallback = function fallback(html) {
  24653. var doc = document.implementation.createHTMLDocument('');
  24654. doc.documentElement.innerHTML = html;
  24655. return doc;
  24656. };
  24657. function parseHTML(html) {
  24658. var doc;
  24659. if (typeof DOMParser !== 'undefined') {
  24660. var parser = new DOMParser();
  24661. doc = parser.parseFromString(html, 'text/html');
  24662. if (doc === null || doc.body === null) {
  24663. doc = fallback(html);
  24664. }
  24665. } else {
  24666. doc = fallback(html);
  24667. }
  24668. return doc.body;
  24669. }
  24670. });
  24671. unwrapExports(parseHTML_1);
  24672. var convertFromHTML_1 = createCommonjsModule(function (module, exports) {
  24673. Object.defineProperty(exports, "__esModule", {
  24674. value: true
  24675. });
  24676. exports["default"] = void 0;
  24677. var _parseHTML = interopRequireDefault(parseHTML_1);
  24678. var _rangeSort = interopRequireDefault(rangeSort);
  24679. /**
  24680. * Copyright (c) 2013-present, Facebook, Inc.
  24681. * All rights reserved.
  24682. *
  24683. * Copyright (c) 2013-present, Facebook, Inc.
  24684. * All rights reserved.
  24685. *
  24686. * This source code is licensed under the BSD-style license found in the
  24687. * LICENSE file in the /src directory of this source tree. An additional grant
  24688. * of patent rights can be found in the PATENTS file in the same directory.
  24689. */
  24690. var NBSP = '&nbsp;';
  24691. var SPACE = ' '; // Arbitrary max indent
  24692. var MAX_DEPTH = 4; // used for replacing characters in HTML
  24693. /* eslint-disable no-control-regex */
  24694. var REGEX_CR = new RegExp('\r', 'g');
  24695. var REGEX_LF = new RegExp('\n', 'g');
  24696. var REGEX_NBSP = new RegExp(NBSP, 'g');
  24697. var REGEX_BLOCK_DELIMITER = new RegExp('\r', 'g');
  24698. /* eslint-enable no-control-regex */
  24699. // Block tag flow is different because LIs do not have
  24700. // a deterministic style ;_;
  24701. var blockTags = ['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'li', 'blockquote', 'pre'];
  24702. var inlineTags = {
  24703. b: 'BOLD',
  24704. code: 'CODE',
  24705. del: 'STRIKETHROUGH',
  24706. em: 'ITALIC',
  24707. i: 'ITALIC',
  24708. s: 'STRIKETHROUGH',
  24709. strike: 'STRIKETHROUGH',
  24710. strong: 'BOLD',
  24711. u: 'UNDERLINE'
  24712. };
  24713. var handleMiddleware = function handleMiddleware(maybeMiddleware, base) {
  24714. if (maybeMiddleware && maybeMiddleware.__isMiddleware === true) {
  24715. return maybeMiddleware(base);
  24716. }
  24717. return maybeMiddleware;
  24718. };
  24719. var defaultHTMLToBlock = function defaultHTMLToBlock(nodeName, node, lastList) {
  24720. return undefined;
  24721. };
  24722. var defaultHTMLToStyle = function defaultHTMLToStyle(nodeName, node, currentStyle) {
  24723. return currentStyle;
  24724. };
  24725. var defaultHTMLToEntity = function defaultHTMLToEntity(nodeName, node) {
  24726. return undefined;
  24727. };
  24728. var defaultTextToEntity = function defaultTextToEntity(text) {
  24729. return [];
  24730. };
  24731. var nullthrows = function nullthrows(x) {
  24732. if (x != null) {
  24733. return x;
  24734. }
  24735. throw new Error('Got unexpected null or undefined');
  24736. };
  24737. var sanitizeDraftText = function sanitizeDraftText(input) {
  24738. return input.replace(REGEX_BLOCK_DELIMITER, '');
  24739. };
  24740. function getEmptyChunk() {
  24741. return {
  24742. text: '',
  24743. inlines: [],
  24744. entities: [],
  24745. blocks: []
  24746. };
  24747. }
  24748. function getWhitespaceChunk(inEntity) {
  24749. var entities = new Array(1);
  24750. if (inEntity) {
  24751. entities[0] = inEntity;
  24752. }
  24753. return {
  24754. text: SPACE,
  24755. inlines: [(0, immutable$2.OrderedSet)()],
  24756. entities: entities,
  24757. blocks: []
  24758. };
  24759. }
  24760. function getSoftNewlineChunk(block, depth) {
  24761. var flat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  24762. var data = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : (0, immutable$2.Map)();
  24763. if (flat === true) {
  24764. return {
  24765. text: '\r',
  24766. inlines: [(0, immutable$2.OrderedSet)()],
  24767. entities: new Array(1),
  24768. blocks: [{
  24769. type: block,
  24770. data: data,
  24771. depth: Math.max(0, Math.min(MAX_DEPTH, depth))
  24772. }],
  24773. isNewline: true
  24774. };
  24775. }
  24776. return {
  24777. text: '\n',
  24778. inlines: [(0, immutable$2.OrderedSet)()],
  24779. entities: new Array(1),
  24780. blocks: []
  24781. };
  24782. }
  24783. function getBlockDividerChunk(block, depth) {
  24784. var data = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : (0, immutable$2.Map)();
  24785. return {
  24786. text: '\r',
  24787. inlines: [(0, immutable$2.OrderedSet)()],
  24788. entities: new Array(1),
  24789. blocks: [{
  24790. type: block,
  24791. data: data,
  24792. depth: Math.max(0, Math.min(MAX_DEPTH, depth))
  24793. }]
  24794. };
  24795. }
  24796. function getBlockTypeForTag(tag, lastList) {
  24797. switch (tag) {
  24798. case 'h1':
  24799. return 'header-one';
  24800. case 'h2':
  24801. return 'header-two';
  24802. case 'h3':
  24803. return 'header-three';
  24804. case 'h4':
  24805. return 'header-four';
  24806. case 'h5':
  24807. return 'header-five';
  24808. case 'h6':
  24809. return 'header-six';
  24810. case 'li':
  24811. if (lastList === 'ol') {
  24812. return 'ordered-list-item';
  24813. }
  24814. return 'unordered-list-item';
  24815. case 'blockquote':
  24816. return 'blockquote';
  24817. case 'pre':
  24818. return 'code-block';
  24819. case 'div':
  24820. case 'p':
  24821. return 'unstyled';
  24822. default:
  24823. return null;
  24824. }
  24825. }
  24826. function baseCheckBlockType(nodeName, node, lastList) {
  24827. return getBlockTypeForTag(nodeName, lastList);
  24828. }
  24829. function processInlineTag(tag, node, currentStyle) {
  24830. var styleToCheck = inlineTags[tag];
  24831. if (styleToCheck) {
  24832. currentStyle = currentStyle.add(styleToCheck).toOrderedSet();
  24833. } else if (node instanceof HTMLElement) {
  24834. var htmlElement = node;
  24835. currentStyle = currentStyle.withMutations(function (style) {
  24836. if (htmlElement.style.fontWeight === 'bold') {
  24837. style.add('BOLD');
  24838. }
  24839. if (htmlElement.style.fontStyle === 'italic') {
  24840. style.add('ITALIC');
  24841. }
  24842. if (htmlElement.style.textDecoration === 'underline') {
  24843. style.add('UNDERLINE');
  24844. }
  24845. if (htmlElement.style.textDecoration === 'line-through') {
  24846. style.add('STRIKETHROUGH');
  24847. }
  24848. }).toOrderedSet();
  24849. }
  24850. return currentStyle;
  24851. }
  24852. function baseProcessInlineTag(tag, node) {
  24853. var inlineStyles = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : (0, immutable$2.OrderedSet)();
  24854. return processInlineTag(tag, node, inlineStyles);
  24855. }
  24856. function joinChunks(A, B) {
  24857. var flat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  24858. // Sometimes two blocks will touch in the DOM and we need to strip the
  24859. // extra delimiter to preserve niceness.
  24860. var firstInB = B.text.slice(0, 1);
  24861. var lastInA = A.text.slice(-1);
  24862. var adjacentDividers = lastInA === '\r' && firstInB === '\r';
  24863. var isJoiningBlocks = A.text !== '\r' && B.text !== '\r'; // when joining two full blocks like this we want to pop one divider
  24864. var addingNewlineToEmptyBlock = A.text === '\r' && !A.isNewline && B.isNewline; // when joining a newline to an empty block we want to remove the newline
  24865. if (adjacentDividers && (isJoiningBlocks || addingNewlineToEmptyBlock)) {
  24866. A.text = A.text.slice(0, -1);
  24867. A.inlines.pop();
  24868. A.entities.pop();
  24869. A.blocks.pop();
  24870. } // Kill whitespace after blocks if flat mode is on
  24871. if (A.text.slice(-1) === '\r' && flat === true) {
  24872. if (B.text === SPACE || B.text === '\n') {
  24873. return A;
  24874. } else if (firstInB === SPACE || firstInB === '\n') {
  24875. B.text = B.text.slice(1);
  24876. B.inlines.shift();
  24877. B.entities.shift();
  24878. }
  24879. }
  24880. var isNewline = A.text.length === 0 && B.isNewline;
  24881. return {
  24882. text: A.text + B.text,
  24883. inlines: A.inlines.concat(B.inlines),
  24884. entities: A.entities.concat(B.entities),
  24885. blocks: A.blocks.concat(B.blocks),
  24886. isNewline: isNewline
  24887. };
  24888. }
  24889. /*
  24890. * Check to see if we have anything like <p> <blockquote> <h1>... to create
  24891. * block tags from. If we do, we can use those and ignore <div> tags. If we
  24892. * don't, we can treat <div> tags as meaningful (unstyled) blocks.
  24893. */
  24894. function containsSemanticBlockMarkup(html) {
  24895. return blockTags.some(function (tag) {
  24896. return html.indexOf("<".concat(tag)) !== -1;
  24897. });
  24898. }
  24899. function genFragment(node, inlineStyle, lastList, inBlock, fragmentBlockTags, depth, processCustomInlineStyles, checkEntityNode, checkEntityText, checkBlockType, createEntity, getEntity, mergeEntityData, replaceEntityData, options, inEntity) {
  24900. var nodeName = node.nodeName.toLowerCase();
  24901. var newBlock = false;
  24902. var nextBlockType = 'unstyled'; // Base Case
  24903. if (nodeName === '#text') {
  24904. var text = node.textContent;
  24905. if (text.trim() === '' && inBlock === null) {
  24906. return getEmptyChunk();
  24907. }
  24908. if (text.trim() === '' && inBlock !== 'code-block') {
  24909. return getWhitespaceChunk(inEntity);
  24910. }
  24911. if (inBlock !== 'code-block') {
  24912. // Can't use empty string because MSWord
  24913. text = text.replace(REGEX_LF, SPACE);
  24914. }
  24915. var entities = Array(text.length).fill(inEntity);
  24916. var offsetChange = 0;
  24917. var textEntities = checkEntityText(text, createEntity, getEntity, mergeEntityData, replaceEntityData).sort(_rangeSort["default"]);
  24918. textEntities.forEach(function (_ref) {
  24919. var entity = _ref.entity,
  24920. offset = _ref.offset,
  24921. length = _ref.length,
  24922. result = _ref.result;
  24923. var adjustedOffset = offset + offsetChange;
  24924. if (result === null || result === undefined) {
  24925. result = text.substr(adjustedOffset, length);
  24926. }
  24927. var textArray = text.split('');
  24928. textArray.splice.bind(textArray, adjustedOffset, length).apply(textArray, result.split(''));
  24929. text = textArray.join('');
  24930. entities.splice.bind(entities, adjustedOffset, length).apply(entities, Array(result.length).fill(entity));
  24931. offsetChange += result.length - length;
  24932. });
  24933. return {
  24934. text: text,
  24935. inlines: Array(text.length).fill(inlineStyle),
  24936. entities: entities,
  24937. blocks: []
  24938. };
  24939. } // BR tags
  24940. if (nodeName === 'br') {
  24941. var _blockType = inBlock;
  24942. if (_blockType === null) {
  24943. // BR tag is at top level, treat it as an unstyled block
  24944. return getSoftNewlineChunk('unstyled', depth, true);
  24945. }
  24946. return getSoftNewlineChunk(_blockType || 'unstyled', depth, options.flat);
  24947. }
  24948. var chunk = getEmptyChunk();
  24949. var newChunk = null; // Inline tags
  24950. inlineStyle = processInlineTag(nodeName, node, inlineStyle);
  24951. inlineStyle = processCustomInlineStyles(nodeName, node, inlineStyle); // Handle lists
  24952. if (nodeName === 'ul' || nodeName === 'ol') {
  24953. if (lastList) {
  24954. depth += 1;
  24955. }
  24956. lastList = nodeName;
  24957. inBlock = null;
  24958. } // Block Tags
  24959. var blockInfo = checkBlockType(nodeName, node, lastList, inBlock);
  24960. var blockType;
  24961. var blockDataMap;
  24962. if (blockInfo === false) {
  24963. return getEmptyChunk();
  24964. }
  24965. blockInfo = blockInfo || {};
  24966. if (typeof blockInfo === 'string') {
  24967. blockType = blockInfo;
  24968. blockDataMap = (0, immutable$2.Map)();
  24969. } else {
  24970. blockType = typeof blockInfo === 'string' ? blockInfo : blockInfo.type;
  24971. blockDataMap = blockInfo.data ? (0, immutable$2.Map)(blockInfo.data) : (0, immutable$2.Map)();
  24972. }
  24973. if (!inBlock && (fragmentBlockTags.indexOf(nodeName) !== -1 || blockType)) {
  24974. chunk = getBlockDividerChunk(blockType || getBlockTypeForTag(nodeName, lastList), depth, blockDataMap);
  24975. inBlock = blockType || getBlockTypeForTag(nodeName, lastList);
  24976. newBlock = true;
  24977. } else if (lastList && (inBlock === 'ordered-list-item' || inBlock === 'unordered-list-item') && nodeName === 'li') {
  24978. var listItemBlockType = getBlockTypeForTag(nodeName, lastList);
  24979. chunk = getBlockDividerChunk(listItemBlockType, depth);
  24980. inBlock = listItemBlockType;
  24981. newBlock = true;
  24982. nextBlockType = lastList === 'ul' ? 'unordered-list-item' : 'ordered-list-item';
  24983. } else if (inBlock && inBlock !== 'atomic' && blockType === 'atomic') {
  24984. inBlock = blockType;
  24985. newBlock = true;
  24986. chunk = getSoftNewlineChunk(blockType, depth, true, // atomic blocks within non-atomic blocks must always be split out
  24987. blockDataMap);
  24988. } // Recurse through children
  24989. var child = node.firstChild; // hack to allow conversion of atomic blocks from HTML (e.g. <figure><img
  24990. // src="..." /></figure>). since metadata must be stored on an entity text
  24991. // must exist for the entity to apply to. the way chunks are joined strips
  24992. // whitespace at the end so it cannot be a space character.
  24993. if (child == null && inEntity && (blockType === 'atomic' || inBlock === 'atomic')) {
  24994. child = document.createTextNode('a');
  24995. }
  24996. if (child != null) {
  24997. nodeName = child.nodeName.toLowerCase();
  24998. }
  24999. var entityId = null;
  25000. while (child) {
  25001. entityId = checkEntityNode(nodeName, child, createEntity, getEntity, mergeEntityData, replaceEntityData);
  25002. newChunk = genFragment(child, inlineStyle, lastList, inBlock, fragmentBlockTags, depth, processCustomInlineStyles, checkEntityNode, checkEntityText, checkBlockType, createEntity, getEntity, mergeEntityData, replaceEntityData, options, entityId || inEntity);
  25003. chunk = joinChunks(chunk, newChunk, options.flat);
  25004. var sibling = child.nextSibling; // Put in a newline to break up blocks inside blocks
  25005. if (sibling && fragmentBlockTags.indexOf(nodeName) >= 0 && inBlock) {
  25006. var newBlockInfo = checkBlockType(nodeName, child, lastList, inBlock);
  25007. var newBlockType = void 0;
  25008. var newBlockData = void 0;
  25009. if (newBlockInfo !== false) {
  25010. newBlockInfo = newBlockInfo || {};
  25011. if (typeof newBlockInfo === 'string') {
  25012. newBlockType = newBlockInfo;
  25013. newBlockData = (0, immutable$2.Map)();
  25014. } else {
  25015. newBlockType = newBlockInfo.type || getBlockTypeForTag(nodeName, lastList);
  25016. newBlockData = newBlockInfo.data ? (0, immutable$2.Map)(newBlockInfo.data) : (0, immutable$2.Map)();
  25017. }
  25018. chunk = joinChunks(chunk, getSoftNewlineChunk(newBlockType, depth, options.flat, newBlockData), options.flat);
  25019. }
  25020. }
  25021. if (sibling) {
  25022. nodeName = sibling.nodeName.toLowerCase();
  25023. }
  25024. child = sibling;
  25025. }
  25026. if (newBlock) {
  25027. chunk = joinChunks(chunk, getBlockDividerChunk(nextBlockType, depth, (0, immutable$2.Map)()), options.flat);
  25028. }
  25029. return chunk;
  25030. }
  25031. function getChunkForHTML(html, processCustomInlineStyles, checkEntityNode, checkEntityText, checkBlockType, createEntity, getEntity, mergeEntityData, replaceEntityData, options, DOMBuilder) {
  25032. html = html.trim().replace(REGEX_CR, '').replace(REGEX_NBSP, SPACE);
  25033. var safeBody = DOMBuilder(html);
  25034. if (!safeBody) {
  25035. return null;
  25036. } // Sometimes we aren't dealing with content that contains nice semantic
  25037. // tags. In this case, use divs to separate everything out into paragraphs
  25038. // and hope for the best.
  25039. var workingBlocks = containsSemanticBlockMarkup(html) ? blockTags.concat(['div']) : ['div']; // Start with -1 block depth to offset the fact that we are passing in a fake
  25040. // UL block to sta rt with.
  25041. 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
  25042. if (chunk.text.indexOf('\r') === 0) {
  25043. chunk = {
  25044. text: chunk.text.slice(1),
  25045. inlines: chunk.inlines.slice(1),
  25046. entities: chunk.entities.slice(1),
  25047. blocks: chunk.blocks
  25048. };
  25049. } // Kill block delimiter at the end
  25050. if (chunk.text.slice(-1) === '\r') {
  25051. chunk.text = chunk.text.slice(0, -1);
  25052. chunk.inlines = chunk.inlines.slice(0, -1);
  25053. chunk.entities = chunk.entities.slice(0, -1);
  25054. chunk.blocks.pop();
  25055. } // If we saw no block tags, put an unstyled one in
  25056. if (chunk.blocks.length === 0) {
  25057. chunk.blocks.push({
  25058. type: 'unstyled',
  25059. data: (0, immutable$2.Map)(),
  25060. depth: 0
  25061. });
  25062. } // Sometimes we start with text that isn't in a block, which is then
  25063. // followed by blocks. Need to fix up the blocks to add in
  25064. // an unstyled block for this content
  25065. if (chunk.text.split('\r').length === chunk.blocks.length + 1) {
  25066. chunk.blocks.unshift({
  25067. type: 'unstyled',
  25068. data: (0, immutable$2.Map)(),
  25069. depth: 0
  25070. });
  25071. }
  25072. return chunk;
  25073. }
  25074. function convertFromHTMLtoContentBlocks(html, processCustomInlineStyles, checkEntityNode, checkEntityText, checkBlockType, createEntity, getEntity, mergeEntityData, replaceEntityData, options, DOMBuilder, generateKey) {
  25075. // Be ABSOLUTELY SURE that the dom builder you pass hare won't execute
  25076. // arbitrary code in whatever environment you're running this in. For an
  25077. // example of how we try to do this in-browser, see getSafeBodyFromHTML.
  25078. var chunk = getChunkForHTML(html, processCustomInlineStyles, checkEntityNode, checkEntityText, checkBlockType, createEntity, getEntity, mergeEntityData, replaceEntityData, options, DOMBuilder);
  25079. if (chunk == null) {
  25080. return [];
  25081. }
  25082. var start = 0;
  25083. return chunk.text.split('\r').map(function (textBlock, blockIndex) {
  25084. // Make absolutely certain that our text is acceptable.
  25085. textBlock = sanitizeDraftText(textBlock);
  25086. var end = start + textBlock.length;
  25087. var inlines = nullthrows(chunk).inlines.slice(start, end);
  25088. var entities = nullthrows(chunk).entities.slice(start, end);
  25089. var characterList = (0, immutable$2.List)(inlines.map(function (style, entityIndex) {
  25090. var data = {
  25091. style: style,
  25092. entity: null
  25093. };
  25094. if (entities[entityIndex]) {
  25095. data.entity = entities[entityIndex];
  25096. }
  25097. return Draft.CharacterMetadata.create(data);
  25098. }));
  25099. start = end + 1;
  25100. return new Draft.ContentBlock({
  25101. key: generateKey(),
  25102. type: nullthrows(chunk).blocks[blockIndex].type,
  25103. data: nullthrows(chunk).blocks[blockIndex].data,
  25104. depth: nullthrows(chunk).blocks[blockIndex].depth,
  25105. text: textBlock,
  25106. characterList: characterList
  25107. });
  25108. });
  25109. }
  25110. var convertFromHTML = function convertFromHTML(_ref2) {
  25111. var _ref2$htmlToStyle = _ref2.htmlToStyle,
  25112. htmlToStyle = _ref2$htmlToStyle === void 0 ? defaultHTMLToStyle : _ref2$htmlToStyle,
  25113. _ref2$htmlToEntity = _ref2.htmlToEntity,
  25114. htmlToEntity = _ref2$htmlToEntity === void 0 ? defaultHTMLToEntity : _ref2$htmlToEntity,
  25115. _ref2$textToEntity = _ref2.textToEntity,
  25116. textToEntity = _ref2$textToEntity === void 0 ? defaultTextToEntity : _ref2$textToEntity,
  25117. _ref2$htmlToBlock = _ref2.htmlToBlock,
  25118. htmlToBlock = _ref2$htmlToBlock === void 0 ? defaultHTMLToBlock : _ref2$htmlToBlock;
  25119. return function (html) {
  25120. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
  25121. flat: false
  25122. };
  25123. var DOMBuilder = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _parseHTML["default"];
  25124. var generateKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : Draft.genKey;
  25125. var contentState = Draft.ContentState.createFromText('');
  25126. var createEntityWithContentState = function createEntityWithContentState() {
  25127. if (contentState.createEntity) {
  25128. var _contentState;
  25129. contentState = (_contentState = contentState).createEntity.apply(_contentState, arguments);
  25130. return contentState.getLastCreatedEntityKey();
  25131. }
  25132. return Draft.Entity.create.apply(Draft.Entity, arguments);
  25133. };
  25134. var getEntityWithContentState = function getEntityWithContentState() {
  25135. if (contentState.getEntity) {
  25136. var _contentState2;
  25137. return (_contentState2 = contentState).getEntity.apply(_contentState2, arguments);
  25138. }
  25139. return Draft.Entity.get.apply(Draft.Entity, arguments);
  25140. };
  25141. var mergeEntityDataWithContentState = function mergeEntityDataWithContentState() {
  25142. if (contentState.mergeEntityData) {
  25143. var _contentState3;
  25144. contentState = (_contentState3 = contentState).mergeEntityData.apply(_contentState3, arguments);
  25145. return;
  25146. }
  25147. Draft.Entity.mergeData.apply(Draft.Entity, arguments);
  25148. };
  25149. var replaceEntityDataWithContentState = function replaceEntityDataWithContentState() {
  25150. if (contentState.replaceEntityData) {
  25151. var _contentState4;
  25152. contentState = (_contentState4 = contentState).replaceEntityData.apply(_contentState4, arguments);
  25153. return;
  25154. }
  25155. Draft.Entity.replaceData.apply(Draft.Entity, arguments);
  25156. };
  25157. var contentBlocks = convertFromHTMLtoContentBlocks(html, handleMiddleware(htmlToStyle, baseProcessInlineTag), handleMiddleware(htmlToEntity, defaultHTMLToEntity), handleMiddleware(textToEntity, defaultTextToEntity), handleMiddleware(htmlToBlock, baseCheckBlockType), createEntityWithContentState, getEntityWithContentState, mergeEntityDataWithContentState, replaceEntityDataWithContentState, options, DOMBuilder, generateKey);
  25158. var blockMap = Draft.BlockMapBuilder.createFromArray(contentBlocks);
  25159. var firstBlockKey = contentBlocks[0].getKey();
  25160. return contentState.merge({
  25161. blockMap: blockMap,
  25162. selectionBefore: Draft.SelectionState.createEmpty(firstBlockKey),
  25163. selectionAfter: Draft.SelectionState.createEmpty(firstBlockKey)
  25164. });
  25165. };
  25166. };
  25167. var _default = function _default() {
  25168. if (arguments.length >= 1 && typeof (arguments.length <= 0 ? undefined : arguments[0]) === 'string') {
  25169. return convertFromHTML({}).apply(void 0, arguments);
  25170. }
  25171. return convertFromHTML.apply(void 0, arguments);
  25172. };
  25173. exports["default"] = _default;
  25174. });
  25175. unwrapExports(convertFromHTML_1);
  25176. var lib = createCommonjsModule(function (module, exports) {
  25177. Object.defineProperty(exports, "__esModule", {
  25178. value: true
  25179. });
  25180. Object.defineProperty(exports, "convertToHTML", {
  25181. enumerable: true,
  25182. get: function get() {
  25183. return _convertToHTML["default"];
  25184. }
  25185. });
  25186. Object.defineProperty(exports, "convertFromHTML", {
  25187. enumerable: true,
  25188. get: function get() {
  25189. return _convertFromHTML["default"];
  25190. }
  25191. });
  25192. Object.defineProperty(exports, "parseHTML", {
  25193. enumerable: true,
  25194. get: function get() {
  25195. return _parseHTML["default"];
  25196. }
  25197. });
  25198. var _convertToHTML = interopRequireDefault(convertToHTML_1);
  25199. var _convertFromHTML = interopRequireDefault(convertFromHTML_1);
  25200. var _parseHTML = interopRequireDefault(parseHTML_1);
  25201. });
  25202. unwrapExports(lib);
  25203. var configs = createCommonjsModule(function (module, exports) {
  25204. Object.defineProperty(exports, "__esModule", {
  25205. value: true
  25206. });
  25207. exports.getFromHTMLConfig = exports.getToHTMLConfig = exports.blocks = exports.getHexColor = exports.defaultFontFamilies = exports.namedColors = undefined;
  25208. 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; };
  25209. var _react2 = _interopRequireDefault(React);
  25210. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  25211. 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; }
  25212. var namedColors = exports.namedColors = {
  25213. "aliceblue": "#f0f8ff",
  25214. "antiquewhite": "#faebd7",
  25215. "aqua": "#00ffff",
  25216. "aquamarine": "#7fffd4",
  25217. "azure": "#f0ffff",
  25218. "beige": "#f5f5dc",
  25219. "bisque": "#ffe4c4",
  25220. "black": "#000000",
  25221. "blanchedalmond": "#ffebcd",
  25222. "blue": "#0000ff",
  25223. "blueviolet": "#8a2be2",
  25224. "brown": "#a52a2a",
  25225. "burlywood": "#deb887",
  25226. "cadetblue": "#5f9ea0",
  25227. "chartreuse": "#7fff00",
  25228. "chocolate": "#d2691e",
  25229. "coral": "#ff7f50",
  25230. "cornflowerblue": "#6495ed",
  25231. "cornsilk": "#fff8dc",
  25232. "crimson": "#dc143c",
  25233. "cyan": "#00ffff",
  25234. "darkblue": "#00008b",
  25235. "darkcyan": "#008b8b",
  25236. "darkgoldenrod": "#b8860b",
  25237. "darkgray": "#a9a9a9",
  25238. "darkgreen": "#006400",
  25239. "darkkhaki": "#bdb76b",
  25240. "darkmagenta": "#8b008b",
  25241. "darkolivegreen": "#556b2f",
  25242. "darkorange": "#ff8c00",
  25243. "darkorchid": "#9932cc",
  25244. "darkred": "#8b0000",
  25245. "darksalmon": "#e9967a",
  25246. "darkseagreen": "#8fbc8f",
  25247. "darkslateblue": "#483d8b",
  25248. "darkslategray": "#2f4f4f",
  25249. "darkturquoise": "#00ced1",
  25250. "darkviolet": "#9400d3",
  25251. "deeppink": "#ff1493",
  25252. "deepskyblue": "#00bfff",
  25253. "dimgray": "#696969",
  25254. "dodgerblue": "#1e90ff",
  25255. "firebrick": "#b22222",
  25256. "floralwhite": "#fffaf0",
  25257. "forestgreen": "#228b22",
  25258. "fuchsia": "#ff00ff",
  25259. "gainsboro": "#dcdcdc",
  25260. "ghostwhite": "#f8f8ff",
  25261. "gold": "#ffd700",
  25262. "goldenrod": "#daa520",
  25263. "gray": "#808080",
  25264. "green": "#008000",
  25265. "greenyellow": "#adff2f",
  25266. "honeydew": "#f0fff0",
  25267. "hotpink": "#ff69b4",
  25268. "indianred ": "#cd5c5c",
  25269. "indigo": "#4b0082",
  25270. "ivory": "#fffff0",
  25271. "khaki": "#f0e68c",
  25272. "lavender": "#e6e6fa",
  25273. "lavenderblush": "#fff0f5",
  25274. "lawngreen": "#7cfc00",
  25275. "lemonchiffon": "#fffacd",
  25276. "lightblue": "#add8e6",
  25277. "lightcoral": "#f08080",
  25278. "lightcyan": "#e0ffff",
  25279. "lightgoldenrodyellow": "#fafad2",
  25280. "lightgrey": "#d3d3d3",
  25281. "lightgreen": "#90ee90",
  25282. "lightpink": "#ffb6c1",
  25283. "lightsalmon": "#ffa07a",
  25284. "lightseagreen": "#20b2aa",
  25285. "lightskyblue": "#87cefa",
  25286. "lightslategray": "#778899",
  25287. "lightsteelblue": "#b0c4de",
  25288. "lightyellow": "#ffffe0",
  25289. "lime": "#00ff00",
  25290. "limegreen": "#32cd32",
  25291. "linen": "#faf0e6",
  25292. "magenta": "#ff00ff",
  25293. "maroon": "#800000",
  25294. "mediumaquamarine": "#66cdaa",
  25295. "mediumblue": "#0000cd",
  25296. "mediumorchid": "#ba55d3",
  25297. "mediumpurple": "#9370d8",
  25298. "mediumseagreen": "#3cb371",
  25299. "mediumslateblue": "#7b68ee",
  25300. "mediumspringgreen": "#00fa9a",
  25301. "mediumturquoise": "#48d1cc",
  25302. "mediumvioletred": "#c71585",
  25303. "midnightblue": "#191970",
  25304. "mintcream": "#f5fffa",
  25305. "mistyrose": "#ffe4e1",
  25306. "moccasin": "#ffe4b5",
  25307. "navajowhite": "#ffdead",
  25308. "navy": "#000080",
  25309. "oldlace": "#fdf5e6",
  25310. "olive": "#808000",
  25311. "olivedrab": "#6b8e23",
  25312. "orange": "#ffa500",
  25313. "orangered": "#ff4500",
  25314. "orchid": "#da70d6",
  25315. "palegoldenrod": "#eee8aa",
  25316. "palegreen": "#98fb98",
  25317. "paleturquoise": "#afeeee",
  25318. "palevioletred": "#d87093",
  25319. "papayawhip": "#ffefd5",
  25320. "peachpuff": "#ffdab9",
  25321. "peru": "#cd853f",
  25322. "pink": "#ffc0cb",
  25323. "plum": "#dda0dd",
  25324. "powderblue": "#b0e0e6",
  25325. "purple": "#800080",
  25326. "rebeccapurple": "#663399",
  25327. "red": "#ff0000",
  25328. "rosybrown": "#bc8f8f",
  25329. "royalblue": "#4169e1",
  25330. "saddlebrown": "#8b4513",
  25331. "salmon": "#fa8072",
  25332. "sandybrown": "#f4a460",
  25333. "seagreen": "#2e8b57",
  25334. "seashell": "#fff5ee",
  25335. "sienna": "#a0522d",
  25336. "silver": "#c0c0c0",
  25337. "skyblue": "#87ceeb",
  25338. "slateblue": "#6a5acd",
  25339. "slategray": "#708090",
  25340. "snow": "#fffafa",
  25341. "springgreen": "#00ff7f",
  25342. "steelblue": "#4682b4",
  25343. "tan": "#d2b48c",
  25344. "teal": "#008080",
  25345. "thistle": "#d8bfd8",
  25346. "tomato": "#ff6347",
  25347. "turquoise": "#40e0d0",
  25348. "violet": "#ee82ee",
  25349. "wheat": "#f5deb3",
  25350. "white": "#ffffff",
  25351. "whitesmoke": "#f5f5f5",
  25352. "yellow": "#ffff00",
  25353. "yellowgreen": "#9acd32"
  25354. };
  25355. var getStyleValue = function getStyleValue(style) {
  25356. return style.split('-')[1];
  25357. };
  25358. var defaultUnitExportFn = function defaultUnitExportFn(unit) {
  25359. return unit + 'px';
  25360. };
  25361. var defaultUnitImportFn = function defaultUnitImportFn(unit) {
  25362. return unit.replace('px', '');
  25363. };
  25364. var ignoredNodeAttributes = ['style'];
  25365. var ignoredEntityNodeAttributes = ['style', 'href', 'target', 'alt', 'title', 'id', 'controls', 'autoplay', 'loop', 'poster'];
  25366. var spreadNodeAttributes = function spreadNodeAttributes(attributesObject) {
  25367. return Object.keys(attributesObject).reduce(function (attributeString, attributeName) {
  25368. return attributeString + " " + attributeName + "=\"" + attributesObject[attributeName] + "\"";
  25369. }, '').replace(/^\s$/, '');
  25370. };
  25371. var defaultFontFamilies = exports.defaultFontFamilies = [{
  25372. name: 'Araial',
  25373. family: 'Arial, Helvetica, sans-serif'
  25374. }, {
  25375. name: 'Georgia',
  25376. family: 'Georgia, serif'
  25377. }, {
  25378. name: 'Impact',
  25379. family: 'Impact, serif'
  25380. }, {
  25381. name: 'Monospace',
  25382. family: '"Courier New", Courier, monospace'
  25383. }, {
  25384. name: 'Tahoma',
  25385. family: "tahoma, arial, 'Hiragino Sans GB', 宋体, sans-serif"
  25386. }];
  25387. var getHexColor = exports.getHexColor = function getHexColor(color) {
  25388. color = color.replace('color:', '').replace(';', '').replace(' ', '');
  25389. if (/^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/.test(color)) {
  25390. return color;
  25391. } else if (namedColors[color]) {
  25392. return namedColors[color];
  25393. } else if (color.indexOf('rgb') === 0) {
  25394. var rgbArray = color.split(',');
  25395. var convertedColor = rgbArray.length < 3 ? null : '#' + [rgbArray[0], rgbArray[1], rgbArray[2]].map(function (x) {
  25396. var hex = parseInt(x.replace(/\D/g, ''), 10).toString(16);
  25397. return hex.length === 1 ? '0' + hex : hex;
  25398. }).join('');
  25399. return (/^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/.test(convertedColor) ? convertedColor : null
  25400. );
  25401. } else {
  25402. return null;
  25403. }
  25404. };
  25405. var blocks = exports.blocks = {
  25406. 'header-one': 'h1',
  25407. 'header-two': 'h2',
  25408. 'header-three': 'h3',
  25409. 'header-four': 'h4',
  25410. 'header-five': 'h5',
  25411. 'header-six': 'h6',
  25412. 'unstyled': 'p',
  25413. 'blockquote': 'blockquote'
  25414. };
  25415. var blockTypes = Object.keys(blocks);
  25416. var blockNames = blockTypes.map(function (key) {
  25417. return blocks[key];
  25418. });
  25419. var convertAtomicBlock = function convertAtomicBlock(block, contentState, blockNodeAttributes) {
  25420. if (!block || !block.key) {
  25421. return _react2.default.createElement("p", null);
  25422. }
  25423. var contentBlock = contentState.getBlockForKey(block.key);
  25424. var className = blockNodeAttributes.class,
  25425. nodeAttrAsProps = _objectWithoutProperties(blockNodeAttributes, ["class"]);
  25426. nodeAttrAsProps.className = className;
  25427. if (!contentBlock) {
  25428. return _react2.default.createElement("p", null);
  25429. }
  25430. var entityKey = contentBlock.getEntityAt(0);
  25431. if (!entityKey) {
  25432. return _react2.default.createElement("p", null);
  25433. }
  25434. var entity = contentState.getEntity(entityKey);
  25435. var mediaType = entity.getType().toLowerCase();
  25436. var _block$data = block.data,
  25437. float = _block$data.float,
  25438. alignment = _block$data.alignment;
  25439. var _entity$getData = entity.getData(),
  25440. url = _entity$getData.url,
  25441. link = _entity$getData.link,
  25442. link_target = _entity$getData.link_target,
  25443. width = _entity$getData.width,
  25444. height = _entity$getData.height,
  25445. meta = _entity$getData.meta;
  25446. if (mediaType === 'image') {
  25447. var imageWrapStyle = {};
  25448. var styledClassName = '';
  25449. if (float) {
  25450. imageWrapStyle.float = float;
  25451. styledClassName += ' float-' + float;
  25452. } else if (alignment) {
  25453. imageWrapStyle.textAlign = alignment;
  25454. styledClassName += ' align-' + alignment;
  25455. }
  25456. if (link) {
  25457. return _react2.default.createElement(
  25458. "div",
  25459. { className: "media-wrap image-wrap" + styledClassName, style: imageWrapStyle },
  25460. _react2.default.createElement(
  25461. "a",
  25462. { style: { display: 'inline-block' }, href: link, target: link_target },
  25463. _react2.default.createElement("img", _extends({}, nodeAttrAsProps, meta, { src: url, width: width, height: height, style: { width: width, height: height } }))
  25464. )
  25465. );
  25466. } else {
  25467. return _react2.default.createElement(
  25468. "div",
  25469. { className: "media-wrap image-wrap" + styledClassName, style: imageWrapStyle },
  25470. _react2.default.createElement("img", _extends({}, nodeAttrAsProps, meta, { src: url, width: width, height: height, style: { width: width, height: height } }))
  25471. );
  25472. }
  25473. } else if (mediaType === 'audio') {
  25474. return _react2.default.createElement(
  25475. "div",
  25476. { className: "media-wrap audio-wrap" },
  25477. _react2.default.createElement("audio", _extends({ controls: true }, nodeAttrAsProps, meta, { src: url }))
  25478. );
  25479. } else if (mediaType === 'video') {
  25480. return _react2.default.createElement(
  25481. "div",
  25482. { className: "media-wrap video-wrap" },
  25483. _react2.default.createElement("video", _extends({ controls: true }, nodeAttrAsProps, meta, { src: url, width: width, height: height }))
  25484. );
  25485. } else if (mediaType === 'embed') {
  25486. return _react2.default.createElement(
  25487. "div",
  25488. { className: "media-wrap embed-wrap" },
  25489. _react2.default.createElement("div", { dangerouslySetInnerHTML: { __html: url } })
  25490. );
  25491. } else if (mediaType === 'hr') {
  25492. return _react2.default.createElement("hr", null);
  25493. } else {
  25494. return _react2.default.createElement("p", null);
  25495. }
  25496. };
  25497. var entityToHTML = function entityToHTML(options) {
  25498. return function (entity, originalText) {
  25499. var entityExportFn = options.entityExportFn;
  25500. var entityType = entity.type.toLowerCase();
  25501. if (entityExportFn) {
  25502. var customOutput = entityExportFn(entity, originalText);
  25503. if (customOutput) {
  25504. return customOutput;
  25505. }
  25506. }
  25507. if (entityType === 'link') {
  25508. var _ref = entity.data.nodeAttributes || {},
  25509. className = _ref.class,
  25510. nodeAttrAsProps = _objectWithoutProperties(_ref, ["class"]);
  25511. nodeAttrAsProps.className = className;
  25512. return _react2.default.createElement("a", _extends({ href: entity.data.href, target: entity.data.target }, nodeAttrAsProps));
  25513. }
  25514. };
  25515. };
  25516. var styleToHTML = function styleToHTML(options) {
  25517. return function (style) {
  25518. var unitExportFn = options.unitExportFn || defaultUnitExportFn;
  25519. if (options.styleExportFn) {
  25520. var customOutput = options.styleExportFn(style, options);
  25521. if (customOutput) {
  25522. return customOutput;
  25523. }
  25524. }
  25525. style = style.toLowerCase();
  25526. if (style === 'strikethrough') {
  25527. return _react2.default.createElement("span", { style: { textDecoration: 'line-through' } });
  25528. } else if (style === 'superscript') {
  25529. return _react2.default.createElement("sup", null);
  25530. } else if (style === 'subscript') {
  25531. return _react2.default.createElement("sub", null);
  25532. } else if (style.indexOf('color-') === 0) {
  25533. return _react2.default.createElement("span", { style: { color: '#' + getStyleValue(style) } });
  25534. } else if (style.indexOf('bgcolor-') === 0) {
  25535. return _react2.default.createElement("span", { style: { backgroundColor: '#' + getStyleValue(style) } });
  25536. } else if (style.indexOf('fontsize-') === 0) {
  25537. return _react2.default.createElement("span", { style: { fontSize: unitExportFn(getStyleValue(style), 'font-size', 'html') } });
  25538. } else if (style.indexOf('lineheight-') === 0) {
  25539. return _react2.default.createElement("span", { style: { lineHeight: unitExportFn(getStyleValue(style), 'line-height', 'html') } });
  25540. } else if (style.indexOf('letterspacing-') === 0) {
  25541. return _react2.default.createElement("span", { style: { letterSpacing: unitExportFn(getStyleValue(style), 'letter-spacing', 'html') } });
  25542. } else if (style.indexOf('fontfamily-') === 0) {
  25543. var fontFamily = options.fontFamilies.find(function (item) {
  25544. return item.name.toLowerCase() === getStyleValue(style);
  25545. });
  25546. if (!fontFamily) return;
  25547. return _react2.default.createElement("span", { style: { fontFamily: fontFamily.family } });
  25548. }
  25549. };
  25550. };
  25551. var blockToHTML = function blockToHTML(options) {
  25552. return function (block) {
  25553. var blockExportFn = options.blockExportFn,
  25554. contentState = options.contentState;
  25555. if (blockExportFn) {
  25556. var customOutput = blockExportFn(contentState, block);
  25557. if (customOutput) {
  25558. return customOutput;
  25559. }
  25560. }
  25561. var blockStyle = '';
  25562. var blockType = block.type.toLowerCase();
  25563. var _block$data2 = block.data,
  25564. textAlign = _block$data2.textAlign,
  25565. textIndent = _block$data2.textIndent,
  25566. _block$data2$nodeAttr = _block$data2.nodeAttributes,
  25567. nodeAttributes = _block$data2$nodeAttr === undefined ? {} : _block$data2$nodeAttr;
  25568. var attributeString = spreadNodeAttributes(nodeAttributes);
  25569. if (textAlign || textIndent) {
  25570. blockStyle = ' style="';
  25571. if (textAlign) {
  25572. blockStyle += "text-align:" + textAlign + ";";
  25573. }
  25574. if (textIndent && !isNaN(textIndent) && textIndent > 0) {
  25575. blockStyle += "text-indent:" + textIndent * 2 + "em;";
  25576. }
  25577. blockStyle += '"';
  25578. }
  25579. if (blockType === 'atomic') {
  25580. return convertAtomicBlock(block, contentState, nodeAttributes);
  25581. } else if (blockType === 'code-block') {
  25582. var previousBlock = contentState.getBlockBefore(block.key);
  25583. var nextBlock = contentState.getBlockAfter(block.key);
  25584. var previousBlockType = previousBlock && previousBlock.getType();
  25585. var nextBlockType = nextBlock && nextBlock.getType();
  25586. var start = '';
  25587. var end = '';
  25588. if (previousBlockType !== 'code-block') {
  25589. start = "<pre" + attributeString + "><code>";
  25590. } else {
  25591. start = '';
  25592. }
  25593. if (nextBlockType !== 'code-block') {
  25594. end = '</code></pre>';
  25595. } else {
  25596. end = '<br/>';
  25597. }
  25598. return { start: start, end: end };
  25599. } else if (blocks[blockType]) {
  25600. return {
  25601. start: "<" + blocks[blockType] + blockStyle + attributeString + ">",
  25602. end: "</" + blocks[blockType] + ">"
  25603. };
  25604. } else if (blockType === 'unordered-list-item') {
  25605. return {
  25606. start: "<li" + blockStyle + attributeString + ">",
  25607. end: '</li>',
  25608. nest: _react2.default.createElement("ul", null)
  25609. };
  25610. } else if (blockType === 'ordered-list-item') {
  25611. return {
  25612. start: "<li" + blockStyle + attributeString + ">",
  25613. end: '</li>',
  25614. nest: _react2.default.createElement("ol", null)
  25615. };
  25616. }
  25617. };
  25618. };
  25619. var htmlToStyle = function htmlToStyle(options, source) {
  25620. return function (nodeName, node, currentStyle) {
  25621. if (!node || !node.style) {
  25622. return currentStyle;
  25623. }
  25624. var unitImportFn = options.unitImportFn || defaultUnitImportFn;
  25625. var newStyle = currentStyle;
  25626. [].forEach.call(node.style, function (style) {
  25627. if (nodeName === 'span' && style === 'color') {
  25628. var color = getHexColor(node.style.color);
  25629. newStyle = color ? newStyle.add('COLOR-' + color.replace('#', '').toUpperCase()) : newStyle;
  25630. } else if (nodeName === 'span' && style === 'background-color') {
  25631. var _color = getHexColor(node.style.backgroundColor);
  25632. newStyle = _color ? newStyle.add('BGCOLOR-' + _color.replace('#', '').toUpperCase()) : newStyle;
  25633. } else if (nodeName === 'span' && style === 'font-size') {
  25634. newStyle = newStyle.add('FONTSIZE-' + unitImportFn(node.style.fontSize, 'font-size', source));
  25635. } else if (nodeName === 'span' && style === 'line-height' && !isNaN(parseFloat(node.style.lineHeight, 10))) {
  25636. newStyle = newStyle.add('LINEHEIGHT-' + unitImportFn(node.style.lineHeight, 'line-height', source));
  25637. } else if (nodeName === 'span' && style === 'letter-spacing' && !isNaN(parseFloat(node.style.letterSpacing, 10))) {
  25638. newStyle = newStyle.add('LETTERSPACING-' + unitImportFn(node.style.letterSpacing, 'letter-spacing', source));
  25639. } else if (nodeName === 'span' && style === 'text-decoration') {
  25640. if (node.style.textDecoration === 'line-through') {
  25641. newStyle = newStyle.add('STRIKETHROUGH');
  25642. } else if (node.style.textDecoration === 'underline') {
  25643. newStyle = newStyle.add('UNDERLINE');
  25644. }
  25645. } else if (nodeName === 'span' && style === 'font-family') {
  25646. var fontFamily = options.fontFamilies.find(function (item) {
  25647. return item.family.toLowerCase() === node.style.fontFamily.toLowerCase();
  25648. });
  25649. if (!fontFamily) return;
  25650. newStyle = newStyle.add('FONTFAMILY-' + fontFamily.name.toUpperCase());
  25651. }
  25652. });
  25653. if (nodeName === 'sup') {
  25654. newStyle = newStyle.add('SUPERSCRIPT');
  25655. } else if (nodeName === 'sub') {
  25656. newStyle = newStyle.add('SUBSCRIPT');
  25657. }
  25658. options.styleImportFn && (newStyle = options.styleImportFn(nodeName, node, newStyle, source) || newStyle);
  25659. return newStyle;
  25660. };
  25661. };
  25662. var htmlToEntity = function htmlToEntity(options, source) {
  25663. return function (nodeName, node, createEntity) {
  25664. if (options && options.entityImportFn) {
  25665. var customInput = options.entityImportFn(nodeName, node, createEntity, source);
  25666. if (customInput) {
  25667. return customInput;
  25668. }
  25669. }
  25670. nodeName = nodeName.toLowerCase();
  25671. var alt = node.alt,
  25672. title = node.title,
  25673. id = node.id,
  25674. controls = node.controls,
  25675. autoplay = node.autoplay,
  25676. loop = node.loop,
  25677. poster = node.poster;
  25678. var meta = {};
  25679. var nodeAttributes = {};
  25680. id && (meta.id = id);
  25681. alt && (meta.alt = alt);
  25682. title && (meta.title = title);
  25683. controls && (meta.controls = controls);
  25684. autoplay && (meta.autoPlay = autoplay);
  25685. loop && (meta.loop = loop);
  25686. poster && (meta.poster = poster);
  25687. node.attributes && Object.keys(node.attributes).forEach(function (key) {
  25688. var attr = node.attributes[key];
  25689. ignoredEntityNodeAttributes.indexOf(attr.name) === -1 && (nodeAttributes[attr.name] = attr.value);
  25690. });
  25691. if (nodeName === 'a' && !node.querySelectorAll('img').length) {
  25692. var href = node.getAttribute('href');
  25693. var _target = node.getAttribute('target');
  25694. return createEntity('LINK', 'MUTABLE', { href: href, target: _target, nodeAttributes: nodeAttributes });
  25695. } else if (nodeName === 'audio') {
  25696. return createEntity('AUDIO', 'IMMUTABLE', { url: node.getAttribute('src'), meta: meta, nodeAttributes: nodeAttributes });
  25697. } else if (nodeName === 'video') {
  25698. return createEntity('VIDEO', 'IMMUTABLE', { url: node.getAttribute('src'), meta: meta, nodeAttributes: nodeAttributes });
  25699. } else if (nodeName === 'img') {
  25700. var parentNode = node.parentNode;
  25701. var entityData = { meta: meta };
  25702. var _node$style = node.style,
  25703. width = _node$style.width,
  25704. height = _node$style.height;
  25705. entityData.url = node.getAttribute('src');
  25706. width && (entityData.width = width);
  25707. height && (entityData.height = height);
  25708. if (parentNode.nodeName.toLowerCase() === 'a') {
  25709. entityData.link = parentNode.getAttribute('href');
  25710. entityData.link_target = parentNode.getAttribute('target');
  25711. }
  25712. return createEntity('IMAGE', 'IMMUTABLE', entityData);
  25713. } else if (nodeName === 'hr') {
  25714. return createEntity('HR', 'IMMUTABLE', {});
  25715. } else if (node.parentNode && node.parentNode.classList.contains('embed-wrap')) {
  25716. var embedContent = node.innerHTML || node.outerHTML;
  25717. if (embedContent) {
  25718. return createEntity('EMBED', 'IMMUTABLE', {
  25719. url: embedContent
  25720. });
  25721. }
  25722. }
  25723. };
  25724. };
  25725. var htmlToBlock = function htmlToBlock(options, source) {
  25726. return function (nodeName, node) {
  25727. if (options && options.blockImportFn) {
  25728. var customInput = options.blockImportFn(nodeName, node, source);
  25729. if (customInput) {
  25730. return customInput;
  25731. }
  25732. }
  25733. var nodeAttributes = {};
  25734. var nodeStyle = node.style || {};
  25735. node.attributes && Object.keys(node.attributes).forEach(function (key) {
  25736. var attr = node.attributes[key];
  25737. ignoredNodeAttributes.indexOf(attr.name) === -1 && (nodeAttributes[attr.name] = attr.value);
  25738. });
  25739. if (node.classList && node.classList.contains('media-wrap')) {
  25740. return {
  25741. type: 'atomic',
  25742. data: {
  25743. nodeAttributes: nodeAttributes,
  25744. float: nodeStyle.float,
  25745. alignment: nodeStyle.textAlign
  25746. }
  25747. };
  25748. } else if (nodeName === 'img') {
  25749. return {
  25750. type: 'atomic',
  25751. data: {
  25752. nodeAttributes: nodeAttributes,
  25753. float: nodeStyle.float,
  25754. alignment: nodeStyle.textAlign
  25755. }
  25756. };
  25757. } else if (nodeName === 'hr') {
  25758. return {
  25759. type: 'atomic',
  25760. data: { nodeAttributes: nodeAttributes }
  25761. };
  25762. } else if (nodeName === 'pre') {
  25763. node.innerHTML = node.innerHTML.replace(/<code(.*?)>/g, '').replace(/<\/code>/g, '');
  25764. return {
  25765. type: 'code-block',
  25766. data: { nodeAttributes: nodeAttributes }
  25767. };
  25768. } else if (blockNames.indexOf(nodeName) !== -1) {
  25769. var blockData = { nodeAttributes: nodeAttributes };
  25770. if (nodeStyle.textAlign) {
  25771. blockData.textAlign = nodeStyle.textAlign;
  25772. }
  25773. if (nodeStyle.textIndent) {
  25774. blockData.textIndent = /^\d+em$/.test(nodeStyle.textIndent) ? Math.ceil(parseInt(nodeStyle.textIndent, 10) / 2) : 1;
  25775. }
  25776. return {
  25777. type: blockTypes[blockNames.indexOf(nodeName)],
  25778. data: blockData
  25779. };
  25780. }
  25781. };
  25782. };
  25783. var getToHTMLConfig = exports.getToHTMLConfig = function getToHTMLConfig(options) {
  25784. return {
  25785. styleToHTML: styleToHTML(options),
  25786. entityToHTML: entityToHTML(options),
  25787. blockToHTML: blockToHTML(options)
  25788. };
  25789. };
  25790. var getFromHTMLConfig = exports.getFromHTMLConfig = function getFromHTMLConfig(options) {
  25791. var source = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'unknow';
  25792. return {
  25793. htmlToStyle: htmlToStyle(options, source),
  25794. htmlToEntity: htmlToEntity(options, source),
  25795. htmlToBlock: htmlToBlock(options, source)
  25796. };
  25797. };
  25798. });
  25799. unwrapExports(configs);
  25800. var configs_1 = configs.getFromHTMLConfig;
  25801. var configs_2 = configs.getToHTMLConfig;
  25802. var configs_3 = configs.blocks;
  25803. var configs_4 = configs.getHexColor;
  25804. var configs_5 = configs.defaultFontFamilies;
  25805. var configs_6 = configs.namedColors;
  25806. var dist = createCommonjsModule(function (module, exports) {
  25807. Object.defineProperty(exports, "__esModule", {
  25808. value: true
  25809. });
  25810. exports.convertRawToEditorState = exports.convertEditorStateToRaw = exports.convertHTMLToEditorState = exports.convertEditorStateToHTML = exports.convertHTMLToRaw = exports.convertRawToHTML = undefined;
  25811. 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; };
  25812. var defaultConvertOptions = {
  25813. fontFamilies: configs.defaultFontFamilies
  25814. };
  25815. var convertRawToHTML = exports.convertRawToHTML = function convertRawToHTML(rawContent, options) {
  25816. options = _extends({}, defaultConvertOptions, options);
  25817. try {
  25818. var contentState = (0, Draft.convertFromRaw)(rawContent);
  25819. options.contentState = contentState;
  25820. return (0, lib.convertToHTML)((0, configs.getToHTMLConfig)(options))(contentState);
  25821. } catch (error) {
  25822. console.warn(error);
  25823. return '';
  25824. }
  25825. };
  25826. var convertHTMLToRaw = exports.convertHTMLToRaw = function convertHTMLToRaw(HTMLString, options, source) {
  25827. options = _extends({}, defaultConvertOptions, options);
  25828. try {
  25829. var contentState = (0, lib.convertFromHTML)((0, configs.getFromHTMLConfig)(options, source))(HTMLString);
  25830. return (0, Draft.convertToRaw)(contentState);
  25831. } catch (error) {
  25832. console.warn(error);
  25833. return {};
  25834. }
  25835. };
  25836. var convertEditorStateToHTML = exports.convertEditorStateToHTML = function convertEditorStateToHTML(editorState, options) {
  25837. options = _extends({}, defaultConvertOptions, options);
  25838. try {
  25839. var contentState = editorState.getCurrentContent();
  25840. options.contentState = contentState;
  25841. return (0, lib.convertToHTML)((0, configs.getToHTMLConfig)(options))(contentState);
  25842. } catch (error) {
  25843. console.warn(error);
  25844. return '';
  25845. }
  25846. };
  25847. var convertHTMLToEditorState = exports.convertHTMLToEditorState = function convertHTMLToEditorState(HTMLString, editorDecorators, options, source) {
  25848. options = _extends({}, defaultConvertOptions, options);
  25849. try {
  25850. return Draft.EditorState.createWithContent((0, lib.convertFromHTML)((0, configs.getFromHTMLConfig)(options, source))(HTMLString), editorDecorators);
  25851. } catch (error) {
  25852. console.warn(error);
  25853. return Draft.EditorState.createEmpty(editorDecorators);
  25854. }
  25855. };
  25856. var convertEditorStateToRaw = exports.convertEditorStateToRaw = function convertEditorStateToRaw(editorState) {
  25857. return (0, Draft.convertToRaw)(editorState.getCurrentContent());
  25858. };
  25859. var convertRawToEditorState = exports.convertRawToEditorState = function convertRawToEditorState(rawContent, editorDecorators) {
  25860. try {
  25861. return Draft.EditorState.createWithContent((0, Draft.convertFromRaw)(rawContent), editorDecorators);
  25862. } catch (error) {
  25863. console.warn(error);
  25864. return Draft.EditorState.createEmpty(editorDecorators);
  25865. }
  25866. };
  25867. });
  25868. unwrapExports(dist);
  25869. var dist_1 = dist.convertRawToEditorState;
  25870. var dist_2 = dist.convertEditorStateToRaw;
  25871. var dist_3 = dist.convertHTMLToEditorState;
  25872. var dist_4 = dist.convertEditorStateToHTML;
  25873. var dist_5 = dist.convertHTMLToRaw;
  25874. var dist_6 = dist.convertRawToHTML;
  25875. var content = createCommonjsModule(function (module, exports) {
  25876. Object.defineProperty(exports, "__esModule", {
  25877. value: true
  25878. });
  25879. 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;
  25880. var _immutable2 = _interopRequireDefault(immutable$1);
  25881. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  25882. var strictBlockTypes = ['atomic'];
  25883. var registerStrictBlockType = exports.registerStrictBlockType = function registerStrictBlockType(blockType) {
  25884. strictBlockTypes.indexOf(blockType) === -1 && strictBlockTypes.push(blockType);
  25885. };
  25886. var isEditorState = exports.isEditorState = function isEditorState(editorState) {
  25887. return editorState instanceof Draft.EditorState;
  25888. };
  25889. var createEmptyEditorState = exports.createEmptyEditorState = function createEmptyEditorState(editorDecorators) {
  25890. return Draft.EditorState.createEmpty(editorDecorators);
  25891. };
  25892. var createEditorState = exports.createEditorState = function createEditorState(contentState, editorDecorators) {
  25893. return Draft.EditorState.createWithContent(contentState, editorDecorators);
  25894. };
  25895. var isSelectionCollapsed = exports.isSelectionCollapsed = function isSelectionCollapsed(editorState) {
  25896. return editorState.getSelection().isCollapsed();
  25897. };
  25898. var selectionContainsBlockType = exports.selectionContainsBlockType = function selectionContainsBlockType(editorState, blockType) {
  25899. return getSelectedBlocks(editorState).find(function (block) {
  25900. return block.getType() === blockType;
  25901. });
  25902. };
  25903. var selectionContainsStrictBlock = exports.selectionContainsStrictBlock = function selectionContainsStrictBlock(editorState) {
  25904. return getSelectedBlocks(editorState).find(function (block) {
  25905. return ~strictBlockTypes.indexOf(block.getType());
  25906. });
  25907. };
  25908. var selectBlock = exports.selectBlock = function selectBlock(editorState, block) {
  25909. var blockKey = block.getKey();
  25910. return Draft.EditorState.forceSelection(editorState, new Draft.SelectionState({
  25911. anchorKey: blockKey,
  25912. anchorOffset: 0,
  25913. focusKey: blockKey,
  25914. focusOffset: block.getLength()
  25915. }));
  25916. };
  25917. var selectNextBlock = exports.selectNextBlock = function selectNextBlock(editorState, block) {
  25918. var nextBlock = editorState.getCurrentContent().getBlockAfter(block.getKey());
  25919. return nextBlock ? selectBlock(editorState, nextBlock) : editorState;
  25920. };
  25921. var removeBlock = exports.removeBlock = function removeBlock(editorState, block) {
  25922. var lastSelection = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  25923. var nextContentState = void 0,
  25924. nextEditorState = void 0;
  25925. var blockKey = block.getKey();
  25926. nextContentState = Draft.Modifier.removeRange(editorState.getCurrentContent(), new Draft.SelectionState({
  25927. anchorKey: blockKey,
  25928. anchorOffset: 0,
  25929. focusKey: blockKey,
  25930. focusOffset: block.getLength()
  25931. }), 'backward');
  25932. nextContentState = Draft.Modifier.setBlockType(nextContentState, nextContentState.getSelectionAfter(), 'unstyled');
  25933. nextEditorState = Draft.EditorState.push(editorState, nextContentState, 'remove-range');
  25934. return Draft.EditorState.forceSelection(nextEditorState, lastSelection || nextContentState.getSelectionAfter());
  25935. };
  25936. var getSelectionBlock = exports.getSelectionBlock = function getSelectionBlock(editorState) {
  25937. return editorState.getCurrentContent().getBlockForKey(editorState.getSelection().getAnchorKey());
  25938. };
  25939. var updateEachCharacterOfSelection = exports.updateEachCharacterOfSelection = function updateEachCharacterOfSelection(editorState, callback) {
  25940. var selectionState = editorState.getSelection();
  25941. var contentState = editorState.getCurrentContent();
  25942. var contentBlocks = contentState.getBlockMap();
  25943. var selectedBlocks = getSelectedBlocks(editorState);
  25944. if (selectedBlocks.length === 0) {
  25945. return editorState;
  25946. }
  25947. var startKey = selectionState.getStartKey();
  25948. var startOffset = selectionState.getStartOffset();
  25949. var endKey = selectionState.getEndKey();
  25950. var endOffset = selectionState.getEndOffset();
  25951. var nextContentBlocks = contentBlocks.map(function (block) {
  25952. if (selectedBlocks.indexOf(block) === -1) {
  25953. return block;
  25954. }
  25955. var blockKey = block.getKey();
  25956. var charactersList = block.getCharacterList();
  25957. var nextCharactersList = null;
  25958. if (blockKey === startKey && blockKey === endKey) {
  25959. nextCharactersList = charactersList.map(function (character, index) {
  25960. if (index >= startOffset && index < endOffset) {
  25961. return callback(character);
  25962. }
  25963. return character;
  25964. });
  25965. } else if (blockKey === startKey) {
  25966. nextCharactersList = charactersList.map(function (character, index) {
  25967. if (index >= startOffset) {
  25968. return callback(character);
  25969. }
  25970. return character;
  25971. });
  25972. } else if (blockKey === endKey) {
  25973. nextCharactersList = charactersList.map(function (character, index) {
  25974. if (index < endOffset) {
  25975. return callback(character);
  25976. }
  25977. return character;
  25978. });
  25979. } else {
  25980. nextCharactersList = charactersList.map(function (character) {
  25981. return callback(character);
  25982. });
  25983. }
  25984. return block.merge({
  25985. 'characterList': nextCharactersList
  25986. });
  25987. });
  25988. return Draft.EditorState.push(editorState, contentState.merge({
  25989. blockMap: nextContentBlocks,
  25990. selectionBefore: selectionState,
  25991. selectionAfter: selectionState
  25992. }), 'update-selection-character-list');
  25993. };
  25994. var getSelectedBlocks = exports.getSelectedBlocks = function getSelectedBlocks(editorState) {
  25995. var selectionState = editorState.getSelection();
  25996. var contentState = editorState.getCurrentContent();
  25997. var startKey = selectionState.getStartKey();
  25998. var endKey = selectionState.getEndKey();
  25999. var isSameBlock = startKey === endKey;
  26000. var startingBlock = contentState.getBlockForKey(startKey);
  26001. var selectedBlocks = [startingBlock];
  26002. if (!isSameBlock) {
  26003. var blockKey = startKey;
  26004. while (blockKey !== endKey) {
  26005. var nextBlock = contentState.getBlockAfter(blockKey);
  26006. selectedBlocks.push(nextBlock);
  26007. blockKey = nextBlock.getKey();
  26008. }
  26009. }
  26010. return selectedBlocks;
  26011. };
  26012. var setSelectionBlockData = exports.setSelectionBlockData = function setSelectionBlockData(editorState, blockData, override) {
  26013. var newBlockData = override ? blockData : Object.assign({}, getSelectionBlockData(editorState).toJS(), blockData);
  26014. Object.keys(newBlockData).forEach(function (key) {
  26015. if (newBlockData.hasOwnProperty(key) && newBlockData[key] === undefined) {
  26016. delete newBlockData[key];
  26017. }
  26018. });
  26019. return (0, draftjsUtils.setBlockData)(editorState, newBlockData);
  26020. };
  26021. var getSelectionBlockData = exports.getSelectionBlockData = function getSelectionBlockData(editorState, name) {
  26022. var blockData = getSelectionBlock(editorState).getData();
  26023. return name ? blockData.get(name) : blockData;
  26024. };
  26025. var getSelectionBlockType = exports.getSelectionBlockType = function getSelectionBlockType(editorState) {
  26026. return getSelectionBlock(editorState).getType();
  26027. };
  26028. var getSelectionText = exports.getSelectionText = function getSelectionText(editorState) {
  26029. var selectionState = editorState.getSelection();
  26030. var contentState = editorState.getCurrentContent();
  26031. if (selectionState.isCollapsed() || getSelectionBlockType(editorState) === 'atomic') {
  26032. return '';
  26033. }
  26034. var anchorKey = selectionState.getAnchorKey();
  26035. var currentContentBlock = contentState.getBlockForKey(anchorKey);
  26036. var start = selectionState.getStartOffset();
  26037. var end = selectionState.getEndOffset();
  26038. return currentContentBlock.getText().slice(start, end);
  26039. };
  26040. var toggleSelectionBlockType = exports.toggleSelectionBlockType = function toggleSelectionBlockType(editorState, blockType) {
  26041. if (selectionContainsStrictBlock(editorState)) {
  26042. return editorState;
  26043. }
  26044. return Draft.RichUtils.toggleBlockType(editorState, blockType);
  26045. };
  26046. var getSelectionEntityType = exports.getSelectionEntityType = function getSelectionEntityType(editorState) {
  26047. var entityKey = (0, draftjsUtils.getSelectionEntity)(editorState);
  26048. if (entityKey) {
  26049. var entity = editorState.getCurrentContent().getEntity(entityKey);
  26050. return entity ? entity.get('type') : null;
  26051. }
  26052. return null;
  26053. };
  26054. var getSelectionEntityData = exports.getSelectionEntityData = function getSelectionEntityData(editorState, type) {
  26055. var entityKey = (0, draftjsUtils.getSelectionEntity)(editorState);
  26056. if (entityKey) {
  26057. var entity = editorState.getCurrentContent().getEntity(entityKey);
  26058. if (entity && entity.get('type') === type) {
  26059. return entity.getData();
  26060. } else {
  26061. return {};
  26062. }
  26063. } else {
  26064. return {};
  26065. }
  26066. };
  26067. var toggleSelectionEntity = exports.toggleSelectionEntity = function toggleSelectionEntity(editorState, entity) {
  26068. var contentState = editorState.getCurrentContent();
  26069. var selectionState = editorState.getSelection();
  26070. if (selectionState.isCollapsed() || getSelectionBlockType(editorState) === 'atomic') {
  26071. return editorState;
  26072. }
  26073. if (!entity || !entity.type || getSelectionEntityType(editorState) === entity.type) {
  26074. return Draft.EditorState.push(editorState, Draft.Modifier.applyEntity(contentState, selectionState, null), 'apply-entity');
  26075. }
  26076. try {
  26077. var nextContentState = contentState.createEntity(entity.type, entity.mutability, entity.data);
  26078. var entityKey = nextContentState.getLastCreatedEntityKey();
  26079. var nextEditorState = Draft.EditorState.set(editorState, {
  26080. currentContent: nextContentState
  26081. });
  26082. return Draft.EditorState.push(nextEditorState, Draft.Modifier.applyEntity(nextContentState, selectionState, entityKey), 'apply-entity');
  26083. } catch (error) {
  26084. console.warn(error);
  26085. return editorState;
  26086. }
  26087. };
  26088. var toggleSelectionLink = exports.toggleSelectionLink = function toggleSelectionLink(editorState, href, target) {
  26089. var contentState = editorState.getCurrentContent();
  26090. var selectionState = editorState.getSelection();
  26091. var entityData = { href: href, target: target };
  26092. if (selectionState.isCollapsed() || getSelectionBlockType(editorState) === 'atomic') {
  26093. return editorState;
  26094. }
  26095. if (href === false) {
  26096. return Draft.RichUtils.toggleLink(editorState, selectionState, null);
  26097. }
  26098. if (href === null) {
  26099. delete entityData.href;
  26100. }
  26101. try {
  26102. var nextContentState = contentState.createEntity('LINK', 'MUTABLE', entityData);
  26103. var entityKey = nextContentState.getLastCreatedEntityKey();
  26104. var nextEditorState = Draft.EditorState.set(editorState, {
  26105. currentContent: nextContentState
  26106. });
  26107. nextEditorState = Draft.RichUtils.toggleLink(nextEditorState, selectionState, entityKey);
  26108. nextEditorState = Draft.EditorState.forceSelection(nextEditorState, selectionState.merge({
  26109. anchorOffset: selectionState.getEndOffset(),
  26110. focusOffset: selectionState.getEndOffset()
  26111. }));
  26112. nextEditorState = Draft.EditorState.push(nextEditorState, Draft.Modifier.insertText(nextEditorState.getCurrentContent(), nextEditorState.getSelection(), ''), 'insert-text');
  26113. return nextEditorState;
  26114. } catch (error) {
  26115. console.warn(error);
  26116. return editorState;
  26117. }
  26118. };
  26119. var getSelectionInlineStyle = exports.getSelectionInlineStyle = function getSelectionInlineStyle(editorState) {
  26120. return editorState.getCurrentInlineStyle();
  26121. };
  26122. var selectionHasInlineStyle = exports.selectionHasInlineStyle = function selectionHasInlineStyle(editorState, style) {
  26123. return getSelectionInlineStyle(editorState).has(style.toUpperCase());
  26124. };
  26125. var toggleSelectionInlineStyle = exports.toggleSelectionInlineStyle = function toggleSelectionInlineStyle(editorState, style) {
  26126. var prefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
  26127. var nextEditorState = editorState;
  26128. style = prefix + style.toUpperCase();
  26129. if (prefix) {
  26130. nextEditorState = updateEachCharacterOfSelection(nextEditorState, function (characterMetadata) {
  26131. return characterMetadata.toJS().style.reduce(function (characterMetadata, characterStyle) {
  26132. if (characterStyle.indexOf(prefix) === 0 && style !== characterStyle) {
  26133. return Draft.CharacterMetadata.removeStyle(characterMetadata, characterStyle);
  26134. } else {
  26135. return characterMetadata;
  26136. }
  26137. }, characterMetadata);
  26138. });
  26139. }
  26140. return Draft.RichUtils.toggleInlineStyle(nextEditorState, style);
  26141. };
  26142. var removeSelectionInlineStyles = exports.removeSelectionInlineStyles = function removeSelectionInlineStyles(editorState) {
  26143. return updateEachCharacterOfSelection(editorState, function (characterMetadata) {
  26144. return characterMetadata.merge({
  26145. style: _immutable2.default.OrderedSet([])
  26146. });
  26147. });
  26148. };
  26149. var toggleSelectionAlignment = exports.toggleSelectionAlignment = function toggleSelectionAlignment(editorState, alignment) {
  26150. return setSelectionBlockData(editorState, {
  26151. textAlign: getSelectionBlockData(editorState, 'textAlign') !== alignment ? alignment : undefined
  26152. });
  26153. };
  26154. var toggleSelectionIndent = exports.toggleSelectionIndent = function toggleSelectionIndent(editorState, textIndent) {
  26155. var maxIndent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 6;
  26156. return textIndent < 0 || textIndent > maxIndent || isNaN(textIndent) ? editorState : setSelectionBlockData(editorState, {
  26157. textIndent: textIndent || undefined
  26158. });
  26159. };
  26160. var increaseSelectionIndent = exports.increaseSelectionIndent = function increaseSelectionIndent(editorState) {
  26161. var maxIndent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 6;
  26162. var currentIndent = getSelectionBlockData(editorState, 'textIndent') || 0;
  26163. return toggleSelectionIndent(editorState, currentIndent + 1, maxIndent);
  26164. };
  26165. var decreaseSelectionIndent = exports.decreaseSelectionIndent = function decreaseSelectionIndent(editorState) {
  26166. var currentIndent = getSelectionBlockData(editorState, 'textIndent') || 0;
  26167. return toggleSelectionIndent(editorState, currentIndent - 1);
  26168. };
  26169. var toggleSelectionColor = exports.toggleSelectionColor = function toggleSelectionColor(editorState, color) {
  26170. return toggleSelectionInlineStyle(editorState, color.replace('#', ''), 'COLOR-');
  26171. };
  26172. var toggleSelectionBackgroundColor = exports.toggleSelectionBackgroundColor = function toggleSelectionBackgroundColor(editorState, color) {
  26173. return toggleSelectionInlineStyle(editorState, color.replace('#', ''), 'BGCOLOR-');
  26174. };
  26175. var toggleSelectionFontSize = exports.toggleSelectionFontSize = function toggleSelectionFontSize(editorState, fontSize) {
  26176. return toggleSelectionInlineStyle(editorState, fontSize, 'FONTSIZE-');
  26177. };
  26178. var toggleSelectionLineHeight = exports.toggleSelectionLineHeight = function toggleSelectionLineHeight(editorState, lineHeight) {
  26179. return toggleSelectionInlineStyle(editorState, lineHeight, 'LINEHEIGHT-');
  26180. };
  26181. var toggleSelectionFontFamily = exports.toggleSelectionFontFamily = function toggleSelectionFontFamily(editorState, fontFamily) {
  26182. return toggleSelectionInlineStyle(editorState, fontFamily, 'FONTFAMILY-');
  26183. };
  26184. var toggleSelectionLetterSpacing = exports.toggleSelectionLetterSpacing = function toggleSelectionLetterSpacing(editorState, letterSpacing) {
  26185. return toggleSelectionInlineStyle(editorState, letterSpacing, 'LETTERSPACING-');
  26186. };
  26187. var insertText = exports.insertText = function insertText(editorState, text, inlineStyle, entity) {
  26188. var selectionState = editorState.getSelection();
  26189. var currentSelectedBlockType = getSelectionBlockType(editorState);
  26190. if (currentSelectedBlockType === 'atomic') {
  26191. return editorState;
  26192. }
  26193. var entityKey = void 0;
  26194. var contentState = editorState.getCurrentContent();
  26195. if (entity && entity.type) {
  26196. contentState = contentState.createEntity(entity.type, entity.mutability || 'MUTABLE', entity.data || entityData);
  26197. entityKey = contentState.getLastCreatedEntityKey();
  26198. }
  26199. if (!selectionState.isCollapsed()) {
  26200. return Draft.EditorState.push(editorState, Draft.Modifier.replaceText(contentState, selectionState, text, inlineStyle, entityKey), 'replace-text');
  26201. } else {
  26202. return Draft.EditorState.push(editorState, Draft.Modifier.insertText(contentState, selectionState, text, inlineStyle, entityKey), 'insert-text');
  26203. }
  26204. };
  26205. var insertHTML = exports.insertHTML = function insertHTML(editorState, htmlString, source) {
  26206. if (!htmlString) {
  26207. return editorState;
  26208. }
  26209. var selectionState = editorState.getSelection();
  26210. var contentState = editorState.getCurrentContent();
  26211. var options = editorState.convertOptions || {};
  26212. try {
  26213. var _convertFromRaw = (0, Draft.convertFromRaw)((0, dist.convertHTMLToRaw)(htmlString, options, source)),
  26214. blockMap = _convertFromRaw.blockMap;
  26215. return Draft.EditorState.push(editorState, Draft.Modifier.replaceWithFragment(contentState, selectionState, blockMap), 'insert-fragment');
  26216. } catch (error) {
  26217. console.warn(error);
  26218. return editorState;
  26219. }
  26220. };
  26221. var insertAtomicBlock = exports.insertAtomicBlock = function insertAtomicBlock(editorState, type) {
  26222. var immutable = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
  26223. var data = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
  26224. if (selectionContainsStrictBlock(editorState)) {
  26225. return insertAtomicBlock(selectNextBlock(editorState, getSelectionBlock(editorState)), type, immutable, data);
  26226. }
  26227. var selectionState = editorState.getSelection();
  26228. var contentState = editorState.getCurrentContent();
  26229. if (!selectionState.isCollapsed() || getSelectionBlockType(editorState) === 'atomic') {
  26230. return editorState;
  26231. }
  26232. var contentStateWithEntity = contentState.createEntity(type, immutable ? 'IMMUTABLE' : 'MUTABLE', data);
  26233. var entityKey = contentStateWithEntity.getLastCreatedEntityKey();
  26234. var newEditorState = Draft.AtomicBlockUtils.insertAtomicBlock(editorState, entityKey, ' ');
  26235. return newEditorState;
  26236. };
  26237. var insertHorizontalLine = exports.insertHorizontalLine = function insertHorizontalLine(editorState) {
  26238. return insertAtomicBlock(editorState, 'HR');
  26239. };
  26240. var insertMedias = exports.insertMedias = function insertMedias(editorState) {
  26241. var medias = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  26242. if (!medias.length) {
  26243. return editorState;
  26244. }
  26245. return medias.reduce(function (editorState, media) {
  26246. var url = media.url,
  26247. link = media.link,
  26248. link_target = media.link_target,
  26249. name = media.name,
  26250. type = media.type,
  26251. width = media.width,
  26252. height = media.height,
  26253. meta = media.meta;
  26254. return insertAtomicBlock(editorState, type, true, { url: url, link: link, link_target: link_target, name: name, type: type, width: width, height: height, meta: meta });
  26255. }, editorState);
  26256. };
  26257. var setMediaData = exports.setMediaData = function setMediaData(editorState, entityKey, data) {
  26258. return Draft.EditorState.push(editorState, editorState.getCurrentContent().mergeEntityData(entityKey, data), 'change-block-data');
  26259. };
  26260. var removeMedia = exports.removeMedia = function removeMedia(editorState, mediaBlock) {
  26261. return removeBlock(editorState, mediaBlock);
  26262. };
  26263. var setMediaPosition = exports.setMediaPosition = function setMediaPosition(editorState, mediaBlock, position) {
  26264. var newPosition = {};
  26265. var float = position.float,
  26266. alignment = position.alignment;
  26267. if (typeof float !== 'undefined') {
  26268. newPosition.float = mediaBlock.getData().get('float') === float ? null : float;
  26269. }
  26270. if (typeof alignment !== 'undefined') {
  26271. newPosition.alignment = mediaBlock.getData().get('alignment') === alignment ? null : alignment;
  26272. }
  26273. return setSelectionBlockData(selectBlock(editorState, mediaBlock), newPosition);
  26274. };
  26275. var clear = exports.clear = function clear(editorState) {
  26276. var contentState = editorState.getCurrentContent();
  26277. var firstBlock = contentState.getFirstBlock();
  26278. var lastBlock = contentState.getLastBlock();
  26279. var allSelected = new Draft.SelectionState({
  26280. anchorKey: firstBlock.getKey(),
  26281. anchorOffset: 0,
  26282. focusKey: lastBlock.getKey(),
  26283. focusOffset: lastBlock.getLength(),
  26284. hasFocus: true
  26285. });
  26286. return Draft.RichUtils.toggleBlockType(Draft.EditorState.push(editorState, Draft.Modifier.removeRange(contentState, allSelected, 'backward'), 'remove-range'), 'unstyled');
  26287. };
  26288. var handleKeyCommand = exports.handleKeyCommand = function handleKeyCommand(editorState, command) {
  26289. return Draft.RichUtils.handleKeyCommand(editorState, command);
  26290. };
  26291. var undo = exports.undo = function undo(editorState) {
  26292. return Draft.EditorState.undo(editorState);
  26293. };
  26294. var redo = exports.redo = function redo(editorState) {
  26295. return Draft.EditorState.redo(editorState);
  26296. };
  26297. });
  26298. unwrapExports(content);
  26299. var content_1 = content.redo;
  26300. var content_2 = content.undo;
  26301. var content_3 = content.handleKeyCommand;
  26302. var content_4 = content.clear;
  26303. var content_5 = content.setMediaPosition;
  26304. var content_6 = content.removeMedia;
  26305. var content_7 = content.setMediaData;
  26306. var content_8 = content.insertMedias;
  26307. var content_9 = content.insertHorizontalLine;
  26308. var content_10 = content.insertAtomicBlock;
  26309. var content_11 = content.insertHTML;
  26310. var content_12 = content.insertText;
  26311. var content_13 = content.toggleSelectionLetterSpacing;
  26312. var content_14 = content.toggleSelectionFontFamily;
  26313. var content_15 = content.toggleSelectionLineHeight;
  26314. var content_16 = content.toggleSelectionFontSize;
  26315. var content_17 = content.toggleSelectionBackgroundColor;
  26316. var content_18 = content.toggleSelectionColor;
  26317. var content_19 = content.decreaseSelectionIndent;
  26318. var content_20 = content.increaseSelectionIndent;
  26319. var content_21 = content.toggleSelectionIndent;
  26320. var content_22 = content.toggleSelectionAlignment;
  26321. var content_23 = content.removeSelectionInlineStyles;
  26322. var content_24 = content.toggleSelectionInlineStyle;
  26323. var content_25 = content.selectionHasInlineStyle;
  26324. var content_26 = content.getSelectionInlineStyle;
  26325. var content_27 = content.toggleSelectionLink;
  26326. var content_28 = content.toggleSelectionEntity;
  26327. var content_29 = content.getSelectionEntityData;
  26328. var content_30 = content.getSelectionEntityType;
  26329. var content_31 = content.toggleSelectionBlockType;
  26330. var content_32 = content.getSelectionText;
  26331. var content_33 = content.getSelectionBlockType;
  26332. var content_34 = content.getSelectionBlockData;
  26333. var content_35 = content.setSelectionBlockData;
  26334. var content_36 = content.getSelectedBlocks;
  26335. var content_37 = content.updateEachCharacterOfSelection;
  26336. var content_38 = content.getSelectionBlock;
  26337. var content_39 = content.removeBlock;
  26338. var content_40 = content.selectNextBlock;
  26339. var content_41 = content.selectBlock;
  26340. var content_42 = content.selectionContainsStrictBlock;
  26341. var content_43 = content.selectionContainsBlockType;
  26342. var content_44 = content.isSelectionCollapsed;
  26343. var content_45 = content.createEditorState;
  26344. var content_46 = content.createEmptyEditorState;
  26345. var content_47 = content.isEditorState;
  26346. var content_48 = content.registerStrictBlockType;
  26347. var base = createCommonjsModule(function (module, exports) {
  26348. Object.defineProperty(exports, "__esModule", {
  26349. value: true
  26350. });
  26351. var braftUniqueIndex = 0;
  26352. var UniqueIndex = exports.UniqueIndex = function UniqueIndex() {
  26353. return braftUniqueIndex += 1;
  26354. };
  26355. });
  26356. unwrapExports(base);
  26357. var base_1 = base.UniqueIndex;
  26358. var color = createCommonjsModule(function (module, exports) {
  26359. Object.defineProperty(exports, "__esModule", {
  26360. value: true
  26361. });
  26362. var _namedColors = {
  26363. "aliceblue": "#f0f8ff",
  26364. "antiquewhite": "#faebd7",
  26365. "aqua": "#00ffff",
  26366. "aquamarine": "#7fffd4",
  26367. "azure": "#f0ffff",
  26368. "beige": "#f5f5dc",
  26369. "bisque": "#ffe4c4",
  26370. "black": "#000000",
  26371. "blanchedalmond": "#ffebcd",
  26372. "blue": "#0000ff",
  26373. "blueviolet": "#8a2be2",
  26374. "brown": "#a52a2a",
  26375. "burlywood": "#deb887",
  26376. "cadetblue": "#5f9ea0",
  26377. "chartreuse": "#7fff00",
  26378. "chocolate": "#d2691e",
  26379. "coral": "#ff7f50",
  26380. "cornflowerblue": "#6495ed",
  26381. "cornsilk": "#fff8dc",
  26382. "crimson": "#dc143c",
  26383. "cyan": "#00ffff",
  26384. "darkblue": "#00008b",
  26385. "darkcyan": "#008b8b",
  26386. "darkgoldenrod": "#b8860b",
  26387. "darkgray": "#a9a9a9",
  26388. "darkgreen": "#006400",
  26389. "darkkhaki": "#bdb76b",
  26390. "darkmagenta": "#8b008b",
  26391. "darkolivegreen": "#556b2f",
  26392. "darkorange": "#ff8c00",
  26393. "darkorchid": "#9932cc",
  26394. "darkred": "#8b0000",
  26395. "darksalmon": "#e9967a",
  26396. "darkseagreen": "#8fbc8f",
  26397. "darkslateblue": "#483d8b",
  26398. "darkslategray": "#2f4f4f",
  26399. "darkturquoise": "#00ced1",
  26400. "darkviolet": "#9400d3",
  26401. "deeppink": "#ff1493",
  26402. "deepskyblue": "#00bfff",
  26403. "dimgray": "#696969",
  26404. "dodgerblue": "#1e90ff",
  26405. "firebrick": "#b22222",
  26406. "floralwhite": "#fffaf0",
  26407. "forestgreen": "#228b22",
  26408. "fuchsia": "#ff00ff",
  26409. "gainsboro": "#dcdcdc",
  26410. "ghostwhite": "#f8f8ff",
  26411. "gold": "#ffd700",
  26412. "goldenrod": "#daa520",
  26413. "gray": "#808080",
  26414. "green": "#008000",
  26415. "greenyellow": "#adff2f",
  26416. "honeydew": "#f0fff0",
  26417. "hotpink": "#ff69b4",
  26418. "indianred ": "#cd5c5c",
  26419. "indigo": "#4b0082",
  26420. "ivory": "#fffff0",
  26421. "khaki": "#f0e68c",
  26422. "lavender": "#e6e6fa",
  26423. "lavenderblush": "#fff0f5",
  26424. "lawngreen": "#7cfc00",
  26425. "lemonchiffon": "#fffacd",
  26426. "lightblue": "#add8e6",
  26427. "lightcoral": "#f08080",
  26428. "lightcyan": "#e0ffff",
  26429. "lightgoldenrodyellow": "#fafad2",
  26430. "lightgrey": "#d3d3d3",
  26431. "lightgreen": "#90ee90",
  26432. "lightpink": "#ffb6c1",
  26433. "lightsalmon": "#ffa07a",
  26434. "lightseagreen": "#20b2aa",
  26435. "lightskyblue": "#87cefa",
  26436. "lightslategray": "#778899",
  26437. "lightsteelblue": "#b0c4de",
  26438. "lightyellow": "#ffffe0",
  26439. "lime": "#00ff00",
  26440. "limegreen": "#32cd32",
  26441. "linen": "#faf0e6",
  26442. "magenta": "#ff00ff",
  26443. "maroon": "#800000",
  26444. "mediumaquamarine": "#66cdaa",
  26445. "mediumblue": "#0000cd",
  26446. "mediumorchid": "#ba55d3",
  26447. "mediumpurple": "#9370d8",
  26448. "mediumseagreen": "#3cb371",
  26449. "mediumslateblue": "#7b68ee",
  26450. "mediumspringgreen": "#00fa9a",
  26451. "mediumturquoise": "#48d1cc",
  26452. "mediumvioletred": "#c71585",
  26453. "midnightblue": "#191970",
  26454. "mintcream": "#f5fffa",
  26455. "mistyrose": "#ffe4e1",
  26456. "moccasin": "#ffe4b5",
  26457. "navajowhite": "#ffdead",
  26458. "navy": "#000080",
  26459. "oldlace": "#fdf5e6",
  26460. "olive": "#808000",
  26461. "olivedrab": "#6b8e23",
  26462. "orange": "#ffa500",
  26463. "orangered": "#ff4500",
  26464. "orchid": "#da70d6",
  26465. "palegoldenrod": "#eee8aa",
  26466. "palegreen": "#98fb98",
  26467. "paleturquoise": "#afeeee",
  26468. "palevioletred": "#d87093",
  26469. "papayawhip": "#ffefd5",
  26470. "peachpuff": "#ffdab9",
  26471. "peru": "#cd853f",
  26472. "pink": "#ffc0cb",
  26473. "plum": "#dda0dd",
  26474. "powderblue": "#b0e0e6",
  26475. "purple": "#800080",
  26476. "rebeccapurple": "#663399",
  26477. "red": "#ff0000",
  26478. "rosybrown": "#bc8f8f",
  26479. "royalblue": "#4169e1",
  26480. "saddlebrown": "#8b4513",
  26481. "salmon": "#fa8072",
  26482. "sandybrown": "#f4a460",
  26483. "seagreen": "#2e8b57",
  26484. "seashell": "#fff5ee",
  26485. "sienna": "#a0522d",
  26486. "silver": "#c0c0c0",
  26487. "skyblue": "#87ceeb",
  26488. "slateblue": "#6a5acd",
  26489. "slategray": "#708090",
  26490. "snow": "#fffafa",
  26491. "springgreen": "#00ff7f",
  26492. "steelblue": "#4682b4",
  26493. "tan": "#d2b48c",
  26494. "teal": "#008080",
  26495. "thistle": "#d8bfd8",
  26496. "tomato": "#ff6347",
  26497. "turquoise": "#40e0d0",
  26498. "violet": "#ee82ee",
  26499. "wheat": "#f5deb3",
  26500. "white": "#ffffff",
  26501. "whitesmoke": "#f5f5f5",
  26502. "yellow": "#ffff00",
  26503. "yellowgreen": "#9acd32"
  26504. };
  26505. var _getHexColor = function _getHexColor(color) {
  26506. color = color.replace('color:', '').replace(';', '').replace(' ', '');
  26507. if (/^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/.test(color)) {
  26508. return color;
  26509. } else if (namedColors[color]) {
  26510. return namedColors[color];
  26511. } else if (color.indexOf('rgb') === 0) {
  26512. var rgbArray = color.split(',');
  26513. var convertedColor = rgbArray.length < 3 ? null : '#' + [rgbArray[0], rgbArray[1], rgbArray[2]].map(function (x) {
  26514. var hex = parseInt(x.replace(/\D/g, ''), 10).toString(16);
  26515. return hex.length === 1 ? '0' + hex : hex;
  26516. }).join('');
  26517. return (/^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/.test(convertedColor) ? convertedColor : null
  26518. );
  26519. } else {
  26520. return null;
  26521. }
  26522. };
  26523. var namedColors = exports.namedColors = _namedColors;
  26524. var getHexColor = exports.getHexColor = _getHexColor;
  26525. var detectColorsFromHTMLString = exports.detectColorsFromHTMLString = function detectColorsFromHTMLString(html) {
  26526. return typeof html !== 'string' ? [] : (html.match(/color:[^;]{3,24};/g) || []).map(getHexColor).filter(function (color) {
  26527. return color;
  26528. });
  26529. };
  26530. var detectColorsFromDraftState = exports.detectColorsFromDraftState = function detectColorsFromDraftState(draftState) {
  26531. var result = [];
  26532. if (!draftState || !draftState.blocks || !draftState.blocks.length) {
  26533. return result;
  26534. }
  26535. draftState.blocks.forEach(function (block) {
  26536. if (block && block.inlineStyleRanges && block.inlineStyleRanges.length) {
  26537. block.inlineStyleRanges.forEach(function (inlineStyle) {
  26538. if (inlineStyle.style && inlineStyle.style.indexOf('COLOR-') >= 0) {
  26539. result.push('#' + inlineStyle.style.split('COLOR-')[1]);
  26540. }
  26541. });
  26542. }
  26543. });
  26544. return result.filter(function (color) {
  26545. return color;
  26546. });
  26547. };
  26548. });
  26549. unwrapExports(color);
  26550. var color_1 = color.namedColors;
  26551. var color_2 = color.getHexColor;
  26552. var color_3 = color.detectColorsFromHTMLString;
  26553. var color_4 = color.detectColorsFromDraftState;
  26554. var dist$1 = createCommonjsModule(function (module, exports) {
  26555. Object.defineProperty(exports, "__esModule", {
  26556. value: true
  26557. });
  26558. exports.ColorUtils = exports.BaseUtils = exports.ContentUtils = undefined;
  26559. var _ContentUtils = _interopRequireWildcard(content);
  26560. var _BaseUtils = _interopRequireWildcard(base);
  26561. var _ColorUtils = _interopRequireWildcard(color);
  26562. 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; } }
  26563. var ContentUtils = exports.ContentUtils = _ContentUtils;
  26564. var BaseUtils = exports.BaseUtils = _BaseUtils;
  26565. var ColorUtils = exports.ColorUtils = _ColorUtils;
  26566. });
  26567. unwrapExports(dist$1);
  26568. var dist_1$1 = dist$1.ColorUtils;
  26569. var dist_2$1 = dist$1.BaseUtils;
  26570. var dist_3$1 = dist$1.ContentUtils;
  26571. var immutable$3 = createCommonjsModule(function (module, exports) {
  26572. /**
  26573. * Copyright (c) 2014-2015, Facebook, Inc.
  26574. * All rights reserved.
  26575. *
  26576. * This source code is licensed under the BSD-style license found in the
  26577. * LICENSE file in the root directory of this source tree. An additional grant
  26578. * of patent rights can be found in the PATENTS file in the same directory.
  26579. */
  26580. (function (global, factory) {
  26581. module.exports = factory() ;
  26582. }(commonjsGlobal, function () {var SLICE$0 = Array.prototype.slice;
  26583. function createClass(ctor, superClass) {
  26584. if (superClass) {
  26585. ctor.prototype = Object.create(superClass.prototype);
  26586. }
  26587. ctor.prototype.constructor = ctor;
  26588. }
  26589. function Iterable(value) {
  26590. return isIterable(value) ? value : Seq(value);
  26591. }
  26592. createClass(KeyedIterable, Iterable);
  26593. function KeyedIterable(value) {
  26594. return isKeyed(value) ? value : KeyedSeq(value);
  26595. }
  26596. createClass(IndexedIterable, Iterable);
  26597. function IndexedIterable(value) {
  26598. return isIndexed(value) ? value : IndexedSeq(value);
  26599. }
  26600. createClass(SetIterable, Iterable);
  26601. function SetIterable(value) {
  26602. return isIterable(value) && !isAssociative(value) ? value : SetSeq(value);
  26603. }
  26604. function isIterable(maybeIterable) {
  26605. return !!(maybeIterable && maybeIterable[IS_ITERABLE_SENTINEL]);
  26606. }
  26607. function isKeyed(maybeKeyed) {
  26608. return !!(maybeKeyed && maybeKeyed[IS_KEYED_SENTINEL]);
  26609. }
  26610. function isIndexed(maybeIndexed) {
  26611. return !!(maybeIndexed && maybeIndexed[IS_INDEXED_SENTINEL]);
  26612. }
  26613. function isAssociative(maybeAssociative) {
  26614. return isKeyed(maybeAssociative) || isIndexed(maybeAssociative);
  26615. }
  26616. function isOrdered(maybeOrdered) {
  26617. return !!(maybeOrdered && maybeOrdered[IS_ORDERED_SENTINEL]);
  26618. }
  26619. Iterable.isIterable = isIterable;
  26620. Iterable.isKeyed = isKeyed;
  26621. Iterable.isIndexed = isIndexed;
  26622. Iterable.isAssociative = isAssociative;
  26623. Iterable.isOrdered = isOrdered;
  26624. Iterable.Keyed = KeyedIterable;
  26625. Iterable.Indexed = IndexedIterable;
  26626. Iterable.Set = SetIterable;
  26627. var IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
  26628. var IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
  26629. var IS_INDEXED_SENTINEL = '@@__IMMUTABLE_INDEXED__@@';
  26630. var IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
  26631. // Used for setting prototype methods that IE8 chokes on.
  26632. var DELETE = 'delete';
  26633. // Constants describing the size of trie nodes.
  26634. var SHIFT = 5; // Resulted in best performance after ______?
  26635. var SIZE = 1 << SHIFT;
  26636. var MASK = SIZE - 1;
  26637. // A consistent shared value representing "not set" which equals nothing other
  26638. // than itself, and nothing that could be provided externally.
  26639. var NOT_SET = {};
  26640. // Boolean references, Rough equivalent of `bool &`.
  26641. var CHANGE_LENGTH = { value: false };
  26642. var DID_ALTER = { value: false };
  26643. function MakeRef(ref) {
  26644. ref.value = false;
  26645. return ref;
  26646. }
  26647. function SetRef(ref) {
  26648. ref && (ref.value = true);
  26649. }
  26650. // A function which returns a value representing an "owner" for transient writes
  26651. // to tries. The return value will only ever equal itself, and will not equal
  26652. // the return of any subsequent call of this function.
  26653. function OwnerID() {}
  26654. // http://jsperf.com/copy-array-inline
  26655. function arrCopy(arr, offset) {
  26656. offset = offset || 0;
  26657. var len = Math.max(0, arr.length - offset);
  26658. var newArr = new Array(len);
  26659. for (var ii = 0; ii < len; ii++) {
  26660. newArr[ii] = arr[ii + offset];
  26661. }
  26662. return newArr;
  26663. }
  26664. function ensureSize(iter) {
  26665. if (iter.size === undefined) {
  26666. iter.size = iter.__iterate(returnTrue);
  26667. }
  26668. return iter.size;
  26669. }
  26670. function wrapIndex(iter, index) {
  26671. // This implements "is array index" which the ECMAString spec defines as:
  26672. //
  26673. // A String property name P is an array index if and only if
  26674. // ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal
  26675. // to 2^32−1.
  26676. //
  26677. // http://www.ecma-international.org/ecma-262/6.0/#sec-array-exotic-objects
  26678. if (typeof index !== 'number') {
  26679. var uint32Index = index >>> 0; // N >>> 0 is shorthand for ToUint32
  26680. if ('' + uint32Index !== index || uint32Index === 4294967295) {
  26681. return NaN;
  26682. }
  26683. index = uint32Index;
  26684. }
  26685. return index < 0 ? ensureSize(iter) + index : index;
  26686. }
  26687. function returnTrue() {
  26688. return true;
  26689. }
  26690. function wholeSlice(begin, end, size) {
  26691. return (begin === 0 || (size !== undefined && begin <= -size)) &&
  26692. (end === undefined || (size !== undefined && end >= size));
  26693. }
  26694. function resolveBegin(begin, size) {
  26695. return resolveIndex(begin, size, 0);
  26696. }
  26697. function resolveEnd(end, size) {
  26698. return resolveIndex(end, size, size);
  26699. }
  26700. function resolveIndex(index, size, defaultIndex) {
  26701. return index === undefined ?
  26702. defaultIndex :
  26703. index < 0 ?
  26704. Math.max(0, size + index) :
  26705. size === undefined ?
  26706. index :
  26707. Math.min(size, index);
  26708. }
  26709. /* global Symbol */
  26710. var ITERATE_KEYS = 0;
  26711. var ITERATE_VALUES = 1;
  26712. var ITERATE_ENTRIES = 2;
  26713. var REAL_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
  26714. var FAUX_ITERATOR_SYMBOL = '@@iterator';
  26715. var ITERATOR_SYMBOL = REAL_ITERATOR_SYMBOL || FAUX_ITERATOR_SYMBOL;
  26716. function Iterator(next) {
  26717. this.next = next;
  26718. }
  26719. Iterator.prototype.toString = function() {
  26720. return '[Iterator]';
  26721. };
  26722. Iterator.KEYS = ITERATE_KEYS;
  26723. Iterator.VALUES = ITERATE_VALUES;
  26724. Iterator.ENTRIES = ITERATE_ENTRIES;
  26725. Iterator.prototype.inspect =
  26726. Iterator.prototype.toSource = function () { return this.toString(); };
  26727. Iterator.prototype[ITERATOR_SYMBOL] = function () {
  26728. return this;
  26729. };
  26730. function iteratorValue(type, k, v, iteratorResult) {
  26731. var value = type === 0 ? k : type === 1 ? v : [k, v];
  26732. iteratorResult ? (iteratorResult.value = value) : (iteratorResult = {
  26733. value: value, done: false
  26734. });
  26735. return iteratorResult;
  26736. }
  26737. function iteratorDone() {
  26738. return { value: undefined, done: true };
  26739. }
  26740. function hasIterator(maybeIterable) {
  26741. return !!getIteratorFn(maybeIterable);
  26742. }
  26743. function isIterator(maybeIterator) {
  26744. return maybeIterator && typeof maybeIterator.next === 'function';
  26745. }
  26746. function getIterator(iterable) {
  26747. var iteratorFn = getIteratorFn(iterable);
  26748. return iteratorFn && iteratorFn.call(iterable);
  26749. }
  26750. function getIteratorFn(iterable) {
  26751. var iteratorFn = iterable && (
  26752. (REAL_ITERATOR_SYMBOL && iterable[REAL_ITERATOR_SYMBOL]) ||
  26753. iterable[FAUX_ITERATOR_SYMBOL]
  26754. );
  26755. if (typeof iteratorFn === 'function') {
  26756. return iteratorFn;
  26757. }
  26758. }
  26759. function isArrayLike(value) {
  26760. return value && typeof value.length === 'number';
  26761. }
  26762. createClass(Seq, Iterable);
  26763. function Seq(value) {
  26764. return value === null || value === undefined ? emptySequence() :
  26765. isIterable(value) ? value.toSeq() : seqFromValue(value);
  26766. }
  26767. Seq.of = function(/*...values*/) {
  26768. return Seq(arguments);
  26769. };
  26770. Seq.prototype.toSeq = function() {
  26771. return this;
  26772. };
  26773. Seq.prototype.toString = function() {
  26774. return this.__toString('Seq {', '}');
  26775. };
  26776. Seq.prototype.cacheResult = function() {
  26777. if (!this._cache && this.__iterateUncached) {
  26778. this._cache = this.entrySeq().toArray();
  26779. this.size = this._cache.length;
  26780. }
  26781. return this;
  26782. };
  26783. // abstract __iterateUncached(fn, reverse)
  26784. Seq.prototype.__iterate = function(fn, reverse) {
  26785. return seqIterate(this, fn, reverse, true);
  26786. };
  26787. // abstract __iteratorUncached(type, reverse)
  26788. Seq.prototype.__iterator = function(type, reverse) {
  26789. return seqIterator(this, type, reverse, true);
  26790. };
  26791. createClass(KeyedSeq, Seq);
  26792. function KeyedSeq(value) {
  26793. return value === null || value === undefined ?
  26794. emptySequence().toKeyedSeq() :
  26795. isIterable(value) ?
  26796. (isKeyed(value) ? value.toSeq() : value.fromEntrySeq()) :
  26797. keyedSeqFromValue(value);
  26798. }
  26799. KeyedSeq.prototype.toKeyedSeq = function() {
  26800. return this;
  26801. };
  26802. createClass(IndexedSeq, Seq);
  26803. function IndexedSeq(value) {
  26804. return value === null || value === undefined ? emptySequence() :
  26805. !isIterable(value) ? indexedSeqFromValue(value) :
  26806. isKeyed(value) ? value.entrySeq() : value.toIndexedSeq();
  26807. }
  26808. IndexedSeq.of = function(/*...values*/) {
  26809. return IndexedSeq(arguments);
  26810. };
  26811. IndexedSeq.prototype.toIndexedSeq = function() {
  26812. return this;
  26813. };
  26814. IndexedSeq.prototype.toString = function() {
  26815. return this.__toString('Seq [', ']');
  26816. };
  26817. IndexedSeq.prototype.__iterate = function(fn, reverse) {
  26818. return seqIterate(this, fn, reverse, false);
  26819. };
  26820. IndexedSeq.prototype.__iterator = function(type, reverse) {
  26821. return seqIterator(this, type, reverse, false);
  26822. };
  26823. createClass(SetSeq, Seq);
  26824. function SetSeq(value) {
  26825. return (
  26826. value === null || value === undefined ? emptySequence() :
  26827. !isIterable(value) ? indexedSeqFromValue(value) :
  26828. isKeyed(value) ? value.entrySeq() : value
  26829. ).toSetSeq();
  26830. }
  26831. SetSeq.of = function(/*...values*/) {
  26832. return SetSeq(arguments);
  26833. };
  26834. SetSeq.prototype.toSetSeq = function() {
  26835. return this;
  26836. };
  26837. Seq.isSeq = isSeq;
  26838. Seq.Keyed = KeyedSeq;
  26839. Seq.Set = SetSeq;
  26840. Seq.Indexed = IndexedSeq;
  26841. var IS_SEQ_SENTINEL = '@@__IMMUTABLE_SEQ__@@';
  26842. Seq.prototype[IS_SEQ_SENTINEL] = true;
  26843. createClass(ArraySeq, IndexedSeq);
  26844. function ArraySeq(array) {
  26845. this._array = array;
  26846. this.size = array.length;
  26847. }
  26848. ArraySeq.prototype.get = function(index, notSetValue) {
  26849. return this.has(index) ? this._array[wrapIndex(this, index)] : notSetValue;
  26850. };
  26851. ArraySeq.prototype.__iterate = function(fn, reverse) {
  26852. var array = this._array;
  26853. var maxIndex = array.length - 1;
  26854. for (var ii = 0; ii <= maxIndex; ii++) {
  26855. if (fn(array[reverse ? maxIndex - ii : ii], ii, this) === false) {
  26856. return ii + 1;
  26857. }
  26858. }
  26859. return ii;
  26860. };
  26861. ArraySeq.prototype.__iterator = function(type, reverse) {
  26862. var array = this._array;
  26863. var maxIndex = array.length - 1;
  26864. var ii = 0;
  26865. return new Iterator(function()
  26866. {return ii > maxIndex ?
  26867. iteratorDone() :
  26868. iteratorValue(type, ii, array[reverse ? maxIndex - ii++ : ii++])}
  26869. );
  26870. };
  26871. createClass(ObjectSeq, KeyedSeq);
  26872. function ObjectSeq(object) {
  26873. var keys = Object.keys(object);
  26874. this._object = object;
  26875. this._keys = keys;
  26876. this.size = keys.length;
  26877. }
  26878. ObjectSeq.prototype.get = function(key, notSetValue) {
  26879. if (notSetValue !== undefined && !this.has(key)) {
  26880. return notSetValue;
  26881. }
  26882. return this._object[key];
  26883. };
  26884. ObjectSeq.prototype.has = function(key) {
  26885. return this._object.hasOwnProperty(key);
  26886. };
  26887. ObjectSeq.prototype.__iterate = function(fn, reverse) {
  26888. var object = this._object;
  26889. var keys = this._keys;
  26890. var maxIndex = keys.length - 1;
  26891. for (var ii = 0; ii <= maxIndex; ii++) {
  26892. var key = keys[reverse ? maxIndex - ii : ii];
  26893. if (fn(object[key], key, this) === false) {
  26894. return ii + 1;
  26895. }
  26896. }
  26897. return ii;
  26898. };
  26899. ObjectSeq.prototype.__iterator = function(type, reverse) {
  26900. var object = this._object;
  26901. var keys = this._keys;
  26902. var maxIndex = keys.length - 1;
  26903. var ii = 0;
  26904. return new Iterator(function() {
  26905. var key = keys[reverse ? maxIndex - ii : ii];
  26906. return ii++ > maxIndex ?
  26907. iteratorDone() :
  26908. iteratorValue(type, key, object[key]);
  26909. });
  26910. };
  26911. ObjectSeq.prototype[IS_ORDERED_SENTINEL] = true;
  26912. createClass(IterableSeq, IndexedSeq);
  26913. function IterableSeq(iterable) {
  26914. this._iterable = iterable;
  26915. this.size = iterable.length || iterable.size;
  26916. }
  26917. IterableSeq.prototype.__iterateUncached = function(fn, reverse) {
  26918. if (reverse) {
  26919. return this.cacheResult().__iterate(fn, reverse);
  26920. }
  26921. var iterable = this._iterable;
  26922. var iterator = getIterator(iterable);
  26923. var iterations = 0;
  26924. if (isIterator(iterator)) {
  26925. var step;
  26926. while (!(step = iterator.next()).done) {
  26927. if (fn(step.value, iterations++, this) === false) {
  26928. break;
  26929. }
  26930. }
  26931. }
  26932. return iterations;
  26933. };
  26934. IterableSeq.prototype.__iteratorUncached = function(type, reverse) {
  26935. if (reverse) {
  26936. return this.cacheResult().__iterator(type, reverse);
  26937. }
  26938. var iterable = this._iterable;
  26939. var iterator = getIterator(iterable);
  26940. if (!isIterator(iterator)) {
  26941. return new Iterator(iteratorDone);
  26942. }
  26943. var iterations = 0;
  26944. return new Iterator(function() {
  26945. var step = iterator.next();
  26946. return step.done ? step : iteratorValue(type, iterations++, step.value);
  26947. });
  26948. };
  26949. createClass(IteratorSeq, IndexedSeq);
  26950. function IteratorSeq(iterator) {
  26951. this._iterator = iterator;
  26952. this._iteratorCache = [];
  26953. }
  26954. IteratorSeq.prototype.__iterateUncached = function(fn, reverse) {
  26955. if (reverse) {
  26956. return this.cacheResult().__iterate(fn, reverse);
  26957. }
  26958. var iterator = this._iterator;
  26959. var cache = this._iteratorCache;
  26960. var iterations = 0;
  26961. while (iterations < cache.length) {
  26962. if (fn(cache[iterations], iterations++, this) === false) {
  26963. return iterations;
  26964. }
  26965. }
  26966. var step;
  26967. while (!(step = iterator.next()).done) {
  26968. var val = step.value;
  26969. cache[iterations] = val;
  26970. if (fn(val, iterations++, this) === false) {
  26971. break;
  26972. }
  26973. }
  26974. return iterations;
  26975. };
  26976. IteratorSeq.prototype.__iteratorUncached = function(type, reverse) {
  26977. if (reverse) {
  26978. return this.cacheResult().__iterator(type, reverse);
  26979. }
  26980. var iterator = this._iterator;
  26981. var cache = this._iteratorCache;
  26982. var iterations = 0;
  26983. return new Iterator(function() {
  26984. if (iterations >= cache.length) {
  26985. var step = iterator.next();
  26986. if (step.done) {
  26987. return step;
  26988. }
  26989. cache[iterations] = step.value;
  26990. }
  26991. return iteratorValue(type, iterations, cache[iterations++]);
  26992. });
  26993. };
  26994. // # pragma Helper functions
  26995. function isSeq(maybeSeq) {
  26996. return !!(maybeSeq && maybeSeq[IS_SEQ_SENTINEL]);
  26997. }
  26998. var EMPTY_SEQ;
  26999. function emptySequence() {
  27000. return EMPTY_SEQ || (EMPTY_SEQ = new ArraySeq([]));
  27001. }
  27002. function keyedSeqFromValue(value) {
  27003. var seq =
  27004. Array.isArray(value) ? new ArraySeq(value).fromEntrySeq() :
  27005. isIterator(value) ? new IteratorSeq(value).fromEntrySeq() :
  27006. hasIterator(value) ? new IterableSeq(value).fromEntrySeq() :
  27007. typeof value === 'object' ? new ObjectSeq(value) :
  27008. undefined;
  27009. if (!seq) {
  27010. throw new TypeError(
  27011. 'Expected Array or iterable object of [k, v] entries, '+
  27012. 'or keyed object: ' + value
  27013. );
  27014. }
  27015. return seq;
  27016. }
  27017. function indexedSeqFromValue(value) {
  27018. var seq = maybeIndexedSeqFromValue(value);
  27019. if (!seq) {
  27020. throw new TypeError(
  27021. 'Expected Array or iterable object of values: ' + value
  27022. );
  27023. }
  27024. return seq;
  27025. }
  27026. function seqFromValue(value) {
  27027. var seq = maybeIndexedSeqFromValue(value) ||
  27028. (typeof value === 'object' && new ObjectSeq(value));
  27029. if (!seq) {
  27030. throw new TypeError(
  27031. 'Expected Array or iterable object of values, or keyed object: ' + value
  27032. );
  27033. }
  27034. return seq;
  27035. }
  27036. function maybeIndexedSeqFromValue(value) {
  27037. return (
  27038. isArrayLike(value) ? new ArraySeq(value) :
  27039. isIterator(value) ? new IteratorSeq(value) :
  27040. hasIterator(value) ? new IterableSeq(value) :
  27041. undefined
  27042. );
  27043. }
  27044. function seqIterate(seq, fn, reverse, useKeys) {
  27045. var cache = seq._cache;
  27046. if (cache) {
  27047. var maxIndex = cache.length - 1;
  27048. for (var ii = 0; ii <= maxIndex; ii++) {
  27049. var entry = cache[reverse ? maxIndex - ii : ii];
  27050. if (fn(entry[1], useKeys ? entry[0] : ii, seq) === false) {
  27051. return ii + 1;
  27052. }
  27053. }
  27054. return ii;
  27055. }
  27056. return seq.__iterateUncached(fn, reverse);
  27057. }
  27058. function seqIterator(seq, type, reverse, useKeys) {
  27059. var cache = seq._cache;
  27060. if (cache) {
  27061. var maxIndex = cache.length - 1;
  27062. var ii = 0;
  27063. return new Iterator(function() {
  27064. var entry = cache[reverse ? maxIndex - ii : ii];
  27065. return ii++ > maxIndex ?
  27066. iteratorDone() :
  27067. iteratorValue(type, useKeys ? entry[0] : ii - 1, entry[1]);
  27068. });
  27069. }
  27070. return seq.__iteratorUncached(type, reverse);
  27071. }
  27072. function fromJS(json, converter) {
  27073. return converter ?
  27074. fromJSWith(converter, json, '', {'': json}) :
  27075. fromJSDefault(json);
  27076. }
  27077. function fromJSWith(converter, json, key, parentJSON) {
  27078. if (Array.isArray(json)) {
  27079. return converter.call(parentJSON, key, IndexedSeq(json).map(function(v, k) {return fromJSWith(converter, v, k, json)}));
  27080. }
  27081. if (isPlainObj(json)) {
  27082. return converter.call(parentJSON, key, KeyedSeq(json).map(function(v, k) {return fromJSWith(converter, v, k, json)}));
  27083. }
  27084. return json;
  27085. }
  27086. function fromJSDefault(json) {
  27087. if (Array.isArray(json)) {
  27088. return IndexedSeq(json).map(fromJSDefault).toList();
  27089. }
  27090. if (isPlainObj(json)) {
  27091. return KeyedSeq(json).map(fromJSDefault).toMap();
  27092. }
  27093. return json;
  27094. }
  27095. function isPlainObj(value) {
  27096. return value && (value.constructor === Object || value.constructor === undefined);
  27097. }
  27098. /**
  27099. * An extension of the "same-value" algorithm as [described for use by ES6 Map
  27100. * and Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map#Key_equality)
  27101. *
  27102. * NaN is considered the same as NaN, however -0 and 0 are considered the same
  27103. * value, which is different from the algorithm described by
  27104. * [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is).
  27105. *
  27106. * This is extended further to allow Objects to describe the values they
  27107. * represent, by way of `valueOf` or `equals` (and `hashCode`).
  27108. *
  27109. * Note: because of this extension, the key equality of Immutable.Map and the
  27110. * value equality of Immutable.Set will differ from ES6 Map and Set.
  27111. *
  27112. * ### Defining custom values
  27113. *
  27114. * The easiest way to describe the value an object represents is by implementing
  27115. * `valueOf`. For example, `Date` represents a value by returning a unix
  27116. * timestamp for `valueOf`:
  27117. *
  27118. * var date1 = new Date(1234567890000); // Fri Feb 13 2009 ...
  27119. * var date2 = new Date(1234567890000);
  27120. * date1.valueOf(); // 1234567890000
  27121. * assert( date1 !== date2 );
  27122. * assert( Immutable.is( date1, date2 ) );
  27123. *
  27124. * Note: overriding `valueOf` may have other implications if you use this object
  27125. * where JavaScript expects a primitive, such as implicit string coercion.
  27126. *
  27127. * For more complex types, especially collections, implementing `valueOf` may
  27128. * not be performant. An alternative is to implement `equals` and `hashCode`.
  27129. *
  27130. * `equals` takes another object, presumably of similar type, and returns true
  27131. * if the it is equal. Equality is symmetrical, so the same result should be
  27132. * returned if this and the argument are flipped.
  27133. *
  27134. * assert( a.equals(b) === b.equals(a) );
  27135. *
  27136. * `hashCode` returns a 32bit integer number representing the object which will
  27137. * be used to determine how to store the value object in a Map or Set. You must
  27138. * provide both or neither methods, one must not exist without the other.
  27139. *
  27140. * Also, an important relationship between these methods must be upheld: if two
  27141. * values are equal, they *must* return the same hashCode. If the values are not
  27142. * equal, they might have the same hashCode; this is called a hash collision,
  27143. * and while undesirable for performance reasons, it is acceptable.
  27144. *
  27145. * if (a.equals(b)) {
  27146. * assert( a.hashCode() === b.hashCode() );
  27147. * }
  27148. *
  27149. * All Immutable collections implement `equals` and `hashCode`.
  27150. *
  27151. */
  27152. function is(valueA, valueB) {
  27153. if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
  27154. return true;
  27155. }
  27156. if (!valueA || !valueB) {
  27157. return false;
  27158. }
  27159. if (typeof valueA.valueOf === 'function' &&
  27160. typeof valueB.valueOf === 'function') {
  27161. valueA = valueA.valueOf();
  27162. valueB = valueB.valueOf();
  27163. if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
  27164. return true;
  27165. }
  27166. if (!valueA || !valueB) {
  27167. return false;
  27168. }
  27169. }
  27170. if (typeof valueA.equals === 'function' &&
  27171. typeof valueB.equals === 'function' &&
  27172. valueA.equals(valueB)) {
  27173. return true;
  27174. }
  27175. return false;
  27176. }
  27177. function deepEqual(a, b) {
  27178. if (a === b) {
  27179. return true;
  27180. }
  27181. if (
  27182. !isIterable(b) ||
  27183. a.size !== undefined && b.size !== undefined && a.size !== b.size ||
  27184. a.__hash !== undefined && b.__hash !== undefined && a.__hash !== b.__hash ||
  27185. isKeyed(a) !== isKeyed(b) ||
  27186. isIndexed(a) !== isIndexed(b) ||
  27187. isOrdered(a) !== isOrdered(b)
  27188. ) {
  27189. return false;
  27190. }
  27191. if (a.size === 0 && b.size === 0) {
  27192. return true;
  27193. }
  27194. var notAssociative = !isAssociative(a);
  27195. if (isOrdered(a)) {
  27196. var entries = a.entries();
  27197. return b.every(function(v, k) {
  27198. var entry = entries.next().value;
  27199. return entry && is(entry[1], v) && (notAssociative || is(entry[0], k));
  27200. }) && entries.next().done;
  27201. }
  27202. var flipped = false;
  27203. if (a.size === undefined) {
  27204. if (b.size === undefined) {
  27205. if (typeof a.cacheResult === 'function') {
  27206. a.cacheResult();
  27207. }
  27208. } else {
  27209. flipped = true;
  27210. var _ = a;
  27211. a = b;
  27212. b = _;
  27213. }
  27214. }
  27215. var allEqual = true;
  27216. var bSize = b.__iterate(function(v, k) {
  27217. if (notAssociative ? !a.has(v) :
  27218. flipped ? !is(v, a.get(k, NOT_SET)) : !is(a.get(k, NOT_SET), v)) {
  27219. allEqual = false;
  27220. return false;
  27221. }
  27222. });
  27223. return allEqual && a.size === bSize;
  27224. }
  27225. createClass(Repeat, IndexedSeq);
  27226. function Repeat(value, times) {
  27227. if (!(this instanceof Repeat)) {
  27228. return new Repeat(value, times);
  27229. }
  27230. this._value = value;
  27231. this.size = times === undefined ? Infinity : Math.max(0, times);
  27232. if (this.size === 0) {
  27233. if (EMPTY_REPEAT) {
  27234. return EMPTY_REPEAT;
  27235. }
  27236. EMPTY_REPEAT = this;
  27237. }
  27238. }
  27239. Repeat.prototype.toString = function() {
  27240. if (this.size === 0) {
  27241. return 'Repeat []';
  27242. }
  27243. return 'Repeat [ ' + this._value + ' ' + this.size + ' times ]';
  27244. };
  27245. Repeat.prototype.get = function(index, notSetValue) {
  27246. return this.has(index) ? this._value : notSetValue;
  27247. };
  27248. Repeat.prototype.includes = function(searchValue) {
  27249. return is(this._value, searchValue);
  27250. };
  27251. Repeat.prototype.slice = function(begin, end) {
  27252. var size = this.size;
  27253. return wholeSlice(begin, end, size) ? this :
  27254. new Repeat(this._value, resolveEnd(end, size) - resolveBegin(begin, size));
  27255. };
  27256. Repeat.prototype.reverse = function() {
  27257. return this;
  27258. };
  27259. Repeat.prototype.indexOf = function(searchValue) {
  27260. if (is(this._value, searchValue)) {
  27261. return 0;
  27262. }
  27263. return -1;
  27264. };
  27265. Repeat.prototype.lastIndexOf = function(searchValue) {
  27266. if (is(this._value, searchValue)) {
  27267. return this.size;
  27268. }
  27269. return -1;
  27270. };
  27271. Repeat.prototype.__iterate = function(fn, reverse) {
  27272. for (var ii = 0; ii < this.size; ii++) {
  27273. if (fn(this._value, ii, this) === false) {
  27274. return ii + 1;
  27275. }
  27276. }
  27277. return ii;
  27278. };
  27279. Repeat.prototype.__iterator = function(type, reverse) {var this$0 = this;
  27280. var ii = 0;
  27281. return new Iterator(function()
  27282. {return ii < this$0.size ? iteratorValue(type, ii++, this$0._value) : iteratorDone()}
  27283. );
  27284. };
  27285. Repeat.prototype.equals = function(other) {
  27286. return other instanceof Repeat ?
  27287. is(this._value, other._value) :
  27288. deepEqual(other);
  27289. };
  27290. var EMPTY_REPEAT;
  27291. function invariant(condition, error) {
  27292. if (!condition) throw new Error(error);
  27293. }
  27294. createClass(Range, IndexedSeq);
  27295. function Range(start, end, step) {
  27296. if (!(this instanceof Range)) {
  27297. return new Range(start, end, step);
  27298. }
  27299. invariant(step !== 0, 'Cannot step a Range by 0');
  27300. start = start || 0;
  27301. if (end === undefined) {
  27302. end = Infinity;
  27303. }
  27304. step = step === undefined ? 1 : Math.abs(step);
  27305. if (end < start) {
  27306. step = -step;
  27307. }
  27308. this._start = start;
  27309. this._end = end;
  27310. this._step = step;
  27311. this.size = Math.max(0, Math.ceil((end - start) / step - 1) + 1);
  27312. if (this.size === 0) {
  27313. if (EMPTY_RANGE) {
  27314. return EMPTY_RANGE;
  27315. }
  27316. EMPTY_RANGE = this;
  27317. }
  27318. }
  27319. Range.prototype.toString = function() {
  27320. if (this.size === 0) {
  27321. return 'Range []';
  27322. }
  27323. return 'Range [ ' +
  27324. this._start + '...' + this._end +
  27325. (this._step > 1 ? ' by ' + this._step : '') +
  27326. ' ]';
  27327. };
  27328. Range.prototype.get = function(index, notSetValue) {
  27329. return this.has(index) ?
  27330. this._start + wrapIndex(this, index) * this._step :
  27331. notSetValue;
  27332. };
  27333. Range.prototype.includes = function(searchValue) {
  27334. var possibleIndex = (searchValue - this._start) / this._step;
  27335. return possibleIndex >= 0 &&
  27336. possibleIndex < this.size &&
  27337. possibleIndex === Math.floor(possibleIndex);
  27338. };
  27339. Range.prototype.slice = function(begin, end) {
  27340. if (wholeSlice(begin, end, this.size)) {
  27341. return this;
  27342. }
  27343. begin = resolveBegin(begin, this.size);
  27344. end = resolveEnd(end, this.size);
  27345. if (end <= begin) {
  27346. return new Range(0, 0);
  27347. }
  27348. return new Range(this.get(begin, this._end), this.get(end, this._end), this._step);
  27349. };
  27350. Range.prototype.indexOf = function(searchValue) {
  27351. var offsetValue = searchValue - this._start;
  27352. if (offsetValue % this._step === 0) {
  27353. var index = offsetValue / this._step;
  27354. if (index >= 0 && index < this.size) {
  27355. return index
  27356. }
  27357. }
  27358. return -1;
  27359. };
  27360. Range.prototype.lastIndexOf = function(searchValue) {
  27361. return this.indexOf(searchValue);
  27362. };
  27363. Range.prototype.__iterate = function(fn, reverse) {
  27364. var maxIndex = this.size - 1;
  27365. var step = this._step;
  27366. var value = reverse ? this._start + maxIndex * step : this._start;
  27367. for (var ii = 0; ii <= maxIndex; ii++) {
  27368. if (fn(value, ii, this) === false) {
  27369. return ii + 1;
  27370. }
  27371. value += reverse ? -step : step;
  27372. }
  27373. return ii;
  27374. };
  27375. Range.prototype.__iterator = function(type, reverse) {
  27376. var maxIndex = this.size - 1;
  27377. var step = this._step;
  27378. var value = reverse ? this._start + maxIndex * step : this._start;
  27379. var ii = 0;
  27380. return new Iterator(function() {
  27381. var v = value;
  27382. value += reverse ? -step : step;
  27383. return ii > maxIndex ? iteratorDone() : iteratorValue(type, ii++, v);
  27384. });
  27385. };
  27386. Range.prototype.equals = function(other) {
  27387. return other instanceof Range ?
  27388. this._start === other._start &&
  27389. this._end === other._end &&
  27390. this._step === other._step :
  27391. deepEqual(this, other);
  27392. };
  27393. var EMPTY_RANGE;
  27394. createClass(Collection, Iterable);
  27395. function Collection() {
  27396. throw TypeError('Abstract');
  27397. }
  27398. createClass(KeyedCollection, Collection);function KeyedCollection() {}
  27399. createClass(IndexedCollection, Collection);function IndexedCollection() {}
  27400. createClass(SetCollection, Collection);function SetCollection() {}
  27401. Collection.Keyed = KeyedCollection;
  27402. Collection.Indexed = IndexedCollection;
  27403. Collection.Set = SetCollection;
  27404. var imul =
  27405. typeof Math.imul === 'function' && Math.imul(0xffffffff, 2) === -2 ?
  27406. Math.imul :
  27407. function imul(a, b) {
  27408. a = a | 0; // int
  27409. b = b | 0; // int
  27410. var c = a & 0xffff;
  27411. var d = b & 0xffff;
  27412. // Shift by 0 fixes the sign on the high part.
  27413. return (c * d) + ((((a >>> 16) * d + c * (b >>> 16)) << 16) >>> 0) | 0; // int
  27414. };
  27415. // v8 has an optimization for storing 31-bit signed numbers.
  27416. // Values which have either 00 or 11 as the high order bits qualify.
  27417. // This function drops the highest order bit in a signed number, maintaining
  27418. // the sign bit.
  27419. function smi(i32) {
  27420. return ((i32 >>> 1) & 0x40000000) | (i32 & 0xBFFFFFFF);
  27421. }
  27422. function hash(o) {
  27423. if (o === false || o === null || o === undefined) {
  27424. return 0;
  27425. }
  27426. if (typeof o.valueOf === 'function') {
  27427. o = o.valueOf();
  27428. if (o === false || o === null || o === undefined) {
  27429. return 0;
  27430. }
  27431. }
  27432. if (o === true) {
  27433. return 1;
  27434. }
  27435. var type = typeof o;
  27436. if (type === 'number') {
  27437. var h = o | 0;
  27438. if (h !== o) {
  27439. h ^= o * 0xFFFFFFFF;
  27440. }
  27441. while (o > 0xFFFFFFFF) {
  27442. o /= 0xFFFFFFFF;
  27443. h ^= o;
  27444. }
  27445. return smi(h);
  27446. }
  27447. if (type === 'string') {
  27448. return o.length > STRING_HASH_CACHE_MIN_STRLEN ? cachedHashString(o) : hashString(o);
  27449. }
  27450. if (typeof o.hashCode === 'function') {
  27451. return o.hashCode();
  27452. }
  27453. if (type === 'object') {
  27454. return hashJSObj(o);
  27455. }
  27456. if (typeof o.toString === 'function') {
  27457. return hashString(o.toString());
  27458. }
  27459. throw new Error('Value type ' + type + ' cannot be hashed.');
  27460. }
  27461. function cachedHashString(string) {
  27462. var hash = stringHashCache[string];
  27463. if (hash === undefined) {
  27464. hash = hashString(string);
  27465. if (STRING_HASH_CACHE_SIZE === STRING_HASH_CACHE_MAX_SIZE) {
  27466. STRING_HASH_CACHE_SIZE = 0;
  27467. stringHashCache = {};
  27468. }
  27469. STRING_HASH_CACHE_SIZE++;
  27470. stringHashCache[string] = hash;
  27471. }
  27472. return hash;
  27473. }
  27474. // http://jsperf.com/hashing-strings
  27475. function hashString(string) {
  27476. // This is the hash from JVM
  27477. // The hash code for a string is computed as
  27478. // s[0] * 31 ^ (n - 1) + s[1] * 31 ^ (n - 2) + ... + s[n - 1],
  27479. // where s[i] is the ith character of the string and n is the length of
  27480. // the string. We "mod" the result to make it between 0 (inclusive) and 2^31
  27481. // (exclusive) by dropping high bits.
  27482. var hash = 0;
  27483. for (var ii = 0; ii < string.length; ii++) {
  27484. hash = 31 * hash + string.charCodeAt(ii) | 0;
  27485. }
  27486. return smi(hash);
  27487. }
  27488. function hashJSObj(obj) {
  27489. var hash;
  27490. if (usingWeakMap) {
  27491. hash = weakMap.get(obj);
  27492. if (hash !== undefined) {
  27493. return hash;
  27494. }
  27495. }
  27496. hash = obj[UID_HASH_KEY];
  27497. if (hash !== undefined) {
  27498. return hash;
  27499. }
  27500. if (!canDefineProperty) {
  27501. hash = obj.propertyIsEnumerable && obj.propertyIsEnumerable[UID_HASH_KEY];
  27502. if (hash !== undefined) {
  27503. return hash;
  27504. }
  27505. hash = getIENodeHash(obj);
  27506. if (hash !== undefined) {
  27507. return hash;
  27508. }
  27509. }
  27510. hash = ++objHashUID;
  27511. if (objHashUID & 0x40000000) {
  27512. objHashUID = 0;
  27513. }
  27514. if (usingWeakMap) {
  27515. weakMap.set(obj, hash);
  27516. } else if (isExtensible !== undefined && isExtensible(obj) === false) {
  27517. throw new Error('Non-extensible objects are not allowed as keys.');
  27518. } else if (canDefineProperty) {
  27519. Object.defineProperty(obj, UID_HASH_KEY, {
  27520. 'enumerable': false,
  27521. 'configurable': false,
  27522. 'writable': false,
  27523. 'value': hash
  27524. });
  27525. } else if (obj.propertyIsEnumerable !== undefined &&
  27526. obj.propertyIsEnumerable === obj.constructor.prototype.propertyIsEnumerable) {
  27527. // Since we can't define a non-enumerable property on the object
  27528. // we'll hijack one of the less-used non-enumerable properties to
  27529. // save our hash on it. Since this is a function it will not show up in
  27530. // `JSON.stringify` which is what we want.
  27531. obj.propertyIsEnumerable = function() {
  27532. return this.constructor.prototype.propertyIsEnumerable.apply(this, arguments);
  27533. };
  27534. obj.propertyIsEnumerable[UID_HASH_KEY] = hash;
  27535. } else if (obj.nodeType !== undefined) {
  27536. // At this point we couldn't get the IE `uniqueID` to use as a hash
  27537. // and we couldn't use a non-enumerable property to exploit the
  27538. // dontEnum bug so we simply add the `UID_HASH_KEY` on the node
  27539. // itself.
  27540. obj[UID_HASH_KEY] = hash;
  27541. } else {
  27542. throw new Error('Unable to set a non-enumerable property on object.');
  27543. }
  27544. return hash;
  27545. }
  27546. // Get references to ES5 object methods.
  27547. var isExtensible = Object.isExtensible;
  27548. // True if Object.defineProperty works as expected. IE8 fails this test.
  27549. var canDefineProperty = (function() {
  27550. try {
  27551. Object.defineProperty({}, '@', {});
  27552. return true;
  27553. } catch (e) {
  27554. return false;
  27555. }
  27556. }());
  27557. // IE has a `uniqueID` property on DOM nodes. We can construct the hash from it
  27558. // and avoid memory leaks from the IE cloneNode bug.
  27559. function getIENodeHash(node) {
  27560. if (node && node.nodeType > 0) {
  27561. switch (node.nodeType) {
  27562. case 1: // Element
  27563. return node.uniqueID;
  27564. case 9: // Document
  27565. return node.documentElement && node.documentElement.uniqueID;
  27566. }
  27567. }
  27568. }
  27569. // If possible, use a WeakMap.
  27570. var usingWeakMap = typeof WeakMap === 'function';
  27571. var weakMap;
  27572. if (usingWeakMap) {
  27573. weakMap = new WeakMap();
  27574. }
  27575. var objHashUID = 0;
  27576. var UID_HASH_KEY = '__immutablehash__';
  27577. if (typeof Symbol === 'function') {
  27578. UID_HASH_KEY = Symbol(UID_HASH_KEY);
  27579. }
  27580. var STRING_HASH_CACHE_MIN_STRLEN = 16;
  27581. var STRING_HASH_CACHE_MAX_SIZE = 255;
  27582. var STRING_HASH_CACHE_SIZE = 0;
  27583. var stringHashCache = {};
  27584. function assertNotInfinite(size) {
  27585. invariant(
  27586. size !== Infinity,
  27587. 'Cannot perform this action with an infinite size.'
  27588. );
  27589. }
  27590. createClass(Map, KeyedCollection);
  27591. // @pragma Construction
  27592. function Map(value) {
  27593. return value === null || value === undefined ? emptyMap() :
  27594. isMap(value) && !isOrdered(value) ? value :
  27595. emptyMap().withMutations(function(map ) {
  27596. var iter = KeyedIterable(value);
  27597. assertNotInfinite(iter.size);
  27598. iter.forEach(function(v, k) {return map.set(k, v)});
  27599. });
  27600. }
  27601. Map.prototype.toString = function() {
  27602. return this.__toString('Map {', '}');
  27603. };
  27604. // @pragma Access
  27605. Map.prototype.get = function(k, notSetValue) {
  27606. return this._root ?
  27607. this._root.get(0, undefined, k, notSetValue) :
  27608. notSetValue;
  27609. };
  27610. // @pragma Modification
  27611. Map.prototype.set = function(k, v) {
  27612. return updateMap(this, k, v);
  27613. };
  27614. Map.prototype.setIn = function(keyPath, v) {
  27615. return this.updateIn(keyPath, NOT_SET, function() {return v});
  27616. };
  27617. Map.prototype.remove = function(k) {
  27618. return updateMap(this, k, NOT_SET);
  27619. };
  27620. Map.prototype.deleteIn = function(keyPath) {
  27621. return this.updateIn(keyPath, function() {return NOT_SET});
  27622. };
  27623. Map.prototype.update = function(k, notSetValue, updater) {
  27624. return arguments.length === 1 ?
  27625. k(this) :
  27626. this.updateIn([k], notSetValue, updater);
  27627. };
  27628. Map.prototype.updateIn = function(keyPath, notSetValue, updater) {
  27629. if (!updater) {
  27630. updater = notSetValue;
  27631. notSetValue = undefined;
  27632. }
  27633. var updatedValue = updateInDeepMap(
  27634. this,
  27635. forceIterator(keyPath),
  27636. notSetValue,
  27637. updater
  27638. );
  27639. return updatedValue === NOT_SET ? undefined : updatedValue;
  27640. };
  27641. Map.prototype.clear = function() {
  27642. if (this.size === 0) {
  27643. return this;
  27644. }
  27645. if (this.__ownerID) {
  27646. this.size = 0;
  27647. this._root = null;
  27648. this.__hash = undefined;
  27649. this.__altered = true;
  27650. return this;
  27651. }
  27652. return emptyMap();
  27653. };
  27654. // @pragma Composition
  27655. Map.prototype.merge = function(/*...iters*/) {
  27656. return mergeIntoMapWith(this, undefined, arguments);
  27657. };
  27658. Map.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  27659. return mergeIntoMapWith(this, merger, iters);
  27660. };
  27661. Map.prototype.mergeIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1);
  27662. return this.updateIn(
  27663. keyPath,
  27664. emptyMap(),
  27665. function(m ) {return typeof m.merge === 'function' ?
  27666. m.merge.apply(m, iters) :
  27667. iters[iters.length - 1]}
  27668. );
  27669. };
  27670. Map.prototype.mergeDeep = function(/*...iters*/) {
  27671. return mergeIntoMapWith(this, deepMerger, arguments);
  27672. };
  27673. Map.prototype.mergeDeepWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  27674. return mergeIntoMapWith(this, deepMergerWith(merger), iters);
  27675. };
  27676. Map.prototype.mergeDeepIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1);
  27677. return this.updateIn(
  27678. keyPath,
  27679. emptyMap(),
  27680. function(m ) {return typeof m.mergeDeep === 'function' ?
  27681. m.mergeDeep.apply(m, iters) :
  27682. iters[iters.length - 1]}
  27683. );
  27684. };
  27685. Map.prototype.sort = function(comparator) {
  27686. // Late binding
  27687. return OrderedMap(sortFactory(this, comparator));
  27688. };
  27689. Map.prototype.sortBy = function(mapper, comparator) {
  27690. // Late binding
  27691. return OrderedMap(sortFactory(this, comparator, mapper));
  27692. };
  27693. // @pragma Mutability
  27694. Map.prototype.withMutations = function(fn) {
  27695. var mutable = this.asMutable();
  27696. fn(mutable);
  27697. return mutable.wasAltered() ? mutable.__ensureOwner(this.__ownerID) : this;
  27698. };
  27699. Map.prototype.asMutable = function() {
  27700. return this.__ownerID ? this : this.__ensureOwner(new OwnerID());
  27701. };
  27702. Map.prototype.asImmutable = function() {
  27703. return this.__ensureOwner();
  27704. };
  27705. Map.prototype.wasAltered = function() {
  27706. return this.__altered;
  27707. };
  27708. Map.prototype.__iterator = function(type, reverse) {
  27709. return new MapIterator(this, type, reverse);
  27710. };
  27711. Map.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  27712. var iterations = 0;
  27713. this._root && this._root.iterate(function(entry ) {
  27714. iterations++;
  27715. return fn(entry[1], entry[0], this$0);
  27716. }, reverse);
  27717. return iterations;
  27718. };
  27719. Map.prototype.__ensureOwner = function(ownerID) {
  27720. if (ownerID === this.__ownerID) {
  27721. return this;
  27722. }
  27723. if (!ownerID) {
  27724. this.__ownerID = ownerID;
  27725. this.__altered = false;
  27726. return this;
  27727. }
  27728. return makeMap(this.size, this._root, ownerID, this.__hash);
  27729. };
  27730. function isMap(maybeMap) {
  27731. return !!(maybeMap && maybeMap[IS_MAP_SENTINEL]);
  27732. }
  27733. Map.isMap = isMap;
  27734. var IS_MAP_SENTINEL = '@@__IMMUTABLE_MAP__@@';
  27735. var MapPrototype = Map.prototype;
  27736. MapPrototype[IS_MAP_SENTINEL] = true;
  27737. MapPrototype[DELETE] = MapPrototype.remove;
  27738. MapPrototype.removeIn = MapPrototype.deleteIn;
  27739. // #pragma Trie Nodes
  27740. function ArrayMapNode(ownerID, entries) {
  27741. this.ownerID = ownerID;
  27742. this.entries = entries;
  27743. }
  27744. ArrayMapNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  27745. var entries = this.entries;
  27746. for (var ii = 0, len = entries.length; ii < len; ii++) {
  27747. if (is(key, entries[ii][0])) {
  27748. return entries[ii][1];
  27749. }
  27750. }
  27751. return notSetValue;
  27752. };
  27753. ArrayMapNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  27754. var removed = value === NOT_SET;
  27755. var entries = this.entries;
  27756. var idx = 0;
  27757. for (var len = entries.length; idx < len; idx++) {
  27758. if (is(key, entries[idx][0])) {
  27759. break;
  27760. }
  27761. }
  27762. var exists = idx < len;
  27763. if (exists ? entries[idx][1] === value : removed) {
  27764. return this;
  27765. }
  27766. SetRef(didAlter);
  27767. (removed || !exists) && SetRef(didChangeSize);
  27768. if (removed && entries.length === 1) {
  27769. return; // undefined
  27770. }
  27771. if (!exists && !removed && entries.length >= MAX_ARRAY_MAP_SIZE) {
  27772. return createNodes(ownerID, entries, key, value);
  27773. }
  27774. var isEditable = ownerID && ownerID === this.ownerID;
  27775. var newEntries = isEditable ? entries : arrCopy(entries);
  27776. if (exists) {
  27777. if (removed) {
  27778. idx === len - 1 ? newEntries.pop() : (newEntries[idx] = newEntries.pop());
  27779. } else {
  27780. newEntries[idx] = [key, value];
  27781. }
  27782. } else {
  27783. newEntries.push([key, value]);
  27784. }
  27785. if (isEditable) {
  27786. this.entries = newEntries;
  27787. return this;
  27788. }
  27789. return new ArrayMapNode(ownerID, newEntries);
  27790. };
  27791. function BitmapIndexedNode(ownerID, bitmap, nodes) {
  27792. this.ownerID = ownerID;
  27793. this.bitmap = bitmap;
  27794. this.nodes = nodes;
  27795. }
  27796. BitmapIndexedNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  27797. if (keyHash === undefined) {
  27798. keyHash = hash(key);
  27799. }
  27800. var bit = (1 << ((shift === 0 ? keyHash : keyHash >>> shift) & MASK));
  27801. var bitmap = this.bitmap;
  27802. return (bitmap & bit) === 0 ? notSetValue :
  27803. this.nodes[popCount(bitmap & (bit - 1))].get(shift + SHIFT, keyHash, key, notSetValue);
  27804. };
  27805. BitmapIndexedNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  27806. if (keyHash === undefined) {
  27807. keyHash = hash(key);
  27808. }
  27809. var keyHashFrag = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  27810. var bit = 1 << keyHashFrag;
  27811. var bitmap = this.bitmap;
  27812. var exists = (bitmap & bit) !== 0;
  27813. if (!exists && value === NOT_SET) {
  27814. return this;
  27815. }
  27816. var idx = popCount(bitmap & (bit - 1));
  27817. var nodes = this.nodes;
  27818. var node = exists ? nodes[idx] : undefined;
  27819. var newNode = updateNode(node, ownerID, shift + SHIFT, keyHash, key, value, didChangeSize, didAlter);
  27820. if (newNode === node) {
  27821. return this;
  27822. }
  27823. if (!exists && newNode && nodes.length >= MAX_BITMAP_INDEXED_SIZE) {
  27824. return expandNodes(ownerID, nodes, bitmap, keyHashFrag, newNode);
  27825. }
  27826. if (exists && !newNode && nodes.length === 2 && isLeafNode(nodes[idx ^ 1])) {
  27827. return nodes[idx ^ 1];
  27828. }
  27829. if (exists && newNode && nodes.length === 1 && isLeafNode(newNode)) {
  27830. return newNode;
  27831. }
  27832. var isEditable = ownerID && ownerID === this.ownerID;
  27833. var newBitmap = exists ? newNode ? bitmap : bitmap ^ bit : bitmap | bit;
  27834. var newNodes = exists ? newNode ?
  27835. setIn(nodes, idx, newNode, isEditable) :
  27836. spliceOut(nodes, idx, isEditable) :
  27837. spliceIn(nodes, idx, newNode, isEditable);
  27838. if (isEditable) {
  27839. this.bitmap = newBitmap;
  27840. this.nodes = newNodes;
  27841. return this;
  27842. }
  27843. return new BitmapIndexedNode(ownerID, newBitmap, newNodes);
  27844. };
  27845. function HashArrayMapNode(ownerID, count, nodes) {
  27846. this.ownerID = ownerID;
  27847. this.count = count;
  27848. this.nodes = nodes;
  27849. }
  27850. HashArrayMapNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  27851. if (keyHash === undefined) {
  27852. keyHash = hash(key);
  27853. }
  27854. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  27855. var node = this.nodes[idx];
  27856. return node ? node.get(shift + SHIFT, keyHash, key, notSetValue) : notSetValue;
  27857. };
  27858. HashArrayMapNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  27859. if (keyHash === undefined) {
  27860. keyHash = hash(key);
  27861. }
  27862. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  27863. var removed = value === NOT_SET;
  27864. var nodes = this.nodes;
  27865. var node = nodes[idx];
  27866. if (removed && !node) {
  27867. return this;
  27868. }
  27869. var newNode = updateNode(node, ownerID, shift + SHIFT, keyHash, key, value, didChangeSize, didAlter);
  27870. if (newNode === node) {
  27871. return this;
  27872. }
  27873. var newCount = this.count;
  27874. if (!node) {
  27875. newCount++;
  27876. } else if (!newNode) {
  27877. newCount--;
  27878. if (newCount < MIN_HASH_ARRAY_MAP_SIZE) {
  27879. return packNodes(ownerID, nodes, newCount, idx);
  27880. }
  27881. }
  27882. var isEditable = ownerID && ownerID === this.ownerID;
  27883. var newNodes = setIn(nodes, idx, newNode, isEditable);
  27884. if (isEditable) {
  27885. this.count = newCount;
  27886. this.nodes = newNodes;
  27887. return this;
  27888. }
  27889. return new HashArrayMapNode(ownerID, newCount, newNodes);
  27890. };
  27891. function HashCollisionNode(ownerID, keyHash, entries) {
  27892. this.ownerID = ownerID;
  27893. this.keyHash = keyHash;
  27894. this.entries = entries;
  27895. }
  27896. HashCollisionNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  27897. var entries = this.entries;
  27898. for (var ii = 0, len = entries.length; ii < len; ii++) {
  27899. if (is(key, entries[ii][0])) {
  27900. return entries[ii][1];
  27901. }
  27902. }
  27903. return notSetValue;
  27904. };
  27905. HashCollisionNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  27906. if (keyHash === undefined) {
  27907. keyHash = hash(key);
  27908. }
  27909. var removed = value === NOT_SET;
  27910. if (keyHash !== this.keyHash) {
  27911. if (removed) {
  27912. return this;
  27913. }
  27914. SetRef(didAlter);
  27915. SetRef(didChangeSize);
  27916. return mergeIntoNode(this, ownerID, shift, keyHash, [key, value]);
  27917. }
  27918. var entries = this.entries;
  27919. var idx = 0;
  27920. for (var len = entries.length; idx < len; idx++) {
  27921. if (is(key, entries[idx][0])) {
  27922. break;
  27923. }
  27924. }
  27925. var exists = idx < len;
  27926. if (exists ? entries[idx][1] === value : removed) {
  27927. return this;
  27928. }
  27929. SetRef(didAlter);
  27930. (removed || !exists) && SetRef(didChangeSize);
  27931. if (removed && len === 2) {
  27932. return new ValueNode(ownerID, this.keyHash, entries[idx ^ 1]);
  27933. }
  27934. var isEditable = ownerID && ownerID === this.ownerID;
  27935. var newEntries = isEditable ? entries : arrCopy(entries);
  27936. if (exists) {
  27937. if (removed) {
  27938. idx === len - 1 ? newEntries.pop() : (newEntries[idx] = newEntries.pop());
  27939. } else {
  27940. newEntries[idx] = [key, value];
  27941. }
  27942. } else {
  27943. newEntries.push([key, value]);
  27944. }
  27945. if (isEditable) {
  27946. this.entries = newEntries;
  27947. return this;
  27948. }
  27949. return new HashCollisionNode(ownerID, this.keyHash, newEntries);
  27950. };
  27951. function ValueNode(ownerID, keyHash, entry) {
  27952. this.ownerID = ownerID;
  27953. this.keyHash = keyHash;
  27954. this.entry = entry;
  27955. }
  27956. ValueNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  27957. return is(key, this.entry[0]) ? this.entry[1] : notSetValue;
  27958. };
  27959. ValueNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  27960. var removed = value === NOT_SET;
  27961. var keyMatch = is(key, this.entry[0]);
  27962. if (keyMatch ? value === this.entry[1] : removed) {
  27963. return this;
  27964. }
  27965. SetRef(didAlter);
  27966. if (removed) {
  27967. SetRef(didChangeSize);
  27968. return; // undefined
  27969. }
  27970. if (keyMatch) {
  27971. if (ownerID && ownerID === this.ownerID) {
  27972. this.entry[1] = value;
  27973. return this;
  27974. }
  27975. return new ValueNode(ownerID, this.keyHash, [key, value]);
  27976. }
  27977. SetRef(didChangeSize);
  27978. return mergeIntoNode(this, ownerID, shift, hash(key), [key, value]);
  27979. };
  27980. // #pragma Iterators
  27981. ArrayMapNode.prototype.iterate =
  27982. HashCollisionNode.prototype.iterate = function (fn, reverse) {
  27983. var entries = this.entries;
  27984. for (var ii = 0, maxIndex = entries.length - 1; ii <= maxIndex; ii++) {
  27985. if (fn(entries[reverse ? maxIndex - ii : ii]) === false) {
  27986. return false;
  27987. }
  27988. }
  27989. };
  27990. BitmapIndexedNode.prototype.iterate =
  27991. HashArrayMapNode.prototype.iterate = function (fn, reverse) {
  27992. var nodes = this.nodes;
  27993. for (var ii = 0, maxIndex = nodes.length - 1; ii <= maxIndex; ii++) {
  27994. var node = nodes[reverse ? maxIndex - ii : ii];
  27995. if (node && node.iterate(fn, reverse) === false) {
  27996. return false;
  27997. }
  27998. }
  27999. };
  28000. ValueNode.prototype.iterate = function (fn, reverse) {
  28001. return fn(this.entry);
  28002. };
  28003. createClass(MapIterator, Iterator);
  28004. function MapIterator(map, type, reverse) {
  28005. this._type = type;
  28006. this._reverse = reverse;
  28007. this._stack = map._root && mapIteratorFrame(map._root);
  28008. }
  28009. MapIterator.prototype.next = function() {
  28010. var type = this._type;
  28011. var stack = this._stack;
  28012. while (stack) {
  28013. var node = stack.node;
  28014. var index = stack.index++;
  28015. var maxIndex;
  28016. if (node.entry) {
  28017. if (index === 0) {
  28018. return mapIteratorValue(type, node.entry);
  28019. }
  28020. } else if (node.entries) {
  28021. maxIndex = node.entries.length - 1;
  28022. if (index <= maxIndex) {
  28023. return mapIteratorValue(type, node.entries[this._reverse ? maxIndex - index : index]);
  28024. }
  28025. } else {
  28026. maxIndex = node.nodes.length - 1;
  28027. if (index <= maxIndex) {
  28028. var subNode = node.nodes[this._reverse ? maxIndex - index : index];
  28029. if (subNode) {
  28030. if (subNode.entry) {
  28031. return mapIteratorValue(type, subNode.entry);
  28032. }
  28033. stack = this._stack = mapIteratorFrame(subNode, stack);
  28034. }
  28035. continue;
  28036. }
  28037. }
  28038. stack = this._stack = this._stack.__prev;
  28039. }
  28040. return iteratorDone();
  28041. };
  28042. function mapIteratorValue(type, entry) {
  28043. return iteratorValue(type, entry[0], entry[1]);
  28044. }
  28045. function mapIteratorFrame(node, prev) {
  28046. return {
  28047. node: node,
  28048. index: 0,
  28049. __prev: prev
  28050. };
  28051. }
  28052. function makeMap(size, root, ownerID, hash) {
  28053. var map = Object.create(MapPrototype);
  28054. map.size = size;
  28055. map._root = root;
  28056. map.__ownerID = ownerID;
  28057. map.__hash = hash;
  28058. map.__altered = false;
  28059. return map;
  28060. }
  28061. var EMPTY_MAP;
  28062. function emptyMap() {
  28063. return EMPTY_MAP || (EMPTY_MAP = makeMap(0));
  28064. }
  28065. function updateMap(map, k, v) {
  28066. var newRoot;
  28067. var newSize;
  28068. if (!map._root) {
  28069. if (v === NOT_SET) {
  28070. return map;
  28071. }
  28072. newSize = 1;
  28073. newRoot = new ArrayMapNode(map.__ownerID, [[k, v]]);
  28074. } else {
  28075. var didChangeSize = MakeRef(CHANGE_LENGTH);
  28076. var didAlter = MakeRef(DID_ALTER);
  28077. newRoot = updateNode(map._root, map.__ownerID, 0, undefined, k, v, didChangeSize, didAlter);
  28078. if (!didAlter.value) {
  28079. return map;
  28080. }
  28081. newSize = map.size + (didChangeSize.value ? v === NOT_SET ? -1 : 1 : 0);
  28082. }
  28083. if (map.__ownerID) {
  28084. map.size = newSize;
  28085. map._root = newRoot;
  28086. map.__hash = undefined;
  28087. map.__altered = true;
  28088. return map;
  28089. }
  28090. return newRoot ? makeMap(newSize, newRoot) : emptyMap();
  28091. }
  28092. function updateNode(node, ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  28093. if (!node) {
  28094. if (value === NOT_SET) {
  28095. return node;
  28096. }
  28097. SetRef(didAlter);
  28098. SetRef(didChangeSize);
  28099. return new ValueNode(ownerID, keyHash, [key, value]);
  28100. }
  28101. return node.update(ownerID, shift, keyHash, key, value, didChangeSize, didAlter);
  28102. }
  28103. function isLeafNode(node) {
  28104. return node.constructor === ValueNode || node.constructor === HashCollisionNode;
  28105. }
  28106. function mergeIntoNode(node, ownerID, shift, keyHash, entry) {
  28107. if (node.keyHash === keyHash) {
  28108. return new HashCollisionNode(ownerID, keyHash, [node.entry, entry]);
  28109. }
  28110. var idx1 = (shift === 0 ? node.keyHash : node.keyHash >>> shift) & MASK;
  28111. var idx2 = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  28112. var newNode;
  28113. var nodes = idx1 === idx2 ?
  28114. [mergeIntoNode(node, ownerID, shift + SHIFT, keyHash, entry)] :
  28115. ((newNode = new ValueNode(ownerID, keyHash, entry)), idx1 < idx2 ? [node, newNode] : [newNode, node]);
  28116. return new BitmapIndexedNode(ownerID, (1 << idx1) | (1 << idx2), nodes);
  28117. }
  28118. function createNodes(ownerID, entries, key, value) {
  28119. if (!ownerID) {
  28120. ownerID = new OwnerID();
  28121. }
  28122. var node = new ValueNode(ownerID, hash(key), [key, value]);
  28123. for (var ii = 0; ii < entries.length; ii++) {
  28124. var entry = entries[ii];
  28125. node = node.update(ownerID, 0, undefined, entry[0], entry[1]);
  28126. }
  28127. return node;
  28128. }
  28129. function packNodes(ownerID, nodes, count, excluding) {
  28130. var bitmap = 0;
  28131. var packedII = 0;
  28132. var packedNodes = new Array(count);
  28133. for (var ii = 0, bit = 1, len = nodes.length; ii < len; ii++, bit <<= 1) {
  28134. var node = nodes[ii];
  28135. if (node !== undefined && ii !== excluding) {
  28136. bitmap |= bit;
  28137. packedNodes[packedII++] = node;
  28138. }
  28139. }
  28140. return new BitmapIndexedNode(ownerID, bitmap, packedNodes);
  28141. }
  28142. function expandNodes(ownerID, nodes, bitmap, including, node) {
  28143. var count = 0;
  28144. var expandedNodes = new Array(SIZE);
  28145. for (var ii = 0; bitmap !== 0; ii++, bitmap >>>= 1) {
  28146. expandedNodes[ii] = bitmap & 1 ? nodes[count++] : undefined;
  28147. }
  28148. expandedNodes[including] = node;
  28149. return new HashArrayMapNode(ownerID, count + 1, expandedNodes);
  28150. }
  28151. function mergeIntoMapWith(map, merger, iterables) {
  28152. var iters = [];
  28153. for (var ii = 0; ii < iterables.length; ii++) {
  28154. var value = iterables[ii];
  28155. var iter = KeyedIterable(value);
  28156. if (!isIterable(value)) {
  28157. iter = iter.map(function(v ) {return fromJS(v)});
  28158. }
  28159. iters.push(iter);
  28160. }
  28161. return mergeIntoCollectionWith(map, merger, iters);
  28162. }
  28163. function deepMerger(existing, value, key) {
  28164. return existing && existing.mergeDeep && isIterable(value) ?
  28165. existing.mergeDeep(value) :
  28166. is(existing, value) ? existing : value;
  28167. }
  28168. function deepMergerWith(merger) {
  28169. return function(existing, value, key) {
  28170. if (existing && existing.mergeDeepWith && isIterable(value)) {
  28171. return existing.mergeDeepWith(merger, value);
  28172. }
  28173. var nextValue = merger(existing, value, key);
  28174. return is(existing, nextValue) ? existing : nextValue;
  28175. };
  28176. }
  28177. function mergeIntoCollectionWith(collection, merger, iters) {
  28178. iters = iters.filter(function(x ) {return x.size !== 0});
  28179. if (iters.length === 0) {
  28180. return collection;
  28181. }
  28182. if (collection.size === 0 && !collection.__ownerID && iters.length === 1) {
  28183. return collection.constructor(iters[0]);
  28184. }
  28185. return collection.withMutations(function(collection ) {
  28186. var mergeIntoMap = merger ?
  28187. function(value, key) {
  28188. collection.update(key, NOT_SET, function(existing )
  28189. {return existing === NOT_SET ? value : merger(existing, value, key)}
  28190. );
  28191. } :
  28192. function(value, key) {
  28193. collection.set(key, value);
  28194. };
  28195. for (var ii = 0; ii < iters.length; ii++) {
  28196. iters[ii].forEach(mergeIntoMap);
  28197. }
  28198. });
  28199. }
  28200. function updateInDeepMap(existing, keyPathIter, notSetValue, updater) {
  28201. var isNotSet = existing === NOT_SET;
  28202. var step = keyPathIter.next();
  28203. if (step.done) {
  28204. var existingValue = isNotSet ? notSetValue : existing;
  28205. var newValue = updater(existingValue);
  28206. return newValue === existingValue ? existing : newValue;
  28207. }
  28208. invariant(
  28209. isNotSet || (existing && existing.set),
  28210. 'invalid keyPath'
  28211. );
  28212. var key = step.value;
  28213. var nextExisting = isNotSet ? NOT_SET : existing.get(key, NOT_SET);
  28214. var nextUpdated = updateInDeepMap(
  28215. nextExisting,
  28216. keyPathIter,
  28217. notSetValue,
  28218. updater
  28219. );
  28220. return nextUpdated === nextExisting ? existing :
  28221. nextUpdated === NOT_SET ? existing.remove(key) :
  28222. (isNotSet ? emptyMap() : existing).set(key, nextUpdated);
  28223. }
  28224. function popCount(x) {
  28225. x = x - ((x >> 1) & 0x55555555);
  28226. x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
  28227. x = (x + (x >> 4)) & 0x0f0f0f0f;
  28228. x = x + (x >> 8);
  28229. x = x + (x >> 16);
  28230. return x & 0x7f;
  28231. }
  28232. function setIn(array, idx, val, canEdit) {
  28233. var newArray = canEdit ? array : arrCopy(array);
  28234. newArray[idx] = val;
  28235. return newArray;
  28236. }
  28237. function spliceIn(array, idx, val, canEdit) {
  28238. var newLen = array.length + 1;
  28239. if (canEdit && idx + 1 === newLen) {
  28240. array[idx] = val;
  28241. return array;
  28242. }
  28243. var newArray = new Array(newLen);
  28244. var after = 0;
  28245. for (var ii = 0; ii < newLen; ii++) {
  28246. if (ii === idx) {
  28247. newArray[ii] = val;
  28248. after = -1;
  28249. } else {
  28250. newArray[ii] = array[ii + after];
  28251. }
  28252. }
  28253. return newArray;
  28254. }
  28255. function spliceOut(array, idx, canEdit) {
  28256. var newLen = array.length - 1;
  28257. if (canEdit && idx === newLen) {
  28258. array.pop();
  28259. return array;
  28260. }
  28261. var newArray = new Array(newLen);
  28262. var after = 0;
  28263. for (var ii = 0; ii < newLen; ii++) {
  28264. if (ii === idx) {
  28265. after = 1;
  28266. }
  28267. newArray[ii] = array[ii + after];
  28268. }
  28269. return newArray;
  28270. }
  28271. var MAX_ARRAY_MAP_SIZE = SIZE / 4;
  28272. var MAX_BITMAP_INDEXED_SIZE = SIZE / 2;
  28273. var MIN_HASH_ARRAY_MAP_SIZE = SIZE / 4;
  28274. createClass(List, IndexedCollection);
  28275. // @pragma Construction
  28276. function List(value) {
  28277. var empty = emptyList();
  28278. if (value === null || value === undefined) {
  28279. return empty;
  28280. }
  28281. if (isList(value)) {
  28282. return value;
  28283. }
  28284. var iter = IndexedIterable(value);
  28285. var size = iter.size;
  28286. if (size === 0) {
  28287. return empty;
  28288. }
  28289. assertNotInfinite(size);
  28290. if (size > 0 && size < SIZE) {
  28291. return makeList(0, size, SHIFT, null, new VNode(iter.toArray()));
  28292. }
  28293. return empty.withMutations(function(list ) {
  28294. list.setSize(size);
  28295. iter.forEach(function(v, i) {return list.set(i, v)});
  28296. });
  28297. }
  28298. List.of = function(/*...values*/) {
  28299. return this(arguments);
  28300. };
  28301. List.prototype.toString = function() {
  28302. return this.__toString('List [', ']');
  28303. };
  28304. // @pragma Access
  28305. List.prototype.get = function(index, notSetValue) {
  28306. index = wrapIndex(this, index);
  28307. if (index >= 0 && index < this.size) {
  28308. index += this._origin;
  28309. var node = listNodeFor(this, index);
  28310. return node && node.array[index & MASK];
  28311. }
  28312. return notSetValue;
  28313. };
  28314. // @pragma Modification
  28315. List.prototype.set = function(index, value) {
  28316. return updateList(this, index, value);
  28317. };
  28318. List.prototype.remove = function(index) {
  28319. return !this.has(index) ? this :
  28320. index === 0 ? this.shift() :
  28321. index === this.size - 1 ? this.pop() :
  28322. this.splice(index, 1);
  28323. };
  28324. List.prototype.insert = function(index, value) {
  28325. return this.splice(index, 0, value);
  28326. };
  28327. List.prototype.clear = function() {
  28328. if (this.size === 0) {
  28329. return this;
  28330. }
  28331. if (this.__ownerID) {
  28332. this.size = this._origin = this._capacity = 0;
  28333. this._level = SHIFT;
  28334. this._root = this._tail = null;
  28335. this.__hash = undefined;
  28336. this.__altered = true;
  28337. return this;
  28338. }
  28339. return emptyList();
  28340. };
  28341. List.prototype.push = function(/*...values*/) {
  28342. var values = arguments;
  28343. var oldSize = this.size;
  28344. return this.withMutations(function(list ) {
  28345. setListBounds(list, 0, oldSize + values.length);
  28346. for (var ii = 0; ii < values.length; ii++) {
  28347. list.set(oldSize + ii, values[ii]);
  28348. }
  28349. });
  28350. };
  28351. List.prototype.pop = function() {
  28352. return setListBounds(this, 0, -1);
  28353. };
  28354. List.prototype.unshift = function(/*...values*/) {
  28355. var values = arguments;
  28356. return this.withMutations(function(list ) {
  28357. setListBounds(list, -values.length);
  28358. for (var ii = 0; ii < values.length; ii++) {
  28359. list.set(ii, values[ii]);
  28360. }
  28361. });
  28362. };
  28363. List.prototype.shift = function() {
  28364. return setListBounds(this, 1);
  28365. };
  28366. // @pragma Composition
  28367. List.prototype.merge = function(/*...iters*/) {
  28368. return mergeIntoListWith(this, undefined, arguments);
  28369. };
  28370. List.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  28371. return mergeIntoListWith(this, merger, iters);
  28372. };
  28373. List.prototype.mergeDeep = function(/*...iters*/) {
  28374. return mergeIntoListWith(this, deepMerger, arguments);
  28375. };
  28376. List.prototype.mergeDeepWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  28377. return mergeIntoListWith(this, deepMergerWith(merger), iters);
  28378. };
  28379. List.prototype.setSize = function(size) {
  28380. return setListBounds(this, 0, size);
  28381. };
  28382. // @pragma Iteration
  28383. List.prototype.slice = function(begin, end) {
  28384. var size = this.size;
  28385. if (wholeSlice(begin, end, size)) {
  28386. return this;
  28387. }
  28388. return setListBounds(
  28389. this,
  28390. resolveBegin(begin, size),
  28391. resolveEnd(end, size)
  28392. );
  28393. };
  28394. List.prototype.__iterator = function(type, reverse) {
  28395. var index = 0;
  28396. var values = iterateList(this, reverse);
  28397. return new Iterator(function() {
  28398. var value = values();
  28399. return value === DONE ?
  28400. iteratorDone() :
  28401. iteratorValue(type, index++, value);
  28402. });
  28403. };
  28404. List.prototype.__iterate = function(fn, reverse) {
  28405. var index = 0;
  28406. var values = iterateList(this, reverse);
  28407. var value;
  28408. while ((value = values()) !== DONE) {
  28409. if (fn(value, index++, this) === false) {
  28410. break;
  28411. }
  28412. }
  28413. return index;
  28414. };
  28415. List.prototype.__ensureOwner = function(ownerID) {
  28416. if (ownerID === this.__ownerID) {
  28417. return this;
  28418. }
  28419. if (!ownerID) {
  28420. this.__ownerID = ownerID;
  28421. return this;
  28422. }
  28423. return makeList(this._origin, this._capacity, this._level, this._root, this._tail, ownerID, this.__hash);
  28424. };
  28425. function isList(maybeList) {
  28426. return !!(maybeList && maybeList[IS_LIST_SENTINEL]);
  28427. }
  28428. List.isList = isList;
  28429. var IS_LIST_SENTINEL = '@@__IMMUTABLE_LIST__@@';
  28430. var ListPrototype = List.prototype;
  28431. ListPrototype[IS_LIST_SENTINEL] = true;
  28432. ListPrototype[DELETE] = ListPrototype.remove;
  28433. ListPrototype.setIn = MapPrototype.setIn;
  28434. ListPrototype.deleteIn =
  28435. ListPrototype.removeIn = MapPrototype.removeIn;
  28436. ListPrototype.update = MapPrototype.update;
  28437. ListPrototype.updateIn = MapPrototype.updateIn;
  28438. ListPrototype.mergeIn = MapPrototype.mergeIn;
  28439. ListPrototype.mergeDeepIn = MapPrototype.mergeDeepIn;
  28440. ListPrototype.withMutations = MapPrototype.withMutations;
  28441. ListPrototype.asMutable = MapPrototype.asMutable;
  28442. ListPrototype.asImmutable = MapPrototype.asImmutable;
  28443. ListPrototype.wasAltered = MapPrototype.wasAltered;
  28444. function VNode(array, ownerID) {
  28445. this.array = array;
  28446. this.ownerID = ownerID;
  28447. }
  28448. // TODO: seems like these methods are very similar
  28449. VNode.prototype.removeBefore = function(ownerID, level, index) {
  28450. if (index === level ? 1 << level : this.array.length === 0) {
  28451. return this;
  28452. }
  28453. var originIndex = (index >>> level) & MASK;
  28454. if (originIndex >= this.array.length) {
  28455. return new VNode([], ownerID);
  28456. }
  28457. var removingFirst = originIndex === 0;
  28458. var newChild;
  28459. if (level > 0) {
  28460. var oldChild = this.array[originIndex];
  28461. newChild = oldChild && oldChild.removeBefore(ownerID, level - SHIFT, index);
  28462. if (newChild === oldChild && removingFirst) {
  28463. return this;
  28464. }
  28465. }
  28466. if (removingFirst && !newChild) {
  28467. return this;
  28468. }
  28469. var editable = editableVNode(this, ownerID);
  28470. if (!removingFirst) {
  28471. for (var ii = 0; ii < originIndex; ii++) {
  28472. editable.array[ii] = undefined;
  28473. }
  28474. }
  28475. if (newChild) {
  28476. editable.array[originIndex] = newChild;
  28477. }
  28478. return editable;
  28479. };
  28480. VNode.prototype.removeAfter = function(ownerID, level, index) {
  28481. if (index === (level ? 1 << level : 0) || this.array.length === 0) {
  28482. return this;
  28483. }
  28484. var sizeIndex = ((index - 1) >>> level) & MASK;
  28485. if (sizeIndex >= this.array.length) {
  28486. return this;
  28487. }
  28488. var newChild;
  28489. if (level > 0) {
  28490. var oldChild = this.array[sizeIndex];
  28491. newChild = oldChild && oldChild.removeAfter(ownerID, level - SHIFT, index);
  28492. if (newChild === oldChild && sizeIndex === this.array.length - 1) {
  28493. return this;
  28494. }
  28495. }
  28496. var editable = editableVNode(this, ownerID);
  28497. editable.array.splice(sizeIndex + 1);
  28498. if (newChild) {
  28499. editable.array[sizeIndex] = newChild;
  28500. }
  28501. return editable;
  28502. };
  28503. var DONE = {};
  28504. function iterateList(list, reverse) {
  28505. var left = list._origin;
  28506. var right = list._capacity;
  28507. var tailPos = getTailOffset(right);
  28508. var tail = list._tail;
  28509. return iterateNodeOrLeaf(list._root, list._level, 0);
  28510. function iterateNodeOrLeaf(node, level, offset) {
  28511. return level === 0 ?
  28512. iterateLeaf(node, offset) :
  28513. iterateNode(node, level, offset);
  28514. }
  28515. function iterateLeaf(node, offset) {
  28516. var array = offset === tailPos ? tail && tail.array : node && node.array;
  28517. var from = offset > left ? 0 : left - offset;
  28518. var to = right - offset;
  28519. if (to > SIZE) {
  28520. to = SIZE;
  28521. }
  28522. return function() {
  28523. if (from === to) {
  28524. return DONE;
  28525. }
  28526. var idx = reverse ? --to : from++;
  28527. return array && array[idx];
  28528. };
  28529. }
  28530. function iterateNode(node, level, offset) {
  28531. var values;
  28532. var array = node && node.array;
  28533. var from = offset > left ? 0 : (left - offset) >> level;
  28534. var to = ((right - offset) >> level) + 1;
  28535. if (to > SIZE) {
  28536. to = SIZE;
  28537. }
  28538. return function() {
  28539. do {
  28540. if (values) {
  28541. var value = values();
  28542. if (value !== DONE) {
  28543. return value;
  28544. }
  28545. values = null;
  28546. }
  28547. if (from === to) {
  28548. return DONE;
  28549. }
  28550. var idx = reverse ? --to : from++;
  28551. values = iterateNodeOrLeaf(
  28552. array && array[idx], level - SHIFT, offset + (idx << level)
  28553. );
  28554. } while (true);
  28555. };
  28556. }
  28557. }
  28558. function makeList(origin, capacity, level, root, tail, ownerID, hash) {
  28559. var list = Object.create(ListPrototype);
  28560. list.size = capacity - origin;
  28561. list._origin = origin;
  28562. list._capacity = capacity;
  28563. list._level = level;
  28564. list._root = root;
  28565. list._tail = tail;
  28566. list.__ownerID = ownerID;
  28567. list.__hash = hash;
  28568. list.__altered = false;
  28569. return list;
  28570. }
  28571. var EMPTY_LIST;
  28572. function emptyList() {
  28573. return EMPTY_LIST || (EMPTY_LIST = makeList(0, 0, SHIFT));
  28574. }
  28575. function updateList(list, index, value) {
  28576. index = wrapIndex(list, index);
  28577. if (index !== index) {
  28578. return list;
  28579. }
  28580. if (index >= list.size || index < 0) {
  28581. return list.withMutations(function(list ) {
  28582. index < 0 ?
  28583. setListBounds(list, index).set(0, value) :
  28584. setListBounds(list, 0, index + 1).set(index, value);
  28585. });
  28586. }
  28587. index += list._origin;
  28588. var newTail = list._tail;
  28589. var newRoot = list._root;
  28590. var didAlter = MakeRef(DID_ALTER);
  28591. if (index >= getTailOffset(list._capacity)) {
  28592. newTail = updateVNode(newTail, list.__ownerID, 0, index, value, didAlter);
  28593. } else {
  28594. newRoot = updateVNode(newRoot, list.__ownerID, list._level, index, value, didAlter);
  28595. }
  28596. if (!didAlter.value) {
  28597. return list;
  28598. }
  28599. if (list.__ownerID) {
  28600. list._root = newRoot;
  28601. list._tail = newTail;
  28602. list.__hash = undefined;
  28603. list.__altered = true;
  28604. return list;
  28605. }
  28606. return makeList(list._origin, list._capacity, list._level, newRoot, newTail);
  28607. }
  28608. function updateVNode(node, ownerID, level, index, value, didAlter) {
  28609. var idx = (index >>> level) & MASK;
  28610. var nodeHas = node && idx < node.array.length;
  28611. if (!nodeHas && value === undefined) {
  28612. return node;
  28613. }
  28614. var newNode;
  28615. if (level > 0) {
  28616. var lowerNode = node && node.array[idx];
  28617. var newLowerNode = updateVNode(lowerNode, ownerID, level - SHIFT, index, value, didAlter);
  28618. if (newLowerNode === lowerNode) {
  28619. return node;
  28620. }
  28621. newNode = editableVNode(node, ownerID);
  28622. newNode.array[idx] = newLowerNode;
  28623. return newNode;
  28624. }
  28625. if (nodeHas && node.array[idx] === value) {
  28626. return node;
  28627. }
  28628. SetRef(didAlter);
  28629. newNode = editableVNode(node, ownerID);
  28630. if (value === undefined && idx === newNode.array.length - 1) {
  28631. newNode.array.pop();
  28632. } else {
  28633. newNode.array[idx] = value;
  28634. }
  28635. return newNode;
  28636. }
  28637. function editableVNode(node, ownerID) {
  28638. if (ownerID && node && ownerID === node.ownerID) {
  28639. return node;
  28640. }
  28641. return new VNode(node ? node.array.slice() : [], ownerID);
  28642. }
  28643. function listNodeFor(list, rawIndex) {
  28644. if (rawIndex >= getTailOffset(list._capacity)) {
  28645. return list._tail;
  28646. }
  28647. if (rawIndex < 1 << (list._level + SHIFT)) {
  28648. var node = list._root;
  28649. var level = list._level;
  28650. while (node && level > 0) {
  28651. node = node.array[(rawIndex >>> level) & MASK];
  28652. level -= SHIFT;
  28653. }
  28654. return node;
  28655. }
  28656. }
  28657. function setListBounds(list, begin, end) {
  28658. // Sanitize begin & end using this shorthand for ToInt32(argument)
  28659. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  28660. if (begin !== undefined) {
  28661. begin = begin | 0;
  28662. }
  28663. if (end !== undefined) {
  28664. end = end | 0;
  28665. }
  28666. var owner = list.__ownerID || new OwnerID();
  28667. var oldOrigin = list._origin;
  28668. var oldCapacity = list._capacity;
  28669. var newOrigin = oldOrigin + begin;
  28670. var newCapacity = end === undefined ? oldCapacity : end < 0 ? oldCapacity + end : oldOrigin + end;
  28671. if (newOrigin === oldOrigin && newCapacity === oldCapacity) {
  28672. return list;
  28673. }
  28674. // If it's going to end after it starts, it's empty.
  28675. if (newOrigin >= newCapacity) {
  28676. return list.clear();
  28677. }
  28678. var newLevel = list._level;
  28679. var newRoot = list._root;
  28680. // New origin might need creating a higher root.
  28681. var offsetShift = 0;
  28682. while (newOrigin + offsetShift < 0) {
  28683. newRoot = new VNode(newRoot && newRoot.array.length ? [undefined, newRoot] : [], owner);
  28684. newLevel += SHIFT;
  28685. offsetShift += 1 << newLevel;
  28686. }
  28687. if (offsetShift) {
  28688. newOrigin += offsetShift;
  28689. oldOrigin += offsetShift;
  28690. newCapacity += offsetShift;
  28691. oldCapacity += offsetShift;
  28692. }
  28693. var oldTailOffset = getTailOffset(oldCapacity);
  28694. var newTailOffset = getTailOffset(newCapacity);
  28695. // New size might need creating a higher root.
  28696. while (newTailOffset >= 1 << (newLevel + SHIFT)) {
  28697. newRoot = new VNode(newRoot && newRoot.array.length ? [newRoot] : [], owner);
  28698. newLevel += SHIFT;
  28699. }
  28700. // Locate or create the new tail.
  28701. var oldTail = list._tail;
  28702. var newTail = newTailOffset < oldTailOffset ?
  28703. listNodeFor(list, newCapacity - 1) :
  28704. newTailOffset > oldTailOffset ? new VNode([], owner) : oldTail;
  28705. // Merge Tail into tree.
  28706. if (oldTail && newTailOffset > oldTailOffset && newOrigin < oldCapacity && oldTail.array.length) {
  28707. newRoot = editableVNode(newRoot, owner);
  28708. var node = newRoot;
  28709. for (var level = newLevel; level > SHIFT; level -= SHIFT) {
  28710. var idx = (oldTailOffset >>> level) & MASK;
  28711. node = node.array[idx] = editableVNode(node.array[idx], owner);
  28712. }
  28713. node.array[(oldTailOffset >>> SHIFT) & MASK] = oldTail;
  28714. }
  28715. // If the size has been reduced, there's a chance the tail needs to be trimmed.
  28716. if (newCapacity < oldCapacity) {
  28717. newTail = newTail && newTail.removeAfter(owner, 0, newCapacity);
  28718. }
  28719. // If the new origin is within the tail, then we do not need a root.
  28720. if (newOrigin >= newTailOffset) {
  28721. newOrigin -= newTailOffset;
  28722. newCapacity -= newTailOffset;
  28723. newLevel = SHIFT;
  28724. newRoot = null;
  28725. newTail = newTail && newTail.removeBefore(owner, 0, newOrigin);
  28726. // Otherwise, if the root has been trimmed, garbage collect.
  28727. } else if (newOrigin > oldOrigin || newTailOffset < oldTailOffset) {
  28728. offsetShift = 0;
  28729. // Identify the new top root node of the subtree of the old root.
  28730. while (newRoot) {
  28731. var beginIndex = (newOrigin >>> newLevel) & MASK;
  28732. if (beginIndex !== (newTailOffset >>> newLevel) & MASK) {
  28733. break;
  28734. }
  28735. if (beginIndex) {
  28736. offsetShift += (1 << newLevel) * beginIndex;
  28737. }
  28738. newLevel -= SHIFT;
  28739. newRoot = newRoot.array[beginIndex];
  28740. }
  28741. // Trim the new sides of the new root.
  28742. if (newRoot && newOrigin > oldOrigin) {
  28743. newRoot = newRoot.removeBefore(owner, newLevel, newOrigin - offsetShift);
  28744. }
  28745. if (newRoot && newTailOffset < oldTailOffset) {
  28746. newRoot = newRoot.removeAfter(owner, newLevel, newTailOffset - offsetShift);
  28747. }
  28748. if (offsetShift) {
  28749. newOrigin -= offsetShift;
  28750. newCapacity -= offsetShift;
  28751. }
  28752. }
  28753. if (list.__ownerID) {
  28754. list.size = newCapacity - newOrigin;
  28755. list._origin = newOrigin;
  28756. list._capacity = newCapacity;
  28757. list._level = newLevel;
  28758. list._root = newRoot;
  28759. list._tail = newTail;
  28760. list.__hash = undefined;
  28761. list.__altered = true;
  28762. return list;
  28763. }
  28764. return makeList(newOrigin, newCapacity, newLevel, newRoot, newTail);
  28765. }
  28766. function mergeIntoListWith(list, merger, iterables) {
  28767. var iters = [];
  28768. var maxSize = 0;
  28769. for (var ii = 0; ii < iterables.length; ii++) {
  28770. var value = iterables[ii];
  28771. var iter = IndexedIterable(value);
  28772. if (iter.size > maxSize) {
  28773. maxSize = iter.size;
  28774. }
  28775. if (!isIterable(value)) {
  28776. iter = iter.map(function(v ) {return fromJS(v)});
  28777. }
  28778. iters.push(iter);
  28779. }
  28780. if (maxSize > list.size) {
  28781. list = list.setSize(maxSize);
  28782. }
  28783. return mergeIntoCollectionWith(list, merger, iters);
  28784. }
  28785. function getTailOffset(size) {
  28786. return size < SIZE ? 0 : (((size - 1) >>> SHIFT) << SHIFT);
  28787. }
  28788. createClass(OrderedMap, Map);
  28789. // @pragma Construction
  28790. function OrderedMap(value) {
  28791. return value === null || value === undefined ? emptyOrderedMap() :
  28792. isOrderedMap(value) ? value :
  28793. emptyOrderedMap().withMutations(function(map ) {
  28794. var iter = KeyedIterable(value);
  28795. assertNotInfinite(iter.size);
  28796. iter.forEach(function(v, k) {return map.set(k, v)});
  28797. });
  28798. }
  28799. OrderedMap.of = function(/*...values*/) {
  28800. return this(arguments);
  28801. };
  28802. OrderedMap.prototype.toString = function() {
  28803. return this.__toString('OrderedMap {', '}');
  28804. };
  28805. // @pragma Access
  28806. OrderedMap.prototype.get = function(k, notSetValue) {
  28807. var index = this._map.get(k);
  28808. return index !== undefined ? this._list.get(index)[1] : notSetValue;
  28809. };
  28810. // @pragma Modification
  28811. OrderedMap.prototype.clear = function() {
  28812. if (this.size === 0) {
  28813. return this;
  28814. }
  28815. if (this.__ownerID) {
  28816. this.size = 0;
  28817. this._map.clear();
  28818. this._list.clear();
  28819. return this;
  28820. }
  28821. return emptyOrderedMap();
  28822. };
  28823. OrderedMap.prototype.set = function(k, v) {
  28824. return updateOrderedMap(this, k, v);
  28825. };
  28826. OrderedMap.prototype.remove = function(k) {
  28827. return updateOrderedMap(this, k, NOT_SET);
  28828. };
  28829. OrderedMap.prototype.wasAltered = function() {
  28830. return this._map.wasAltered() || this._list.wasAltered();
  28831. };
  28832. OrderedMap.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  28833. return this._list.__iterate(
  28834. function(entry ) {return entry && fn(entry[1], entry[0], this$0)},
  28835. reverse
  28836. );
  28837. };
  28838. OrderedMap.prototype.__iterator = function(type, reverse) {
  28839. return this._list.fromEntrySeq().__iterator(type, reverse);
  28840. };
  28841. OrderedMap.prototype.__ensureOwner = function(ownerID) {
  28842. if (ownerID === this.__ownerID) {
  28843. return this;
  28844. }
  28845. var newMap = this._map.__ensureOwner(ownerID);
  28846. var newList = this._list.__ensureOwner(ownerID);
  28847. if (!ownerID) {
  28848. this.__ownerID = ownerID;
  28849. this._map = newMap;
  28850. this._list = newList;
  28851. return this;
  28852. }
  28853. return makeOrderedMap(newMap, newList, ownerID, this.__hash);
  28854. };
  28855. function isOrderedMap(maybeOrderedMap) {
  28856. return isMap(maybeOrderedMap) && isOrdered(maybeOrderedMap);
  28857. }
  28858. OrderedMap.isOrderedMap = isOrderedMap;
  28859. OrderedMap.prototype[IS_ORDERED_SENTINEL] = true;
  28860. OrderedMap.prototype[DELETE] = OrderedMap.prototype.remove;
  28861. function makeOrderedMap(map, list, ownerID, hash) {
  28862. var omap = Object.create(OrderedMap.prototype);
  28863. omap.size = map ? map.size : 0;
  28864. omap._map = map;
  28865. omap._list = list;
  28866. omap.__ownerID = ownerID;
  28867. omap.__hash = hash;
  28868. return omap;
  28869. }
  28870. var EMPTY_ORDERED_MAP;
  28871. function emptyOrderedMap() {
  28872. return EMPTY_ORDERED_MAP || (EMPTY_ORDERED_MAP = makeOrderedMap(emptyMap(), emptyList()));
  28873. }
  28874. function updateOrderedMap(omap, k, v) {
  28875. var map = omap._map;
  28876. var list = omap._list;
  28877. var i = map.get(k);
  28878. var has = i !== undefined;
  28879. var newMap;
  28880. var newList;
  28881. if (v === NOT_SET) { // removed
  28882. if (!has) {
  28883. return omap;
  28884. }
  28885. if (list.size >= SIZE && list.size >= map.size * 2) {
  28886. newList = list.filter(function(entry, idx) {return entry !== undefined && i !== idx});
  28887. newMap = newList.toKeyedSeq().map(function(entry ) {return entry[0]}).flip().toMap();
  28888. if (omap.__ownerID) {
  28889. newMap.__ownerID = newList.__ownerID = omap.__ownerID;
  28890. }
  28891. } else {
  28892. newMap = map.remove(k);
  28893. newList = i === list.size - 1 ? list.pop() : list.set(i, undefined);
  28894. }
  28895. } else {
  28896. if (has) {
  28897. if (v === list.get(i)[1]) {
  28898. return omap;
  28899. }
  28900. newMap = map;
  28901. newList = list.set(i, [k, v]);
  28902. } else {
  28903. newMap = map.set(k, list.size);
  28904. newList = list.set(list.size, [k, v]);
  28905. }
  28906. }
  28907. if (omap.__ownerID) {
  28908. omap.size = newMap.size;
  28909. omap._map = newMap;
  28910. omap._list = newList;
  28911. omap.__hash = undefined;
  28912. return omap;
  28913. }
  28914. return makeOrderedMap(newMap, newList);
  28915. }
  28916. createClass(ToKeyedSequence, KeyedSeq);
  28917. function ToKeyedSequence(indexed, useKeys) {
  28918. this._iter = indexed;
  28919. this._useKeys = useKeys;
  28920. this.size = indexed.size;
  28921. }
  28922. ToKeyedSequence.prototype.get = function(key, notSetValue) {
  28923. return this._iter.get(key, notSetValue);
  28924. };
  28925. ToKeyedSequence.prototype.has = function(key) {
  28926. return this._iter.has(key);
  28927. };
  28928. ToKeyedSequence.prototype.valueSeq = function() {
  28929. return this._iter.valueSeq();
  28930. };
  28931. ToKeyedSequence.prototype.reverse = function() {var this$0 = this;
  28932. var reversedSequence = reverseFactory(this, true);
  28933. if (!this._useKeys) {
  28934. reversedSequence.valueSeq = function() {return this$0._iter.toSeq().reverse()};
  28935. }
  28936. return reversedSequence;
  28937. };
  28938. ToKeyedSequence.prototype.map = function(mapper, context) {var this$0 = this;
  28939. var mappedSequence = mapFactory(this, mapper, context);
  28940. if (!this._useKeys) {
  28941. mappedSequence.valueSeq = function() {return this$0._iter.toSeq().map(mapper, context)};
  28942. }
  28943. return mappedSequence;
  28944. };
  28945. ToKeyedSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  28946. var ii;
  28947. return this._iter.__iterate(
  28948. this._useKeys ?
  28949. function(v, k) {return fn(v, k, this$0)} :
  28950. ((ii = reverse ? resolveSize(this) : 0),
  28951. function(v ) {return fn(v, reverse ? --ii : ii++, this$0)}),
  28952. reverse
  28953. );
  28954. };
  28955. ToKeyedSequence.prototype.__iterator = function(type, reverse) {
  28956. if (this._useKeys) {
  28957. return this._iter.__iterator(type, reverse);
  28958. }
  28959. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  28960. var ii = reverse ? resolveSize(this) : 0;
  28961. return new Iterator(function() {
  28962. var step = iterator.next();
  28963. return step.done ? step :
  28964. iteratorValue(type, reverse ? --ii : ii++, step.value, step);
  28965. });
  28966. };
  28967. ToKeyedSequence.prototype[IS_ORDERED_SENTINEL] = true;
  28968. createClass(ToIndexedSequence, IndexedSeq);
  28969. function ToIndexedSequence(iter) {
  28970. this._iter = iter;
  28971. this.size = iter.size;
  28972. }
  28973. ToIndexedSequence.prototype.includes = function(value) {
  28974. return this._iter.includes(value);
  28975. };
  28976. ToIndexedSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  28977. var iterations = 0;
  28978. return this._iter.__iterate(function(v ) {return fn(v, iterations++, this$0)}, reverse);
  28979. };
  28980. ToIndexedSequence.prototype.__iterator = function(type, reverse) {
  28981. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  28982. var iterations = 0;
  28983. return new Iterator(function() {
  28984. var step = iterator.next();
  28985. return step.done ? step :
  28986. iteratorValue(type, iterations++, step.value, step)
  28987. });
  28988. };
  28989. createClass(ToSetSequence, SetSeq);
  28990. function ToSetSequence(iter) {
  28991. this._iter = iter;
  28992. this.size = iter.size;
  28993. }
  28994. ToSetSequence.prototype.has = function(key) {
  28995. return this._iter.includes(key);
  28996. };
  28997. ToSetSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  28998. return this._iter.__iterate(function(v ) {return fn(v, v, this$0)}, reverse);
  28999. };
  29000. ToSetSequence.prototype.__iterator = function(type, reverse) {
  29001. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  29002. return new Iterator(function() {
  29003. var step = iterator.next();
  29004. return step.done ? step :
  29005. iteratorValue(type, step.value, step.value, step);
  29006. });
  29007. };
  29008. createClass(FromEntriesSequence, KeyedSeq);
  29009. function FromEntriesSequence(entries) {
  29010. this._iter = entries;
  29011. this.size = entries.size;
  29012. }
  29013. FromEntriesSequence.prototype.entrySeq = function() {
  29014. return this._iter.toSeq();
  29015. };
  29016. FromEntriesSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  29017. return this._iter.__iterate(function(entry ) {
  29018. // Check if entry exists first so array access doesn't throw for holes
  29019. // in the parent iteration.
  29020. if (entry) {
  29021. validateEntry(entry);
  29022. var indexedIterable = isIterable(entry);
  29023. return fn(
  29024. indexedIterable ? entry.get(1) : entry[1],
  29025. indexedIterable ? entry.get(0) : entry[0],
  29026. this$0
  29027. );
  29028. }
  29029. }, reverse);
  29030. };
  29031. FromEntriesSequence.prototype.__iterator = function(type, reverse) {
  29032. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  29033. return new Iterator(function() {
  29034. while (true) {
  29035. var step = iterator.next();
  29036. if (step.done) {
  29037. return step;
  29038. }
  29039. var entry = step.value;
  29040. // Check if entry exists first so array access doesn't throw for holes
  29041. // in the parent iteration.
  29042. if (entry) {
  29043. validateEntry(entry);
  29044. var indexedIterable = isIterable(entry);
  29045. return iteratorValue(
  29046. type,
  29047. indexedIterable ? entry.get(0) : entry[0],
  29048. indexedIterable ? entry.get(1) : entry[1],
  29049. step
  29050. );
  29051. }
  29052. }
  29053. });
  29054. };
  29055. ToIndexedSequence.prototype.cacheResult =
  29056. ToKeyedSequence.prototype.cacheResult =
  29057. ToSetSequence.prototype.cacheResult =
  29058. FromEntriesSequence.prototype.cacheResult =
  29059. cacheResultThrough;
  29060. function flipFactory(iterable) {
  29061. var flipSequence = makeSequence(iterable);
  29062. flipSequence._iter = iterable;
  29063. flipSequence.size = iterable.size;
  29064. flipSequence.flip = function() {return iterable};
  29065. flipSequence.reverse = function () {
  29066. var reversedSequence = iterable.reverse.apply(this); // super.reverse()
  29067. reversedSequence.flip = function() {return iterable.reverse()};
  29068. return reversedSequence;
  29069. };
  29070. flipSequence.has = function(key ) {return iterable.includes(key)};
  29071. flipSequence.includes = function(key ) {return iterable.has(key)};
  29072. flipSequence.cacheResult = cacheResultThrough;
  29073. flipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  29074. return iterable.__iterate(function(v, k) {return fn(k, v, this$0) !== false}, reverse);
  29075. };
  29076. flipSequence.__iteratorUncached = function(type, reverse) {
  29077. if (type === ITERATE_ENTRIES) {
  29078. var iterator = iterable.__iterator(type, reverse);
  29079. return new Iterator(function() {
  29080. var step = iterator.next();
  29081. if (!step.done) {
  29082. var k = step.value[0];
  29083. step.value[0] = step.value[1];
  29084. step.value[1] = k;
  29085. }
  29086. return step;
  29087. });
  29088. }
  29089. return iterable.__iterator(
  29090. type === ITERATE_VALUES ? ITERATE_KEYS : ITERATE_VALUES,
  29091. reverse
  29092. );
  29093. };
  29094. return flipSequence;
  29095. }
  29096. function mapFactory(iterable, mapper, context) {
  29097. var mappedSequence = makeSequence(iterable);
  29098. mappedSequence.size = iterable.size;
  29099. mappedSequence.has = function(key ) {return iterable.has(key)};
  29100. mappedSequence.get = function(key, notSetValue) {
  29101. var v = iterable.get(key, NOT_SET);
  29102. return v === NOT_SET ?
  29103. notSetValue :
  29104. mapper.call(context, v, key, iterable);
  29105. };
  29106. mappedSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  29107. return iterable.__iterate(
  29108. function(v, k, c) {return fn(mapper.call(context, v, k, c), k, this$0) !== false},
  29109. reverse
  29110. );
  29111. };
  29112. mappedSequence.__iteratorUncached = function (type, reverse) {
  29113. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  29114. return new Iterator(function() {
  29115. var step = iterator.next();
  29116. if (step.done) {
  29117. return step;
  29118. }
  29119. var entry = step.value;
  29120. var key = entry[0];
  29121. return iteratorValue(
  29122. type,
  29123. key,
  29124. mapper.call(context, entry[1], key, iterable),
  29125. step
  29126. );
  29127. });
  29128. };
  29129. return mappedSequence;
  29130. }
  29131. function reverseFactory(iterable, useKeys) {
  29132. var reversedSequence = makeSequence(iterable);
  29133. reversedSequence._iter = iterable;
  29134. reversedSequence.size = iterable.size;
  29135. reversedSequence.reverse = function() {return iterable};
  29136. if (iterable.flip) {
  29137. reversedSequence.flip = function () {
  29138. var flipSequence = flipFactory(iterable);
  29139. flipSequence.reverse = function() {return iterable.flip()};
  29140. return flipSequence;
  29141. };
  29142. }
  29143. reversedSequence.get = function(key, notSetValue)
  29144. {return iterable.get(useKeys ? key : -1 - key, notSetValue)};
  29145. reversedSequence.has = function(key )
  29146. {return iterable.has(useKeys ? key : -1 - key)};
  29147. reversedSequence.includes = function(value ) {return iterable.includes(value)};
  29148. reversedSequence.cacheResult = cacheResultThrough;
  29149. reversedSequence.__iterate = function (fn, reverse) {var this$0 = this;
  29150. return iterable.__iterate(function(v, k) {return fn(v, k, this$0)}, !reverse);
  29151. };
  29152. reversedSequence.__iterator =
  29153. function(type, reverse) {return iterable.__iterator(type, !reverse)};
  29154. return reversedSequence;
  29155. }
  29156. function filterFactory(iterable, predicate, context, useKeys) {
  29157. var filterSequence = makeSequence(iterable);
  29158. if (useKeys) {
  29159. filterSequence.has = function(key ) {
  29160. var v = iterable.get(key, NOT_SET);
  29161. return v !== NOT_SET && !!predicate.call(context, v, key, iterable);
  29162. };
  29163. filterSequence.get = function(key, notSetValue) {
  29164. var v = iterable.get(key, NOT_SET);
  29165. return v !== NOT_SET && predicate.call(context, v, key, iterable) ?
  29166. v : notSetValue;
  29167. };
  29168. }
  29169. filterSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  29170. var iterations = 0;
  29171. iterable.__iterate(function(v, k, c) {
  29172. if (predicate.call(context, v, k, c)) {
  29173. iterations++;
  29174. return fn(v, useKeys ? k : iterations - 1, this$0);
  29175. }
  29176. }, reverse);
  29177. return iterations;
  29178. };
  29179. filterSequence.__iteratorUncached = function (type, reverse) {
  29180. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  29181. var iterations = 0;
  29182. return new Iterator(function() {
  29183. while (true) {
  29184. var step = iterator.next();
  29185. if (step.done) {
  29186. return step;
  29187. }
  29188. var entry = step.value;
  29189. var key = entry[0];
  29190. var value = entry[1];
  29191. if (predicate.call(context, value, key, iterable)) {
  29192. return iteratorValue(type, useKeys ? key : iterations++, value, step);
  29193. }
  29194. }
  29195. });
  29196. };
  29197. return filterSequence;
  29198. }
  29199. function countByFactory(iterable, grouper, context) {
  29200. var groups = Map().asMutable();
  29201. iterable.__iterate(function(v, k) {
  29202. groups.update(
  29203. grouper.call(context, v, k, iterable),
  29204. 0,
  29205. function(a ) {return a + 1}
  29206. );
  29207. });
  29208. return groups.asImmutable();
  29209. }
  29210. function groupByFactory(iterable, grouper, context) {
  29211. var isKeyedIter = isKeyed(iterable);
  29212. var groups = (isOrdered(iterable) ? OrderedMap() : Map()).asMutable();
  29213. iterable.__iterate(function(v, k) {
  29214. groups.update(
  29215. grouper.call(context, v, k, iterable),
  29216. function(a ) {return (a = a || [], a.push(isKeyedIter ? [k, v] : v), a)}
  29217. );
  29218. });
  29219. var coerce = iterableClass(iterable);
  29220. return groups.map(function(arr ) {return reify(iterable, coerce(arr))});
  29221. }
  29222. function sliceFactory(iterable, begin, end, useKeys) {
  29223. var originalSize = iterable.size;
  29224. // Sanitize begin & end using this shorthand for ToInt32(argument)
  29225. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  29226. if (begin !== undefined) {
  29227. begin = begin | 0;
  29228. }
  29229. if (end !== undefined) {
  29230. end = end | 0;
  29231. }
  29232. if (wholeSlice(begin, end, originalSize)) {
  29233. return iterable;
  29234. }
  29235. var resolvedBegin = resolveBegin(begin, originalSize);
  29236. var resolvedEnd = resolveEnd(end, originalSize);
  29237. // begin or end will be NaN if they were provided as negative numbers and
  29238. // this iterable's size is unknown. In that case, cache first so there is
  29239. // a known size and these do not resolve to NaN.
  29240. if (resolvedBegin !== resolvedBegin || resolvedEnd !== resolvedEnd) {
  29241. return sliceFactory(iterable.toSeq().cacheResult(), begin, end, useKeys);
  29242. }
  29243. // Note: resolvedEnd is undefined when the original sequence's length is
  29244. // unknown and this slice did not supply an end and should contain all
  29245. // elements after resolvedBegin.
  29246. // In that case, resolvedSize will be NaN and sliceSize will remain undefined.
  29247. var resolvedSize = resolvedEnd - resolvedBegin;
  29248. var sliceSize;
  29249. if (resolvedSize === resolvedSize) {
  29250. sliceSize = resolvedSize < 0 ? 0 : resolvedSize;
  29251. }
  29252. var sliceSeq = makeSequence(iterable);
  29253. // If iterable.size is undefined, the size of the realized sliceSeq is
  29254. // unknown at this point unless the number of items to slice is 0
  29255. sliceSeq.size = sliceSize === 0 ? sliceSize : iterable.size && sliceSize || undefined;
  29256. if (!useKeys && isSeq(iterable) && sliceSize >= 0) {
  29257. sliceSeq.get = function (index, notSetValue) {
  29258. index = wrapIndex(this, index);
  29259. return index >= 0 && index < sliceSize ?
  29260. iterable.get(index + resolvedBegin, notSetValue) :
  29261. notSetValue;
  29262. };
  29263. }
  29264. sliceSeq.__iterateUncached = function(fn, reverse) {var this$0 = this;
  29265. if (sliceSize === 0) {
  29266. return 0;
  29267. }
  29268. if (reverse) {
  29269. return this.cacheResult().__iterate(fn, reverse);
  29270. }
  29271. var skipped = 0;
  29272. var isSkipping = true;
  29273. var iterations = 0;
  29274. iterable.__iterate(function(v, k) {
  29275. if (!(isSkipping && (isSkipping = skipped++ < resolvedBegin))) {
  29276. iterations++;
  29277. return fn(v, useKeys ? k : iterations - 1, this$0) !== false &&
  29278. iterations !== sliceSize;
  29279. }
  29280. });
  29281. return iterations;
  29282. };
  29283. sliceSeq.__iteratorUncached = function(type, reverse) {
  29284. if (sliceSize !== 0 && reverse) {
  29285. return this.cacheResult().__iterator(type, reverse);
  29286. }
  29287. // Don't bother instantiating parent iterator if taking 0.
  29288. var iterator = sliceSize !== 0 && iterable.__iterator(type, reverse);
  29289. var skipped = 0;
  29290. var iterations = 0;
  29291. return new Iterator(function() {
  29292. while (skipped++ < resolvedBegin) {
  29293. iterator.next();
  29294. }
  29295. if (++iterations > sliceSize) {
  29296. return iteratorDone();
  29297. }
  29298. var step = iterator.next();
  29299. if (useKeys || type === ITERATE_VALUES) {
  29300. return step;
  29301. } else if (type === ITERATE_KEYS) {
  29302. return iteratorValue(type, iterations - 1, undefined, step);
  29303. } else {
  29304. return iteratorValue(type, iterations - 1, step.value[1], step);
  29305. }
  29306. });
  29307. };
  29308. return sliceSeq;
  29309. }
  29310. function takeWhileFactory(iterable, predicate, context) {
  29311. var takeSequence = makeSequence(iterable);
  29312. takeSequence.__iterateUncached = function(fn, reverse) {var this$0 = this;
  29313. if (reverse) {
  29314. return this.cacheResult().__iterate(fn, reverse);
  29315. }
  29316. var iterations = 0;
  29317. iterable.__iterate(function(v, k, c)
  29318. {return predicate.call(context, v, k, c) && ++iterations && fn(v, k, this$0)}
  29319. );
  29320. return iterations;
  29321. };
  29322. takeSequence.__iteratorUncached = function(type, reverse) {var this$0 = this;
  29323. if (reverse) {
  29324. return this.cacheResult().__iterator(type, reverse);
  29325. }
  29326. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  29327. var iterating = true;
  29328. return new Iterator(function() {
  29329. if (!iterating) {
  29330. return iteratorDone();
  29331. }
  29332. var step = iterator.next();
  29333. if (step.done) {
  29334. return step;
  29335. }
  29336. var entry = step.value;
  29337. var k = entry[0];
  29338. var v = entry[1];
  29339. if (!predicate.call(context, v, k, this$0)) {
  29340. iterating = false;
  29341. return iteratorDone();
  29342. }
  29343. return type === ITERATE_ENTRIES ? step :
  29344. iteratorValue(type, k, v, step);
  29345. });
  29346. };
  29347. return takeSequence;
  29348. }
  29349. function skipWhileFactory(iterable, predicate, context, useKeys) {
  29350. var skipSequence = makeSequence(iterable);
  29351. skipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  29352. if (reverse) {
  29353. return this.cacheResult().__iterate(fn, reverse);
  29354. }
  29355. var isSkipping = true;
  29356. var iterations = 0;
  29357. iterable.__iterate(function(v, k, c) {
  29358. if (!(isSkipping && (isSkipping = predicate.call(context, v, k, c)))) {
  29359. iterations++;
  29360. return fn(v, useKeys ? k : iterations - 1, this$0);
  29361. }
  29362. });
  29363. return iterations;
  29364. };
  29365. skipSequence.__iteratorUncached = function(type, reverse) {var this$0 = this;
  29366. if (reverse) {
  29367. return this.cacheResult().__iterator(type, reverse);
  29368. }
  29369. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  29370. var skipping = true;
  29371. var iterations = 0;
  29372. return new Iterator(function() {
  29373. var step, k, v;
  29374. do {
  29375. step = iterator.next();
  29376. if (step.done) {
  29377. if (useKeys || type === ITERATE_VALUES) {
  29378. return step;
  29379. } else if (type === ITERATE_KEYS) {
  29380. return iteratorValue(type, iterations++, undefined, step);
  29381. } else {
  29382. return iteratorValue(type, iterations++, step.value[1], step);
  29383. }
  29384. }
  29385. var entry = step.value;
  29386. k = entry[0];
  29387. v = entry[1];
  29388. skipping && (skipping = predicate.call(context, v, k, this$0));
  29389. } while (skipping);
  29390. return type === ITERATE_ENTRIES ? step :
  29391. iteratorValue(type, k, v, step);
  29392. });
  29393. };
  29394. return skipSequence;
  29395. }
  29396. function concatFactory(iterable, values) {
  29397. var isKeyedIterable = isKeyed(iterable);
  29398. var iters = [iterable].concat(values).map(function(v ) {
  29399. if (!isIterable(v)) {
  29400. v = isKeyedIterable ?
  29401. keyedSeqFromValue(v) :
  29402. indexedSeqFromValue(Array.isArray(v) ? v : [v]);
  29403. } else if (isKeyedIterable) {
  29404. v = KeyedIterable(v);
  29405. }
  29406. return v;
  29407. }).filter(function(v ) {return v.size !== 0});
  29408. if (iters.length === 0) {
  29409. return iterable;
  29410. }
  29411. if (iters.length === 1) {
  29412. var singleton = iters[0];
  29413. if (singleton === iterable ||
  29414. isKeyedIterable && isKeyed(singleton) ||
  29415. isIndexed(iterable) && isIndexed(singleton)) {
  29416. return singleton;
  29417. }
  29418. }
  29419. var concatSeq = new ArraySeq(iters);
  29420. if (isKeyedIterable) {
  29421. concatSeq = concatSeq.toKeyedSeq();
  29422. } else if (!isIndexed(iterable)) {
  29423. concatSeq = concatSeq.toSetSeq();
  29424. }
  29425. concatSeq = concatSeq.flatten(true);
  29426. concatSeq.size = iters.reduce(
  29427. function(sum, seq) {
  29428. if (sum !== undefined) {
  29429. var size = seq.size;
  29430. if (size !== undefined) {
  29431. return sum + size;
  29432. }
  29433. }
  29434. },
  29435. 0
  29436. );
  29437. return concatSeq;
  29438. }
  29439. function flattenFactory(iterable, depth, useKeys) {
  29440. var flatSequence = makeSequence(iterable);
  29441. flatSequence.__iterateUncached = function(fn, reverse) {
  29442. var iterations = 0;
  29443. var stopped = false;
  29444. function flatDeep(iter, currentDepth) {var this$0 = this;
  29445. iter.__iterate(function(v, k) {
  29446. if ((!depth || currentDepth < depth) && isIterable(v)) {
  29447. flatDeep(v, currentDepth + 1);
  29448. } else if (fn(v, useKeys ? k : iterations++, this$0) === false) {
  29449. stopped = true;
  29450. }
  29451. return !stopped;
  29452. }, reverse);
  29453. }
  29454. flatDeep(iterable, 0);
  29455. return iterations;
  29456. };
  29457. flatSequence.__iteratorUncached = function(type, reverse) {
  29458. var iterator = iterable.__iterator(type, reverse);
  29459. var stack = [];
  29460. var iterations = 0;
  29461. return new Iterator(function() {
  29462. while (iterator) {
  29463. var step = iterator.next();
  29464. if (step.done !== false) {
  29465. iterator = stack.pop();
  29466. continue;
  29467. }
  29468. var v = step.value;
  29469. if (type === ITERATE_ENTRIES) {
  29470. v = v[1];
  29471. }
  29472. if ((!depth || stack.length < depth) && isIterable(v)) {
  29473. stack.push(iterator);
  29474. iterator = v.__iterator(type, reverse);
  29475. } else {
  29476. return useKeys ? step : iteratorValue(type, iterations++, v, step);
  29477. }
  29478. }
  29479. return iteratorDone();
  29480. });
  29481. };
  29482. return flatSequence;
  29483. }
  29484. function flatMapFactory(iterable, mapper, context) {
  29485. var coerce = iterableClass(iterable);
  29486. return iterable.toSeq().map(
  29487. function(v, k) {return coerce(mapper.call(context, v, k, iterable))}
  29488. ).flatten(true);
  29489. }
  29490. function interposeFactory(iterable, separator) {
  29491. var interposedSequence = makeSequence(iterable);
  29492. interposedSequence.size = iterable.size && iterable.size * 2 -1;
  29493. interposedSequence.__iterateUncached = function(fn, reverse) {var this$0 = this;
  29494. var iterations = 0;
  29495. iterable.__iterate(function(v, k)
  29496. {return (!iterations || fn(separator, iterations++, this$0) !== false) &&
  29497. fn(v, iterations++, this$0) !== false},
  29498. reverse
  29499. );
  29500. return iterations;
  29501. };
  29502. interposedSequence.__iteratorUncached = function(type, reverse) {
  29503. var iterator = iterable.__iterator(ITERATE_VALUES, reverse);
  29504. var iterations = 0;
  29505. var step;
  29506. return new Iterator(function() {
  29507. if (!step || iterations % 2) {
  29508. step = iterator.next();
  29509. if (step.done) {
  29510. return step;
  29511. }
  29512. }
  29513. return iterations % 2 ?
  29514. iteratorValue(type, iterations++, separator) :
  29515. iteratorValue(type, iterations++, step.value, step);
  29516. });
  29517. };
  29518. return interposedSequence;
  29519. }
  29520. function sortFactory(iterable, comparator, mapper) {
  29521. if (!comparator) {
  29522. comparator = defaultComparator;
  29523. }
  29524. var isKeyedIterable = isKeyed(iterable);
  29525. var index = 0;
  29526. var entries = iterable.toSeq().map(
  29527. function(v, k) {return [k, v, index++, mapper ? mapper(v, k, iterable) : v]}
  29528. ).toArray();
  29529. entries.sort(function(a, b) {return comparator(a[3], b[3]) || a[2] - b[2]}).forEach(
  29530. isKeyedIterable ?
  29531. function(v, i) { entries[i].length = 2; } :
  29532. function(v, i) { entries[i] = v[1]; }
  29533. );
  29534. return isKeyedIterable ? KeyedSeq(entries) :
  29535. isIndexed(iterable) ? IndexedSeq(entries) :
  29536. SetSeq(entries);
  29537. }
  29538. function maxFactory(iterable, comparator, mapper) {
  29539. if (!comparator) {
  29540. comparator = defaultComparator;
  29541. }
  29542. if (mapper) {
  29543. var entry = iterable.toSeq()
  29544. .map(function(v, k) {return [v, mapper(v, k, iterable)]})
  29545. .reduce(function(a, b) {return maxCompare(comparator, a[1], b[1]) ? b : a});
  29546. return entry && entry[0];
  29547. } else {
  29548. return iterable.reduce(function(a, b) {return maxCompare(comparator, a, b) ? b : a});
  29549. }
  29550. }
  29551. function maxCompare(comparator, a, b) {
  29552. var comp = comparator(b, a);
  29553. // b is considered the new max if the comparator declares them equal, but
  29554. // they are not equal and b is in fact a nullish value.
  29555. return (comp === 0 && b !== a && (b === undefined || b === null || b !== b)) || comp > 0;
  29556. }
  29557. function zipWithFactory(keyIter, zipper, iters) {
  29558. var zipSequence = makeSequence(keyIter);
  29559. zipSequence.size = new ArraySeq(iters).map(function(i ) {return i.size}).min();
  29560. // Note: this a generic base implementation of __iterate in terms of
  29561. // __iterator which may be more generically useful in the future.
  29562. zipSequence.__iterate = function(fn, reverse) {
  29563. /* generic:
  29564. var iterator = this.__iterator(ITERATE_ENTRIES, reverse);
  29565. var step;
  29566. var iterations = 0;
  29567. while (!(step = iterator.next()).done) {
  29568. iterations++;
  29569. if (fn(step.value[1], step.value[0], this) === false) {
  29570. break;
  29571. }
  29572. }
  29573. return iterations;
  29574. */
  29575. // indexed:
  29576. var iterator = this.__iterator(ITERATE_VALUES, reverse);
  29577. var step;
  29578. var iterations = 0;
  29579. while (!(step = iterator.next()).done) {
  29580. if (fn(step.value, iterations++, this) === false) {
  29581. break;
  29582. }
  29583. }
  29584. return iterations;
  29585. };
  29586. zipSequence.__iteratorUncached = function(type, reverse) {
  29587. var iterators = iters.map(function(i )
  29588. {return (i = Iterable(i), getIterator(reverse ? i.reverse() : i))}
  29589. );
  29590. var iterations = 0;
  29591. var isDone = false;
  29592. return new Iterator(function() {
  29593. var steps;
  29594. if (!isDone) {
  29595. steps = iterators.map(function(i ) {return i.next()});
  29596. isDone = steps.some(function(s ) {return s.done});
  29597. }
  29598. if (isDone) {
  29599. return iteratorDone();
  29600. }
  29601. return iteratorValue(
  29602. type,
  29603. iterations++,
  29604. zipper.apply(null, steps.map(function(s ) {return s.value}))
  29605. );
  29606. });
  29607. };
  29608. return zipSequence
  29609. }
  29610. // #pragma Helper Functions
  29611. function reify(iter, seq) {
  29612. return isSeq(iter) ? seq : iter.constructor(seq);
  29613. }
  29614. function validateEntry(entry) {
  29615. if (entry !== Object(entry)) {
  29616. throw new TypeError('Expected [K, V] tuple: ' + entry);
  29617. }
  29618. }
  29619. function resolveSize(iter) {
  29620. assertNotInfinite(iter.size);
  29621. return ensureSize(iter);
  29622. }
  29623. function iterableClass(iterable) {
  29624. return isKeyed(iterable) ? KeyedIterable :
  29625. isIndexed(iterable) ? IndexedIterable :
  29626. SetIterable;
  29627. }
  29628. function makeSequence(iterable) {
  29629. return Object.create(
  29630. (
  29631. isKeyed(iterable) ? KeyedSeq :
  29632. isIndexed(iterable) ? IndexedSeq :
  29633. SetSeq
  29634. ).prototype
  29635. );
  29636. }
  29637. function cacheResultThrough() {
  29638. if (this._iter.cacheResult) {
  29639. this._iter.cacheResult();
  29640. this.size = this._iter.size;
  29641. return this;
  29642. } else {
  29643. return Seq.prototype.cacheResult.call(this);
  29644. }
  29645. }
  29646. function defaultComparator(a, b) {
  29647. return a > b ? 1 : a < b ? -1 : 0;
  29648. }
  29649. function forceIterator(keyPath) {
  29650. var iter = getIterator(keyPath);
  29651. if (!iter) {
  29652. // Array might not be iterable in this environment, so we need a fallback
  29653. // to our wrapped type.
  29654. if (!isArrayLike(keyPath)) {
  29655. throw new TypeError('Expected iterable or array-like: ' + keyPath);
  29656. }
  29657. iter = getIterator(Iterable(keyPath));
  29658. }
  29659. return iter;
  29660. }
  29661. createClass(Record, KeyedCollection);
  29662. function Record(defaultValues, name) {
  29663. var hasInitialized;
  29664. var RecordType = function Record(values) {
  29665. if (values instanceof RecordType) {
  29666. return values;
  29667. }
  29668. if (!(this instanceof RecordType)) {
  29669. return new RecordType(values);
  29670. }
  29671. if (!hasInitialized) {
  29672. hasInitialized = true;
  29673. var keys = Object.keys(defaultValues);
  29674. setProps(RecordTypePrototype, keys);
  29675. RecordTypePrototype.size = keys.length;
  29676. RecordTypePrototype._name = name;
  29677. RecordTypePrototype._keys = keys;
  29678. RecordTypePrototype._defaultValues = defaultValues;
  29679. }
  29680. this._map = Map(values);
  29681. };
  29682. var RecordTypePrototype = RecordType.prototype = Object.create(RecordPrototype);
  29683. RecordTypePrototype.constructor = RecordType;
  29684. return RecordType;
  29685. }
  29686. Record.prototype.toString = function() {
  29687. return this.__toString(recordName(this) + ' {', '}');
  29688. };
  29689. // @pragma Access
  29690. Record.prototype.has = function(k) {
  29691. return this._defaultValues.hasOwnProperty(k);
  29692. };
  29693. Record.prototype.get = function(k, notSetValue) {
  29694. if (!this.has(k)) {
  29695. return notSetValue;
  29696. }
  29697. var defaultVal = this._defaultValues[k];
  29698. return this._map ? this._map.get(k, defaultVal) : defaultVal;
  29699. };
  29700. // @pragma Modification
  29701. Record.prototype.clear = function() {
  29702. if (this.__ownerID) {
  29703. this._map && this._map.clear();
  29704. return this;
  29705. }
  29706. var RecordType = this.constructor;
  29707. return RecordType._empty || (RecordType._empty = makeRecord(this, emptyMap()));
  29708. };
  29709. Record.prototype.set = function(k, v) {
  29710. if (!this.has(k)) {
  29711. throw new Error('Cannot set unknown key "' + k + '" on ' + recordName(this));
  29712. }
  29713. var newMap = this._map && this._map.set(k, v);
  29714. if (this.__ownerID || newMap === this._map) {
  29715. return this;
  29716. }
  29717. return makeRecord(this, newMap);
  29718. };
  29719. Record.prototype.remove = function(k) {
  29720. if (!this.has(k)) {
  29721. return this;
  29722. }
  29723. var newMap = this._map && this._map.remove(k);
  29724. if (this.__ownerID || newMap === this._map) {
  29725. return this;
  29726. }
  29727. return makeRecord(this, newMap);
  29728. };
  29729. Record.prototype.wasAltered = function() {
  29730. return this._map.wasAltered();
  29731. };
  29732. Record.prototype.__iterator = function(type, reverse) {var this$0 = this;
  29733. return KeyedIterable(this._defaultValues).map(function(_, k) {return this$0.get(k)}).__iterator(type, reverse);
  29734. };
  29735. Record.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  29736. return KeyedIterable(this._defaultValues).map(function(_, k) {return this$0.get(k)}).__iterate(fn, reverse);
  29737. };
  29738. Record.prototype.__ensureOwner = function(ownerID) {
  29739. if (ownerID === this.__ownerID) {
  29740. return this;
  29741. }
  29742. var newMap = this._map && this._map.__ensureOwner(ownerID);
  29743. if (!ownerID) {
  29744. this.__ownerID = ownerID;
  29745. this._map = newMap;
  29746. return this;
  29747. }
  29748. return makeRecord(this, newMap, ownerID);
  29749. };
  29750. var RecordPrototype = Record.prototype;
  29751. RecordPrototype[DELETE] = RecordPrototype.remove;
  29752. RecordPrototype.deleteIn =
  29753. RecordPrototype.removeIn = MapPrototype.removeIn;
  29754. RecordPrototype.merge = MapPrototype.merge;
  29755. RecordPrototype.mergeWith = MapPrototype.mergeWith;
  29756. RecordPrototype.mergeIn = MapPrototype.mergeIn;
  29757. RecordPrototype.mergeDeep = MapPrototype.mergeDeep;
  29758. RecordPrototype.mergeDeepWith = MapPrototype.mergeDeepWith;
  29759. RecordPrototype.mergeDeepIn = MapPrototype.mergeDeepIn;
  29760. RecordPrototype.setIn = MapPrototype.setIn;
  29761. RecordPrototype.update = MapPrototype.update;
  29762. RecordPrototype.updateIn = MapPrototype.updateIn;
  29763. RecordPrototype.withMutations = MapPrototype.withMutations;
  29764. RecordPrototype.asMutable = MapPrototype.asMutable;
  29765. RecordPrototype.asImmutable = MapPrototype.asImmutable;
  29766. function makeRecord(likeRecord, map, ownerID) {
  29767. var record = Object.create(Object.getPrototypeOf(likeRecord));
  29768. record._map = map;
  29769. record.__ownerID = ownerID;
  29770. return record;
  29771. }
  29772. function recordName(record) {
  29773. return record._name || record.constructor.name || 'Record';
  29774. }
  29775. function setProps(prototype, names) {
  29776. try {
  29777. names.forEach(setProp.bind(undefined, prototype));
  29778. } catch (error) {
  29779. // Object.defineProperty failed. Probably IE8.
  29780. }
  29781. }
  29782. function setProp(prototype, name) {
  29783. Object.defineProperty(prototype, name, {
  29784. get: function() {
  29785. return this.get(name);
  29786. },
  29787. set: function(value) {
  29788. invariant(this.__ownerID, 'Cannot set on an immutable record.');
  29789. this.set(name, value);
  29790. }
  29791. });
  29792. }
  29793. createClass(Set, SetCollection);
  29794. // @pragma Construction
  29795. function Set(value) {
  29796. return value === null || value === undefined ? emptySet() :
  29797. isSet(value) && !isOrdered(value) ? value :
  29798. emptySet().withMutations(function(set ) {
  29799. var iter = SetIterable(value);
  29800. assertNotInfinite(iter.size);
  29801. iter.forEach(function(v ) {return set.add(v)});
  29802. });
  29803. }
  29804. Set.of = function(/*...values*/) {
  29805. return this(arguments);
  29806. };
  29807. Set.fromKeys = function(value) {
  29808. return this(KeyedIterable(value).keySeq());
  29809. };
  29810. Set.prototype.toString = function() {
  29811. return this.__toString('Set {', '}');
  29812. };
  29813. // @pragma Access
  29814. Set.prototype.has = function(value) {
  29815. return this._map.has(value);
  29816. };
  29817. // @pragma Modification
  29818. Set.prototype.add = function(value) {
  29819. return updateSet(this, this._map.set(value, true));
  29820. };
  29821. Set.prototype.remove = function(value) {
  29822. return updateSet(this, this._map.remove(value));
  29823. };
  29824. Set.prototype.clear = function() {
  29825. return updateSet(this, this._map.clear());
  29826. };
  29827. // @pragma Composition
  29828. Set.prototype.union = function() {var iters = SLICE$0.call(arguments, 0);
  29829. iters = iters.filter(function(x ) {return x.size !== 0});
  29830. if (iters.length === 0) {
  29831. return this;
  29832. }
  29833. if (this.size === 0 && !this.__ownerID && iters.length === 1) {
  29834. return this.constructor(iters[0]);
  29835. }
  29836. return this.withMutations(function(set ) {
  29837. for (var ii = 0; ii < iters.length; ii++) {
  29838. SetIterable(iters[ii]).forEach(function(value ) {return set.add(value)});
  29839. }
  29840. });
  29841. };
  29842. Set.prototype.intersect = function() {var iters = SLICE$0.call(arguments, 0);
  29843. if (iters.length === 0) {
  29844. return this;
  29845. }
  29846. iters = iters.map(function(iter ) {return SetIterable(iter)});
  29847. var originalSet = this;
  29848. return this.withMutations(function(set ) {
  29849. originalSet.forEach(function(value ) {
  29850. if (!iters.every(function(iter ) {return iter.includes(value)})) {
  29851. set.remove(value);
  29852. }
  29853. });
  29854. });
  29855. };
  29856. Set.prototype.subtract = function() {var iters = SLICE$0.call(arguments, 0);
  29857. if (iters.length === 0) {
  29858. return this;
  29859. }
  29860. iters = iters.map(function(iter ) {return SetIterable(iter)});
  29861. var originalSet = this;
  29862. return this.withMutations(function(set ) {
  29863. originalSet.forEach(function(value ) {
  29864. if (iters.some(function(iter ) {return iter.includes(value)})) {
  29865. set.remove(value);
  29866. }
  29867. });
  29868. });
  29869. };
  29870. Set.prototype.merge = function() {
  29871. return this.union.apply(this, arguments);
  29872. };
  29873. Set.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  29874. return this.union.apply(this, iters);
  29875. };
  29876. Set.prototype.sort = function(comparator) {
  29877. // Late binding
  29878. return OrderedSet(sortFactory(this, comparator));
  29879. };
  29880. Set.prototype.sortBy = function(mapper, comparator) {
  29881. // Late binding
  29882. return OrderedSet(sortFactory(this, comparator, mapper));
  29883. };
  29884. Set.prototype.wasAltered = function() {
  29885. return this._map.wasAltered();
  29886. };
  29887. Set.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  29888. return this._map.__iterate(function(_, k) {return fn(k, k, this$0)}, reverse);
  29889. };
  29890. Set.prototype.__iterator = function(type, reverse) {
  29891. return this._map.map(function(_, k) {return k}).__iterator(type, reverse);
  29892. };
  29893. Set.prototype.__ensureOwner = function(ownerID) {
  29894. if (ownerID === this.__ownerID) {
  29895. return this;
  29896. }
  29897. var newMap = this._map.__ensureOwner(ownerID);
  29898. if (!ownerID) {
  29899. this.__ownerID = ownerID;
  29900. this._map = newMap;
  29901. return this;
  29902. }
  29903. return this.__make(newMap, ownerID);
  29904. };
  29905. function isSet(maybeSet) {
  29906. return !!(maybeSet && maybeSet[IS_SET_SENTINEL]);
  29907. }
  29908. Set.isSet = isSet;
  29909. var IS_SET_SENTINEL = '@@__IMMUTABLE_SET__@@';
  29910. var SetPrototype = Set.prototype;
  29911. SetPrototype[IS_SET_SENTINEL] = true;
  29912. SetPrototype[DELETE] = SetPrototype.remove;
  29913. SetPrototype.mergeDeep = SetPrototype.merge;
  29914. SetPrototype.mergeDeepWith = SetPrototype.mergeWith;
  29915. SetPrototype.withMutations = MapPrototype.withMutations;
  29916. SetPrototype.asMutable = MapPrototype.asMutable;
  29917. SetPrototype.asImmutable = MapPrototype.asImmutable;
  29918. SetPrototype.__empty = emptySet;
  29919. SetPrototype.__make = makeSet;
  29920. function updateSet(set, newMap) {
  29921. if (set.__ownerID) {
  29922. set.size = newMap.size;
  29923. set._map = newMap;
  29924. return set;
  29925. }
  29926. return newMap === set._map ? set :
  29927. newMap.size === 0 ? set.__empty() :
  29928. set.__make(newMap);
  29929. }
  29930. function makeSet(map, ownerID) {
  29931. var set = Object.create(SetPrototype);
  29932. set.size = map ? map.size : 0;
  29933. set._map = map;
  29934. set.__ownerID = ownerID;
  29935. return set;
  29936. }
  29937. var EMPTY_SET;
  29938. function emptySet() {
  29939. return EMPTY_SET || (EMPTY_SET = makeSet(emptyMap()));
  29940. }
  29941. createClass(OrderedSet, Set);
  29942. // @pragma Construction
  29943. function OrderedSet(value) {
  29944. return value === null || value === undefined ? emptyOrderedSet() :
  29945. isOrderedSet(value) ? value :
  29946. emptyOrderedSet().withMutations(function(set ) {
  29947. var iter = SetIterable(value);
  29948. assertNotInfinite(iter.size);
  29949. iter.forEach(function(v ) {return set.add(v)});
  29950. });
  29951. }
  29952. OrderedSet.of = function(/*...values*/) {
  29953. return this(arguments);
  29954. };
  29955. OrderedSet.fromKeys = function(value) {
  29956. return this(KeyedIterable(value).keySeq());
  29957. };
  29958. OrderedSet.prototype.toString = function() {
  29959. return this.__toString('OrderedSet {', '}');
  29960. };
  29961. function isOrderedSet(maybeOrderedSet) {
  29962. return isSet(maybeOrderedSet) && isOrdered(maybeOrderedSet);
  29963. }
  29964. OrderedSet.isOrderedSet = isOrderedSet;
  29965. var OrderedSetPrototype = OrderedSet.prototype;
  29966. OrderedSetPrototype[IS_ORDERED_SENTINEL] = true;
  29967. OrderedSetPrototype.__empty = emptyOrderedSet;
  29968. OrderedSetPrototype.__make = makeOrderedSet;
  29969. function makeOrderedSet(map, ownerID) {
  29970. var set = Object.create(OrderedSetPrototype);
  29971. set.size = map ? map.size : 0;
  29972. set._map = map;
  29973. set.__ownerID = ownerID;
  29974. return set;
  29975. }
  29976. var EMPTY_ORDERED_SET;
  29977. function emptyOrderedSet() {
  29978. return EMPTY_ORDERED_SET || (EMPTY_ORDERED_SET = makeOrderedSet(emptyOrderedMap()));
  29979. }
  29980. createClass(Stack, IndexedCollection);
  29981. // @pragma Construction
  29982. function Stack(value) {
  29983. return value === null || value === undefined ? emptyStack() :
  29984. isStack(value) ? value :
  29985. emptyStack().unshiftAll(value);
  29986. }
  29987. Stack.of = function(/*...values*/) {
  29988. return this(arguments);
  29989. };
  29990. Stack.prototype.toString = function() {
  29991. return this.__toString('Stack [', ']');
  29992. };
  29993. // @pragma Access
  29994. Stack.prototype.get = function(index, notSetValue) {
  29995. var head = this._head;
  29996. index = wrapIndex(this, index);
  29997. while (head && index--) {
  29998. head = head.next;
  29999. }
  30000. return head ? head.value : notSetValue;
  30001. };
  30002. Stack.prototype.peek = function() {
  30003. return this._head && this._head.value;
  30004. };
  30005. // @pragma Modification
  30006. Stack.prototype.push = function(/*...values*/) {
  30007. if (arguments.length === 0) {
  30008. return this;
  30009. }
  30010. var newSize = this.size + arguments.length;
  30011. var head = this._head;
  30012. for (var ii = arguments.length - 1; ii >= 0; ii--) {
  30013. head = {
  30014. value: arguments[ii],
  30015. next: head
  30016. };
  30017. }
  30018. if (this.__ownerID) {
  30019. this.size = newSize;
  30020. this._head = head;
  30021. this.__hash = undefined;
  30022. this.__altered = true;
  30023. return this;
  30024. }
  30025. return makeStack(newSize, head);
  30026. };
  30027. Stack.prototype.pushAll = function(iter) {
  30028. iter = IndexedIterable(iter);
  30029. if (iter.size === 0) {
  30030. return this;
  30031. }
  30032. assertNotInfinite(iter.size);
  30033. var newSize = this.size;
  30034. var head = this._head;
  30035. iter.reverse().forEach(function(value ) {
  30036. newSize++;
  30037. head = {
  30038. value: value,
  30039. next: head
  30040. };
  30041. });
  30042. if (this.__ownerID) {
  30043. this.size = newSize;
  30044. this._head = head;
  30045. this.__hash = undefined;
  30046. this.__altered = true;
  30047. return this;
  30048. }
  30049. return makeStack(newSize, head);
  30050. };
  30051. Stack.prototype.pop = function() {
  30052. return this.slice(1);
  30053. };
  30054. Stack.prototype.unshift = function(/*...values*/) {
  30055. return this.push.apply(this, arguments);
  30056. };
  30057. Stack.prototype.unshiftAll = function(iter) {
  30058. return this.pushAll(iter);
  30059. };
  30060. Stack.prototype.shift = function() {
  30061. return this.pop.apply(this, arguments);
  30062. };
  30063. Stack.prototype.clear = function() {
  30064. if (this.size === 0) {
  30065. return this;
  30066. }
  30067. if (this.__ownerID) {
  30068. this.size = 0;
  30069. this._head = undefined;
  30070. this.__hash = undefined;
  30071. this.__altered = true;
  30072. return this;
  30073. }
  30074. return emptyStack();
  30075. };
  30076. Stack.prototype.slice = function(begin, end) {
  30077. if (wholeSlice(begin, end, this.size)) {
  30078. return this;
  30079. }
  30080. var resolvedBegin = resolveBegin(begin, this.size);
  30081. var resolvedEnd = resolveEnd(end, this.size);
  30082. if (resolvedEnd !== this.size) {
  30083. // super.slice(begin, end);
  30084. return IndexedCollection.prototype.slice.call(this, begin, end);
  30085. }
  30086. var newSize = this.size - resolvedBegin;
  30087. var head = this._head;
  30088. while (resolvedBegin--) {
  30089. head = head.next;
  30090. }
  30091. if (this.__ownerID) {
  30092. this.size = newSize;
  30093. this._head = head;
  30094. this.__hash = undefined;
  30095. this.__altered = true;
  30096. return this;
  30097. }
  30098. return makeStack(newSize, head);
  30099. };
  30100. // @pragma Mutability
  30101. Stack.prototype.__ensureOwner = function(ownerID) {
  30102. if (ownerID === this.__ownerID) {
  30103. return this;
  30104. }
  30105. if (!ownerID) {
  30106. this.__ownerID = ownerID;
  30107. this.__altered = false;
  30108. return this;
  30109. }
  30110. return makeStack(this.size, this._head, ownerID, this.__hash);
  30111. };
  30112. // @pragma Iteration
  30113. Stack.prototype.__iterate = function(fn, reverse) {
  30114. if (reverse) {
  30115. return this.reverse().__iterate(fn);
  30116. }
  30117. var iterations = 0;
  30118. var node = this._head;
  30119. while (node) {
  30120. if (fn(node.value, iterations++, this) === false) {
  30121. break;
  30122. }
  30123. node = node.next;
  30124. }
  30125. return iterations;
  30126. };
  30127. Stack.prototype.__iterator = function(type, reverse) {
  30128. if (reverse) {
  30129. return this.reverse().__iterator(type);
  30130. }
  30131. var iterations = 0;
  30132. var node = this._head;
  30133. return new Iterator(function() {
  30134. if (node) {
  30135. var value = node.value;
  30136. node = node.next;
  30137. return iteratorValue(type, iterations++, value);
  30138. }
  30139. return iteratorDone();
  30140. });
  30141. };
  30142. function isStack(maybeStack) {
  30143. return !!(maybeStack && maybeStack[IS_STACK_SENTINEL]);
  30144. }
  30145. Stack.isStack = isStack;
  30146. var IS_STACK_SENTINEL = '@@__IMMUTABLE_STACK__@@';
  30147. var StackPrototype = Stack.prototype;
  30148. StackPrototype[IS_STACK_SENTINEL] = true;
  30149. StackPrototype.withMutations = MapPrototype.withMutations;
  30150. StackPrototype.asMutable = MapPrototype.asMutable;
  30151. StackPrototype.asImmutable = MapPrototype.asImmutable;
  30152. StackPrototype.wasAltered = MapPrototype.wasAltered;
  30153. function makeStack(size, head, ownerID, hash) {
  30154. var map = Object.create(StackPrototype);
  30155. map.size = size;
  30156. map._head = head;
  30157. map.__ownerID = ownerID;
  30158. map.__hash = hash;
  30159. map.__altered = false;
  30160. return map;
  30161. }
  30162. var EMPTY_STACK;
  30163. function emptyStack() {
  30164. return EMPTY_STACK || (EMPTY_STACK = makeStack(0));
  30165. }
  30166. /**
  30167. * Contributes additional methods to a constructor
  30168. */
  30169. function mixin(ctor, methods) {
  30170. var keyCopier = function(key ) { ctor.prototype[key] = methods[key]; };
  30171. Object.keys(methods).forEach(keyCopier);
  30172. Object.getOwnPropertySymbols &&
  30173. Object.getOwnPropertySymbols(methods).forEach(keyCopier);
  30174. return ctor;
  30175. }
  30176. Iterable.Iterator = Iterator;
  30177. mixin(Iterable, {
  30178. // ### Conversion to other types
  30179. toArray: function() {
  30180. assertNotInfinite(this.size);
  30181. var array = new Array(this.size || 0);
  30182. this.valueSeq().__iterate(function(v, i) { array[i] = v; });
  30183. return array;
  30184. },
  30185. toIndexedSeq: function() {
  30186. return new ToIndexedSequence(this);
  30187. },
  30188. toJS: function() {
  30189. return this.toSeq().map(
  30190. function(value ) {return value && typeof value.toJS === 'function' ? value.toJS() : value}
  30191. ).__toJS();
  30192. },
  30193. toJSON: function() {
  30194. return this.toSeq().map(
  30195. function(value ) {return value && typeof value.toJSON === 'function' ? value.toJSON() : value}
  30196. ).__toJS();
  30197. },
  30198. toKeyedSeq: function() {
  30199. return new ToKeyedSequence(this, true);
  30200. },
  30201. toMap: function() {
  30202. // Use Late Binding here to solve the circular dependency.
  30203. return Map(this.toKeyedSeq());
  30204. },
  30205. toObject: function() {
  30206. assertNotInfinite(this.size);
  30207. var object = {};
  30208. this.__iterate(function(v, k) { object[k] = v; });
  30209. return object;
  30210. },
  30211. toOrderedMap: function() {
  30212. // Use Late Binding here to solve the circular dependency.
  30213. return OrderedMap(this.toKeyedSeq());
  30214. },
  30215. toOrderedSet: function() {
  30216. // Use Late Binding here to solve the circular dependency.
  30217. return OrderedSet(isKeyed(this) ? this.valueSeq() : this);
  30218. },
  30219. toSet: function() {
  30220. // Use Late Binding here to solve the circular dependency.
  30221. return Set(isKeyed(this) ? this.valueSeq() : this);
  30222. },
  30223. toSetSeq: function() {
  30224. return new ToSetSequence(this);
  30225. },
  30226. toSeq: function() {
  30227. return isIndexed(this) ? this.toIndexedSeq() :
  30228. isKeyed(this) ? this.toKeyedSeq() :
  30229. this.toSetSeq();
  30230. },
  30231. toStack: function() {
  30232. // Use Late Binding here to solve the circular dependency.
  30233. return Stack(isKeyed(this) ? this.valueSeq() : this);
  30234. },
  30235. toList: function() {
  30236. // Use Late Binding here to solve the circular dependency.
  30237. return List(isKeyed(this) ? this.valueSeq() : this);
  30238. },
  30239. // ### Common JavaScript methods and properties
  30240. toString: function() {
  30241. return '[Iterable]';
  30242. },
  30243. __toString: function(head, tail) {
  30244. if (this.size === 0) {
  30245. return head + tail;
  30246. }
  30247. return head + ' ' + this.toSeq().map(this.__toStringMapper).join(', ') + ' ' + tail;
  30248. },
  30249. // ### ES6 Collection methods (ES6 Array and Map)
  30250. concat: function() {var values = SLICE$0.call(arguments, 0);
  30251. return reify(this, concatFactory(this, values));
  30252. },
  30253. includes: function(searchValue) {
  30254. return this.some(function(value ) {return is(value, searchValue)});
  30255. },
  30256. entries: function() {
  30257. return this.__iterator(ITERATE_ENTRIES);
  30258. },
  30259. every: function(predicate, context) {
  30260. assertNotInfinite(this.size);
  30261. var returnValue = true;
  30262. this.__iterate(function(v, k, c) {
  30263. if (!predicate.call(context, v, k, c)) {
  30264. returnValue = false;
  30265. return false;
  30266. }
  30267. });
  30268. return returnValue;
  30269. },
  30270. filter: function(predicate, context) {
  30271. return reify(this, filterFactory(this, predicate, context, true));
  30272. },
  30273. find: function(predicate, context, notSetValue) {
  30274. var entry = this.findEntry(predicate, context);
  30275. return entry ? entry[1] : notSetValue;
  30276. },
  30277. findEntry: function(predicate, context) {
  30278. var found;
  30279. this.__iterate(function(v, k, c) {
  30280. if (predicate.call(context, v, k, c)) {
  30281. found = [k, v];
  30282. return false;
  30283. }
  30284. });
  30285. return found;
  30286. },
  30287. findLastEntry: function(predicate, context) {
  30288. return this.toSeq().reverse().findEntry(predicate, context);
  30289. },
  30290. forEach: function(sideEffect, context) {
  30291. assertNotInfinite(this.size);
  30292. return this.__iterate(context ? sideEffect.bind(context) : sideEffect);
  30293. },
  30294. join: function(separator) {
  30295. assertNotInfinite(this.size);
  30296. separator = separator !== undefined ? '' + separator : ',';
  30297. var joined = '';
  30298. var isFirst = true;
  30299. this.__iterate(function(v ) {
  30300. isFirst ? (isFirst = false) : (joined += separator);
  30301. joined += v !== null && v !== undefined ? v.toString() : '';
  30302. });
  30303. return joined;
  30304. },
  30305. keys: function() {
  30306. return this.__iterator(ITERATE_KEYS);
  30307. },
  30308. map: function(mapper, context) {
  30309. return reify(this, mapFactory(this, mapper, context));
  30310. },
  30311. reduce: function(reducer, initialReduction, context) {
  30312. assertNotInfinite(this.size);
  30313. var reduction;
  30314. var useFirst;
  30315. if (arguments.length < 2) {
  30316. useFirst = true;
  30317. } else {
  30318. reduction = initialReduction;
  30319. }
  30320. this.__iterate(function(v, k, c) {
  30321. if (useFirst) {
  30322. useFirst = false;
  30323. reduction = v;
  30324. } else {
  30325. reduction = reducer.call(context, reduction, v, k, c);
  30326. }
  30327. });
  30328. return reduction;
  30329. },
  30330. reduceRight: function(reducer, initialReduction, context) {
  30331. var reversed = this.toKeyedSeq().reverse();
  30332. return reversed.reduce.apply(reversed, arguments);
  30333. },
  30334. reverse: function() {
  30335. return reify(this, reverseFactory(this, true));
  30336. },
  30337. slice: function(begin, end) {
  30338. return reify(this, sliceFactory(this, begin, end, true));
  30339. },
  30340. some: function(predicate, context) {
  30341. return !this.every(not(predicate), context);
  30342. },
  30343. sort: function(comparator) {
  30344. return reify(this, sortFactory(this, comparator));
  30345. },
  30346. values: function() {
  30347. return this.__iterator(ITERATE_VALUES);
  30348. },
  30349. // ### More sequential methods
  30350. butLast: function() {
  30351. return this.slice(0, -1);
  30352. },
  30353. isEmpty: function() {
  30354. return this.size !== undefined ? this.size === 0 : !this.some(function() {return true});
  30355. },
  30356. count: function(predicate, context) {
  30357. return ensureSize(
  30358. predicate ? this.toSeq().filter(predicate, context) : this
  30359. );
  30360. },
  30361. countBy: function(grouper, context) {
  30362. return countByFactory(this, grouper, context);
  30363. },
  30364. equals: function(other) {
  30365. return deepEqual(this, other);
  30366. },
  30367. entrySeq: function() {
  30368. var iterable = this;
  30369. if (iterable._cache) {
  30370. // We cache as an entries array, so we can just return the cache!
  30371. return new ArraySeq(iterable._cache);
  30372. }
  30373. var entriesSequence = iterable.toSeq().map(entryMapper).toIndexedSeq();
  30374. entriesSequence.fromEntrySeq = function() {return iterable.toSeq()};
  30375. return entriesSequence;
  30376. },
  30377. filterNot: function(predicate, context) {
  30378. return this.filter(not(predicate), context);
  30379. },
  30380. findLast: function(predicate, context, notSetValue) {
  30381. return this.toKeyedSeq().reverse().find(predicate, context, notSetValue);
  30382. },
  30383. first: function() {
  30384. return this.find(returnTrue);
  30385. },
  30386. flatMap: function(mapper, context) {
  30387. return reify(this, flatMapFactory(this, mapper, context));
  30388. },
  30389. flatten: function(depth) {
  30390. return reify(this, flattenFactory(this, depth, true));
  30391. },
  30392. fromEntrySeq: function() {
  30393. return new FromEntriesSequence(this);
  30394. },
  30395. get: function(searchKey, notSetValue) {
  30396. return this.find(function(_, key) {return is(key, searchKey)}, undefined, notSetValue);
  30397. },
  30398. getIn: function(searchKeyPath, notSetValue) {
  30399. var nested = this;
  30400. // Note: in an ES6 environment, we would prefer:
  30401. // for (var key of searchKeyPath) {
  30402. var iter = forceIterator(searchKeyPath);
  30403. var step;
  30404. while (!(step = iter.next()).done) {
  30405. var key = step.value;
  30406. nested = nested && nested.get ? nested.get(key, NOT_SET) : NOT_SET;
  30407. if (nested === NOT_SET) {
  30408. return notSetValue;
  30409. }
  30410. }
  30411. return nested;
  30412. },
  30413. groupBy: function(grouper, context) {
  30414. return groupByFactory(this, grouper, context);
  30415. },
  30416. has: function(searchKey) {
  30417. return this.get(searchKey, NOT_SET) !== NOT_SET;
  30418. },
  30419. hasIn: function(searchKeyPath) {
  30420. return this.getIn(searchKeyPath, NOT_SET) !== NOT_SET;
  30421. },
  30422. isSubset: function(iter) {
  30423. iter = typeof iter.includes === 'function' ? iter : Iterable(iter);
  30424. return this.every(function(value ) {return iter.includes(value)});
  30425. },
  30426. isSuperset: function(iter) {
  30427. iter = typeof iter.isSubset === 'function' ? iter : Iterable(iter);
  30428. return iter.isSubset(this);
  30429. },
  30430. keySeq: function() {
  30431. return this.toSeq().map(keyMapper).toIndexedSeq();
  30432. },
  30433. last: function() {
  30434. return this.toSeq().reverse().first();
  30435. },
  30436. max: function(comparator) {
  30437. return maxFactory(this, comparator);
  30438. },
  30439. maxBy: function(mapper, comparator) {
  30440. return maxFactory(this, comparator, mapper);
  30441. },
  30442. min: function(comparator) {
  30443. return maxFactory(this, comparator ? neg(comparator) : defaultNegComparator);
  30444. },
  30445. minBy: function(mapper, comparator) {
  30446. return maxFactory(this, comparator ? neg(comparator) : defaultNegComparator, mapper);
  30447. },
  30448. rest: function() {
  30449. return this.slice(1);
  30450. },
  30451. skip: function(amount) {
  30452. return this.slice(Math.max(0, amount));
  30453. },
  30454. skipLast: function(amount) {
  30455. return reify(this, this.toSeq().reverse().skip(amount).reverse());
  30456. },
  30457. skipWhile: function(predicate, context) {
  30458. return reify(this, skipWhileFactory(this, predicate, context, true));
  30459. },
  30460. skipUntil: function(predicate, context) {
  30461. return this.skipWhile(not(predicate), context);
  30462. },
  30463. sortBy: function(mapper, comparator) {
  30464. return reify(this, sortFactory(this, comparator, mapper));
  30465. },
  30466. take: function(amount) {
  30467. return this.slice(0, Math.max(0, amount));
  30468. },
  30469. takeLast: function(amount) {
  30470. return reify(this, this.toSeq().reverse().take(amount).reverse());
  30471. },
  30472. takeWhile: function(predicate, context) {
  30473. return reify(this, takeWhileFactory(this, predicate, context));
  30474. },
  30475. takeUntil: function(predicate, context) {
  30476. return this.takeWhile(not(predicate), context);
  30477. },
  30478. valueSeq: function() {
  30479. return this.toIndexedSeq();
  30480. },
  30481. // ### Hashable Object
  30482. hashCode: function() {
  30483. return this.__hash || (this.__hash = hashIterable(this));
  30484. }
  30485. // ### Internal
  30486. // abstract __iterate(fn, reverse)
  30487. // abstract __iterator(type, reverse)
  30488. });
  30489. // var IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
  30490. // var IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
  30491. // var IS_INDEXED_SENTINEL = '@@__IMMUTABLE_INDEXED__@@';
  30492. // var IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
  30493. var IterablePrototype = Iterable.prototype;
  30494. IterablePrototype[IS_ITERABLE_SENTINEL] = true;
  30495. IterablePrototype[ITERATOR_SYMBOL] = IterablePrototype.values;
  30496. IterablePrototype.__toJS = IterablePrototype.toArray;
  30497. IterablePrototype.__toStringMapper = quoteString;
  30498. IterablePrototype.inspect =
  30499. IterablePrototype.toSource = function() { return this.toString(); };
  30500. IterablePrototype.chain = IterablePrototype.flatMap;
  30501. IterablePrototype.contains = IterablePrototype.includes;
  30502. // Temporary warning about using length
  30503. (function () {
  30504. try {
  30505. Object.defineProperty(IterablePrototype, 'length', {
  30506. get: function () {
  30507. if (!Iterable.noLengthWarning) {
  30508. var stack;
  30509. try {
  30510. throw new Error();
  30511. } catch (error) {
  30512. stack = error.stack;
  30513. }
  30514. if (stack.indexOf('_wrapObject') === -1) {
  30515. console && console.warn && console.warn(
  30516. 'iterable.length has been deprecated, '+
  30517. 'use iterable.size or iterable.count(). '+
  30518. 'This warning will become a silent error in a future version. ' +
  30519. stack
  30520. );
  30521. return this.size;
  30522. }
  30523. }
  30524. }
  30525. });
  30526. } catch (e) {}
  30527. })();
  30528. mixin(KeyedIterable, {
  30529. // ### More sequential methods
  30530. flip: function() {
  30531. return reify(this, flipFactory(this));
  30532. },
  30533. findKey: function(predicate, context) {
  30534. var entry = this.findEntry(predicate, context);
  30535. return entry && entry[0];
  30536. },
  30537. findLastKey: function(predicate, context) {
  30538. return this.toSeq().reverse().findKey(predicate, context);
  30539. },
  30540. keyOf: function(searchValue) {
  30541. return this.findKey(function(value ) {return is(value, searchValue)});
  30542. },
  30543. lastKeyOf: function(searchValue) {
  30544. return this.findLastKey(function(value ) {return is(value, searchValue)});
  30545. },
  30546. mapEntries: function(mapper, context) {var this$0 = this;
  30547. var iterations = 0;
  30548. return reify(this,
  30549. this.toSeq().map(
  30550. function(v, k) {return mapper.call(context, [k, v], iterations++, this$0)}
  30551. ).fromEntrySeq()
  30552. );
  30553. },
  30554. mapKeys: function(mapper, context) {var this$0 = this;
  30555. return reify(this,
  30556. this.toSeq().flip().map(
  30557. function(k, v) {return mapper.call(context, k, v, this$0)}
  30558. ).flip()
  30559. );
  30560. }
  30561. });
  30562. var KeyedIterablePrototype = KeyedIterable.prototype;
  30563. KeyedIterablePrototype[IS_KEYED_SENTINEL] = true;
  30564. KeyedIterablePrototype[ITERATOR_SYMBOL] = IterablePrototype.entries;
  30565. KeyedIterablePrototype.__toJS = IterablePrototype.toObject;
  30566. KeyedIterablePrototype.__toStringMapper = function(v, k) {return JSON.stringify(k) + ': ' + quoteString(v)};
  30567. mixin(IndexedIterable, {
  30568. // ### Conversion to other types
  30569. toKeyedSeq: function() {
  30570. return new ToKeyedSequence(this, false);
  30571. },
  30572. // ### ES6 Collection methods (ES6 Array and Map)
  30573. filter: function(predicate, context) {
  30574. return reify(this, filterFactory(this, predicate, context, false));
  30575. },
  30576. findIndex: function(predicate, context) {
  30577. var entry = this.findEntry(predicate, context);
  30578. return entry ? entry[0] : -1;
  30579. },
  30580. indexOf: function(searchValue) {
  30581. var key = this.toKeyedSeq().keyOf(searchValue);
  30582. return key === undefined ? -1 : key;
  30583. },
  30584. lastIndexOf: function(searchValue) {
  30585. var key = this.toKeyedSeq().reverse().keyOf(searchValue);
  30586. return key === undefined ? -1 : key;
  30587. // var index =
  30588. // return this.toSeq().reverse().indexOf(searchValue);
  30589. },
  30590. reverse: function() {
  30591. return reify(this, reverseFactory(this, false));
  30592. },
  30593. slice: function(begin, end) {
  30594. return reify(this, sliceFactory(this, begin, end, false));
  30595. },
  30596. splice: function(index, removeNum /*, ...values*/) {
  30597. var numArgs = arguments.length;
  30598. removeNum = Math.max(removeNum | 0, 0);
  30599. if (numArgs === 0 || (numArgs === 2 && !removeNum)) {
  30600. return this;
  30601. }
  30602. // If index is negative, it should resolve relative to the size of the
  30603. // collection. However size may be expensive to compute if not cached, so
  30604. // only call count() if the number is in fact negative.
  30605. index = resolveBegin(index, index < 0 ? this.count() : this.size);
  30606. var spliced = this.slice(0, index);
  30607. return reify(
  30608. this,
  30609. numArgs === 1 ?
  30610. spliced :
  30611. spliced.concat(arrCopy(arguments, 2), this.slice(index + removeNum))
  30612. );
  30613. },
  30614. // ### More collection methods
  30615. findLastIndex: function(predicate, context) {
  30616. var key = this.toKeyedSeq().findLastKey(predicate, context);
  30617. return key === undefined ? -1 : key;
  30618. },
  30619. first: function() {
  30620. return this.get(0);
  30621. },
  30622. flatten: function(depth) {
  30623. return reify(this, flattenFactory(this, depth, false));
  30624. },
  30625. get: function(index, notSetValue) {
  30626. index = wrapIndex(this, index);
  30627. return (index < 0 || (this.size === Infinity ||
  30628. (this.size !== undefined && index > this.size))) ?
  30629. notSetValue :
  30630. this.find(function(_, key) {return key === index}, undefined, notSetValue);
  30631. },
  30632. has: function(index) {
  30633. index = wrapIndex(this, index);
  30634. return index >= 0 && (this.size !== undefined ?
  30635. this.size === Infinity || index < this.size :
  30636. this.indexOf(index) !== -1
  30637. );
  30638. },
  30639. interpose: function(separator) {
  30640. return reify(this, interposeFactory(this, separator));
  30641. },
  30642. interleave: function(/*...iterables*/) {
  30643. var iterables = [this].concat(arrCopy(arguments));
  30644. var zipped = zipWithFactory(this.toSeq(), IndexedSeq.of, iterables);
  30645. var interleaved = zipped.flatten(true);
  30646. if (zipped.size) {
  30647. interleaved.size = zipped.size * iterables.length;
  30648. }
  30649. return reify(this, interleaved);
  30650. },
  30651. last: function() {
  30652. return this.get(-1);
  30653. },
  30654. skipWhile: function(predicate, context) {
  30655. return reify(this, skipWhileFactory(this, predicate, context, false));
  30656. },
  30657. zip: function(/*, ...iterables */) {
  30658. var iterables = [this].concat(arrCopy(arguments));
  30659. return reify(this, zipWithFactory(this, defaultZipper, iterables));
  30660. },
  30661. zipWith: function(zipper/*, ...iterables */) {
  30662. var iterables = arrCopy(arguments);
  30663. iterables[0] = this;
  30664. return reify(this, zipWithFactory(this, zipper, iterables));
  30665. }
  30666. });
  30667. IndexedIterable.prototype[IS_INDEXED_SENTINEL] = true;
  30668. IndexedIterable.prototype[IS_ORDERED_SENTINEL] = true;
  30669. mixin(SetIterable, {
  30670. // ### ES6 Collection methods (ES6 Array and Map)
  30671. get: function(value, notSetValue) {
  30672. return this.has(value) ? value : notSetValue;
  30673. },
  30674. includes: function(value) {
  30675. return this.has(value);
  30676. },
  30677. // ### More sequential methods
  30678. keySeq: function() {
  30679. return this.valueSeq();
  30680. }
  30681. });
  30682. SetIterable.prototype.has = IterablePrototype.includes;
  30683. // Mixin subclasses
  30684. mixin(KeyedSeq, KeyedIterable.prototype);
  30685. mixin(IndexedSeq, IndexedIterable.prototype);
  30686. mixin(SetSeq, SetIterable.prototype);
  30687. mixin(KeyedCollection, KeyedIterable.prototype);
  30688. mixin(IndexedCollection, IndexedIterable.prototype);
  30689. mixin(SetCollection, SetIterable.prototype);
  30690. // #pragma Helper functions
  30691. function keyMapper(v, k) {
  30692. return k;
  30693. }
  30694. function entryMapper(v, k) {
  30695. return [k, v];
  30696. }
  30697. function not(predicate) {
  30698. return function() {
  30699. return !predicate.apply(this, arguments);
  30700. }
  30701. }
  30702. function neg(predicate) {
  30703. return function() {
  30704. return -predicate.apply(this, arguments);
  30705. }
  30706. }
  30707. function quoteString(value) {
  30708. return typeof value === 'string' ? JSON.stringify(value) : value;
  30709. }
  30710. function defaultZipper() {
  30711. return arrCopy(arguments);
  30712. }
  30713. function defaultNegComparator(a, b) {
  30714. return a < b ? 1 : a > b ? -1 : 0;
  30715. }
  30716. function hashIterable(iterable) {
  30717. if (iterable.size === Infinity) {
  30718. return 0;
  30719. }
  30720. var ordered = isOrdered(iterable);
  30721. var keyed = isKeyed(iterable);
  30722. var h = ordered ? 1 : 0;
  30723. var size = iterable.__iterate(
  30724. keyed ?
  30725. ordered ?
  30726. function(v, k) { h = 31 * h + hashMerge(hash(v), hash(k)) | 0; } :
  30727. function(v, k) { h = h + hashMerge(hash(v), hash(k)) | 0; } :
  30728. ordered ?
  30729. function(v ) { h = 31 * h + hash(v) | 0; } :
  30730. function(v ) { h = h + hash(v) | 0; }
  30731. );
  30732. return murmurHashOfSize(size, h);
  30733. }
  30734. function murmurHashOfSize(size, h) {
  30735. h = imul(h, 0xCC9E2D51);
  30736. h = imul(h << 15 | h >>> -15, 0x1B873593);
  30737. h = imul(h << 13 | h >>> -13, 5);
  30738. h = (h + 0xE6546B64 | 0) ^ size;
  30739. h = imul(h ^ h >>> 16, 0x85EBCA6B);
  30740. h = imul(h ^ h >>> 13, 0xC2B2AE35);
  30741. h = smi(h ^ h >>> 16);
  30742. return h;
  30743. }
  30744. function hashMerge(a, b) {
  30745. return a ^ b + 0x9E3779B9 + (a << 6) + (a >> 2) | 0; // int
  30746. }
  30747. var Immutable = {
  30748. Iterable: Iterable,
  30749. Seq: Seq,
  30750. Collection: Collection,
  30751. Map: Map,
  30752. OrderedMap: OrderedMap,
  30753. List: List,
  30754. Stack: Stack,
  30755. Set: Set,
  30756. OrderedSet: OrderedSet,
  30757. Record: Record,
  30758. Range: Range,
  30759. Repeat: Repeat,
  30760. is: is,
  30761. fromJS: fromJS
  30762. };
  30763. return Immutable;
  30764. }));
  30765. });
  30766. var dist$2 = createCommonjsModule(function (module, exports) {
  30767. (function webpackUniversalModuleDefinition(root, factory) {
  30768. module.exports = factory(React);
  30769. })(window, function(__WEBPACK_EXTERNAL_MODULE__2__) {
  30770. return /******/ (function(modules) { // webpackBootstrap
  30771. /******/ // The module cache
  30772. /******/ var installedModules = {};
  30773. /******/
  30774. /******/ // The require function
  30775. /******/ function __webpack_require__(moduleId) {
  30776. /******/
  30777. /******/ // Check if module is in cache
  30778. /******/ if(installedModules[moduleId]) {
  30779. /******/ return installedModules[moduleId].exports;
  30780. /******/ }
  30781. /******/ // Create a new module (and put it into the cache)
  30782. /******/ var module = installedModules[moduleId] = {
  30783. /******/ i: moduleId,
  30784. /******/ l: false,
  30785. /******/ exports: {}
  30786. /******/ };
  30787. /******/
  30788. /******/ // Execute the module function
  30789. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  30790. /******/
  30791. /******/ // Flag the module as loaded
  30792. /******/ module.l = true;
  30793. /******/
  30794. /******/ // Return the exports of the module
  30795. /******/ return module.exports;
  30796. /******/ }
  30797. /******/
  30798. /******/
  30799. /******/ // expose the modules object (__webpack_modules__)
  30800. /******/ __webpack_require__.m = modules;
  30801. /******/
  30802. /******/ // expose the module cache
  30803. /******/ __webpack_require__.c = installedModules;
  30804. /******/
  30805. /******/ // define getter function for harmony exports
  30806. /******/ __webpack_require__.d = function(exports, name, getter) {
  30807. /******/ if(!__webpack_require__.o(exports, name)) {
  30808. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  30809. /******/ }
  30810. /******/ };
  30811. /******/
  30812. /******/ // define __esModule on exports
  30813. /******/ __webpack_require__.r = function(exports) {
  30814. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  30815. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  30816. /******/ }
  30817. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  30818. /******/ };
  30819. /******/
  30820. /******/ // create a fake namespace object
  30821. /******/ // mode & 1: value is a module id, require it
  30822. /******/ // mode & 2: merge all properties of value into the ns
  30823. /******/ // mode & 4: return value when already ns object
  30824. /******/ // mode & 8|1: behave like require
  30825. /******/ __webpack_require__.t = function(value, mode) {
  30826. /******/ if(mode & 1) value = __webpack_require__(value);
  30827. /******/ if(mode & 8) return value;
  30828. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  30829. /******/ var ns = Object.create(null);
  30830. /******/ __webpack_require__.r(ns);
  30831. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  30832. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  30833. /******/ return ns;
  30834. /******/ };
  30835. /******/
  30836. /******/ // getDefaultExport function for compatibility with non-harmony modules
  30837. /******/ __webpack_require__.n = function(module) {
  30838. /******/ var getter = module && module.__esModule ?
  30839. /******/ function getDefault() { return module['default']; } :
  30840. /******/ function getModuleExports() { return module; };
  30841. /******/ __webpack_require__.d(getter, 'a', getter);
  30842. /******/ return getter;
  30843. /******/ };
  30844. /******/
  30845. /******/ // Object.prototype.hasOwnProperty.call
  30846. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  30847. /******/
  30848. /******/ // __webpack_public_path__
  30849. /******/ __webpack_require__.p = "/";
  30850. /******/
  30851. /******/
  30852. /******/ // Load entry module and return exports
  30853. /******/ return __webpack_require__(__webpack_require__.s = 20);
  30854. /******/ })
  30855. /************************************************************************/
  30856. /******/ ([
  30857. /* 0 */
  30858. /***/ (function(module, exports, __webpack_require__) {
  30859. Object.defineProperty(exports, "__esModule", {
  30860. value: true
  30861. });
  30862. var compressImage = exports.compressImage = function compressImage(url) {
  30863. var width = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1280;
  30864. var height = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 800;
  30865. return new Promise(function (resolve, reject) {
  30866. var image = new Image();
  30867. image.src = url;
  30868. image.onerror = function (error) {
  30869. reject(error);
  30870. };
  30871. image.onload = function () {
  30872. try {
  30873. var compressCanvas = document.createElement('canvas');
  30874. var scale = this.width > width || this.height > height ? this.width > this.height ? width / this.width : height / this.height : 1;
  30875. compressCanvas.width = this.width * scale;
  30876. compressCanvas.height = this.height * scale;
  30877. var canvasContext = compressCanvas.getContext('2d');
  30878. canvasContext.drawImage(this, 0, 0, compressCanvas.width, compressCanvas.height);
  30879. resolve({
  30880. url: compressCanvas.toDataURL('image/png', 1),
  30881. width: compressCanvas.width,
  30882. height: compressCanvas.height
  30883. });
  30884. } catch (error) {
  30885. reject(error);
  30886. }
  30887. };
  30888. });
  30889. };
  30890. /***/ }),
  30891. /* 1 */
  30892. /***/ (function(module, exports, __webpack_require__) {
  30893. Object.defineProperty(exports, "__esModule", {
  30894. value: true
  30895. });
  30896. var UniqueIndex = exports.UniqueIndex = function UniqueIndex() {
  30897. if (isNaN(window.__BRAFT_MM_UNIQUE_INDEX__)) {
  30898. window.__BRAFT_MM_UNIQUE_INDEX__ = 1;
  30899. } else {
  30900. window.__BRAFT_MM_UNIQUE_INDEX__ += 1;
  30901. }
  30902. return window.__BRAFT_MM_UNIQUE_INDEX__;
  30903. };
  30904. /***/ }),
  30905. /* 2 */
  30906. /***/ (function(module, exports) {
  30907. module.exports = __WEBPACK_EXTERNAL_MODULE__2__;
  30908. /***/ }),
  30909. /* 3 */
  30910. /***/ (function(module, exports, __webpack_require__) {
  30911. Object.defineProperty(exports, "__esModule", {
  30912. value: true
  30913. });
  30914. exports.default = {
  30915. remove: 'Kaldır',
  30916. cancel: 'İptal',
  30917. confirm: 'Onayla',
  30918. insert: 'Seçilenleri ekle',
  30919. width: 'Genişlik',
  30920. height: 'Yükseklik',
  30921. image: 'Resim',
  30922. video: 'Görüntü',
  30923. audio: 'Ses',
  30924. embed: 'Nesne göm',
  30925. caption: 'Kitaplık',
  30926. dragTip: 'Tıkla ya da dosya sürükle',
  30927. dropTip: 'Yüklemek için sürükleyin',
  30928. selectAll: 'Tümünü seç',
  30929. deselect: 'Seçimi kaldır',
  30930. removeSelected: 'Seçilenleri kaldır',
  30931. externalInputPlaceHolder: 'Kaynak adı|Kaynak bağlantısı',
  30932. externalInputTip: 'Kaynak asını ve bağlantısını "|" ile ayırın ve Enter\' a basın.',
  30933. addLocalFile: 'Yerel\' den ekle',
  30934. addExternalSource: 'Harici kaynaktan ekle',
  30935. unnamedItem: 'Adlandırılmamış giriş',
  30936. confirmInsert: 'Seçilenleri ekle'
  30937. };
  30938. /***/ }),
  30939. /* 4 */
  30940. /***/ (function(module, exports, __webpack_require__) {
  30941. Object.defineProperty(exports, "__esModule", {
  30942. value: true
  30943. });
  30944. exports.default = {
  30945. remove: '削除する',
  30946. cancel: 'キャンセル',
  30947. confirm: '確認する',
  30948. insert: '選択したアイテムを挿入',
  30949. width: '幅',
  30950. height: '身長',
  30951. image: '絵',
  30952. video: 'ビデオ',
  30953. audio: '音声',
  30954. embed: '埋め込みメディア',
  30955. caption: 'メディアライブラリー',
  30956. dragTip: 'ファイルをこの位置までクリックまたはドラッグします',
  30957. dropTip: 'アップロードするマウスを放します',
  30958. selectAll: 'すべて選択',
  30959. deselect: '選択を解除',
  30960. removeSelected: '選択したアイテムを削除',
  30961. externalInputPlaceHolder: 'リソース名|リソースアドレス',
  30962. externalInputTip: 'リソース名とリソースアドレスは "|"で区切ります。',
  30963. addLocalFile: 'ローカルリソースを追加する',
  30964. addExternalSource: 'ネットワークリソースを追加する',
  30965. unnamedItem: '名前のないアイテム',
  30966. confirmInsert: '選択したアイテムを挿入'
  30967. };
  30968. /***/ }),
  30969. /* 5 */
  30970. /***/ (function(module, exports, __webpack_require__) {
  30971. Object.defineProperty(exports, "__esModule", {
  30972. value: true
  30973. });
  30974. exports.default = {
  30975. remove: '삭제',
  30976. cancel: '취소',
  30977. confirm: '확인',
  30978. insert: '선택한항목삽입',
  30979. width: '너비',
  30980. height: '높이',
  30981. image: '그림',
  30982. video: '비디오',
  30983. audio: '오디오',
  30984. embed: '임베디드미디어',
  30985. caption: '미디어라이브러리',
  30986. dragTip: '파일을 클릭하거나이 지점으로 드래그하십시오.',
  30987. dropTip: '업로드하려면마우스를놓으십시오.',
  30988. selectAll: '모두 선택',
  30989. deselect: '선택 취소',
  30990. removeSelected: '선택한 항목 삭제',
  30991. externalInputPlaceHolder: '리소스 이름 | 리소스 주소',
  30992. externalInputTip: '자원 이름과 자원 주소를 "|"',
  30993. addLocalFile: '로컬 리소스 추가',
  30994. addExternalSource: '네트워크 리소스 추가',
  30995. unnamedItem: '이름없는 항목',
  30996. confirmInsert: '선택한 항목 삽입'
  30997. };
  30998. /***/ }),
  30999. /* 6 */
  31000. /***/ (function(module, exports, __webpack_require__) {
  31001. Object.defineProperty(exports, "__esModule", {
  31002. value: true
  31003. });
  31004. exports.default = {
  31005. remove: 'Usuń',
  31006. cancel: 'Anuluj',
  31007. confirm: 'Potwierdź',
  31008. insert: 'Wstaw wybrane elementy',
  31009. width: 'Szerokość',
  31010. height: 'Wysokość',
  31011. image: 'Obraz',
  31012. video: 'Wideo',
  31013. audio: 'Dźwięk',
  31014. embed: 'Obiekt',
  31015. caption: 'Biblioteka mediów',
  31016. dragTip: 'Kliknij lub przenieś tu pliki',
  31017. dropTip: 'Upuść aby dodać plik',
  31018. selectAll: 'Zaznacz wszystko',
  31019. deselect: 'Odznacz',
  31020. removeSelected: 'Usuń wybrane',
  31021. externalInputPlaceHolder: 'Nazwa źródła|Adres URL',
  31022. externalInputTip: 'Oddziel nazwę i adres URL źródła z pomocą "|", Potwierdź Enter-em',
  31023. addLocalFile: 'Dodaj z komputera',
  31024. addExternalSource: 'Dodaj z Internetu',
  31025. unnamedItem: 'Bez nazwy',
  31026. confirmInsert: 'Dodaj wybrane elementy'
  31027. };
  31028. /***/ }),
  31029. /* 7 */
  31030. /***/ (function(module, exports, __webpack_require__) {
  31031. Object.defineProperty(exports, "__esModule", {
  31032. value: true
  31033. });
  31034. exports.default = {
  31035. remove: '删除',
  31036. cancel: '取消',
  31037. confirm: '确认',
  31038. insert: '插入所选项目',
  31039. width: '宽度',
  31040. height: '高度',
  31041. image: '图片',
  31042. video: '视频',
  31043. audio: '音频',
  31044. embed: '嵌入式媒体',
  31045. caption: '媒体库',
  31046. dragTip: '点击或拖动文件至此',
  31047. dropTip: '放开鼠标以上传',
  31048. selectAll: '选择全部',
  31049. deselect: '取消选择',
  31050. removeSelected: '删除选中项目',
  31051. externalInputPlaceHolder: '资源名称|资源地址',
  31052. externalInputTip: '使用“|”分隔资源名称和资源地址',
  31053. addLocalFile: '添加本地资源',
  31054. addExternalSource: '添加网络资源',
  31055. unnamedItem: '未命名项目',
  31056. confirmInsert: '插入选中项目'
  31057. };
  31058. /***/ }),
  31059. /* 8 */
  31060. /***/ (function(module, exports, __webpack_require__) {
  31061. Object.defineProperty(exports, "__esModule", {
  31062. value: true
  31063. });
  31064. exports.default = {
  31065. remove: '删除',
  31066. cancel: '取消',
  31067. confirm: '确认',
  31068. insert: '插入所选项目',
  31069. width: '宽度',
  31070. height: '高度',
  31071. image: '图片',
  31072. video: '视频',
  31073. audio: '音频',
  31074. embed: '嵌入式媒体',
  31075. caption: '媒体库',
  31076. dragTip: '点击或拖动文件至此',
  31077. dropTip: '放开鼠标以上传',
  31078. selectAll: '选择全部',
  31079. deselect: '取消选择',
  31080. removeSelected: '删除选中项目',
  31081. externalInputPlaceHolder: '资源名称|资源地址',
  31082. externalInputTip: '使用“|”分隔资源名称和资源地址',
  31083. addLocalFile: '添加本地资源',
  31084. addExternalSource: '添加网络资源',
  31085. unnamedItem: '未命名项目',
  31086. confirmInsert: '插入选中项目'
  31087. };
  31088. /***/ }),
  31089. /* 9 */
  31090. /***/ (function(module, exports, __webpack_require__) {
  31091. Object.defineProperty(exports, "__esModule", {
  31092. value: true
  31093. });
  31094. exports.default = {
  31095. remove: 'Remove',
  31096. cancel: 'Cancel',
  31097. confirm: 'Confirm',
  31098. insert: 'Insert Selected Items',
  31099. width: 'Width',
  31100. height: 'Height',
  31101. image: 'Image',
  31102. video: 'Video',
  31103. audio: 'Audio',
  31104. embed: 'Embed',
  31105. caption: 'Media Library',
  31106. dragTip: 'Click Or Drag Files Here',
  31107. dropTip: 'Drop To Upload',
  31108. selectAll: 'Select All',
  31109. deselect: 'Deselect',
  31110. removeSelected: 'Remove Selected Items',
  31111. externalInputPlaceHolder: 'Source Name|Source URL',
  31112. externalInputTip: 'Split source name and source URL with "|", confirm by hit Enter.',
  31113. addLocalFile: 'Add from local',
  31114. addExternalSource: 'Add from Internet',
  31115. unnamedItem: 'Unnamed Item',
  31116. confirmInsert: 'Insert selected items'
  31117. };
  31118. /***/ }),
  31119. /* 10 */
  31120. /***/ (function(module, exports, __webpack_require__) {
  31121. Object.defineProperty(exports, "__esModule", {
  31122. value: true
  31123. });
  31124. var _en = __webpack_require__(9);
  31125. var _en2 = _interopRequireDefault(_en);
  31126. var _zh = __webpack_require__(8);
  31127. var _zh2 = _interopRequireDefault(_zh);
  31128. var _zhHant = __webpack_require__(7);
  31129. var _zhHant2 = _interopRequireDefault(_zhHant);
  31130. var _pl = __webpack_require__(6);
  31131. var _pl2 = _interopRequireDefault(_pl);
  31132. var _kr = __webpack_require__(5);
  31133. var _kr2 = _interopRequireDefault(_kr);
  31134. var _jpn = __webpack_require__(4);
  31135. var _jpn2 = _interopRequireDefault(_jpn);
  31136. var _tr = __webpack_require__(3);
  31137. var _tr2 = _interopRequireDefault(_tr);
  31138. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  31139. exports.default = {
  31140. "en": _en2.default,
  31141. "zh": _zh2.default,
  31142. "zh-hant": _zhHant2.default,
  31143. "pl": _pl2.default,
  31144. "kr": _kr2.default,
  31145. "jpn": _jpn2.default,
  31146. "tr": _tr2.default
  31147. };
  31148. /***/ }),
  31149. /* 11 */
  31150. /***/ (function(module, exports) {
  31151. /**
  31152. * When source maps are enabled, `style-loader` uses a link element with a data-uri to
  31153. * embed the css on the page. This breaks all relative urls because now they are relative to a
  31154. * bundle instead of the current page.
  31155. *
  31156. * One solution is to only use full urls, but that may be impossible.
  31157. *
  31158. * Instead, this function "fixes" the relative urls to be absolute according to the current page location.
  31159. *
  31160. * A rudimentary test suite is located at `test/fixUrls.js` and can be run via the `npm test` command.
  31161. *
  31162. */
  31163. module.exports = function (css) {
  31164. // get current location
  31165. var location = typeof window !== "undefined" && window.location;
  31166. if (!location) {
  31167. throw new Error("fixUrls requires window.location");
  31168. }
  31169. // blank or null?
  31170. if (!css || typeof css !== "string") {
  31171. return css;
  31172. }
  31173. var baseUrl = location.protocol + "//" + location.host;
  31174. var currentDir = baseUrl + location.pathname.replace(/\/[^\/]*$/, "/");
  31175. // convert each url(...)
  31176. /*
  31177. This regular expression is just a way to recursively match brackets within
  31178. a string.
  31179. /url\s*\( = Match on the word "url" with any whitespace after it and then a parens
  31180. ( = Start a capturing group
  31181. (?: = Start a non-capturing group
  31182. [^)(] = Match anything that isn't a parentheses
  31183. | = OR
  31184. \( = Match a start parentheses
  31185. (?: = Start another non-capturing groups
  31186. [^)(]+ = Match anything that isn't a parentheses
  31187. | = OR
  31188. \( = Match a start parentheses
  31189. [^)(]* = Match anything that isn't a parentheses
  31190. \) = Match a end parentheses
  31191. ) = End Group
  31192. *\) = Match anything and then a close parens
  31193. ) = Close non-capturing group
  31194. * = Match anything
  31195. ) = Close capturing group
  31196. \) = Match a close parens
  31197. /gi = Get all matches, not the first. Be case insensitive.
  31198. */
  31199. var fixedCss = css.replace(/url\s*\(((?:[^)(]|\((?:[^)(]+|\([^)(]*\))*\))*)\)/gi, function(fullMatch, origUrl) {
  31200. // strip quotes (if they exist)
  31201. var unquotedOrigUrl = origUrl
  31202. .trim()
  31203. .replace(/^"(.*)"$/, function(o, $1){ return $1; })
  31204. .replace(/^'(.*)'$/, function(o, $1){ return $1; });
  31205. // already a full url? no change
  31206. if (/^(#|data:|http:\/\/|https:\/\/|file:\/\/\/|\s*$)/i.test(unquotedOrigUrl)) {
  31207. return fullMatch;
  31208. }
  31209. // convert the url to a full url
  31210. var newUrl;
  31211. if (unquotedOrigUrl.indexOf("//") === 0) {
  31212. //TODO: should we add protocol?
  31213. newUrl = unquotedOrigUrl;
  31214. } else if (unquotedOrigUrl.indexOf("/") === 0) {
  31215. // path should be relative to the base url
  31216. newUrl = baseUrl + unquotedOrigUrl; // already starts with '/'
  31217. } else {
  31218. // path should be relative to current directory
  31219. newUrl = currentDir + unquotedOrigUrl.replace(/^\.\//, ""); // Strip leading './'
  31220. }
  31221. // send back the fixed url(...)
  31222. return "url(" + JSON.stringify(newUrl) + ")";
  31223. });
  31224. // send back the fixed css
  31225. return fixedCss;
  31226. };
  31227. /***/ }),
  31228. /* 12 */
  31229. /***/ (function(module, exports, __webpack_require__) {
  31230. /*
  31231. MIT License http://www.opensource.org/licenses/mit-license.php
  31232. Author Tobias Koppers @sokra
  31233. */
  31234. var stylesInDom = {};
  31235. var memoize = function (fn) {
  31236. var memo;
  31237. return function () {
  31238. if (typeof memo === "undefined") memo = fn.apply(this, arguments);
  31239. return memo;
  31240. };
  31241. };
  31242. var isOldIE = memoize(function () {
  31243. // Test for IE <= 9 as proposed by Browserhacks
  31244. // @see http://browserhacks.com/#hack-e71d8692f65334173fee715c222cb805
  31245. // Tests for existence of standard globals is to allow style-loader
  31246. // to operate correctly into non-standard environments
  31247. // @see https://github.com/webpack-contrib/style-loader/issues/177
  31248. return window && document && document.all && !window.atob;
  31249. });
  31250. var getTarget = function (target) {
  31251. return document.querySelector(target);
  31252. };
  31253. var getElement = (function (fn) {
  31254. var memo = {};
  31255. return function(target) {
  31256. // If passing function in options, then use it for resolve "head" element.
  31257. // Useful for Shadow Root style i.e
  31258. // {
  31259. // insertInto: function () { return document.querySelector("#foo").shadowRoot }
  31260. // }
  31261. if (typeof target === 'function') {
  31262. return target();
  31263. }
  31264. if (typeof memo[target] === "undefined") {
  31265. var styleTarget = getTarget.call(this, target);
  31266. // Special case to return head of iframe instead of iframe itself
  31267. if (window.HTMLIFrameElement && styleTarget instanceof window.HTMLIFrameElement) {
  31268. try {
  31269. // This will throw an exception if access to iframe is blocked
  31270. // due to cross-origin restrictions
  31271. styleTarget = styleTarget.contentDocument.head;
  31272. } catch(e) {
  31273. styleTarget = null;
  31274. }
  31275. }
  31276. memo[target] = styleTarget;
  31277. }
  31278. return memo[target]
  31279. };
  31280. })();
  31281. var singleton = null;
  31282. var singletonCounter = 0;
  31283. var stylesInsertedAtTop = [];
  31284. var fixUrls = __webpack_require__(11);
  31285. module.exports = function(list, options) {
  31286. if (typeof DEBUG !== "undefined" && DEBUG) {
  31287. if (typeof document !== "object") throw new Error("The style-loader cannot be used in a non-browser environment");
  31288. }
  31289. options = options || {};
  31290. options.attrs = typeof options.attrs === "object" ? options.attrs : {};
  31291. // Force single-tag solution on IE6-9, which has a hard limit on the # of <style>
  31292. // tags it will allow on a page
  31293. if (!options.singleton && typeof options.singleton !== "boolean") options.singleton = isOldIE();
  31294. // By default, add <style> tags to the <head> element
  31295. if (!options.insertInto) options.insertInto = "head";
  31296. // By default, add <style> tags to the bottom of the target
  31297. if (!options.insertAt) options.insertAt = "bottom";
  31298. var styles = listToStyles(list, options);
  31299. addStylesToDom(styles, options);
  31300. return function update (newList) {
  31301. var mayRemove = [];
  31302. for (var i = 0; i < styles.length; i++) {
  31303. var item = styles[i];
  31304. var domStyle = stylesInDom[item.id];
  31305. domStyle.refs--;
  31306. mayRemove.push(domStyle);
  31307. }
  31308. if(newList) {
  31309. var newStyles = listToStyles(newList, options);
  31310. addStylesToDom(newStyles, options);
  31311. }
  31312. for (var i = 0; i < mayRemove.length; i++) {
  31313. var domStyle = mayRemove[i];
  31314. if(domStyle.refs === 0) {
  31315. for (var j = 0; j < domStyle.parts.length; j++) domStyle.parts[j]();
  31316. delete stylesInDom[domStyle.id];
  31317. }
  31318. }
  31319. };
  31320. };
  31321. function addStylesToDom (styles, options) {
  31322. for (var i = 0; i < styles.length; i++) {
  31323. var item = styles[i];
  31324. var domStyle = stylesInDom[item.id];
  31325. if(domStyle) {
  31326. domStyle.refs++;
  31327. for(var j = 0; j < domStyle.parts.length; j++) {
  31328. domStyle.parts[j](item.parts[j]);
  31329. }
  31330. for(; j < item.parts.length; j++) {
  31331. domStyle.parts.push(addStyle(item.parts[j], options));
  31332. }
  31333. } else {
  31334. var parts = [];
  31335. for(var j = 0; j < item.parts.length; j++) {
  31336. parts.push(addStyle(item.parts[j], options));
  31337. }
  31338. stylesInDom[item.id] = {id: item.id, refs: 1, parts: parts};
  31339. }
  31340. }
  31341. }
  31342. function listToStyles (list, options) {
  31343. var styles = [];
  31344. var newStyles = {};
  31345. for (var i = 0; i < list.length; i++) {
  31346. var item = list[i];
  31347. var id = options.base ? item[0] + options.base : item[0];
  31348. var css = item[1];
  31349. var media = item[2];
  31350. var sourceMap = item[3];
  31351. var part = {css: css, media: media, sourceMap: sourceMap};
  31352. if(!newStyles[id]) styles.push(newStyles[id] = {id: id, parts: [part]});
  31353. else newStyles[id].parts.push(part);
  31354. }
  31355. return styles;
  31356. }
  31357. function insertStyleElement (options, style) {
  31358. var target = getElement(options.insertInto);
  31359. if (!target) {
  31360. throw new Error("Couldn't find a style target. This probably means that the value for the 'insertInto' parameter is invalid.");
  31361. }
  31362. var lastStyleElementInsertedAtTop = stylesInsertedAtTop[stylesInsertedAtTop.length - 1];
  31363. if (options.insertAt === "top") {
  31364. if (!lastStyleElementInsertedAtTop) {
  31365. target.insertBefore(style, target.firstChild);
  31366. } else if (lastStyleElementInsertedAtTop.nextSibling) {
  31367. target.insertBefore(style, lastStyleElementInsertedAtTop.nextSibling);
  31368. } else {
  31369. target.appendChild(style);
  31370. }
  31371. stylesInsertedAtTop.push(style);
  31372. } else if (options.insertAt === "bottom") {
  31373. target.appendChild(style);
  31374. } else if (typeof options.insertAt === "object" && options.insertAt.before) {
  31375. var nextSibling = getElement(options.insertInto + " " + options.insertAt.before);
  31376. target.insertBefore(style, nextSibling);
  31377. } else {
  31378. 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");
  31379. }
  31380. }
  31381. function removeStyleElement (style) {
  31382. if (style.parentNode === null) return false;
  31383. style.parentNode.removeChild(style);
  31384. var idx = stylesInsertedAtTop.indexOf(style);
  31385. if(idx >= 0) {
  31386. stylesInsertedAtTop.splice(idx, 1);
  31387. }
  31388. }
  31389. function createStyleElement (options) {
  31390. var style = document.createElement("style");
  31391. if(options.attrs.type === undefined) {
  31392. options.attrs.type = "text/css";
  31393. }
  31394. addAttrs(style, options.attrs);
  31395. insertStyleElement(options, style);
  31396. return style;
  31397. }
  31398. function createLinkElement (options) {
  31399. var link = document.createElement("link");
  31400. if(options.attrs.type === undefined) {
  31401. options.attrs.type = "text/css";
  31402. }
  31403. options.attrs.rel = "stylesheet";
  31404. addAttrs(link, options.attrs);
  31405. insertStyleElement(options, link);
  31406. return link;
  31407. }
  31408. function addAttrs (el, attrs) {
  31409. Object.keys(attrs).forEach(function (key) {
  31410. el.setAttribute(key, attrs[key]);
  31411. });
  31412. }
  31413. function addStyle (obj, options) {
  31414. var style, update, remove, result;
  31415. // If a transform function was defined, run it on the css
  31416. if (options.transform && obj.css) {
  31417. result = options.transform(obj.css);
  31418. if (result) {
  31419. // If transform returns a value, use that instead of the original css.
  31420. // This allows running runtime transformations on the css.
  31421. obj.css = result;
  31422. } else {
  31423. // If the transform function returns a falsy value, don't add this css.
  31424. // This allows conditional loading of css
  31425. return function() {
  31426. // noop
  31427. };
  31428. }
  31429. }
  31430. if (options.singleton) {
  31431. var styleIndex = singletonCounter++;
  31432. style = singleton || (singleton = createStyleElement(options));
  31433. update = applyToSingletonTag.bind(null, style, styleIndex, false);
  31434. remove = applyToSingletonTag.bind(null, style, styleIndex, true);
  31435. } else if (
  31436. obj.sourceMap &&
  31437. typeof URL === "function" &&
  31438. typeof URL.createObjectURL === "function" &&
  31439. typeof URL.revokeObjectURL === "function" &&
  31440. typeof Blob === "function" &&
  31441. typeof btoa === "function"
  31442. ) {
  31443. style = createLinkElement(options);
  31444. update = updateLink.bind(null, style, options);
  31445. remove = function () {
  31446. removeStyleElement(style);
  31447. if(style.href) URL.revokeObjectURL(style.href);
  31448. };
  31449. } else {
  31450. style = createStyleElement(options);
  31451. update = applyToTag.bind(null, style);
  31452. remove = function () {
  31453. removeStyleElement(style);
  31454. };
  31455. }
  31456. update(obj);
  31457. return function updateStyle (newObj) {
  31458. if (newObj) {
  31459. if (
  31460. newObj.css === obj.css &&
  31461. newObj.media === obj.media &&
  31462. newObj.sourceMap === obj.sourceMap
  31463. ) {
  31464. return;
  31465. }
  31466. update(obj = newObj);
  31467. } else {
  31468. remove();
  31469. }
  31470. };
  31471. }
  31472. var replaceText = (function () {
  31473. var textStore = [];
  31474. return function (index, replacement) {
  31475. textStore[index] = replacement;
  31476. return textStore.filter(Boolean).join('\n');
  31477. };
  31478. })();
  31479. function applyToSingletonTag (style, index, remove, obj) {
  31480. var css = remove ? "" : obj.css;
  31481. if (style.styleSheet) {
  31482. style.styleSheet.cssText = replaceText(index, css);
  31483. } else {
  31484. var cssNode = document.createTextNode(css);
  31485. var childNodes = style.childNodes;
  31486. if (childNodes[index]) style.removeChild(childNodes[index]);
  31487. if (childNodes.length) {
  31488. style.insertBefore(cssNode, childNodes[index]);
  31489. } else {
  31490. style.appendChild(cssNode);
  31491. }
  31492. }
  31493. }
  31494. function applyToTag (style, obj) {
  31495. var css = obj.css;
  31496. var media = obj.media;
  31497. if(media) {
  31498. style.setAttribute("media", media);
  31499. }
  31500. if(style.styleSheet) {
  31501. style.styleSheet.cssText = css;
  31502. } else {
  31503. while(style.firstChild) {
  31504. style.removeChild(style.firstChild);
  31505. }
  31506. style.appendChild(document.createTextNode(css));
  31507. }
  31508. }
  31509. function updateLink (link, options, obj) {
  31510. var css = obj.css;
  31511. var sourceMap = obj.sourceMap;
  31512. /*
  31513. If convertToAbsoluteUrls isn't defined, but sourcemaps are enabled
  31514. and there is no publicPath defined then lets turn convertToAbsoluteUrls
  31515. on by default. Otherwise default to the convertToAbsoluteUrls option
  31516. directly
  31517. */
  31518. var autoFixUrls = options.convertToAbsoluteUrls === undefined && sourceMap;
  31519. if (options.convertToAbsoluteUrls || autoFixUrls) {
  31520. css = fixUrls(css);
  31521. }
  31522. if (sourceMap) {
  31523. // http://stackoverflow.com/a/26603875
  31524. css += "\n/*# sourceMappingURL=data:application/json;base64," + btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap)))) + " */";
  31525. }
  31526. var blob = new Blob([css], { type: "text/css" });
  31527. var oldSrc = link.href;
  31528. link.href = URL.createObjectURL(blob);
  31529. if(oldSrc) URL.revokeObjectURL(oldSrc);
  31530. }
  31531. /***/ }),
  31532. /* 13 */
  31533. /***/ (function(module, exports) {
  31534. 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=";
  31535. /***/ }),
  31536. /* 14 */
  31537. /***/ (function(module, exports) {
  31538. /*
  31539. MIT License http://www.opensource.org/licenses/mit-license.php
  31540. Author Tobias Koppers @sokra
  31541. */
  31542. // css base code, injected by the css-loader
  31543. module.exports = function(useSourceMap) {
  31544. var list = [];
  31545. // return the list of modules as css string
  31546. list.toString = function toString() {
  31547. return this.map(function (item) {
  31548. var content = cssWithMappingToString(item, useSourceMap);
  31549. if(item[2]) {
  31550. return "@media " + item[2] + "{" + content + "}";
  31551. } else {
  31552. return content;
  31553. }
  31554. }).join("");
  31555. };
  31556. // import a list of modules into the list
  31557. list.i = function(modules, mediaQuery) {
  31558. if(typeof modules === "string")
  31559. modules = [[null, modules, ""]];
  31560. var alreadyImportedModules = {};
  31561. for(var i = 0; i < this.length; i++) {
  31562. var id = this[i][0];
  31563. if(typeof id === "number")
  31564. alreadyImportedModules[id] = true;
  31565. }
  31566. for(i = 0; i < modules.length; i++) {
  31567. var item = modules[i];
  31568. // skip already imported module
  31569. // this implementation is not 100% perfect for weird media query combinations
  31570. // when a module is imported multiple times with different media queries.
  31571. // I hope this will never occur (Hey this way we have smaller bundles)
  31572. if(typeof item[0] !== "number" || !alreadyImportedModules[item[0]]) {
  31573. if(mediaQuery && !item[2]) {
  31574. item[2] = mediaQuery;
  31575. } else if(mediaQuery) {
  31576. item[2] = "(" + item[2] + ") and (" + mediaQuery + ")";
  31577. }
  31578. list.push(item);
  31579. }
  31580. }
  31581. };
  31582. return list;
  31583. };
  31584. function cssWithMappingToString(item, useSourceMap) {
  31585. var content = item[1] || '';
  31586. var cssMapping = item[3];
  31587. if (!cssMapping) {
  31588. return content;
  31589. }
  31590. if (useSourceMap && typeof btoa === 'function') {
  31591. var sourceMapping = toComment(cssMapping);
  31592. var sourceURLs = cssMapping.sources.map(function (source) {
  31593. return '/*# sourceURL=' + cssMapping.sourceRoot + source + ' */'
  31594. });
  31595. return [content].concat(sourceURLs).concat([sourceMapping]).join('\n');
  31596. }
  31597. return [content].join('\n');
  31598. }
  31599. // Adapted from convert-source-map (MIT)
  31600. function toComment(sourceMap) {
  31601. // eslint-disable-next-line no-undef
  31602. var base64 = btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap))));
  31603. var data = 'sourceMappingURL=data:application/json;charset=utf-8;base64,' + base64;
  31604. return '/*# ' + data + ' */';
  31605. }
  31606. /***/ }),
  31607. /* 15 */
  31608. /***/ (function(module, exports) {
  31609. module.exports = function escape(url) {
  31610. if (typeof url !== 'string') {
  31611. return url
  31612. }
  31613. // If url is already wrapped in quotes, remove them
  31614. if (/^['"].*['"]$/.test(url)) {
  31615. url = url.slice(1, -1);
  31616. }
  31617. // Should url be wrapped?
  31618. // See https://drafts.csswg.org/css-values-3/#urls
  31619. if (/["'() \t\n]/.test(url)) {
  31620. return '"' + url.replace(/"/g, '\\"').replace(/\n/g, '\\n') + '"'
  31621. }
  31622. return url
  31623. };
  31624. /***/ }),
  31625. /* 16 */
  31626. /***/ (function(module, exports, __webpack_require__) {
  31627. var escape = __webpack_require__(15);
  31628. exports = module.exports = __webpack_require__(14)(false);
  31629. // imports
  31630. // module
  31631. 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", ""]);
  31632. // exports
  31633. /***/ }),
  31634. /* 17 */
  31635. /***/ (function(module, exports, __webpack_require__) {
  31636. var content = __webpack_require__(16);
  31637. if(typeof content === 'string') content = [[module.i, content, '']];
  31638. var transform;
  31639. var options = {"hmr":true};
  31640. options.transform = transform;
  31641. options.insertInto = undefined;
  31642. var update = __webpack_require__(12)(content, options);
  31643. if(content.locals) module.exports = content.locals;
  31644. /***/ }),
  31645. /* 18 */
  31646. /***/ (function(module, exports, __webpack_require__) {
  31647. Object.defineProperty(exports, "__esModule", {
  31648. value: true
  31649. });
  31650. 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; };
  31651. 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; }; }();
  31652. __webpack_require__(17);
  31653. var _react = __webpack_require__(2);
  31654. var _react2 = _interopRequireDefault(_react);
  31655. var _base = __webpack_require__(1);
  31656. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  31657. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  31658. 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; }
  31659. 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; }
  31660. var defaultAccepts = {
  31661. image: 'image/png,image/jpeg,image/gif,image/webp,image/apng,image/svg',
  31662. video: 'video/mp4',
  31663. audio: 'audio/mp3'
  31664. };
  31665. var BraftFinderView = function (_React$Component) {
  31666. _inherits(BraftFinderView, _React$Component);
  31667. function BraftFinderView(props) {
  31668. _classCallCheck(this, BraftFinderView);
  31669. var _this = _possibleConstructorReturn(this, (BraftFinderView.__proto__ || Object.getPrototypeOf(BraftFinderView)).call(this, props));
  31670. _this.toggleSelectItem = function (event) {
  31671. var itemId = event.currentTarget.dataset.id;
  31672. var item = _this.controller.getMediaItem(itemId);
  31673. if (!item) {
  31674. return false;
  31675. }
  31676. if (item.selected) {
  31677. if (!_this.props.onBeforeDeselect || _this.props.onBeforeDeselect([item], _this.controller.getItems()) !== false) {
  31678. _this.controller.deselectMediaItem(itemId);
  31679. _this.props.onDeselect && _this.props.onDeselect([item], _this.controller.getItems());
  31680. }
  31681. } else {
  31682. if (!_this.props.onBeforeSelect || _this.props.onBeforeSelect([item], _this.controller.getItems()) !== false) {
  31683. _this.controller.selectMediaItem(itemId);
  31684. _this.props.onSelect && _this.props.onSelect([item], _this.controller.getItems());
  31685. }
  31686. }
  31687. };
  31688. _this.removeItem = function (event) {
  31689. var itemId = event.currentTarget.dataset.id;
  31690. var item = _this.controller.getMediaItem(itemId);
  31691. if (!item) {
  31692. return false;
  31693. }
  31694. if (!_this.props.onBeforeRemove || _this.props.onBeforeRemove([item], _this.controller.getItems()) !== false) {
  31695. _this.controller.removeMediaItem(itemId);
  31696. _this.props.onRemove && _this.props.onRemove([item], _this.controller.getItems());
  31697. }
  31698. event.stopPropagation();
  31699. };
  31700. _this.selectAllItems = function () {
  31701. var allItems = _this.controller.getItems();
  31702. if (!_this.props.onBeforeSelect || _this.props.onBeforeSelect(allItems, allItems) !== false) {
  31703. _this.controller.selectAllItems();
  31704. _this.props.onSelect && _this.props.onSelect(allItems, allItems);
  31705. }
  31706. };
  31707. _this.deselectAllItems = function () {
  31708. var allItems = _this.controller.getItems();
  31709. if (!_this.props.onBeforeDeselect || _this.props.onBeforeDeselect(allItems, allItems) !== false) {
  31710. _this.controller.deselectAllItems();
  31711. _this.props.onDeselect && _this.props.onDeselect(allItems, allItems);
  31712. }
  31713. };
  31714. _this.removeSelectedItems = function () {
  31715. var selectedItems = _this.controller.getSelectedItems();
  31716. if (!_this.props.onBeforeRemove || _this.props.onBeforeRemove(selectedItems, _this.controller.getItems()) !== false) {
  31717. _this.controller.removeSelectedItems();
  31718. _this.props.onRemove && _this.props.onRemove(selectedItems, _this.controller.getItems());
  31719. }
  31720. };
  31721. _this.handleDragLeave = function (event) {
  31722. event.preventDefault();
  31723. _this.dragCounter--;
  31724. _this.dragCounter === 0 && _this.setState({
  31725. draging: false
  31726. });
  31727. };
  31728. _this.handleDragDrop = function (event) {
  31729. event.preventDefault();
  31730. _this.dragCounter = 0;
  31731. _this.setState({ draging: false });
  31732. _this.reslovePickedFiles(event);
  31733. };
  31734. _this.handleDragEnter = function (event) {
  31735. event.preventDefault();
  31736. _this.dragCounter++;
  31737. _this.setState({ draging: true });
  31738. };
  31739. _this.reslovePickedFiles = function (event) {
  31740. event.persist();
  31741. var _ref = event.type === 'drop' ? event.dataTransfer : event.target,
  31742. files = _ref.files;
  31743. if (_this.props.onFileSelect) {
  31744. var result = _this.props.onFileSelect(files);
  31745. if (result === false) {
  31746. return false;
  31747. } else if (result instanceof FileList || result instanceof Array) {
  31748. files = result;
  31749. }
  31750. }
  31751. var accepts = _extends({}, defaultAccepts, _this.props.accepts);
  31752. _this.controller.resolveFiles({
  31753. files: files,
  31754. onItemReady: function onItemReady(_ref2) {
  31755. var id = _ref2.id;
  31756. return _this.controller.selectMediaItem(id);
  31757. },
  31758. onAllReady: function onAllReady() {
  31759. return event.target.value = null;
  31760. }
  31761. }, 0, accepts);
  31762. };
  31763. _this.inputExternal = function (event) {
  31764. _this.setState({
  31765. external: _extends({}, _this.state.external, {
  31766. url: event.target.value
  31767. })
  31768. });
  31769. };
  31770. _this.switchExternalType = function (event) {
  31771. _this.setState({
  31772. external: _extends({}, _this.state.external, { type: event.target.dataset.type })
  31773. });
  31774. };
  31775. _this.confirmAddExternal = function (event) {
  31776. if (event.target.nodeName.toLowerCase() === 'button' || event.keyCode === 13) {
  31777. var _this$state$external = _this.state.external,
  31778. url = _this$state$external.url,
  31779. type = _this$state$external.type;
  31780. url = url.split('|');
  31781. var name = url.length > 1 ? url[0] : _this.props.language.unnamedItem;
  31782. url = url.length > 1 ? url[1] : url[0];
  31783. var thumbnail = type === 'IMAGE' ? url : null;
  31784. _this.controller.addItems([{
  31785. thumbnail: thumbnail, url: url, name: name, type: type,
  31786. id: new Date().getTime() + '_' + (0, _base.UniqueIndex)(),
  31787. uploading: false,
  31788. uploadProgress: 1,
  31789. selected: true
  31790. }]);
  31791. _this.setState({
  31792. showExternalForm: false,
  31793. external: {
  31794. url: '',
  31795. type: 'IMAGE'
  31796. }
  31797. });
  31798. }
  31799. };
  31800. _this.toggleExternalForm = function () {
  31801. _this.setState({
  31802. showExternalForm: !_this.state.showExternalForm
  31803. });
  31804. };
  31805. _this.cancelInsert = function () {
  31806. _this.props.onCancel && _this.props.onCancel();
  31807. };
  31808. _this.confirmInsert = function () {
  31809. var selectedItems = _this.controller.getSelectedItems();
  31810. if (_this.props.onBeforeInsert) {
  31811. var filteredItems = _this.props.onBeforeInsert(selectedItems);
  31812. if (filteredItems && filteredItems instanceof Array) {
  31813. _this.controller.deselectAllItems();
  31814. _this.props.onInsert && _this.props.onInsert(filteredItems);
  31815. } else if (filteredItems !== false) {
  31816. _this.controller.deselectAllItems();
  31817. _this.props.onInsert && _this.props.onInsert(selectedItems);
  31818. }
  31819. } else {
  31820. _this.controller.deselectAllItems();
  31821. _this.props.onInsert && _this.props.onInsert(selectedItems);
  31822. }
  31823. };
  31824. _this.dragCounter = 0;
  31825. _this.controller = _this.props.controller;
  31826. var initialItems = _this.controller.getItems();
  31827. _this.state = {
  31828. draging: false,
  31829. error: false,
  31830. confirmable: initialItems.find(function (_ref3) {
  31831. var selected = _ref3.selected;
  31832. return selected;
  31833. }),
  31834. external: {
  31835. url: '',
  31836. type: 'IMAGE'
  31837. },
  31838. fileAccept: '',
  31839. showExternalForm: false,
  31840. allowExternal: false,
  31841. items: initialItems
  31842. };
  31843. _this.changeListenerId = _this.controller.onChange(function (items) {
  31844. _this.setState({ items: items, confirmable: items.find(function (_ref4) {
  31845. var selected = _ref4.selected;
  31846. return selected;
  31847. }) });
  31848. _this.props.onChange && _this.props.onChange(items);
  31849. });
  31850. return _this;
  31851. }
  31852. _createClass(BraftFinderView, [{
  31853. key: 'mapPropsToState',
  31854. value: function mapPropsToState(props) {
  31855. var accepts = props.accepts,
  31856. externals = props.externals;
  31857. accepts = _extends({}, defaultAccepts, accepts);
  31858. var fileAccept = !accepts ? [defaultAccepts.image, defaultAccepts.video, defaultAccepts.audio].join(',') : [accepts.image, accepts.video, accepts.audio].filter(function (item) {
  31859. return item;
  31860. }).join(',');
  31861. var external = {
  31862. url: '',
  31863. type: externals.image ? 'IMAGE' : externals.audio ? 'AUDIO' : externals.video ? 'VIDEO' : externals.embed ? 'EMBED' : ''
  31864. };
  31865. return {
  31866. fileAccept: fileAccept,
  31867. external: external,
  31868. allowExternal: externals && (externals.image || externals.audio || externals.video || externals.embed)
  31869. };
  31870. }
  31871. }, {
  31872. key: 'componentDidMount',
  31873. value: function componentDidMount() {
  31874. this.setState(this.mapPropsToState(this.props));
  31875. }
  31876. }, {
  31877. key: 'componentWillReceiveProps',
  31878. value: function componentWillReceiveProps(nextProps) {
  31879. this.setState(this.mapPropsToState(nextProps));
  31880. }
  31881. }, {
  31882. key: 'componentWillUnmount',
  31883. value: function componentWillUnmount() {
  31884. this.controller.offChange(this.changeListenerId);
  31885. }
  31886. }, {
  31887. key: 'render',
  31888. value: function render() {
  31889. var _props = this.props,
  31890. language = _props.language,
  31891. externals = _props.externals;
  31892. var _state = this.state,
  31893. items = _state.items,
  31894. draging = _state.draging,
  31895. confirmable = _state.confirmable,
  31896. fileAccept = _state.fileAccept,
  31897. external = _state.external,
  31898. showExternalForm = _state.showExternalForm,
  31899. allowExternal = _state.allowExternal;
  31900. return _react2.default.createElement(
  31901. 'div',
  31902. { className: 'braft-finder' },
  31903. _react2.default.createElement(
  31904. 'div',
  31905. {
  31906. onDragEnter: this.handleDragEnter,
  31907. onDragOver: this.handleDragEnter,
  31908. onDragLeave: this.handleDragLeave,
  31909. onDrop: this.handleDragDrop,
  31910. className: 'bf-uploader'
  31911. },
  31912. _react2.default.createElement(
  31913. 'div',
  31914. { className: "bf-drag-uploader " + (draging || !items.length ? 'active ' : ' ') + (draging ? 'draging' : '') },
  31915. _react2.default.createElement(
  31916. 'span',
  31917. { className: 'bf-drag-tip' },
  31918. _react2.default.createElement('input', { accept: fileAccept, onChange: this.reslovePickedFiles, multiple: true, type: 'file' }),
  31919. draging ? language.dropTip : language.dragTip
  31920. )
  31921. ),
  31922. items.length ? _react2.default.createElement(
  31923. 'div',
  31924. { className: 'bf-list-wrap' },
  31925. _react2.default.createElement(
  31926. 'div',
  31927. { className: 'bf-list-tools' },
  31928. _react2.default.createElement(
  31929. 'span',
  31930. { onClick: this.selectAllItems, className: 'bf-select-all' },
  31931. _react2.default.createElement('i', { className: 'braft-icon-done' }),
  31932. ' ',
  31933. language.selectAll
  31934. ),
  31935. _react2.default.createElement(
  31936. 'span',
  31937. { onClick: this.deselectAllItems, disabled: !confirmable, className: 'bf-deselect-all' },
  31938. _react2.default.createElement('i', { className: 'braft-icon-close' }),
  31939. ' ',
  31940. language.deselect
  31941. ),
  31942. _react2.default.createElement(
  31943. 'span',
  31944. { onClick: this.removeSelectedItems, disabled: !confirmable, className: 'bf-remove-selected' },
  31945. _react2.default.createElement('i', { className: 'braft-icon-bin' }),
  31946. ' ',
  31947. language.removeSelected
  31948. )
  31949. ),
  31950. this.buildItemList()
  31951. ) : null,
  31952. showExternalForm && allowExternal ? _react2.default.createElement(
  31953. 'div',
  31954. { className: 'bf-add-external' },
  31955. _react2.default.createElement(
  31956. 'div',
  31957. { className: 'bf-external-form' },
  31958. _react2.default.createElement(
  31959. 'div',
  31960. { className: 'bf-external-input' },
  31961. _react2.default.createElement(
  31962. 'div',
  31963. null,
  31964. _react2.default.createElement('input', { onKeyDown: this.confirmAddExternal, value: external.url, onChange: this.inputExternal, placeholder: language.externalInputPlaceHolder })
  31965. ),
  31966. _react2.default.createElement(
  31967. 'button',
  31968. { type: 'button', onClick: this.confirmAddExternal, disabled: !external.url.trim().length },
  31969. language.confirm
  31970. )
  31971. ),
  31972. _react2.default.createElement(
  31973. 'div',
  31974. { 'data-type': external.type, className: 'bf-switch-external-type' },
  31975. externals.image ? _react2.default.createElement(
  31976. 'button',
  31977. { type: 'button', onClick: this.switchExternalType, 'data-type': 'IMAGE' },
  31978. language.image
  31979. ) : null,
  31980. externals.audio ? _react2.default.createElement(
  31981. 'button',
  31982. { type: 'button', onClick: this.switchExternalType, 'data-type': 'AUDIO' },
  31983. language.audio
  31984. ) : null,
  31985. externals.video ? _react2.default.createElement(
  31986. 'button',
  31987. { type: 'button', onClick: this.switchExternalType, 'data-type': 'VIDEO' },
  31988. language.video
  31989. ) : null,
  31990. externals.embed ? _react2.default.createElement(
  31991. 'button',
  31992. { type: 'button', onClick: this.switchExternalType, 'data-type': 'EMBED' },
  31993. language.embed
  31994. ) : null
  31995. ),
  31996. _react2.default.createElement(
  31997. 'span',
  31998. { className: 'bf-external-tip' },
  31999. language.externalInputTip
  32000. )
  32001. )
  32002. ) : null
  32003. ),
  32004. _react2.default.createElement(
  32005. 'footer',
  32006. { className: 'bf-manager-footer' },
  32007. _react2.default.createElement(
  32008. 'div',
  32009. { className: 'pull-left' },
  32010. allowExternal ? _react2.default.createElement(
  32011. 'span',
  32012. {
  32013. onClick: this.toggleExternalForm,
  32014. className: 'bf-toggle-external-form'
  32015. },
  32016. showExternalForm ? _react2.default.createElement(
  32017. 'span',
  32018. { className: 'bf-bottom-text' },
  32019. _react2.default.createElement('i', { className: 'braft-icon-add' }),
  32020. ' ',
  32021. language.addLocalFile
  32022. ) : _react2.default.createElement(
  32023. 'span',
  32024. { className: 'bf-bottom-text' },
  32025. _react2.default.createElement('i', { className: 'braft-icon-add' }),
  32026. ' ',
  32027. language.addExternalSource
  32028. )
  32029. ) : null
  32030. ),
  32031. _react2.default.createElement(
  32032. 'div',
  32033. { className: 'pull-right' },
  32034. _react2.default.createElement(
  32035. 'button',
  32036. { onClick: this.confirmInsert, className: 'button button-insert', disabled: !confirmable },
  32037. language.insert
  32038. ),
  32039. _react2.default.createElement(
  32040. 'button',
  32041. { onClick: this.cancelInsert, className: 'button button-cancel' },
  32042. language.cancel
  32043. )
  32044. )
  32045. )
  32046. );
  32047. }
  32048. }, {
  32049. key: 'buildItemList',
  32050. value: function buildItemList() {
  32051. var _this2 = this;
  32052. return _react2.default.createElement(
  32053. 'ul',
  32054. { className: 'bf-list' },
  32055. _react2.default.createElement(
  32056. 'li',
  32057. { className: 'bf-add-item' },
  32058. _react2.default.createElement('i', { className: 'braft-icon-add' }),
  32059. _react2.default.createElement('input', { accept: this.state.fileAccept, onChange: this.reslovePickedFiles, multiple: true, type: 'file' })
  32060. ),
  32061. this.state.items.map(function (item, index) {
  32062. var previewerComponents = null;
  32063. var progressMarker = item.uploading && !_this2.props.hideProgress ? _react2.default.createElement(
  32064. 'div',
  32065. { className: 'bf-item-uploading' },
  32066. _react2.default.createElement('div', { className: 'bf-item-uploading-bar', style: { width: item.uploadProgress / 1 + '%' } })
  32067. ) : '';
  32068. switch (item.type) {
  32069. case 'IMAGE':
  32070. previewerComponents = _react2.default.createElement(
  32071. 'div',
  32072. { className: 'bf-image' },
  32073. progressMarker,
  32074. _react2.default.createElement('img', { src: item.thumbnail || item.url })
  32075. );
  32076. break;
  32077. case 'VIDEO':
  32078. previewerComponents = _react2.default.createElement(
  32079. 'div',
  32080. { className: 'bf-icon bf-video', title: item.url },
  32081. progressMarker,
  32082. _react2.default.createElement('i', { className: 'braft-icon-film' }),
  32083. _react2.default.createElement(
  32084. 'span',
  32085. null,
  32086. item.name || item.url
  32087. )
  32088. );
  32089. break;
  32090. case 'AUDIO':
  32091. previewerComponents = _react2.default.createElement(
  32092. 'div',
  32093. { className: 'bf-icon bf-audio', title: item.url },
  32094. progressMarker,
  32095. _react2.default.createElement('i', { className: 'braft-icon-music' }),
  32096. _react2.default.createElement(
  32097. 'span',
  32098. null,
  32099. item.name || item.url
  32100. )
  32101. );
  32102. break;
  32103. case 'EMBED':
  32104. previewerComponents = _react2.default.createElement(
  32105. 'div',
  32106. { className: 'bf-icon bf-embed', title: item.url },
  32107. progressMarker,
  32108. _react2.default.createElement('i', { className: 'braft-icon-code' }),
  32109. _react2.default.createElement(
  32110. 'span',
  32111. null,
  32112. item.name || _this2.props.language.embed
  32113. )
  32114. );
  32115. break;
  32116. default:
  32117. previewerComponents = _react2.default.createElement(
  32118. 'a',
  32119. { className: 'bf-icon bf-file', title: item.url, href: item.url },
  32120. progressMarker,
  32121. _react2.default.createElement('i', { className: 'braft-icon-file-text' }),
  32122. _react2.default.createElement(
  32123. 'span',
  32124. null,
  32125. item.name || item.url
  32126. )
  32127. );
  32128. break;
  32129. }
  32130. var className = ['bf-item'];
  32131. item.selected && className.push('active');
  32132. item.uploading && className.push('uploading');
  32133. item.error && className.push('error');
  32134. return _react2.default.createElement(
  32135. 'li',
  32136. {
  32137. key: index,
  32138. title: item.name,
  32139. 'data-id': item.id,
  32140. className: className.join(' '),
  32141. onClick: _this2.toggleSelectItem
  32142. },
  32143. previewerComponents,
  32144. _react2.default.createElement('span', { 'data-id': item.id, onClick: _this2.removeItem, className: 'bf-item-remove braft-icon-close' }),
  32145. _react2.default.createElement(
  32146. 'span',
  32147. { className: 'bf-item-title' },
  32148. item.name
  32149. )
  32150. );
  32151. })
  32152. );
  32153. }
  32154. }]);
  32155. return BraftFinderView;
  32156. }(_react2.default.Component);
  32157. BraftFinderView.defaultProps = {
  32158. accepts: defaultAccepts,
  32159. externals: {
  32160. image: true,
  32161. video: true,
  32162. audio: true,
  32163. embed: true
  32164. }
  32165. };
  32166. exports.default = BraftFinderView;
  32167. /***/ }),
  32168. /* 19 */
  32169. /***/ (function(module, exports, __webpack_require__) {
  32170. Object.defineProperty(exports, "__esModule", {
  32171. value: true
  32172. });
  32173. 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; };
  32174. var _base = __webpack_require__(1);
  32175. var _image = __webpack_require__(0);
  32176. 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); } }
  32177. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  32178. var defaultValidator = function defaultValidator() {
  32179. return true;
  32180. };
  32181. var BraftFinderController = function BraftFinderController() {
  32182. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  32183. _classCallCheck(this, BraftFinderController);
  32184. _initialiseProps.call(this);
  32185. this.items = props.items || [];
  32186. this.uploadFn = props.uploader;
  32187. this.validateFn = props.validator || defaultValidator;
  32188. this.changeListeners = [];
  32189. }
  32190. // resolvePastedFiles ({ clipboardData }, callback) {
  32191. // if (clipboardData && clipboardData.items && clipboardData.items[0].type.indexOf('image') > -1) {
  32192. // this.uploadImage(clipboardData.items[0].getAsFile(), callback)
  32193. // }
  32194. // }
  32195. ;
  32196. var _initialiseProps = function _initialiseProps() {
  32197. var _this = this;
  32198. this.setProps = function () {
  32199. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  32200. _this.items = props.items || _this.items || [];
  32201. _this.uploadFn = props.uploader;
  32202. _this.validateFn = props.validator || defaultValidator;
  32203. };
  32204. this.getMediaItem = function (id) {
  32205. return _this.items.find(function (item) {
  32206. return item.id === id;
  32207. });
  32208. };
  32209. this.getSelectedItems = function () {
  32210. return _this.items.filter(function (item) {
  32211. return item.selected;
  32212. });
  32213. };
  32214. this.getItems = function () {
  32215. return _this.items;
  32216. };
  32217. this.setItems = function (items) {
  32218. _this.items = items.map(function (item) {
  32219. return _extends({}, item, { id: item.id.toString() });
  32220. }) || [];
  32221. _this.applyChange();
  32222. _this.uploadItems();
  32223. };
  32224. this.addMediaItem = function (item) {
  32225. _this.addItems([item]);
  32226. };
  32227. this.addItems = function (items) {
  32228. _this.items = [].concat(_toConsumableArray(_this.items), _toConsumableArray(items.map(function (item) {
  32229. return _extends({}, item, { id: item.id.toString() });
  32230. })));
  32231. _this.applyChange();
  32232. _this.uploadItems();
  32233. };
  32234. this.selectMediaItem = function (id) {
  32235. var item = _this.getMediaItem(id);
  32236. if (item && (item.uploading || item.error)) {
  32237. return false;
  32238. }
  32239. _this.setMediaItemState(id, {
  32240. selected: true
  32241. });
  32242. };
  32243. this.selectAllItems = function () {
  32244. _this.items = _this.items.filter(function (item) {
  32245. return !item.error && !item.uploading;
  32246. }).map(function (item) {
  32247. return _extends({}, item, { selected: true });
  32248. });
  32249. _this.applyChange();
  32250. };
  32251. this.deselectMediaItem = function (id) {
  32252. _this.setMediaItemState(id, {
  32253. selected: false
  32254. });
  32255. };
  32256. this.deselectAllItems = function () {
  32257. _this.items = _this.items.map(function (item) {
  32258. return _extends({}, item, { selected: false });
  32259. });
  32260. _this.applyChange();
  32261. };
  32262. this.removeMediaItem = function (id) {
  32263. _this.items = _this.items.filter(function (item) {
  32264. return item.id !== id;
  32265. });
  32266. _this.applyChange();
  32267. };
  32268. this.removeItems = function () {
  32269. var ids = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  32270. _this.items = _this.items.filter(function (item) {
  32271. return !ids.includes(item.id);
  32272. });
  32273. _this.applyChange();
  32274. };
  32275. this.removeSelectedItems = function () {
  32276. _this.items = _this.items.filter(function (item) {
  32277. return !item.selected;
  32278. });
  32279. _this.applyChange();
  32280. };
  32281. this.removeErrorItems = function () {
  32282. _this.items = _this.items.filter(function (item) {
  32283. return !item.error;
  32284. });
  32285. _this.applyChange();
  32286. };
  32287. this.removeAllItems = function () {
  32288. _this.items = [];
  32289. _this.applyChange();
  32290. };
  32291. this.setMediaItemState = function (id, state) {
  32292. _this.items = _this.items.map(function (item) {
  32293. return item.id === id ? _extends({}, item, state) : item;
  32294. });
  32295. _this.applyChange();
  32296. };
  32297. this.reuploadErrorItems = function () {
  32298. _this.uploadItems(true);
  32299. };
  32300. this.uploadItems = function () {
  32301. var ignoreError = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  32302. _this.items.forEach(function (item, index) {
  32303. if (item.uploading || item.url) {
  32304. return false;
  32305. }
  32306. if (!ignoreError && item.error) {
  32307. return false;
  32308. }
  32309. if (item.type === 'IMAGE') {
  32310. _this.createThumbnail(item);
  32311. _this.uploadFn = _this.uploadFn || _this.createInlineImage;
  32312. } else if (!_this.uploadFn) {
  32313. _this.setMediaItemState(item.id, { error: 1 });
  32314. return false;
  32315. }
  32316. _this.setMediaItemState(item.id, {
  32317. uploading: true,
  32318. uploadProgress: 0,
  32319. error: 0
  32320. });
  32321. _this.uploadFn({
  32322. id: item.id,
  32323. file: item.file,
  32324. success: function success(res) {
  32325. _this.handleUploadSuccess(item.id, res);
  32326. },
  32327. progress: function progress(_progress) {
  32328. _this.setMediaItemState(item.id, {
  32329. uploading: true,
  32330. uploadProgress: _progress
  32331. });
  32332. },
  32333. error: function error(_error) {
  32334. _this.setMediaItemState(item.id, {
  32335. uploading: false,
  32336. error: 2
  32337. });
  32338. }
  32339. });
  32340. });
  32341. };
  32342. this.createThumbnail = function (_ref) {
  32343. var id = _ref.id,
  32344. file = _ref.file;
  32345. (0, _image.compressImage)(URL.createObjectURL(file), 226, 226).then(function (result) {
  32346. _this.setMediaItemState(id, { thumbnail: result.url });
  32347. });
  32348. };
  32349. this.createInlineImage = function (param) {
  32350. (0, _image.compressImage)(URL.createObjectURL(param.file), 1280, 800).then(function (result) {
  32351. param.success({ url: result.url });
  32352. }).catch(function (error) {
  32353. param.error(error);
  32354. });
  32355. };
  32356. this.handleUploadSuccess = function (id, data) {
  32357. _this.setMediaItemState(id, _extends({}, data, {
  32358. file: null,
  32359. uploadProgress: 1,
  32360. uploading: false,
  32361. selected: false
  32362. }));
  32363. var item = _this.getMediaItem(data.id || id);
  32364. item.onReady && item.onReady(item);
  32365. };
  32366. this.applyChange = function () {
  32367. _this.changeListeners.forEach(function (_ref2) {
  32368. var callback = _ref2.callback;
  32369. return callback(_this.items);
  32370. });
  32371. };
  32372. this.uploadImage = function (file, callback) {
  32373. var fileId = new Date().getTime() + '_' + (0, _base.UniqueIndex)();
  32374. _this.addMediaItem({
  32375. type: 'IMAGE',
  32376. id: fileId,
  32377. file: file,
  32378. name: fileId,
  32379. size: file.size,
  32380. uploadProgress: 0,
  32381. uploading: false,
  32382. selected: false,
  32383. error: 0,
  32384. onReady: callback
  32385. });
  32386. };
  32387. this.uploadImageRecursively = function (files, callback) {
  32388. var index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
  32389. if (files[index] && files[index].type.indexOf('image') > -1) {
  32390. _this.uploadImage(files[index], function (image) {
  32391. callback && callback(image);
  32392. index < files.length - 1 && _this.uploadImageRecursively(files, callback, index + 1);
  32393. });
  32394. } else {
  32395. index < files.length - 1 && _this.uploadImageRecursively(files, callback, index + 1);
  32396. }
  32397. };
  32398. this.addResolvedFiles = function (param, index, accepts) {
  32399. var data = {
  32400. id: new Date().getTime() + '_' + (0, _base.UniqueIndex)(),
  32401. file: param.files[index],
  32402. name: param.files[index].name,
  32403. size: param.files[index].size,
  32404. uploadProgress: 0,
  32405. uploading: false,
  32406. selected: false,
  32407. error: 0,
  32408. onReady: function onReady(item) {
  32409. param.onItemReady && param.onItemReady(item);
  32410. }
  32411. };
  32412. if (param.files[index].type.indexOf('image/') === 0 && accepts.image) {
  32413. data.type = 'IMAGE';
  32414. _this.addMediaItem(data);
  32415. } else if (param.files[index].type.indexOf('video/') === 0 && accepts.video) {
  32416. data.type = 'VIDEO';
  32417. _this.addMediaItem(data);
  32418. } else if (param.files[index].type.indexOf('audio/') === 0 && accepts.audio) {
  32419. data.type = 'AUDIO';
  32420. _this.addMediaItem(data);
  32421. }
  32422. setTimeout(function () {
  32423. _this.resolveFiles(param, index + 1, accepts);
  32424. }, 60);
  32425. };
  32426. this.resolveFiles = function (param, index, accepts) {
  32427. if (index < param.files.length) {
  32428. var validateResult = _this.validateFn(param.files[index]);
  32429. if (validateResult instanceof Promise) {
  32430. validateResult.then(function () {
  32431. _this.addResolvedFiles(param, index, accepts);
  32432. });
  32433. } else if (validateResult) {
  32434. _this.addResolvedFiles(param, index, accepts);
  32435. }
  32436. } else {
  32437. param.onAllReady && param.onAllReady();
  32438. }
  32439. };
  32440. this.onChange = function (callback) {
  32441. var listenerId = (0, _base.UniqueIndex)();
  32442. _this.changeListeners.push({
  32443. id: listenerId,
  32444. callback: callback
  32445. });
  32446. return listenerId;
  32447. };
  32448. this.offChange = function (listenerId) {
  32449. _this.changeListeners = _this.changeListeners.filter(function (_ref3) {
  32450. var id = _ref3.id;
  32451. return id !== listenerId;
  32452. });
  32453. };
  32454. };
  32455. exports.default = BraftFinderController;
  32456. /***/ }),
  32457. /* 20 */
  32458. /***/ (function(module, exports, __webpack_require__) {
  32459. Object.defineProperty(exports, "__esModule", {
  32460. value: true
  32461. });
  32462. exports.ImageUtils = undefined;
  32463. 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; };
  32464. var _react = __webpack_require__(2);
  32465. var _react2 = _interopRequireDefault(_react);
  32466. var _controller = __webpack_require__(19);
  32467. var _controller2 = _interopRequireDefault(_controller);
  32468. var _view = __webpack_require__(18);
  32469. var _view2 = _interopRequireDefault(_view);
  32470. var _languages = __webpack_require__(10);
  32471. var _languages2 = _interopRequireDefault(_languages);
  32472. var _image = __webpack_require__(0);
  32473. var ImageUtils = _interopRequireWildcard(_image);
  32474. 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; } }
  32475. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  32476. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  32477. 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; }
  32478. 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; }
  32479. var BraftFinder = function (_FinderController) {
  32480. _inherits(BraftFinder, _FinderController);
  32481. function BraftFinder(props) {
  32482. _classCallCheck(this, BraftFinder);
  32483. var _this = _possibleConstructorReturn(this, (BraftFinder.__proto__ || Object.getPrototypeOf(BraftFinder)).call(this, props));
  32484. _initialiseProps.call(_this);
  32485. _this.superProps = props;
  32486. return _this;
  32487. }
  32488. return BraftFinder;
  32489. }(_controller2.default);
  32490. var _initialiseProps = function _initialiseProps() {
  32491. var _this2 = this;
  32492. this.ReactComponent = function () {
  32493. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  32494. var componentProps = _extends({}, _this2.superProps, props);
  32495. var language = (typeof componentProps.language === 'function' ? componentProps.language(_languages2.default, 'braft-finder') : _languages2.default[componentProps.language]) || _languages2.default['zh'];
  32496. return _react2.default.createElement(_view2.default, _extends({}, componentProps, {
  32497. language: language,
  32498. controller: _this2
  32499. }));
  32500. };
  32501. };
  32502. exports.default = BraftFinder;
  32503. exports.ImageUtils = ImageUtils;
  32504. /***/ })
  32505. /******/ ]);
  32506. });
  32507. });
  32508. unwrapExports(dist$2);
  32509. var draftjsUtils$1 = createCommonjsModule(function (module, exports) {
  32510. !function(e,t){module.exports=t(Draft,immutable$3);}("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);}])});
  32511. });
  32512. unwrapExports(draftjsUtils$1);
  32513. var draftjsUtils_1$1 = draftjsUtils$1.draftjsUtils;
  32514. var dist$3 = createCommonjsModule(function (module, exports) {
  32515. (function webpackUniversalModuleDefinition(root, factory) {
  32516. module.exports = factory(React, dist$1, Draft, immutable$3, dist, ReactDOM, dist$2, draftjsUtils$1);
  32517. })(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__) {
  32518. return /******/ (function(modules) { // webpackBootstrap
  32519. /******/ // The module cache
  32520. /******/ var installedModules = {};
  32521. /******/
  32522. /******/ // The require function
  32523. /******/ function __webpack_require__(moduleId) {
  32524. /******/
  32525. /******/ // Check if module is in cache
  32526. /******/ if(installedModules[moduleId]) {
  32527. /******/ return installedModules[moduleId].exports;
  32528. /******/ }
  32529. /******/ // Create a new module (and put it into the cache)
  32530. /******/ var module = installedModules[moduleId] = {
  32531. /******/ i: moduleId,
  32532. /******/ l: false,
  32533. /******/ exports: {}
  32534. /******/ };
  32535. /******/
  32536. /******/ // Execute the module function
  32537. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  32538. /******/
  32539. /******/ // Flag the module as loaded
  32540. /******/ module.l = true;
  32541. /******/
  32542. /******/ // Return the exports of the module
  32543. /******/ return module.exports;
  32544. /******/ }
  32545. /******/
  32546. /******/
  32547. /******/ // expose the modules object (__webpack_modules__)
  32548. /******/ __webpack_require__.m = modules;
  32549. /******/
  32550. /******/ // expose the module cache
  32551. /******/ __webpack_require__.c = installedModules;
  32552. /******/
  32553. /******/ // define getter function for harmony exports
  32554. /******/ __webpack_require__.d = function(exports, name, getter) {
  32555. /******/ if(!__webpack_require__.o(exports, name)) {
  32556. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  32557. /******/ }
  32558. /******/ };
  32559. /******/
  32560. /******/ // define __esModule on exports
  32561. /******/ __webpack_require__.r = function(exports) {
  32562. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  32563. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  32564. /******/ }
  32565. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  32566. /******/ };
  32567. /******/
  32568. /******/ // create a fake namespace object
  32569. /******/ // mode & 1: value is a module id, require it
  32570. /******/ // mode & 2: merge all properties of value into the ns
  32571. /******/ // mode & 4: return value when already ns object
  32572. /******/ // mode & 8|1: behave like require
  32573. /******/ __webpack_require__.t = function(value, mode) {
  32574. /******/ if(mode & 1) value = __webpack_require__(value);
  32575. /******/ if(mode & 8) return value;
  32576. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  32577. /******/ var ns = Object.create(null);
  32578. /******/ __webpack_require__.r(ns);
  32579. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  32580. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  32581. /******/ return ns;
  32582. /******/ };
  32583. /******/
  32584. /******/ // getDefaultExport function for compatibility with non-harmony modules
  32585. /******/ __webpack_require__.n = function(module) {
  32586. /******/ var getter = module && module.__esModule ?
  32587. /******/ function getDefault() { return module['default']; } :
  32588. /******/ function getModuleExports() { return module; };
  32589. /******/ __webpack_require__.d(getter, 'a', getter);
  32590. /******/ return getter;
  32591. /******/ };
  32592. /******/
  32593. /******/ // Object.prototype.hasOwnProperty.call
  32594. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  32595. /******/
  32596. /******/ // __webpack_public_path__
  32597. /******/ __webpack_require__.p = "/";
  32598. /******/
  32599. /******/
  32600. /******/ // Load entry module and return exports
  32601. /******/ return __webpack_require__(__webpack_require__.s = 39);
  32602. /******/ })
  32603. /************************************************************************/
  32604. /******/ ([
  32605. /* 0 */
  32606. /***/ (function(module, exports) {
  32607. module.exports = __WEBPACK_EXTERNAL_MODULE__0__;
  32608. /***/ }),
  32609. /* 1 */
  32610. /***/ (function(module, exports) {
  32611. function _assertThisInitialized(self) {
  32612. if (self === void 0) {
  32613. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  32614. }
  32615. return self;
  32616. }
  32617. module.exports = _assertThisInitialized;
  32618. /***/ }),
  32619. /* 2 */
  32620. /***/ (function(module, exports) {
  32621. function _defineProperty(obj, key, value) {
  32622. if (key in obj) {
  32623. Object.defineProperty(obj, key, {
  32624. value: value,
  32625. enumerable: true,
  32626. configurable: true,
  32627. writable: true
  32628. });
  32629. } else {
  32630. obj[key] = value;
  32631. }
  32632. return obj;
  32633. }
  32634. module.exports = _defineProperty;
  32635. /***/ }),
  32636. /* 3 */
  32637. /***/ (function(module, exports) {
  32638. module.exports = __WEBPACK_EXTERNAL_MODULE__3__;
  32639. /***/ }),
  32640. /* 4 */
  32641. /***/ (function(module, exports) {
  32642. function _classCallCheck(instance, Constructor) {
  32643. if (!(instance instanceof Constructor)) {
  32644. throw new TypeError("Cannot call a class as a function");
  32645. }
  32646. }
  32647. module.exports = _classCallCheck;
  32648. /***/ }),
  32649. /* 5 */
  32650. /***/ (function(module, exports, __webpack_require__) {
  32651. var defineProperty = __webpack_require__(2);
  32652. function _objectSpread(target) {
  32653. for (var i = 1; i < arguments.length; i++) {
  32654. var source = arguments[i] != null ? arguments[i] : {};
  32655. var ownKeys = Object.keys(source);
  32656. if (typeof Object.getOwnPropertySymbols === 'function') {
  32657. ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
  32658. return Object.getOwnPropertyDescriptor(source, sym).enumerable;
  32659. }));
  32660. }
  32661. ownKeys.forEach(function (key) {
  32662. defineProperty(target, key, source[key]);
  32663. });
  32664. }
  32665. return target;
  32666. }
  32667. module.exports = _objectSpread;
  32668. /***/ }),
  32669. /* 6 */
  32670. /***/ (function(module, exports) {
  32671. module.exports = __WEBPACK_EXTERNAL_MODULE__6__;
  32672. /***/ }),
  32673. /* 7 */
  32674. /***/ (function(module, exports) {
  32675. function _defineProperties(target, props) {
  32676. for (var i = 0; i < props.length; i++) {
  32677. var descriptor = props[i];
  32678. descriptor.enumerable = descriptor.enumerable || false;
  32679. descriptor.configurable = true;
  32680. if ("value" in descriptor) descriptor.writable = true;
  32681. Object.defineProperty(target, descriptor.key, descriptor);
  32682. }
  32683. }
  32684. function _createClass(Constructor, protoProps, staticProps) {
  32685. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  32686. if (staticProps) _defineProperties(Constructor, staticProps);
  32687. return Constructor;
  32688. }
  32689. module.exports = _createClass;
  32690. /***/ }),
  32691. /* 8 */
  32692. /***/ (function(module, exports, __webpack_require__) {
  32693. var _typeof = __webpack_require__(15);
  32694. var assertThisInitialized = __webpack_require__(1);
  32695. function _possibleConstructorReturn(self, call) {
  32696. if (call && (_typeof(call) === "object" || typeof call === "function")) {
  32697. return call;
  32698. }
  32699. return assertThisInitialized(self);
  32700. }
  32701. module.exports = _possibleConstructorReturn;
  32702. /***/ }),
  32703. /* 9 */
  32704. /***/ (function(module, exports) {
  32705. function _getPrototypeOf(o) {
  32706. module.exports = _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
  32707. return o.__proto__ || Object.getPrototypeOf(o);
  32708. };
  32709. return _getPrototypeOf(o);
  32710. }
  32711. module.exports = _getPrototypeOf;
  32712. /***/ }),
  32713. /* 10 */
  32714. /***/ (function(module, exports, __webpack_require__) {
  32715. var setPrototypeOf = __webpack_require__(26);
  32716. function _inherits(subClass, superClass) {
  32717. if (typeof superClass !== "function" && superClass !== null) {
  32718. throw new TypeError("Super expression must either be null or a function");
  32719. }
  32720. subClass.prototype = Object.create(superClass && superClass.prototype, {
  32721. constructor: {
  32722. value: subClass,
  32723. writable: true,
  32724. configurable: true
  32725. }
  32726. });
  32727. if (superClass) setPrototypeOf(subClass, superClass);
  32728. }
  32729. module.exports = _inherits;
  32730. /***/ }),
  32731. /* 11 */
  32732. /***/ (function(module, exports) {
  32733. function _extends() {
  32734. module.exports = _extends = Object.assign || function (target) {
  32735. for (var i = 1; i < arguments.length; i++) {
  32736. var source = arguments[i];
  32737. for (var key in source) {
  32738. if (Object.prototype.hasOwnProperty.call(source, key)) {
  32739. target[key] = source[key];
  32740. }
  32741. }
  32742. }
  32743. return target;
  32744. };
  32745. return _extends.apply(this, arguments);
  32746. }
  32747. module.exports = _extends;
  32748. /***/ }),
  32749. /* 12 */
  32750. /***/ (function(module, exports, __webpack_require__) {
  32751. var arrayWithoutHoles = __webpack_require__(27);
  32752. var iterableToArray = __webpack_require__(28);
  32753. var nonIterableSpread = __webpack_require__(29);
  32754. function _toConsumableArray(arr) {
  32755. return arrayWithoutHoles(arr) || iterableToArray(arr) || nonIterableSpread();
  32756. }
  32757. module.exports = _toConsumableArray;
  32758. /***/ }),
  32759. /* 13 */
  32760. /***/ (function(module, exports) {
  32761. module.exports = __WEBPACK_EXTERNAL_MODULE__13__;
  32762. /***/ }),
  32763. /* 14 */
  32764. /***/ (function(module, exports) {
  32765. module.exports = __WEBPACK_EXTERNAL_MODULE__14__;
  32766. /***/ }),
  32767. /* 15 */
  32768. /***/ (function(module, exports) {
  32769. 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); }
  32770. function _typeof(obj) {
  32771. if (typeof Symbol === "function" && _typeof2(Symbol.iterator) === "symbol") {
  32772. module.exports = _typeof = function _typeof(obj) {
  32773. return _typeof2(obj);
  32774. };
  32775. } else {
  32776. module.exports = _typeof = function _typeof(obj) {
  32777. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : _typeof2(obj);
  32778. };
  32779. }
  32780. return _typeof(obj);
  32781. }
  32782. module.exports = _typeof;
  32783. /***/ }),
  32784. /* 16 */
  32785. /***/ (function(module, exports) {
  32786. module.exports = __WEBPACK_EXTERNAL_MODULE__16__;
  32787. /***/ }),
  32788. /* 17 */
  32789. /***/ (function(module, exports) {
  32790. module.exports = __WEBPACK_EXTERNAL_MODULE__17__;
  32791. /***/ }),
  32792. /* 18 */
  32793. /***/ (function(module, exports, __webpack_require__) {
  32794. var Immutable = __webpack_require__(13);
  32795. var KEY_SEPARATOR = '-';
  32796. function MultiDecorator(decorators) {
  32797. this.decorators = Immutable.List(decorators);
  32798. }
  32799. /**
  32800. Return list of decoration IDs per character
  32801. @param {ContentBlock}
  32802. @return {List<String>}
  32803. */
  32804. MultiDecorator.prototype.getDecorations = function(block) {
  32805. var decorations = Array(block.getText().length).fill(null);
  32806. this.decorators.forEach(function(decorator, i) {
  32807. var _decorations = decorator.getDecorations(block);
  32808. _decorations.forEach(function(key, offset) {
  32809. if (!key) {
  32810. return;
  32811. }
  32812. key = i + KEY_SEPARATOR + key;
  32813. decorations[offset] = key;
  32814. });
  32815. });
  32816. return Immutable.List(decorations);
  32817. };
  32818. /**
  32819. Return component to render a decoration
  32820. @param {String}
  32821. @return {Function}
  32822. */
  32823. MultiDecorator.prototype.getComponentForKey = function(key) {
  32824. var decorator = this.getDecoratorForKey(key);
  32825. return decorator.getComponentForKey(
  32826. this.getInnerKey(key)
  32827. );
  32828. };
  32829. /**
  32830. Return props to render a decoration
  32831. @param {String}
  32832. @return {Object}
  32833. */
  32834. MultiDecorator.prototype.getPropsForKey = function(key) {
  32835. var decorator = this.getDecoratorForKey(key);
  32836. return decorator.getPropsForKey(
  32837. this.getInnerKey(key)
  32838. );
  32839. };
  32840. /**
  32841. Return a decorator for a specific key
  32842. @param {String}
  32843. @return {Decorator}
  32844. */
  32845. MultiDecorator.prototype.getDecoratorForKey = function(key) {
  32846. var parts = key.split(KEY_SEPARATOR);
  32847. var index = Number(parts[0]);
  32848. return this.decorators.get(index);
  32849. };
  32850. /**
  32851. Return inner key for a decorator
  32852. @param {String}
  32853. @return {String}
  32854. */
  32855. MultiDecorator.prototype.getInnerKey = function(key) {
  32856. var parts = key.split(KEY_SEPARATOR);
  32857. return parts.slice(1).join(KEY_SEPARATOR);
  32858. };
  32859. module.exports = MultiDecorator;
  32860. /***/ }),
  32861. /* 19 */
  32862. /***/ (function(module, exports, __webpack_require__) {
  32863. /**
  32864. * Copyright (c) 2013-present, Facebook, Inc.
  32865. * All rights reserved.
  32866. *
  32867. * This source code is licensed under the BSD-style license found in the
  32868. * LICENSE file in the root directory of this source tree. An additional grant
  32869. * of patent rights can be found in the PATENTS file in the same directory.
  32870. *
  32871. * @providesModule CharacterMetadata
  32872. * @format
  32873. *
  32874. */
  32875. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  32876. 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; }
  32877. 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; }
  32878. var _require = __webpack_require__(13),
  32879. Map = _require.Map,
  32880. OrderedSet = _require.OrderedSet,
  32881. Record = _require.Record;
  32882. // Immutable.map is typed such that the value for every key in the map
  32883. // must be the same type
  32884. var EMPTY_SET = OrderedSet();
  32885. var defaultRecord = {
  32886. style: EMPTY_SET,
  32887. entity: null
  32888. };
  32889. var CharacterMetadataRecord = Record(defaultRecord);
  32890. var CharacterMetadata = function (_CharacterMetadataRec) {
  32891. _inherits(CharacterMetadata, _CharacterMetadataRec);
  32892. function CharacterMetadata() {
  32893. _classCallCheck(this, CharacterMetadata);
  32894. return _possibleConstructorReturn(this, _CharacterMetadataRec.apply(this, arguments));
  32895. }
  32896. CharacterMetadata.prototype.getStyle = function getStyle() {
  32897. return this.get('style');
  32898. };
  32899. CharacterMetadata.prototype.getEntity = function getEntity() {
  32900. return this.get('entity');
  32901. };
  32902. CharacterMetadata.prototype.hasStyle = function hasStyle(style) {
  32903. return this.getStyle().includes(style);
  32904. };
  32905. CharacterMetadata.applyStyle = function applyStyle(record, style) {
  32906. var withStyle = record.set('style', record.getStyle().add(style));
  32907. return CharacterMetadata.create(withStyle);
  32908. };
  32909. CharacterMetadata.removeStyle = function removeStyle(record, style) {
  32910. var withoutStyle = record.set('style', record.getStyle().remove(style));
  32911. return CharacterMetadata.create(withoutStyle);
  32912. };
  32913. CharacterMetadata.applyEntity = function applyEntity(record, entityKey) {
  32914. var withEntity = record.getEntity() === entityKey ? record : record.set('entity', entityKey);
  32915. return CharacterMetadata.create(withEntity);
  32916. };
  32917. /**
  32918. * Use this function instead of the `CharacterMetadata` constructor.
  32919. * Since most content generally uses only a very small number of
  32920. * style/entity permutations, we can reuse these objects as often as
  32921. * possible.
  32922. */
  32923. CharacterMetadata.create = function create(config) {
  32924. if (!config) {
  32925. return EMPTY;
  32926. }
  32927. var defaultConfig = {
  32928. style: EMPTY_SET,
  32929. entity: null
  32930. };
  32931. // Fill in unspecified properties, if necessary.
  32932. var configMap = Map(defaultConfig).merge(config);
  32933. var existing = pool.get(configMap);
  32934. if (existing) {
  32935. return existing;
  32936. }
  32937. var newCharacter = new CharacterMetadata(configMap);
  32938. pool = pool.set(configMap, newCharacter);
  32939. return newCharacter;
  32940. };
  32941. return CharacterMetadata;
  32942. }(CharacterMetadataRecord);
  32943. var EMPTY = new CharacterMetadata();
  32944. var pool = Map([[Map(defaultRecord), EMPTY]]);
  32945. CharacterMetadata.EMPTY = EMPTY;
  32946. module.exports = CharacterMetadata;
  32947. /***/ }),
  32948. /* 20 */
  32949. /***/ (function(module, exports, __webpack_require__) {
  32950. /**
  32951. * Copyright (c) 2013-present, Facebook, Inc.
  32952. * All rights reserved.
  32953. *
  32954. * This source code is licensed under the BSD-style license found in the
  32955. * LICENSE file in the root directory of this source tree. An additional grant
  32956. * of patent rights can be found in the PATENTS file in the same directory.
  32957. *
  32958. * @providesModule findRangesImmutable
  32959. * @format
  32960. *
  32961. */
  32962. /**
  32963. * Search through an array to find contiguous stretches of elements that
  32964. * match a specified filter function.
  32965. *
  32966. * When ranges are found, execute a specified `found` function to supply
  32967. * the values to the caller.
  32968. */
  32969. function findRangesImmutable(haystack, areEqualFn, filterFn, foundFn) {
  32970. if (!haystack.size) {
  32971. return;
  32972. }
  32973. var cursor = 0;
  32974. haystack.reduce(function (value, nextValue, nextIndex) {
  32975. if (!areEqualFn(value, nextValue)) {
  32976. if (filterFn(value)) {
  32977. foundFn(cursor, nextIndex);
  32978. }
  32979. cursor = nextIndex;
  32980. }
  32981. return nextValue;
  32982. });
  32983. filterFn(haystack.last()) && foundFn(cursor, haystack.count());
  32984. }
  32985. module.exports = findRangesImmutable;
  32986. /***/ }),
  32987. /* 21 */
  32988. /***/ (function(module, exports, __webpack_require__) {
  32989. var objectWithoutPropertiesLoose = __webpack_require__(25);
  32990. function _objectWithoutProperties(source, excluded) {
  32991. if (source == null) return {};
  32992. var target = objectWithoutPropertiesLoose(source, excluded);
  32993. var key, i;
  32994. if (Object.getOwnPropertySymbols) {
  32995. var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
  32996. for (i = 0; i < sourceSymbolKeys.length; i++) {
  32997. key = sourceSymbolKeys[i];
  32998. if (excluded.indexOf(key) >= 0) continue;
  32999. if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
  33000. target[key] = source[key];
  33001. }
  33002. }
  33003. return target;
  33004. }
  33005. module.exports = _objectWithoutProperties;
  33006. /***/ }),
  33007. /* 22 */
  33008. /***/ (function(module, exports, __webpack_require__) {
  33009. /**
  33010. * Copyright (c) 2013-present, Facebook, Inc.
  33011. * All rights reserved.
  33012. *
  33013. * This source code is licensed under the BSD-style license found in the
  33014. * LICENSE file in the root directory of this source tree. An additional grant
  33015. * of patent rights can be found in the PATENTS file in the same directory.
  33016. *
  33017. * @providesModule getFragmentFromSelection
  33018. * @format
  33019. *
  33020. */
  33021. var getContentStateFragment = __webpack_require__(30);
  33022. function getFragmentFromSelection(editorState) {
  33023. var selectionState = editorState.getSelection();
  33024. if (selectionState.isCollapsed()) {
  33025. return null;
  33026. }
  33027. return getContentStateFragment(editorState.getCurrentContent(), selectionState);
  33028. }
  33029. module.exports = getFragmentFromSelection;
  33030. /***/ }),
  33031. /* 23 */
  33032. /***/ (function(module, exports) {
  33033. module.exports = __WEBPACK_EXTERNAL_MODULE__23__;
  33034. /***/ }),
  33035. /* 24 */
  33036. /***/ (function(module, exports, __webpack_require__) {
  33037. var arrayWithHoles = __webpack_require__(36);
  33038. var iterableToArrayLimit = __webpack_require__(37);
  33039. var nonIterableRest = __webpack_require__(38);
  33040. function _slicedToArray(arr, i) {
  33041. return arrayWithHoles(arr) || iterableToArrayLimit(arr, i) || nonIterableRest();
  33042. }
  33043. module.exports = _slicedToArray;
  33044. /***/ }),
  33045. /* 25 */
  33046. /***/ (function(module, exports) {
  33047. function _objectWithoutPropertiesLoose(source, excluded) {
  33048. if (source == null) return {};
  33049. var target = {};
  33050. var sourceKeys = Object.keys(source);
  33051. var key, i;
  33052. for (i = 0; i < sourceKeys.length; i++) {
  33053. key = sourceKeys[i];
  33054. if (excluded.indexOf(key) >= 0) continue;
  33055. target[key] = source[key];
  33056. }
  33057. return target;
  33058. }
  33059. module.exports = _objectWithoutPropertiesLoose;
  33060. /***/ }),
  33061. /* 26 */
  33062. /***/ (function(module, exports) {
  33063. function _setPrototypeOf(o, p) {
  33064. module.exports = _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  33065. o.__proto__ = p;
  33066. return o;
  33067. };
  33068. return _setPrototypeOf(o, p);
  33069. }
  33070. module.exports = _setPrototypeOf;
  33071. /***/ }),
  33072. /* 27 */
  33073. /***/ (function(module, exports) {
  33074. function _arrayWithoutHoles(arr) {
  33075. if (Array.isArray(arr)) {
  33076. for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {
  33077. arr2[i] = arr[i];
  33078. }
  33079. return arr2;
  33080. }
  33081. }
  33082. module.exports = _arrayWithoutHoles;
  33083. /***/ }),
  33084. /* 28 */
  33085. /***/ (function(module, exports) {
  33086. function _iterableToArray(iter) {
  33087. if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
  33088. }
  33089. module.exports = _iterableToArray;
  33090. /***/ }),
  33091. /* 29 */
  33092. /***/ (function(module, exports) {
  33093. function _nonIterableSpread() {
  33094. throw new TypeError("Invalid attempt to spread non-iterable instance");
  33095. }
  33096. module.exports = _nonIterableSpread;
  33097. /***/ }),
  33098. /* 30 */
  33099. /***/ (function(module, exports, __webpack_require__) {
  33100. /**
  33101. * Copyright (c) 2013-present, Facebook, Inc.
  33102. * All rights reserved.
  33103. *
  33104. * This source code is licensed under the BSD-style license found in the
  33105. * LICENSE file in the root directory of this source tree. An additional grant
  33106. * of patent rights can be found in the PATENTS file in the same directory.
  33107. *
  33108. * @providesModule getContentStateFragment
  33109. * @format
  33110. *
  33111. */
  33112. var randomizeBlockMapKeys = __webpack_require__(31);
  33113. var removeEntitiesAtEdges = __webpack_require__(34);
  33114. var getContentStateFragment = function getContentStateFragment(contentState, selectionState) {
  33115. var startKey = selectionState.getStartKey();
  33116. var startOffset = selectionState.getStartOffset();
  33117. var endKey = selectionState.getEndKey();
  33118. var endOffset = selectionState.getEndOffset();
  33119. // Edge entities should be stripped to ensure that we don't preserve
  33120. // invalid partial entities when the fragment is reused. We do, however,
  33121. // preserve entities that are entirely within the selection range.
  33122. var contentWithoutEdgeEntities = removeEntitiesAtEdges(contentState, selectionState);
  33123. var blockMap = contentWithoutEdgeEntities.getBlockMap();
  33124. var blockKeys = blockMap.keySeq();
  33125. var startIndex = blockKeys.indexOf(startKey);
  33126. var endIndex = blockKeys.indexOf(endKey) + 1;
  33127. return randomizeBlockMapKeys(blockMap.slice(startIndex, endIndex).map(function (block, blockKey) {
  33128. var text = block.getText();
  33129. var chars = block.getCharacterList();
  33130. if (startKey === endKey) {
  33131. return block.merge({
  33132. text: text.slice(startOffset, endOffset),
  33133. characterList: chars.slice(startOffset, endOffset)
  33134. });
  33135. }
  33136. if (blockKey === startKey) {
  33137. return block.merge({
  33138. text: text.slice(startOffset),
  33139. characterList: chars.slice(startOffset)
  33140. });
  33141. }
  33142. if (blockKey === endKey) {
  33143. return block.merge({
  33144. text: text.slice(0, endOffset),
  33145. characterList: chars.slice(0, endOffset)
  33146. });
  33147. }
  33148. return block;
  33149. }));
  33150. };
  33151. module.exports = getContentStateFragment;
  33152. /***/ }),
  33153. /* 31 */
  33154. /***/ (function(module, exports, __webpack_require__) {
  33155. /**
  33156. * Copyright (c) 2013-present, Facebook, Inc.
  33157. * All rights reserved.
  33158. *
  33159. * This source code is licensed under the BSD-style license found in the
  33160. * LICENSE file in the root directory of this source tree. An additional grant
  33161. * of patent rights can be found in the PATENTS file in the same directory.
  33162. *
  33163. * @providesModule randomizeBlockMapKeys
  33164. * @format
  33165. *
  33166. */
  33167. var ContentBlockNode = __webpack_require__(32);
  33168. var Immutable = __webpack_require__(13);
  33169. var generateRandomKey = __webpack_require__(33);
  33170. var OrderedMap = Immutable.OrderedMap;
  33171. var randomizeContentBlockNodeKeys = function randomizeContentBlockNodeKeys(blockMap) {
  33172. var newKeysRef = {};
  33173. // we keep track of root blocks in order to update subsequent sibling links
  33174. var lastRootBlock = void 0;
  33175. return OrderedMap(blockMap.withMutations(function (blockMapState) {
  33176. blockMapState.forEach(function (block, index) {
  33177. var oldKey = block.getKey();
  33178. var nextKey = block.getNextSiblingKey();
  33179. var prevKey = block.getPrevSiblingKey();
  33180. var childrenKeys = block.getChildKeys();
  33181. var parentKey = block.getParentKey();
  33182. // new key that we will use to build linking
  33183. var key = generateRandomKey();
  33184. // we will add it here to re-use it later
  33185. newKeysRef[oldKey] = key;
  33186. if (nextKey) {
  33187. var nextBlock = blockMapState.get(nextKey);
  33188. if (nextBlock) {
  33189. blockMapState.setIn([nextKey, 'prevSibling'], key);
  33190. } else {
  33191. // this can happen when generating random keys for fragments
  33192. blockMapState.setIn([oldKey, 'nextSibling'], null);
  33193. }
  33194. }
  33195. if (prevKey) {
  33196. var prevBlock = blockMapState.get(prevKey);
  33197. if (prevBlock) {
  33198. blockMapState.setIn([prevKey, 'nextSibling'], key);
  33199. } else {
  33200. // this can happen when generating random keys for fragments
  33201. blockMapState.setIn([oldKey, 'prevSibling'], null);
  33202. }
  33203. }
  33204. if (parentKey && blockMapState.get(parentKey)) {
  33205. var parentBlock = blockMapState.get(parentKey);
  33206. var parentChildrenList = parentBlock.getChildKeys();
  33207. blockMapState.setIn([parentKey, 'children'], parentChildrenList.set(parentChildrenList.indexOf(block.getKey()), key));
  33208. } else {
  33209. // blocks will then be treated as root block nodes
  33210. blockMapState.setIn([oldKey, 'parent'], null);
  33211. if (lastRootBlock) {
  33212. blockMapState.setIn([lastRootBlock.getKey(), 'nextSibling'], key);
  33213. blockMapState.setIn([oldKey, 'prevSibling'], newKeysRef[lastRootBlock.getKey()]);
  33214. }
  33215. lastRootBlock = blockMapState.get(oldKey);
  33216. }
  33217. childrenKeys.forEach(function (childKey) {
  33218. var childBlock = blockMapState.get(childKey);
  33219. if (childBlock) {
  33220. blockMapState.setIn([childKey, 'parent'], key);
  33221. } else {
  33222. blockMapState.setIn([oldKey, 'children'], block.getChildKeys().filter(function (child) {
  33223. return child !== childKey;
  33224. }));
  33225. }
  33226. });
  33227. });
  33228. }).toArray().map(function (block) {
  33229. return [newKeysRef[block.getKey()], block.set('key', newKeysRef[block.getKey()])];
  33230. }));
  33231. };
  33232. var randomizeContentBlockKeys = function randomizeContentBlockKeys(blockMap) {
  33233. return OrderedMap(blockMap.toArray().map(function (block) {
  33234. var key = generateRandomKey();
  33235. return [key, block.set('key', key)];
  33236. }));
  33237. };
  33238. var randomizeBlockMapKeys = function randomizeBlockMapKeys(blockMap) {
  33239. var isTreeBasedBlockMap = blockMap.first() instanceof ContentBlockNode;
  33240. if (!isTreeBasedBlockMap) {
  33241. return randomizeContentBlockKeys(blockMap);
  33242. }
  33243. return randomizeContentBlockNodeKeys(blockMap);
  33244. };
  33245. module.exports = randomizeBlockMapKeys;
  33246. /***/ }),
  33247. /* 32 */
  33248. /***/ (function(module, exports, __webpack_require__) {
  33249. /**
  33250. * Copyright (c) 2013-present, Facebook, Inc.
  33251. * All rights reserved.
  33252. *
  33253. * This source code is licensed under the BSD-style license found in the
  33254. * LICENSE file in the root directory of this source tree. An additional grant
  33255. * of patent rights can be found in the PATENTS file in the same directory.
  33256. *
  33257. * @providesModule ContentBlockNode
  33258. * @format
  33259. *
  33260. *
  33261. * This file is a fork of ContentBlock adding support for nesting references by
  33262. * providing links to children, parent, prevSibling, and nextSibling.
  33263. *
  33264. * This is unstable and not part of the public API and should not be used by
  33265. * production systems. This file may be update/removed without notice.
  33266. */
  33267. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  33268. 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; }
  33269. 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; }
  33270. var CharacterMetadata = __webpack_require__(19);
  33271. var Immutable = __webpack_require__(13);
  33272. var findRangesImmutable = __webpack_require__(20);
  33273. var List = Immutable.List,
  33274. Map = Immutable.Map,
  33275. OrderedSet = Immutable.OrderedSet,
  33276. Record = Immutable.Record,
  33277. Repeat = Immutable.Repeat;
  33278. var EMPTY_SET = OrderedSet();
  33279. var defaultRecord = {
  33280. parent: null,
  33281. characterList: List(),
  33282. data: Map(),
  33283. depth: 0,
  33284. key: '',
  33285. text: '',
  33286. type: 'unstyled',
  33287. children: List(),
  33288. prevSibling: null,
  33289. nextSibling: null
  33290. };
  33291. var haveEqualStyle = function haveEqualStyle(charA, charB) {
  33292. return charA.getStyle() === charB.getStyle();
  33293. };
  33294. var haveEqualEntity = function haveEqualEntity(charA, charB) {
  33295. return charA.getEntity() === charB.getEntity();
  33296. };
  33297. var decorateCharacterList = function decorateCharacterList(config) {
  33298. if (!config) {
  33299. return config;
  33300. }
  33301. var characterList = config.characterList,
  33302. text = config.text;
  33303. if (text && !characterList) {
  33304. config.characterList = List(Repeat(CharacterMetadata.EMPTY, text.length));
  33305. }
  33306. return config;
  33307. };
  33308. var ContentBlockNode = function (_Record) {
  33309. _inherits(ContentBlockNode, _Record);
  33310. function ContentBlockNode() {
  33311. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultRecord;
  33312. _classCallCheck(this, ContentBlockNode);
  33313. return _possibleConstructorReturn(this, _Record.call(this, decorateCharacterList(props)));
  33314. }
  33315. ContentBlockNode.prototype.getKey = function getKey() {
  33316. return this.get('key');
  33317. };
  33318. ContentBlockNode.prototype.getType = function getType() {
  33319. return this.get('type');
  33320. };
  33321. ContentBlockNode.prototype.getText = function getText() {
  33322. return this.get('text');
  33323. };
  33324. ContentBlockNode.prototype.getCharacterList = function getCharacterList() {
  33325. return this.get('characterList');
  33326. };
  33327. ContentBlockNode.prototype.getLength = function getLength() {
  33328. return this.getText().length;
  33329. };
  33330. ContentBlockNode.prototype.getDepth = function getDepth() {
  33331. return this.get('depth');
  33332. };
  33333. ContentBlockNode.prototype.getData = function getData() {
  33334. return this.get('data');
  33335. };
  33336. ContentBlockNode.prototype.getInlineStyleAt = function getInlineStyleAt(offset) {
  33337. var character = this.getCharacterList().get(offset);
  33338. return character ? character.getStyle() : EMPTY_SET;
  33339. };
  33340. ContentBlockNode.prototype.getEntityAt = function getEntityAt(offset) {
  33341. var character = this.getCharacterList().get(offset);
  33342. return character ? character.getEntity() : null;
  33343. };
  33344. ContentBlockNode.prototype.getChildKeys = function getChildKeys() {
  33345. return this.get('children');
  33346. };
  33347. ContentBlockNode.prototype.getParentKey = function getParentKey() {
  33348. return this.get('parent');
  33349. };
  33350. ContentBlockNode.prototype.getPrevSiblingKey = function getPrevSiblingKey() {
  33351. return this.get('prevSibling');
  33352. };
  33353. ContentBlockNode.prototype.getNextSiblingKey = function getNextSiblingKey() {
  33354. return this.get('nextSibling');
  33355. };
  33356. ContentBlockNode.prototype.findStyleRanges = function findStyleRanges(filterFn, callback) {
  33357. findRangesImmutable(this.getCharacterList(), haveEqualStyle, filterFn, callback);
  33358. };
  33359. ContentBlockNode.prototype.findEntityRanges = function findEntityRanges(filterFn, callback) {
  33360. findRangesImmutable(this.getCharacterList(), haveEqualEntity, filterFn, callback);
  33361. };
  33362. return ContentBlockNode;
  33363. }(Record(defaultRecord));
  33364. module.exports = ContentBlockNode;
  33365. /***/ }),
  33366. /* 33 */
  33367. /***/ (function(module, exports, __webpack_require__) {
  33368. /**
  33369. * Copyright (c) 2013-present, Facebook, Inc.
  33370. * All rights reserved.
  33371. *
  33372. * This source code is licensed under the BSD-style license found in the
  33373. * LICENSE file in the root directory of this source tree. An additional grant
  33374. * of patent rights can be found in the PATENTS file in the same directory.
  33375. *
  33376. * @providesModule generateRandomKey
  33377. * @format
  33378. *
  33379. */
  33380. var seenKeys = {};
  33381. var MULTIPLIER = Math.pow(2, 24);
  33382. function generateRandomKey() {
  33383. var key = void 0;
  33384. while (key === undefined || seenKeys.hasOwnProperty(key) || !isNaN(+key)) {
  33385. key = Math.floor(Math.random() * MULTIPLIER).toString(32);
  33386. }
  33387. seenKeys[key] = true;
  33388. return key;
  33389. }
  33390. module.exports = generateRandomKey;
  33391. /***/ }),
  33392. /* 34 */
  33393. /***/ (function(module, exports, __webpack_require__) {
  33394. /**
  33395. * Copyright (c) 2013-present, Facebook, Inc.
  33396. * All rights reserved.
  33397. *
  33398. * This source code is licensed under the BSD-style license found in the
  33399. * LICENSE file in the root directory of this source tree. An additional grant
  33400. * of patent rights can be found in the PATENTS file in the same directory.
  33401. *
  33402. * @providesModule removeEntitiesAtEdges
  33403. * @format
  33404. *
  33405. */
  33406. var CharacterMetadata = __webpack_require__(19);
  33407. var findRangesImmutable = __webpack_require__(20);
  33408. var invariant = __webpack_require__(35);
  33409. function removeEntitiesAtEdges(contentState, selectionState) {
  33410. var blockMap = contentState.getBlockMap();
  33411. var entityMap = contentState.getEntityMap();
  33412. var updatedBlocks = {};
  33413. var startKey = selectionState.getStartKey();
  33414. var startOffset = selectionState.getStartOffset();
  33415. var startBlock = blockMap.get(startKey);
  33416. var updatedStart = removeForBlock(entityMap, startBlock, startOffset);
  33417. if (updatedStart !== startBlock) {
  33418. updatedBlocks[startKey] = updatedStart;
  33419. }
  33420. var endKey = selectionState.getEndKey();
  33421. var endOffset = selectionState.getEndOffset();
  33422. var endBlock = blockMap.get(endKey);
  33423. if (startKey === endKey) {
  33424. endBlock = updatedStart;
  33425. }
  33426. var updatedEnd = removeForBlock(entityMap, endBlock, endOffset);
  33427. if (updatedEnd !== endBlock) {
  33428. updatedBlocks[endKey] = updatedEnd;
  33429. }
  33430. if (!Object.keys(updatedBlocks).length) {
  33431. return contentState.set('selectionAfter', selectionState);
  33432. }
  33433. return contentState.merge({
  33434. blockMap: blockMap.merge(updatedBlocks),
  33435. selectionAfter: selectionState
  33436. });
  33437. }
  33438. function getRemovalRange(characters, key, offset) {
  33439. var removalRange;
  33440. findRangesImmutable(characters, function (a, b) {
  33441. return a.getEntity() === b.getEntity();
  33442. }, function (element) {
  33443. return element.getEntity() === key;
  33444. }, function (start, end) {
  33445. if (start <= offset && end >= offset) {
  33446. removalRange = { start: start, end: end };
  33447. }
  33448. });
  33449. !(typeof removalRange === 'object') ? invariant(false) : void 0;
  33450. return removalRange;
  33451. }
  33452. function removeForBlock(entityMap, block, offset) {
  33453. var chars = block.getCharacterList();
  33454. var charBefore = offset > 0 ? chars.get(offset - 1) : undefined;
  33455. var charAfter = offset < chars.count() ? chars.get(offset) : undefined;
  33456. var entityBeforeCursor = charBefore ? charBefore.getEntity() : undefined;
  33457. var entityAfterCursor = charAfter ? charAfter.getEntity() : undefined;
  33458. if (entityAfterCursor && entityAfterCursor === entityBeforeCursor) {
  33459. var entity = entityMap.__get(entityAfterCursor);
  33460. if (entity.getMutability() !== 'MUTABLE') {
  33461. var _getRemovalRange = getRemovalRange(chars, entityAfterCursor, offset),
  33462. start = _getRemovalRange.start,
  33463. end = _getRemovalRange.end;
  33464. var current;
  33465. while (start < end) {
  33466. current = chars.get(start);
  33467. chars = chars.set(start, CharacterMetadata.applyEntity(current, null));
  33468. start++;
  33469. }
  33470. return block.set('characterList', chars);
  33471. }
  33472. }
  33473. return block;
  33474. }
  33475. module.exports = removeEntitiesAtEdges;
  33476. /***/ }),
  33477. /* 35 */
  33478. /***/ (function(module, exports, __webpack_require__) {
  33479. function invariant(condition, format, a, b, c, d, e, f) {
  33480. if (!condition) {
  33481. var error;
  33482. if (format === undefined) {
  33483. error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
  33484. } else {
  33485. var args = [a, b, c, d, e, f];
  33486. var argIndex = 0;
  33487. error = new Error(format.replace(/%s/g, function () {
  33488. return args[argIndex++];
  33489. }));
  33490. error.name = 'Invariant Violation';
  33491. }
  33492. error.framesToPop = 1; // we don't care about invariant's own frame
  33493. throw error;
  33494. }
  33495. }
  33496. module.exports = invariant;
  33497. /***/ }),
  33498. /* 36 */
  33499. /***/ (function(module, exports) {
  33500. function _arrayWithHoles(arr) {
  33501. if (Array.isArray(arr)) return arr;
  33502. }
  33503. module.exports = _arrayWithHoles;
  33504. /***/ }),
  33505. /* 37 */
  33506. /***/ (function(module, exports) {
  33507. function _iterableToArrayLimit(arr, i) {
  33508. var _arr = [];
  33509. var _n = true;
  33510. var _d = false;
  33511. var _e = undefined;
  33512. try {
  33513. for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
  33514. _arr.push(_s.value);
  33515. if (i && _arr.length === i) break;
  33516. }
  33517. } catch (err) {
  33518. _d = true;
  33519. _e = err;
  33520. } finally {
  33521. try {
  33522. if (!_n && _i["return"] != null) _i["return"]();
  33523. } finally {
  33524. if (_d) throw _e;
  33525. }
  33526. }
  33527. return _arr;
  33528. }
  33529. module.exports = _iterableToArrayLimit;
  33530. /***/ }),
  33531. /* 38 */
  33532. /***/ (function(module, exports) {
  33533. function _nonIterableRest() {
  33534. throw new TypeError("Invalid attempt to destructure non-iterable instance");
  33535. }
  33536. module.exports = _nonIterableRest;
  33537. /***/ }),
  33538. /* 39 */
  33539. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  33540. __webpack_require__.r(__webpack_exports__);
  33541. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/typeof.js
  33542. var helpers_typeof = __webpack_require__(15);
  33543. var typeof_default = /*#__PURE__*/__webpack_require__.n(helpers_typeof);
  33544. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/objectSpread.js
  33545. var objectSpread = __webpack_require__(5);
  33546. var objectSpread_default = /*#__PURE__*/__webpack_require__.n(objectSpread);
  33547. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/objectWithoutProperties.js
  33548. var objectWithoutProperties = __webpack_require__(21);
  33549. var objectWithoutProperties_default = /*#__PURE__*/__webpack_require__.n(objectWithoutProperties);
  33550. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/classCallCheck.js
  33551. var classCallCheck = __webpack_require__(4);
  33552. var classCallCheck_default = /*#__PURE__*/__webpack_require__.n(classCallCheck);
  33553. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/createClass.js
  33554. var createClass = __webpack_require__(7);
  33555. var createClass_default = /*#__PURE__*/__webpack_require__.n(createClass);
  33556. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js
  33557. var possibleConstructorReturn = __webpack_require__(8);
  33558. var possibleConstructorReturn_default = /*#__PURE__*/__webpack_require__.n(possibleConstructorReturn);
  33559. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/getPrototypeOf.js
  33560. var getPrototypeOf = __webpack_require__(9);
  33561. var getPrototypeOf_default = /*#__PURE__*/__webpack_require__.n(getPrototypeOf);
  33562. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/inherits.js
  33563. var inherits = __webpack_require__(10);
  33564. var inherits_default = /*#__PURE__*/__webpack_require__.n(inherits);
  33565. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/assertThisInitialized.js
  33566. var assertThisInitialized = __webpack_require__(1);
  33567. var assertThisInitialized_default = /*#__PURE__*/__webpack_require__.n(assertThisInitialized);
  33568. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/defineProperty.js
  33569. var defineProperty = __webpack_require__(2);
  33570. var defineProperty_default = /*#__PURE__*/__webpack_require__.n(defineProperty);
  33571. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/toConsumableArray.js
  33572. var toConsumableArray = __webpack_require__(12);
  33573. var toConsumableArray_default = /*#__PURE__*/__webpack_require__.n(toConsumableArray);
  33574. // EXTERNAL MODULE: ../node_modules/draft-js/dist/Draft.css
  33575. var Draft = __webpack_require__(40);
  33576. // EXTERNAL MODULE: ./assets/scss/_base.scss
  33577. var _base = __webpack_require__(42);
  33578. // EXTERNAL MODULE: external "react"
  33579. var external_react_ = __webpack_require__(0);
  33580. var external_react_default = /*#__PURE__*/__webpack_require__.n(external_react_);
  33581. // CONCATENATED MODULE: ./languages/en.js
  33582. /* harmony default export */ var en = ({
  33583. base: {
  33584. remove: 'Remove',
  33585. cancel: 'Cancel',
  33586. confirm: 'Confirm',
  33587. inert: 'Insert',
  33588. width: 'Width',
  33589. height: 'Height'
  33590. },
  33591. controls: {
  33592. clear: 'Clear',
  33593. undo: 'Undo',
  33594. redo: 'Redo',
  33595. fontSize: 'Font Size',
  33596. color: 'Color',
  33597. textColor: 'Text',
  33598. tempColors: 'Temp Colors',
  33599. backgroundColor: 'Background',
  33600. bold: 'Bold',
  33601. lineHeight: 'Line Height',
  33602. letterSpacing: 'Letter Spacing',
  33603. textIndent: 'Text Indent',
  33604. increaseIndent: 'Increase Indent',
  33605. decreaseIndent: 'Decrease Indent',
  33606. italic: 'Italic',
  33607. underline: 'Underline',
  33608. strikeThrough: 'Strike Through',
  33609. fontFamily: 'Font Family',
  33610. textAlign: 'Text Alignment',
  33611. alignLeft: 'Left Alignment',
  33612. alignCenter: 'Center Alignment',
  33613. alignRight: 'Right Alignment',
  33614. alignJustify: 'Justify Alignment',
  33615. floatLeft: 'Left Float',
  33616. floatRight: 'Right Float',
  33617. superScript: 'Super Script',
  33618. subScript: 'Sub Script',
  33619. removeStyles: 'Remove Styles',
  33620. headings: 'Headings',
  33621. header: 'Header',
  33622. normal: 'Normal',
  33623. orderedList: 'Ordered List',
  33624. unorderedList: 'Unordered List',
  33625. blockQuote: 'Quote',
  33626. code: 'Code',
  33627. link: 'Link',
  33628. unlink: 'Unlink',
  33629. hr: 'Horizontal Line',
  33630. media: 'Media',
  33631. mediaLibirary: 'Media Library',
  33632. emoji: 'Emoji',
  33633. fullscreen: 'Fullscreen',
  33634. exitFullscreen: 'Exit Fullscreen'
  33635. },
  33636. linkEditor: {
  33637. textInputPlaceHolder: 'Input link text',
  33638. linkInputPlaceHolder: 'Input link URL',
  33639. inputWithEnterPlaceHolder: 'Input link URL and press Enter',
  33640. openInNewWindow: 'Open in new window',
  33641. removeLink: 'Remove Link'
  33642. },
  33643. audioPlayer: {
  33644. title: 'Play Audio'
  33645. },
  33646. videoPlayer: {
  33647. title: 'Play Video',
  33648. embedTitle: 'Embed Media'
  33649. },
  33650. media: {
  33651. image: 'Image',
  33652. video: 'Video',
  33653. audio: 'Audio',
  33654. embed: 'Embed'
  33655. }
  33656. });
  33657. // CONCATENATED MODULE: ./languages/zh.js
  33658. /* harmony default export */ var zh = ({
  33659. base: {
  33660. remove: '删除',
  33661. cancel: '取消',
  33662. confirm: '确定',
  33663. inert: '插入',
  33664. width: '宽度',
  33665. height: '高度'
  33666. },
  33667. controls: {
  33668. clear: '清除内容',
  33669. undo: '撤销',
  33670. redo: '重做',
  33671. fontSize: '字号',
  33672. lineHeight: '行高',
  33673. letterSpacing: '字间距',
  33674. textIndent: '段落缩进',
  33675. increaseIndent: '增加缩进',
  33676. decreaseIndent: '减少缩进',
  33677. border: '边框',
  33678. color: '颜色',
  33679. textColor: '文字颜色',
  33680. backgroundColor: '背景颜色',
  33681. tempColors: '临时颜色',
  33682. bold: '加粗',
  33683. italic: '斜体',
  33684. underline: '下划线',
  33685. strikeThrough: '删除线',
  33686. fontFamily: '字体',
  33687. textAlign: '文本对齐',
  33688. alignLeft: '居左',
  33689. alignCenter: '居中',
  33690. alignRight: '居右',
  33691. alignJustify: '两端',
  33692. floatLeft: '左浮动',
  33693. floatRight: '右浮动',
  33694. superScript: '上标',
  33695. subScript: '下标',
  33696. removeStyles: '清除样式',
  33697. headings: '标题',
  33698. header: '标题',
  33699. normal: '常规',
  33700. orderedList: '有序列表',
  33701. unorderedList: '无序列表',
  33702. blockQuote: '引用',
  33703. code: '代码',
  33704. link: '链接',
  33705. unlink: '清除链接',
  33706. hr: '水平线',
  33707. media: '媒体',
  33708. mediaLibirary: '媒体库',
  33709. emoji: '小表情',
  33710. fullscreen: '全屏',
  33711. exitFullscreen: '退出全屏'
  33712. },
  33713. linkEditor: {
  33714. textInputPlaceHolder: '输入链接文字',
  33715. linkInputPlaceHolder: '输入链接地址',
  33716. inputWithEnterPlaceHolder: '输入链接地址并回车',
  33717. openInNewWindow: '在新窗口打开',
  33718. removeLink: '移除链接'
  33719. },
  33720. audioPlayer: {
  33721. title: '播放音频文件'
  33722. },
  33723. videoPlayer: {
  33724. title: '播放视频文件',
  33725. embedTitle: '嵌入式媒体'
  33726. },
  33727. media: {
  33728. image: '图像',
  33729. video: '视频',
  33730. audio: '音频',
  33731. embed: '嵌入式媒体'
  33732. }
  33733. });
  33734. // CONCATENATED MODULE: ./languages/zh-hant.js
  33735. /* harmony default export */ var zh_hant = ({
  33736. base: {
  33737. remove: '刪除',
  33738. cancel: '取消',
  33739. confirm: '確定',
  33740. inert: '插入',
  33741. width: '宽度',
  33742. height: '高度'
  33743. },
  33744. controls: {
  33745. clear: '清除内容',
  33746. undo: '撤銷',
  33747. redo: '重做',
  33748. fontSize: '字號',
  33749. color: '顏色',
  33750. textColor: '文字顏色',
  33751. backgroundColor: '背景顏色',
  33752. tempColors: '臨時顏色',
  33753. bold: '加粗',
  33754. lineHeight: '行高',
  33755. letterSpacing: '字間距',
  33756. textIndent: '段落縮進',
  33757. increaseIndent: '增加縮進',
  33758. decreaseIndent: '减少縮進',
  33759. border: '邊框',
  33760. italic: '斜體',
  33761. underline: '下劃線',
  33762. strikeThrough: '刪除線',
  33763. fontFamily: '字體',
  33764. textAlign: '文本對齊',
  33765. alignLeft: '居左',
  33766. alignCenter: '居中',
  33767. alignRight: '居右',
  33768. alignJustify: '兩端對齊',
  33769. floatLeft: '左浮動',
  33770. floatRight: '右浮動',
  33771. superScript: '上標',
  33772. subScript: '下標',
  33773. removeStyles: '清除样式',
  33774. headings: '標題',
  33775. header: '標題',
  33776. normal: '常規',
  33777. orderedList: '有序列表',
  33778. unorderedList: '無序列表',
  33779. blockQuote: '引用',
  33780. code: '代碼',
  33781. link: '鏈接',
  33782. unlink: '清除鏈接',
  33783. hr: '水平线',
  33784. media: '媒體',
  33785. mediaLibirary: '媒體库',
  33786. emoji: '小表情',
  33787. fullscreen: '全熒幕',
  33788. exitFullscreen: '退出全熒幕'
  33789. },
  33790. linkEditor: {
  33791. textInputPlaceHolder: '輸入鏈接文字',
  33792. linkInputPlaceHolder: '輸入鏈接地址',
  33793. inputWithEnterPlaceHolder: '輸入鏈接地址並回車',
  33794. openInNewWindow: '在新窗口打開',
  33795. removeLink: '移除鏈接'
  33796. },
  33797. audioPlayer: {
  33798. title: '播放音頻文件'
  33799. },
  33800. videoPlayer: {
  33801. title: '播放視頻文件',
  33802. embedTitle: '嵌入式媒體'
  33803. },
  33804. media: {
  33805. image: '圖像',
  33806. video: '視頻',
  33807. audio: '音頻',
  33808. embed: '嵌入式媒體'
  33809. }
  33810. });
  33811. // CONCATENATED MODULE: ./languages/pl.js
  33812. /* harmony default export */ var pl = ({
  33813. base: {
  33814. remove: 'Usuń',
  33815. cancel: 'Anuluj',
  33816. confirm: 'Potwierdź',
  33817. inert: 'Wstaw',
  33818. width: 'Szerokość',
  33819. height: 'Wysokość'
  33820. },
  33821. controls: {
  33822. clear: 'Wyczyść',
  33823. undo: 'Cofnij',
  33824. redo: 'Przywróć',
  33825. fontSize: 'Wielkość',
  33826. color: 'Kolor',
  33827. textColor: 'Kolor tekstu',
  33828. tempColors: 'Kolory',
  33829. backgroundColor: 'Tło',
  33830. bold: 'Pogrubienie',
  33831. lineHeight: 'Wysokość linii',
  33832. letterSpacing: 'Odstęp znaków',
  33833. textIndent: 'Wcięcie tekstu',
  33834. increaseIndent: 'Zwiększ wcięcie',
  33835. decreaseIndent: 'Zmniejsz wcięcie',
  33836. italic: 'Italiki',
  33837. underline: 'Podkreślenie',
  33838. strikeThrough: 'Przekreślenie',
  33839. fontFamily: 'Czcionka',
  33840. textAlign: 'Wyrównanie tekstu',
  33841. alignLeft: 'Do lewej',
  33842. alignCenter: 'Wycentruj',
  33843. alignRight: 'Do prawej',
  33844. alignJustify: 'Wyjustuj',
  33845. floatLeft: 'Do lewej',
  33846. floatRight: 'Do prawej',
  33847. superScript: 'Superskrypt',
  33848. subScript: 'Subskrypt',
  33849. removeStyles: 'Usuń stylowanie',
  33850. headings: 'Nagłówki',
  33851. header: 'Nagłówek',
  33852. normal: 'Normalny',
  33853. orderedList: 'Lista uporządkowana',
  33854. unorderedList: 'Lista nieuporządkowana',
  33855. blockQuote: 'Cytat',
  33856. code: 'Kod',
  33857. link: 'Link',
  33858. unlink: 'Usuń link',
  33859. hr: 'Linia pozioma',
  33860. media: 'Media',
  33861. mediaLibirary: 'Biblioteka mediów',
  33862. emoji: 'Emoji'
  33863. },
  33864. linkEditor: {
  33865. textInputPlaceHolder: 'Wpisz tekst linku',
  33866. linkInputPlaceHolder: 'Wpisz Adres URL',
  33867. inputWithEnterPlaceHolder: 'Wpisz adres URL i naciśnij Enter',
  33868. openInNewWindow: 'Otwórz w nowym oknie',
  33869. removeLink: 'Usuń link'
  33870. },
  33871. audioPlayer: {
  33872. title: 'Odtwórz audio'
  33873. },
  33874. videoPlayer: {
  33875. title: 'Odtwórz wideo',
  33876. embedTitle: 'Tytuł'
  33877. },
  33878. media: {
  33879. image: 'Obraz',
  33880. video: 'Wideo',
  33881. audio: 'Audio',
  33882. embed: 'Obiekt osadzony'
  33883. }
  33884. });
  33885. // CONCATENATED MODULE: ./languages/kr.js
  33886. /* harmony default export */ var kr = ({
  33887. base: {
  33888. remove: '삭제',
  33889. cancel: '취소',
  33890. confirm: '결정',
  33891. inert: '삽입',
  33892. width: '너비',
  33893. height: '높이'
  33894. },
  33895. controls: {
  33896. clear: '콘텐츠지우기',
  33897. undo: '취소',
  33898. redo: '다시하기',
  33899. fontSize: '글자크기',
  33900. lineHeight: '행높이',
  33901. letterSpacing: '단어간격',
  33902. textIndent: '단락들여쓰기',
  33903. increaseIndent: '들여쓰기늘리기',
  33904. decreaseIndent: '들여쓰기줄이기',
  33905. border: '국경',
  33906. color: '색상',
  33907. textColor: '텍스트색상',
  33908. backgroundColor: '배경색상',
  33909. tempColors: '임시색',
  33910. bold: '굵게',
  33911. italic: '기울임꼴',
  33912. underline: '밑줄',
  33913. strikeThrough: '취소선',
  33914. fontFamily: '글꼴',
  33915. textAlign: '텍스트정렬',
  33916. alignLeft: '왼쪽',
  33917. alignCenter: '중심',
  33918. alignRight: '오른쪽',
  33919. alignJustify: '양쪽끝',
  33920. floatLeft: '떠다니기',
  33921. floatRight: '오른쪽부동',
  33922. superScript: '위첨자',
  33923. subScript: '첨자',
  33924. removeStyles: '스타일지우기',
  33925. headings: '제목',
  33926. header: '제목',
  33927. normal: '재래식',
  33928. orderedList: '순서가지정된목록',
  33929. unorderedList: '정렬되지않은목록',
  33930. blockQuote: '참고문헌',
  33931. code: '코드',
  33932. link: '링크',
  33933. unlink: '링크삭제',
  33934. hr: '수평선',
  33935. media: '미디어',
  33936. mediaLibirary: '미디어라이브러리',
  33937. emoji: '작은표현',
  33938. fullscreen: '전체화면',
  33939. exitFullscreen: '전체화면종료'
  33940. },
  33941. linkEditor: {
  33942. textInputPlaceHolder: '링크텍스트입력',
  33943. linkInputPlaceHolder: '링크주소입력',
  33944. inputWithEnterPlaceHolder: '링크주소입력.',
  33945. openInNewWindow: '새창열기',
  33946. removeLink: '링크삭제'
  33947. },
  33948. audioPlayer: {
  33949. title: '오디오파일재생'
  33950. },
  33951. videoPlayer: {
  33952. title: '비디오파일재생',
  33953. embedTitle: '임베디드미디어'
  33954. },
  33955. media: {
  33956. image: '이미지',
  33957. video: '비디오',
  33958. audio: '오디오',
  33959. embed: '임베디드미디어'
  33960. }
  33961. });
  33962. // CONCATENATED MODULE: ./languages/tr.js
  33963. /* harmony default export */ var tr = ({
  33964. base: {
  33965. remove: 'Kaldır',
  33966. cancel: 'İptal',
  33967. confirm: 'Onayla',
  33968. inert: 'Ekle',
  33969. width: 'Genişlik',
  33970. height: 'Yükseklik'
  33971. },
  33972. controls: {
  33973. clear: 'Temizle',
  33974. undo: 'Geri al',
  33975. redo: 'İleri al',
  33976. fontSize: 'Yazı boyutu',
  33977. color: 'Renk',
  33978. textColor: 'Yazı rengi',
  33979. tempColors: 'Geçici renkler',
  33980. backgroundColor: 'Arkaplan',
  33981. bold: 'Kalın',
  33982. lineHeight: 'Satır yüksekliği',
  33983. letterSpacing: 'Harf aralığı',
  33984. textIndent: 'Çentik aralığı',
  33985. increaseIndent: 'Çentiği genişlet',
  33986. decreaseIndent: 'Çentiği daralt',
  33987. italic: 'Eğik',
  33988. underline: 'Altı çizili',
  33989. strikeThrough: 'Üstü çizili',
  33990. fontFamily: 'Yazı tipi',
  33991. textAlign: 'Metin Hizalama',
  33992. alignLeft: 'Sola hizala',
  33993. alignCenter: 'Ortaya hizala',
  33994. alignRight: 'Sağa hizala',
  33995. alignJustify: 'Her iki tarafa hizala',
  33996. floatLeft: 'Sola yatır',
  33997. floatRight: 'Sağa yatır',
  33998. superScript: 'Ana kod',
  33999. subScript: 'Alt kod',
  34000. removeStyles: 'Stilleri kaldır',
  34001. headings: 'Başlıklar',
  34002. header: 'Başlık',
  34003. normal: 'Normal',
  34004. orderedList: 'Sıralı liste',
  34005. unorderedList: 'Sırasız liste',
  34006. blockQuote: 'Alıntı',
  34007. code: 'Kod',
  34008. link: 'Bağlantı',
  34009. unlink: 'Bağlantıyı kaldır',
  34010. hr: 'Yatay çizgi',
  34011. media: 'Medya',
  34012. mediaLibirary: 'Kütüphane',
  34013. emoji: 'İfade',
  34014. fullscreen: 'Tam ekran',
  34015. exitFullscreen: 'Tam ekrandan çık'
  34016. },
  34017. linkEditor: {
  34018. textInputPlaceHolder: 'Bağlantı metnini girin',
  34019. linkInputPlaceHolder: 'Bağlantı URL\' si girin',
  34020. inputWithEnterPlaceHolder: 'Bağlantı URL\'si girin ve Enter\' a basın',
  34021. openInNewWindow: 'Yeni pencerede aç',
  34022. removeLink: 'Bağlantıyı kaldır'
  34023. },
  34024. audioPlayer: {
  34025. title: 'Ses çal'
  34026. },
  34027. videoPlayer: {
  34028. title: 'Görüntü oynat',
  34029. embedTitle: 'Görüntüyü göm'
  34030. },
  34031. media: {
  34032. image: 'Resim',
  34033. video: 'Görüntü',
  34034. audio: 'Ses',
  34035. embed: 'Gömülü nesne'
  34036. }
  34037. });
  34038. // CONCATENATED MODULE: ./languages/jpn.js
  34039. /* harmony default export */ var jpn = ({
  34040. base: {
  34041. remove: '削除',
  34042. cancel: 'キャンセル',
  34043. confirm: '決定',
  34044. inert: '挿入',
  34045. width: '幅',
  34046. height: '高さ'
  34047. },
  34048. controls: {
  34049. clear: 'クリアコンテンツ',
  34050. undo: 'キャンセル',
  34051. redo: 'キャンセル',
  34052. fontSize: 'フォントサイズ',
  34053. lineHeight: 'フォントサイズ',
  34054. letterSpacing: 'ワード間隔',
  34055. textIndent: '段落のインデント',
  34056. increaseIndent: 'インデントを増やす',
  34057. decreaseIndent: 'インデントを減らす',
  34058. border: '国境',
  34059. color: '色',
  34060. textColor: 'テキストの色',
  34061. backgroundColor: '背景色',
  34062. tempColors: '仮色',
  34063. bold: '太字',
  34064. italic: 'イタリック体',
  34065. underline: '下線',
  34066. strikeThrough: '取り消し線',
  34067. fontFamily: 'フォント',
  34068. textAlign: 'テキストの配置',
  34069. alignLeft: '左',
  34070. alignCenter: '中央揃え',
  34071. alignRight: '右に立つ',
  34072. alignJustify: '両端',
  34073. floatLeft: '左フローティング',
  34074. floatRight: '右フローティング',
  34075. superScript: '上付き',
  34076. subScript: '下付き文字',
  34077. removeStyles: 'クリアスタイル',
  34078. headings: '役職',
  34079. header: '役職',
  34080. normal: '従来の',
  34081. orderedList: '順序付きリスト',
  34082. unorderedList: '番号なしリスト',
  34083. blockQuote: '参照',
  34084. code: 'コード',
  34085. link: 'リンク',
  34086. unlink: 'リンクを解除',
  34087. hr: '横線',
  34088. media: 'メディア',
  34089. mediaLibirary: 'メディアライブラリー',
  34090. emoji: '小さな表現',
  34091. fullscreen: '全画面',
  34092. exitFullscreen: '全画面を退く'
  34093. },
  34094. linkEditor: {
  34095. textInputPlaceHolder: 'リンクテキストを入力',
  34096. linkInputPlaceHolder: 'リンクアドレスを入力',
  34097. inputWithEnterPlaceHolder: 'リンクアドレスを入力して戻ります',
  34098. openInNewWindow: '新しいウィンドウで開く',
  34099. removeLink: '新しいウィンドウで開く'
  34100. },
  34101. audioPlayer: {
  34102. title: 'オーディオファイルを再生する'
  34103. },
  34104. videoPlayer: {
  34105. title: 'ビデオファイルを再生する',
  34106. embedTitle: '埋め込みメディア'
  34107. },
  34108. media: {
  34109. image: '画像',
  34110. video: 'ビデオ',
  34111. audio: '音声',
  34112. embed: '埋め込みメディア'
  34113. }
  34114. });
  34115. // CONCATENATED MODULE: ./languages/ru.js
  34116. /* harmony default export */ var ru = ({
  34117. base: {
  34118. remove: 'Удалить',
  34119. cancel: 'Отмена',
  34120. confirm: 'Подтвердить',
  34121. insert: 'Вставить',
  34122. width: 'Ширина',
  34123. height: 'Высота'
  34124. },
  34125. controls: {
  34126. clear: 'Очистить',
  34127. undo: 'Отменить',
  34128. redo: 'Повторить',
  34129. fontSize: 'Размер шрифта',
  34130. color: 'Цвет',
  34131. textColor: 'Цвет текста',
  34132. tempColors: 'Temp Colors',
  34133. backgroundColor: 'Цвет фона',
  34134. bold: 'Жирный',
  34135. lineHeight: 'Межстрочный интервал',
  34136. letterSpacing: 'Межбуквенный интервал',
  34137. textIndent: 'Отступ',
  34138. increaseIndent: 'Увеличить отступ',
  34139. decreaseIndent: 'Уменьшить отступ',
  34140. italic: 'Курсив',
  34141. underline: 'Подчеркнутый',
  34142. strikeThrough: 'Перечеркнутый',
  34143. fontFamily: 'Шрифт',
  34144. textAlign: 'Расположение текста',
  34145. alignLeft: 'По левому краю',
  34146. alignCenter: 'По центру',
  34147. alignRight: 'По правому краю',
  34148. alignJustify: 'По ширине',
  34149. floatLeft: 'Обтекание слева',
  34150. floatRight: 'Обтекание справа',
  34151. superScript: 'Надстрочный индекс',
  34152. subScript: 'Подстрочный индекс',
  34153. removeStyles: 'Убрать стили',
  34154. headings: 'Заголовки',
  34155. header: 'Заголовок',
  34156. normal: 'Обычный',
  34157. orderedList: 'Упорядоченный список',
  34158. unorderedList: 'Неупорядоченный список',
  34159. blockQuote: 'Цитата',
  34160. code: 'Код',
  34161. link: 'Вставить ссылку',
  34162. unlink: 'Убрать ссылку',
  34163. hr: 'Горизонтальная линия',
  34164. media: 'Медиа',
  34165. mediaLibirary: 'Медиа библиотека',
  34166. emoji: 'Emoji',
  34167. fullscreen: 'Полноэкранный режим',
  34168. exitFullscreen: 'Выйти из полноэкранного режима'
  34169. },
  34170. linkEditor: {
  34171. textInputPlaceHolder: 'Введите текст ссылки',
  34172. linkInputPlaceHolder: 'Вставить ссылку',
  34173. inputWithEnterPlaceHolder: 'Вставить ссылку и нажать Enter',
  34174. openInNewWindow: 'Открыть в новом окне',
  34175. removeLink: 'Убрать ссылку'
  34176. },
  34177. audioPlayer: {
  34178. title: 'Воспроизвести аудиофайл'
  34179. },
  34180. videoPlayer: {
  34181. title: 'Воспроизвести видеофайл',
  34182. embedTitle: 'Embed Media'
  34183. },
  34184. media: {
  34185. image: 'Картинка',
  34186. video: 'Видео',
  34187. audio: 'Аудио',
  34188. embed: 'Встроенное'
  34189. }
  34190. });
  34191. // CONCATENATED MODULE: ./languages/fr.js
  34192. /* harmony default export */ var fr = ({
  34193. base: {
  34194. remove: 'Supprimer',
  34195. cancel: 'Annuler',
  34196. confirm: 'Confirmer',
  34197. inert: 'Insérer',
  34198. width: 'Largeur',
  34199. height: 'Hauteur'
  34200. },
  34201. controls: {
  34202. clear: 'Effacer',
  34203. undo: 'Annuler',
  34204. redo: 'Refaire',
  34205. fontSize: 'Taille de police',
  34206. color: 'Couleur',
  34207. textColor: 'Texte',
  34208. tempColors: 'Couleurs temporaire',
  34209. backgroundColor: 'Couleur d\'arrière plan',
  34210. bold: 'Gras',
  34211. lineHeight: 'Hauteur de ligne',
  34212. letterSpacing: 'Espacement des lettres',
  34213. textIndent: 'Indentation du texte',
  34214. increaseIndent: 'Augmenter l\'indentation',
  34215. decreaseIndent: 'Réduire l\'indentation',
  34216. italic: 'Italique',
  34217. underline: 'Souligner',
  34218. strikeThrough: 'Barrer',
  34219. fontFamily: 'Police d\'écriture',
  34220. textAlign: 'Alignement du texte',
  34221. alignLeft: 'Aligner à gauche',
  34222. alignCenter: 'Aligner au centre',
  34223. alignRight: 'Aligner à droite',
  34224. alignJustify: 'Justifier',
  34225. floatLeft: 'Déplacer à gauche',
  34226. floatRight: 'Déplacer à droite',
  34227. superScript: 'Super-script',
  34228. subScript: 'Sous-script',
  34229. removeStyles: 'Supprimer les styles',
  34230. headings: 'Titres',
  34231. header: 'Entêtes',
  34232. normal: 'Normal',
  34233. orderedList: 'Liste ordonnée',
  34234. unorderedList: 'Liste non-ordonnée',
  34235. blockQuote: 'Citation',
  34236. code: 'Code',
  34237. link: 'Insérer un lien',
  34238. unlink: 'Supprimer le lien',
  34239. hr: 'Ligne horizontale',
  34240. media: 'Média',
  34241. mediaLibirary: 'Bibliothêque',
  34242. emoji: 'Emoji',
  34243. fullscreen: 'Plein écran',
  34244. exitFullscreen: 'Quitter le plein écran'
  34245. },
  34246. linkEditor: {
  34247. textInputPlaceHolder: 'Insérer le texte à afficher',
  34248. linkInputPlaceHolder: 'Insérer le lien URL',
  34249. inputWithEnterPlaceHolder: 'Insérer le lien URL puis appuyer sur Entrée',
  34250. openInNewWindow: 'Ouvrir dans une nouvelle fenêtre',
  34251. removeLink: 'Supprimer le lien'
  34252. },
  34253. audioPlayer: {
  34254. title: 'Lancer le son audio'
  34255. },
  34256. videoPlayer: {
  34257. title: 'Lancer la video',
  34258. embedTitle: 'Intégrer média'
  34259. },
  34260. media: {
  34261. image: 'Image',
  34262. video: 'Vidéo',
  34263. audio: 'Audio',
  34264. embed: 'Intégré'
  34265. }
  34266. });
  34267. // CONCATENATED MODULE: ./languages/pt-br.js
  34268. /* harmony default export */ var pt_br = ({
  34269. base: {
  34270. remove: 'Remover',
  34271. cancel: 'Cancelar',
  34272. confirm: 'Confirmar',
  34273. inert: 'Inserir',
  34274. width: 'Largura',
  34275. height: 'Altura'
  34276. },
  34277. controls: {
  34278. clear: 'Limpar',
  34279. undo: 'Desfazer',
  34280. redo: 'Refazer',
  34281. fontSize: 'Tamanho da Fonte',
  34282. color: 'Cor',
  34283. textColor: 'Texto',
  34284. tempColors: 'Temp Colors',
  34285. backgroundColor: 'Cor de Fundo',
  34286. bold: 'Negrito',
  34287. lineHeight: 'Altura da LinhaLine Height',
  34288. letterSpacing: 'Espaçamento entre Letras',
  34289. textIndent: 'Identação de Texto',
  34290. increaseIndent: 'Aumentar Identação',
  34291. decreaseIndent: 'Diminuir Identção',
  34292. italic: 'Itálico',
  34293. underline: 'Sublinhado',
  34294. strikeThrough: 'Riscado',
  34295. fontFamily: 'Família da Fonte',
  34296. textAlign: 'Alinhamento de Texto',
  34297. alignLeft: 'Alinhamento à Esquerda',
  34298. alignCenter: 'Alinhamento Centralizado',
  34299. alignRight: 'Alinhamento à Direita',
  34300. alignJustify: 'Alinhamento Justificado',
  34301. floatLeft: 'Flutuação à Esquerda',
  34302. floatRight: 'Flutuação à Direita',
  34303. superScript: 'Sobrescrito',
  34304. subScript: 'Subscrito',
  34305. removeStyles: 'Remover Estilos',
  34306. headings: 'Cabeçalhos',
  34307. header: 'Cabeçalho',
  34308. normal: 'Normal',
  34309. orderedList: 'Lista Ordenada',
  34310. unorderedList: 'Lista Não Ordenada',
  34311. blockQuote: 'Citação',
  34312. code: 'Código',
  34313. link: 'Link',
  34314. unlink: 'Remover Link',
  34315. hr: 'Linha Horizontal',
  34316. media: 'Mídia',
  34317. mediaLibirary: 'Biblioteca de Mídia',
  34318. emoji: 'Emoji',
  34319. fullscreen: 'Tela Cheia',
  34320. exitFullscreen: 'Sair de Tela Cheia'
  34321. },
  34322. linkEditor: {
  34323. textInputPlaceHolder: 'Insira o texto do link',
  34324. linkInputPlaceHolder: 'Insira a URL do link',
  34325. inputWithEnterPlaceHolder: 'Insira a URL do link e aperte Enter',
  34326. openInNewWindow: 'Abrir em nova janela',
  34327. removeLink: 'Remover Link'
  34328. },
  34329. audioPlayer: {
  34330. title: 'Tocar Áudio'
  34331. },
  34332. videoPlayer: {
  34333. title: 'Tocar Vídeo',
  34334. embedTitle: 'Mídia Embutida'
  34335. },
  34336. media: {
  34337. image: 'Imagem',
  34338. video: 'Vídeo',
  34339. audio: 'Áudio',
  34340. embed: 'Embutido'
  34341. }
  34342. });
  34343. // CONCATENATED MODULE: ./languages/index.js
  34344. /* harmony default export */ var languages = ({
  34345. 'en': en,
  34346. 'zh': zh,
  34347. 'zh-hant': zh_hant,
  34348. 'pl': pl,
  34349. 'kr': kr,
  34350. 'tr': tr,
  34351. 'jpn': jpn,
  34352. 'ru': ru,
  34353. 'fr': fr,
  34354. 'pt-br': pt_br
  34355. });
  34356. // EXTERNAL MODULE: external "braft-finder"
  34357. var external_braft_finder_ = __webpack_require__(17);
  34358. var external_braft_finder_default = /*#__PURE__*/__webpack_require__.n(external_braft_finder_);
  34359. // EXTERNAL MODULE: external "braft-utils"
  34360. var external_braft_utils_ = __webpack_require__(3);
  34361. // EXTERNAL MODULE: external "draft-js"
  34362. var external_draft_js_ = __webpack_require__(6);
  34363. // EXTERNAL MODULE: external "immutable"
  34364. var external_immutable_ = __webpack_require__(13);
  34365. var external_immutable_default = /*#__PURE__*/__webpack_require__.n(external_immutable_);
  34366. // CONCATENATED MODULE: ./configs/keybindings.js
  34367. // TODO
  34368. // 允许自定义的快捷键设置
  34369. /* harmony default export */ var keybindings = (function (customKeyBindingFn) {
  34370. return function (event) {
  34371. if (event.keyCode === 83 && (external_draft_js_["KeyBindingUtil"].hasCommandModifier(event) || external_draft_js_["KeyBindingUtil"].isCtrlKeyCommand(event))) {
  34372. return 'braft-save';
  34373. }
  34374. if (customKeyBindingFn) {
  34375. return customKeyBindingFn(event) || Object(external_draft_js_["getDefaultKeyBinding"])(event);
  34376. }
  34377. return Object(external_draft_js_["getDefaultKeyBinding"])(event);
  34378. };
  34379. });
  34380. // CONCATENATED MODULE: ./configs/props.js
  34381. /* harmony default export */ var configs_props = ({
  34382. language: 'zh',
  34383. 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'],
  34384. excludeControls: [],
  34385. extendControls: [],
  34386. extendAtomics: [],
  34387. componentBelowControlBar: null,
  34388. media: {
  34389. pasteImage: true,
  34390. imagePasteLimit: 5,
  34391. image: true,
  34392. video: true,
  34393. audio: true,
  34394. uploadFn: null,
  34395. validateFn: null,
  34396. onBeforeDeselect: null,
  34397. onDeselect: null,
  34398. onBeforeSelect: null,
  34399. onSelect: null,
  34400. onBeforeRemove: null,
  34401. onRemove: null,
  34402. onCancel: null,
  34403. onFileSelect: null,
  34404. onBeforeInsert: null,
  34405. onInsert: null,
  34406. onChange: null,
  34407. accepts: {
  34408. image: 'image/png,image/jpeg,image/gif,image/webp,image/apng,image/svg',
  34409. video: 'video/mp4',
  34410. audio: 'audio/mp3'
  34411. },
  34412. externals: {
  34413. audio: true,
  34414. video: true,
  34415. image: true,
  34416. embed: true
  34417. }
  34418. },
  34419. imageControls: ['float-left', 'float-right', 'align-left', 'align-center', 'align-right', 'link', 'size', 'remove'],
  34420. imageResizable: true,
  34421. colors: ['#000000', '#333333', '#666666', '#999999', '#cccccc', '#ffffff', '#61a951', '#16a085', '#07a9fe', '#003ba5', '#8e44ad', '#f32784', '#c0392b', '#d35400', '#f39c12', '#fdda00'],
  34422. colorPicker: null,
  34423. colorPickerTheme: 'dark',
  34424. colorPickerAutoHide: true,
  34425. codeTabIndents: 2,
  34426. headings: ['header-one', 'header-two', 'header-three', 'header-four', 'header-five', 'header-six', 'unstyled'],
  34427. textAligns: ['left', 'center', 'right', 'justify'],
  34428. textBackgroundColor: true,
  34429. allowInsertLinkText: false,
  34430. defaultLinkTarget: '',
  34431. letterSpacings: [0, 1, 2, 3, 4, 5, 6],
  34432. lineHeights: [1, 1.2, 1.5, 1.75, 2, 2.5, 3, 4],
  34433. fontSizes: [12, 14, 16, 18, 20, 24, 28, 30, 32, 36, 40, 48, 56, 64, 72, 96, 120, 144],
  34434. fontFamilies: [{
  34435. name: 'Araial',
  34436. family: 'Arial, Helvetica, sans-serif'
  34437. }, {
  34438. name: 'Georgia',
  34439. family: 'Georgia, serif'
  34440. }, {
  34441. name: 'Impact',
  34442. family: 'Impact, serif'
  34443. }, {
  34444. name: 'Monospace',
  34445. family: '"Courier New", Courier, monospace'
  34446. }, {
  34447. name: 'Tahoma',
  34448. family: 'tahoma, arial, "Hiragino Sans GB", 宋体, sans-serif'
  34449. }],
  34450. converts: {
  34451. unitExportFn: function unitExportFn(value, type) {
  34452. return type === 'line-height' ? value : "".concat(value, "px");
  34453. }
  34454. },
  34455. emojis: ['🤣', '🙌', '💚', '💛', '👏', '😉', '💯', '💕', '💞', '💘', '💙', '💝', '🖤', '💜', '❤️', '😍', '😻', '💓', '💗', '😋', '😇', '😂', '😹', '😘', '💖', '😁', '😀', '🤞', '😲', '😄', '😊', '👍', '😌', '😃', '😅', '✌️', '🤗', '💋', '😗', '😽', '😚', '🤠', '😙', '😺', '👄', '😸', '😏', '😼', '👌', '😎', '😆', '😛', '🙏', '🤝', '🙂', '🤑', '😝', '😐', '😑', '🤤', '😤', '🙃', '🤡', '😶', '😪', '😴', '😵', '😓', '👊', '😦', '😷', '🤐', '😜', '🤓', '👻', '😥', '🙄', '🤔', '🤒', '🙁', '😔', '😯', '☹️', '☠️', '😰', '😩', '😖', '😕', '😒', '😣', '😢', '😮', '😿', '🤧', '😫', '🤥', '😞', '😬', '👎', '💀', '😳', '😨', '🤕', '🤢', '😱', '😭', '😠', '😈', '😧', '💔', '😟', '🙀', '💩', '👿', '😡', '😾', '🖕'],
  34456. stripPastedStyles: false,
  34457. triggerChangeOnMount: true,
  34458. className: '',
  34459. style: {},
  34460. controlBarClassName: '',
  34461. controlBarStyle: {},
  34462. contentClassName: '',
  34463. contentStyle: {},
  34464. draftProps: {},
  34465. hooks: {},
  34466. onChange: null,
  34467. onFocus: null,
  34468. onBlur: null,
  34469. onTab: null,
  34470. onDelete: null,
  34471. onSave: null,
  34472. fixPlaceholder: false
  34473. });
  34474. // EXTERNAL MODULE: ../node_modules/draft-js/lib/getFragmentFromSelection.js
  34475. var getFragmentFromSelection = __webpack_require__(22);
  34476. var getFragmentFromSelection_default = /*#__PURE__*/__webpack_require__.n(getFragmentFromSelection);
  34477. // EXTERNAL MODULE: external "draftjs-utils"
  34478. var external_draftjs_utils_ = __webpack_require__(23);
  34479. // CONCATENATED MODULE: ./configs/handlers.js
  34480. var handlers_keyCommandHandlers = function keyCommandHandlers(command, editorState, editor) {
  34481. if (editor.editorProps.handleKeyCommand && editor.editorProps.handleKeyCommand(command, editorState, editor) === 'handled') {
  34482. return 'handled';
  34483. }
  34484. if (command === 'braft-save') {
  34485. editor.editorProps.onSave && editor.editorProps.onSave(editorState);
  34486. return 'handled';
  34487. }
  34488. var _editor$editorProps = editor.editorProps,
  34489. controls = _editor$editorProps.controls,
  34490. excludeControls = _editor$editorProps.excludeControls;
  34491. var allowIndent = (controls.indexOf('text-indent') !== 0 || controls.find(function (item) {
  34492. return item.key === 'text-indent';
  34493. })) && excludeControls.indexOf('text-indent') === -1;
  34494. var cursorStart = editorState.getSelection().getStartOffset();
  34495. var cursorEnd = editorState.getSelection().getEndOffset();
  34496. var cursorIsAtFirst = cursorStart === 0 && cursorEnd === 0;
  34497. if (command === 'backspace') {
  34498. if (editor.editorProps.onDelete && editor.editorProps.onDelete(editorState) === false) {
  34499. return 'handled';
  34500. }
  34501. var blockType = external_braft_utils_["ContentUtils"].getSelectionBlockType(editorState);
  34502. if (allowIndent && cursorIsAtFirst && blockType !== 'code-block') {
  34503. editor.setValue(external_braft_utils_["ContentUtils"].decreaseSelectionIndent(editorState));
  34504. }
  34505. }
  34506. if (command === 'tab') {
  34507. var _blockType = external_braft_utils_["ContentUtils"].getSelectionBlockType(editorState);
  34508. if (_blockType === 'code-block') {
  34509. editor.setValue(external_braft_utils_["ContentUtils"].insertText(editorState, ' '.repeat(editor.editorProps.codeTabIndents)));
  34510. return 'handled';
  34511. } else if (_blockType === 'ordered-list-item' || _blockType === 'unordered-list-item') {
  34512. var newEditorState = external_draft_js_["RichUtils"].onTab(event, editorState, 4);
  34513. if (newEditorState !== editorState) {
  34514. editor.setValue(newEditorState);
  34515. }
  34516. return 'handled';
  34517. } else if (_blockType !== 'atomic' && allowIndent && cursorIsAtFirst) {
  34518. editor.setValue(external_braft_utils_["ContentUtils"].increaseSelectionIndent(editorState));
  34519. return 'handled';
  34520. }
  34521. }
  34522. var nextEditorState = external_braft_utils_["ContentUtils"].handleKeyCommand(editorState, command);
  34523. if (nextEditorState) {
  34524. editor.setValue(nextEditorState);
  34525. return 'handled';
  34526. }
  34527. return 'not-handled';
  34528. };
  34529. var handlers_returnHandlers = function returnHandlers(event, editorState, editor) {
  34530. if (editor.editorProps.handleReturn && editor.editorProps.handleReturn(event, editorState, editor) === 'handled') {
  34531. return 'handled';
  34532. }
  34533. var currentBlock = external_braft_utils_["ContentUtils"].getSelectionBlock(editorState);
  34534. var currentBlockType = currentBlock.getType();
  34535. if (currentBlockType === 'unordered-list-item' || currentBlockType === 'ordered-list-item') {
  34536. if (currentBlock.getLength() === 0) {
  34537. editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionBlockType(editorState, 'unstyled'));
  34538. return 'handled';
  34539. }
  34540. return 'not-handled';
  34541. } else if (currentBlockType === 'code-block') {
  34542. if (event.which === 13 && (event.getModifierState('Shift') || event.getModifierState('Alt') || event.getModifierState('Control'))) {
  34543. editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionBlockType(editorState, 'unstyled'));
  34544. return 'handled';
  34545. }
  34546. return 'not-handled';
  34547. } else if (currentBlockType === 'blockquote') {
  34548. if (event.which === 13) {
  34549. if (event.getModifierState('Shift') || event.getModifierState('Alt') || event.getModifierState('Control')) {
  34550. event.which = 0;
  34551. } else {
  34552. editor.setValue(external_draft_js_["RichUtils"].insertSoftNewline(editorState));
  34553. return 'handled';
  34554. }
  34555. }
  34556. }
  34557. var nextEditorState = Object(external_draftjs_utils_["handleNewLine"])(editorState, event);
  34558. if (nextEditorState) {
  34559. editor.setValue(nextEditorState);
  34560. return 'handled';
  34561. }
  34562. return 'not-handled';
  34563. };
  34564. var beforeInputHandlers = function beforeInputHandlers(chars, editorState, editor) {
  34565. if (editor.editorProps.handleBeforeInput && editor.editorProps.handleBeforeInput(chars, editorState, editor) === 'handled') {
  34566. return 'handled';
  34567. }
  34568. return 'not-handled';
  34569. };
  34570. var handlers_compositionStartHandler = function compositionStartHandler(_, editor) {
  34571. var editorState = editor.state.editorState;
  34572. var selectedBlocks = external_braft_utils_["ContentUtils"].getSelectedBlocks(editorState);
  34573. if (selectedBlocks && selectedBlocks.length > 1) {
  34574. var nextEditorState = external_draft_js_["EditorState"].push(editorState, external_draft_js_["Modifier"].removeRange(editorState.getCurrentContent(), editorState.getSelection(), 'backward'), 'remove-range');
  34575. editor.setValue(nextEditorState);
  34576. }
  34577. };
  34578. var handlers_dropHandlers = function dropHandlers(selectionState, dataTransfer, editor) {
  34579. if (editor.editorProps.readOnly || editor.editorProps.disabled) {
  34580. return 'handled';
  34581. }
  34582. if (window && window.__BRAFT_DRAGING__IMAGE__) {
  34583. var nextEditorState = external_draft_js_["EditorState"].forceSelection(editor.state.editorState, selectionState);
  34584. nextEditorState = external_braft_utils_["ContentUtils"].insertMedias(nextEditorState, [window.__BRAFT_DRAGING__IMAGE__.mediaData]);
  34585. nextEditorState = external_braft_utils_["ContentUtils"].removeBlock(nextEditorState, window.__BRAFT_DRAGING__IMAGE__.block, nextEditorState.getSelection());
  34586. window.__BRAFT_DRAGING__IMAGE__ = null;
  34587. editor.lockOrUnlockEditor(true);
  34588. editor.setValue(nextEditorState);
  34589. return 'handled';
  34590. } else if (!dataTransfer || !dataTransfer.getText()) {
  34591. return 'handled';
  34592. }
  34593. return 'not-handled';
  34594. };
  34595. var handlers_handleFiles = function handleFiles(files, editor) {
  34596. var _editor$constructor$d = objectSpread_default()({}, editor.constructor.defaultProps.media, editor.editorProps.media),
  34597. pasteImage = _editor$constructor$d.pasteImage,
  34598. validateFn = _editor$constructor$d.validateFn,
  34599. imagePasteLimit = _editor$constructor$d.imagePasteLimit;
  34600. pasteImage && files.slice(0, imagePasteLimit).forEach(function (file) {
  34601. if (file && file.type.indexOf('image') > -1 && editor.braftFinder) {
  34602. var validateResult = validateFn ? validateFn(file) : true;
  34603. if (validateResult instanceof Promise) {
  34604. validateResult.then(function () {
  34605. editor.braftFinder.uploadImage(file, function (image) {
  34606. editor.isLiving && editor.setValue(external_braft_utils_["ContentUtils"].insertMedias(editor.state.editorState, [image]));
  34607. });
  34608. });
  34609. } else if (validateResult) {
  34610. editor.braftFinder.uploadImage(file, function (image) {
  34611. editor.isLiving && editor.setValue(external_braft_utils_["ContentUtils"].insertMedias(editor.state.editorState, [image]));
  34612. });
  34613. }
  34614. }
  34615. });
  34616. if (files[0] && files[0].type.indexOf('image') > -1 && pasteImage) {
  34617. return 'handled';
  34618. }
  34619. return 'not-handled';
  34620. };
  34621. var droppedFilesHandlers = function droppedFilesHandlers(selectionState, files, editor) {
  34622. if (editor.editorProps.handleDroppedFiles && editor.editorProps.handleDroppedFiles(selectionState, files, editor) === 'handled') {
  34623. return 'handled';
  34624. }
  34625. return handlers_handleFiles(files, editor);
  34626. };
  34627. var pastedFilesHandlers = function pastedFilesHandlers(files, editor) {
  34628. if (editor.editorProps.handlePastedFiles && editor.editorProps.handlePastedFiles(files, editor) === 'handled') {
  34629. return 'handled';
  34630. }
  34631. return handlers_handleFiles(files, editor);
  34632. };
  34633. var handlers_copyHandlers = function copyHandlers(event, editor) {
  34634. var blockMap = getFragmentFromSelection_default()(editor.state.editorState);
  34635. if (blockMap && blockMap.toArray) {
  34636. try {
  34637. var tempContentState = external_draft_js_["ContentState"].createFromBlockArray(blockMap.toArray());
  34638. var tempEditorState = external_draft_js_["EditorState"].createWithContent(tempContentState);
  34639. var clipboardData = event.clipboardData || window.clipboardData || event.originalEvent.clipboardData;
  34640. tempEditorState.setConvertOptions(editor.state.editorState.convertOptions);
  34641. clipboardData.setData('text/html', tempEditorState.toHTML());
  34642. clipboardData.setData('text/plain', tempEditorState.toText());
  34643. event.preventDefault();
  34644. } catch (error) {
  34645. console.warn(error);
  34646. }
  34647. }
  34648. };
  34649. var handlers_pastedTextHandlers = function pastedTextHandlers(text, html, editorState, editor) {
  34650. if (editor.editorProps.handlePastedText && editor.editorProps.handlePastedText(text, html, editorState, editor) === 'handled') {
  34651. return 'handled';
  34652. }
  34653. if (!html || editor.editorProps.stripPastedStyles) {
  34654. return false;
  34655. }
  34656. var tempColors = external_braft_utils_["ColorUtils"].detectColorsFromHTMLString(html);
  34657. editor.setState({
  34658. tempColors: toConsumableArray_default()(editor.state.tempColors).concat(toConsumableArray_default()(tempColors)).filter(function (item) {
  34659. return editor.editorProps.colors.indexOf(item) === -1;
  34660. }).filter(function (item, index, array) {
  34661. return array.indexOf(item) === index;
  34662. })
  34663. }, function () {
  34664. editor.setValue(external_braft_utils_["ContentUtils"].insertHTML(editorState, html, 'paste'));
  34665. });
  34666. return 'handled';
  34667. };
  34668. // CONCATENATED MODULE: ./helpers/extension.js
  34669. // TODO
  34670. // - block-style和atomic类型的扩展支持
  34671. var extension_extensionControls = [];
  34672. var extension_extensionDecorators = [];
  34673. var extension_propInterceptors = [];
  34674. var extension_extensionBlockRenderMaps = [];
  34675. var extension_extensionBlockRendererFns = [];
  34676. var extensionInlineStyleMaps = [];
  34677. var extension_extensionInlineStyleFns = [];
  34678. var extensionEntities = [];
  34679. var inlineStyleImporters = [];
  34680. var inlineStyleExporters = [];
  34681. var blockImporters = [];
  34682. var blockExporters = [];
  34683. var filterByEditorId = function filterByEditorId(items, editorId) {
  34684. if (!editorId) {
  34685. return items.filter(function (item) {
  34686. return !item.includeEditors;
  34687. }).map(function (item) {
  34688. return item.data;
  34689. });
  34690. }
  34691. return items.map(function (item) {
  34692. if (!item.includeEditors && !item.excludeEditors) {
  34693. return item.data;
  34694. }
  34695. if (item.includeEditors) {
  34696. return item.includeEditors.indexOf(editorId) !== -1 ? item.data : false;
  34697. }
  34698. if (item.excludeEditors) {
  34699. return item.excludeEditors.indexOf(editorId) !== -1 ? false : item.data;
  34700. }
  34701. return false;
  34702. }).filter(function (item) {
  34703. return item;
  34704. });
  34705. };
  34706. var getPropInterceptors = function getPropInterceptors(editorId) {
  34707. return filterByEditorId(extension_propInterceptors, editorId);
  34708. };
  34709. var getExtensionControls = function getExtensionControls(editorId) {
  34710. return filterByEditorId(extension_extensionControls, editorId);
  34711. };
  34712. var getExtensionDecorators = function getExtensionDecorators(editorId) {
  34713. return filterByEditorId(extension_extensionDecorators, editorId);
  34714. };
  34715. var getExtensionBlockRenderMaps = function getExtensionBlockRenderMaps(editorId) {
  34716. return filterByEditorId(extension_extensionBlockRenderMaps, editorId);
  34717. };
  34718. var getExtensionBlockRendererFns = function getExtensionBlockRendererFns(editorId) {
  34719. return filterByEditorId(extension_extensionBlockRendererFns, editorId);
  34720. };
  34721. var getExtensionInlineStyleMap = function getExtensionInlineStyleMap(editorId) {
  34722. var inlineStyleMap = {};
  34723. filterByEditorId(extensionInlineStyleMaps, editorId).forEach(function (item) {
  34724. inlineStyleMap[item.inlineStyleName] = item.styleMap;
  34725. });
  34726. return inlineStyleMap;
  34727. };
  34728. var getExtensionInlineStyleFns = function getExtensionInlineStyleFns(editorId) {
  34729. return filterByEditorId(extension_extensionInlineStyleFns, editorId);
  34730. };
  34731. var compositeStyleImportFn = function compositeStyleImportFn(styleImportFn, editorId) {
  34732. return function (nodeName, node, style) {
  34733. filterByEditorId(inlineStyleImporters, editorId).forEach(function (styleImporter) {
  34734. if (styleImporter.importer && styleImporter.importer(nodeName, node)) {
  34735. style = style.add(styleImporter.inlineStyleName);
  34736. }
  34737. });
  34738. return styleImportFn ? styleImportFn(nodeName, node, style) : style;
  34739. };
  34740. };
  34741. var compositeStyleExportFn = function compositeStyleExportFn(styleExportFn, editorId) {
  34742. return function (style) {
  34743. style = style.toUpperCase();
  34744. var result = styleExportFn ? styleExportFn(style) : undefined;
  34745. if (result) {
  34746. return result;
  34747. }
  34748. filterByEditorId(inlineStyleExporters, editorId).find(function (item) {
  34749. if (item.inlineStyleName === style) {
  34750. result = item.exporter;
  34751. return true;
  34752. }
  34753. });
  34754. return result;
  34755. };
  34756. };
  34757. var compositeEntityImportFn = function compositeEntityImportFn(entityImportFn, editorId) {
  34758. return function (nodeName, node, createEntity, source) {
  34759. var result = entityImportFn ? entityImportFn(nodeName, node, createEntity, source) : null;
  34760. if (result) {
  34761. return result;
  34762. }
  34763. filterByEditorId(extensionEntities, editorId).find(function (entityItem) {
  34764. var matched = entityItem.importer ? entityItem.importer(nodeName, node, source) : null;
  34765. matched && (result = createEntity(entityItem.entityType, matched.mutability || 'MUTABLE', matched.data || {}));
  34766. return !!matched;
  34767. });
  34768. return result;
  34769. };
  34770. };
  34771. var compositeEntityExportFn = function compositeEntityExportFn(entityExportFn, editorId) {
  34772. return function (entity, originalText) {
  34773. var result = entityExportFn ? entityExportFn(entity, originalText) : undefined;
  34774. if (result) {
  34775. return result;
  34776. }
  34777. var entityType = entity.type.toUpperCase();
  34778. filterByEditorId(extensionEntities, editorId).find(function (entityItem) {
  34779. if (entityItem.entityType === entityType) {
  34780. result = entityItem.exporter ? entityItem.exporter(entity, originalText) : undefined;
  34781. return true;
  34782. }
  34783. });
  34784. return result;
  34785. };
  34786. };
  34787. var compositeBlockImportFn = function compositeBlockImportFn(blockImportFn, editorId) {
  34788. return function (nodeName, node, source) {
  34789. var result = blockImportFn ? blockImportFn(nodeName, node, source) : null;
  34790. if (result) {
  34791. return result;
  34792. }
  34793. filterByEditorId(blockImporters, editorId).find(function (blockImporter) {
  34794. var matched = blockImporter.importer ? blockImporter.importer(nodeName, node, source) : undefined;
  34795. matched && (result = matched);
  34796. return !!matched;
  34797. });
  34798. return result;
  34799. };
  34800. };
  34801. var compositeBlockExportFn = function compositeBlockExportFn(blockExportFn, editorId) {
  34802. return function (contentState, block) {
  34803. var result = blockExportFn ? blockExportFn(contentState, block) : null;
  34804. if (result) {
  34805. return result;
  34806. }
  34807. filterByEditorId(blockExporters, editorId).find(function (blockExporter) {
  34808. var matched = blockExporter.exporter ? blockExporter.exporter(contentState, block) : undefined;
  34809. matched && (result = matched);
  34810. return !!matched;
  34811. });
  34812. return result;
  34813. };
  34814. };
  34815. var extension_useExtension = function useExtension(extension) {
  34816. if (extension instanceof Array) {
  34817. extension.forEach(useExtension);
  34818. return false;
  34819. }
  34820. if (!extension || !extension.type || typeof extension.type !== 'string') {
  34821. return false;
  34822. }
  34823. var includeEditors = extension.includeEditors,
  34824. excludeEditors = extension.excludeEditors;
  34825. if (extension.type === 'control') {
  34826. extension_extensionControls.push({
  34827. includeEditors: includeEditors,
  34828. excludeEditors: excludeEditors,
  34829. data: extension.control
  34830. });
  34831. } else if (extension.type === 'inline-style') {
  34832. var inlineStyleName = extension.name.toUpperCase();
  34833. if (extension.control) {
  34834. extension_extensionControls.push({
  34835. includeEditors: includeEditors,
  34836. excludeEditors: excludeEditors,
  34837. data: objectSpread_default()({
  34838. key: inlineStyleName,
  34839. type: 'inline-style',
  34840. command: inlineStyleName
  34841. }, extension.control)
  34842. });
  34843. }
  34844. if (extension.style) {
  34845. extensionInlineStyleMaps.push({
  34846. includeEditors: includeEditors,
  34847. excludeEditors: excludeEditors,
  34848. data: {
  34849. inlineStyleName: inlineStyleName,
  34850. styleMap: extension.style
  34851. }
  34852. });
  34853. }
  34854. if (extension.styleFn) {
  34855. extension_extensionInlineStyleFns.push({
  34856. includeEditors: includeEditors,
  34857. excludeEditors: excludeEditors,
  34858. data: {
  34859. inlineStyleName: inlineStyleName,
  34860. styleFn: extension.styleFn
  34861. }
  34862. });
  34863. }
  34864. if (extension.importer) {
  34865. inlineStyleImporters.push({
  34866. includeEditors: includeEditors,
  34867. excludeEditors: excludeEditors,
  34868. data: {
  34869. inlineStyleName: inlineStyleName,
  34870. importer: extension.importer
  34871. }
  34872. });
  34873. }
  34874. inlineStyleExporters.push({
  34875. includeEditors: includeEditors,
  34876. excludeEditors: excludeEditors,
  34877. data: {
  34878. inlineStyleName: inlineStyleName,
  34879. exporter: extension.exporter ? extension.exporter(extension) : external_react_default.a.createElement("span", {
  34880. style: extension.style
  34881. })
  34882. }
  34883. });
  34884. } else if (extension.type === 'block-style') ; else if (extension.type === 'entity') {
  34885. var entityType = extension.name.toUpperCase();
  34886. if (extension.control) {
  34887. extension_extensionControls.push({
  34888. includeEditors: includeEditors,
  34889. excludeEditors: excludeEditors,
  34890. data: typeof extension.control === 'function' ? extension.control : objectSpread_default()({
  34891. key: entityType,
  34892. type: 'entity',
  34893. command: entityType,
  34894. data: {
  34895. mutability: extension.mutability || 'MUTABLE',
  34896. data: extension.data || {}
  34897. }
  34898. }, extension.control)
  34899. });
  34900. }
  34901. extensionEntities.push({
  34902. includeEditors: includeEditors,
  34903. excludeEditors: excludeEditors,
  34904. data: {
  34905. entityType: entityType,
  34906. importer: extension.importer,
  34907. exporter: extension.exporter
  34908. }
  34909. });
  34910. extension_extensionDecorators.push({
  34911. includeEditors: includeEditors,
  34912. excludeEditors: excludeEditors,
  34913. data: {
  34914. type: 'entity',
  34915. decorator: {
  34916. key: entityType,
  34917. component: extension.component
  34918. }
  34919. }
  34920. });
  34921. } else if (extension.type === 'block') {
  34922. var blockType = extension.name;
  34923. if (extension.renderMap) {
  34924. extension_extensionBlockRenderMaps.push({
  34925. includeEditors: includeEditors,
  34926. excludeEditors: excludeEditors,
  34927. data: {
  34928. blockType: blockType,
  34929. renderMap: extension.renderMap
  34930. }
  34931. });
  34932. }
  34933. if (extension.rendererFn) {
  34934. extension_extensionBlockRendererFns.push({
  34935. includeEditors: includeEditors,
  34936. excludeEditors: excludeEditors,
  34937. data: {
  34938. blockType: blockType,
  34939. rendererFn: extension.rendererFn
  34940. }
  34941. });
  34942. }
  34943. if (extension.importer) {
  34944. blockImporters.push({
  34945. includeEditors: includeEditors,
  34946. excludeEditors: excludeEditors,
  34947. data: {
  34948. blockType: blockType,
  34949. importer: extension.importer
  34950. }
  34951. });
  34952. }
  34953. if (extension.exporter) {
  34954. blockExporters.push({
  34955. includeEditors: includeEditors,
  34956. excludeEditors: excludeEditors,
  34957. data: {
  34958. blockType: blockType,
  34959. exporter: extension.exporter
  34960. }
  34961. });
  34962. }
  34963. } else if (extension.type === 'atomic') ; else if (extension.type === 'decorator') {
  34964. var decorator = extension.decorator;
  34965. if (decorator && decorator.strategy && decorator.component) {
  34966. extension_extensionDecorators.push({
  34967. includeEditors: includeEditors,
  34968. excludeEditors: excludeEditors,
  34969. data: {
  34970. type: 'strategy',
  34971. decorator: decorator
  34972. }
  34973. });
  34974. } else if (decorator && decorator.getDecorations) {
  34975. extension_extensionDecorators.push({
  34976. includeEditors: includeEditors,
  34977. excludeEditors: excludeEditors,
  34978. data: {
  34979. type: 'class',
  34980. decorator: decorator
  34981. }
  34982. });
  34983. }
  34984. } else if (extension.type === 'prop-interception') {
  34985. extension_propInterceptors.push({
  34986. includeEditors: includeEditors,
  34987. excludeEditors: excludeEditors,
  34988. data: extension.interceptor
  34989. });
  34990. }
  34991. };
  34992. var createExtensibleEditor = function createExtensibleEditor(BraftEditor) {
  34993. BraftEditor.use = extension_useExtension;
  34994. return BraftEditor;
  34995. };
  34996. // CONCATENATED MODULE: ./renderers/block/blockRenderMap.js
  34997. /* harmony default export */ var block_blockRenderMap = (function (props, blockRenderMap) {
  34998. var customBlockRenderMap = Object(external_immutable_["Map"])({
  34999. 'atomic': {
  35000. element: ''
  35001. },
  35002. 'code-block': {
  35003. element: 'code',
  35004. wrapper: external_react_default.a.createElement("pre", {
  35005. className: "braft-code-block"
  35006. })
  35007. }
  35008. });
  35009. try {
  35010. var extensionBlockRenderMaps = getExtensionBlockRenderMaps(props.editorId);
  35011. customBlockRenderMap = extensionBlockRenderMaps.reduce(function (customBlockRenderMap, item) {
  35012. return customBlockRenderMap.merge(typeof item.renderMap === 'function' ? item.renderMap(props) : item.renderMap);
  35013. }, customBlockRenderMap);
  35014. if (blockRenderMap) {
  35015. if (typeof blockRenderMap === 'function') {
  35016. customBlockRenderMap = customBlockRenderMap.merge(blockRenderMap(props));
  35017. } else {
  35018. customBlockRenderMap = customBlockRenderMap.merge(blockRenderMap);
  35019. }
  35020. }
  35021. customBlockRenderMap = external_draft_js_["DefaultDraftBlockRenderMap"].merge(customBlockRenderMap);
  35022. } catch (error) {
  35023. console.warn(error);
  35024. }
  35025. return customBlockRenderMap;
  35026. });
  35027. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/extends.js
  35028. var helpers_extends = __webpack_require__(11);
  35029. var extends_default = /*#__PURE__*/__webpack_require__.n(helpers_extends);
  35030. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/slicedToArray.js
  35031. var slicedToArray = __webpack_require__(24);
  35032. var slicedToArray_default = /*#__PURE__*/__webpack_require__.n(slicedToArray);
  35033. // EXTERNAL MODULE: ./renderers/atomics/Image/style.scss
  35034. var Image_style = __webpack_require__(45);
  35035. // EXTERNAL MODULE: ./components/common/Switch/style.scss
  35036. var Switch_style = __webpack_require__(46);
  35037. // CONCATENATED MODULE: ./components/common/Switch/index.jsx
  35038. /* harmony default export */ var Switch = (function (props) {
  35039. var active = props.active,
  35040. _onClick = props.onClick,
  35041. className = props.className;
  35042. return external_react_default.a.createElement("div", {
  35043. onClick: function onClick() {
  35044. return _onClick();
  35045. },
  35046. className: 'bf-switch ' + className + (active ? ' active' : '')
  35047. });
  35048. });
  35049. // CONCATENATED MODULE: ./configs/controls.js
  35050. /* harmony default export */ var configs_controls = (function (lang, editor) {
  35051. return [{
  35052. key: 'undo',
  35053. title: lang.controls.undo,
  35054. text: external_react_default.a.createElement("i", {
  35055. className: "bfi-undo"
  35056. }),
  35057. type: 'editor-method',
  35058. command: 'undo'
  35059. }, {
  35060. key: 'redo',
  35061. title: lang.controls.redo,
  35062. text: external_react_default.a.createElement("i", {
  35063. className: "bfi-redo"
  35064. }),
  35065. type: 'editor-method',
  35066. command: 'redo'
  35067. }, {
  35068. key: 'remove-styles',
  35069. title: lang.controls.removeStyles,
  35070. text: external_react_default.a.createElement("i", {
  35071. className: "bfi-format_clear"
  35072. }),
  35073. type: 'editor-method',
  35074. command: 'removeSelectionInlineStyles'
  35075. }, {
  35076. key: 'hr',
  35077. title: lang.controls.hr,
  35078. text: external_react_default.a.createElement("i", {
  35079. className: "bfi-hr"
  35080. }),
  35081. type: 'editor-method',
  35082. command: 'insertHorizontalLine'
  35083. }, {
  35084. key: 'bold',
  35085. title: lang.controls.bold,
  35086. text: external_react_default.a.createElement("i", {
  35087. className: "bfi-bold"
  35088. }),
  35089. type: 'inline-style',
  35090. command: 'bold'
  35091. }, {
  35092. key: 'italic',
  35093. title: lang.controls.italic,
  35094. text: external_react_default.a.createElement("i", {
  35095. className: "bfi-italic"
  35096. }),
  35097. type: 'inline-style',
  35098. command: 'italic'
  35099. }, {
  35100. key: 'underline',
  35101. title: lang.controls.underline,
  35102. text: external_react_default.a.createElement("i", {
  35103. className: "bfi-underlined"
  35104. }),
  35105. type: 'inline-style',
  35106. command: 'underline'
  35107. }, {
  35108. key: 'strike-through',
  35109. title: lang.controls.strikeThrough,
  35110. text: external_react_default.a.createElement("i", {
  35111. className: "bfi-strikethrough"
  35112. }),
  35113. type: 'inline-style',
  35114. command: 'strikethrough'
  35115. }, {
  35116. key: 'superscript',
  35117. title: lang.controls.superScript,
  35118. text: external_react_default.a.createElement("i", {
  35119. className: "bfi-superscript"
  35120. }),
  35121. type: 'inline-style',
  35122. command: 'superscript'
  35123. }, {
  35124. key: 'subscript',
  35125. title: lang.controls.subScript,
  35126. text: external_react_default.a.createElement("i", {
  35127. className: "bfi-subscript"
  35128. }),
  35129. type: 'inline-style',
  35130. command: 'subscript'
  35131. }, {
  35132. key: 'headings',
  35133. title: lang.controls.headings,
  35134. type: 'headings'
  35135. }, {
  35136. key: 'blockquote',
  35137. title: lang.controls.blockQuote,
  35138. text: external_react_default.a.createElement("i", {
  35139. className: "bfi-quote"
  35140. }),
  35141. type: 'block-type',
  35142. command: 'blockquote'
  35143. }, {
  35144. key: 'code',
  35145. title: lang.controls.code,
  35146. text: external_react_default.a.createElement("i", {
  35147. className: "bfi-code"
  35148. }),
  35149. type: 'block-type',
  35150. command: 'code-block'
  35151. }, {
  35152. key: 'list-ul',
  35153. title: lang.controls.unorderedList,
  35154. text: external_react_default.a.createElement("i", {
  35155. className: "bfi-list"
  35156. }),
  35157. type: 'block-type',
  35158. command: 'unordered-list-item'
  35159. }, {
  35160. key: 'list-ol',
  35161. title: lang.controls.orderedList,
  35162. text: external_react_default.a.createElement("i", {
  35163. className: "bfi-list-numbered"
  35164. }),
  35165. type: 'block-type',
  35166. command: 'ordered-list-item'
  35167. }, {
  35168. key: 'link',
  35169. title: lang.controls.link,
  35170. type: 'link'
  35171. }, {
  35172. key: 'text-color',
  35173. title: lang.controls.color,
  35174. type: 'text-color'
  35175. }, {
  35176. key: 'line-height',
  35177. title: lang.controls.lineHeight,
  35178. type: 'line-height'
  35179. }, {
  35180. key: 'letter-spacing',
  35181. title: lang.controls.letterSpacing,
  35182. type: 'letter-spacing'
  35183. }, {
  35184. key: 'text-indent',
  35185. title: lang.controls.textIndent,
  35186. type: 'text-indent'
  35187. }, {
  35188. key: 'font-size',
  35189. title: lang.controls.fontSize,
  35190. type: 'font-size'
  35191. }, {
  35192. key: 'font-family',
  35193. title: lang.controls.fontFamily,
  35194. type: 'font-family'
  35195. }, {
  35196. key: 'text-align',
  35197. title: lang.controls.textAlign,
  35198. type: 'text-align'
  35199. }, {
  35200. key: 'media',
  35201. title: lang.controls.media,
  35202. text: external_react_default.a.createElement("i", {
  35203. className: "bfi-media"
  35204. }),
  35205. type: 'media'
  35206. }, {
  35207. key: 'emoji',
  35208. title: lang.controls.emoji,
  35209. text: external_react_default.a.createElement("i", {
  35210. className: "bfi-emoji"
  35211. }),
  35212. type: 'emoji'
  35213. }, {
  35214. key: 'clear',
  35215. title: lang.controls.clear,
  35216. text: external_react_default.a.createElement("i", {
  35217. className: "bfi-clear_all"
  35218. }),
  35219. type: 'editor-method',
  35220. command: 'clearEditorContent'
  35221. }, {
  35222. key: 'fullscreen',
  35223. title: editor.state.isFullscreen ? lang.controls.exitFullscreen : lang.controls.fullscreen,
  35224. text: external_react_default.a.createElement("i", {
  35225. className: editor.state.isFullscreen ? 'bfi-fullscreen-exit' : 'bfi-fullscreen'
  35226. }),
  35227. type: 'editor-method',
  35228. command: 'toggleFullscreen'
  35229. }, {
  35230. key: 'modal',
  35231. type: 'modal'
  35232. }, {
  35233. key: 'button',
  35234. type: 'button'
  35235. }, {
  35236. key: 'dropdown',
  35237. type: 'dropdown'
  35238. }, {
  35239. key: 'component',
  35240. type: 'component'
  35241. }];
  35242. });
  35243. var imageControlItems = {
  35244. 'float-left': {
  35245. text: external_react_default.a.createElement("span", {
  35246. "data-float": "left"
  35247. }, "\uE91E"),
  35248. command: 'setImageFloat|left'
  35249. },
  35250. 'float-right': {
  35251. text: external_react_default.a.createElement("span", {
  35252. "data-float": "right"
  35253. }, "\uE914"),
  35254. command: 'setImageFloat|right'
  35255. },
  35256. 'align-left': {
  35257. text: external_react_default.a.createElement("span", {
  35258. "data-align": "left"
  35259. }, "\uE027"),
  35260. command: 'setImageAlignment|left'
  35261. },
  35262. 'align-center': {
  35263. text: external_react_default.a.createElement("span", {
  35264. "data-align": "center"
  35265. }, "\uE028"),
  35266. command: 'setImageAlignment|center'
  35267. },
  35268. 'align-right': {
  35269. text: external_react_default.a.createElement("span", {
  35270. "data-align": "right"
  35271. }, "\uE029"),
  35272. command: 'setImageAlignment|right'
  35273. },
  35274. 'size': {
  35275. text: external_react_default.a.createElement("span", null, "\uE3C2"),
  35276. command: 'toggleSizeEditor'
  35277. },
  35278. 'link': {
  35279. text: external_react_default.a.createElement("span", null, "\uE91A"),
  35280. command: 'toggleLinkEditor'
  35281. },
  35282. 'remove': {
  35283. text: external_react_default.a.createElement("span", null, "\uE9AC"),
  35284. command: 'removeImage'
  35285. }
  35286. };
  35287. // CONCATENATED MODULE: ./renderers/atomics/Image/index.jsx
  35288. var Image_Image =
  35289. /*#__PURE__*/
  35290. function (_React$Component) {
  35291. inherits_default()(Image, _React$Component);
  35292. function Image() {
  35293. var _getPrototypeOf2;
  35294. var _this;
  35295. classCallCheck_default()(this, Image);
  35296. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  35297. args[_key] = arguments[_key];
  35298. }
  35299. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(Image)).call.apply(_getPrototypeOf2, [this].concat(args)));
  35300. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "state", {
  35301. toolbarVisible: false,
  35302. toolbarOffset: 0,
  35303. linkEditorVisible: false,
  35304. sizeEditorVisible: false,
  35305. tempLink: null,
  35306. tempWidth: null,
  35307. tempHeight: null
  35308. });
  35309. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "initialLeft", void 0);
  35310. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "initialTop", void 0);
  35311. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "initialWidth", void 0);
  35312. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "initialHeight", void 0);
  35313. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "reSizeType", void 0);
  35314. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "changeSize", function (e) {
  35315. var type = _this.reSizeType;
  35316. if (!_this.initialLeft) {
  35317. _this.initialLeft = e.screenX;
  35318. _this.initialTop = e.screenY;
  35319. }
  35320. if (type === 'rightbottom') {
  35321. _this.initialHeight += e.screenY - _this.initialTop;
  35322. _this.initialWidth += e.screenX - _this.initialLeft;
  35323. }
  35324. if (type === 'leftbottom') {
  35325. _this.initialHeight += e.screenY - _this.initialTop;
  35326. _this.initialWidth += -e.screenX + _this.initialLeft;
  35327. }
  35328. _this.initialLeft = e.screenX;
  35329. _this.initialTop = e.screenY;
  35330. });
  35331. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "moveImage", function (e) {
  35332. _this.changeSize(e);
  35333. _this.setState({
  35334. tempWidth: Math.abs(_this.initialWidth),
  35335. tempHeight: Math.abs(_this.initialHeight)
  35336. });
  35337. });
  35338. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "upImage", function () {
  35339. _this.confirmImageSize();
  35340. document.removeEventListener('mousemove', _this.moveImage);
  35341. document.removeEventListener('mouseup', _this.upImage);
  35342. });
  35343. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "repareChangeSize", function (type) {
  35344. return function (e) {
  35345. _this.reSizeType = type;
  35346. var imageRect = _this.imageElement.getBoundingClientRect();
  35347. _this.initialLeft = _this.initialTop = 0;
  35348. _this.initialWidth = imageRect.width;
  35349. _this.initialHeight = imageRect.height;
  35350. e.preventDefault();
  35351. document.addEventListener('mousemove', _this.moveImage);
  35352. document.addEventListener('mouseup', _this.upImage);
  35353. };
  35354. });
  35355. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "preventDragEvent", function (event) {
  35356. event.stopPropagation();
  35357. event.preventDefault();
  35358. });
  35359. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleDragStart", function () {
  35360. if (_this.props.editor.editorProps.readOnly || _this.props.editor.editorProps.disabled) {
  35361. return false;
  35362. }
  35363. window.__BRAFT_DRAGING__IMAGE__ = {
  35364. block: _this.props.block,
  35365. mediaData: objectSpread_default()({
  35366. type: 'IMAGE'
  35367. }, _this.props.mediaData)
  35368. };
  35369. _this.setState({
  35370. toolbarVisible: false
  35371. }, function () {
  35372. _this.unlockEditor();
  35373. });
  35374. return true;
  35375. });
  35376. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleDragEnd", function () {
  35377. window.__BRAFT_DRAGING__IMAGE__ = null;
  35378. return false;
  35379. });
  35380. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "executeCommand", function (command) {
  35381. if (typeof command === 'string') {
  35382. var _command$split = command.split('|'),
  35383. _command$split2 = slicedToArray_default()(_command$split, 2),
  35384. method = _command$split2[0],
  35385. param = _command$split2[1];
  35386. _this[method] && _this[method](param);
  35387. } else if (typeof command === 'function') {
  35388. command(_this.props.block, _this.props.mediaData, _this.props.editor.getValue());
  35389. }
  35390. });
  35391. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "removeImage", function () {
  35392. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].removeBlock(_this.props.editor.getValue(), _this.props.block));
  35393. _this.unlockEditor();
  35394. });
  35395. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "toggleLinkEditor", function () {
  35396. _this.setState({
  35397. linkEditorVisible: !_this.state.linkEditorVisible,
  35398. sizeEditorVisible: false
  35399. });
  35400. });
  35401. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "toggleSizeEditor", function () {
  35402. _this.setState({
  35403. linkEditorVisible: false,
  35404. sizeEditorVisible: !_this.state.sizeEditorVisible
  35405. });
  35406. });
  35407. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleLinkInputKeyDown", function (e) {
  35408. if (e.keyCode === 13) {
  35409. _this.confirmImageLink();
  35410. } else {
  35411. return;
  35412. }
  35413. });
  35414. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "setImageLink", function (e) {
  35415. _this.setState({
  35416. tempLink: e.currentTarget.value
  35417. });
  35418. return;
  35419. });
  35420. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "confirmImageLink", function () {
  35421. var link = _this.state.tempLink;
  35422. var hookReturns = _this.props.hooks('set-image-link', link)(link);
  35423. if (hookReturns === false) {
  35424. return false;
  35425. }
  35426. if (typeof hookReturns === 'string') {
  35427. link = hookReturns;
  35428. }
  35429. if (link !== null) {
  35430. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].setMediaData(_this.props.editor.getValue(), _this.props.entityKey, {
  35431. link: link
  35432. }));
  35433. window.setImmediate(_this.props.editor.forceRender);
  35434. }
  35435. });
  35436. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleSizeInputKeyDown", function (e) {
  35437. if (e.keyCode === 13) {
  35438. _this.confirmImageSize();
  35439. } else {
  35440. return;
  35441. }
  35442. });
  35443. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "setImageWidth", function (_ref) {
  35444. var currentTarget = _ref.currentTarget;
  35445. var value = currentTarget.value;
  35446. value && !isNaN(value) && (value = value + 'px');
  35447. _this.setState({
  35448. tempWidth: value
  35449. });
  35450. return;
  35451. });
  35452. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "setImageHeight", function (_ref2) {
  35453. var currentTarget = _ref2.currentTarget;
  35454. var value = currentTarget.value;
  35455. value && !isNaN(value) && (value = value + 'px');
  35456. _this.setState({
  35457. tempHeight: value
  35458. });
  35459. return;
  35460. });
  35461. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "confirmImageSize", function () {
  35462. var _this$state = _this.state,
  35463. width = _this$state.tempWidth,
  35464. height = _this$state.tempHeight;
  35465. var newImageSize = {};
  35466. width !== null && (newImageSize.width = width);
  35467. height !== null && (newImageSize.height = height);
  35468. var hookReturns = _this.props.hooks('set-image-size', newImageSize)(newImageSize);
  35469. if (hookReturns === false) {
  35470. return false;
  35471. }
  35472. if (hookReturns && (hookReturns.width || hookReturns.height)) {
  35473. newImageSize = hookReturns;
  35474. }
  35475. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].setMediaData(_this.props.editor.getValue(), _this.props.entityKey, newImageSize));
  35476. window.setImmediate(_this.props.editor.forceRender);
  35477. });
  35478. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "setImageFloat", function (float) {
  35479. var hookReturns = _this.props.hooks('set-image-float', float)(float);
  35480. if (hookReturns === false) {
  35481. return false;
  35482. }
  35483. if (typeof hookReturns === 'string') {
  35484. float = hookReturns;
  35485. }
  35486. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].setMediaPosition(_this.props.editor.getValue(), _this.props.block, {
  35487. float: float
  35488. }));
  35489. _this.unlockEditor();
  35490. });
  35491. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "setImageAlignment", function (alignment) {
  35492. var hookReturns = _this.props.hooks('set-image-alignment', alignment)(alignment);
  35493. if (hookReturns === false) {
  35494. return false;
  35495. }
  35496. if (typeof hookReturns === 'string') {
  35497. alignment = hookReturns;
  35498. }
  35499. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].setMediaPosition(_this.props.editor.getValue(), _this.props.block, {
  35500. alignment: alignment
  35501. }));
  35502. _this.unlockEditor();
  35503. });
  35504. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "showToolbar", function (event) {
  35505. if (_this.props.editor.editorProps.readOnly || _this.props.editor.editorProps.disabled) {
  35506. return false;
  35507. }
  35508. event.preventDefault();
  35509. if (!_this.state.toolbarVisible) {
  35510. _this.setState({
  35511. toolbarVisible: true
  35512. }, function () {
  35513. _this.lockEditor();
  35514. _this.setState({
  35515. toolbarOffset: _this.calcToolbarOffset()
  35516. });
  35517. });
  35518. }
  35519. });
  35520. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "hideToolbar", function (event) {
  35521. event.preventDefault();
  35522. _this.setState({
  35523. toolbarVisible: false
  35524. }, function () {
  35525. _this.unlockEditor(); // this.props.editor.requestFocus()
  35526. });
  35527. });
  35528. return _this;
  35529. }
  35530. createClass_default()(Image, [{
  35531. key: "render",
  35532. value: function render() {
  35533. var _this2 = this;
  35534. var _this$props = this.props,
  35535. mediaData = _this$props.mediaData,
  35536. language = _this$props.language,
  35537. imageControls = _this$props.imageControls,
  35538. imageResizable = _this$props.imageResizable;
  35539. var _this$state2 = this.state,
  35540. toolbarVisible = _this$state2.toolbarVisible,
  35541. toolbarOffset = _this$state2.toolbarOffset,
  35542. linkEditorVisible = _this$state2.linkEditorVisible,
  35543. sizeEditorVisible = _this$state2.sizeEditorVisible,
  35544. tempWidth = _this$state2.tempWidth,
  35545. tempHeight = _this$state2.tempHeight;
  35546. var blockData = this.props.block.getData();
  35547. var float = blockData.get('float');
  35548. var alignment = blockData.get('alignment');
  35549. var url = mediaData.url,
  35550. link = mediaData.link,
  35551. link_target = mediaData.link_target,
  35552. width = mediaData.width,
  35553. height = mediaData.height,
  35554. meta = mediaData.meta;
  35555. var imageStyles = {};
  35556. var clearFix = false;
  35557. if (float) {
  35558. alignment = null;
  35559. } else if (alignment === 'left') {
  35560. imageStyles.float = 'left';
  35561. clearFix = true;
  35562. } else if (alignment === 'right') {
  35563. imageStyles.float = 'right';
  35564. clearFix = true;
  35565. } else if (alignment === 'center') {
  35566. imageStyles.textAlign = 'center';
  35567. } else {
  35568. imageStyles.float = 'left';
  35569. clearFix = true;
  35570. }
  35571. var renderedControlItems = imageControls.map(function (item, index) {
  35572. if (typeof item === 'string' && imageControlItems[item]) {
  35573. return external_react_default.a.createElement("a", {
  35574. className: item === 'link' && link ? 'active' : '',
  35575. key: index,
  35576. onClick: function onClick() {
  35577. return _this2.executeCommand(imageControlItems[item].command);
  35578. }
  35579. }, imageControlItems[item].text);
  35580. } else if (item && (item.render || item.text)) {
  35581. return item.render ? item.render(mediaData, _this2.props.block) : external_react_default.a.createElement("a", {
  35582. key: index,
  35583. onClick: function onClick() {
  35584. return item.onClick && _this2.executeCommand(item.onClick);
  35585. }
  35586. }, item.text);
  35587. } else {
  35588. return null;
  35589. }
  35590. });
  35591. return external_react_default.a.createElement("div", {
  35592. className: "bf-media"
  35593. }, external_react_default.a.createElement("div", {
  35594. style: imageStyles,
  35595. draggable: true,
  35596. onMouseEnter: this.showToolbar,
  35597. onMouseMove: this.showToolbar,
  35598. onMouseLeave: this.hideToolbar,
  35599. onDragStart: this.handleDragStart,
  35600. onDragEnd: this.handleDragEnd,
  35601. ref: function ref(instance) {
  35602. return _this2.mediaEmbederInstance = instance;
  35603. },
  35604. className: "bf-image"
  35605. }, toolbarVisible ? external_react_default.a.createElement("div", {
  35606. style: {
  35607. marginLeft: toolbarOffset
  35608. },
  35609. ref: function ref(instance) {
  35610. return _this2.toolbarElement = instance;
  35611. },
  35612. "data-float": float,
  35613. "data-align": alignment,
  35614. className: "bf-media-toolbar"
  35615. }, linkEditorVisible ? external_react_default.a.createElement("div", {
  35616. className: "bf-image-link-editor"
  35617. }, external_react_default.a.createElement("div", {
  35618. className: "editor-input-group"
  35619. }, external_react_default.a.createElement("input", {
  35620. type: "text",
  35621. placeholder: language.linkEditor.inputWithEnterPlaceHolder,
  35622. onKeyDown: this.handleLinkInputKeyDown,
  35623. onChange: this.setImageLink,
  35624. defaultValue: link
  35625. }), external_react_default.a.createElement("button", {
  35626. type: "button",
  35627. onClick: this.confirmImageLink
  35628. }, language.base.confirm)), external_react_default.a.createElement("div", {
  35629. className: "switch-group"
  35630. }, external_react_default.a.createElement(Switch, {
  35631. active: link_target === '_blank',
  35632. onClick: function onClick() {
  35633. return _this2.setImageLinkTarget(link_target);
  35634. }
  35635. }), external_react_default.a.createElement("label", null, language.linkEditor.openInNewWindow))) : null, sizeEditorVisible ? external_react_default.a.createElement("div", {
  35636. className: "bf-image-size-editor"
  35637. }, external_react_default.a.createElement("div", {
  35638. className: "editor-input-group"
  35639. }, external_react_default.a.createElement("input", {
  35640. type: "text",
  35641. placeholder: language.base.width,
  35642. onKeyDown: this.handleSizeInputKeyDown,
  35643. onChange: this.setImageWidth,
  35644. defaultValue: width
  35645. }), external_react_default.a.createElement("input", {
  35646. type: "text",
  35647. placeholder: language.base.height,
  35648. onKeyDown: this.handleSizeInputKeyDown,
  35649. onChange: this.setImageHeight,
  35650. defaultValue: height
  35651. }), external_react_default.a.createElement("button", {
  35652. type: "button",
  35653. onClick: this.confirmImageSize
  35654. }, language.base.confirm))) : null, renderedControlItems, external_react_default.a.createElement("i", {
  35655. style: {
  35656. marginLeft: toolbarOffset * -1
  35657. },
  35658. className: "bf-media-toolbar-arrow"
  35659. })) : null, external_react_default.a.createElement("div", {
  35660. style: {
  35661. position: 'relative',
  35662. width: "".concat(width, "px"),
  35663. height: "".concat(height, "px"),
  35664. display: 'inline-block'
  35665. }
  35666. }, external_react_default.a.createElement("img", extends_default()({
  35667. ref: function ref(instance) {
  35668. return _this2.imageElement = instance;
  35669. },
  35670. src: url,
  35671. width: width,
  35672. height: height
  35673. }, meta)), toolbarVisible && imageResizable ? external_react_default.a.createElement("div", {
  35674. className: "bf-csize-icon right-bottom",
  35675. onMouseDown: this.repareChangeSize('rightbottom')
  35676. }) : null, toolbarVisible && imageResizable ? external_react_default.a.createElement("div", {
  35677. className: "bf-csize-icon left-bottom",
  35678. onMouseDown: this.repareChangeSize('leftbottom')
  35679. }) : null, external_react_default.a.createElement("div", {
  35680. className: "bf-pre-csize ".concat(this.reSizeType),
  35681. style: {
  35682. width: "".concat(tempWidth, "px"),
  35683. height: "".concat(tempHeight, "px")
  35684. }
  35685. }))), clearFix && external_react_default.a.createElement("div", {
  35686. className: "clearfix",
  35687. style: {
  35688. clear: 'both',
  35689. height: 0,
  35690. lineHeight: 0,
  35691. float: 'none'
  35692. }
  35693. }));
  35694. }
  35695. }, {
  35696. key: "lockEditor",
  35697. value: function lockEditor() {
  35698. this.props.editor.lockOrUnlockEditor(true);
  35699. }
  35700. }, {
  35701. key: "unlockEditor",
  35702. value: function unlockEditor() {
  35703. this.props.editor.lockOrUnlockEditor(false);
  35704. }
  35705. }, {
  35706. key: "calcToolbarOffset",
  35707. value: function calcToolbarOffset() {
  35708. var _this$props2 = this.props,
  35709. getContainerNode = _this$props2.getContainerNode,
  35710. containerNode = _this$props2.containerNode;
  35711. var container = getContainerNode ? getContainerNode() : containerNode;
  35712. if (!container) {
  35713. return 0;
  35714. }
  35715. var viewRect = container.querySelector('.bf-content').getBoundingClientRect();
  35716. var toolbarRect = this.toolbarElement.getBoundingClientRect();
  35717. var imageRect = this.imageElement.getBoundingClientRect();
  35718. var right = viewRect.right - (imageRect.right - imageRect.width / 2 + toolbarRect.width / 2);
  35719. var left = imageRect.left + imageRect.width / 2 - toolbarRect.width / 2 - viewRect.left;
  35720. if (right < 10) {
  35721. return right - 10;
  35722. } else if (left < 10) {
  35723. return left * -1 + 10;
  35724. } else {
  35725. return 0;
  35726. }
  35727. }
  35728. }, {
  35729. key: "setImageLinkTarget",
  35730. value: function setImageLinkTarget(link_target) {
  35731. var hookReturns = this.props.hooks('set-image-link-target', link_target)(link_target);
  35732. if (hookReturns === false) {
  35733. return false;
  35734. }
  35735. if (typeof hookReturns === 'string') {
  35736. link_target = hookReturns;
  35737. }
  35738. link_target = link_target === '_blank' ? '' : '_blank';
  35739. this.props.editor.setValue(external_braft_utils_["ContentUtils"].setMediaData(this.props.editor.getValue(), this.props.entityKey, {
  35740. link_target: link_target
  35741. }));
  35742. window.setImmediate(this.props.editor.forceRender);
  35743. }
  35744. }]);
  35745. return Image;
  35746. }(external_react_default.a.Component);
  35747. // EXTERNAL MODULE: ./renderers/atomics/Video/style.scss
  35748. var Video_style = __webpack_require__(47);
  35749. // EXTERNAL MODULE: ./components/common/Modal/style.scss
  35750. var Modal_style = __webpack_require__(48);
  35751. // EXTERNAL MODULE: external "react-dom"
  35752. var external_react_dom_ = __webpack_require__(16);
  35753. var external_react_dom_default = /*#__PURE__*/__webpack_require__.n(external_react_dom_);
  35754. // CONCATENATED MODULE: ./components/common/Modal/index.jsx
  35755. var Modal_Modal =
  35756. /*#__PURE__*/
  35757. function (_React$Component) {
  35758. inherits_default()(Modal, _React$Component);
  35759. function Modal(props) {
  35760. var _this;
  35761. classCallCheck_default()(this, Modal);
  35762. _this = possibleConstructorReturn_default()(this, getPrototypeOf_default()(Modal).call(this, props));
  35763. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleTransitionEnd", function () {
  35764. if (!_this.rootElement || !_this.rootElement.classList) {
  35765. return false;
  35766. }
  35767. if (!_this.rootElement.classList.contains('active')) {
  35768. external_react_dom_default.a.unmountComponentAtNode(_this.rootElement) && _this.rootElement.parentNode.removeChild(_this.rootElement);
  35769. }
  35770. });
  35771. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleMouseDown", function (event) {
  35772. var tagName = event.target.tagName.toLowerCase();
  35773. if (tagName === 'input' || tagName === 'textarea') {
  35774. return false;
  35775. }
  35776. event.preventDefault();
  35777. });
  35778. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleCancel", function () {
  35779. _this.props.closeOnCancel && _this.close();
  35780. _this.props.onCancel && _this.props.onCancel();
  35781. });
  35782. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleConfirm", function () {
  35783. _this.props.closeOnConfirm && _this.close();
  35784. _this.props.onConfirm && _this.props.onConfirm();
  35785. });
  35786. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleMaskClick", function () {
  35787. _this.props.closeOnBlur && _this.close();
  35788. _this.props.onBlue && _this.props.onBlue();
  35789. });
  35790. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "close", function () {
  35791. _this.unrenderComponent();
  35792. _this.props.onClose && _this.props.onClose();
  35793. });
  35794. _this.active = false;
  35795. _this.componentId = 'BRAFT-MODAL-' + external_braft_utils_["BaseUtils"].UniqueIndex();
  35796. return _this;
  35797. }
  35798. createClass_default()(Modal, [{
  35799. key: "componentDidMount",
  35800. value: function componentDidMount() {
  35801. if (this.props.visible) {
  35802. this.active = true;
  35803. this.renderComponent(this.props);
  35804. }
  35805. }
  35806. }, {
  35807. key: "componentWillReceiveProps",
  35808. value: function componentWillReceiveProps(next) {
  35809. if (this.props.visible && !next.visible) {
  35810. this.unrenderComponent();
  35811. } else if (this.props.visible || next.visible) {
  35812. this.active = true;
  35813. this.renderComponent(next);
  35814. }
  35815. }
  35816. }, {
  35817. key: "render",
  35818. value: function render() {
  35819. return null;
  35820. }
  35821. }, {
  35822. key: "unrenderComponent",
  35823. value: function unrenderComponent() {
  35824. this.active = false;
  35825. this.activeId && window.clearImmediate(this.activeId);
  35826. if (this.rootElement && this.rootElement.classList) {
  35827. this.rootElement.classList.remove('active');
  35828. }
  35829. }
  35830. }, {
  35831. key: "renderComponent",
  35832. value: function renderComponent(props) {
  35833. var _this2 = this;
  35834. if (!this.active) {
  35835. return false;
  35836. }
  35837. var title = props.title,
  35838. className = props.className,
  35839. width = props.width,
  35840. height = props.height,
  35841. children = props.children,
  35842. component = props.component,
  35843. confirmable = props.confirmable,
  35844. showFooter = props.showFooter,
  35845. showCancel = props.showCancel,
  35846. showConfirm = props.showConfirm,
  35847. showClose = props.showClose,
  35848. cancelText = props.cancelText,
  35849. confirmText = props.confirmText,
  35850. bottomText = props.bottomText,
  35851. language = props.language;
  35852. typeof showCancel === 'undefined' && (showCancel = true);
  35853. typeof showClose === 'undefined' && (showClose = true);
  35854. typeof showConfirm === 'undefined' && (showConfirm = true);
  35855. typeof showFooter === 'undefined' && (showFooter = true);
  35856. var childComponent = external_react_default.a.createElement("div", {
  35857. onMouseDown: this.handleMouseDown,
  35858. className: 'bf-modal ' + (className || '')
  35859. }, external_react_default.a.createElement("div", {
  35860. className: "bf-modal-mask",
  35861. onClick: this.handleMaskClick
  35862. }), external_react_default.a.createElement("div", {
  35863. onTransitionEnd: this.handleTransitionEnd,
  35864. style: {
  35865. width: width,
  35866. height: height
  35867. },
  35868. className: "bf-modal-content"
  35869. }, external_react_default.a.createElement("div", {
  35870. className: "bf-modal-header"
  35871. }, external_react_default.a.createElement("h3", {
  35872. className: "bf-modal-caption"
  35873. }, title), showClose && external_react_default.a.createElement("button", {
  35874. type: "button",
  35875. onClick: this.close,
  35876. className: "bf-modal-close-button"
  35877. }, external_react_default.a.createElement("i", {
  35878. className: "bfi-close"
  35879. }))), external_react_default.a.createElement("div", {
  35880. className: "bf-modal-body"
  35881. }, children || component), showFooter ? external_react_default.a.createElement("div", {
  35882. className: "bf-modal-footer"
  35883. }, external_react_default.a.createElement("div", {
  35884. className: "bf-modal-addon-text"
  35885. }, bottomText), external_react_default.a.createElement("div", {
  35886. className: "bf-modal-buttons"
  35887. }, showCancel && external_react_default.a.createElement("button", {
  35888. type: "button",
  35889. onClick: this.handleCancel,
  35890. className: "bf-modal-cancel"
  35891. }, cancelText || language.base.cancel), showConfirm && external_react_default.a.createElement("button", {
  35892. type: "button",
  35893. onClick: this.handleConfirm,
  35894. className: 'bf-modal-confirm ' + (!confirmable ? 'disabled' : '')
  35895. }, confirmText || language.base.confirm))) : null));
  35896. this.rootElement = document.querySelector('#' + this.componentId);
  35897. if (!this.rootElement) {
  35898. this.rootElement = document.createElement('div');
  35899. this.rootElement.id = this.componentId;
  35900. this.rootElement.className = 'bf-modal-root';
  35901. document.body.appendChild(this.rootElement);
  35902. }
  35903. external_react_dom_default.a.render(childComponent, this.rootElement);
  35904. this.activeId = window.setImmediate(function () {
  35905. _this2.rootElement.classList.add('active');
  35906. });
  35907. }
  35908. }]);
  35909. return Modal;
  35910. }(external_react_default.a.Component);
  35911. defineProperty_default()(Modal_Modal, "defaultProps", {
  35912. showFooter: true,
  35913. closeOnBlur: true
  35914. });
  35915. var Modal_showModal = function showModal(props) {
  35916. var hostNode = document.createElement('div');
  35917. hostNode.style.display = 'none';
  35918. document.body.appendChild(hostNode);
  35919. props = objectSpread_default()({
  35920. visible: true,
  35921. closeOnConfirm: true,
  35922. closeOnCancel: true
  35923. }, props);
  35924. var close = function close() {
  35925. external_react_dom_default.a.unmountComponentAtNode(hostNode) && hostNode.parentNode.removeChild(hostNode);
  35926. };
  35927. var onConfirm = function onConfirm() {
  35928. props.onConfirm && props.onConfirm();
  35929. };
  35930. var onCancel = function onCancel() {
  35931. props.onCancel && props.onCancel();
  35932. };
  35933. var onClose = function onClose() {
  35934. close();
  35935. props.onClose && props.onClose();
  35936. };
  35937. var modalInstance = external_react_dom_default.a.render(external_react_default.a.createElement(Modal_Modal, extends_default()({}, props, {
  35938. onConfirm: onConfirm,
  35939. onCancel: onCancel,
  35940. onClose: onClose
  35941. })), hostNode);
  35942. modalInstance.destroy = close;
  35943. modalInstance.update = modalInstance.renderComponent;
  35944. return modalInstance;
  35945. };
  35946. // EXTERNAL MODULE: ./components/business/PlayerModal/style.scss
  35947. var PlayerModal_style = __webpack_require__(49);
  35948. // CONCATENATED MODULE: ./components/business/PlayerModal/index.jsx
  35949. var PlayerModal_playViaModal = function playViaModal(title, component, language) {
  35950. return Modal_showModal({
  35951. title: title,
  35952. component: component,
  35953. language: language,
  35954. showFooter: false
  35955. });
  35956. };
  35957. var typeIconsMap = {
  35958. 'video': 'bfi-film',
  35959. 'audio': 'bfi-music',
  35960. 'embed': 'bfi-code'
  35961. };
  35962. /* harmony default export */ var PlayerModal = (function (_ref) {
  35963. var title = _ref.title,
  35964. type = _ref.type,
  35965. language = _ref.language,
  35966. name = _ref.name,
  35967. url = _ref.url,
  35968. poster = _ref.poster,
  35969. children = _ref.children,
  35970. onRemove = _ref.onRemove;
  35971. return external_react_default.a.createElement("div", {
  35972. className: "bf-player-holder ".concat(type)
  35973. }, external_react_default.a.createElement("div", {
  35974. className: "icon-badge"
  35975. }, external_react_default.a.createElement("i", {
  35976. className: typeIconsMap[type]
  35977. }), external_react_default.a.createElement("span", {
  35978. className: "text"
  35979. }, language.media[type])), external_react_default.a.createElement("button", {
  35980. onMouseDown: onRemove,
  35981. className: "button-remove"
  35982. }, external_react_default.a.createElement("i", {
  35983. className: "bfi-close"
  35984. })), external_react_default.a.createElement("button", {
  35985. onMouseDown: function onMouseDown() {
  35986. return PlayerModal_playViaModal(name ? "".concat(title, ":").concat(name) : title, children, language);
  35987. },
  35988. className: "button-play"
  35989. }, external_react_default.a.createElement("i", {
  35990. className: "bfi-play_arrow"
  35991. })), name ? external_react_default.a.createElement("h5", {
  35992. className: "bf-name"
  35993. }, name) : null, external_react_default.a.createElement("h6", {
  35994. className: "bf-url"
  35995. }, url), poster ? external_react_default.a.createElement("div", {
  35996. className: "bf-poster",
  35997. style: {
  35998. backgroundImage: "url(".concat(poster, ")")
  35999. }
  36000. }) : null);
  36001. });
  36002. // CONCATENATED MODULE: ./renderers/atomics/Video/index.jsx
  36003. var Video_Video =
  36004. /*#__PURE__*/
  36005. function (_React$Component) {
  36006. inherits_default()(Video, _React$Component);
  36007. function Video() {
  36008. var _getPrototypeOf2;
  36009. var _this;
  36010. classCallCheck_default()(this, Video);
  36011. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  36012. args[_key] = arguments[_key];
  36013. }
  36014. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(Video)).call.apply(_getPrototypeOf2, [this].concat(args)));
  36015. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "removeVideo", function () {
  36016. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].removeBlock(_this.props.editorState, _this.props.block));
  36017. });
  36018. return _this;
  36019. }
  36020. createClass_default()(Video, [{
  36021. key: "render",
  36022. value: function render() {
  36023. var _this$props = this.props,
  36024. mediaData = _this$props.mediaData,
  36025. language = _this$props.language;
  36026. var url = mediaData.url,
  36027. name = mediaData.name,
  36028. meta = mediaData.meta;
  36029. return external_react_default.a.createElement("div", {
  36030. className: "bf-video-wrap"
  36031. }, external_react_default.a.createElement(PlayerModal, {
  36032. type: "video",
  36033. onRemove: this.removeVideo,
  36034. poster: meta ? meta.poster || '' : '',
  36035. language: language,
  36036. url: url,
  36037. name: name,
  36038. title: language.videoPlayer.title
  36039. }, external_react_default.a.createElement("div", {
  36040. className: "bf-video-player"
  36041. }, external_react_default.a.createElement("video", {
  36042. controls: true,
  36043. poster: meta ? meta.poster || '' : ''
  36044. }, external_react_default.a.createElement("source", {
  36045. src: url
  36046. })))));
  36047. }
  36048. }]);
  36049. return Video;
  36050. }(external_react_default.a.Component);
  36051. // EXTERNAL MODULE: ./renderers/atomics/Audio/style.scss
  36052. var Audio_style = __webpack_require__(50);
  36053. // CONCATENATED MODULE: ./renderers/atomics/Audio/index.jsx
  36054. var Audio_Audio =
  36055. /*#__PURE__*/
  36056. function (_React$Component) {
  36057. inherits_default()(Audio, _React$Component);
  36058. function Audio() {
  36059. var _getPrototypeOf2;
  36060. var _this;
  36061. classCallCheck_default()(this, Audio);
  36062. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  36063. args[_key] = arguments[_key];
  36064. }
  36065. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(Audio)).call.apply(_getPrototypeOf2, [this].concat(args)));
  36066. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "removeAudio", function () {
  36067. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].removeBlock(_this.props.editorState, _this.props.block));
  36068. });
  36069. return _this;
  36070. }
  36071. createClass_default()(Audio, [{
  36072. key: "render",
  36073. value: function render() {
  36074. var _this$props = this.props,
  36075. mediaData = _this$props.mediaData,
  36076. language = _this$props.language;
  36077. var url = mediaData.url,
  36078. name = mediaData.name,
  36079. meta = mediaData.meta;
  36080. return external_react_default.a.createElement("div", {
  36081. className: "bf-audio-wrap"
  36082. }, external_react_default.a.createElement(PlayerModal, {
  36083. type: "audio",
  36084. onRemove: this.removeAudio,
  36085. poster: meta ? meta.poster || '' : '',
  36086. language: language,
  36087. url: url,
  36088. name: name,
  36089. title: language.audioPlayer.title
  36090. }, external_react_default.a.createElement("div", {
  36091. className: "bf-audio-player"
  36092. }, external_react_default.a.createElement("audio", {
  36093. controls: true,
  36094. src: url
  36095. }))));
  36096. }
  36097. }]);
  36098. return Audio;
  36099. }(external_react_default.a.Component);
  36100. // EXTERNAL MODULE: ./renderers/atomics/Embed/style.scss
  36101. var Embed_style = __webpack_require__(51);
  36102. // CONCATENATED MODULE: ./renderers/atomics/Embed/index.jsx
  36103. var Embed_Embed =
  36104. /*#__PURE__*/
  36105. function (_React$Component) {
  36106. inherits_default()(Embed, _React$Component);
  36107. function Embed() {
  36108. var _getPrototypeOf2;
  36109. var _this;
  36110. classCallCheck_default()(this, Embed);
  36111. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  36112. args[_key] = arguments[_key];
  36113. }
  36114. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(Embed)).call.apply(_getPrototypeOf2, [this].concat(args)));
  36115. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "removeEmbed", function () {
  36116. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].removeBlock(_this.props.editorState, _this.props.block));
  36117. });
  36118. return _this;
  36119. }
  36120. createClass_default()(Embed, [{
  36121. key: "render",
  36122. value: function render() {
  36123. var _this$props = this.props,
  36124. mediaData = _this$props.mediaData,
  36125. language = _this$props.language;
  36126. var name = mediaData.name,
  36127. url = mediaData.url,
  36128. meta = mediaData.meta;
  36129. return external_react_default.a.createElement("div", {
  36130. className: "bf-embed-wrap"
  36131. }, external_react_default.a.createElement(PlayerModal, {
  36132. type: "embed",
  36133. onRemove: this.removeEmbed,
  36134. poster: meta ? meta.poster || '' : '',
  36135. language: language,
  36136. url: url,
  36137. name: name,
  36138. title: language.videoPlayer.embedTitle
  36139. }, external_react_default.a.createElement("div", {
  36140. className: "bf-embed-player",
  36141. dangerouslySetInnerHTML: {
  36142. __html: url
  36143. }
  36144. })));
  36145. }
  36146. }]);
  36147. return Embed;
  36148. }(external_react_default.a.Component);
  36149. // EXTERNAL MODULE: ./renderers/atomics/HorizontalLine/style.scss
  36150. var HorizontalLine_style = __webpack_require__(52);
  36151. // CONCATENATED MODULE: ./renderers/atomics/HorizontalLine/index.jsx
  36152. var HorizontalLine_HorizontalLine =
  36153. /*#__PURE__*/
  36154. function (_React$Component) {
  36155. inherits_default()(HorizontalLine, _React$Component);
  36156. function HorizontalLine() {
  36157. var _getPrototypeOf2;
  36158. var _this;
  36159. classCallCheck_default()(this, HorizontalLine);
  36160. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  36161. args[_key] = arguments[_key];
  36162. }
  36163. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(HorizontalLine)).call.apply(_getPrototypeOf2, [this].concat(args)));
  36164. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "removeHorizontalLine", function () {
  36165. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].removeBlock(_this.props.editorState, _this.props.block));
  36166. });
  36167. return _this;
  36168. }
  36169. createClass_default()(HorizontalLine, [{
  36170. key: "render",
  36171. value: function render() {
  36172. return external_react_default.a.createElement("div", {
  36173. className: "bf-hr"
  36174. }, external_react_default.a.createElement("div", {
  36175. className: "bf-media-toolbar"
  36176. }, external_react_default.a.createElement("a", {
  36177. onClick: this.removeHorizontalLine
  36178. }, "\uE9AC")));
  36179. }
  36180. }]);
  36181. return HorizontalLine;
  36182. }(external_react_default.a.Component);
  36183. // CONCATENATED MODULE: ./renderers/block/blockRendererFn.js
  36184. var blockRendererFn_BlockRenderFnContext = function BlockRenderFnContext() {
  36185. var _this = this;
  36186. classCallCheck_default()(this, BlockRenderFnContext);
  36187. defineProperty_default()(this, "superProps", void 0);
  36188. defineProperty_default()(this, "customBlockRendererFn", void 0);
  36189. defineProperty_default()(this, "getRenderFn", function (superProps, customBlockRendererFn) {
  36190. _this.superProps = superProps;
  36191. _this.customBlockRendererFn = customBlockRendererFn;
  36192. return _this.blockRendererFn;
  36193. });
  36194. defineProperty_default()(this, "renderAtomicBlock", function (props) {
  36195. var superProps = _this.superProps;
  36196. var entityKey = props.block.getEntityAt(0);
  36197. if (!entityKey) {
  36198. return null;
  36199. }
  36200. var entity = props.contentState.getEntity(entityKey);
  36201. var mediaData = entity.getData();
  36202. var mediaType = entity.getType();
  36203. var mediaProps = objectSpread_default()({}, superProps, {
  36204. block: props.block,
  36205. mediaData: mediaData,
  36206. entityKey: entityKey
  36207. });
  36208. if (mediaType === 'IMAGE') {
  36209. return external_react_default.a.createElement(Image_Image, mediaProps);
  36210. } else if (mediaType === 'AUDIO') {
  36211. return external_react_default.a.createElement(Audio_Audio, mediaProps);
  36212. } else if (mediaType === 'VIDEO') {
  36213. return external_react_default.a.createElement(Video_Video, mediaProps);
  36214. } else if (mediaType === 'EMBED') {
  36215. return external_react_default.a.createElement(Embed_Embed, mediaProps);
  36216. } else if (mediaType === 'HR') {
  36217. return external_react_default.a.createElement(HorizontalLine_HorizontalLine, mediaProps);
  36218. }
  36219. if (superProps.extendAtomics) {
  36220. var atomics = superProps.extendAtomics;
  36221. for (var i = 0; i < atomics.length; i++) {
  36222. if (mediaType === atomics[i].type) {
  36223. var Component = atomics[i].component;
  36224. return external_react_default.a.createElement(Component, mediaProps);
  36225. }
  36226. }
  36227. }
  36228. return null;
  36229. });
  36230. defineProperty_default()(this, "blockRendererFn", function (block) {
  36231. var customBlockRendererFn = _this.customBlockRendererFn,
  36232. superProps = _this.superProps;
  36233. var blockType = block.getType();
  36234. var blockRenderer = null;
  36235. if (customBlockRendererFn) {
  36236. blockRenderer = customBlockRendererFn(block, superProps) || null;
  36237. }
  36238. if (blockRenderer) {
  36239. return blockRenderer;
  36240. }
  36241. var extensionBlockRendererFns = getExtensionBlockRendererFns(superProps.editorId);
  36242. extensionBlockRendererFns.find(function (item) {
  36243. if (item.blockType === blockType || item.blockType instanceof RegExp && item.blockType.test(blockType)) {
  36244. blockRenderer = item.rendererFn ? item.rendererFn(superProps) : null;
  36245. return true;
  36246. }
  36247. });
  36248. if (blockRenderer) {
  36249. return blockRenderer;
  36250. }
  36251. if (blockType === 'atomic') {
  36252. blockRenderer = {
  36253. component: _this.renderAtomicBlock,
  36254. editable: false
  36255. };
  36256. }
  36257. return blockRenderer;
  36258. });
  36259. };
  36260. var blockRenderFnContext = new blockRendererFn_BlockRenderFnContext();
  36261. /* harmony default export */ var block_blockRendererFn = (blockRenderFnContext.getRenderFn);
  36262. // CONCATENATED MODULE: ./renderers/block/blockStyleFn.js
  36263. /* harmony default export */ var block_blockStyleFn = (function (customBlockStyleFn) {
  36264. return function (block) {
  36265. var blockAlignment = block.getData() && block.getData().get('textAlign');
  36266. var blockIndent = block.getData() && block.getData().get('textIndent');
  36267. var blockFloat = block.getData() && block.getData().get('float');
  36268. var result = '';
  36269. if (blockAlignment) {
  36270. result = "bfa-".concat(blockAlignment);
  36271. }
  36272. if (blockIndent && blockIndent !== 0) {
  36273. result += " bftd-".concat(blockIndent);
  36274. }
  36275. if (blockFloat) {
  36276. result += " bff-".concat(blockFloat);
  36277. }
  36278. if (customBlockStyleFn) {
  36279. result += customBlockStyleFn(block) || '';
  36280. }
  36281. return result;
  36282. };
  36283. });
  36284. // CONCATENATED MODULE: ./renderers/inline/inlineStyleMap.js
  36285. /* harmony default export */ var inlineStyleMap = (function (props) {
  36286. var customStyleMap = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  36287. var extensionInlineStyleMap = getExtensionInlineStyleMap(props.editorId);
  36288. return objectSpread_default()({
  36289. 'SUPERSCRIPT': {
  36290. position: 'relative',
  36291. top: '-8px',
  36292. fontSize: '11px'
  36293. },
  36294. 'SUBSCRIPT': {
  36295. position: 'relative',
  36296. bottom: '-8px',
  36297. fontSize: '11px'
  36298. }
  36299. }, extensionInlineStyleMap, customStyleMap);
  36300. });
  36301. // CONCATENATED MODULE: ./renderers/inline/inlineStyleFn.js
  36302. var getStyleValue = function getStyleValue(style) {
  36303. return style.split('-')[1];
  36304. };
  36305. /* harmony default export */ var inlineStyleFn = (function (props, options) {
  36306. return function (styles, block) {
  36307. var output = {};
  36308. var fontFamilies = options.fontFamilies,
  36309. unitExportFn = options.unitExportFn,
  36310. customStyleFn = options.customStyleFn;
  36311. var extensionInlineStyleFns = getExtensionInlineStyleFns(props.editorId);
  36312. extensionInlineStyleFns.forEach(function (item) {
  36313. output = item.styleFn ? item.styleFn(styles, block, output) : output;
  36314. });
  36315. output = customStyleFn ? customStyleFn(styles, block, output) : {};
  36316. styles.forEach(function (style) {
  36317. if (style.indexOf('COLOR-') === 0) {
  36318. output.color = '#' + getStyleValue(style);
  36319. } else if (style.indexOf('BGCOLOR-') === 0) {
  36320. output.backgroundColor = '#' + getStyleValue(style);
  36321. } else if (style.indexOf('FONTSIZE-') === 0) {
  36322. output.fontSize = unitExportFn(getStyleValue(style), 'font-size', 'editor');
  36323. } else if (style.indexOf('LINEHEIGHT-') === 0) {
  36324. output.lineHeight = unitExportFn(getStyleValue(style), 'line-height', 'editor');
  36325. } else if (style.indexOf('LETTERSPACING-') === 0) {
  36326. output.letterSpacing = unitExportFn(getStyleValue(style), 'letter-spacing', 'editor');
  36327. } else if (style.indexOf('TEXTINDENT-') === 0) {
  36328. output.textIndent = unitExportFn(getStyleValue(style), 'text-indent', 'editor');
  36329. } else if (style.indexOf('FONTFAMILY-') === 0) {
  36330. output.fontFamily = (fontFamilies.find(function (item) {
  36331. return item.name.toUpperCase() === getStyleValue(style);
  36332. }) || {}).family || '';
  36333. }
  36334. });
  36335. return output;
  36336. };
  36337. });
  36338. // EXTERNAL MODULE: ../node_modules/draft-js-multidecorators/index.js
  36339. var draft_js_multidecorators = __webpack_require__(18);
  36340. var draft_js_multidecorators_default = /*#__PURE__*/__webpack_require__.n(draft_js_multidecorators);
  36341. // CONCATENATED MODULE: ./renderers/decorators/Link/index.jsx
  36342. /* harmony default export */ var Link = (function (props) {
  36343. var children = props.children,
  36344. entityKey = props.entityKey,
  36345. contentState = props.contentState;
  36346. var _contentState$getEnti = contentState.getEntity(entityKey).getData(),
  36347. href = _contentState$getEnti.href,
  36348. target = _contentState$getEnti.target;
  36349. return external_react_default.a.createElement("span", {
  36350. className: "bf-link-wrap"
  36351. }, external_react_default.a.createElement("a", {
  36352. onClick: function onClick(event) {
  36353. return viewLink(event, href);
  36354. },
  36355. className: "bf-link",
  36356. href: href,
  36357. target: target
  36358. }, children));
  36359. });
  36360. var viewLink = function viewLink(event, link) {
  36361. // 当按下Ctrl/command键时,点击打开链接文字中的url
  36362. if (event.getModifierState('Control') || event.getModifierState('Meta')) {
  36363. var tempLink = document.createElement('a');
  36364. tempLink.href = link;
  36365. tempLink.target = event.currentTarget.target;
  36366. tempLink.click();
  36367. }
  36368. };
  36369. // CONCATENATED MODULE: ./renderers/decorators/index.js
  36370. var KEY_SEPARATOR = '-';
  36371. draft_js_multidecorators_default.a.prototype.getDecorations = function (block, contentState) {
  36372. var decorations = Array(block.getText().length).fill(null);
  36373. this.decorators.forEach(function (decorator, i) {
  36374. decorator.getDecorations(block, contentState).forEach(function (key, offset) {
  36375. if (!key) {
  36376. return;
  36377. }
  36378. key = i + KEY_SEPARATOR + key;
  36379. decorations[offset] = key;
  36380. });
  36381. });
  36382. return external_immutable_default.a.List(decorations);
  36383. };
  36384. var builtinDecorators = [{
  36385. type: 'entity',
  36386. decorator: {
  36387. key: 'LINK',
  36388. component: Link
  36389. }
  36390. }];
  36391. var createStrategy = function createStrategy(type) {
  36392. return function (block, callback, contentState) {
  36393. block.findEntityRanges(function (character) {
  36394. var entityKey = character.getEntity();
  36395. return entityKey !== null && contentState.getEntity(entityKey).getType() === type;
  36396. }, callback);
  36397. };
  36398. };
  36399. /* harmony default export */ var decorators = (function (editorId) {
  36400. var extensionDecorators = getExtensionDecorators(editorId);
  36401. var entityDecorators = builtinDecorators.concat(toConsumableArray_default()(extensionDecorators.filter(function (item) {
  36402. return item.type === 'entity';
  36403. })));
  36404. var strategyDecorators = extensionDecorators.filter(function (item) {
  36405. return item.type === 'strategy';
  36406. });
  36407. var classDecorators = extensionDecorators.filter(function (item) {
  36408. return item.type === 'class';
  36409. });
  36410. return new draft_js_multidecorators_default.a(toConsumableArray_default()(classDecorators.map(function (item) {
  36411. return item.decorator;
  36412. })).concat([// combine decorators created with strategy
  36413. new external_draft_js_["CompositeDecorator"](strategyDecorators.map(function (item) {
  36414. return item.decorator;
  36415. })), // combine decorators for entities
  36416. new external_draft_js_["CompositeDecorator"](entityDecorators.map(function (item) {
  36417. return {
  36418. strategy: createStrategy(item.decorator.key),
  36419. component: item.decorator.component
  36420. };
  36421. }))]));
  36422. });
  36423. // CONCATENATED MODULE: ./renderers/index.js
  36424. var getBlockRenderMap = block_blockRenderMap;
  36425. var getBlockRendererFn = block_blockRendererFn;
  36426. var getBlockStyleFn = block_blockStyleFn;
  36427. var getCustomStyleMap = inlineStyleMap;
  36428. var getCustomStyleFn = inlineStyleFn;
  36429. var getDecorators = decorators;
  36430. // EXTERNAL MODULE: ./components/business/ControlBar/style.scss
  36431. var ControlBar_style = __webpack_require__(53);
  36432. // EXTERNAL MODULE: ./components/business/LinkEditor/style.scss
  36433. var LinkEditor_style = __webpack_require__(54);
  36434. // EXTERNAL MODULE: ./components/common/DropDown/style.scss
  36435. var DropDown_style = __webpack_require__(55);
  36436. // CONCATENATED MODULE: ./helpers/responsive.js
  36437. var resizeEventHandlers = [];
  36438. var responsiveHelperInited = false;
  36439. var debouce = false;
  36440. /* harmony default export */ var responsive = ({
  36441. resolve: function resolve(eventHandler) {
  36442. var id = external_braft_utils_["BaseUtils"].UniqueIndex();
  36443. resizeEventHandlers.push({
  36444. id: id,
  36445. eventHandler: eventHandler
  36446. });
  36447. return id;
  36448. },
  36449. unresolve: function unresolve(id) {
  36450. resizeEventHandlers = resizeEventHandlers.filter(function (item) {
  36451. return item.id !== id;
  36452. });
  36453. }
  36454. });
  36455. if (!responsiveHelperInited && (typeof window === "undefined" ? "undefined" : typeof_default()(window)) === 'object') {
  36456. window.addEventListener('resize', function (event) {
  36457. clearTimeout(debouce);
  36458. debouce = setTimeout(function () {
  36459. resizeEventHandlers.map(function (item) {
  36460. typeof item.eventHandler === 'function' && item.eventHandler(event);
  36461. });
  36462. debouce = false;
  36463. }, 100);
  36464. });
  36465. responsiveHelperInited = true;
  36466. }
  36467. // CONCATENATED MODULE: ./components/common/DropDown/index.jsx
  36468. var DropDown_DropDown =
  36469. /*#__PURE__*/
  36470. function (_React$Component) {
  36471. inherits_default()(DropDown, _React$Component);
  36472. function DropDown() {
  36473. var _getPrototypeOf2;
  36474. var _this;
  36475. classCallCheck_default()(this, DropDown);
  36476. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  36477. args[_key] = arguments[_key];
  36478. }
  36479. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(DropDown)).call.apply(_getPrototypeOf2, [this].concat(args)));
  36480. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "responsiveResolveId", null);
  36481. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "dropDownHandlerElement", null);
  36482. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "dropDownContentElement", null);
  36483. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "state", {
  36484. active: false,
  36485. offset: 0
  36486. });
  36487. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "fixDropDownPosition", function () {
  36488. var viewRect = _this.props.getContainerNode().getBoundingClientRect();
  36489. var handlerRect = _this.dropDownHandlerElement.getBoundingClientRect();
  36490. var contentRect = _this.dropDownContentElement.getBoundingClientRect();
  36491. var offset = 0;
  36492. var right = handlerRect.right - handlerRect.width / 2 + contentRect.width / 2;
  36493. var left = handlerRect.left + handlerRect.width / 2 - contentRect.width / 2;
  36494. right = viewRect.right - right;
  36495. left = left - viewRect.left;
  36496. if (right < 10) {
  36497. offset = right - 10;
  36498. } else if (left < 10) {
  36499. offset = left * -1 + 10;
  36500. }
  36501. if (offset !== _this.state.offset) {
  36502. _this.setState({
  36503. offset: offset
  36504. });
  36505. }
  36506. });
  36507. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "registerClickEvent", function (event) {
  36508. var autoHide = _this.props.autoHide;
  36509. var active = _this.state.active;
  36510. if (_this.dropDownContentElement.contains(event.target) || _this.dropDownHandlerElement.contains(event.target)) {
  36511. return false;
  36512. }
  36513. autoHide && active && _this.hide();
  36514. });
  36515. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "toggle", function () {
  36516. _this.setState({
  36517. active: !_this.state.active
  36518. });
  36519. });
  36520. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "show", function () {
  36521. _this.setState({
  36522. active: true
  36523. });
  36524. });
  36525. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "hide", function () {
  36526. _this.setState({
  36527. active: false
  36528. });
  36529. });
  36530. return _this;
  36531. }
  36532. createClass_default()(DropDown, [{
  36533. key: "componentDidMount",
  36534. value: function componentDidMount() {
  36535. if (document) {
  36536. document.body.addEventListener('click', this.registerClickEvent);
  36537. this.responsiveResolveId = responsive.resolve(this.fixDropDownPosition);
  36538. }
  36539. }
  36540. }, {
  36541. key: "componentWillReceiveProps",
  36542. value: function componentWillReceiveProps(next) {
  36543. if (!this.props.disabled && next.disabled) {
  36544. this.hide();
  36545. }
  36546. }
  36547. }, {
  36548. key: "componentDidUpdate",
  36549. value: function componentDidUpdate(prevState) {
  36550. if (!prevState.active && this.state.active) {
  36551. this.fixDropDownPosition();
  36552. }
  36553. }
  36554. }, {
  36555. key: "componentWillUnmount",
  36556. value: function componentWillUnmount() {
  36557. if (document) {
  36558. document.body.removeEventListener('click', this.registerClickEvent);
  36559. responsive.unresolve(this.responsiveResolveId);
  36560. }
  36561. }
  36562. }, {
  36563. key: "render",
  36564. value: function render() {
  36565. var _this2 = this;
  36566. var _this$state = this.state,
  36567. active = _this$state.active,
  36568. offset = _this$state.offset;
  36569. var _this$props = this.props,
  36570. caption = _this$props.caption,
  36571. htmlCaption = _this$props.htmlCaption,
  36572. title = _this$props.title,
  36573. disabled = _this$props.disabled,
  36574. showArrow = _this$props.showArrow,
  36575. arrowActive = _this$props.arrowActive,
  36576. className = _this$props.className,
  36577. children = _this$props.children,
  36578. theme = _this$props.theme;
  36579. disabled && (active = false);
  36580. theme === 'light' && (className = ' light-theme ' + className);
  36581. return external_react_default.a.createElement("div", {
  36582. className: 'bf-dropdown ' + (active ? 'active ' : '') + (disabled ? 'disabled ' : '') + className
  36583. }, htmlCaption ? external_react_default.a.createElement("button", {
  36584. type: "button",
  36585. className: "dropdown-handler",
  36586. "data-title": title,
  36587. onClick: this.toggle,
  36588. dangerouslySetInnerHTML: htmlCaption ? {
  36589. __html: htmlCaption
  36590. } : null,
  36591. ref: function ref(instance) {
  36592. return _this2.dropDownHandlerElement = instance;
  36593. }
  36594. }) : external_react_default.a.createElement("button", {
  36595. type: "button",
  36596. className: "dropdown-handler",
  36597. "data-title": title,
  36598. onClick: this.toggle,
  36599. ref: function ref(instance) {
  36600. return _this2.dropDownHandlerElement = instance;
  36601. }
  36602. }, external_react_default.a.createElement("span", null, caption), showArrow !== false ? external_react_default.a.createElement("i", {
  36603. className: "bfi-drop-down"
  36604. }) : null), external_react_default.a.createElement("div", {
  36605. className: "dropdown-content",
  36606. style: {
  36607. marginLeft: offset
  36608. },
  36609. ref: function ref(instance) {
  36610. return _this2.dropDownContentElement = instance;
  36611. }
  36612. }, external_react_default.a.createElement("i", {
  36613. style: {
  36614. marginLeft: offset * -1
  36615. },
  36616. className: 'dropdown-arrow' + (arrowActive ? ' active' : '')
  36617. }), external_react_default.a.createElement("div", {
  36618. className: "dropdown-content-inner"
  36619. }, children)));
  36620. }
  36621. }]);
  36622. return DropDown;
  36623. }(external_react_default.a.Component);
  36624. // CONCATENATED MODULE: ./components/business/ControlGroup/index.jsx
  36625. /* harmony default export */ var ControlGroup = (function (props) {
  36626. if (external_react_default.a.Fragment) {
  36627. return external_react_default.a.createElement(external_react_default.a.Fragment, null, props.children);
  36628. } else {
  36629. return external_react_default.a.createElement("div", {
  36630. className: "control-item-group"
  36631. }, props.children);
  36632. }
  36633. });
  36634. // CONCATENATED MODULE: ./components/business/LinkEditor/index.jsx
  36635. var LinkEditor_LinkEditor =
  36636. /*#__PURE__*/
  36637. function (_React$Component) {
  36638. inherits_default()(LinkEditor, _React$Component);
  36639. function LinkEditor(props) {
  36640. var _this;
  36641. classCallCheck_default()(this, LinkEditor);
  36642. _this = possibleConstructorReturn_default()(this, getPrototypeOf_default()(LinkEditor).call(this, props));
  36643. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "dropDownInstance", null);
  36644. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handeKeyDown", function (e) {
  36645. if (e.keyCode === 13) {
  36646. _this.handleConfirm();
  36647. e.preventDefault();
  36648. return false;
  36649. }
  36650. });
  36651. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleTnputText", function (e) {
  36652. _this.setState({
  36653. text: e.currentTarget.value
  36654. });
  36655. });
  36656. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleInputLink", function (e) {
  36657. _this.setState({
  36658. href: e.currentTarget.value
  36659. });
  36660. });
  36661. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "setTarget", function () {
  36662. _this.setState({
  36663. target: _this.state.target === '_blank' ? '' : '_blank'
  36664. });
  36665. });
  36666. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleCancel", function () {
  36667. _this.dropDownInstance.hide();
  36668. });
  36669. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleUnlink", function () {
  36670. _this.dropDownInstance.hide();
  36671. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionLink(_this.props.editorState, false));
  36672. });
  36673. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleConfirm", function () {
  36674. var _this$state = _this.state,
  36675. text = _this$state.text,
  36676. href = _this$state.href,
  36677. target = _this$state.target,
  36678. textSelected = _this$state.textSelected;
  36679. var hookReturns = _this.props.hooks('toggle-link', {
  36680. href: href,
  36681. target: target
  36682. })({
  36683. href: href,
  36684. target: target
  36685. });
  36686. _this.dropDownInstance.hide();
  36687. _this.props.editor.requestFocus();
  36688. if (hookReturns === false) {
  36689. return false;
  36690. }
  36691. if (hookReturns) {
  36692. typeof hookReturns.href === 'string' && (href = hookReturns.href);
  36693. typeof hookReturns.target === 'string' && (target = hookReturns.target);
  36694. }
  36695. if (textSelected) {
  36696. if (href) {
  36697. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionLink(_this.props.editorState, href, target));
  36698. } else {
  36699. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionLink(_this.props.editorState, false));
  36700. }
  36701. } else {
  36702. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].insertText(_this.props.editorState, text || href, null, {
  36703. type: 'LINK',
  36704. data: {
  36705. href: href,
  36706. target: target
  36707. }
  36708. }));
  36709. }
  36710. });
  36711. _this.state = {
  36712. text: '',
  36713. href: '',
  36714. target: props.defaultLinkTarget || '',
  36715. textSelected: false
  36716. };
  36717. return _this;
  36718. }
  36719. createClass_default()(LinkEditor, [{
  36720. key: "componentWillReceiveProps",
  36721. value: function componentWillReceiveProps(nextProps) {
  36722. var _ContentUtils$getSele = external_braft_utils_["ContentUtils"].getSelectionEntityData(nextProps.editorState, 'LINK'),
  36723. href = _ContentUtils$getSele.href,
  36724. target = _ContentUtils$getSele.target;
  36725. var textSelected = !external_braft_utils_["ContentUtils"].isSelectionCollapsed(this.props.editorState) && external_braft_utils_["ContentUtils"].getSelectionBlockType(this.props.editorState) !== 'atomic';
  36726. var selectedText = '';
  36727. if (textSelected) {
  36728. selectedText = external_braft_utils_["ContentUtils"].getSelectionText(this.props.editorState);
  36729. }
  36730. this.setState({
  36731. textSelected: textSelected,
  36732. text: selectedText,
  36733. href: href || '',
  36734. target: typeof target === 'undefined' ? nextProps.defaultLinkTarget || '' : target || ''
  36735. });
  36736. }
  36737. }, {
  36738. key: "render",
  36739. value: function render() {
  36740. var _this2 = this;
  36741. var allowInsertLinkText = this.props.allowInsertLinkText;
  36742. var _this$state2 = this.state,
  36743. text = _this$state2.text,
  36744. href = _this$state2.href,
  36745. target = _this$state2.target,
  36746. textSelected = _this$state2.textSelected;
  36747. var caption = external_react_default.a.createElement("i", {
  36748. className: "bfi-link"
  36749. });
  36750. return external_react_default.a.createElement(ControlGroup, null, external_react_default.a.createElement(DropDown_DropDown, {
  36751. key: 0,
  36752. caption: caption,
  36753. title: this.props.language.controls.link,
  36754. autoHide: true,
  36755. getContainerNode: this.props.getContainerNode,
  36756. showArrow: false,
  36757. ref: function ref(instance) {
  36758. return _this2.dropDownInstance = instance;
  36759. },
  36760. className: 'control-item dropdown link-editor-dropdown'
  36761. }, external_react_default.a.createElement("div", {
  36762. className: "bf-link-editor"
  36763. }, allowInsertLinkText ? external_react_default.a.createElement("div", {
  36764. className: "input-group"
  36765. }, external_react_default.a.createElement("input", {
  36766. type: "text",
  36767. value: text,
  36768. spellCheck: false,
  36769. disabled: textSelected,
  36770. placeholder: this.props.language.linkEditor.textInputPlaceHolder,
  36771. onKeyDown: this.handeKeyDown,
  36772. onChange: this.handleTnputText
  36773. })) : null, external_react_default.a.createElement("div", {
  36774. className: "input-group"
  36775. }, external_react_default.a.createElement("input", {
  36776. type: "text",
  36777. value: href,
  36778. spellCheck: false,
  36779. placeholder: this.props.language.linkEditor.linkInputPlaceHolder,
  36780. onKeyDown: this.handeKeyDown,
  36781. onChange: this.handleInputLink
  36782. })), external_react_default.a.createElement("div", {
  36783. className: "switch-group"
  36784. }, external_react_default.a.createElement(Switch, {
  36785. active: target === '_blank',
  36786. onClick: this.setTarget
  36787. }), external_react_default.a.createElement("label", null, this.props.language.linkEditor.openInNewWindow)), external_react_default.a.createElement("div", {
  36788. className: "buttons"
  36789. }, external_react_default.a.createElement("a", {
  36790. onClick: this.handleUnlink,
  36791. className: "primary button-remove-link pull-left"
  36792. }, external_react_default.a.createElement("i", {
  36793. className: "bfi-close"
  36794. }), external_react_default.a.createElement("span", null, this.props.language.linkEditor.removeLink)), external_react_default.a.createElement("button", {
  36795. type: "button",
  36796. onClick: this.handleConfirm,
  36797. className: "primary pull-right"
  36798. }, this.props.language.base.confirm), external_react_default.a.createElement("button", {
  36799. type: "button",
  36800. onClick: this.handleCancel,
  36801. className: "default pull-right"
  36802. }, this.props.language.base.cancel)))), external_react_default.a.createElement("button", {
  36803. key: 1,
  36804. type: "button",
  36805. "data-title": this.props.language.controls.unlink,
  36806. className: "control-item button",
  36807. onClick: this.handleUnlink,
  36808. disabled: !textSelected || !href
  36809. }, external_react_default.a.createElement("i", {
  36810. className: "bfi-link-off"
  36811. })));
  36812. }
  36813. }]);
  36814. return LinkEditor;
  36815. }(external_react_default.a.Component);
  36816. // EXTERNAL MODULE: ./components/business/Headings/style.scss
  36817. var Headings_style = __webpack_require__(56);
  36818. // CONCATENATED MODULE: ./configs/maps.js
  36819. var maps_getHeadings = function getHeadings(lang) {
  36820. return [{
  36821. key: 'header-one',
  36822. title: lang.controls.header + ' 1',
  36823. text: external_react_default.a.createElement("h1", null, lang.controls.header, " 1"),
  36824. type: 'block-type',
  36825. command: 'header-one'
  36826. }, {
  36827. key: 'header-two',
  36828. title: lang.controls.header + ' 2',
  36829. text: external_react_default.a.createElement("h2", null, lang.controls.header, " 2"),
  36830. type: 'block-type',
  36831. command: 'header-two'
  36832. }, {
  36833. key: 'header-three',
  36834. title: lang.controls.header + ' 3',
  36835. text: external_react_default.a.createElement("h3", null, lang.controls.header, " 3"),
  36836. type: 'block-type',
  36837. command: 'header-three'
  36838. }, {
  36839. key: 'header-four',
  36840. title: lang.controls.header + ' 4',
  36841. text: external_react_default.a.createElement("h4", null, lang.controls.header, " 4"),
  36842. type: 'block-type',
  36843. command: 'header-four'
  36844. }, {
  36845. key: 'header-five',
  36846. title: lang.controls.header + ' 5',
  36847. text: external_react_default.a.createElement("h5", null, lang.controls.header, " 5"),
  36848. type: 'block-type',
  36849. command: 'header-five'
  36850. }, {
  36851. key: 'header-six',
  36852. title: lang.controls.header + ' 6',
  36853. text: external_react_default.a.createElement("h6", null, lang.controls.header, " 6"),
  36854. type: 'block-type',
  36855. command: 'header-six'
  36856. }, {
  36857. key: 'unstyled',
  36858. title: lang.controls.normal,
  36859. text: lang.controls.normal,
  36860. type: 'block-type',
  36861. command: 'unstyled'
  36862. }];
  36863. };
  36864. // CONCATENATED MODULE: ./components/business/Headings/index.jsx
  36865. /* harmony default export */ var Headings = (function (props) {
  36866. var dropDownInstance = null;
  36867. var headings = maps_getHeadings(props.language).filter(function (item) {
  36868. return props.headings.indexOf(item.key) !== -1;
  36869. });
  36870. var currentHeadingIndex = headings.findIndex(function (item) {
  36871. return item.command === props.current;
  36872. });
  36873. var caption = headings[currentHeadingIndex] ? headings[currentHeadingIndex].title : props.language.controls.normal;
  36874. return external_react_default.a.createElement(DropDown_DropDown, {
  36875. caption: caption,
  36876. autoHide: true,
  36877. getContainerNode: props.getContainerNode,
  36878. title: props.language.controls.headings,
  36879. arrowActive: currentHeadingIndex === 0,
  36880. ref: function ref(instance) {
  36881. return dropDownInstance = instance;
  36882. },
  36883. className: 'control-item dropdown headings-dropdown'
  36884. }, external_react_default.a.createElement("ul", {
  36885. className: "menu"
  36886. }, headings.map(function (item, index) {
  36887. var isActive = props.current === item.command;
  36888. return external_react_default.a.createElement("li", {
  36889. key: index,
  36890. className: 'menu-item' + (isActive ? ' active' : ''),
  36891. onClick: function onClick() {
  36892. props.onChange(item.command, item.type), dropDownInstance.hide();
  36893. }
  36894. }, item.text);
  36895. })));
  36896. });
  36897. // EXTERNAL MODULE: ./components/business/TextColor/style.scss
  36898. var TextColor_style = __webpack_require__(57);
  36899. // EXTERNAL MODULE: ./components/common/ColorPicker/style.scss
  36900. var ColorPicker_style = __webpack_require__(58);
  36901. // CONCATENATED MODULE: ./components/common/ColorPicker/index.jsx
  36902. /* harmony default export */ var common_ColorPicker = (function (props) {
  36903. return external_react_default.a.createElement("div", {
  36904. className: "bf-colors-wrap"
  36905. }, external_react_default.a.createElement("ul", {
  36906. className: "bf-colors"
  36907. }, props.presetColors.map(function (item, index) {
  36908. var className = props.color && item.toLowerCase() === props.color.toLowerCase() ? 'color-item active' : 'color-item';
  36909. return external_react_default.a.createElement("li", {
  36910. key: index,
  36911. title: item,
  36912. className: className,
  36913. style: {
  36914. color: item
  36915. },
  36916. "data-color": item.replace('#', ''),
  36917. onClick: function onClick(e) {
  36918. props.onChange(e.currentTarget.dataset.color, true);
  36919. }
  36920. });
  36921. })));
  36922. });
  36923. // CONCATENATED MODULE: ./components/business/TextColor/index.jsx
  36924. var TextColor_TextColor =
  36925. /*#__PURE__*/
  36926. function (_React$Component) {
  36927. inherits_default()(TextColor, _React$Component);
  36928. function TextColor() {
  36929. var _getPrototypeOf2;
  36930. var _this;
  36931. classCallCheck_default()(this, TextColor);
  36932. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  36933. args[_key] = arguments[_key];
  36934. }
  36935. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(TextColor)).call.apply(_getPrototypeOf2, [this].concat(args)));
  36936. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "state", {
  36937. colorType: 'color'
  36938. });
  36939. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "switchColorType", function (_ref) {
  36940. var currentTarget = _ref.currentTarget;
  36941. _this.setState({
  36942. colorType: currentTarget.dataset.type
  36943. });
  36944. });
  36945. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "toggleColor", function (color, closePicker) {
  36946. if (color) {
  36947. var hookReturns = _this.props.hooks("toggle-text-".concat(_this.state.colorType), color)(color);
  36948. if (hookReturns === false) {
  36949. return false;
  36950. }
  36951. if (typeof hookReturns === 'string') {
  36952. color = hookReturns;
  36953. }
  36954. if (_this.state.colorType === 'color') {
  36955. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionColor(_this.props.editorState, color));
  36956. } else {
  36957. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionBackgroundColor(_this.props.editorState, color));
  36958. }
  36959. }
  36960. if (closePicker) {
  36961. _this.dropDownInstance.hide();
  36962. _this.props.editor.requestFocus();
  36963. }
  36964. });
  36965. return _this;
  36966. }
  36967. createClass_default()(TextColor, [{
  36968. key: "render",
  36969. value: function render() {
  36970. var _this2 = this;
  36971. var captionStyle = {};
  36972. var currentColor = null;
  36973. var colorType = this.state.colorType;
  36974. var selectionStyles = this.props.editorState.getCurrentInlineStyle().toJS();
  36975. selectionStyles.forEach(function (style) {
  36976. if (style.indexOf('COLOR-') === 0) {
  36977. captionStyle.color = '#' + style.split('-')[1];
  36978. colorType === 'color' && (currentColor = captionStyle.color);
  36979. }
  36980. if (style.indexOf('BGCOLOR-') === 0) {
  36981. captionStyle.backgroundColor = '#' + style.split('-')[1];
  36982. colorType === 'background-color' && (currentColor = captionStyle.backgroundColor);
  36983. }
  36984. });
  36985. var caption = external_react_default.a.createElement("i", {
  36986. style: captionStyle,
  36987. className: "bfi-text-color"
  36988. }, external_react_default.a.createElement("span", {
  36989. className: "path1"
  36990. }), external_react_default.a.createElement("span", {
  36991. className: "path2"
  36992. }));
  36993. var ColorPicker = this.props.colorPicker || common_ColorPicker;
  36994. return external_react_default.a.createElement(DropDown_DropDown, {
  36995. caption: caption,
  36996. title: this.props.language.controls.color,
  36997. showArrow: false,
  36998. autoHide: this.props.autoHide,
  36999. theme: this.props.theme,
  37000. getContainerNode: this.props.getContainerNode,
  37001. ref: function ref(instance) {
  37002. return _this2.dropDownInstance = instance;
  37003. },
  37004. className: 'control-item dropdown text-color-dropdown'
  37005. }, external_react_default.a.createElement("div", {
  37006. className: "bf-text-color-picker-wrap"
  37007. }, external_react_default.a.createElement("div", {
  37008. className: "bf-color-switch-buttons",
  37009. style: this.props.enableBackgroundColor ? {} : {
  37010. display: 'none'
  37011. }
  37012. }, external_react_default.a.createElement("button", {
  37013. type: "button",
  37014. "data-type": "color",
  37015. className: colorType === 'color' ? 'active' : '',
  37016. onClick: this.switchColorType
  37017. }, this.props.language.controls.textColor), external_react_default.a.createElement("button", {
  37018. type: "button",
  37019. "data-type": "background-color",
  37020. className: colorType === 'background-color' ? 'active' : '',
  37021. onClick: this.switchColorType
  37022. }, this.props.language.controls.backgroundColor)), external_react_default.a.createElement(ColorPicker, {
  37023. width: 200,
  37024. color: currentColor,
  37025. disableAlpha: true,
  37026. presetColors: this.props.colors,
  37027. onChange: this.toggleColor
  37028. })));
  37029. }
  37030. }]);
  37031. return TextColor;
  37032. }(external_react_default.a.Component);
  37033. // EXTERNAL MODULE: ./components/business/FontSize/style.scss
  37034. var FontSize_style = __webpack_require__(59);
  37035. // CONCATENATED MODULE: ./components/business/FontSize/index.jsx
  37036. var FontSize_toggleFontSize = function toggleFontSize(event, props) {
  37037. var fontSize = event.currentTarget.dataset.size;
  37038. var hookReturns = props.hooks('toggle-font-size', fontSize)(fontSize);
  37039. if (hookReturns === false) {
  37040. return false;
  37041. }
  37042. if (!isNaN(fontSize)) {
  37043. fontSize = hookReturns;
  37044. }
  37045. props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionFontSize(props.editorState, fontSize));
  37046. props.editor.requestFocus();
  37047. };
  37048. /* harmony default export */ var FontSize = (function (props) {
  37049. var caption = null;
  37050. var currentFontSize = null;
  37051. var dropDownInstance = null;
  37052. props.fontSizes.find(function (item) {
  37053. if (external_braft_utils_["ContentUtils"].selectionHasInlineStyle(props.editorState, 'FONTSIZE-' + item)) {
  37054. caption = item;
  37055. currentFontSize = item;
  37056. return true;
  37057. }
  37058. return false;
  37059. });
  37060. return external_react_default.a.createElement(DropDown_DropDown, {
  37061. autoHide: true,
  37062. caption: caption || props.defaultCaption,
  37063. getContainerNode: props.getContainerNode,
  37064. title: props.language.controls.fontSize,
  37065. ref: function ref(instance) {
  37066. return dropDownInstance = instance;
  37067. },
  37068. className: 'control-item dropdown bf-font-size-dropdown'
  37069. }, external_react_default.a.createElement("ul", {
  37070. className: "bf-font-sizes"
  37071. }, props.fontSizes.map(function (item, index) {
  37072. return external_react_default.a.createElement("li", {
  37073. key: index,
  37074. className: item === currentFontSize ? 'active' : null,
  37075. "data-size": item,
  37076. onClick: function onClick(event) {
  37077. FontSize_toggleFontSize(event, props), dropDownInstance.hide();
  37078. }
  37079. }, item);
  37080. })));
  37081. });
  37082. // EXTERNAL MODULE: ./components/business/LineHeight/style.scss
  37083. var LineHeight_style = __webpack_require__(60);
  37084. // CONCATENATED MODULE: ./components/business/LineHeight/index.jsx
  37085. var LineHeight_toggleLineHeight = function toggleLineHeight(event, props) {
  37086. var lineHeight = event.currentTarget.dataset.size;
  37087. var hookReturns = props.hooks('toggle-line-height', lineHeight)(lineHeight);
  37088. if (hookReturns === false) {
  37089. return false;
  37090. }
  37091. if (!isNaN(hookReturns)) {
  37092. lineHeight = hookReturns;
  37093. }
  37094. props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionLineHeight(props.editorState, lineHeight));
  37095. props.editor.requestFocus();
  37096. };
  37097. /* harmony default export */ var LineHeight = (function (props) {
  37098. var caption = null;
  37099. var currentLineHeight = null;
  37100. var dropDownInstance = null;
  37101. props.lineHeights.find(function (item) {
  37102. if (external_braft_utils_["ContentUtils"].selectionHasInlineStyle(props.editorState, 'LINEHEIGHT-' + item)) {
  37103. caption = item;
  37104. currentLineHeight = item;
  37105. return true;
  37106. }
  37107. return false;
  37108. });
  37109. return external_react_default.a.createElement(DropDown_DropDown, {
  37110. autoHide: true,
  37111. caption: caption || props.defaultCaption,
  37112. getContainerNode: props.getContainerNode,
  37113. title: props.language.controls.lineHeight,
  37114. ref: function ref(instance) {
  37115. return dropDownInstance = instance;
  37116. },
  37117. className: 'control-item dropdown bf-line-height-dropdown'
  37118. }, external_react_default.a.createElement("ul", {
  37119. className: "bf-line-heights"
  37120. }, props.lineHeights.map(function (item, index) {
  37121. return external_react_default.a.createElement("li", {
  37122. key: index,
  37123. className: item === currentLineHeight ? 'active' : null,
  37124. "data-size": item,
  37125. onClick: function onClick(event) {
  37126. LineHeight_toggleLineHeight(event, props), dropDownInstance.hide();
  37127. }
  37128. }, item);
  37129. })));
  37130. });
  37131. // EXTERNAL MODULE: ./components/business/FontFamily/style.scss
  37132. var FontFamily_style = __webpack_require__(61);
  37133. // CONCATENATED MODULE: ./components/business/FontFamily/index.jsx
  37134. var FontFamily_toggleFontFamily = function toggleFontFamily(event, props) {
  37135. var fontFamilyName = event.currentTarget.dataset.name;
  37136. var hookReturns = props.hooks('toggle-font-family', fontFamilyName)(fontFamilyName, props.fontFamilies);
  37137. if (hookReturns === false) {
  37138. return false;
  37139. }
  37140. if (typeof hookReturns === 'string') {
  37141. fontFamilyName = hookReturns;
  37142. }
  37143. props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionFontFamily(props.editorState, fontFamilyName));
  37144. props.editor.requestFocus();
  37145. };
  37146. /* harmony default export */ var FontFamily = (function (props) {
  37147. var caption = null;
  37148. var currentIndex = null;
  37149. var dropDownInstance = null;
  37150. props.fontFamilies.find(function (item, index) {
  37151. if (external_braft_utils_["ContentUtils"].selectionHasInlineStyle(props.editorState, 'FONTFAMILY-' + item.name)) {
  37152. caption = item.name;
  37153. currentIndex = index;
  37154. return true;
  37155. }
  37156. return false;
  37157. });
  37158. return external_react_default.a.createElement(DropDown_DropDown, {
  37159. caption: caption || props.defaultCaption,
  37160. getContainerNode: props.getContainerNode,
  37161. title: props.language.controls.fontFamily,
  37162. autoHide: true,
  37163. arrowActive: currentIndex === 0,
  37164. ref: function ref(instance) {
  37165. return dropDownInstance = instance;
  37166. },
  37167. className: 'control-item dropdown font-family-dropdown'
  37168. }, external_react_default.a.createElement("ul", {
  37169. className: "menu"
  37170. }, props.fontFamilies.map(function (item, index) {
  37171. return external_react_default.a.createElement("li", {
  37172. key: index,
  37173. className: 'menu-item ' + (index === currentIndex ? 'active' : ''),
  37174. "data-name": item.name,
  37175. onClick: function onClick(event) {
  37176. FontFamily_toggleFontFamily(event, props), dropDownInstance.hide();
  37177. }
  37178. }, external_react_default.a.createElement("span", {
  37179. style: {
  37180. fontFamily: item.family
  37181. }
  37182. }, item.name));
  37183. })));
  37184. });
  37185. // CONCATENATED MODULE: ./components/business/TextAlign/index.jsx
  37186. var TextAlign_TextAlign =
  37187. /*#__PURE__*/
  37188. function (_React$Component) {
  37189. inherits_default()(TextAlign, _React$Component);
  37190. function TextAlign() {
  37191. var _getPrototypeOf2;
  37192. var _this;
  37193. classCallCheck_default()(this, TextAlign);
  37194. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  37195. args[_key] = arguments[_key];
  37196. }
  37197. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(TextAlign)).call.apply(_getPrototypeOf2, [this].concat(args)));
  37198. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "state", {
  37199. currentAlignment: undefined
  37200. });
  37201. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "setAlignment", function (event) {
  37202. var alignment = event.currentTarget.dataset.alignment;
  37203. var hookReturns = _this.props.hooks('toggle-text-alignment', alignment)(alignment);
  37204. if (_this.props.textAligns.indexOf(hookReturns) > -1) {
  37205. alignment = hookReturns;
  37206. }
  37207. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionAlignment(_this.props.editorState, alignment));
  37208. _this.props.editor.requestFocus();
  37209. });
  37210. return _this;
  37211. }
  37212. createClass_default()(TextAlign, [{
  37213. key: "componentWillReceiveProps",
  37214. value: function componentWillReceiveProps(next) {
  37215. this.setState({
  37216. currentAlignment: external_braft_utils_["ContentUtils"].getSelectionBlockData(next.editorState, 'textAlign')
  37217. });
  37218. }
  37219. }, {
  37220. key: "render",
  37221. value: function render() {
  37222. var _this2 = this;
  37223. var textAlignmentTitles = [this.props.language.controls.alignLeft, this.props.language.controls.alignCenter, this.props.language.controls.alignRight, this.props.language.controls.alignJustify];
  37224. return external_react_default.a.createElement(ControlGroup, null, this.props.textAligns.map(function (item, index) {
  37225. return external_react_default.a.createElement("button", {
  37226. type: "button",
  37227. key: index,
  37228. "data-title": textAlignmentTitles[index],
  37229. "data-alignment": item,
  37230. className: 'control-item button ' + (item === _this2.state.currentAlignment ? 'active' : null),
  37231. onClick: _this2.setAlignment
  37232. }, external_react_default.a.createElement("i", {
  37233. className: 'bfi-align-' + item
  37234. }));
  37235. }));
  37236. }
  37237. }]);
  37238. return TextAlign;
  37239. }(external_react_default.a.Component);
  37240. // EXTERNAL MODULE: ./components/business/EmojiPicker/style.scss
  37241. var EmojiPicker_style = __webpack_require__(62);
  37242. // CONCATENATED MODULE: ./components/business/EmojiPicker/index.jsx
  37243. var EmojiPicker_insertEmoji = function insertEmoji(event, props) {
  37244. var emoji = event.currentTarget.dataset.emoji;
  37245. var hookReturns = props.hooks('insert-emoji', emoji)(emoji);
  37246. if (hookReturns === false) {
  37247. return false;
  37248. }
  37249. if (typeof hookReturns === 'string') {
  37250. emoji = hookReturns;
  37251. }
  37252. props.editor.setValue(external_braft_utils_["ContentUtils"].insertText(props.editorState, emoji));
  37253. props.editor.requestFocus();
  37254. };
  37255. /* harmony default export */ var EmojiPicker = (function (props) {
  37256. return external_react_default.a.createElement(DropDown_DropDown, {
  37257. caption: props.defaultCaption,
  37258. autoHide: true,
  37259. showArrow: false,
  37260. getContainerNode: props.getContainerNode,
  37261. title: props.language.controls.emoji,
  37262. className: 'control-item dropdown bf-emoji-dropdown'
  37263. }, external_react_default.a.createElement("div", {
  37264. className: "bf-emojis-wrap"
  37265. }, external_react_default.a.createElement("ul", {
  37266. className: "bf-emojis"
  37267. }, props.emojis.map(function (item, index) {
  37268. return external_react_default.a.createElement("li", {
  37269. key: index,
  37270. "data-emoji": item,
  37271. onClick: function onClick(event) {
  37272. return EmojiPicker_insertEmoji(event, props);
  37273. }
  37274. }, item);
  37275. }))));
  37276. });
  37277. // EXTERNAL MODULE: ./components/business/LetterSpacing/style.scss
  37278. var LetterSpacing_style = __webpack_require__(63);
  37279. // CONCATENATED MODULE: ./components/business/LetterSpacing/index.jsx
  37280. var LetterSpacing_toggleLetterSpacing = function toggleLetterSpacing(event, props) {
  37281. var letterSpacing = event.currentTarget.dataset.size;
  37282. var hookReturns = props.hooks('toggle-letter-spacing', letterSpacing)(letterSpacing);
  37283. if (hookReturns === false) {
  37284. return false;
  37285. }
  37286. if (!isNaN(hookReturns)) {
  37287. letterSpacing = hookReturns;
  37288. }
  37289. props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionLetterSpacing(props.editorState, letterSpacing));
  37290. props.editor.requestFocus();
  37291. };
  37292. /* harmony default export */ var LetterSpacing = (function (props) {
  37293. var caption = null;
  37294. var currentLetterSpacing = null;
  37295. var dropDownInstance = null;
  37296. props.letterSpacings.find(function (item) {
  37297. if (external_braft_utils_["ContentUtils"].selectionHasInlineStyle(props.editorState, 'LETTERSPACING-' + item)) {
  37298. caption = item;
  37299. currentLetterSpacing = item;
  37300. return true;
  37301. }
  37302. return false;
  37303. });
  37304. return external_react_default.a.createElement(DropDown_DropDown, {
  37305. autoHide: true,
  37306. caption: caption || props.defaultCaption,
  37307. getContainerNode: props.getContainerNode,
  37308. title: props.language.controls.letterSpacing,
  37309. ref: function ref(instance) {
  37310. return dropDownInstance = instance;
  37311. },
  37312. className: 'control-item dropdown bf-letter-spacing-dropdown'
  37313. }, external_react_default.a.createElement("ul", {
  37314. className: "bf-letter-spacings"
  37315. }, props.letterSpacings.map(function (item, index) {
  37316. return external_react_default.a.createElement("li", {
  37317. key: index,
  37318. className: item === currentLetterSpacing ? 'active' : null,
  37319. "data-size": item,
  37320. onClick: function onClick(event) {
  37321. LetterSpacing_toggleLetterSpacing(event, props), dropDownInstance.hide();
  37322. }
  37323. }, item);
  37324. })));
  37325. });
  37326. // CONCATENATED MODULE: ./components/business/TextIndent/index.jsx
  37327. var TextIndent_TextAlign =
  37328. /*#__PURE__*/
  37329. function (_React$Component) {
  37330. inherits_default()(TextAlign, _React$Component);
  37331. function TextAlign() {
  37332. var _getPrototypeOf2;
  37333. var _this;
  37334. classCallCheck_default()(this, TextAlign);
  37335. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  37336. args[_key] = arguments[_key];
  37337. }
  37338. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(TextAlign)).call.apply(_getPrototypeOf2, [this].concat(args)));
  37339. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "state", {
  37340. currentIndent: 0
  37341. });
  37342. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "increaseIndent", function () {
  37343. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].increaseSelectionIndent(_this.props.editorState));
  37344. _this.props.editor.requestFocus();
  37345. });
  37346. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "decreaseIndent", function () {
  37347. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].decreaseSelectionIndent(_this.props.editorState));
  37348. _this.props.editor.requestFocus();
  37349. });
  37350. return _this;
  37351. }
  37352. createClass_default()(TextAlign, [{
  37353. key: "componentWillReceiveProps",
  37354. value: function componentWillReceiveProps(nextProps) {
  37355. this.setState({
  37356. currentIndent: external_braft_utils_["ContentUtils"].getSelectionBlockData(nextProps.editorState, 'textIndent') || 0
  37357. });
  37358. }
  37359. }, {
  37360. key: "render",
  37361. value: function render() {
  37362. var currentIndent = this.state.currentIndent;
  37363. var language = this.props.language;
  37364. return external_react_default.a.createElement(ControlGroup, null, external_react_default.a.createElement("button", {
  37365. key: 0,
  37366. type: "button",
  37367. "data-title": language.controls.increaseIndent,
  37368. disabled: currentIndent >= 6,
  37369. className: "control-item button button-indent-increase".concat(currentIndent > 0 && currentIndent < 6 ? ' active' : ''),
  37370. onClick: this.increaseIndent
  37371. }, external_react_default.a.createElement("i", {
  37372. className: 'bfi-indent-increase'
  37373. })), external_react_default.a.createElement("button", {
  37374. key: 1,
  37375. type: "button",
  37376. "data-title": language.controls.decreaseIndent,
  37377. disabled: currentIndent <= 0,
  37378. className: "control-item button button-indent-decrease",
  37379. onClick: this.decreaseIndent
  37380. }, external_react_default.a.createElement("i", {
  37381. className: 'bfi-indent-decrease'
  37382. })));
  37383. }
  37384. }]);
  37385. return TextAlign;
  37386. }(external_react_default.a.Component);
  37387. // CONCATENATED MODULE: ./components/business/ControlBar/index.jsx
  37388. var commandHookMap = {
  37389. 'inline-style': 'toggle-inline-style',
  37390. 'block-type': 'change-block-type',
  37391. 'editor-method': 'exec-editor-command'
  37392. };
  37393. var exclusiveInlineStyles = {
  37394. 'superscript': 'subscript',
  37395. 'subscript': 'superscript'
  37396. };
  37397. var mergeControls = function mergeControls(commonProps, builtControls, extensionControls, extendControls) {
  37398. extensionControls = extensionControls.map(function (item) {
  37399. return typeof item === 'function' ? item(commonProps) : item;
  37400. });
  37401. extendControls = extendControls.map(function (item) {
  37402. return typeof item === 'function' ? item(commonProps) : item;
  37403. });
  37404. if (extensionControls.length === 0 && extendControls.length === 0) {
  37405. return builtControls;
  37406. }
  37407. return builtControls.map(function (item) {
  37408. return extendControls.find(function (subItem) {
  37409. return subItem.replace === (item.key || item);
  37410. }) || extensionControls.find(function (subItem) {
  37411. return subItem.replace === (item.key || item);
  37412. }) || item;
  37413. }).concat(extensionControls.length ? 'separator' : '').concat(extensionControls.filter(function (item) {
  37414. return !item.replace;
  37415. })).concat(extendControls.filter(function (item) {
  37416. return typeof item === 'string' || !item.replace;
  37417. }));
  37418. };
  37419. var ControlBar_ControlBar =
  37420. /*#__PURE__*/
  37421. function (_React$Component) {
  37422. inherits_default()(ControlBar, _React$Component);
  37423. function ControlBar() {
  37424. var _getPrototypeOf2;
  37425. var _this;
  37426. classCallCheck_default()(this, ControlBar);
  37427. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  37428. args[_key] = arguments[_key];
  37429. }
  37430. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(ControlBar)).call.apply(_getPrototypeOf2, [this].concat(args)));
  37431. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "allControls", []);
  37432. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "mediaLibiraryModal", null);
  37433. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "extendedModals", {});
  37434. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "openBraftFinder", function () {
  37435. if (!_this.props.braftFinder || !_this.props.braftFinder.ReactComponent) {
  37436. return false;
  37437. }
  37438. if (_this.props.hooks('open-braft-finder')() === false) {
  37439. return false;
  37440. }
  37441. var mediaProps = _this.props.media;
  37442. var MediaLibrary = _this.props.braftFinder.ReactComponent;
  37443. _this.mediaLibiraryModal = Modal_showModal({
  37444. title: _this.props.language.controls.mediaLibirary,
  37445. language: _this.props.language,
  37446. width: 640,
  37447. showFooter: false,
  37448. component: external_react_default.a.createElement(MediaLibrary, {
  37449. accepts: mediaProps.accepts,
  37450. onCancel: _this.closeBraftFinder,
  37451. onInsert: _this.insertMedias,
  37452. onChange: mediaProps.onChange,
  37453. externals: mediaProps.externals,
  37454. onBeforeSelect: _this.bindBraftFinderHook('select-medias'),
  37455. onBeforeDeselect: _this.bindBraftFinderHook('deselect-medias'),
  37456. onBeforeRemove: _this.bindBraftFinderHook('remove-medias'),
  37457. onBeforeInsert: _this.bindBraftFinderHook('insert-medias'),
  37458. onFileSelect: _this.bindBraftFinderHook('select-files')
  37459. })
  37460. });
  37461. });
  37462. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "bindBraftFinderHook", function (hookName) {
  37463. return function () {
  37464. return _this.props.hooks(hookName, arguments.length <= 0 ? undefined : arguments[0]).apply(void 0, arguments);
  37465. };
  37466. });
  37467. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "insertMedias", function (medias) {
  37468. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].insertMedias(_this.props.editorState, medias));
  37469. _this.props.editor.requestFocus();
  37470. _this.props.media.onInsert && _this.props.media.onInsert(medias);
  37471. _this.closeBraftFinder();
  37472. });
  37473. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "closeBraftFinder", function () {
  37474. _this.props.media.onCancel && _this.props.media.onCancel();
  37475. _this.mediaLibiraryModal && _this.mediaLibiraryModal.close();
  37476. });
  37477. return _this;
  37478. }
  37479. createClass_default()(ControlBar, [{
  37480. key: "componentDidUpdate",
  37481. value: function componentDidUpdate() {
  37482. var _this2 = this;
  37483. var language = this.props.language;
  37484. this.allControls.forEach(function (item) {
  37485. if (item.type === 'modal') {
  37486. if (item.modal && item.modal.id && _this2.extendedModals[item.modal.id]) {
  37487. _this2.extendedModals[item.modal.id].update(objectSpread_default()({}, item.modal, {
  37488. language: language
  37489. }));
  37490. }
  37491. }
  37492. });
  37493. }
  37494. }, {
  37495. key: "getControlItemClassName",
  37496. value: function getControlItemClassName(data) {
  37497. var className = 'control-item button';
  37498. var type = data.type,
  37499. command = data.command;
  37500. if (type === 'inline-style' && external_braft_utils_["ContentUtils"].selectionHasInlineStyle(this.props.editorState, command)) {
  37501. className += ' active';
  37502. } else if (type === 'block-type' && external_braft_utils_["ContentUtils"].getSelectionBlockType(this.props.editorState) === command) {
  37503. className += ' active';
  37504. } else if (type === 'entity' && external_braft_utils_["ContentUtils"].getSelectionEntityType(this.props.editorState) === command) {
  37505. className += ' active';
  37506. }
  37507. return className;
  37508. }
  37509. }, {
  37510. key: "applyControl",
  37511. value: function applyControl(command, type) {
  37512. var data = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  37513. var hookReturns = this.props.hooks(commandHookMap[type] || type, command)(command);
  37514. var editorState = this.props.editorState;
  37515. if (hookReturns === false) {
  37516. return false;
  37517. }
  37518. if (typeof hookReturns === 'string') {
  37519. command = hookReturns;
  37520. }
  37521. if (type === 'inline-style') {
  37522. var exclusiveInlineStyle = exclusiveInlineStyles[command];
  37523. if (exclusiveInlineStyle && external_braft_utils_["ContentUtils"].selectionHasInlineStyle(editorState, exclusiveInlineStyle)) {
  37524. editorState = external_braft_utils_["ContentUtils"].toggleSelectionInlineStyle(editorState, exclusiveInlineStyle);
  37525. }
  37526. this.props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionInlineStyle(editorState, command));
  37527. } else if (type === 'block-type') {
  37528. this.props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionBlockType(editorState, command));
  37529. } else if (type === 'entity') {
  37530. this.props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionEntity(editorState, {
  37531. type: command,
  37532. mutability: data.mutability || 'MUTABLE',
  37533. data: data.data || {}
  37534. }));
  37535. } else if (type === 'editor-method') {
  37536. this.props.editor[command] && this.props.editor[command]();
  37537. }
  37538. }
  37539. }, {
  37540. key: "render",
  37541. value: function render() {
  37542. var _this3 = this;
  37543. var _this$props = this.props,
  37544. editor = _this$props.editor,
  37545. editorId = _this$props.editorId,
  37546. editorState = _this$props.editorState,
  37547. className = _this$props.className,
  37548. style = _this$props.style,
  37549. controls = _this$props.controls,
  37550. media = _this$props.media,
  37551. extendControls = _this$props.extendControls,
  37552. language = _this$props.language,
  37553. hooks = _this$props.hooks,
  37554. colors = _this$props.colors,
  37555. colorPicker = _this$props.colorPicker,
  37556. colorPickerTheme = _this$props.colorPickerTheme,
  37557. colorPickerAutoHide = _this$props.colorPickerAutoHide,
  37558. headings = _this$props.headings,
  37559. fontSizes = _this$props.fontSizes,
  37560. fontFamilies = _this$props.fontFamilies,
  37561. emojis = _this$props.emojis,
  37562. getContainerNode = _this$props.getContainerNode,
  37563. lineHeights = _this$props.lineHeights,
  37564. letterSpacings = _this$props.letterSpacings,
  37565. textAligns = _this$props.textAligns,
  37566. textBackgroundColor = _this$props.textBackgroundColor,
  37567. allowInsertLinkText = _this$props.allowInsertLinkText,
  37568. defaultLinkTarget = _this$props.defaultLinkTarget;
  37569. var currentBlockType = external_braft_utils_["ContentUtils"].getSelectionBlockType(editorState);
  37570. var commonProps = {
  37571. editor: editor,
  37572. editorId: editorId,
  37573. editorState: editorState,
  37574. language: language,
  37575. getContainerNode: getContainerNode,
  37576. hooks: hooks
  37577. };
  37578. var renderedControls = [];
  37579. var editorControls = configs_controls(language, editor);
  37580. var extensionControls = getExtensionControls(editorId);
  37581. var allControls = mergeControls(commonProps, controls, extensionControls, extendControls);
  37582. this.allControls = allControls;
  37583. return external_react_default.a.createElement("div", {
  37584. className: "bf-controlbar ".concat(className || ''),
  37585. style: style,
  37586. onMouseDown: this.preventDefault
  37587. }, allControls.map(function (item, index) {
  37588. var itemKey = typeof item === 'string' ? item : item.key;
  37589. if (typeof itemKey !== 'string') {
  37590. return null;
  37591. }
  37592. if (renderedControls.indexOf(itemKey) > -1) {
  37593. return null;
  37594. }
  37595. if (itemKey.toLowerCase() === 'separator') {
  37596. return external_react_default.a.createElement("span", {
  37597. key: index,
  37598. className: "separator-line"
  37599. });
  37600. }
  37601. var controlItem = editorControls.find(function (subItem) {
  37602. return subItem.key.toLowerCase() === itemKey.toLowerCase();
  37603. });
  37604. if (typeof item !== 'string') {
  37605. controlItem = objectSpread_default()({}, controlItem, item);
  37606. }
  37607. if (!controlItem) {
  37608. return null;
  37609. }
  37610. renderedControls.push(itemKey);
  37611. if (controlItem.type === 'headings') {
  37612. return external_react_default.a.createElement(Headings, extends_default()({
  37613. key: index,
  37614. headings: headings,
  37615. current: currentBlockType,
  37616. onChange: function onChange(command) {
  37617. return _this3.applyControl(command, 'block-type');
  37618. }
  37619. }, commonProps));
  37620. } else if (controlItem.type === 'text-color') {
  37621. return external_react_default.a.createElement(TextColor_TextColor, extends_default()({
  37622. key: index,
  37623. colors: colors,
  37624. colorPicker: colorPicker,
  37625. theme: colorPickerTheme,
  37626. autoHide: colorPickerAutoHide,
  37627. enableBackgroundColor: textBackgroundColor
  37628. }, commonProps));
  37629. } else if (controlItem.type === 'font-size') {
  37630. return external_react_default.a.createElement(FontSize, extends_default()({
  37631. key: index,
  37632. fontSizes: fontSizes,
  37633. defaultCaption: controlItem.title
  37634. }, commonProps));
  37635. } else if (controlItem.type === 'line-height') {
  37636. return external_react_default.a.createElement(LineHeight, extends_default()({
  37637. key: index,
  37638. lineHeights: lineHeights,
  37639. defaultCaption: controlItem.title
  37640. }, commonProps));
  37641. } else if (controlItem.type === 'letter-spacing') {
  37642. return external_react_default.a.createElement(LetterSpacing, extends_default()({
  37643. key: index,
  37644. letterSpacings: letterSpacings,
  37645. defaultCaption: controlItem.title
  37646. }, commonProps));
  37647. } else if (controlItem.type === 'text-indent') {
  37648. return external_react_default.a.createElement(TextIndent_TextAlign, extends_default()({
  37649. key: index,
  37650. defaultCaption: controlItem.title
  37651. }, commonProps));
  37652. } else if (controlItem.type === 'font-family') {
  37653. return external_react_default.a.createElement(FontFamily, extends_default()({
  37654. key: index,
  37655. fontFamilies: fontFamilies,
  37656. defaultCaption: controlItem.title
  37657. }, commonProps));
  37658. } else if (controlItem.type === 'emoji') {
  37659. return external_react_default.a.createElement(EmojiPicker, extends_default()({
  37660. key: index,
  37661. emojis: emojis,
  37662. defaultCaption: controlItem.text
  37663. }, commonProps));
  37664. } else if (controlItem.type === 'link') {
  37665. return external_react_default.a.createElement(LinkEditor_LinkEditor, extends_default()({
  37666. key: index,
  37667. defaultLinkTarget: defaultLinkTarget,
  37668. allowInsertLinkText: allowInsertLinkText
  37669. }, commonProps));
  37670. } else if (controlItem.type === 'text-align') {
  37671. return external_react_default.a.createElement(TextAlign_TextAlign, extends_default()({
  37672. key: index,
  37673. textAligns: textAligns
  37674. }, commonProps));
  37675. } else if (controlItem.type === 'media') {
  37676. if (!media.image && !media.video && !media.audio) {
  37677. return null;
  37678. }
  37679. return external_react_default.a.createElement("button", {
  37680. type: "button",
  37681. key: index,
  37682. "data-title": controlItem.title,
  37683. disabled: controlItem.disabled,
  37684. className: "control-item media button",
  37685. onClick: _this3.openBraftFinder
  37686. }, controlItem.text);
  37687. } else if (controlItem.type === 'dropdown') {
  37688. return external_react_default.a.createElement(DropDown_DropDown, extends_default()({
  37689. key: index,
  37690. className: "control-item extend-control-item dropdown ".concat(controlItem.className || ''),
  37691. caption: controlItem.text,
  37692. htmlCaption: controlItem.html,
  37693. showArrow: controlItem.showArrow,
  37694. title: controlItem.title,
  37695. arrowActive: controlItem.arrowActive,
  37696. theme: controlItem.theme,
  37697. autoHide: controlItem.autoHide,
  37698. disabled: controlItem.disabled,
  37699. ref: controlItem.ref
  37700. }, commonProps), controlItem.component);
  37701. } else if (controlItem.type === 'modal') {
  37702. return external_react_default.a.createElement("button", {
  37703. type: "button",
  37704. key: index,
  37705. "data-title": controlItem.title,
  37706. disabled: controlItem.disabled,
  37707. className: "control-item extend-control-item button ".concat(controlItem.className || ''),
  37708. dangerouslySetInnerHTML: controlItem.html ? {
  37709. __html: controlItem.html
  37710. } : null,
  37711. onClick: function onClick(event) {
  37712. if (controlItem.modal && controlItem.modal.id) {
  37713. if (_this3.extendedModals[controlItem.modal.id]) {
  37714. _this3.extendedModals[controlItem.modal.id].active = true;
  37715. _this3.extendedModals[controlItem.modal.id].update(objectSpread_default()({}, controlItem.modal, {
  37716. language: language
  37717. }));
  37718. } else {
  37719. _this3.extendedModals[controlItem.modal.id] = Modal_showModal(objectSpread_default()({}, controlItem.modal, {
  37720. language: language
  37721. }));
  37722. controlItem.modal.onCreate && controlItem.modal.onCreate(_this3.extendedModals[controlItem.modal.id]);
  37723. }
  37724. }
  37725. controlItem.onClick && controlItem.onClick(event);
  37726. }
  37727. }, !controlItem.html ? controlItem.text : null);
  37728. } else if (controlItem.type === 'component') {
  37729. return external_react_default.a.createElement("div", {
  37730. key: index,
  37731. className: "component-wrapper ".concat(controlItem.className || '')
  37732. }, controlItem.component);
  37733. } else if (controlItem.type === 'button') {
  37734. return external_react_default.a.createElement("button", {
  37735. type: "button",
  37736. key: index,
  37737. "data-title": controlItem.title,
  37738. disabled: controlItem.disabled,
  37739. className: "control-item button ".concat(controlItem.className || ''),
  37740. dangerouslySetInnerHTML: controlItem.html ? {
  37741. __html: controlItem.html
  37742. } : null,
  37743. onClick: function onClick(event) {
  37744. return controlItem.onClick && controlItem.onClick(event);
  37745. }
  37746. }, !controlItem.html ? controlItem.text : null);
  37747. } else if (controlItem) {
  37748. var disabled = false;
  37749. if (controlItem.command === 'undo') {
  37750. disabled = editorState.getUndoStack().size === 0;
  37751. } else if (controlItem.command === 'redo') {
  37752. disabled = editorState.getRedoStack().size === 0;
  37753. }
  37754. return external_react_default.a.createElement("button", {
  37755. type: "button",
  37756. key: index,
  37757. disabled: disabled,
  37758. "data-title": controlItem.title,
  37759. className: _this3.getControlItemClassName({
  37760. type: controlItem.type,
  37761. command: controlItem.command
  37762. }),
  37763. onClick: function onClick() {
  37764. return _this3.applyControl(controlItem.command, controlItem.type, controlItem.data);
  37765. }
  37766. }, controlItem.text);
  37767. }
  37768. }));
  37769. }
  37770. }, {
  37771. key: "preventDefault",
  37772. value: function preventDefault(event) {
  37773. var tagName = event.target.tagName.toLowerCase();
  37774. if (tagName === 'input' || tagName === 'label') ; else {
  37775. event.preventDefault();
  37776. }
  37777. }
  37778. }]);
  37779. return ControlBar;
  37780. }(external_react_default.a.Component);
  37781. // CONCATENATED MODULE: ./editor/index.jsx
  37782. var buildHooks = function buildHooks(hooks) {
  37783. return function (hookName) {
  37784. var defaultReturns = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  37785. return hooks[hookName] || function () {
  37786. return defaultReturns;
  37787. };
  37788. };
  37789. };
  37790. var filterColors = function filterColors(colors, colors2) {
  37791. return colors.filter(function (item) {
  37792. return !colors2.find(function (color) {
  37793. return color.toLowerCase() === item.toLowerCase();
  37794. });
  37795. }).filter(function (item, index, array) {
  37796. return array.indexOf(item) === index;
  37797. });
  37798. };
  37799. var editor_isControlEnabled = function isControlEnabled(props, controlName) {
  37800. return toConsumableArray_default()(props.controls).concat(toConsumableArray_default()(props.extendControls)).find(function (item) {
  37801. return item === controlName || item.key === controlName;
  37802. }) && props.excludeControls.indexOf(controlName) === -1;
  37803. };
  37804. var editor_getConvertOptions = function getConvertOptions(props) {
  37805. var editorId = props.editorId || props.id;
  37806. var convertOptions = objectSpread_default()({}, configs_props.converts, props.converts, {
  37807. fontFamilies: props.fontFamilies
  37808. });
  37809. convertOptions.styleImportFn = compositeStyleImportFn(convertOptions.styleImportFn, editorId);
  37810. convertOptions.styleExportFn = compositeStyleExportFn(convertOptions.styleExportFn, editorId);
  37811. convertOptions.entityImportFn = compositeEntityImportFn(convertOptions.entityImportFn, editorId);
  37812. convertOptions.entityExportFn = compositeEntityExportFn(convertOptions.entityExportFn, editorId);
  37813. convertOptions.blockImportFn = compositeBlockImportFn(convertOptions.blockImportFn, editorId);
  37814. convertOptions.blockExportFn = compositeBlockExportFn(convertOptions.blockExportFn, editorId);
  37815. return convertOptions;
  37816. };
  37817. var editor_BraftEditor =
  37818. /*#__PURE__*/
  37819. function (_React$Component) {
  37820. inherits_default()(BraftEditor, _React$Component);
  37821. function BraftEditor(props) {
  37822. var _this;
  37823. classCallCheck_default()(this, BraftEditor);
  37824. _this = possibleConstructorReturn_default()(this, getPrototypeOf_default()(BraftEditor).call(this, props));
  37825. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "onChange", function (editorState, callback) {
  37826. if (!(editorState instanceof external_draft_js_["EditorState"])) {
  37827. editorState = external_draft_js_["EditorState"].set(editorState, {
  37828. decorator: _this.editorDecorators
  37829. });
  37830. }
  37831. if (!editorState.convertOptions) {
  37832. editorState.setConvertOptions(editor_getConvertOptions(_this.editorProps));
  37833. }
  37834. _this.setState({
  37835. editorState: editorState
  37836. }, function () {
  37837. _this.props.onChange && _this.props.onChange(editorState);
  37838. callback && callback(editorState);
  37839. });
  37840. });
  37841. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "getDraftInstance", function () {
  37842. return _this.draftInstance;
  37843. });
  37844. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "getFinderInstance", function () {
  37845. return _this.braftFinder;
  37846. });
  37847. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "getValue", function () {
  37848. return _this.state.editorState;
  37849. });
  37850. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "setValue", function (editorState, callback) {
  37851. return _this.onChange(editorState, callback);
  37852. });
  37853. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "forceRender", function () {
  37854. var selectionState = _this.state.editorState.getSelection();
  37855. _this.setValue(external_draft_js_["EditorState"].set(_this.state.editorState, {
  37856. decorator: _this.editorDecorators
  37857. }), function () {
  37858. _this.setValue(external_draft_js_["EditorState"].forceSelection(_this.state.editorState, selectionState));
  37859. });
  37860. });
  37861. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "onTab", function (event) {
  37862. if (handlers_keyCommandHandlers('tab', _this.state.editorState, assertThisInitialized_default()(assertThisInitialized_default()(_this))) === 'handled') {
  37863. event.preventDefault();
  37864. }
  37865. _this.editorProps.onTab && _this.editorProps.onTab(event);
  37866. });
  37867. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "onFocus", function () {
  37868. _this.isFocused = true;
  37869. _this.editorProps.onFocus && _this.editorProps.onFocus(_this.state.editorState);
  37870. });
  37871. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "onBlur", function () {
  37872. _this.isFocused = false;
  37873. _this.editorProps.onBlur && _this.editorProps.onBlur(_this.state.editorState);
  37874. });
  37875. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "requestFocus", function () {
  37876. setTimeout(function () {
  37877. return _this.draftInstance.focus();
  37878. }, 0);
  37879. });
  37880. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleKeyCommand", function (command, editorState) {
  37881. return handlers_keyCommandHandlers(command, editorState, assertThisInitialized_default()(assertThisInitialized_default()(_this)));
  37882. });
  37883. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleReturn", function (event, editorState) {
  37884. return handlers_returnHandlers(event, editorState, assertThisInitialized_default()(assertThisInitialized_default()(_this)));
  37885. });
  37886. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleBeforeInput", function (chars, editorState) {
  37887. return beforeInputHandlers(chars, editorState, assertThisInitialized_default()(assertThisInitialized_default()(_this)));
  37888. });
  37889. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleDrop", function (selectionState, dataTransfer) {
  37890. return handlers_dropHandlers(selectionState, dataTransfer, assertThisInitialized_default()(assertThisInitialized_default()(_this)));
  37891. });
  37892. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleDroppedFiles", function (selectionState, files) {
  37893. return droppedFilesHandlers(selectionState, files, assertThisInitialized_default()(assertThisInitialized_default()(_this)));
  37894. });
  37895. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handlePastedFiles", function (files) {
  37896. return pastedFilesHandlers(files, assertThisInitialized_default()(assertThisInitialized_default()(_this)));
  37897. });
  37898. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleCopyContent", function (event) {
  37899. return handlers_copyHandlers(event, assertThisInitialized_default()(assertThisInitialized_default()(_this)));
  37900. });
  37901. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handlePastedText", function (text, html, editorState) {
  37902. return handlers_pastedTextHandlers(text, html, editorState, assertThisInitialized_default()(assertThisInitialized_default()(_this)));
  37903. });
  37904. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleCompositionStart", function (event) {
  37905. return handlers_compositionStartHandler(event, assertThisInitialized_default()(assertThisInitialized_default()(_this)));
  37906. });
  37907. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "undo", function () {
  37908. _this.setValue(external_braft_utils_["ContentUtils"].undo(_this.state.editorState));
  37909. });
  37910. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "redo", function () {
  37911. _this.setValue(external_braft_utils_["ContentUtils"].redo(_this.state.editorState));
  37912. });
  37913. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "removeSelectionInlineStyles", function () {
  37914. _this.setValue(external_braft_utils_["ContentUtils"].removeSelectionInlineStyles(_this.state.editorState));
  37915. });
  37916. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "insertHorizontalLine", function () {
  37917. _this.setValue(external_braft_utils_["ContentUtils"].insertHorizontalLine(_this.state.editorState));
  37918. });
  37919. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "clearEditorContent", function () {
  37920. _this.setValue(external_braft_utils_["ContentUtils"].clear(_this.state.editorState), function (editorState) {
  37921. _this.setValue(external_braft_utils_["ContentUtils"].toggleSelectionIndent(editorState, 0));
  37922. });
  37923. });
  37924. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "toggleFullscreen", function (fullscreen) {
  37925. _this.setState({
  37926. isFullscreen: typeof fullscreen !== 'undefined' ? fullscreen : !_this.state.isFullscreen
  37927. }, function () {
  37928. _this.editorProps.onFullscreen && _this.editorProps.onFullscreen(_this.state.isFullscreen);
  37929. });
  37930. });
  37931. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "setEditorContainerNode", function (containerNode) {
  37932. _this.containerNode = containerNode;
  37933. });
  37934. _this.editorProps = _this.getEditorProps(props);
  37935. _this.editorDecorators = getDecorators(_this.editorProps.editorId || _this.editorProps.id);
  37936. _this.isFocused = false;
  37937. _this.isLiving = false;
  37938. _this.braftFinder = null;
  37939. _this.valueInitialized = !!(_this.props.defaultValue || _this.props.value);
  37940. 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);
  37941. defaultEditorState.setConvertOptions(editor_getConvertOptions(_this.editorProps));
  37942. var tempColors = [];
  37943. if (external_braft_utils_["ContentUtils"].isEditorState(defaultEditorState)) {
  37944. var colors = external_braft_utils_["ColorUtils"].detectColorsFromDraftState(defaultEditorState.toRAW(true));
  37945. defaultEditorState.setConvertOptions(editor_getConvertOptions(_this.editorProps));
  37946. tempColors = filterColors(colors, _this.editorProps.colors);
  37947. }
  37948. _this.state = {
  37949. tempColors: tempColors,
  37950. editorState: defaultEditorState,
  37951. isFullscreen: false,
  37952. draftProps: {}
  37953. };
  37954. _this.containerNode = null;
  37955. return _this;
  37956. }
  37957. createClass_default()(BraftEditor, [{
  37958. key: "getEditorProps",
  37959. value: function getEditorProps(props) {
  37960. var _this2 = this;
  37961. props = props || this.props;
  37962. var _props = props,
  37963. value = _props.value,
  37964. defaultValue = _props.defaultValue,
  37965. onChange = _props.onChange,
  37966. restProps = objectWithoutProperties_default()(_props, ["value", "defaultValue", "onChange"]); // eslint-disable-line no-unused-vars
  37967. var propInterceptors = getPropInterceptors(restProps.editorId || restProps.id);
  37968. if (propInterceptors.length === 0) {
  37969. return restProps;
  37970. }
  37971. var porpsMap = Object(external_immutable_["Map"])(restProps);
  37972. propInterceptors.forEach(function (interceptor) {
  37973. porpsMap = porpsMap.merge(Object(external_immutable_["Map"])(interceptor(porpsMap.toJS(), _this2) || {}));
  37974. });
  37975. return porpsMap.toJS();
  37976. }
  37977. }, {
  37978. key: "componentWillMount",
  37979. value: function componentWillMount() {
  37980. if (editor_isControlEnabled(this.editorProps, 'media')) {
  37981. var _this$editorProps = this.editorProps,
  37982. language = _this$editorProps.language,
  37983. media = _this$editorProps.media;
  37984. var _defaultProps$media$m = objectSpread_default()({}, configs_props.media, media),
  37985. uploadFn = _defaultProps$media$m.uploadFn,
  37986. validateFn = _defaultProps$media$m.validateFn,
  37987. items = _defaultProps$media$m.items;
  37988. this.braftFinder = new external_braft_finder_default.a({
  37989. items: items,
  37990. language: language,
  37991. uploader: uploadFn,
  37992. validator: validateFn
  37993. });
  37994. this.forceUpdate();
  37995. }
  37996. }
  37997. }, {
  37998. key: "componentDidMount",
  37999. value: function componentDidMount() {
  38000. this.isLiving = true;
  38001. }
  38002. }, {
  38003. key: "componentDidUpdate",
  38004. value: function componentDidUpdate(_, prevState) {
  38005. if (prevState.editorState !== this.state.editorState) {
  38006. this.state.editorState.setConvertOptions(editor_getConvertOptions(this.editorProps));
  38007. }
  38008. }
  38009. }, {
  38010. key: "componentWillReceiveProps",
  38011. value: function componentWillReceiveProps(props) {
  38012. var _this3 = this;
  38013. this.editorProps = this.getEditorProps(props);
  38014. var editorState = props.value;
  38015. var _this$editorProps2 = this.editorProps,
  38016. media = _this$editorProps2.media,
  38017. language = _this$editorProps2.language;
  38018. var currentProps = this.getEditorProps();
  38019. if (!editor_isControlEnabled(currentProps, 'media') && editor_isControlEnabled(this.editorProps, 'media') && !this.braftFinder) {
  38020. var _defaultProps$media$m2 = objectSpread_default()({}, configs_props.media, media),
  38021. uploadFn = _defaultProps$media$m2.uploadFn,
  38022. validateFn = _defaultProps$media$m2.validateFn,
  38023. items = _defaultProps$media$m2.items;
  38024. this.braftFinder = new external_braft_finder_default.a({
  38025. items: items,
  38026. language: language,
  38027. uploader: uploadFn,
  38028. validator: validateFn
  38029. });
  38030. this.forceUpdate();
  38031. }
  38032. if (media && media.items && this.braftFinder) {
  38033. this.braftFinder.setItems(media.items);
  38034. }
  38035. var nextEditorState;
  38036. if (!this.valueInitialized && typeof this.props.defaultValue === 'undefined' && external_braft_utils_["ContentUtils"].isEditorState(props.defaultValue)) {
  38037. nextEditorState = props.defaultValue;
  38038. } else if (external_braft_utils_["ContentUtils"].isEditorState(editorState)) {
  38039. nextEditorState = editorState;
  38040. }
  38041. if (nextEditorState) {
  38042. if (nextEditorState && nextEditorState !== this.state.editorState) {
  38043. var tempColors = external_braft_utils_["ColorUtils"].detectColorsFromDraftState(nextEditorState.toRAW(true));
  38044. nextEditorState.setConvertOptions(editor_getConvertOptions(this.editorProps));
  38045. this.setState({
  38046. tempColors: filterColors(toConsumableArray_default()(this.state.tempColors).concat(toConsumableArray_default()(tempColors)), currentProps.colors),
  38047. editorState: nextEditorState
  38048. }, function () {
  38049. _this3.props.onChange && _this3.props.onChange(nextEditorState);
  38050. });
  38051. } else {
  38052. this.setState({
  38053. editorState: nextEditorState
  38054. });
  38055. }
  38056. }
  38057. }
  38058. }, {
  38059. key: "componentWillUnmount",
  38060. value: function componentWillUnmount() {
  38061. this.isLiving = false;
  38062. this.controlBarInstance && this.controlBarInstance.closeBraftFinder();
  38063. }
  38064. }, {
  38065. key: "lockOrUnlockEditor",
  38066. value: function lockOrUnlockEditor(editorLocked) {
  38067. this.setState({
  38068. editorLocked: editorLocked
  38069. });
  38070. }
  38071. }, {
  38072. key: "render",
  38073. value: function render() {
  38074. var _this4 = this;
  38075. var _this$editorProps3 = this.editorProps,
  38076. id = _this$editorProps3.id,
  38077. editorId = _this$editorProps3.editorId,
  38078. controls = _this$editorProps3.controls,
  38079. excludeControls = _this$editorProps3.excludeControls,
  38080. extendControls = _this$editorProps3.extendControls,
  38081. readOnly = _this$editorProps3.readOnly,
  38082. disabled = _this$editorProps3.disabled,
  38083. media = _this$editorProps3.media,
  38084. language = _this$editorProps3.language,
  38085. colors = _this$editorProps3.colors,
  38086. colorPicker = _this$editorProps3.colorPicker,
  38087. colorPickerTheme = _this$editorProps3.colorPickerTheme,
  38088. colorPickerAutoHide = _this$editorProps3.colorPickerAutoHide,
  38089. hooks = _this$editorProps3.hooks,
  38090. fontSizes = _this$editorProps3.fontSizes,
  38091. fontFamilies = _this$editorProps3.fontFamilies,
  38092. emojis = _this$editorProps3.emojis,
  38093. placeholder = _this$editorProps3.placeholder,
  38094. fixPlaceholder = _this$editorProps3.fixPlaceholder,
  38095. headings = _this$editorProps3.headings,
  38096. imageControls = _this$editorProps3.imageControls,
  38097. imageResizable = _this$editorProps3.imageResizable,
  38098. lineHeights = _this$editorProps3.lineHeights,
  38099. letterSpacings = _this$editorProps3.letterSpacings,
  38100. textAligns = _this$editorProps3.textAligns,
  38101. textBackgroundColor = _this$editorProps3.textBackgroundColor,
  38102. allowInsertLinkText = _this$editorProps3.allowInsertLinkText,
  38103. defaultLinkTarget = _this$editorProps3.defaultLinkTarget,
  38104. extendAtomics = _this$editorProps3.extendAtomics,
  38105. className = _this$editorProps3.className,
  38106. style = _this$editorProps3.style,
  38107. controlBarClassName = _this$editorProps3.controlBarClassName,
  38108. controlBarStyle = _this$editorProps3.controlBarStyle,
  38109. contentClassName = _this$editorProps3.contentClassName,
  38110. contentStyle = _this$editorProps3.contentStyle,
  38111. stripPastedStyles = _this$editorProps3.stripPastedStyles,
  38112. componentBelowControlBar = _this$editorProps3.componentBelowControlBar;
  38113. var _this$state = this.state,
  38114. isFullscreen = _this$state.isFullscreen,
  38115. editorState = _this$state.editorState;
  38116. editorId = editorId || id;
  38117. hooks = buildHooks(hooks);
  38118. controls = controls.filter(function (item) {
  38119. return excludeControls.indexOf(item) === -1;
  38120. });
  38121. language = (typeof language === 'function' ? language(languages, 'braft-editor') : languages[language]) || languages[configs_props.language];
  38122. var externalMedias = media && media.externals ? objectSpread_default()({}, configs_props.media.externals, media.externals) : configs_props.media.externals;
  38123. var accepts = media && media.accepts ? objectSpread_default()({}, configs_props.media.accepts, media.accepts) : configs_props.media.accepts;
  38124. media = objectSpread_default()({}, configs_props.media, media, {
  38125. externalMedias: externalMedias,
  38126. accepts: accepts
  38127. });
  38128. if (!media.uploadFn) {
  38129. media.video = false;
  38130. media.audio = false;
  38131. }
  38132. var controlBarProps = {
  38133. editor: this,
  38134. editorState: editorState,
  38135. braftFinder: this.braftFinder,
  38136. ref: function ref(instance) {
  38137. return _this4.controlBarInstance = instance;
  38138. },
  38139. getContainerNode: function getContainerNode() {
  38140. return _this4.containerNode;
  38141. },
  38142. className: controlBarClassName,
  38143. style: controlBarStyle,
  38144. colors: toConsumableArray_default()(colors).concat(toConsumableArray_default()(this.state.tempColors)),
  38145. colorPicker: colorPicker,
  38146. colorPickerTheme: colorPickerTheme,
  38147. colorPickerAutoHide: colorPickerAutoHide,
  38148. hooks: hooks,
  38149. editorId: editorId,
  38150. media: media,
  38151. controls: controls,
  38152. language: language,
  38153. extendControls: extendControls,
  38154. headings: headings,
  38155. fontSizes: fontSizes,
  38156. fontFamilies: fontFamilies,
  38157. emojis: emojis,
  38158. lineHeights: lineHeights,
  38159. letterSpacings: letterSpacings,
  38160. textAligns: textAligns,
  38161. textBackgroundColor: textBackgroundColor,
  38162. allowInsertLinkText: allowInsertLinkText,
  38163. defaultLinkTarget: defaultLinkTarget
  38164. };
  38165. var unitExportFn = editorState.convertOptions.unitExportFn;
  38166. var commonProps = {
  38167. editor: this,
  38168. editorId: editorId,
  38169. hooks: hooks,
  38170. editorState: editorState,
  38171. containerNode: this.containerNode,
  38172. imageControls: imageControls,
  38173. imageResizable: imageResizable,
  38174. language: language,
  38175. extendAtomics: extendAtomics
  38176. };
  38177. var blockRendererFn = getBlockRendererFn(commonProps, this.editorProps.blockRendererFn);
  38178. var blockRenderMap = getBlockRenderMap(commonProps, this.editorProps.blockRenderMap);
  38179. var blockStyleFn = getBlockStyleFn(this.editorProps.blockStyleFn);
  38180. var customStyleMap = getCustomStyleMap(commonProps, this.editorProps.customStyleMap);
  38181. var customStyleFn = getCustomStyleFn(commonProps, {
  38182. fontFamilies: fontFamilies,
  38183. unitExportFn: unitExportFn,
  38184. customStyleFn: this.editorProps.customStyleFn
  38185. });
  38186. var keyBindingFn = keybindings(this.editorProps.keyBindingFn);
  38187. var mixedProps = {};
  38188. if (this.state.editorLocked || this.editorProps.disabled || this.editorProps.readOnly || this.editorProps.draftProps.readOnly) {
  38189. mixedProps.readOnly = true;
  38190. }
  38191. if (placeholder && fixPlaceholder && editorState.isEmpty() && editorState.getCurrentContent().getFirstBlock().getType() !== 'unstyled') {
  38192. placeholder = '';
  38193. }
  38194. var draftProps = objectSpread_default()({
  38195. ref: function ref(instance) {
  38196. _this4.draftInstance = instance;
  38197. },
  38198. editorState: editorState,
  38199. handleKeyCommand: this.handleKeyCommand,
  38200. handleReturn: this.handleReturn,
  38201. handleBeforeInput: this.handleBeforeInput,
  38202. handleDrop: this.handleDrop,
  38203. handleDroppedFiles: this.handleDroppedFiles,
  38204. handlePastedText: this.handlePastedText,
  38205. handlePastedFiles: this.handlePastedFiles,
  38206. onChange: this.onChange,
  38207. onTab: this.onTab,
  38208. onFocus: this.onFocus,
  38209. onBlur: this.onBlur,
  38210. blockRenderMap: blockRenderMap,
  38211. blockRendererFn: blockRendererFn,
  38212. blockStyleFn: blockStyleFn,
  38213. customStyleMap: customStyleMap,
  38214. customStyleFn: customStyleFn,
  38215. keyBindingFn: keyBindingFn,
  38216. placeholder: placeholder,
  38217. stripPastedStyles: stripPastedStyles
  38218. }, this.editorProps.draftProps, mixedProps);
  38219. return external_react_default.a.createElement("div", {
  38220. style: style,
  38221. ref: this.setEditorContainerNode,
  38222. className: "bf-container ".concat(className).concat(disabled ? ' disabled' : '').concat(readOnly ? ' read-only' : '').concat(isFullscreen ? ' fullscreen' : '')
  38223. }, external_react_default.a.createElement(ControlBar_ControlBar, controlBarProps), componentBelowControlBar, external_react_default.a.createElement("div", {
  38224. onCompositionStart: this.handleCompositionStart,
  38225. className: "bf-content ".concat(contentClassName),
  38226. onCopy: this.handleCopyContent,
  38227. style: contentStyle
  38228. }, external_react_default.a.createElement(external_draft_js_["Editor"], draftProps)));
  38229. }
  38230. }]);
  38231. return BraftEditor;
  38232. }(external_react_default.a.Component);
  38233. defineProperty_default()(editor_BraftEditor, "defaultProps", configs_props);
  38234. // EXTERNAL MODULE: external "braft-convert"
  38235. var external_braft_convert_ = __webpack_require__(14);
  38236. // CONCATENATED MODULE: ./index.jsx
  38237. /* concated harmony reexport EditorState */__webpack_require__.d(__webpack_exports__, "EditorState", function() { return external_draft_js_["EditorState"]; });
  38238. /* concated harmony reexport getDecorators */__webpack_require__.d(__webpack_exports__, "getDecorators", function() { return getDecorators; });
  38239. external_draft_js_["EditorState"].prototype.setConvertOptions = function () {
  38240. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  38241. this.convertOptions = options;
  38242. };
  38243. external_draft_js_["EditorState"].prototype.toHTML = function () {
  38244. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  38245. var convertOptions = this.convertOptions || {};
  38246. return Object(external_braft_convert_["convertEditorStateToHTML"])(this, objectSpread_default()({}, convertOptions, options));
  38247. };
  38248. external_draft_js_["EditorState"].prototype.toRAW = function (noStringify) {
  38249. return noStringify ? Object(external_braft_convert_["convertEditorStateToRaw"])(this) : JSON.stringify(Object(external_braft_convert_["convertEditorStateToRaw"])(this));
  38250. };
  38251. external_draft_js_["EditorState"].prototype.toText = function () {
  38252. return this.getCurrentContent().getPlainText();
  38253. };
  38254. external_draft_js_["EditorState"].prototype.isEmpty = function () {
  38255. return !this.getCurrentContent().hasText();
  38256. };
  38257. editor_BraftEditor.createEditorState = external_draft_js_["EditorState"].createFrom = function (content) {
  38258. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  38259. options.unitExportFn = options.unitExportFn || editor_BraftEditor.defaultProps.converts.unitExportFn;
  38260. options.styleImportFn = compositeStyleImportFn(options.styleImportFn, options.editorId);
  38261. options.entityImportFn = compositeEntityImportFn(options.entityImportFn, options.editorId);
  38262. options.blockImportFn = compositeBlockImportFn(options.blockImportFn, options.editorId);
  38263. var editorState = null;
  38264. if (content instanceof external_draft_js_["EditorState"]) {
  38265. editorState = content;
  38266. } else if (typeof_default()(content) === 'object' && content && content.blocks && content.entityMap) {
  38267. editorState = Object(external_braft_convert_["convertRawToEditorState"])(content, getDecorators(options.editorId));
  38268. } else if (typeof content === 'string') {
  38269. try {
  38270. if (/^(-)?\d+$/.test(content)) {
  38271. editorState = Object(external_braft_convert_["convertHTMLToEditorState"])(content, getDecorators(options.editorId), options, 'create');
  38272. } else {
  38273. editorState = external_draft_js_["EditorState"].createFrom(JSON.parse(content), options);
  38274. }
  38275. } catch (error) {
  38276. editorState = Object(external_braft_convert_["convertHTMLToEditorState"])(content, getDecorators(options.editorId), options, 'create');
  38277. }
  38278. } else if (typeof content === 'number') {
  38279. editorState = Object(external_braft_convert_["convertHTMLToEditorState"])(content.toLocaleString().replace(/,/g, ''), getDecorators(options.editorId), options, 'create');
  38280. } else {
  38281. editorState = external_draft_js_["EditorState"].createEmpty(getDecorators(options.editorId));
  38282. }
  38283. options.styleExportFn = compositeStyleExportFn(options.styleExportFn, options.editorId);
  38284. options.entityExportFn = compositeEntityExportFn(options.entityExportFn, options.editorId);
  38285. options.blockExportFn = compositeBlockExportFn(options.blockExportFn, options.editorId);
  38286. editorState.setConvertOptions(options);
  38287. return editorState;
  38288. };
  38289. /* harmony default export */ var index_0 = __webpack_exports__["default"] = (createExtensibleEditor(editor_BraftEditor));
  38290. // 2.1版本开发计划
  38291. // [ ]优化选中多行文字是插入链接报错的问题
  38292. // [ ]新增编辑器内图片删除hook
  38293. // 2.2版本开发计划
  38294. // [ ]表格功能
  38295. // [ ]美化UI,包括图标和界面风格
  38296. // 2.3版本开发计划
  38297. // [ ]初级md快捷输入支持
  38298. // [ ]图片裁切等简单的编辑功能
  38299. // [ ]允许自定义快捷键
  38300. /***/ }),
  38301. /* 40 */
  38302. /***/ (function(module, exports) {
  38303. // removed by extract-text-webpack-plugin
  38304. /***/ }),
  38305. /* 41 */,
  38306. /* 42 */
  38307. /***/ (function(module, exports) {
  38308. // removed by extract-text-webpack-plugin
  38309. /***/ }),
  38310. /* 43 */,
  38311. /* 44 */,
  38312. /* 45 */
  38313. /***/ (function(module, exports) {
  38314. // removed by extract-text-webpack-plugin
  38315. /***/ }),
  38316. /* 46 */
  38317. /***/ (function(module, exports) {
  38318. // removed by extract-text-webpack-plugin
  38319. /***/ }),
  38320. /* 47 */
  38321. /***/ (function(module, exports) {
  38322. // removed by extract-text-webpack-plugin
  38323. /***/ }),
  38324. /* 48 */
  38325. /***/ (function(module, exports) {
  38326. // removed by extract-text-webpack-plugin
  38327. /***/ }),
  38328. /* 49 */
  38329. /***/ (function(module, exports) {
  38330. // removed by extract-text-webpack-plugin
  38331. /***/ }),
  38332. /* 50 */
  38333. /***/ (function(module, exports) {
  38334. // removed by extract-text-webpack-plugin
  38335. /***/ }),
  38336. /* 51 */
  38337. /***/ (function(module, exports) {
  38338. // removed by extract-text-webpack-plugin
  38339. /***/ }),
  38340. /* 52 */
  38341. /***/ (function(module, exports) {
  38342. // removed by extract-text-webpack-plugin
  38343. /***/ }),
  38344. /* 53 */
  38345. /***/ (function(module, exports) {
  38346. // removed by extract-text-webpack-plugin
  38347. /***/ }),
  38348. /* 54 */
  38349. /***/ (function(module, exports) {
  38350. // removed by extract-text-webpack-plugin
  38351. /***/ }),
  38352. /* 55 */
  38353. /***/ (function(module, exports) {
  38354. // removed by extract-text-webpack-plugin
  38355. /***/ }),
  38356. /* 56 */
  38357. /***/ (function(module, exports) {
  38358. // removed by extract-text-webpack-plugin
  38359. /***/ }),
  38360. /* 57 */
  38361. /***/ (function(module, exports) {
  38362. // removed by extract-text-webpack-plugin
  38363. /***/ }),
  38364. /* 58 */
  38365. /***/ (function(module, exports) {
  38366. // removed by extract-text-webpack-plugin
  38367. /***/ }),
  38368. /* 59 */
  38369. /***/ (function(module, exports) {
  38370. // removed by extract-text-webpack-plugin
  38371. /***/ }),
  38372. /* 60 */
  38373. /***/ (function(module, exports) {
  38374. // removed by extract-text-webpack-plugin
  38375. /***/ }),
  38376. /* 61 */
  38377. /***/ (function(module, exports) {
  38378. // removed by extract-text-webpack-plugin
  38379. /***/ }),
  38380. /* 62 */
  38381. /***/ (function(module, exports) {
  38382. // removed by extract-text-webpack-plugin
  38383. /***/ }),
  38384. /* 63 */
  38385. /***/ (function(module, exports) {
  38386. // removed by extract-text-webpack-plugin
  38387. /***/ })
  38388. /******/ ]);
  38389. });
  38390. });
  38391. var BraftEditor = unwrapExports(dist$3);
  38392. var css = ".index_baseWrapper__1_-58 {\n position: relative;\n}\n.index_baseWrapper__1_-58 .bf-container {\n display: flex;\n flex-direction: column;\n}\n.index_baseWrapper__1_-58 .bf-container .index_controlBar__3SzSH {\n box-shadow: none;\n}\n.index_baseWrapper__1_-58 .bf-container .index_editorContent__2UOaX {\n border: 1px solid #ccc;\n border-radius: 4px;\n height: auto;\n transition: border-color 0.3s;\n}\n.index_baseWrapper__1_-58 .bf-container .index_editorContent__2UOaX.index_focus__puDJA {\n border-color: #1790ff;\n}\n.index_baseWrapper__1_-58 .index_floatControls__2hVPf {\n position: absolute;\n right: 15px;\n bottom: 15px;\n display: flex;\n z-index: 2;\n}\n";
  38393. var styles = {
  38394. "baseWrapper": "index_baseWrapper__1_-58",
  38395. "controlBar": "index_controlBar__3SzSH",
  38396. "editorContent": "index_editorContent__2UOaX",
  38397. "focus": "index_focus__puDJA",
  38398. "floatControls": "index_floatControls__2hVPf"
  38399. };
  38400. styleInject(css);
  38401. var css$1 = ".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)}";
  38402. styleInject(css$1);
  38403. var css$2 = ".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}";
  38404. styleInject(css$2);
  38405. var emoticon = createCommonjsModule(function (module, exports) {
  38406. (function webpackUniversalModuleDefinition(root, factory) {
  38407. module.exports = factory(React, dist$1);
  38408. })(window, function(__WEBPACK_EXTERNAL_MODULE__1__, __WEBPACK_EXTERNAL_MODULE__6__) {
  38409. return /******/ (function(modules) { // webpackBootstrap
  38410. /******/ // The module cache
  38411. /******/ var installedModules = {};
  38412. /******/
  38413. /******/ // The require function
  38414. /******/ function __webpack_require__(moduleId) {
  38415. /******/
  38416. /******/ // Check if module is in cache
  38417. /******/ if(installedModules[moduleId]) {
  38418. /******/ return installedModules[moduleId].exports;
  38419. /******/ }
  38420. /******/ // Create a new module (and put it into the cache)
  38421. /******/ var module = installedModules[moduleId] = {
  38422. /******/ i: moduleId,
  38423. /******/ l: false,
  38424. /******/ exports: {}
  38425. /******/ };
  38426. /******/
  38427. /******/ // Execute the module function
  38428. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  38429. /******/
  38430. /******/ // Flag the module as loaded
  38431. /******/ module.l = true;
  38432. /******/
  38433. /******/ // Return the exports of the module
  38434. /******/ return module.exports;
  38435. /******/ }
  38436. /******/
  38437. /******/
  38438. /******/ // expose the modules object (__webpack_modules__)
  38439. /******/ __webpack_require__.m = modules;
  38440. /******/
  38441. /******/ // expose the module cache
  38442. /******/ __webpack_require__.c = installedModules;
  38443. /******/
  38444. /******/ // define getter function for harmony exports
  38445. /******/ __webpack_require__.d = function(exports, name, getter) {
  38446. /******/ if(!__webpack_require__.o(exports, name)) {
  38447. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  38448. /******/ }
  38449. /******/ };
  38450. /******/
  38451. /******/ // define __esModule on exports
  38452. /******/ __webpack_require__.r = function(exports) {
  38453. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  38454. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  38455. /******/ }
  38456. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  38457. /******/ };
  38458. /******/
  38459. /******/ // create a fake namespace object
  38460. /******/ // mode & 1: value is a module id, require it
  38461. /******/ // mode & 2: merge all properties of value into the ns
  38462. /******/ // mode & 4: return value when already ns object
  38463. /******/ // mode & 8|1: behave like require
  38464. /******/ __webpack_require__.t = function(value, mode) {
  38465. /******/ if(mode & 1) value = __webpack_require__(value);
  38466. /******/ if(mode & 8) return value;
  38467. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  38468. /******/ var ns = Object.create(null);
  38469. /******/ __webpack_require__.r(ns);
  38470. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  38471. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  38472. /******/ return ns;
  38473. /******/ };
  38474. /******/
  38475. /******/ // getDefaultExport function for compatibility with non-harmony modules
  38476. /******/ __webpack_require__.n = function(module) {
  38477. /******/ var getter = module && module.__esModule ?
  38478. /******/ function getDefault() { return module['default']; } :
  38479. /******/ function getModuleExports() { return module; };
  38480. /******/ __webpack_require__.d(getter, 'a', getter);
  38481. /******/ return getter;
  38482. /******/ };
  38483. /******/
  38484. /******/ // Object.prototype.hasOwnProperty.call
  38485. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  38486. /******/
  38487. /******/ // __webpack_public_path__
  38488. /******/ __webpack_require__.p = "/";
  38489. /******/
  38490. /******/
  38491. /******/ // Load entry module and return exports
  38492. /******/ return __webpack_require__(__webpack_require__.s = 33);
  38493. /******/ })
  38494. /************************************************************************/
  38495. /******/ ({
  38496. /***/ 1:
  38497. /***/ (function(module, exports) {
  38498. module.exports = __WEBPACK_EXTERNAL_MODULE__1__;
  38499. /***/ }),
  38500. /***/ 2:
  38501. /***/ (function(module, exports) {
  38502. function _defineProperty(obj, key, value) {
  38503. if (key in obj) {
  38504. Object.defineProperty(obj, key, {
  38505. value: value,
  38506. enumerable: true,
  38507. configurable: true,
  38508. writable: true
  38509. });
  38510. } else {
  38511. obj[key] = value;
  38512. }
  38513. return obj;
  38514. }
  38515. module.exports = _defineProperty;
  38516. /***/ }),
  38517. /***/ 33:
  38518. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  38519. __webpack_require__.r(__webpack_exports__);
  38520. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "defaultEmoticons", function() { return defaultEmoticons; });
  38521. /* harmony import */ var _babel_runtime_helpers_objectSpread__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(5);
  38522. /* harmony import */ var _babel_runtime_helpers_objectSpread__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_objectSpread__WEBPACK_IMPORTED_MODULE_0__);
  38523. /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1);
  38524. /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_1__);
  38525. /* harmony import */ var braft_utils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6);
  38526. /* harmony import */ var _styles_scss__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(48);
  38527. // https://www.iconfinder.com/iconsets/emoji-18
  38528. 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) {
  38529. return "".concat(item, ".png");
  38530. });
  38531. var insertEmoticon = function insertEmoticon(editor, editorState, src) {
  38532. editor.setValue(braft_utils__WEBPACK_IMPORTED_MODULE_2__["ContentUtils"].insertText(editorState, ' ', null, {
  38533. type: 'EMOTICON',
  38534. mutability: 'IMMUTABLE',
  38535. data: {
  38536. src: src
  38537. }
  38538. }));
  38539. };
  38540. var controlRef = null;
  38541. var bindControlRef = function bindControlRef(ref) {
  38542. return controlRef = ref;
  38543. };
  38544. /* harmony default export */ __webpack_exports__["default"] = (function (options) {
  38545. options = _babel_runtime_helpers_objectSpread__WEBPACK_IMPORTED_MODULE_0___default()({
  38546. emoticons: [],
  38547. closeOnSelect: false,
  38548. closeOnBlur: false
  38549. }, options);
  38550. var _options = options,
  38551. emoticons = _options.emoticons,
  38552. closeOnSelect = _options.closeOnSelect,
  38553. closeOnBlur = _options.closeOnBlur,
  38554. includeEditors = _options.includeEditors,
  38555. excludeEditors = _options.excludeEditors;
  38556. return {
  38557. type: 'entity',
  38558. includeEditors: includeEditors,
  38559. excludeEditors: excludeEditors,
  38560. name: 'EMOTICON',
  38561. control: function control(props) {
  38562. return {
  38563. key: 'EMOTICON',
  38564. replace: 'emoji',
  38565. type: 'dropdown',
  38566. text: react__WEBPACK_IMPORTED_MODULE_1___default.a.createElement("i", {
  38567. className: "bfi-emoji"
  38568. }),
  38569. showArrow: false,
  38570. ref: bindControlRef,
  38571. autoHide: closeOnBlur,
  38572. component: react__WEBPACK_IMPORTED_MODULE_1___default.a.createElement("div", {
  38573. className: "braft-emoticon-picker"
  38574. }, react__WEBPACK_IMPORTED_MODULE_1___default.a.createElement("div", {
  38575. className: "braft-emoticons-list"
  38576. }, emoticons.map(function (item, index) {
  38577. return react__WEBPACK_IMPORTED_MODULE_1___default.a.createElement("img", {
  38578. onClick: function onClick() {
  38579. insertEmoticon(props.editor, props.editorState, item);
  38580. closeOnSelect && controlRef && controlRef.hide();
  38581. },
  38582. key: index,
  38583. src: item
  38584. });
  38585. })))
  38586. };
  38587. },
  38588. mutability: 'IMMUTABLE',
  38589. component: function component(props) {
  38590. var entity = props.contentState.getEntity(props.entityKey);
  38591. var _entity$getData = entity.getData(),
  38592. src = _entity$getData.src;
  38593. return react__WEBPACK_IMPORTED_MODULE_1___default.a.createElement("span", {
  38594. className: "braft-emoticon-in-editor"
  38595. }, react__WEBPACK_IMPORTED_MODULE_1___default.a.createElement("img", {
  38596. src: src
  38597. }), props.children);
  38598. },
  38599. importer: function importer(nodeName, node) {
  38600. if (nodeName.toLowerCase() === 'span' && node.classList && node.classList.contains('braft-emoticon-wrap')) {
  38601. var imgNode = node.querySelector('img');
  38602. var src = imgNode.getAttribute('src'); // 移除img节点以避免生成atomic block
  38603. node.removeChild(imgNode);
  38604. return {
  38605. mutability: 'IMMUTABLE',
  38606. data: {
  38607. src: src
  38608. }
  38609. };
  38610. }
  38611. },
  38612. exporter: function exporter(entityObject, initialText) {
  38613. var src = entityObject.data.src;
  38614. return react__WEBPACK_IMPORTED_MODULE_1___default.a.createElement("span", {
  38615. className: "braft-emoticon-wrap"
  38616. }, react__WEBPACK_IMPORTED_MODULE_1___default.a.createElement("img", {
  38617. src: src
  38618. }), initialText);
  38619. }
  38620. };
  38621. });
  38622. /***/ }),
  38623. /***/ 48:
  38624. /***/ (function(module, exports) {
  38625. // removed by extract-text-webpack-plugin
  38626. /***/ }),
  38627. /***/ 5:
  38628. /***/ (function(module, exports, __webpack_require__) {
  38629. var defineProperty = __webpack_require__(2);
  38630. function _objectSpread(target) {
  38631. for (var i = 1; i < arguments.length; i++) {
  38632. var source = arguments[i] != null ? arguments[i] : {};
  38633. var ownKeys = Object.keys(source);
  38634. if (typeof Object.getOwnPropertySymbols === 'function') {
  38635. ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
  38636. return Object.getOwnPropertyDescriptor(source, sym).enumerable;
  38637. }));
  38638. }
  38639. ownKeys.forEach(function (key) {
  38640. defineProperty(target, key, source[key]);
  38641. });
  38642. }
  38643. return target;
  38644. }
  38645. module.exports = _objectSpread;
  38646. /***/ }),
  38647. /***/ 6:
  38648. /***/ (function(module, exports) {
  38649. module.exports = __WEBPACK_EXTERNAL_MODULE__6__;
  38650. /***/ })
  38651. /******/ });
  38652. });
  38653. });
  38654. var Emoticon = unwrapExports(emoticon);
  38655. var emoticon_1 = emoticon.defaultEmoticons;
  38656. var maxLength = createCommonjsModule(function (module, exports) {
  38657. (function webpackUniversalModuleDefinition(root, factory) {
  38658. module.exports = factory();
  38659. })(window, function() {
  38660. return /******/ (function(modules) { // webpackBootstrap
  38661. /******/ // The module cache
  38662. /******/ var installedModules = {};
  38663. /******/
  38664. /******/ // The require function
  38665. /******/ function __webpack_require__(moduleId) {
  38666. /******/
  38667. /******/ // Check if module is in cache
  38668. /******/ if(installedModules[moduleId]) {
  38669. /******/ return installedModules[moduleId].exports;
  38670. /******/ }
  38671. /******/ // Create a new module (and put it into the cache)
  38672. /******/ var module = installedModules[moduleId] = {
  38673. /******/ i: moduleId,
  38674. /******/ l: false,
  38675. /******/ exports: {}
  38676. /******/ };
  38677. /******/
  38678. /******/ // Execute the module function
  38679. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  38680. /******/
  38681. /******/ // Flag the module as loaded
  38682. /******/ module.l = true;
  38683. /******/
  38684. /******/ // Return the exports of the module
  38685. /******/ return module.exports;
  38686. /******/ }
  38687. /******/
  38688. /******/
  38689. /******/ // expose the modules object (__webpack_modules__)
  38690. /******/ __webpack_require__.m = modules;
  38691. /******/
  38692. /******/ // expose the module cache
  38693. /******/ __webpack_require__.c = installedModules;
  38694. /******/
  38695. /******/ // define getter function for harmony exports
  38696. /******/ __webpack_require__.d = function(exports, name, getter) {
  38697. /******/ if(!__webpack_require__.o(exports, name)) {
  38698. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  38699. /******/ }
  38700. /******/ };
  38701. /******/
  38702. /******/ // define __esModule on exports
  38703. /******/ __webpack_require__.r = function(exports) {
  38704. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  38705. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  38706. /******/ }
  38707. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  38708. /******/ };
  38709. /******/
  38710. /******/ // create a fake namespace object
  38711. /******/ // mode & 1: value is a module id, require it
  38712. /******/ // mode & 2: merge all properties of value into the ns
  38713. /******/ // mode & 4: return value when already ns object
  38714. /******/ // mode & 8|1: behave like require
  38715. /******/ __webpack_require__.t = function(value, mode) {
  38716. /******/ if(mode & 1) value = __webpack_require__(value);
  38717. /******/ if(mode & 8) return value;
  38718. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  38719. /******/ var ns = Object.create(null);
  38720. /******/ __webpack_require__.r(ns);
  38721. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  38722. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  38723. /******/ return ns;
  38724. /******/ };
  38725. /******/
  38726. /******/ // getDefaultExport function for compatibility with non-harmony modules
  38727. /******/ __webpack_require__.n = function(module) {
  38728. /******/ var getter = module && module.__esModule ?
  38729. /******/ function getDefault() { return module['default']; } :
  38730. /******/ function getModuleExports() { return module; };
  38731. /******/ __webpack_require__.d(getter, 'a', getter);
  38732. /******/ return getter;
  38733. /******/ };
  38734. /******/
  38735. /******/ // Object.prototype.hasOwnProperty.call
  38736. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  38737. /******/
  38738. /******/ // __webpack_public_path__
  38739. /******/ __webpack_require__.p = "/";
  38740. /******/
  38741. /******/
  38742. /******/ // Load entry module and return exports
  38743. /******/ return __webpack_require__(__webpack_require__.s = 34);
  38744. /******/ })
  38745. /************************************************************************/
  38746. /******/ ({
  38747. /***/ 2:
  38748. /***/ (function(module, exports) {
  38749. function _defineProperty(obj, key, value) {
  38750. if (key in obj) {
  38751. Object.defineProperty(obj, key, {
  38752. value: value,
  38753. enumerable: true,
  38754. configurable: true,
  38755. writable: true
  38756. });
  38757. } else {
  38758. obj[key] = value;
  38759. }
  38760. return obj;
  38761. }
  38762. module.exports = _defineProperty;
  38763. /***/ }),
  38764. /***/ 34:
  38765. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  38766. __webpack_require__.r(__webpack_exports__);
  38767. /* harmony import */ var _babel_runtime_helpers_objectSpread__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(5);
  38768. /* harmony import */ var _babel_runtime_helpers_objectSpread__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_objectSpread__WEBPACK_IMPORTED_MODULE_0__);
  38769. var getSelectedTextLength = function getSelectedTextLength(editorState) {
  38770. var currentSelection = editorState.getSelection();
  38771. var isCollapsed = currentSelection.isCollapsed();
  38772. var length = 0;
  38773. if (!isCollapsed) {
  38774. var currentContent = editorState.getCurrentContent();
  38775. var startKey = currentSelection.getStartKey();
  38776. var endKey = currentSelection.getEndKey();
  38777. var startBlock = currentContent.getBlockForKey(startKey);
  38778. var isStartAndEndBlockAreTheSame = startKey === endKey;
  38779. var startBlockTextLength = startBlock.getLength();
  38780. var startSelectedTextLength = startBlockTextLength - currentSelection.getStartOffset();
  38781. var endSelectedTextLength = currentSelection.getEndOffset();
  38782. var keyAfterEnd = currentContent.getKeyAfter(endKey);
  38783. if (isStartAndEndBlockAreTheSame) {
  38784. length += currentSelection.getEndOffset() - currentSelection.getStartOffset();
  38785. } else {
  38786. var currentKey = startKey;
  38787. while (currentKey && currentKey !== keyAfterEnd) {
  38788. if (currentKey === startKey) {
  38789. length += startSelectedTextLength + 1;
  38790. } else if (currentKey === endKey) {
  38791. length += endSelectedTextLength;
  38792. } else {
  38793. length += currentContent.getBlockForKey(currentKey).getLength() + 1;
  38794. }
  38795. currentKey = currentContent.getKeyAfter(currentKey);
  38796. }
  38797. }
  38798. }
  38799. return length;
  38800. };
  38801. /* harmony default export */ __webpack_exports__["default"] = (function (options) {
  38802. options = _babel_runtime_helpers_objectSpread__WEBPACK_IMPORTED_MODULE_0___default()({
  38803. defaultValue: Infinity
  38804. }, options);
  38805. var _options = options,
  38806. includeEditors = _options.includeEditors,
  38807. excludeEditors = _options.excludeEditors,
  38808. defaultValue = _options.defaultValue;
  38809. return {
  38810. type: 'prop-interception',
  38811. includeEditors: includeEditors,
  38812. excludeEditors: excludeEditors,
  38813. interceptor: function interceptor(editorProps) {
  38814. var maxLength = editorProps.maxLength || defaultValue;
  38815. editorProps.handleBeforeInput = function (_, editorState) {
  38816. if (maxLength === Infinity) {
  38817. return 'not-handled';
  38818. }
  38819. var currentContentLength = editorState.toText().length;
  38820. var selectedTextLength = getSelectedTextLength(editorState);
  38821. if (currentContentLength - selectedTextLength > maxLength - 1) {
  38822. editorProps.onReachMaxLength && editorProps.onReachMaxLength(maxLength);
  38823. return 'handled';
  38824. }
  38825. };
  38826. editorProps.handlePastedText = function (pastedText, _, editorState) {
  38827. if (maxLength === Infinity) {
  38828. return 'not-handled';
  38829. }
  38830. var currentContentLength = editorState.toText().length;
  38831. var selectedTextLength = getSelectedTextLength(editorState);
  38832. if (currentContentLength + pastedText.length - selectedTextLength > maxLength) {
  38833. editorProps.onReachMaxLength && editorProps.onReachMaxLength(maxLength);
  38834. return 'handled';
  38835. }
  38836. };
  38837. return editorProps;
  38838. }
  38839. };
  38840. });
  38841. /***/ }),
  38842. /***/ 5:
  38843. /***/ (function(module, exports, __webpack_require__) {
  38844. var defineProperty = __webpack_require__(2);
  38845. function _objectSpread(target) {
  38846. for (var i = 1; i < arguments.length; i++) {
  38847. var source = arguments[i] != null ? arguments[i] : {};
  38848. var ownKeys = Object.keys(source);
  38849. if (typeof Object.getOwnPropertySymbols === 'function') {
  38850. ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
  38851. return Object.getOwnPropertyDescriptor(source, sym).enumerable;
  38852. }));
  38853. }
  38854. ownKeys.forEach(function (key) {
  38855. defineProperty(target, key, source[key]);
  38856. });
  38857. }
  38858. return target;
  38859. }
  38860. module.exports = _objectSpread;
  38861. /***/ })
  38862. /******/ });
  38863. });
  38864. });
  38865. var MaxLength = unwrapExports(maxLength);
  38866. var lengthOptions = {
  38867. defaultValue: 100
  38868. };
  38869. BraftEditor.use(MaxLength(lengthOptions));
  38870. var emoticons = emoticon_1.map(function (item) {
  38871. return require("braft-extensions/dist/assets/".concat(item));
  38872. });
  38873. var emotionOptions = {
  38874. emoticons: emoticons,
  38875. closeOnBlur: true,
  38876. closeOnSelect: false
  38877. };
  38878. BraftEditor.use(Emoticon(emotionOptions));
  38879. var BarftEditorPage = function BarftEditorPage(_ref) {
  38880. var _classnames2;
  38881. var value = _ref.value,
  38882. onChange = _ref.onChange,
  38883. controls = _ref.controls,
  38884. FloatControls = _ref.FloatControls;
  38885. var optionsControls = controls ? controls : ["bold", "italic", "underline", "separator", "link", "emoji", "separator", "media"];
  38886. var options = {
  38887. controls: optionsControls,
  38888. showControlsBar: optionsControls && optionsControls.length > 0 && !FloatControls,
  38889. showFloatControls: FloatControls
  38890. };
  38891. var _useState = useState(false),
  38892. _useState2 = _slicedToArray(_useState, 2),
  38893. focusState = _useState2[0],
  38894. setFocusState = _useState2[1];
  38895. return React.createElement("div", {
  38896. className: styles.baseWrapper
  38897. }, React.createElement(BraftEditor, {
  38898. value: value,
  38899. onChange: onChange,
  38900. controls: options.controls,
  38901. controlBarClassName: classnames(styles.controlBar, _defineProperty$1({}, styles.focus, focusState)),
  38902. controlBarStyle: options.showControlsBar ? {} : {
  38903. display: "none"
  38904. },
  38905. contentClassName: classnames(styles.editorContent, (_classnames2 = {}, _defineProperty$1(_classnames2, styles.focus, focusState), _defineProperty$1(_classnames2, styles.hasFloatControls, options.showFloatControls), _classnames2)),
  38906. contentStyle: {},
  38907. onFocus: function onFocus() {
  38908. return setFocusState(true);
  38909. },
  38910. onBlur: function onBlur() {
  38911. return setFocusState(false);
  38912. },
  38913. hooks: {
  38914. "toggle-link": function toggleLink(_ref2) {
  38915. var href = _ref2.href,
  38916. target = _ref2.target;
  38917. href = href.indexOf("http") === 0 ? href : "http://".concat(href);
  38918. return {
  38919. href: href,
  38920. target: target
  38921. };
  38922. }
  38923. }
  38924. }), options.showFloatControls ? React.createElement("div", {
  38925. className: classnames(styles.floatControls)
  38926. }, React.createElement(FloatControls, {
  38927. editorState: value,
  38928. setEditorState: onChange
  38929. })) : null);
  38930. };
  38931. export default BarftEditorPage;
  38932. export { BarftEditorPage };
  38933. //# sourceMappingURL=index.js.map